From 89f02276f28847380d62e2021491127ed1ae091c Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 15 Oct 2020 12:36:16 -0400 Subject: [PATCH] allow eval into a submodule during incremental precompile (#38013) This was never intended to be disallowed, but got mixed up in a refactor. Fixes #37771 --- src/toplevel.c | 9 +++++++++ test/precompile.jl | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/toplevel.c b/src/toplevel.c index 5dfc3cf7eef23..ef5720a0d4f0e 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -895,6 +895,15 @@ static void jl_check_open_for(jl_module_t *m, const char* funcname) if (m != jl_main_module) { // TODO: this was grand-fathered in JL_LOCK(&jl_modules_mutex); int open = ptrhash_has(&jl_current_modules, (void*)m); + if (!open && jl_module_init_order != NULL) { + size_t i, l = jl_array_len(jl_module_init_order); + for (i = 0; i < l; i++) { + if (m == (jl_module_t*)jl_array_ptr_ref(jl_module_init_order, i)) { + open = 1; + break; + } + } + } JL_UNLOCK(&jl_modules_mutex); if (!open && !jl_is__toplevel__mod(m)) { const char* name = jl_symbol_name(m->name); diff --git a/test/precompile.jl b/test/precompile.jl index 3b7ee5d6b1947..a16c6c6123c8e 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -67,9 +67,10 @@ try include_dependency("foo.jl") include_dependency("foo.jl") module Bar - @doc "bar function" bar(x) = x + 2 include_dependency("bar.jl") end + @doc "Bar module" Bar # this needs to define the META dictionary via eval + @eval Bar @doc "bar function" bar(x) = x + 2 # test for creation of some reasonably complicated type struct MyType{T} end @@ -262,6 +263,7 @@ try # issue #12284: @test string(Base.Docs.doc(Foo.foo)) == "foo function\n" @test string(Base.Docs.doc(Foo.Bar.bar)) == "bar function\n" + @test string(Base.Docs.doc(Foo.Bar)) == "Bar module\n" modules, (deps, requires), required_modules = Base.parse_cache_header(cachefile) discard_module = mod_fl_mt -> (mod_fl_mt.filename, mod_fl_mt.mtime)