Skip to content

Commit 477ebee

Browse files
authored
Merge pull request #4156 from dotty-staging/opt-findRef
Optimize findRef
2 parents 4a257df + 1e34d2d commit 477ebee

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
549549
if (inst.exists) sigName(inst) else tpnme.Uninstantiated
550550
case tp: TypeProxy =>
551551
sigName(tp.underlying)
552-
case _: ErrorType | WildcardType =>
552+
case _: ErrorType | WildcardType | NoType =>
553553
tpnme.WILDCARD
554554
case tp: WildcardType =>
555555
sigName(tp.optBounds)

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,20 @@ object Types {
508508
case tp1 => tp1
509509
})
510510
case tp: TypeRef =>
511-
tp.denot.findMember(name, pre, excluded)
511+
tp.denot match {
512+
case d: ClassDenotation => d.findMember(name, pre, excluded)
513+
case d => go(d.info)
514+
}
512515
case tp: AppliedType =>
513-
goApplied(tp)
514-
case tp: ThisType =>
516+
tp.tycon match {
517+
case tc: TypeRef if tc.symbol.isClass =>
518+
go(tc)
519+
case tc: HKTypeLambda =>
520+
goApplied(tp, tc)
521+
case _ =>
522+
go(tp.superType)
523+
}
524+
case tp: ThisType => // ??? inline
515525
goThis(tp)
516526
case tp: RefinedType =>
517527
if (name eq tp.refinedName) goRefined(tp) else go(tp.parent)
@@ -598,15 +608,9 @@ object Types {
598608
}
599609
}
600610

601-
def goApplied(tp: AppliedType) = tp.tycon match {
602-
case tl: HKTypeLambda =>
603-
go(tl.resType).mapInfo(info =>
604-
tl.derivedLambdaAbstraction(tl.paramNames, tl.paramInfos, info).appliedTo(tp.args))
605-
case tc: TypeRef if tc.symbol.isClass =>
606-
go(tc)
607-
case _ =>
608-
go(tp.superType)
609-
}
611+
def goApplied(tp: AppliedType, tycon: HKTypeLambda) =
612+
go(tycon.resType).mapInfo(info =>
613+
tycon.derivedLambdaAbstraction(tycon.paramNames, tycon.paramInfos, info).appliedTo(tp.args))
610614

611615
def goThis(tp: ThisType) = {
612616
val d = go(tp.underlying)
@@ -623,6 +627,7 @@ object Types {
623627
// loadClassWithPrivateInnerAndSubSelf in ShowClassTests
624628
go(tp.cls.typeRef) orElse d
625629
}
630+
626631
def goParam(tp: TypeParamRef) = {
627632
val next = tp.underlying
628633
ctx.typerState.constraint.entry(tp) match {
@@ -632,12 +637,14 @@ object Types {
632637
go(next)
633638
}
634639
}
640+
635641
def goSuper(tp: SuperType) = go(tp.underlying) match {
636642
case d: JointRefDenotation =>
637643
typr.println(i"redirecting super.$name from $tp to ${d.symbol.showLocated}")
638644
new UniqueRefDenotation(d.symbol, tp.memberInfo(d.symbol), d.validFor)
639645
case d => d
640646
}
647+
641648
def goAnd(l: Type, r: Type) = {
642649
go(l) & (go(r), pre, safeIntersection = ctx.pendingMemberSearches.contains(name))
643650
}

0 commit comments

Comments
 (0)