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

enhance maintainability of jl_ir_ accessors #52167

Merged
merged 1 commit into from
Nov 16, 2023
Merged

Conversation

aviatesk
Copy link
Member

By allowing us to change data size at one place when we make a change to the layout of compressed IR.

@aviatesk aviatesk requested a review from Keno November 14, 2023 18:09
Copy link
Member

@Keno Keno left a comment

Choose a reason for hiding this comment

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

Yes, this is what I had in mind, plus some asserts in the serializer that asserts that the offset matches what is being written.

@aviatesk
Copy link
Member Author

plus some asserts in the serializer that asserts that the offset matches what is being written

Do you mean something like this?

diff --git a/src/ircode.c b/src/ircode.c
index 8516cf9817..fb322a37a9 100644
--- a/src/ircode.c
+++ b/src/ircode.c
@@ -825,12 +825,16 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code)
     jl_code_info_flags_t flags = code_info_flags(code->inferred, code->propagate_inbounds, code->has_fcall,
                                                  code->nospecializeinfer, code->inlining, code->constprop);
     write_uint8(s.s, flags.packed);
+    assert(sizeof(flags.packed) == ir_datasize_flags);
     write_uint8(s.s, code->purity.bits);
+    assert(sizeof(code->purity.bits) == ir_datasize_purity);
     write_uint16(s.s, code->inlining_cost);
+    assert(sizeof(code->inlining_cost) == ir_datasize_inlining_cost);
 
-    size_t nslots = jl_array_nrows(code->slotflags);
+    int32_t nslots = jl_array_nrows(code->slotflags);
     assert(nslots >= m->nargs && nslots < INT32_MAX); // required by generated functions
     write_int32(s.s, nslots);
+    assert(sizeof(nslots) == ir_datasize_nslots);
     ios_write(s.s, jl_array_data(code->slotflags, const char), nslots);
 
     // N.B.: The layout of everything before this point is explicitly referenced

@Keno
Copy link
Member

Keno commented Nov 15, 2023

Yes, although those could probably be static asserts, since they're constexpr, which would help even if you're not building in debug mode. The intention is for something to fail loudly if things get messed up.

@aviatesk
Copy link
Member Author

Hmm, it looks like they aren't constexprs in the CI setup? I couldn't reproduce it locally..

By allowing us to change data size at one place when we make a change
to the layout of compressed IR.
@aviatesk aviatesk merged commit 253cddc into master Nov 16, 2023
5 of 7 checks passed
@aviatesk aviatesk deleted the avi/ir_data_offset branch November 16, 2023 05:27
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