Skip to content

Commit 451766a

Browse files
authored
[CompilerDevTools] Properly handle builtins in with_new_compiler (#58074)
1 parent 4b19ab4 commit 451766a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Compiler/extras/CompilerDevTools/src/CompilerDevTools.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ function Compiler.transform_result_for_cache(interp::SplitCacheInterp, result::C
5454
isexpr(stmt, :call) || continue
5555
f = stmt.args[1]
5656
f === override && continue
57-
if isa(f, GlobalRef)
58-
T = widenconst(argextype(f, ir))
59-
T <: Core.Builtin && continue
60-
end
57+
T = widenconst(argextype(f, ir))
58+
T <: Core.Builtin && continue
6159
insert!(stmt.args, 1, override)
6260
insert!(stmt.args, 3, interp.owner)
6361
end
@@ -67,6 +65,10 @@ end
6765
with_new_compiler(f, args...; owner::SplitCacheOwner = SplitCacheOwner()) = with_new_compiler(f, owner, args...)
6866

6967
function with_new_compiler(f, owner::SplitCacheOwner, args...)
68+
# We try to avoid introducing `with_new_compiler` in the first place,
69+
# but if we can't see the type, it's still possible to end up with a
70+
# builtin here - simply forward to the ordinary builtin call.
71+
isa(f, Core.Builtin) && return f(args...)
7072
mi = lookup_method_instance(f, args...)
7173
new_compiler_ci = Core.OptimizedGenerics.CompilerPlugins.typeinf(
7274
owner, mi, Compiler.SOURCE_MODE_ABI

Compiler/extras/CompilerDevTools/test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ using CompilerDevTools: lookup_method_instance, SplitCacheInterp
1717
# required extra work to be cached under the same cache owner.
1818
mi = lookup_method_instance(do_work, 1, 2)
1919
@test haskey(cache, mi)
20+
21+
# Should not error with a builtin whose type we do not know
22+
f_unknown_builtin() = Base.compilerbarrier(:type, isa)(1, Int)
23+
with_new_compiler(f_unknown_builtin, interp.owner) === true
2024
end;

0 commit comments

Comments
 (0)