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

Portabilize Stdlib #3393

Open
wants to merge 46 commits into
base: stable_val_modalities
Choose a base branch
from

Conversation

tdelvecchio-jsc
Copy link
Contributor

@tdelvecchio-jsc tdelvecchio-jsc commented Dec 18, 2024

This PR updates stdlib in three main ways:

  1. Annotates functions as portable when possible.
  2. Marks various functions that, without mode annotations, are unsafe with [@alert unsafe_multidomain "Use [...]."].
  3. Creates Safe submodules when necessary to redefine unsafe functions from (2) with necessary mode annotations.

One place in particular that needed some work is Domain, which needed a rework of the DLS module to fit more in line with the capsule model.

Portable versions of functors in Set, Map, Hashtbl, and Ephemeron are also created, which take portable input modules and produce portable output modules.

Tests are updated to disable the "unsafe_multidomain" alert rather than moving tests to the new "safe" versions.

This PR currently depends on #3391 and #3424 .

Changes should be reviewed as a whole, not by commit.

@tdelvecchio-jsc tdelvecchio-jsc force-pushed the tdelvecchio-portablize-stdlib branch from 569c742 to 8096435 Compare December 18, 2024 22:25
@tdelvecchio-jsc tdelvecchio-jsc force-pushed the tdelvecchio-portablize-stdlib branch from ce744e4 to b14c2da Compare January 2, 2025 16:57
[@@alert unsynchronized_access
"GC parameters are a mutable global state."
]
(** Return the current values of the GC parameters in a [control] record. *)

external set : control -> unit = "caml_gc_set"
external set : control -> unit @@ nonportable = "caml_gc_set"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be alerted?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we can remove the alert now. Feel free to do it here or in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant should these be alerted as [@@alert unsafe_multidomain]? They are unsafe w.r.t. portability/contention, but there's no "safe" version that's easily writable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it unsafe if annotated with nonportable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing discussion in Slack, but basically these functions use atomic_load_relaxed/atomic_store_relaxed, which I think are unsafe in general without some kind of fencing (though I really don't understand this stuff well).

Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
@tdelvecchio-jsc tdelvecchio-jsc force-pushed the tdelvecchio-portablize-stdlib branch from 0b26357 to 529cbf5 Compare January 3, 2025 18:06
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
Signed-off-by: Thomas Del Vecchio <[email protected]>
@tdelvecchio-jsc tdelvecchio-jsc marked this pull request as ready for review January 3, 2025 20:25
glittershark and others added 3 commits January 3, 2025 15:56
Replace the [@@unsafe_allow_any_kind_in_{impl,intf}] attributes with a new
[@@unsafe_allow_any_mode_crossing] attribute. This is different in that it:

1. Works on the type declaration, not the inclusion check, so is more powerful -
   it can be used to illegally mode cross types defined in the same module, or
   illegally mode cross non-abstract types in interfaces. The latter especially
   is necessary to fully subsume -allow-illegal-crossing in stdlib
2. Only allows changing the modal bounds of a kind, not the layout - it's
   unclear that anyone should ever want to unsafely change the layout of a kind;
   I personally can't think of any sound reason to do so.

Some [past discussion][0] on the specific syntax for this attribute suggested
specifying the bounds directly on the attribute, rather than using the jkind
annotation, but I and others feel reasonably strongly that this way of doing
things is a better design for the sake of consistency.

[0]: #3385 (comment)
Signed-off-by: Thomas Del Vecchio <[email protected]>
@dkalinichenko-js
Copy link
Contributor

Does the tree build with this PR?

@dkalinichenko-js
Copy link
Contributor

Could you move the unsafe_allow_any_mode_crossing change into a separate PR that we can merge first?

@@ -28,6 +30,8 @@ type raw_data = nativeint (* @since 4.12 *)
external repr : 'a -> t = "%obj_magic"
external obj : t -> 'a = "%obj_magic"
external magic : 'a -> 'b = "%obj_magic"
external magic_portable : 'a -> 'a @ portable = "%identity"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those should have alerts, even if Obj.magic does not have one.

@dkalinichenko-js dkalinichenko-js changed the base branch from main to stable_val_modalities January 6, 2025 17:27
@tdelvecchio-jsc
Copy link
Contributor Author

Could you move the unsafe_allow_any_mode_crossing change into a separate PR that we can merge first?

This commit comes from #3424 . Updated PR description to mention this.

@tdelvecchio-jsc
Copy link
Contributor Author

Does the tree build with this PR?

Working on it, but not yet; there's a few bugs I'm working with @riaqn on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants