@@ -2230,31 +2230,31 @@ end
22302230
22312231function abstract_eval_special_value (interp:: AbstractInterpreter , @nospecialize (e), vtypes:: Union{VarTable,Nothing} , sv:: AbsIntState )
22322232 if isa (e, QuoteNode)
2233- return Const (e. value)
2233+ return RTEffects ( Const (e. value), EFFECTS_TOTAL )
22342234 elseif isa (e, SSAValue)
2235- return abstract_eval_ssavalue (e, sv)
2235+ return RTEffects ( abstract_eval_ssavalue (e, sv), EFFECTS_TOTAL )
22362236 elseif isa (e, SlotNumber)
2237+ effects = EFFECTS_THROWS
22372238 if vtypes != = nothing
22382239 vtyp = vtypes[slot_id (e)]
2239- if vtyp. undef
2240- merge_effects! (interp, sv, Effects ( EFFECTS_TOTAL; nothrow = false ))
2240+ if ! vtyp. undef
2241+ effects = EFFECTS_TOTAL
22412242 end
2242- return vtyp. typ
2243+ return RTEffects ( vtyp. typ, effects)
22432244 end
2244- merge_effects! (interp, sv, Effects (EFFECTS_TOTAL; nothrow= false ))
2245- return Any
2245+ return RTEffects (Any, effects)
22462246 elseif isa (e, Argument)
22472247 if vtypes != = nothing
2248- return vtypes[slot_id (e)]. typ
2248+ return RTEffects ( vtypes[slot_id (e)]. typ, EFFECTS_TOTAL)
22492249 else
22502250 @assert isa (sv, IRInterpretationState)
2251- return sv. ir. argtypes[e. n] # TODO frame_argtypes(sv)[e.n] and remove the assertion
2251+ return RTEffects ( sv. ir. argtypes[e. n], EFFECTS_TOTAL) # TODO frame_argtypes(sv)[e.n] and remove the assertion
22522252 end
22532253 elseif isa (e, GlobalRef)
22542254 return abstract_eval_globalref (interp, e, sv)
22552255 end
22562256
2257- return Const (e)
2257+ return RTEffects ( Const (e), EFFECTS_TOTAL )
22582258end
22592259
22602260function abstract_eval_value_expr (interp:: AbstractInterpreter , e:: Expr , vtypes:: Union{VarTable,Nothing} , sv:: AbsIntState )
@@ -2288,8 +2288,9 @@ function abstract_eval_value(interp::AbstractInterpreter, @nospecialize(e), vtyp
22882288 if isa (e, Expr)
22892289 return abstract_eval_value_expr (interp, e, vtypes, sv)
22902290 else
2291- typ = abstract_eval_special_value (interp, e, vtypes, sv)
2292- return collect_limitations! (typ, sv)
2291+ (;rt, effects) = abstract_eval_special_value (interp, e, vtypes, sv)
2292+ merge_effects! (interp, sv, effects)
2293+ return collect_limitations! (rt, sv)
22932294 end
22942295end
22952296
@@ -2615,7 +2616,9 @@ function abstract_eval_phi(interp::AbstractInterpreter, phi::PhiNode, vtypes::Un
26152616 for i in 1 : length (phi. values)
26162617 isassigned (phi. values, i) || continue
26172618 val = phi. values[i]
2618- rt = tmerge (typeinf_lattice (interp), rt, abstract_eval_special_value (interp, val, vtypes, sv))
2619+ # N.B.: Phi arguments are restricted to not have effects, so we can drop
2620+ # them here safely.
2621+ rt = tmerge (typeinf_lattice (interp), rt, abstract_eval_special_value (interp, val, vtypes, sv). rt)
26192622 end
26202623 return rt
26212624end
@@ -2631,53 +2634,55 @@ function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e),
26312634 add_curr_ssaflag! (sv, IR_FLAG_EFFECT_FREE | IR_FLAG_NOTHROW)
26322635 return abstract_eval_phi (interp, e, vtypes, sv)
26332636 end
2634- return abstract_eval_special_value (interp, e, vtypes, sv)
2635- end
2636- (; rt, effects) = abstract_eval_statement_expr (interp, e, vtypes, sv)
2637- if effects. noub === NOUB_IF_NOINBOUNDS
2638- if ! iszero (get_curr_ssaflag (sv) & IR_FLAG_INBOUNDS)
2639- effects = Effects (effects; noub= ALWAYS_FALSE)
2640- elseif ! propagate_inbounds (sv)
2641- # The callee read our inbounds flag, but unless we propagate inbounds,
2642- # we ourselves don't read our parent's inbounds.
2643- effects = Effects (effects; noub= ALWAYS_TRUE)
2637+ (; rt, effects) = abstract_eval_special_value (interp, e, vtypes, sv)
2638+ else
2639+ (; rt, effects) = abstract_eval_statement_expr (interp, e, vtypes, sv)
2640+ if effects. noub === NOUB_IF_NOINBOUNDS
2641+ if ! iszero (get_curr_ssaflag (sv) & IR_FLAG_INBOUNDS)
2642+ effects = Effects (effects; noub= ALWAYS_FALSE)
2643+ elseif ! propagate_inbounds (sv)
2644+ # The callee read our inbounds flag, but unless we propagate inbounds,
2645+ # we ourselves don't read our parent's inbounds.
2646+ effects = Effects (effects; noub= ALWAYS_TRUE)
2647+ end
2648+ end
2649+ e = e:: Expr
2650+ @assert ! isa (rt, TypeVar) " unhandled TypeVar"
2651+ rt = maybe_singleton_const (rt)
2652+ if ! isempty (sv. pclimitations)
2653+ if rt isa Const || rt === Union{}
2654+ empty! (sv. pclimitations)
2655+ else
2656+ rt = LimitedAccuracy (rt, sv. pclimitations)
2657+ sv. pclimitations = IdSet {InferenceState} ()
2658+ end
26442659 end
26452660 end
26462661 # N.B.: This only applies to the effects of the statement itself.
26472662 # It is possible for arguments (GlobalRef/:static_parameter) to throw,
26482663 # but these will be recomputed during SSA construction later.
26492664 set_curr_ssaflag! (sv, flags_for_effects (effects), IR_FLAGS_EFFECTS)
26502665 merge_effects! (interp, sv, effects)
2651- e = e:: Expr
2652- @assert ! isa (rt, TypeVar) " unhandled TypeVar"
2653- rt = maybe_singleton_const (rt)
2654- if ! isempty (sv. pclimitations)
2655- if rt isa Const || rt === Union{}
2656- empty! (sv. pclimitations)
2657- else
2658- rt = LimitedAccuracy (rt, sv. pclimitations)
2659- sv. pclimitations = IdSet {InferenceState} ()
2660- end
2661- end
2666+
26622667 return rt
26632668end
26642669
26652670function isdefined_globalref (g:: GlobalRef )
26662671 return ccall (:jl_globalref_boundp , Cint, (Any,), g) != 0
26672672end
26682673
2669- function abstract_eval_globalref (g:: GlobalRef )
2674+ function abstract_eval_globalref_type (g:: GlobalRef )
26702675 if isdefined_globalref (g) && isconst (g)
26712676 return Const (ccall (:jl_get_globalref_value , Any, (Any,), g))
26722677 end
26732678 ty = ccall (:jl_get_binding_type , Any, (Any, Any), g. mod, g. name)
26742679 ty === nothing && return Any
26752680 return ty
26762681end
2677- abstract_eval_global (M:: Module , s:: Symbol ) = abstract_eval_globalref (GlobalRef (M, s))
2682+ abstract_eval_global (M:: Module , s:: Symbol ) = abstract_eval_globalref_type (GlobalRef (M, s))
26782683
26792684function abstract_eval_globalref (interp:: AbstractInterpreter , g:: GlobalRef , sv:: AbsIntState )
2680- rt = abstract_eval_globalref (g)
2685+ rt = abstract_eval_globalref_type (g)
26812686 consistent = inaccessiblememonly = ALWAYS_FALSE
26822687 nothrow = false
26832688 if isa (rt, Const)
@@ -2692,8 +2697,7 @@ function abstract_eval_globalref(interp::AbstractInterpreter, g::GlobalRef, sv::
26922697 consistent = inaccessiblememonly = ALWAYS_TRUE
26932698 rt = Union{}
26942699 end
2695- merge_effects! (interp, sv, Effects (EFFECTS_TOTAL; consistent, nothrow, inaccessiblememonly))
2696- return rt
2700+ return RTEffects (rt, Effects (EFFECTS_TOTAL; consistent, nothrow, inaccessiblememonly))
26972701end
26982702
26992703function handle_global_assignment! (interp:: AbstractInterpreter , frame:: InferenceState , lhs:: GlobalRef , @nospecialize (newty))
0 commit comments