Skip to content

Fix #3250: Make HKLambda a cached type #3287

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 3 commits into from
Oct 9, 2017
Merged
Changes from 1 commit
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
31 changes: 27 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2599,7 +2599,32 @@ object Types {
final override def toString = s"$prefixString($paramNames, $paramInfos, $resType)"
}

trait HKLambda extends LambdaType
abstract class HKLambda extends CachedProxyType with LambdaType {
final override def underlying(implicit ctx: Context) = resType

final override def computeHash = doHash(paramNames, resType, paramInfos)

final override def equals(that: Any) = that match {
case that: HKLambda =>
paramNames == that.paramNames &&
paramInfos == that.paramInfos &&
resType == that.resType &&
companion.eq(that.companion)
case _ =>
false
}

final override def eql(that: Type) = that match {
case that: HKLambda =>
paramNames.equals(that.paramNames) &&
paramInfos.equals(that.paramInfos) &&
resType.equals(that.resType) &&
Copy link
Member

Choose a reason for hiding this comment

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

That was already the case before #3239, but why is this equals and not eq?

Copy link
Contributor Author

@odersky odersky Oct 9, 2017

Choose a reason for hiding this comment

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

I am not even sure that equals is needed. But the idea is that, since many types get a compiler generated equals since they are case classes, the rest of the types would conform to that.

companion.eq(that.companion)
case _ =>
false
}
}

trait MethodOrPoly extends LambdaType with MethodicType

trait TermLambda extends LambdaType { thisLambdaType =>
Expand Down Expand Up @@ -2909,7 +2934,7 @@ object Types {
*/
class HKTypeLambda(val paramNames: List[TypeName])(
paramInfosExp: HKTypeLambda => List[TypeBounds], resultTypeExp: HKTypeLambda => Type)
extends UncachedProxyType with HKLambda with TypeLambda {
extends HKLambda with TypeLambda {
type This = HKTypeLambda
def companion = HKTypeLambda

Expand All @@ -2919,8 +2944,6 @@ object Types {
assert(resType.isInstanceOf[TermType], this)
assert(paramNames.nonEmpty)

final override def underlying(implicit ctx: Context) = resType

protected def prefixString = "HKTypeLambda"
}

Expand Down