Skip to content

Commit 9e9e8df

Browse files
authored
don't save implicit imports into Main (JuliaLang#35415)
fix `eval` and `include` for userimg.jl
1 parent 0e96f04 commit 9e9e8df

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

base/sysimg.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,24 @@ empty!(LOAD_PATH)
8282
@eval Base creating_sysimg = false
8383
Base.init_load_path() # want to be able to find external packages in userimg.jl
8484

85-
let
86-
tot_time_userimg = @elapsed (Base.isfile("userimg.jl") && Base.include(Main, "userimg.jl"))
85+
# Set up Main module
86+
import Base.MainInclude: eval, include
8787

88+
Base.@eval Base let
89+
ccall(:jl_clear_implicit_imports, Cvoid, (Any,), Main)
90+
tot_time_userimg = @elapsed (isfile("userimg.jl") && include(Main, "userimg.jl"))
8891

89-
tot_time_base = (Base.end_base_include - Base.start_base_include) * 10.0^(-9)
90-
tot_time = tot_time_base + Base.tot_time_stdlib[] + tot_time_userimg
92+
tot_time_base = (end_base_include - start_base_include) * 10.0^(-9)
93+
tot_time = tot_time_base + tot_time_stdlib[] + tot_time_userimg
9194

92-
println("Sysimage built. Summary:")
93-
print("Total ─────── "); Base.time_print(tot_time * 10^9); print(" \n");
94-
print("Base: ─────── "); Base.time_print(tot_time_base * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (tot_time_base / tot_time) * 100); println("%")
95-
print("Stdlibs: ──── "); Base.time_print(Base.tot_time_stdlib[] * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (Base.tot_time_stdlib[] / tot_time) * 100); println("%")
96-
if isfile("userimg.jl")
97-
print("Userimg: ──── "); Base.time_print(tot_time_userimg * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (tot_time_userimg / tot_time) * 100); println("%")
98-
end
95+
println("Sysimage built. Summary:")
96+
print("Total ─────── "); time_print(tot_time * 10^9); print(" \n");
97+
print("Base: ─────── "); time_print(tot_time_base * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (tot_time_base / tot_time) * 100); println("%")
98+
print("Stdlibs: ──── "); time_print(tot_time_stdlib[] * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (tot_time_stdlib[] / tot_time) * 100); println("%")
99+
if isfile("userimg.jl")
100+
print("Userimg: ──── "); time_print(tot_time_userimg * 10^9); print(" "); show(IOContext(stdout, :compact=>true), (tot_time_userimg / tot_time) * 100); println("%")
101+
end
99102
end
100103

101-
empty!(LOAD_PATH)
102-
empty!(DEPOT_PATH)
103-
104-
# Set up Main module
105-
import Base.MainInclude: eval, include
104+
Base.empty!(LOAD_PATH)
105+
Base.empty!(DEPOT_PATH)

src/module.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,25 @@ int jl_is_submodule(jl_module_t *child, jl_module_t *parent) JL_NOTSAFEPOINT
784784
}
785785
}
786786

787+
// Remove implicitly imported identifiers, effectively resetting all the binding
788+
// resolution decisions for a module. This is dangerous, and should only be
789+
// done for modules that are essentially empty anyway. The only use case for this
790+
// is to leave `Main` as empty as possible in the default system image.
791+
JL_DLLEXPORT void jl_clear_implicit_imports(jl_module_t *m)
792+
{
793+
size_t i;
794+
JL_LOCK(&m->lock);
795+
void **table = m->bindings.table;
796+
for (i = 1; i < m->bindings.size; i+=2) {
797+
if (table[i] != HT_NOTFOUND) {
798+
jl_binding_t *b = (jl_binding_t*)table[i];
799+
if (b->owner != m && !b->imported)
800+
table[i] = HT_NOTFOUND;
801+
}
802+
}
803+
JL_UNLOCK(&m->lock);
804+
}
805+
787806
#ifdef __cplusplus
788807
}
789808
#endif

0 commit comments

Comments
 (0)