Skip to content

Commit 9a8f575

Browse files
committed
Drop redundant computations
Avoiding parents in superclasses was done twice. We drop the second computation, which is less efficient than the first.
1 parent fa6a257 commit 9a8f575

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -360,27 +360,6 @@ object RefChecks {
360360

361361
//Console.println(infoString(member) + " overrides " + infoString(other) + " in " + clazz);//DEBUG
362362

363-
// return if we already checked this combination elsewhere
364-
if (member.owner != clazz) {
365-
def deferredCheck = member.is(Deferred) || !other.is(Deferred)
366-
def subOther(s: Symbol) = s derivesFrom other.owner
367-
def subMember(s: Symbol) = s derivesFrom member.owner
368-
369-
if (subOther(member.owner) && deferredCheck)
370-
//Console.println(infoString(member) + " shadows1 " + infoString(other) " in " + clazz);//DEBUG
371-
return
372-
val parentSymbols = clazz.info.parents.map(_.typeSymbol)
373-
def matchIn(parent: Symbol): Boolean = considerMatching(member, other, parent.thisType)
374-
if parentSymbols.exists(p =>
375-
subOther(p) && subMember(p) && deferredCheck && matchIn(p))
376-
then
377-
//Console.println(infoString(member) + " shadows2 " + infoString(other) + " in " + clazz);//DEBUG
378-
return
379-
if parentSymbols.forall(p => subOther(p) == subMember(p) && matchIn(p)) then
380-
//Console.println(infoString(member) + " shadows " + infoString(other) + " in " + clazz);//DEBUG
381-
return
382-
}
383-
384363
/* Is the intersection between given two lists of overridden symbols empty? */
385364
def intersectionIsEmpty(syms1: Iterator[Symbol], syms2: Iterator[Symbol]) = {
386365
val set2 = syms2.toSet
@@ -508,21 +487,27 @@ object RefChecks {
508487
* - matching names and types, but different target names
509488
*/
510489
def considerMatching(sym1: Symbol, sym2: Symbol, self: Type): Boolean =
511-
!(sym1.owner.is(JavaDefined, butNot = Trait) && sym2.owner.is(JavaDefined, butNot = Trait)) && // javac already handles these checks
512-
(sym1.isType || {
513-
val sd1 = sym1.asSeenFrom(self)
514-
val sd2 = sym2.asSeenFrom(self)
515-
sd1.matchesLoosely(sd2)
490+
if sym1.owner.is(JavaDefined, butNot = Trait)
491+
&& sym2.owner.is(JavaDefined, butNot = Trait)
492+
then false // javac already handles these checks
493+
else if sym1.isType then true
494+
else
495+
val sd1 = sym1.asSeenFrom(self)
496+
val sd2 = sym2.asSeenFrom(self)
497+
sd1.matchesLoosely(sd2)
516498
&& (sym1.hasTargetName(sym2.targetName)
517499
|| compatibleTypes(sym1, sd1.info, sym2, sd2.info))
518-
})
519500

520501
val opc = new OverridingPairs.Cursor(clazz):
521502
override def matches(sym1: Symbol, sym2: Symbol): Boolean =
522503
considerMatching(sym1, sym2, self)
504+
505+
// We can exclude pairs safely from checking only of they also matched in
506+
// the parent class. See neg/i12828.scala for an example where this matters.
523507
override def canBeHandledByParent(sym1: Symbol, sym2: Symbol, parentType: Type): Boolean =
524508
considerMatching(sym1, sym2, parentType)
525509
.showing(i"already handled ${sym1.showLocated}: ${sym1.asSeenFrom(parentType).signature}, ${sym2.showLocated}: ${sym2.asSeenFrom(parentType).signature} = $result", refcheck)
510+
end opc
526511

527512
while opc.hasNext do
528513
checkOverride(opc.overriding, opc.overridden)

0 commit comments

Comments
 (0)