Skip to content

Store GADT constraints until PostTyper #12258

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

Merged
merged 2 commits into from
Apr 29, 2021

Conversation

abgruszecki
Copy link
Contributor

In some cases, the attachment can get dropped. We have a lot of such cases. Most seem to happen for tuple patterns.

@odersky
Copy link
Contributor

odersky commented Apr 29, 2021

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

I am wary that this could give bad memory leaks. GADT constraints can be large.

Why do we need GADT constraints in PostTyper? The PR does not explain, nor does the code.

@abgruszecki
Copy link
Contributor Author

abgruszecki commented Apr 29, 2021

@odersky there's a serious problem - type application that needs GADT constraints simply doesn't work. #12226 is one example. Another one is that without this PR we get an error on this line: https://github.com/lampepfl/dotty/pull/12258/files#diff-953aaf705b431c6945ad2bd63ce89e017169f7373c45f9c40f265f4d11705a81R11.

The reason why type application doesn't work is that we check it in PostTyper, when we already forgot the GADT constraints. I tried moving the checks to Typer, but it seems like there's no clean way to do that, for instance b/c when we exit typedTypeApply, the type arguments may still be variables. So that means we should either re-infer the constraints in PostTyper, or store and extract them. Of those two solutions, storing the constraints is by far the cleanest and the most future-proof. EDIT: also, note that we actually remove the constraints in PostTyper.

If we ever get problems because of too many GADT constraints, we could simply infer less of them. It's always sound to infer less GADT constraints. IIRC, GHC also stores its GADT constraints, and won't record constraints past some threshold.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench2.epfl.ch/12258/ to see the changes.

Benchmarks is based on merging with master (2d2038e)

@odersky
Copy link
Contributor

odersky commented Apr 29, 2021

OK. I'd just add a comment explaining why we need to attach GADT constraints

@abgruszecki abgruszecki merged commit 9faabb6 into scala:master Apr 29, 2021
@abgruszecki abgruszecki deleted the fix-12226 branch April 29, 2021 16:54
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
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.

Pattern match over a parametrised ADT with type-constrained children no longer compiles
5 participants