Skip to content

Commit 280f9d3

Browse files
KristofferCLilithHafner
authored andcommitted
make failure to precompile a method return a value instead of a unconditionally warn (JuliaLang#41447)
1 parent 1fcfe07 commit 280f9d3

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

base/loading.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,11 +1937,13 @@ function precompile(@nospecialize(f), args::Tuple)
19371937
precompile(Tuple{Core.Typeof(f), args...})
19381938
end
19391939

1940+
const ENABLE_PRECOMPILE_WARNINGS = Ref(false)
19401941
function precompile(argt::Type)
1941-
if ccall(:jl_compile_hint, Int32, (Any,), argt) == 0
1942+
ret = ccall(:jl_compile_hint, Int32, (Any,), argt) != 0
1943+
if !ret && ENABLE_PRECOMPILE_WARNINGS[]
19421944
@warn "Inactive precompile statement" maxlog=100 form=argt _module=nothing _file=nothing _line=0
19431945
end
1944-
true
1946+
return ret
19451947
end
19461948

19471949
precompile(include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof(_concrete_dependencies), Nothing))

test/ambiguous.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ end
6666
## Other ways of accessing functions
6767
# Test that non-ambiguous cases work
6868
let io = IOBuffer()
69-
@test @test_logs precompile(ambig, (Int, Int))
69+
@test precompile(ambig, (Int, Int))
7070
cf = @eval @cfunction(ambig, Int, (Int, Int))
7171
@test ccall(cf, Int, (Int, Int), 1, 2) == 4
7272
@test length(code_lowered(ambig, (Int, Int))) == 1
@@ -75,7 +75,7 @@ end
7575

7676
# Test that ambiguous cases fail appropriately
7777
let io = IOBuffer()
78-
@test @test_logs (:warn,) precompile(ambig, (UInt8, Int))
78+
@test !precompile(ambig, (UInt8, Int))
7979
cf = @eval @cfunction(ambig, Int, (UInt8, Int)) # test for a crash (doesn't throw an error)
8080
@test_throws(MethodError(ambig, (UInt8(1), Int(2)), get_world_counter()),
8181
ccall(cf, Int, (UInt8, Int), 1, 2))

0 commit comments

Comments
 (0)