From 280f9d385abda51a081e497851c37dec7126c24b Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 31 Aug 2021 17:34:01 +0200 Subject: [PATCH] make failure to precompile a method return a value instead of a unconditionally warn (#41447) --- base/loading.jl | 6 ++++-- test/ambiguous.jl | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index bec6596b2142a..a87a6ed7423c5 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -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)) diff --git a/test/ambiguous.jl b/test/ambiguous.jl index 265d97776c053..0516d9a74e436 100644 --- a/test/ambiguous.jl +++ b/test/ambiguous.jl @@ -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 @@ -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))