Skip to content
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

Refine GADT casts on singletons #11987

Closed
wants to merge 2 commits into from
Closed

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 5, 2021

  • keep the singleton type in the cast target
  • assert cast target stability if original was stable
  • fix isStable test for TypeParamRefs
  • double check if GADT logic is really needed before inserting a cast

Fixes #11220
Fixes #11955

odersky added 2 commits April 4, 2021 22:29
 - keep the singleton type in the cast target
 - assert cast target stability if original was stable
 - fix isStable test for TypeParamRefs
 - double check if GADT logic is really needed before inserting a cast

Fixes scala#11220
Fixes scala#11955
case CompareResult.OKwithGADTUsed if pt.isValueType =>
case CompareResult.OKwithGADTUsed
if pt.isValueType
&& !inContext(ctx.fresh.setGadt(EmptyGadtConstraint)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abgruszecki Not sure this is the right criterion. We need a way to make sure that the tree type conforms to the expected type without taking GADT constraints into account.

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's the intention, then this check makes perfect sense.

Copy link
Contributor

@abgruszecki abgruszecki left a comment

Choose a reason for hiding this comment

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

Mostly everything LGTM. I tried to remove the code for adding the Stable annotation here (#12015) and it seems like no test failed. Could it be that some test wasn't committed?

case CompareResult.OKwithGADTUsed if pt.isValueType =>
case CompareResult.OKwithGADTUsed
if pt.isValueType
&& !inContext(ctx.fresh.setGadt(EmptyGadtConstraint)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If that's the intention, then this check makes perfect sense.

&& !inContext(ctx.fresh.setGadt(EmptyGadtConstraint)) {
(tree.tpe.widenExpr frozen_<:< pt)
// we overshot; a cast is not needed, after all. (this happens a lot. We should
// find out whether we can make GADTused more precise)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems strange that we'd overshoot often. Could it be that this line is a culprit? It should be debuggable reasonably easily, by printing type comparison traces for the subtype check with and without GADT constraints, right at this code line. I'll take a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"this" gives me a 404 😸

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's a possible source since we do GADT reasoning before falling back to fourthTry. I tried to swap the order of the two clauses but that gives inference errors.

@odersky
Copy link
Contributor Author

odersky commented Apr 7, 2021

Mostly everything LGTM. I tried to remove the code for adding the Stable annotation here (#12015) and it seems like no test failed. Could it be that some test wasn't committed?

i11995.scala failed before I added the refinement to re-check whether a GADT cast was needed. I think it should be possible to come up with a test that exercises i11955 with a GADT cast.

@abgruszecki
Copy link
Contributor

I think we should come up with a test like that, otherwise we risk regressing.

@odersky
Copy link
Contributor Author

odersky commented Apr 9, 2021

I think we should come up with a test like that, otherwise we risk regressing.

OK, I leave that to you.

@abgruszecki
Copy link
Contributor

OK, I pushed some changes but GH doesn't want to cooperate. I'll reopen the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants