Skip to content

Commit

Permalink
Merge pull request scala#7107 from retronym/topic/implicit-imports
Browse files Browse the repository at this point in the history
Avoid expensive call to `imports` in implicit search
  • Loading branch information
lrytz authored Aug 20, 2018
2 parents b339d6f + 2fae7d8 commit e7d934c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/compiler/scala/tools/nsc/typechecker/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ trait Contexts { self: Analyzer =>

/** @return None if a cycle is detected, or Some(infos) containing the in-scope implicits at this context */
private def implicits(nextOuter: Context): Option[List[ImplicitInfo]] = {
val imports = this.imports
val firstImport = this.firstImport
if (owner != nextOuter.owner && owner.isClass && !owner.isPackageClass && !inSelfSuperCall) {
if (!owner.isInitialized) None
else savingEnclClass(this) {
Expand All @@ -1082,13 +1082,14 @@ trait Contexts { self: Analyzer =>
debuglog("collect local implicits " + scope.toList)//DEBUG
Some(collectImplicits(scope, NoPrefix))
} else if (firstImport != nextOuter.firstImport) {
assert(imports.tail.headOption == nextOuter.firstImport, (imports, nextOuter.imports))
Some(collectImplicitImports(imports.head))
if (isDeveloper)
assert(imports.tail.headOption == nextOuter.firstImport, (imports, nextOuter.imports))
Some(collectImplicitImports(firstImport.get))
} else if (owner.isPackageClass) {
// the corresponding package object may contain implicit members.
val pre = owner.packageObject.typeOfThis
Some(collectImplicits(pre.implicitMembers, pre))
} else Some(Nil)
} else SomeNil
}

//
Expand Down Expand Up @@ -1728,6 +1729,8 @@ trait Contexts { self: Analyzer =>
private def imp1Explicit = imp1 isExplicitImport name
private def imp2Explicit = imp2 isExplicitImport name
}

private final val SomeNil = Some(Nil)
}

object ContextMode {
Expand Down

0 comments on commit e7d934c

Please sign in to comment.