Skip to content

Commit

Permalink
make failure to precompile a method return a value instead of a uncon…
Browse files Browse the repository at this point in the history
…ditionally warn (JuliaLang#41447)
  • Loading branch information
KristofferC authored and LilithHafner committed Mar 8, 2022
1 parent 1fcfe07 commit 280f9d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1937,11 +1937,13 @@ function precompile(@nospecialize(f), args::Tuple)
precompile(Tuple{Core.Typeof(f), args...})
end

const ENABLE_PRECOMPILE_WARNINGS = Ref(false)
function precompile(argt::Type)
if ccall(:jl_compile_hint, Int32, (Any,), argt) == 0
ret = ccall(:jl_compile_hint, Int32, (Any,), argt) != 0
if !ret && ENABLE_PRECOMPILE_WARNINGS[]
@warn "Inactive precompile statement" maxlog=100 form=argt _module=nothing _file=nothing _line=0
end
true
return ret
end

precompile(include_package_for_output, (PkgId, String, Vector{String}, Vector{String}, Vector{String}, typeof(_concrete_dependencies), Nothing))
Expand Down
4 changes: 2 additions & 2 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end
## Other ways of accessing functions
# Test that non-ambiguous cases work
let io = IOBuffer()
@test @test_logs precompile(ambig, (Int, Int))
@test precompile(ambig, (Int, Int))
cf = @eval @cfunction(ambig, Int, (Int, Int))
@test ccall(cf, Int, (Int, Int), 1, 2) == 4
@test length(code_lowered(ambig, (Int, Int))) == 1
Expand All @@ -75,7 +75,7 @@ end

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

0 comments on commit 280f9d3

Please sign in to comment.