Skip to content
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

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

aviatesk
Copy link
Member

@aviatesk aviatesk commented Jan 10, 2024

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

@aviatesk aviatesk added REPL Julia's REPL (Read Eval Print Loop) compiler:inference Type inference labels Jan 10, 2024
@aviatesk aviatesk requested a review from Keno January 10, 2024 06:29
@vtjnash
Copy link
Member

vtjnash commented Jan 10, 2024

LGTM

@aviatesk aviatesk force-pushed the avi/52763 branch 2 times, most recently from bd2a136 to 53e69eb Compare January 11, 2024 04:25
@oscardssmith oscardssmith added the bugfix This change fixes an existing bug label Jan 11, 2024
Comment on lines 4940 to 4954
@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}
Copy link
Member Author

@aviatesk aviatesk Jan 11, 2024

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?

Copy link
Member

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.

Copy link
Member Author

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.

@aviatesk
Copy link
Member Author

@nanosoldier runtests(ALL, vs = ":master")

@aviatesk aviatesk force-pushed the avi/52763 branch 4 times, most recently from 20747a9 to a9d2126 Compare January 14, 2024 08:42
@aviatesk
Copy link
Member Author

@nanosoldier runtests()

@nanosoldier
Copy link
Collaborator

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

@nanosoldier
Copy link
Collaborator

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

@aviatesk aviatesk force-pushed the avi/52763 branch 2 times, most recently from ef08e37 to b0be24e Compare January 15, 2024 07:39
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
@aviatesk aviatesk merged commit d479660 into master Jan 16, 2024
7 checks passed
@aviatesk aviatesk deleted the avi/52763 branch January 16, 2024 01:15
aviatesk added a commit that referenced this pull request Jan 16, 2024
…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
Drvi pushed a commit to RelationalAI/julia that referenced this pull request Jun 7, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug compiler:inference Type inference REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REPL becomes unresponsive during completion inference
5 participants