@@ -78,7 +78,18 @@ function append!(bsbmp::BitSetBoundedMinPrioritySet, itr)
7878 end
7979end
8080
81- mutable struct InferenceState
81+ struct AbsIntRecursionState
82+ pclimitations:: IdSet{AbsIntState} # causes of precision restrictions (LimitedAccuracy) on currpc ssavalue
83+ limitations:: IdSet{AbsIntState} # causes of precision restrictions (LimitedAccuracy) on return
84+ callers_in_cycle:: Vector{AbsIntState}
85+ end
86+ function AbsIntRecursionState ()
87+ return AbsIntRecursionState (IdSet {AbsIntState} (),
88+ IdSet {AbsIntState} (),
89+ Vector {AbsIntState} ())
90+ end
91+
92+ mutable struct InferenceState <: AbsIntState
8293 #= information about this method instance =#
8394 linfo:: MethodInstance
8495 world:: UInt
@@ -195,23 +206,25 @@ end
195206is_inferred (sv:: InferenceState ) = is_inferred (sv. result)
196207is_inferred (result:: InferenceResult ) = result. result != = nothing
197208
209+ frame_instance (sv:: InferenceState ) = sv. linfo
210+ frame_parent (sv:: InferenceState ) = sv. parent
211+ frame_cached (sv:: InferenceState ) = sv. cached
212+ frame_src (sv:: InferenceState ) = sv. src
213+ callers_in_cycle (sv:: InferenceState ) = sv. callers_in_cycle
214+
198215function merge_effects! (:: AbstractInterpreter , caller:: InferenceState , effects:: Effects )
199216 caller. ipo_effects = merge_effects (caller. ipo_effects, effects)
200217end
201218
202- merge_effects! (interp:: AbstractInterpreter , caller:: InferenceState , callee:: InferenceState ) =
203- merge_effects! (interp, caller, Effects (callee))
204- merge_effects! (interp:: AbstractInterpreter , caller:: IRCode , effects:: Effects ) = nothing
205-
206- is_effect_overridden (sv:: InferenceState , effect:: Symbol ) = is_effect_overridden (sv. linfo, effect)
219+ is_effect_overridden (sv:: AbsIntState , effect:: Symbol ) = is_effect_overridden (frame_instance (sv), effect)
207220function is_effect_overridden (linfo:: MethodInstance , effect:: Symbol )
208221 def = linfo. def
209222 return isa (def, Method) && is_effect_overridden (def, effect)
210223end
211224is_effect_overridden (method:: Method , effect:: Symbol ) = is_effect_overridden (decode_effects_override (method. purity), effect)
212225is_effect_overridden (override:: EffectsOverride , effect:: Symbol ) = getfield (override, effect)
213226
214- add_remark! (:: AbstractInterpreter , sv :: Union{InferenceState, IRCode} , remark) = return
227+ add_remark! (:: AbstractInterpreter , :: AbsIntState , remark) = return
215228
216229struct InferenceLoopState
217230 sig
@@ -222,13 +235,13 @@ struct InferenceLoopState
222235 end
223236end
224237
225- function bail_out_toplevel_call (:: AbstractInterpreter , state:: InferenceLoopState , sv:: Union{ InferenceState, IRCode} )
226- return isa (sv, InferenceState) && sv. restrict_abstract_call_sites && ! isdispatchtuple (state. sig)
238+ function bail_out_toplevel_call (:: AbstractInterpreter , state:: InferenceLoopState , sv:: InferenceState )
239+ return sv. restrict_abstract_call_sites && ! isdispatchtuple (state. sig)
227240end
228- function bail_out_call (:: AbstractInterpreter , state:: InferenceLoopState , sv :: Union{ InferenceState, IRCode} )
241+ function bail_out_call (:: AbstractInterpreter , state:: InferenceLoopState , :: InferenceState )
229242 return state. rt === Any && ! is_foldable (state. effects)
230243end
231- function bail_out_apply (:: AbstractInterpreter , state:: InferenceLoopState , sv :: Union{ InferenceState, IRCode} )
244+ function bail_out_apply (:: AbstractInterpreter , state:: InferenceLoopState , :: InferenceState )
232245 return state. rt === Any
233246end
234247
@@ -347,21 +360,21 @@ end
347360 children before their parents (i.e. ascending the tree from the given
348361 InferenceState). Note that cycles may be visited in any order.
349362"""
350- struct InfStackUnwind
351- inf:: InferenceState
363+ struct InfStackUnwind{SV <: AbsIntState }
364+ inf:: SV
352365end
353366iterate (unw:: InfStackUnwind ) = (unw. inf, (unw. inf, 0 ))
354- function iterate (unw:: InfStackUnwind , (infstate, cyclei):: Tuple{InferenceState , Int} )
367+ function iterate (unw:: InfStackUnwind{SV} , (infstate, cyclei):: Tuple{SV , Int} ) where SV <: AbsIntState
355368 # iterate through the cycle before walking to the parent
356- if cyclei < length (infstate . callers_in_cycle)
369+ if cyclei < length (callers_in_cycle (infstate) )
357370 cyclei += 1
358- infstate = infstate . callers_in_cycle[cyclei]
371+ infstate = callers_in_cycle (infstate) [cyclei]
359372 else
360373 cyclei = 0
361- infstate = infstate. parent
374+ infstate = frame_parent ( infstate)
362375 end
363376 infstate === nothing && return nothing
364- (infstate:: InferenceState , (infstate, cyclei))
377+ (infstate, (infstate, cyclei))
365378end
366379
367380function InferenceState (result:: InferenceResult , cache:: Symbol , interp:: AbstractInterpreter )
@@ -500,12 +513,12 @@ function sptypes_from_meth_instance(linfo::MethodInstance)
500513 return sptypes
501514end
502515
503- _topmod (sv:: InferenceState ) = _topmod (sv . mod )
516+ _topmod (sv:: InferenceState ) = _topmod (frame_module (sv) )
504517
505518# work towards converging the valid age range for sv
506519function update_valid_age! (sv:: InferenceState , valid_worlds:: WorldRange )
507520 valid_worlds = sv. valid_worlds = intersect (valid_worlds, sv. valid_worlds)
508- @assert ( sv. world in valid_worlds, " invalid age range update" )
521+ @assert sv. world in valid_worlds " invalid age range update"
509522 return valid_worlds
510523end
511524
@@ -543,42 +556,31 @@ end
543556
544557# temporarily accumulate our edges to later add as backedges in the callee
545558function add_backedge! (caller:: InferenceState , mi:: MethodInstance )
546- edges = get_stmt_edges! (caller)
547- if edges != = nothing
548- push! (edges, mi)
549- end
550- return nothing
559+ isa (caller. linfo. def, Method) || return nothing # don't add backedges to toplevel method instance
560+ return push! (get_stmt_edges! (caller), mi)
551561end
552562
553563function add_invoke_backedge! (caller:: InferenceState , @nospecialize (invokesig:: Type ), mi:: MethodInstance )
554- edges = get_stmt_edges! (caller)
555- if edges != = nothing
556- push! (edges, invokesig, mi)
557- end
558- return nothing
564+ isa (caller. linfo. def, Method) || return nothing # don't add backedges to toplevel method instance
565+ return push! (get_stmt_edges! (caller), invokesig, mi)
559566end
560567
561568# used to temporarily accumulate our no method errors to later add as backedges in the callee method table
562569function add_mt_backedge! (caller:: InferenceState , mt:: MethodTable , @nospecialize (typ))
563- edges = get_stmt_edges! (caller)
564- if edges != = nothing
565- push! (edges, mt, typ)
566- end
567- return nothing
570+ isa (caller. linfo. def, Method) || return nothing # don't add backedges to toplevel method instance
571+ return push! (get_stmt_edges! (caller), mt, typ)
568572end
569573
570- function get_stmt_edges! (caller:: InferenceState )
571- if ! isa (caller. linfo. def, Method)
572- return nothing # don't add backedges to toplevel exprs
573- end
574- edges = caller. stmt_edges[caller. currpc]
574+ function get_stmt_edges! (caller:: InferenceState , currpc:: Int = caller. currpc)
575+ stmt_edges = caller. stmt_edges
576+ edges = stmt_edges[currpc]
575577 if edges === nothing
576- edges = caller . stmt_edges[caller . currpc] = []
578+ edges = stmt_edges[currpc] = []
577579 end
578580 return edges
579581end
580582
581- function empty_backedges! (frame:: InferenceState , currpc:: Int = frame. currpc)
583+ function empty_backedges! (frame:: InferenceState , currpc:: Int = frame. currpc)
582584 edges = frame. stmt_edges[currpc]
583585 edges === nothing || empty! (edges)
584586 return nothing
0 commit comments