summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-06-14 08:40:11 +0200
committerJason Zaugg <jzaugg@gmail.com>2012-06-14 08:40:11 +0200
commitd3393306e3899e638b1c5ebe577f3fe1b2729cbd (patch)
tree5896e28b0afb7c30a9dbdd770206940e3c54ee6a /src/compiler
parent9129cfe9117e41d44cda30222ffef22b70767cfb (diff)
downloadscala-d3393306e3899e638b1c5ebe577f3fe1b2729cbd.tar.gz
scala-d3393306e3899e638b1c5ebe577f3fe1b2729cbd.tar.bz2
scala-d3393306e3899e638b1c5ebe577f3fe1b2729cbd.zip
SI-4270 Refactor for efficiency and clarity.
Avoids allocation of the hashset used by shadowing checks when searching in the implicit scope, and replaces three checks for `if (isLocal)` with a sprinkling of polymorphism.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index 97a229a18d..22c0ba3a1c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -739,15 +739,33 @@ trait Implicits {
* enclosing scope, and so on.
*/
class ImplicitComputation(iss: Infoss, isLocal: Boolean) {
- private val shadowed = util.HashSet[Name](512)
+ abstract class Shadower {
+ def addInfos(infos: Infos)
+ def isShadowed(name: Name): Boolean
+ }
+ private val shadower: Shadower = {
+ /** Used for exclude implicits from outer scopes that are shadowed by same-named implicits */
+ final class LocalShadower extends Shadower {
+ val shadowed = util.HashSet[Name](512)
+ def addInfos(infos: Infos) {
+ shadowed addEntries infos.map(_.name)
+ }
+ def isShadowed(name: Name) = shadowed(name)
+ }
+ /** Used for the implicits of expected type, when no shadowing checks are needed. */
+ object NoShadower extends Shadower {
+ def addInfos(infos: Infos) {}
+ def isShadowed(name: Name) = false
+ }
+ if (isLocal) new LocalShadower else NoShadower
+ }
+
private var best: SearchResult = SearchFailure
- private def isShadowed(name: Name) = (
- isLocal && shadowed(name)
- )
+
private def isIneligible(info: ImplicitInfo) = (
info.isCyclicOrErroneous
|| isView && isPredefMemberNamed(info.sym, nme.conforms)
- || isShadowed(info.name)
+ || shadower.isShadowed(info.name)
|| (!context.macrosEnabled && info.sym.isTermMacro)
)
@@ -786,7 +804,7 @@ trait Implicits {
val eligible = {
val matches = iss flatMap { is =>
val result = is filter (info => checkValid(info.sym) && survives(info))
- if (isLocal) shadowed addEntries (is map (_.name))
+ shadower addInfos is
result
}