Skip to content

Commit 2666188

Browse files
committed
Optimize abstract_iteration a little bit
Avoid recomputation of a `widenconst` and initialize `valtype` and `statetype` to `Bottom` before second loop to simplify a `⊑`to a `<:` there.
1 parent 1224d29 commit 2666188

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,11 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
840840
return ret, AbstractIterationInfo(calls)
841841
end
842842
if Nothing <: stateordonet_widened || length(ret) >= InferenceParams(interp).MAX_TUPLE_SPLAT
843+
stateordonet = stateordonet_widened
843844
break
844845
end
845846
if !isa(stateordonet_widened, DataType) || !(stateordonet_widened <: Tuple) || isvatuple(stateordonet_widened) || length(stateordonet_widened.parameters) != 2
847+
stateordonet = stateordonet_widened
846848
break
847849
end
848850
nstatetype = getfield_tfunc(stateordonet, Const(2))
@@ -860,15 +862,17 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
860862
end
861863
# From here on, we start asking for results on the widened types, rather than
862864
# the precise (potentially const) state type
863-
valtype = widenconst(valtype)
865+
# statetype and valtype are reinitialized in the first iteration below from the
866+
# (widened) stateordonet, which has not yet been fully analyzed in the loop above
867+
statetype = Bottom
868+
valtype = Bottom
864869
while valtype !== Any
865-
stateordonet = widenconst(stateordonet)
866870
nounion = typesubtract(stateordonet, Nothing, 0)
867871
if !isa(nounion, DataType) || !(nounion <: Tuple) || isvatuple(nounion) || length(nounion.parameters) != 2
868872
valtype = Any
869873
break
870874
end
871-
if nounion.parameters[1] <: valtype && nounion.parameters[2] statetype
875+
if nounion.parameters[1] <: valtype && nounion.parameters[2] <: statetype
872876
if typeintersect(stateordonet, Nothing) === Union{}
873877
# Reached a fixpoint, but Nothing is not possible => iterator is infinite or failing
874878
return Any[Bottom], nothing
@@ -878,6 +882,7 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
878882
valtype = tmerge(valtype, nounion.parameters[1])
879883
statetype = tmerge(statetype, nounion.parameters[2])
880884
stateordonet = abstract_call_known(interp, iteratef, nothing, Any[Const(iteratef), itertype, statetype], sv).rt
885+
stateordonet = widenconst(stateordonet)
881886
end
882887
push!(ret, Vararg{valtype})
883888
return ret, nothing

0 commit comments

Comments
 (0)