Skip to content

Commit 144f58b

Browse files
authored
disable irinterp for interpreters with may_optimize(...)=false (JuliaLang#53580)
As discussed at <JuliaLang@b8a0a39#commitcomment-139076159>, currently external abstract interpreter that configures `may_optimize` to return `false` may end up with the internal error from irinterp since it fundamentally required optimized IR but it currently assumes that all sources from cached `CodeInstance`s are optimized. This commit addresses the issue by incorporating a `may_optimize` check in `concrete_eval_eligible`, which in turn automatically disables irinterp for such interpreters. Although there were earlier discussions suggesting the revival of `codeinfo.inferred::Bool`, this commit does not need it, and I think this approach maintains the current state more cleanly. This should fix the error of `"inference"` benchmarks from BaseBenchmarks.jl.
1 parent 0311aa4 commit 144f58b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,12 @@ function concrete_eval_eligible(interp::AbstractInterpreter,
897897
add_remark!(interp, sv, "[constprop] Concrete eval disabled for overlayed methods")
898898
end
899899
if !any_conditional(arginfo)
900-
return :semi_concrete_eval
900+
if may_optimize(interp)
901+
return :semi_concrete_eval
902+
else
903+
# disable irinterp if optimization is disabled, since it requires optimized IR
904+
add_remark!(interp, sv, "[constprop] Semi-concrete interpretation disabled for non-optimizing interpreter")
905+
end
901906
end
902907
end
903908
return :none

test/compiler/AbstractInterpreter.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ const CC = Core.Compiler
66
include("irutils.jl")
77
include("newinterp.jl")
88

9+
# interpreter that performs abstract interpretation only
10+
# (semi-concrete interpretation should be disabled automatically)
11+
@newinterp AbsIntOnlyInterp1
12+
CC.may_optimize(::AbsIntOnlyInterp1) = false
13+
@test Base.infer_return_type(Base.init_stdio, (Ptr{Cvoid},); interp=AbsIntOnlyInterp1()) >: IO
14+
15+
# it should work even if the interpreter discards inferred source entirely
16+
@newinterp AbsIntOnlyInterp2
17+
CC.may_optimize(::AbsIntOnlyInterp2) = false
18+
CC.transform_result_for_cache(::AbsIntOnlyInterp2, ::Core.MethodInstance, ::CC.WorldRange, ::CC.InferenceResult) = nothing
19+
@test Base.infer_return_type(Base.init_stdio, (Ptr{Cvoid},); interp=AbsIntOnlyInterp2()) >: IO
920

1021
# OverlayMethodTable
1122
# ==================

0 commit comments

Comments
 (0)