Skip to content

Take HKT injectivity into account when inferring constraints #6461

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

Closed
wants to merge 16 commits into from

Conversation

abgruszecki
Copy link
Contributor

Based on top of #5736.

Fixes #5658.

I'd happily like to note that this works unreasonably well, given the size of the change - we can even see through aliases with no extra effort whatsoever.

abgruszecki added 15 commits May 3, 2019 16:46
If we do not insert TypeVars into the bounds every time, then the only
time we need to remove them is when taking the full bounds of some type.

Since that logic now resides in ConstraintHandling and replaces all
TypeParamRefs internal to SmartGADTMap, we have no need to perform
expensive type traversals.

This removes the only reason for caching bounds.

The addition of HK parameter variance adaptation was necessary to make
tests/pos/i6014-gadt.scala pass.
gadtSyms/gadtContext became redundant, so they were removed.

The logic in typedDefDef was adjusted to only create a fresh context
when necessary.
The rationale for using a Skolem here is: we want to record that there
is at least one value that is both of the pattern type and the scrutinee
type.

All symbols are now considered valid for adding GADT constraints -
the rationale is that set of constrainable symbols should be either
selected on a per-(sub)pattern basis, or be the same for all matches.
Previously, symbols which were only appearing variantly in a scrutinee
type could be considered constrainable anyway because of an outer
pattern match.
Also rename the classes to better reflect their role,
and document and reorder definitions to make more sense.
The added symbols can have inter-dependencies in their bounds.
constrainPatternType is specific to term patterns, whereas in match
types there is a simple subtyping relationship between the pattern and
the scrutinee.

In the future, simply calling isSubType in GADTFlexible context would
likely be sufficient.
@abgruszecki abgruszecki changed the title Gadt injectivity Take HKT injectivity into account when inferring constraints May 6, 2019
@abgruszecki abgruszecki self-assigned this May 6, 2019
@abgruszecki
Copy link
Contributor Author

Integrated into #6398.

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.

Unsoundness due to GADT bounds ignoring type (un)injectivity
1 participant