-
Notifications
You must be signed in to change notification settings - Fork 68
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
Simplify lazy semantics #760
Conversation
* Mark lazy as not concurrency (domains, systhreads, fibers) safe. * Remove RacyLazy exception. Any concurrent use of lazy value may raise Undefined exception. * Remove domain-local id to distinguish concurrent and recursive forcing. * Remove try_force. The commit also fixes a bug to prevent short-circuiting forcing_tag values. We need to bootstrap to remove references to `RacyLazy` from the bootstrap binaries. After bootstrap, the primitive `caml_ml_domain_unique_token` should be removed from the runtime.
fbbb013
to
e380936
Compare
@gasche would appreciate your review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the ping! (I don't get notifications for ocaml-multicore/)
The change looks correct to me. It does simplify the implementation.
The documentation is changed so that Lazy.force is "unspecified" (but safe) in the case of concurrent forcing. I think we could be more precise, and will try to make some proposals.
The PR comes with some changes in the testsuite, some for backward-compatibility, some (dividing iteration counts by 10 or removing some cpu_relax()
call) that seem to come from performance considerations, I'm not sure which/why.
... after thinking more about it, I think that the current non-documentation of concurrent-forcing behavior is okay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have more questions about this code now that I understand it better. Some comments are not about behaviour introduced by this PR, feel free to address them later/separately.
Import trunk changes for flambda Co-authored-by: Guillaume Munch-Maccagnoni <Guillaume.Munch-Maccagnoni@Inria.fr>
The failures are due to line number differences in the backtrace tests. I've already fixed these twice in this PR :-| I'll wait until the review on the changes reaches a fixed point, and then I shall fix the failing tests. |
My high-level impression is that we should try to merge a "good first part" version of this PR, that simplifies the current implementation and does not introduce any new bugs, and then have a separate, second discussion about how to safely read concurrently-modified tags. (I suspect we may not be out of surprises there: many other parts of the runtime read tags, how safe are they with respect to concurrent mutation?) |
To continue on my previous line of thought: I think we could cut the current PR to the commit before "Add new primitive to atomically read tag", and get this merged right away, and then have a dedicated discussion on the memory-safety to make sure that we properly address the issue. (@kayceesrk : just checking that you know about |
I think we're there right after changing |
What about the lazy-tag checks in other parts of the runtime?
|
Why? Worst case you get the wrong result (which is fine), but do you get a crash? |
I think you are correct: we can get garbage in this case, but no crash, because the block arguments of a lazy value remains well-formed at any point. (With the new policy, specified in the current PR, that lazy values are not thread-safe, this is fine. Previously we tried to make them shareable, as long as only there is no racy force.) |
66b4cff
to
8d1fc7c
Compare
Based on the recommendations, I have
I did not know this. Thanks for pointing this out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I would just add a comment (below).
(Note: my inline_lazy_switch suggestion requires massaging from the matching+backend people; if we merge as-is, as I think is reasonable, I will open an issue to track this.) |
Or that could be used as an incentive to explore an implementation that does not mutate tags! |
Will merge when the CI turns green. Thanks @gasche, @gadmm and @xavierleroy. |
…ticore/lazy_simplify Simplify lazy semantics
…ticore/lazy_simplify Simplify lazy semantics
Simplify lazy and fix a bug based on discussions from #749 and #750.
The commit also fixes a bug to prevent short-circuiting forcing_tag values.
We need to bootstrap to remove references to
RacyLazy
from the bootstrap binaries. After bootstrap, the primitivecaml_ml_domain_unique_token
should be removed from the runtime.