Skip to content

Commit d009eb8

Browse files
committed
ResolveSuper: MixinOps save 2-3 seconds on stdlib compilation.
By ordering tests in a smarter way. Add leave a big scary comment.
1 parent 5bcbad2 commit d009eb8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/transform/MixinOps.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class MixinOps(cls: ClassSymbol, thisTransform: DenotTransformer)(implicit ctx:
4040
def isCurrent(sym: Symbol) =
4141
ctx.atPhase(thisTransform) { implicit ctx =>
4242
cls.info.member(sym.name).hasAltWith(_.symbol == sym)
43+
// this is a hot spot, where we spend several seconds while compiling stdlib
44+
// unfortunately it will discard and recompute all the member chaches,
45+
// both making itself slow and slowing down anything that runs after it
46+
// because resolveSuper uses hacks with explicit adding to scopes through .enter
47+
// this cannot be fixed by a smarter caching strategy. With current implementation
48+
// we HAVE to discard caches here for correctness
4349
}
4450

4551
/** Does `method` need a forwarder to in class `cls`
@@ -53,8 +59,8 @@ class MixinOps(cls: ClassSymbol, thisTransform: DenotTransformer)(implicit ctx:
5359
def needsDisambiguation = competingMethods.exists(x=> !(x is Deferred)) // multiple implementations are available
5460
def hasNonInterfaceDefinition = competingMethods.exists(!_.owner.is(Trait)) // there is a definition originating from class
5561
meth.is(Method, butNot = PrivateOrAccessorOrDeferred) &&
56-
isCurrent(meth) &&
57-
(needsDisambiguation || hasNonInterfaceDefinition || meth.owner.is(Scala2x))
62+
(meth.owner.is(Scala2x) || needsDisambiguation || hasNonInterfaceDefinition ) &&
63+
isCurrent(meth)
5864
}
5965

6066
/** Get `sym` of the method that needs a forwarder

0 commit comments

Comments
 (0)