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

Fix freshening substitutions #284

Merged
merged 1 commit into from
Sep 24, 2021
Merged

Conversation

lpw25
Copy link
Collaborator

@lpw25 lpw25 commented Sep 22, 2021

This fixes an issue where freshening substitutions might be applied to module types that had already been freshened. In the case of an identifier collision this produced the wrong result. This bug has probably been around for a long time (maybe since module aliases were added) but we only happened to see an actual collision recently.

@stedolan
Copy link
Contributor

For the record: while this looks like (and is) a straightforward refactoring, the actual bug fix is in Env.scrape_alias: the old code sometimes returned a signature without the freshening substitution applied and sometimes with.

The result of scrape_alias was later freshened, which meant that it could be freshened twice. If the freshened IDs happened to collide with distinct unfreshened identifiers that happened to have the same name then the signature gets corrupted (due to the amount of "happened to" needed to trigger this, the bug was rarely hit). The fix here is to ensure everything is always freshened immediately, using the new Subst.Lazy module to do so efficiently.

@stedolan
Copy link
Contributor

@lpw25: Could you propose this change upstream as well?

Also, the CI failure on principality-and-gadts is almost certainly ocaml/ocaml#10638, so it might be worth porting that patch too.

@poechsel
Copy link
Contributor

Here's a commit fixing the tests:
poechsel@6fba25b

@lpw25
Copy link
Collaborator Author

lpw25 commented Sep 22, 2021

Submitted upstream here: ocaml/ocaml#10659 stealing some of your comment for the PR description.

@lpw25 lpw25 merged commit cf35cf1 into ocaml-flambda:release-4.12 Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants