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

Revisit widening of nesting level of type variables #15884

Closed
odersky opened this issue Aug 19, 2022 · 0 comments · Fixed by #15746
Closed

Revisit widening of nesting level of type variables #15884

odersky opened this issue Aug 19, 2022 · 0 comments · Fixed by #15746

Comments

@odersky
Copy link
Contributor

odersky commented Aug 19, 2022

Compiler Version

3.2.1.-RC1

Issue

When instantiating type variables in #15746, any type variable B in the instance type of a type variable A that is nested deeper than the current context needs to be instantiated itself. If B occurs invariantly in the instance type of A this is awkward since instantiating type variables to one of their bounds loses possibilities. So we do not instantiate B and lower the nesting level of B to the nesting level of the current context instead. The problem is that this trick does not play well with the backtracking of typerstates. As stated in the comment of class NeedsLeveling in ConstraintHandling:

            // TODO: This widening is a side effect that is not undone if a typer state is aborted
            // I don't think it's a soundness problem, since all that could happen is that
            // the type variable causes earlier instantiations of other type variables
            // down the line. But it could produce a hard-to-debug side effect that leads
            // to worse types than expected. We should find a more robust way to do this.
            // Maybe instantiating `tp` to another freshly created type at nesting level?

We should act on the TODO and find a better way to treat invariantly occurring nested type variables.

@odersky odersky added the stat:needs triage Every issue needs to have an "area" and "itype" label label Aug 19, 2022
@odersky odersky added itype:enhancement and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 20, 2022
@odersky odersky linked a pull request Aug 20, 2022 that will close this issue
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants