Skip to content

Optimize findRef #4156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

@Blaisorblade Blaisorblade Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code match twice against WildcardType? I don't get it. In fact, the latter matches appear to be erased away:

scala> def foo: Any => Any = { case _: String | Int => 1; case _: Int => 2 }
def foo: Any => Any
scala> foo(1)
val res0: Any = 2
scala> def foo: Any => Any = { case _: String | AnyRef => 1; case _: AnyRef => 2 }
def foo: Any => Any
scala> foo(new AnyRef())
val res1: Any = 2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It first matches against the object WildcardType, then the case below matches against any instance of the class WildcardType.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sorry, Allan explained me what's going on. But do we really know that the only instance of WildcardType(NoType) is the WildcardType object?

Expand Down
31 changes: 19 additions & 12 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray comment?

goThis(tp)
case tp: RefinedType =>
if (name eq tp.refinedName) goRefined(tp) else go(tp.parent)
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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))
}
Expand Down