From 059abfea4f58d8603f530ca31d6db6bf61e7b4c9 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 6 Jan 2024 13:56:58 -0600 Subject: [PATCH 1/3] Preserve :toplevel in parsing This prepares for a JuliaInterpreter change directed at #718. --- src/parsing.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parsing.jl b/src/parsing.jl index 7821a4f0..313bdf1b 100644 --- a/src/parsing.jl +++ b/src/parsing.jl @@ -72,7 +72,7 @@ function process_source!(mod_exprs_sigs::ModuleExprsSigs, ex, filename, mod::Mod if isa(a, LineNumberNode) lnn = a else - pushex!(exprs_sigs, Expr(:block, lnn, a)) + pushex!(exprs_sigs, Expr(:toplevel, lnn, a)) end end else From b1181ce39ecf3a6d498c4c238e8d58660bd19b3d Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 6 Jan 2024 13:57:56 -0600 Subject: [PATCH 2/3] Add a test for #718 --- test/runtests.jl | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 3f743209..8af44542 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1635,6 +1635,45 @@ const issue639report = [] pop!(LOAD_PATH) end + do_test("Submodule in same file (#718)") && @testset "Submodule in same file (#718)" begin + testdir = newtestdir() + dn = joinpath(testdir, "TestPkg718", "src") + mkpath(dn) + write(joinpath(dn, "TestPkg718.jl"), """ + module TestPkg718 + + module TestModule718 + export _VARIABLE_UNASSIGNED + global _VARIABLE_UNASSIGNED = -84.0 + end + + using .TestModule718 + + end + """) + sleep(mtimedelay) + @eval using TestPkg718 + sleep(mtimedelay) + @test TestPkg718._VARIABLE_UNASSIGNED == -84.0 + write(joinpath(dn, "TestPkg718.jl"), """ + module TestPkg718 + + module TestModule718 + export _VARIABLE_UNASSIGNED + global _VARIABLE_UNASSIGNED = -83.0 + end + + using .TestModule718 + + end + """) + yry() + @test TestPkg718._VARIABLE_UNASSIGNED == -83.0 + + rm_precompile("TestPkg718") + pop!(LOAD_PATH) + end + do_test("Timing (issue #341)") && @testset "Timing (issue #341)" begin testdir = newtestdir() dn = joinpath(testdir, "Timing", "src") From 815209e3fe4acbe4cd52d16c9eb2e8d607f21240 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 6 Jan 2024 13:11:09 -0600 Subject: [PATCH 3/3] Add a nospecialize --- src/lowered.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lowered.jl b/src/lowered.jl index d47fa7f9..799c3989 100644 --- a/src/lowered.jl +++ b/src/lowered.jl @@ -62,7 +62,7 @@ function categorize_stmt(@nospecialize(stmt)) return ismeth, haseval, isinclude, isnamespace, istoplevel end # Check for thunks that define functions (fixes #792) -function defines_function(ci) +function defines_function(@nospecialize(ci)) isa(ci, CodeInfo) || return false if length(ci.code) == 1 stmt = ci.code[1]