Skip to content

Commit c0e12cd

Browse files
authored
inference: enable :call inference in irinterp (#49191)
* inference: enable `:call` inference in irinterp Built on top of #48913, this commit enables `:call` inference in irinterp. In a case when some regression is detected, we can simply revert this commit rather than reverting the whole refactoring from #48913. * fix irinterp lattice Now `LimitedAccuracy` can appear in irinterp, so we should include `InferenceLattice` for `[typeinf|ipo]_lattice` for irinterp.
1 parent 5032a1a commit c0e12cd

File tree

3 files changed

+33
-37
lines changed

3 files changed

+33
-37
lines changed

base/compiler/ssair/irinterp.jl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
# TODO (#48913) remove this overload to enable interprocedural call inference from irinterp
4-
function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
5-
arginfo::ArgInfo, si::StmtInfo, @nospecialize(atype),
6-
sv::IRInterpretationState, max_methods::Int)
7-
return CallMeta(Any, Effects(), NoCallInfo())
8-
end
9-
103
function collect_limitations!(@nospecialize(typ), ::IRInterpretationState)
114
@assert !isa(typ, LimitedAccuracy) "irinterp is unable to handle heavy recursion"
125
return typ
@@ -147,15 +140,15 @@ function reprocess_instruction!(interp::AbstractInterpreter, idx::Int, bb::Union
147140
# Handled at the very end
148141
return false
149142
elseif isa(inst, PiNode)
150-
rt = tmeet(optimizer_lattice(interp), argextype(inst.val, ir), widenconst(inst.typ))
143+
rt = tmeet(typeinf_lattice(interp), argextype(inst.val, ir), widenconst(inst.typ))
151144
elseif inst === nothing
152145
return false
153146
elseif isa(inst, GlobalRef)
154147
# GlobalRef is not refinable
155148
else
156149
error("reprocess_instruction!: unhandled instruction found")
157150
end
158-
if rt !== nothing && !(optimizer_lattice(interp), typ, rt)
151+
if rt !== nothing && !(typeinf_lattice(interp), typ, rt)
159152
ir.stmts[idx][:type] = rt
160153
return true
161154
end
@@ -323,7 +316,7 @@ function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IR
323316
end
324317
inst = ir.stmts[idx][:inst]::ReturnNode
325318
rt = argextype(inst.val, ir)
326-
ultimate_rt = tmerge(optimizer_lattice(interp), ultimate_rt, rt)
319+
ultimate_rt = tmerge(typeinf_lattice(interp), ultimate_rt, rt)
327320
end
328321
end
329322

base/compiler/types.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,12 @@ typeinf_lattice(::AbstractInterpreter) = InferenceLattice(BaseInferenceLattice.i
466466
ipo_lattice(::AbstractInterpreter) = InferenceLattice(IPOResultLattice.instance)
467467
optimizer_lattice(::AbstractInterpreter) = OptimizerLattice(SimpleInferenceLattice.instance)
468468

469-
typeinf_lattice(interp::NativeInterpreter) = interp.irinterp ? optimizer_lattice(interp) : InferenceLattice(BaseInferenceLattice.instance)
470-
ipo_lattice(interp::NativeInterpreter) = interp.irinterp ? optimizer_lattice(interp) : InferenceLattice(IPOResultLattice.instance)
469+
typeinf_lattice(interp::NativeInterpreter) = interp.irinterp ?
470+
OptimizerLattice(InferenceLattice(SimpleInferenceLattice.instance)) :
471+
InferenceLattice(BaseInferenceLattice.instance)
472+
ipo_lattice(interp::NativeInterpreter) = interp.irinterp ?
473+
InferenceLattice(SimpleInferenceLattice.instance) :
474+
InferenceLattice(IPOResultLattice.instance)
471475
optimizer_lattice(interp::NativeInterpreter) = OptimizerLattice(SimpleInferenceLattice.instance)
472476

473477
"""

test/compiler/inference.jl

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4784,31 +4784,30 @@ fhasmethod(::Integer, ::Int32) = 3
47844784
@test only(Base.return_types(()) do; Val(hasmethod(sin, Tuple{Int, Vararg{Int}})); end) == Val{false}
47854785
@test only(Base.return_types(()) do; Val(hasmethod(sin, Tuple{Int, Int, Vararg{Int}})); end) === Val{false}
47864786

4787-
# TODO (#48913) enable interprocedural call inference from irinterp
4788-
# # interprocedural call inference from irinterp
4789-
# @noinline Base.@assume_effects :total issue48679_unknown_any(x) = Base.inferencebarrier(x)
4790-
4791-
# @noinline _issue48679(y::Union{Nothing,T}) where {T} = T::Type
4792-
# Base.@constprop :aggressive function issue48679(x, b)
4793-
# if b
4794-
# x = issue48679_unknown_any(x)
4795-
# end
4796-
# return _issue48679(x)
4797-
# end
4798-
# @test Base.return_types((Float64,)) do x
4799-
# issue48679(x, false)
4800-
# end |> only == Type{Float64}
4801-
4802-
# Base.@constprop :aggressive @noinline _issue48679_const(b, y::Union{Nothing,T}) where {T} = b ? nothing : T::Type
4803-
# Base.@constprop :aggressive function issue48679_const(x, b)
4804-
# if b
4805-
# x = issue48679_unknown_any(x)
4806-
# end
4807-
# return _issue48679_const(b, x)
4808-
# end
4809-
# @test Base.return_types((Float64,)) do x
4810-
# issue48679_const(x, false)
4811-
# end |> only == Type{Float64}
4787+
# interprocedural call inference from irinterp
4788+
@noinline Base.@assume_effects :total issue48679_unknown_any(x) = Base.inferencebarrier(x)
4789+
4790+
@noinline _issue48679(y::Union{Nothing,T}) where {T} = T::Type
4791+
Base.@constprop :aggressive function issue48679(x, b)
4792+
if b
4793+
x = issue48679_unknown_any(x)
4794+
end
4795+
return _issue48679(x)
4796+
end
4797+
@test Base.return_types((Float64,)) do x
4798+
issue48679(x, false)
4799+
end |> only == Type{Float64}
4800+
4801+
Base.@constprop :aggressive @noinline _issue48679_const(b, y::Union{Nothing,T}) where {T} = b ? nothing : T::Type
4802+
Base.@constprop :aggressive function issue48679_const(x, b)
4803+
if b
4804+
x = issue48679_unknown_any(x)
4805+
end
4806+
return _issue48679_const(b, x)
4807+
end
4808+
@test Base.return_types((Float64,)) do x
4809+
issue48679_const(x, false)
4810+
end |> only == Type{Float64}
48124811

48134812
# `invoke` call in irinterp
48144813
@noinline _irinterp_invoke(x::Any) = :any

0 commit comments

Comments
 (0)