-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Value_rec_compiler: prevent duplication of values #13938
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
base: trunk
Are you sure you want to change the base?
Conversation
Note that this PR fixes both #13930 and #13931.
Here |
To avoid having two different values (the dummy allocation that gets updated later, and the actual allocation that eventually gets used to do the update), we move the call to caml_update_dummy to be immediately around the allocation primitive. The now initialised value is then used in the rest of the definition where the allocation would have been.
2a1378c
to
2284b42
Compare
Here is how I understand your proposal:
This is interesting. I see the following downsides:
|
That's not an issue: join points are forbidden (if you look at
Same reasoning: no join means there cannot be any ambiguity.
I think your concern is valid, so I would be in favour of adding the |
Is the fact that join points are forbidden an observation about the current state of what we handle, or something that is part of your internal specification for Value_rec_compiler and will remain true tomorrow? If we follow the route proposed by this PR, we are tying our hands in this respect. I don't have any desire to start accepting more recursive definitions, but I wonder if we could end up in a state where, for example, some join points would start being generated (for currently-accepted programs) in the Typedtree->Lambda translation. |
I explicitly chose to forbid join points when I implemented it, although at that time I did not rely on it.
It is something that I have thought a little about. To sum it up, I'm not too worried. The previous code (before |
My current thinking: I like that this PR improves behavior in some weird corner cases, the behavior when it works well is rather elegant. But I also wouldn't fully trust it to ensure soundness, because it is relying on subtle non-local assumptions. To guarantee soundness, I would rather start from #13933 (including the indirection which I'm very proud of) and then the orthogonal part of this PR that recognize the allocation primitives to fix #13931. Following this line of thinking, the question is whether we also want the present PR in addition, to fix surprising behaviors coming from the duplication of mutable state. I would be tempted to say yes. (The code is a bit complex, but conceptually the idea is clear, and I hope that we could make it pleasant.) |
I'm not very fond of your indirection, but I agree that we should first go with the simpler changes to fix the real bugs, and think about the rest of this PR as a medium-term goal, including producing more documentation and specifications for recursive value definitions. |
To avoid having two different values (the dummy allocation that gets updated later, and the actual allocation that eventually gets used to do the update), we move the call to
caml_update_dummy
to be immediately around the allocation primitive.The now initialised value is then used in the rest of the definition where the allocation would have been.
Copying my example from #13933:
Observing the difference:
(The fix to
primitive.mli
is an unrelated typo that I noticed while working on that)