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

Gadt unification #5611

Merged
merged 8 commits into from
Dec 17, 2018
Merged

Gadt unification #5611

merged 8 commits into from
Dec 17, 2018

Conversation

abgruszecki
Copy link
Contributor

@abgruszecki abgruszecki commented Dec 14, 2018

Cleaned up version of #5258.

Copying over relevant information:

This fixes all of the below:

For the time being, we mishandle injectivity and so we are unsound. See tests/run/gadt-injectivity-unsoundness.scala for a test showing a class cast exception. We will need to create an issue for this.

756cd0a was reverted because it was making the tests fail, and reverting it caused no test failures. I might bring it back later when working on injectivity.

At first glance, it might make sense to merge GADTMap state with TyperState. However, it's not necessary (since it's possible to just keep a fresh copy of GADTMap as the "state") and it's not entirely obvious how to adapt already existing code. See #5258 (comment) for detailed reasoning. For the time being, I think it'd be best to leave the state where it is and refactor later if handling the GADT state becomes problematic.

if ((tycon2bounds.lo `eq` tycon2bounds.hi) && !tycon2bounds.isInstanceOf[MatchAlias])
if (followSuperType) recur(tp1, tp2.superType)
Copy link
Contributor

Choose a reason for hiding this comment

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

It reverted commit fills a hole in the subtype checker. What tests failed before we reverted it? It would be good to find a root cause for the failure.

Copy link
Contributor Author

@abgruszecki abgruszecki Dec 17, 2018

Choose a reason for hiding this comment

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

TypeSafeLambda failed. Since this PR anyway leaves GADTs using HKTs unsound, I wanted to focus first on solving #5630, and then to come back to this problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, agreed. Maybe make an issue so that it is not forgotten?

compiler/src/dotty/tools/dotc/core/Contexts.scala Outdated Show resolved Hide resolved
compiler/src/dotty/tools/dotc/core/Contexts.scala Outdated Show resolved Hide resolved
case tv: TypeVar => tv
case inst =>
gadts.println(i"instantiated: $sym -> $inst")
// this is wrong in general, but "correct" due to a subtype check in TypeComparer#narrowGadtBounds
Copy link
Contributor

Choose a reason for hiding this comment

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

More explanations needed.

Copy link
Contributor Author

@abgruszecki abgruszecki Dec 17, 2018

Choose a reason for hiding this comment

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

Fixed by inlining the code from TypeComparer#narrowGADTBounds. Inlining it did not work previously, but whatever code was causing that must've changed along the way.

compiler/src/dotty/tools/dotc/core/Contexts.scala Outdated Show resolved Hide resolved
compiler/src/dotty/tools/dotc/core/TypeComparer.scala Outdated Show resolved Hide resolved
compiler/src/dotty/tools/dotc/core/TypeComparer.scala Outdated Show resolved Hide resolved
compiler/src/dotty/tools/dotc/typer/Inferencing.scala Outdated Show resolved Hide resolved
@odersky
Copy link
Contributor

odersky commented Dec 14, 2018

Overall this looks good. I have only minor comments.

@odersky odersky assigned abgruszecki and unassigned odersky Dec 14, 2018
@abgruszecki abgruszecki assigned odersky and unassigned abgruszecki Dec 17, 2018
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.

3 participants