-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 serialization of code instances. #46373
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -653,13 +653,15 @@ static int jl_serialize_generic(jl_serializer_state *s, jl_value_t *v) JL_GC_DIS | |
return 0; | ||
} | ||
|
||
static void jl_serialize_code_instance(jl_serializer_state *s, jl_code_instance_t *codeinst, int skip_partial_opaque, int internal) JL_GC_DISABLED | ||
static void jl_serialize_code_instance(jl_serializer_state *s, jl_code_instance_t *codeinst, | ||
int skip_partial_opaque, int internal, | ||
int force) JL_GC_DISABLED | ||
{ | ||
if (internal > 2) { | ||
while (codeinst && !codeinst->relocatability) | ||
codeinst = codeinst->next; | ||
} | ||
if (jl_serialize_generic(s, (jl_value_t*)codeinst)) { | ||
if (!force && jl_serialize_generic(s, (jl_value_t*)codeinst)) { | ||
return; | ||
} | ||
assert(codeinst != NULL); // handle by jl_serialize_generic, but this makes clang-sa happy | ||
|
@@ -680,7 +682,7 @@ static void jl_serialize_code_instance(jl_serializer_state *s, jl_code_instance_ | |
if (write_ret_type && codeinst->rettype_const && | ||
jl_typeis(codeinst->rettype_const, jl_partial_opaque_type)) { | ||
if (skip_partial_opaque) { | ||
jl_serialize_code_instance(s, codeinst->next, skip_partial_opaque, internal); | ||
jl_serialize_code_instance(s, codeinst->next, skip_partial_opaque, internal, 0); | ||
return; | ||
} | ||
else { | ||
|
@@ -707,7 +709,7 @@ static void jl_serialize_code_instance(jl_serializer_state *s, jl_code_instance_ | |
jl_serialize_value(s, jl_nothing); | ||
} | ||
write_uint8(s->s, codeinst->relocatability); | ||
jl_serialize_code_instance(s, codeinst->next, skip_partial_opaque, internal); | ||
jl_serialize_code_instance(s, codeinst->next, skip_partial_opaque, internal, 0); | ||
} | ||
|
||
enum METHOD_SERIALIZATION_MODE { | ||
|
@@ -968,10 +970,10 @@ static void jl_serialize_value_(jl_serializer_state *s, jl_value_t *v, int as_li | |
} | ||
jl_serialize_value(s, (jl_value_t*)backedges); | ||
jl_serialize_value(s, (jl_value_t*)NULL); //callbacks | ||
jl_serialize_code_instance(s, mi->cache, 1, internal); | ||
jl_serialize_code_instance(s, mi->cache, 1, internal, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if a MethodInstance is a code-object? Would you want to serialize the CodeInstances that it points to? If so...we might have to keep track at a higher level of how we got here: if by traversing a module, then don't force, but if we're caching code, then force. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not setting And this does indeed seem to work as expected. With your example above, I can successfully precompile the array of MIs and inspect the CI in the cache: module CodeInstancePrecompile
const some_mis = [first(methods(identity)).specializations[1]]
__init__() = @show some_mis[].cache
end
|
||
} | ||
else if (jl_is_code_instance(v)) { | ||
jl_serialize_code_instance(s, (jl_code_instance_t*)v, 0, 2); | ||
jl_serialize_code_instance(s, (jl_code_instance_t*)v, 0, 2, 1); | ||
} | ||
else if (jl_typeis(v, jl_module_type)) { | ||
jl_serialize_module(s, (jl_module_t*)v); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not pass
force
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just preserving how this function worked before. Presumably there was a reason that
jl_serialize_code_instance
didn't serialize CIs with backref entries on recursive calls tojl_serialize_code_instance
, so I'm just preserving that behavior. Instead, I'm only forcing the CIs to be serialized when I know that the backref table initialization doesn't mean that the object has been serialized, i.e., from thejl_is_code_instance
branch injl_serialize_value
.