From e0552267591eb0111bc0e5a678f83460e8149a24 Mon Sep 17 00:00:00 2001 From: Nick Roberts Date: Tue, 4 Jun 2024 11:41:32 -0400 Subject: [PATCH] flambda-backend: Add Assert_mixed_block_layout_v1 macro (#2647) * Add Assert_mixed_block_layout_v1 macro * Add note about hack * add macro for runtime 4 as well --- runtime/caml/mlvalues.h | 16 ++++++++++++++++ runtime4/caml/mlvalues.h | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/runtime/caml/mlvalues.h b/runtime/caml/mlvalues.h index d55f61738a2..4f265d583eb 100644 --- a/runtime/caml/mlvalues.h +++ b/runtime/caml/mlvalues.h @@ -540,6 +540,22 @@ CAMLextern value caml_atom(tag_t); CAMLextern value caml_set_oo_id(value obj); +/* Users write this to assert that the ensuing C code is sensitive + to the current layout of mixed blocks in a way that's subject + to change in future compiler releases. We'll bump the version + number when we make a breaking change. For example, we currently + don't pack int32's efficiently, and we will want to someday. + + Users can write: + + Assert_mixed_block_layout_v1; + + (Hack: we define using _Static_assert rather than just an empty + definition so that users can write a semicolon, which is treated + better by C formatters.) + */ +#define Assert_mixed_block_layout_v1 _Static_assert(1, "") + /* Header for out-of-heap blocks. */ #define Caml_out_of_heap_header_with_reserved(wosize, tag, reserved) \ diff --git a/runtime4/caml/mlvalues.h b/runtime4/caml/mlvalues.h index cf09e1aa078..a66fb60fc8b 100644 --- a/runtime4/caml/mlvalues.h +++ b/runtime4/caml/mlvalues.h @@ -521,6 +521,22 @@ extern value caml_global_data; CAMLextern value caml_set_oo_id(value obj); +/* Users write this to assert that the ensuing C code is sensitive + to the current layout of mixed blocks in a way that's subject + to change in future compiler releases. We'll bump the version + number when we make a breaking change. For example, we currently + don't pack int32's efficiently, and we will want to someday. + + Users can write: + + Assert_mixed_block_layout_v1; + + (Hack: we define using _Static_assert rather than just an empty + definition so that users can write a semicolon, which is treated + better by C formatters.) + */ +#define Assert_mixed_block_layout_v1 _Static_assert(1, "") + /* Header for out-of-heap blocks. */ #define Caml_out_of_heap_header(wosize, tag) \