Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make failure to precompile a method return a value instead of a unconditionally warn #41447

Merged
merged 5 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1926,11 +1926,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