Skip to content

Fix #4297: handle type param reference #4298

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
Apr 12, 2018

Conversation

liufengyun
Copy link
Contributor

Fix #4297: handle type param reference

case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] =>
val lo = this(tp.info.loBound)
val hi = this(tp.info.hiBound)
if (variance == 0) range(lo, hi)
Copy link
Member

Choose a reason for hiding this comment

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

The range method already does variance checks like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks 👍

@liufengyun
Copy link
Contributor Author

test performance with #fast please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/4298/ to see the changes.

Benchmarks is based on merging with master (7b91742)

def apply(tp: Type): Type = tp match {
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] =>
val lo = this(tp.info.loBound)
val hi = this(tp.info.hiBound)
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace this by apply? It makes it clearer that this is a recursive call

case tpe: AppliedType => isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState())
case tpe: AppliedType =>
isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState()) ||
isClassDetermined(stripTypeParam.apply(X), tpe)(ctx.fresh.setNewTyperState())
Copy link
Contributor

Choose a reason for hiding this comment

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

Call it as stripTypeParam(X) instead of stripTypeParam.apply(X)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems scalac has problem with this syntax, however, I've changed the method so we don't need to call apply anymore.

@@ -116,7 +130,9 @@ object Checkable {
case defn.ArrayOf(tpE) => recur(tpE, tpT)
case _ => recur(defn.AnyType, tpT)
}
case tpe: AppliedType => isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState())
case tpe: AppliedType =>
isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState()) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, you first try without stripping type parameters for performance reasons? Maybe add a comment

@@ -88,19 +88,33 @@ object Checkable {
}
}

def stripTypeParam(implicit ctx: Context) = new ApproximatingTypeMap {
def apply(tp: Type): Type = tp match {
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably equivalent to case tp: TypeRef if tp.symbol.isTypeParam. Maybe clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tp.symbol.isTypeParam doesn't cover the case of type members, so I think it's better to keep the original version here.

@@ -88,19 +88,33 @@ object Checkable {
}
}

def stripTypeParam(implicit ctx: Context) = new ApproximatingTypeMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment: /** Approximate type parameters depending on variance */

@allanrenucci allanrenucci merged commit 84bf2fa into scala:master Apr 12, 2018
@allanrenucci allanrenucci deleted the fix-4297 branch April 12, 2018 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants