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

Weak ephemerons #12251

Closed
Elarnon opened this issue May 21, 2023 · 2 comments
Closed

Weak ephemerons #12251

Elarnon opened this issue May 21, 2023 · 2 comments

Comments

@Elarnon
Copy link
Contributor

Elarnon commented May 21, 2023

In #10737, a new immutable API for ephemerons was introduced for the benefits of the multicore runtime. There, @kayceesrk advocated for the stronger requirement of a GC-oblivious API, because a GC-aware API could have surprising behaviors.

At the time, the PR mentioned that the runtime would only implement the Bucket module (which presumably would be GC-oblivious), but it looks like that is not the case and the low-level Obj.Ephemeron API has not changed. Moreover, the example provided by @kayceesrk to advocate for GC-obliviousness requires an incorrect ordering of set_key and set_data, which the immutable API prevents by not exposing these functions (and calling them in the correct order in make). I don't know if there are plans to separate the implementation of weak references and gc-oblivious ephemerons in the future.

Would the team be open to implementing a function weak_query : ('k, 'd) t -> ('k * 'd) option in Ephemeron.K1.t? Alternatively, to new modules Ephemeron.Weak.K1 etc. (with distinct types) where query has the signature above? If so, I am happy to write the corresponding PR.

For context, I have a program where I am storing an "undo trail" of reference writes to restore the old values later. I would like to avoid the undo trail forcing references to stay alive when they would otherwise be dead. I could use a pair 'a ref Weak.t * ('a ref, 'a) Ephemeron.K1.t, but since 'a ref Weak.t really is ('a ref, unit) Ephemeron.K1.t, it seems wasteful.

@lpw25
Copy link
Contributor

lpw25 commented May 22, 2023

I think the intention in the long run is still to implement the Bucket module directly in the runtime and implement Weak separately. I think we would like to maintain the GC-obliviousness of the Bucket module and the ephemeron interfaces built on top of it. So I think your: 'a ref Weak.t * ('a ref, 'a) Ephemeron.K1.t approach is the best one here.

@Elarnon
Copy link
Contributor Author

Elarnon commented Jun 3, 2023

OK, that is somewhat unfortunate but makes sense if there is still plans to split the implementations. Thanks for the clarification!

@Elarnon Elarnon closed this as completed Jun 3, 2023
@gasche gasche closed this as not planned Won't fix, can't repro, duplicate, stale Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants