Skip to content

Commit fd8dd19

Browse files
committed
ircode: handle content outside of a module
Specifically, content in an `__init__` block is handled by secret duplicate precompile logic, and any content generated by it was previously not eligible to be included into cache files. Fix #58449
1 parent 602d6ee commit fd8dd19

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

src/precompile.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ JL_DLLEXPORT void jl_write_compiler_output(void)
139139
}
140140
}
141141

142-
assert(jl_precompile_toplevel_module == NULL);
143142
void *native_code = NULL;
144143

145144
bool_t emit_native = jl_options.outputo || jl_options.outputbc || jl_options.outputunoptbc || jl_options.outputasm;

src/staticdata.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ static void jl_insert_into_serialization_queue(jl_serializer_state *s, jl_value_
907907
int is_relocatable = !s->incremental || jl_is_code_info(inferred) ||
908908
(jl_is_string(inferred) && jl_string_len(inferred) > 0 && jl_string_data(inferred)[jl_string_len(inferred) - 1]);
909909
if (!is_relocatable) {
910+
jl_(mi);
910911
inferred = jl_nothing;
911912
}
912913
else if (def->source == NULL) {
@@ -3419,9 +3420,6 @@ static void jl_save_system_image_to_stream(ios_t *f, jl_array_t *mod_array,
34193420

34203421
static void jl_write_header_for_incremental(ios_t *f, jl_array_t *worklist, jl_array_t *mod_array, jl_array_t **udeps, int64_t *srctextpos, int64_t *checksumpos)
34213422
{
3422-
assert(jl_precompile_toplevel_module == NULL);
3423-
jl_precompile_toplevel_module = (jl_module_t*)jl_array_ptr_ref(worklist, jl_array_len(worklist)-1);
3424-
34253423
*checksumpos = write_header(f, 0);
34263424
write_uint8(f, jl_cache_flags());
34273425
// write description of contents (name, uuid, buildid)
@@ -3479,9 +3477,7 @@ JL_DLLEXPORT void jl_create_system_image(void **_native_data, jl_array_t *workli
34793477
// Generate _native_data`
34803478
if (_native_data != NULL) {
34813479
jl_prepare_serialization_data(mod_array, newly_inferred, &extext_methods, &new_ext_cis, NULL, &query_cache);
3482-
jl_precompile_toplevel_module = (jl_module_t*)jl_array_ptr_ref(worklist, jl_array_len(worklist)-1);
34833480
*_native_data = jl_precompile_worklist(worklist, extext_methods, new_ext_cis);
3484-
jl_precompile_toplevel_module = NULL;
34853481
extext_methods = NULL;
34863482
new_ext_cis = NULL;
34873483
}
@@ -3528,7 +3524,6 @@ JL_DLLEXPORT void jl_create_system_image(void **_native_data, jl_array_t *workli
35283524
// Re-enable running julia code for postoutput hooks, atexit, etc.
35293525
jl_gc_enable_finalizers(ct, 1);
35303526
ct->reentrant_timing &= ~0b1000u;
3531-
jl_precompile_toplevel_module = NULL;
35323527

35333528
if (worklist) {
35343529
// Go back and update the checksum in the header

src/toplevel.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ htable_t jl_current_modules;
3434
jl_mutex_t jl_modules_mutex;
3535

3636
// During incremental compilation, the following gets set
37-
jl_module_t *jl_precompile_toplevel_module = NULL; // the toplevel module currently being defined
37+
jl_module_t *jl_precompile_toplevel_module = NULL; // the first toplevel module being defined
3838

3939
jl_module_t *jl_add_standard_imports(jl_module_t *m)
4040
{
@@ -172,7 +172,6 @@ static jl_value_t *jl_eval_module_expr(jl_module_t *parent_module, jl_expr_t *ex
172172
}
173173
}
174174

175-
jl_module_t *old_toplevel_module = jl_precompile_toplevel_module;
176175
size_t last_age = ct->world_age;
177176

178177
if (parent_module == jl_main_module && name == jl_symbol("Base") && jl_base_module == NULL) {
@@ -182,7 +181,7 @@ static jl_value_t *jl_eval_module_expr(jl_module_t *parent_module, jl_expr_t *ex
182181

183182
if (is_parent__toplevel__) {
184183
jl_register_root_module(newm);
185-
if (jl_options.incremental) {
184+
if (jl_options.incremental && jl_precompile_toplevel_module == NULL) {
186185
jl_precompile_toplevel_module = newm;
187186
}
188187
}
@@ -241,8 +240,6 @@ static jl_value_t *jl_eval_module_expr(jl_module_t *parent_module, jl_expr_t *ex
241240
}
242241
}
243242

244-
jl_precompile_toplevel_module = old_toplevel_module;
245-
246243
JL_GC_POP();
247244
return (jl_value_t*)newm;
248245
}

0 commit comments

Comments
 (0)