Skip to content

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.

}
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


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.

}
}

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