-
Notifications
You must be signed in to change notification settings - Fork 33
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
(Camlinternal)Uniform_array
: minimal support for uniform arrays
#37
base: master
Are you sure you want to change the base?
Conversation
I'd suggest to look into type item = DummyA | DummyB | DummyC of int
let _ = [DummyA; DummyB; DummyC 0] (* to avoid warnings *)
let dummy_item = (Obj.magic () : item) Why not just |
Thanks for the pointer. From looking at it briefly, I cannot tell whether I would recommend trying to use explicit uniform arrays for this purpose. The "methods" array seems to be a bytecode array with a mix of methods and arguments (so indeed uniform arrays would be a good choice here). The
Git suggests that this is a historic artifact, before those constructors were introduced (What I cannot tell is what |
Coming back to the proposal: I don't see the point on insisting on a particular tag: |
Currently translprim.ml has:
I would propose to add just 5 extra lines of code:
Yes, this is the idea. My idea would be to specialize primitives to carve out less-smart versions, so the amount of new code should be very small in any case.
For now I am not really interested in extending the proposal to explicitly cover non-standard tag choices, which sound a bit dubious to me. If the implementation naturally allows them I will look the other way. |
I don't think you need them. On all platforms for which we support the native compiler, But I guess that shows the difference in how we see this: you seem to want a full-fledged data structure with compiler support, I just want a decent way to manipulate dynamically sized blocks full of values. |
This looks very useful to have to increase legibility and safety in the important use cases you mention. I can also imagine cases when I’d want to enforce absence of allocation in some hot paths. |
Coq/Rocq also includes a small module of uniform arrays in its codebase, as part of the definition of its "persistent arrays": https://github.com/coq/coq/blob/d7d392191a367839b0f5a7772e48b8f24e9f1b3e/kernel/parray.ml . My understanding is that the need for uniformity arises from the compilation scheme of |
This RFC proposes to add minimal support in the OCaml implementation for uniform arrays, which always use the standard
Array_tag
representation and neverDouble_array_tag
.The compiler would offer specialized built-in and C primitives to work with uniform arrays, and a minimal
CamlinternalUniform_array
module in the standard library exposing these primitives.This would make it easier to write some unsafe idioms that enforce uniform arrays in more complex ways today, simplifying the code of
Domain.DLS
, the unboxed implementation ofDynarray
, and theUniform_array
module of Jane Street's Base library and making it easier to reason about their correctness.Full version, rendered.