Skip to content

dotc_core test fails when Config.cacheImplicitScopes == false #347

@olhotak

Description

@olhotak

The dotc_core test fails when Config.cacheImplicitScopes is false (normally, it is set to true). The same failure also occurs even when cacheImplicitScopes is true but AnnotatedTypes are present, because scopes for AnnotatedTypes are never cached.

The following method in Implicits.scala looks suspicious:

    def iscope(tp: Type, isLifted: Boolean = false): OfTypeImplicits =
      if (tp.hash == NotCached || !Config.cacheImplicitScopes)
        ofTypeImplicits(collectCompanions(tp))
      else implicitScopeCache get tp match {
        case Some(is) => is
        case None =>
          val savedEphemeral = ctx.typerState.ephemeral
          ctx.typerState.ephemeral = false
          try {
            val liftedTp = if (isLifted) tp else liftToClasses(tp)
            val result =
              if (liftedTp ne tp) iscope(liftedTp, isLifted = true)
              else ofTypeImplicits(collectCompanions(tp))
            if (ctx.typerState.ephemeral) record("ephemeral cache miss: implicitScope")
            else implicitScopeCache(tp) = result
            result
          }
          finally ctx.typerState.ephemeral |= savedEphemeral
        }

When a type is looked up in the cache but is not found, the code sets the typer state to ephemeral and calls liftToClasses on the type. However, when a type is not looked up in the cache at all, none of this happens, and the code just calls ofTypeImplicits(collectCompanions(tp)) directly.

It would seem that the behaviour ought to be the same in the case of a cache miss as in the case that the cache is not used at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions