-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Fix a precision issue in abstract_iteration
#41839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1d553b8
423dc65
bbfeb79
75372b2
8669893
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -847,9 +847,11 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n | |||||
return ret, AbstractIterationInfo(calls) | ||||||
end | ||||||
if Nothing <: stateordonet_widened || length(ret) >= InferenceParams(interp).MAX_TUPLE_SPLAT | ||||||
stateordonet = stateordonet_widened | ||||||
break | ||||||
end | ||||||
if !isa(stateordonet_widened, DataType) || !(stateordonet_widened <: Tuple) || isvatuple(stateordonet_widened) || length(stateordonet_widened.parameters) != 2 | ||||||
stateordonet = stateordonet_widened | ||||||
break | ||||||
end | ||||||
nstatetype = getfield_tfunc(stateordonet, Const(2)) | ||||||
|
@@ -867,27 +869,40 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n | |||||
end | ||||||
# From here on, we start asking for results on the widened types, rather than | ||||||
# the precise (potentially const) state type | ||||||
statetype = widenconst(statetype) | ||||||
valtype = widenconst(valtype) | ||||||
# statetype and valtype are reinitialized in the first iteration below from the | ||||||
# (widened) stateordonet, which has not yet been fully analyzed in the loop above | ||||||
statetype = Bottom | ||||||
valtype = Bottom | ||||||
may_have_terminated = Nothing <: stateordonet | ||||||
while valtype !== Any | ||||||
stateordonet = abstract_call_known(interp, iteratef, nothing, Any[Const(iteratef), itertype, statetype], sv).rt | ||||||
stateordonet = widenconst(stateordonet) | ||||||
nounion = typesubtract(stateordonet, Nothing, 0) | ||||||
if !isa(nounion, DataType) || !(nounion <: Tuple) || isvatuple(nounion) || length(nounion.parameters) != 2 | ||||||
nounion = typeintersect(stateordonet, Tuple{Any,Any}) | ||||||
if nounion !== Union{} && !isa(nounion, DataType) | ||||||
# nounion is of a type we cannot handle | ||||||
valtype = Any | ||||||
break | ||||||
end | ||||||
if nounion.parameters[1] <: valtype && nounion.parameters[2] <: statetype | ||||||
if nounion === Union{} || (nounion.parameters[1] <: valtype && nounion.parameters[2] <: statetype) | ||||||
# reached a fixpoint or iterator failed/gave invalid answer | ||||||
if typeintersect(stateordonet, Nothing) === Union{} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
As There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be almost identical (since typeintersect can check that property too), so not worth worrying about the difference too much |
||||||
# Reached a fixpoint, but Nothing is not possible => iterator is infinite or failing | ||||||
return Any[Bottom], nothing | ||||||
# ... but cannot terminate | ||||||
if !may_have_terminated | ||||||
# ... and cannot have terminated prior to this loop | ||||||
return Any[Bottom], nothing | ||||||
else | ||||||
# iterator may have terminated prior to this loop, but not during it | ||||||
valtype = Bottom | ||||||
end | ||||||
end | ||||||
break | ||||||
end | ||||||
valtype = tmerge(valtype, nounion.parameters[1]) | ||||||
statetype = tmerge(statetype, nounion.parameters[2]) | ||||||
stateordonet = abstract_call_known(interp, iteratef, nothing, Any[Const(iteratef), itertype, statetype], sv).rt | ||||||
stateordonet = widenconst(stateordonet) | ||||||
end | ||||||
if valtype !== Union{} | ||||||
push!(ret, Vararg{valtype}) | ||||||
end | ||||||
push!(ret, Vararg{valtype}) | ||||||
return ret, nothing | ||||||
end | ||||||
|
||||||
|
Uh oh!
There was an error while loading. Please reload this page.