Skip to content

Commit 9c8de4d

Browse files
committed
Check for __precompile__(false) before attempting to precompile
Fixes #28384
1 parent 0ef8826 commit 9c8de4d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

base/loading.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -926,9 +926,10 @@ function _require(pkg::PkgId)
926926
- Run `Pkg.instantiate()` to install all recorded dependencies.
927927
"""))
928928
end
929+
needs_precompile = !occursin(r"__precompile__\(false\)", read(path, String))
929930

930931
# attempt to load the module file via the precompile cache locations
931-
if JLOptions().use_compiled_modules != 0
932+
if JLOptions().use_compiled_modules != 0 && needs_precompile
932933
m = _require_search_from_serialized(pkg, path)
933934
if !isa(m, Bool)
934935
return
@@ -948,7 +949,7 @@ function _require(pkg::PkgId)
948949
end
949950
end
950951

951-
if JLOptions().use_compiled_modules != 0
952+
if JLOptions().use_compiled_modules != 0 && needs_precompile
952953
if (0 == ccall(:jl_generating_output, Cint, ())) || (JLOptions().incremental != 0)
953954
# spawn off a new incremental pre-compile task for recursive `require` calls
954955
# or if the require search declared it was pre-compiled before (and therefore is expected to still be pre-compilable)

test/precompile.jl

+3
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ try
281281
"""
282282
__precompile__(false)
283283
module Baz
284+
baz() = 1
284285
end
285286
""")
286287

@@ -291,6 +292,8 @@ try
291292
isa(exc, ErrorException) || rethrow(exc)
292293
occursin("__precompile__(false)", exc.msg) && rethrow(exc)
293294
end
295+
@eval using Baz
296+
@test Base.invokelatest(Baz.baz) == 1
294297

295298
# Issue #12720
296299
FooBar1_file = joinpath(dir, "FooBar1.jl")

0 commit comments

Comments
 (0)