Skip to content

Add two extra early return checks to is_recursive_terminator - #165489

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
nnethercote:is_recursive_terminator
Nov 26, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
nnethercote:is_recursive_terminator

Conversation

@nnethercote

@nnethercote nnethercote commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

This helps the new solver because resolution is more expensive for it than the old solver, so it's worth trying harder to avoid it.

The biggest win is for nalgebra, because it impls Add for a matrix type, and + calls on elements also use Add::add. So more precise checks are needed.

r? @oli-obk

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 5, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 5, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 5, 2026
Add two extra early return checks to `is_recursive_terminator`
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 9ce971b (9ce971b1e135ed516a005c354ea8729bf8649597)
Base parent: 2d20b42 (2d20b42b883dcfc014f3c2c56081eeb6091c2179)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (9ce971b): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.0%, 0.6%] 9
Improvements ✅
(primary)
-0.5% [-1.5%, -0.2%] 23
Improvements ✅
(secondary)
-1.0% [-3.0%, -0.2%] 15
All ❌✅ (primary) -0.5% [-1.5%, -0.2%] 23

Max RSS (memory usage)

Results (primary 2.1%, secondary -0.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.1% [2.3%, 3.6%] 3
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
-2.7% [-2.7%, -2.7%] 1
All ❌✅ (primary) 2.1% [-1.1%, 3.6%] 4

Cycles

Results (primary -2.4%, secondary -3.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.4% [-2.8%, -2.1%] 5
Improvements ✅
(secondary)
-3.7% [-4.0%, -3.4%] 2
All ❌✅ (primary) -2.4% [-2.8%, -2.1%] 5

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 480.462s -> 480.549s (0.02%)
Artifact size: 406.22 MiB -> 406.24 MiB (0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 5, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

LLM disclosure: this PR is based off LLM analysis. I wrote the code and text myself.

@nnethercote
nnethercote marked this pull request as ready for review November 5, 2026 07:51
@rustbot

rustbot commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 5, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

Perf results look good: the icount improvements on nalgebra also translate to tangible cycle count and wall-time improvements.

Comment on lines +161 to +174
// Another check to avoid resolving if we can: this time whether the args can unify.
// This is the same `relate_rigid_infer` fast reject done by both trait solvers.
// The `callee != caller` guard means the check is skipped for trait default methods.
if callee != caller {
let call_trait_args =
ty::TraitRef::from_assoc(tcx, tcx.parent(callee), normalized_args).args;
let impl_trait_args = tcx.impl_trait_ref(tcx.parent(caller)).skip_binder().args;
if !ty::DeepRejectCtxt::relate_rigid_infer(tcx)
.args_may_unify(call_trait_args, impl_trait_args)
{
return false;
}
}

@oli-obk oli-obk Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little annoying that this fast reject is now duplicated. Have you tried benchmarking the two changes individually? Maybe only one of them actually causes most of the perf improvement?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the trait_item_of one first and that got a smallish win, then I added the args_may_unify and the win slightly more than doubled in size.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fast reject duplication is a bit annoying, but I don't see how to avoid it. Normally we fast reject deeper in because we need to enumerate multiple candidates, etc., but here we only need to consider a single candidate.

@oli-obk oli-obk added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 6, 2026
This helps the new solver because resolution is more expensive for it
than the old solver, so it's worth trying harder to avoid it.

The biggest win is for `nalgebra`, because it impls `Add` for a matrix
type, and `+` calls on elements also use `Add::add`. So more precise
checks are needed.

This change avoids the ICE in tests/crashes/152295.rs but doesn't
properly fix the underlying problem, so the commit also modifies that
test to re-expose the ICE.
@nnethercote
nnethercote force-pushed the is_recursive_terminator branch from b903e55 to 6f1344c Compare November 11, 2026 00:35
@rustbot

rustbot commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@rustbot

rustbot commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@nnethercote

Copy link
Copy Markdown
Contributor Author

I updated the crash test so it re-manifests, because this PR masked but didn't fix the underlying issue.

Note that the cycle count improvements are a bit higher than the instruction count improvements, which is interesting. (Same story with wall-time, though there's more variation there so it's a bit harder to see.)

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors

rust-bors Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 6f1344c has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
Add two extra early return checks to `is_recursive_terminator`

This helps the new solver because resolution is more expensive for it than the old solver, so it's worth trying harder to avoid it.

The biggest win is for `nalgebra`, because it impls `Add` for a matrix type, and `+` calls on elements also use `Add::add`. So more precise checks are needed.

r? @oli-obk
@rust-bors

rust-bors Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

⌛ Testing commit 6f1344c with merge e123531...

Workflow: https://github.com/rust-lang/rust/actions/runs/45790303194

@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors yield

@rust-bors

rust-bors Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #165789.

@rust-bors

rust-bors Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

⌛ Testing commit 6f1344c with merge c1ec7aa...

Workflow: https://github.com/rust-lang/rust/actions/runs/45838495794

rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
Add two extra early return checks to `is_recursive_terminator`

This helps the new solver because resolution is more expensive for it than the old solver, so it's worth trying harder to avoid it.

The biggest win is for `nalgebra`, because it impls `Add` for a matrix type, and `+` calls on elements also use `Add::add`. So more precise checks are needed.

r? @oli-obk
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors yield

@rust-bors

rust-bors Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #166588.

@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors rollup=iffy
perf-sensitive rollup

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 26, 2026
…r, r=oli-obk

Add two extra early return checks to `is_recursive_terminator`

This helps the new solver because resolution is more expensive for it than the old solver, so it's worth trying harder to avoid it.

The biggest win is for `nalgebra`, because it impls `Add` for a matrix type, and `+` calls on elements also use `Add::add`. So more precise checks are needed.

r? @oli-obk
rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
…uwer

Rollup of 4 perf-sensitive pull requests

Successful merges:

 - #165489 (Add two extra early return checks to `is_recursive_terminator`)
 - #166248 (Make terminator not optional in BasicBlockData)
 - #166264 (Perf: Improve looking up previously scanned items in dead-code)
 - #166492 (rustc-lint: avoid allocation and Ident reconstruction in find_duplicated_parameters)
@rust-bors
rust-bors Bot merged commit 10260a0 into rust-lang:main Nov 26, 2026
14 of 15 checks passed
rust-bors Bot pushed a commit that referenced this pull request Nov 26, 2026
Rollup merge of #165489 - nnethercote:is_recursive_terminator, r=oli-obk

Add two extra early return checks to `is_recursive_terminator`

This helps the new solver because resolution is more expensive for it than the old solver, so it's worth trying harder to avoid it.

The biggest win is for `nalgebra`, because it impls `Add` for a matrix type, and `+` calls on elements also use `Add::add`. So more precise checks are needed.

r? @oli-obk
@rustbot rustbot added this to the 1.102.0 milestone Nov 26, 2026
@nnethercote
nnethercote deleted the is_recursive_terminator branch November 26, 2026 22:16
@rust-timer

Copy link
Copy Markdown

Note

This PR was benchmarked as part of triage of its containing rollup: triage URL.

Finished benchmarking commit (1ea7d49): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.5% [-1.4%, -0.2%] 22
Improvements ✅
(secondary)
-0.8% [-2.8%, -0.1%] 18
All ❌✅ (primary) -0.5% [-1.4%, -0.2%] 22

Max RSS (memory usage)

Results (secondary -2.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-4.9%, -1.0%] 3
All ❌✅ (primary) - - 0

Cycles

Results (primary -1.0%, secondary -2.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.7% [2.7%, 2.8%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.1% [-2.4%, -1.7%] 7
Improvements ✅
(secondary)
-2.6% [-2.8%, -2.3%] 2
All ❌✅ (primary) -1.0% [-2.4%, 2.8%] 9

Binary size

This perf run didn't have relevant results for this metric.

Artifact size: 405.62 MiB -> 405.60 MiB (-0.00%)

@rustbot rustbot removed the perf-regression Performance regression. label Nov 27, 2026
mehmettoplu-rs pushed a commit to mehmettoplu-rs/miri that referenced this pull request Nov 27, 2026
…uwer

Rollup of 4 perf-sensitive pull requests

Successful merges:

 - rust-lang/rust#165489 (Add two extra early return checks to `is_recursive_terminator`)
 - rust-lang/rust#166248 (Make terminator not optional in BasicBlockData)
 - rust-lang/rust#166264 (Perf: Improve looking up previously scanned items in dead-code)
 - rust-lang/rust#166492 (rustc-lint: avoid allocation and Ident reconstruction in find_duplicated_parameters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants