From e7a54380aa3a47ad8b25068add26e6a8ee698569 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 22 Mar 2018 15:44:42 +0100 Subject: [PATCH 1/2] Optimize findRef ... by inlining two frequently used submethods --- .../src/dotty/tools/dotc/core/Types.scala | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 6b68ea100c12..37b3a0cce47d 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -508,10 +508,20 @@ object Types { case tp1 => tp1 }) case tp: TypeRef => - tp.denot.findMember(name, pre, excluded) + tp.denot match { + case d: ClassDenotation => d.findMember(name, pre, excluded) + case d => go(d.info) + } case tp: AppliedType => - goApplied(tp) - case tp: ThisType => + tp.tycon match { + case tc: TypeRef if tc.symbol.isClass => + go(tc) + case tc: HKTypeLambda => + goApplied(tp, tc) + case _ => + go(tp.superType) + } + case tp: ThisType => // ??? inline goThis(tp) case tp: RefinedType => if (name eq tp.refinedName) goRefined(tp) else go(tp.parent) @@ -598,15 +608,9 @@ object Types { } } - def goApplied(tp: AppliedType) = tp.tycon match { - case tl: HKTypeLambda => - go(tl.resType).mapInfo(info => - tl.derivedLambdaAbstraction(tl.paramNames, tl.paramInfos, info).appliedTo(tp.args)) - case tc: TypeRef if tc.symbol.isClass => - go(tc) - case _ => - go(tp.superType) - } + def goApplied(tp: AppliedType, tycon: HKTypeLambda) = + go(tycon.resType).mapInfo(info => + tycon.derivedLambdaAbstraction(tycon.paramNames, tycon.paramInfos, info).appliedTo(tp.args)) def goThis(tp: ThisType) = { val d = go(tp.underlying) @@ -623,6 +627,7 @@ object Types { // loadClassWithPrivateInnerAndSubSelf in ShowClassTests go(tp.cls.typeRef) orElse d } + def goParam(tp: TypeParamRef) = { val next = tp.underlying ctx.typerState.constraint.entry(tp) match { @@ -632,12 +637,14 @@ object Types { go(next) } } + def goSuper(tp: SuperType) = go(tp.underlying) match { case d: JointRefDenotation => typr.println(i"redirecting super.$name from $tp to ${d.symbol.showLocated}") new UniqueRefDenotation(d.symbol, tp.memberInfo(d.symbol), d.validFor) case d => d } + def goAnd(l: Type, r: Type) = { go(l) & (go(r), pre, safeIntersection = ctx.pendingMemberSearches.contains(name)) } From 1e34d2de47b1f0b19c3c1ec3137a3d9174f6d3aa Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 22 Mar 2018 15:45:53 +0100 Subject: [PATCH 2/2] Don't crash when taking the signature of NoType I noted this happening from tyoime to time in the IDE, and it is super annoying when it happens. Let's see if we can survive meaningfully after ignoring this condition. --- compiler/src/dotty/tools/dotc/core/TypeErasure.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 6eaaec1f8fc4..a4566e729b72 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -549,7 +549,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean if (inst.exists) sigName(inst) else tpnme.Uninstantiated case tp: TypeProxy => sigName(tp.underlying) - case _: ErrorType | WildcardType => + case _: ErrorType | WildcardType | NoType => tpnme.WILDCARD case tp: WildcardType => sigName(tp.optBounds)