-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Simplif.simplify_lets generates incorrect code if fed its own output #9954
Comments
This indeed seems concerning to me, I would expect simplifications to be applicable at any point (potentially several times). At least it should be documented, and it would be nice to fix it. |
I'll probably propose some changes to the representation of mutable variables in lambda at some point, which would include a fix for this, but that may not happen soon. I can review related PRs by other people though. |
Used in replacement of Variable attribute of Llet
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc. |
If I understand correctly, this bug has been fixed by #10090. |
* added new lambda construct Lmutvar (ocaml#9954) * added new construct Lmutlet and removed Variable attribute * refactorized Llet and Lmutlet printing * Simplified some computations for mutable variable cases * Fixed an overlooked transformation to Lmutvar and added cautionnary comment * Fixups for backported PR (mostly in translcomprehension) Co-authored-by: Keryan Didier <keryan.didier@ocamlpro.com>
This is not a real bug, and more a lack of documentation and checks, but
Simplif.simplify_lets
will generate incorrect code on some seemingly correct lambda inputs. In particular, running the function on its own output can result in incorrect code being produced.I've found two examples so far (sample ml programs and their lambda output after an extra round of
simplify_lets
).Example 1:
compiles to:
The cause is this optimisation, which replaces
let x = y in expr
byexpr[x <- y]
even forVariable
bindings.Example 2:
compiles to:
which breaks the invariant that variables bound to a
Variable
let must not occur in nested function bodies (they can't be passed in the function's closure like regular variables, in general).This was discovered while trying to force a different type for mutable variables in the lambda representation (and dedicated
Llet
andLvar
variants). I wasn't sure how to patchsimplify_lets
in these cases, and it turns out the current code is wrong for those cases where there are already someVariable
bindings. Fortunately this cannot occur with the current code paths, as the only place whereVariable
bindings are generated is insimplify_lets
itself, and the function doesn't call itself recursively on the result.I'd still like to know if other maintainers are bothered by this behaviour and want to discuss how to fix it, or if it's just how it works and it's not worth spending too much time on it.
The text was updated successfully, but these errors were encountered: