-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
inference: always bail out const-prop' with non-const result limited #52836
Conversation
LGTM |
bd2a136
to
53e69eb
Compare
test/compiler/inference.jl
Outdated
@newinterp RecurseInterpreter | ||
function CC.bail_out_const_call(interp::RecurseInterpreter, result::CC.MethodCallResult, | ||
si::CC.StmtInfo, sv::CC.AbsIntState) | ||
if result.rt isa CC.LimitedAccuracy | ||
return false # allow constprop to recurse into unresolved cycles | ||
end | ||
return @invoke CC.bail_out_const_call(interp::CC.AbstractInterpreter, result::CC.MethodCallResult, | ||
si::CC.StmtInfo, sv::CC.AbsIntState) | ||
end | ||
Base.@constprop :aggressive type_level_recurse1(x...) = x[1] == 2 ? 1 : (length(x) > 100 ? x : type_level_recurse2(x[1] + 1, x..., x...)) | ||
Base.@constprop :aggressive type_level_recurse2(x...) = type_level_recurse1(x...) | ||
type_level_recurse_entry() = Val{type_level_recurse1(1)}() | ||
@test Base.return_types(type_level_recurse_entry, ()) |> only == Val{1} | ||
@test Base.infer_return_type(type_level_recurse_entry, (); interp=RecurseInterpreter()) == Val{1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Keno This PR prevents const-prop' in the presence of unresolvable cycles, regardless of whether const-prop' is enforced. Consequently, it causes the test cases from #48045 to fail. For interpreters requiring optimization against heavy recursions, like Diffractor, do you think it would be fine to make them add explicit overloads to permit const-prop' for cycles as like RecurseInterpreter
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully know. I'm now entirely happy with the recursion story with respect to Diffractor anyway, so I think that needs a larger solution. As long as this doesn't end up causing us immediate problems, I think it's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I'll move forward with this plan. I'll implement the necessary adjustments in Diffractor that would be similar to what RecurseInterpreter
does here.
@nanosoldier |
20747a9
to
a9d2126
Compare
@nanosoldier |
The package evaluation job you requested has completed - possible new issues were detected. |
The package evaluation job you requested has completed - possible new issues were detected. |
ef08e37
to
b0be24e
Compare
Investigating into #52763, I've found that `AbstractInterpreters` which enables the `aggressive_constprop` option, such as `REPLInterpreter`, might perform const-prop' even if the result of a non-const call is `LimitedAccuracy'. This can lead to an unintended infinite loop with a custom aggressive const-prop' implementation. This commit restricts const-prop' for such cases where the non-const call result is limited to avoid the issue. This fix is conservative, but given that accurate inference is mostly impossible when there are unresolvable cycles (which is indicated by limited result), aggressive const-prop' isn't necessary for such cases, and I don't anticipate this leading to any obvious regression. fix #52763
…52836) Investigating into #52763, I've found that `AbstractInterpreters` which enables the `aggressive_constprop` option, such as `REPLInterpreter`, might perform const-prop' even if the result of a non-const call is `LimitedAccuracy`. This can lead to an unintended infinite loop with a custom aggressive const-prop' implementation. This commit restricts const-prop' for such cases where the non-const call result is limited to avoid the issue. This fix is conservative, but given that accurate inference is mostly impossible when there are unresolvable cycles (which is indicated by limited result), aggressive const-prop' isn't necessary for such cases, and I don't anticipate this leading to any obvious regression. fix #52763
…uliaLang#52836) Investigating into JuliaLang#52763, I've found that `AbstractInterpreters` which enables the `aggressive_constprop` option, such as `REPLInterpreter`, might perform const-prop' even if the result of a non-const call is `LimitedAccuracy`. This can lead to an unintended infinite loop with a custom aggressive const-prop' implementation. This commit restricts const-prop' for such cases where the non-const call result is limited to avoid the issue. This fix is conservative, but given that accurate inference is mostly impossible when there are unresolvable cycles (which is indicated by limited result), aggressive const-prop' isn't necessary for such cases, and I don't anticipate this leading to any obvious regression. fix JuliaLang#52763
Investigating into #52763, I've found that
AbstractInterpreters
which enables theaggressive_constprop
option, such asREPLInterpreter
, might perform const-prop' even if the result of a non-const call isLimitedAccuracy
. This can lead to an unintended infinite loop with a custom aggressive const-prop' implementation.This commit restricts const-prop' for such cases where the non-const call result is limited to avoid the issue. This fix is conservative, but given that accurate inference is mostly impossible when there are unresolvable cycles (which is indicated by limited result), aggressive const-prop' isn't necessary for such cases, and I don't anticipate this leading to any obvious regression.
fix #52763