-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Only check the DefId
for the recursion check in MIR inliner.
#100522
Conversation
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
Waiting until a depth limit is hit is not enough to avoid the issue in a variations of the original code, e.g., with two self-recursive calls instead of just one. Maybe keep a history with def ids only? That should be quite robust. In fact there used to be a self-recursion check based on def id only, but looks like it is gone now?. While in the principle there are cases with recursive def ids which we would be good candidates for inlining, they are relatively uncommon in practice. While bootstraping rustc, a recursion check that uses def ids only differs from the one that also includes substitutions only 26 times. |
r? @tmiasko looks like you have thoughts on how this should be handled |
Why? With two self-recursive calls, each inlined call would increase the length of fn inner<T>() { inner2<T::Next>() }
fn inner2<T>() { inner<T::Next>() }
I could only find you PR which introduced the check based on |
I had in mind a case with two calls, where each call site has an independent history, growing in both breadth and depth: #[inline(always)]
fn inner<const N: usize, T: Tr>() {
inner::<N, T::Next>();
inner::<N, T::Next>();
}
The check based on def id was removed in 114c928 (it prevented inlining of functions with direct self-recursion).
Differences: instance that is being optimized, callee
|
584313a
to
1cf8f21
Compare
1cf8f21
to
86645c9
Compare
Thanks! r=me with pull request description updated. |
DefId
for the recursion check in MIR inliner.
@bors r=tmiasko |
Rollup of 9 pull requests Successful merges: - rust-lang#99576 (Do not allow `Drop` impl on foreign fundamental types) - rust-lang#100081 (never consider unsafe blocks unused if they would be required with deny(unsafe_op_in_unsafe_fn)) - rust-lang#100208 (make NOP dyn casts not require anything about the vtable) - rust-lang#100494 (Cleanup rustdoc themes) - rust-lang#100522 (Only check the `DefId` for the recursion check in MIR inliner.) - rust-lang#100592 (Manually implement Debug for ImportKind.) - rust-lang#100598 (Don't fix builtin index when Where clause is found) - rust-lang#100721 (Add diagnostics lints to `rustc_type_ir` module) - rust-lang#100731 (rustdoc: count deref and non-deref as same set of used methods) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The current history check compares
Instance
s, so it cannot detect cases of polymorphic recursion whereSubsts
change.This PR makes it so we only compare
DefId
s, ignoring any change inSubsts
.According to #100522 (comment), in practice only very few inlining decisions change.
Fixes #100476