Skip to content

Commit b5482c8

Browse files
authored
tidy up InferenceState definition (#48775)
1 parent 16801fb commit b5482c8

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function get_max_methods(@nospecialize(f), mod::Module, interp::AbstractInterpre
3030
return get_max_methods(mod, interp)
3131
end
3232

33-
function should_infer_this_call(sv::InferenceState)
34-
if sv.params.unoptimize_throw_blocks
33+
function should_infer_this_call(interp::AbstractInterpreter, sv::InferenceState)
34+
if InferenceParams(interp).unoptimize_throw_blocks
3535
# Disable inference of calls in throw blocks, since we're unlikely to
3636
# need their types. There is one exception however: If up until now, the
3737
# function has not seen any side effects, we would like to make sure there
@@ -52,7 +52,7 @@ function abstract_call_gf_by_type(interp::AbstractInterpreter, @nospecialize(f),
5252
arginfo::ArgInfo, si::StmtInfo, @nospecialize(atype),
5353
sv::InferenceState, max_methods::Int)
5454
= (ipo_lattice(interp))
55-
if !should_infer_this_call(sv)
55+
if !should_infer_this_call(interp, sv)
5656
add_remark!(interp, sv, "Skipped call in throw block")
5757
nonoverlayed = false
5858
if isoverlayed(method_table(interp)) && is_nonoverlayed(sv.ipo_effects)
@@ -2404,13 +2404,13 @@ function abstract_eval_statement_expr(interp::AbstractInterpreter, e::Expr, vtyp
24042404
elseif isa(sym, Symbol)
24052405
if isdefined(sv.mod, sym)
24062406
t = Const(true)
2407-
elseif sv.params.assume_bindings_static
2407+
elseif InferenceParams(interp).assume_bindings_static
24082408
t = Const(false)
24092409
end
24102410
elseif isa(sym, GlobalRef)
24112411
if isdefined(sym.mod, sym.name)
24122412
t = Const(true)
2413-
elseif sv.params.assume_bindings_static
2413+
elseif InferenceParams(interp).assume_bindings_static
24142414
t = Const(false)
24152415
end
24162416
elseif isexpr(sym, :static_parameter)
@@ -2551,7 +2551,7 @@ function abstract_eval_globalref(interp::AbstractInterpreter, g::GlobalRef, fram
25512551
end
25522552
elseif isdefined_globalref(g)
25532553
nothrow = true
2554-
elseif isa(frame, InferenceState) && frame.params.assume_bindings_static
2554+
elseif InferenceParams(interp).assume_bindings_static
25552555
consistent = inaccessiblememonly = ALWAYS_TRUE
25562556
rt = Union{}
25572557
end

base/compiler/inferencestate.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ mutable struct InferenceState
116116
ipo_effects::Effects
117117

118118
#= flags =#
119-
params::InferenceParams
120119
# Whether to restrict inference of abstract call sites to avoid excessive work
121120
# Set by default for toplevel frame.
122121
restrict_abstract_call_sites::Bool
@@ -177,7 +176,6 @@ mutable struct InferenceState
177176
ipo_effects = Effects(ipo_effects; effect_free = ALWAYS_FALSE)
178177
end
179178

180-
params = InferenceParams(interp)
181179
restrict_abstract_call_sites = isa(linfo.def, Module)
182180
@assert cache === :no || cache === :local || cache === :global
183181
cached = cache === :global
@@ -187,11 +185,11 @@ mutable struct InferenceState
187185
currbb, currpc, ip, handler_at, ssavalue_uses, bb_vartables, ssavaluetypes, stmt_edges, stmt_info,
188186
pclimitations, limitations, cycle_backedges, callers_in_cycle, dont_work_on_me, parent, inferred,
189187
result, valid_worlds, bestguess, ipo_effects,
190-
params, restrict_abstract_call_sites, cached, insert_coverage,
188+
restrict_abstract_call_sites, cached, insert_coverage,
191189
interp)
192190

193191
# some more setups
194-
params.unoptimize_throw_blocks && mark_throw_blocks!(src, handler_at)
192+
InferenceParams(interp).unoptimize_throw_blocks && mark_throw_blocks!(src, handler_at)
195193
result.result = frame
196194
cache !== :no && push!(get_inference_cache(interp), result)
197195

base/compiler/typeinfer.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ function record_bestguess!(sv::InferenceState)
626626
return nothing
627627
end
628628

629-
function annotate_slot_load!(undefs::Vector{Bool}, idx::Int, sv::InferenceState, @nospecialize x)
629+
function annotate_slot_load!(interp::AbstractInterpreter, undefs::Vector{Bool}, idx::Int, sv::InferenceState, @nospecialize x)
630630
if isa(x, SlotNumber)
631631
id = slot_id(x)
632632
pc = find_dominating_assignment(id, idx, sv)
@@ -641,7 +641,7 @@ function annotate_slot_load!(undefs::Vector{Bool}, idx::Int, sv::InferenceState,
641641
@assert typ !== NOT_FOUND "active slot in unreached region"
642642
end
643643
# add type annotations where needed
644-
if !(typeinf_lattice(sv.interp), sv.slottypes[id], typ)
644+
if !(typeinf_lattice(interp), sv.slottypes[id], typ)
645645
return TypedSlot(id, typ)
646646
end
647647
return x
@@ -655,13 +655,13 @@ function annotate_slot_load!(undefs::Vector{Bool}, idx::Int, sv::InferenceState,
655655
i0 = 2
656656
end
657657
for i = i0:length(x.args)
658-
x.args[i] = annotate_slot_load!(undefs, idx, sv, x.args[i])
658+
x.args[i] = annotate_slot_load!(interp, undefs, idx, sv, x.args[i])
659659
end
660660
return x
661661
elseif isa(x, ReturnNode) && isdefined(x, :val)
662-
return ReturnNode(annotate_slot_load!(undefs, idx, sv, x.val))
662+
return ReturnNode(annotate_slot_load!(interp, undefs, idx, sv, x.val))
663663
elseif isa(x, GotoIfNot)
664-
return GotoIfNot(annotate_slot_load!(undefs, idx, sv, x.cond), x.dest)
664+
return GotoIfNot(annotate_slot_load!(interp, undefs, idx, sv, x.cond), x.dest)
665665
end
666666
return x
667667
end
@@ -734,7 +734,7 @@ function type_annotate!(interp::AbstractInterpreter, sv::InferenceState, run_opt
734734
end
735735
end
736736
end
737-
body[i] = annotate_slot_load!(undefs, i, sv, expr) # 1&2
737+
body[i] = annotate_slot_load!(interp, undefs, i, sv, expr) # 1&2
738738
ssavaluetypes[i] = widenslotwrapper(ssavaluetypes[i]) # 4
739739
else # i.e. any runtime execution will never reach this statement
740740
any_unreachable = true

0 commit comments

Comments
 (0)