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

Fix the types of C primitives and remove some that are unused #12686

Merged
merged 9 commits into from
Oct 24, 2023

Conversation

xavierleroy
Copy link
Contributor

In preparation for a reboot of #11763 prompted by #12660, this PR makes sure that all functions declared CAMLprim have the correct types to be callable from the bytecode interpreter.

Some functions that are not callable from the bytecode interpreter are declared CAMLexport instead, or removed since they are no longer used. See the commit messages for more details.

@xavierleroy xavierleroy changed the title Remove unused primitives and rectify their types Fix the types of C primitives and remove some that are unused Oct 23, 2023
Copy link
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

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

Nice to see the end of the special case for the int64 primitives! One minor nit (possibly) in ints.c and some extra stuff may need to be done for the runtime_events primitives.

Is it possibly worth a one-line comment in the lexing and parsing changes to be explicit that the structs match the value representation, just because we don't do that elsewhere in the runtime (I think?)

runtime/ints.c Outdated Show resolved Hide resolved
@@ -418,15 +418,15 @@ static void stw_create_runtime_events(
caml_global_barrier();
}

CAMLprim value caml_runtime_events_start(void) {
CAMLprim value caml_runtime_events_start(value vunit) {
Copy link
Member

Choose a reason for hiding this comment

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

These three form part of the public API for runtime events, which is breaking one of the tests. Perhaps rename them to caml_ml_runtime_events_start (a la lots of the I/O primitives) and then either #define caml_runtime_events_start or an inline'd definition of caml_runtime_events_start?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it's a good idea to separate the C API functions caml_runtime_events_start and the primitive caml_ml_runtime_events_start. I went one step further and made the C functions void -> void instead of void -> value, as void -> void is the natural C type for these functions. Let me know what you think about that.

Copy link
Member

Choose a reason for hiding this comment

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

I was fairly sure I wouldn't need to suggest the change to change the return type to void, indeed 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm glad you thought of changing the return type to void!

…ause,resume}`

These are wrappers for `caml_runtime_events_{start,pause,resume}` but with
types appropriate for calling from the bytecode interpreter.
…imitives

They are part of the C API, but not callable from the bytecode interpreter.
Seize the opportunity to give them type `void f(void)` instead of
`value f(void)`.
Its type prevents it from being called from the bytecode interpreter.
…ions

They were introduced in ocaml#2146 to support unboxed 64-bit integer
operations on 32-bit platforms, something that is no longer needed in
OCaml 5 and was removed in ocaml#11904.
`caml_lex_engine`, `caml_new_lex_engine`, `caml_parse_engine` have strange
types with pointers to structs as parameters.  Give parameters
the type `value` and make explicit the casts from `value` to pointer to
struct of `value` in the function bodies.
@MisterDA
Copy link
Contributor

Thanks for the PR, sorry for the slip-up. It looks all good to me too.
Is it worth backporting the type fixes to 4.14 and 5.1?

Copy link
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

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

LGTM!

@dra27 dra27 merged commit b194587 into ocaml:trunk Oct 24, 2023
9 checks passed
@dra27
Copy link
Member

dra27 commented Oct 24, 2023

The fix to prims.h in 92e16dd could be cherry-picked to 4.14/5.1; I'm not sure the rest necessarily needs to be?

@xavierleroy
Copy link
Contributor Author

Thanks for the review and the merge. I don't think the wrong extern declarations for the arrays of primitives (without the const modifiers) can lead the C compiler to generate wrong code, at least until whole-program or link-time optimization is attempted, so I'd suggest not changing anything in 4.14 / 5.1 yet. Later, if we get LTO to work safely, we may want to back-port the changes (which will include but not be limited to this PR) to 4.14 as part of long-term support.

@xavierleroy xavierleroy deleted the primitive-cleanup branch October 24, 2023 16:28
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.

None yet

3 participants