Skip to content

Commit 6839451

Browse files
authored
Merge pull request #18888 from JuliaLang/tb/uncached_reflection
Don't cache inference results if not optimizing.
2 parents ec80011 + d261644 commit 6839451

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

base/reflection.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ function code_typed(f::ANY, types::ANY=Tuple; optimize=true)
583583
asts = []
584584
for x in _methods(f, types, -1)
585585
meth = func_for_method_checked(x[3], types)
586-
(code, ty) = Core.Inference.typeinf_code(meth, x[1], x[2], optimize, !optimize)
586+
(code, ty) = Core.Inference.typeinf_code(meth, x[1], x[2], optimize, optimize)
587587
code === nothing && error("inference not successful") # Inference disabled?
588588
push!(asts, uncompressed_ast(meth, code) => ty)
589589
end

test/reflection.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,20 @@ end
573573
@test counter18434 == 1
574574
@which get_A18434()(1, y=2)
575575
@test counter18434 == 2
576+
577+
# PR #18888: code_typed shouldn't cache if not optimizing
578+
let
579+
f18888() = return nothing
580+
m = first(methods(f18888, Tuple{}))
581+
@test m.specializations == nothing
582+
ft = typeof(f18888)
583+
584+
code_typed(f18888, Tuple{}; optimize=false)
585+
@test m.specializations != nothing # uncached, but creates the specializations entry
586+
code = Core.Inference.code_for_method(m, Tuple{ft}, Core.svec(), true)
587+
@test !isdefined(code, :inferred)
588+
589+
code_typed(f18888, Tuple{}; optimize=true)
590+
code = Core.Inference.code_for_method(m, Tuple{ft}, Core.svec(), true)
591+
@test isdefined(code, :inferred)
592+
end

0 commit comments

Comments
 (0)