Skip to content

Do not increase recursion depth for coroutine witness and rigid opaques when proving auto traits - #162275

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
adwinwhite:half-depth
Sep 25, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
adwinwhite:half-depth

Conversation

@adwinwhite

@adwinwhite adwinwhite commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

With deeply nested async calls, we can easily overflow evaluating auto trait goals as shown in #159228.
Users have no choice but increase the per-crate recursion_limit which is bad for compilation time/RSS. And downstream users may encounter the same warnings when calling library async functions.

We mitigate that by no longer increasing recursion depth for coroutine witness and rigid opaques when proving auto traits. See the comments for why it's okay to do so.
This fix actually makes the required depth a third of what it was before for async calls.

I've checked locally that bors and triagebot no longer have FCWs.

r? lcnr

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Sep 4, 2026
@adwinwhite
adwinwhite marked this pull request as ready for review September 4, 2026 06:13
@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 Sep 4, 2026
ty::Alias(
ty::IsRigid::Yes,
ty::AliasTy { kind: ty::Opaque { .. }, .. },
) => LowerAvailableDepth::No,

@lcnr lcnr Sep 7, 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.

hmm, this means we get

  • Vec<opaque>: Send 7
  • opaque: Send 7
  • hidden_ty: Send 6

instead of

  • Vec<opaque>: Send 7
  • opaque: Send 6
  • hidden_ty: Send 6

This feels slightly iffy as you can also prove opaque: Send using its item bounds 🤔

does just the coroutine witness stuff fix some of the fcws?

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.

Oh, I forgot about alias bound candidate.

The coroutine witness change alone fixes triagebot but not bors, unfortunately.

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.

hmm, we could moe the step_kind computation into this function and then use a separate goal source for the opaque type auto trait leakage?

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.

alternatively, hmm. want to merge just the coroutine witness change for now. I do just feel generally less confident about doing this for auto trait leakage 🤔

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.

I really don't know what I want here :> I guess doing it for opaque auto trait leakage is also fine 🤷 it also doesn#t feel too relevant or principled, no matter what we do 😅

@adwinwhite adwinwhite Sep 11, 2026 •

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.

It's awkward to pass the auto trait leakage info to search graph since the goal source is set by probe_and_evaluate_goal_for_constituent_tys which is used by more than auto traits.
Is it okay to check whether we're gonna pick alias bound candidate in this helper?
We'll still have

  • Vec: Send 7
  • opaque: Send 7
  • hidden: Send 6

but only when it's proved via auto trait leakage.

@rustbot

rustbot commented Sep 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.

@adwinwhite

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 Sep 11, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 11, 2026
Do not increase recursion depth for coroutine witness and rigid opaques when proving auto traits
@rust-bors

rust-bors Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 3a50673 (3a506736b86b6ad0edf17206fe49ac364edaaaeb)
Base parent: 9e9544d (9e9544da4cd757c74428bad35059cc8122fdcd7d)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (3a50673): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@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.2% [0.2%, 0.3%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -0.4%)

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

mean range count
Regressions ❌
(primary)
1.3% [0.4%, 5.9%] 7
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.4% [-7.4%, -2.8%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-7.4%, 5.9%] 10

Cycles

Results (primary -0.6%, secondary 6.8%)

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

mean range count
Regressions ❌
(primary)
0.9% [0.4%, 1.3%] 2
Regressions ❌
(secondary)
6.8% [6.8%, 6.8%] 1
Improvements ✅
(primary)
-0.9% [-2.0%, -0.5%] 10
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.6% [-2.0%, 1.3%] 12

Binary size

Results (primary -0.0%)

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.0% [-0.0%, -0.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 1

Bootstrap: 478.978s -> 478.032s (-0.20%)
Artifact size: 403.72 MiB -> 403.81 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 11, 2026
mycodedoesnotcompile2 pushed a commit to mycodedoesnotcompile2/arti_mirror that referenced this pull request Sep 15, 2026
Current nightly fails without this.

This change is undesirable for a number of reasons - see arti#2715.
But it is required for now to allow building with nightly.  We should
revert it as soon as possible.  (I am watching the upstream ticket and
the MR rust-lang/rust/pull/162275 which may fix it.)

Also, this is a very noisy change which affects many many crates, so
we hope to revert it before the next release!

THIS IS NOT THE ONLY COMMIT TO REVERT.  When reverting, use
  git log -G 'recursion.*limit'
to find appropriate commits an d
  git grep 'recursion.*limit'
to check you're done.
) => {
// We only want to skip lowering depth when the proving is done via auto
// trait leakage. If the goal can be proved via item bounds, we
// should lower depth faithfully.

@lcnr lcnr Sep 24, 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.

can you add a "FIXME: Ideally we'd instead lower the depth for the nested goal instead. Implementing this is a bit harder"

because you could have impl Sized: Send bound as a where-clause with TAIT/rtn. getting the recursion depth wrong isn't a big issue, but would still like to to not be slightly scuffed long-term

with this r=me

View changes since the review

@lcnr

lcnr commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit caadd68 has been approved by lcnr

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-review Status: Awaiting review from the assignee but also interested parties. labels Sep 24, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 24, 2026
Do not increase recursion depth for coroutine witness and rigid opaques when proving auto traits

With deeply nested async calls, we can easily overflow evaluating auto trait goals as shown in rust-lang#159228.
Users have no choice but increase the per-crate `recursion_limit` which is bad for compilation time/RSS. And downstream users may encounter the same warnings when calling library async functions.

We mitigate that by no longer increasing recursion depth for coroutine witness and rigid opaques when proving auto traits. See the comments for why it's okay to do so.
This fix actually makes the required depth a third of what it was before for async calls.

I've checked locally that `bors` and `triagebot` no longer have FCWs.

r? lcnr
rust-bors Bot pushed a commit that referenced this pull request Sep 25, 2026
Rollup of 9 pull requests

Successful merges:

 - #162228 (tests: Run more pauth tests in CI and make them pass)
 - #162493 (Add support for -Zsanitizer-cfi-minimal-runtime)
 - #163271 (add a leak check test)
 - #163282 (cleanup: clean up more dependencies that are unused)
 - #157562 (Avoid computing layout of enums with non-int discriminants)
 - #162275 (Do not increase recursion depth for coroutine witness and rigid opaques when proving auto traits)
 - #163037 (fix and test `va_arg` on `f128` on `x86`)
 - #163114 (Add regression test for hang on mutually recursive trait impls)
 - #163255 (Check the entire library and cg_clif workspaces for permitted deps in tidy)
rust-bors Bot pushed a commit that referenced this pull request Sep 25, 2026
Rollup of 8 pull requests

Successful merges:

 - #162228 (tests: Run more pauth tests in CI and make them pass)
 - #163271 (add a leak check test)
 - #163282 (cleanup: clean up more dependencies that are unused)
 - #157562 (Avoid computing layout of enums with non-int discriminants)
 - #162275 (Do not increase recursion depth for coroutine witness and rigid opaques when proving auto traits)
 - #163037 (fix and test `va_arg` on `f128` on `x86`)
 - #163114 (Add regression test for hang on mutually recursive trait impls)
 - #163255 (Check the entire library and cg_clif workspaces for permitted deps in tidy)
@rust-bors
rust-bors Bot merged commit 396431e into rust-lang:main Sep 25, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 25, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 25, 2026
Rollup merge of #162275 - adwinwhite:half-depth, r=lcnr

Do not increase recursion depth for coroutine witness and rigid opaques when proving auto traits

With deeply nested async calls, we can easily overflow evaluating auto trait goals as shown in #159228.
Users have no choice but increase the per-crate `recursion_limit` which is bad for compilation time/RSS. And downstream users may encounter the same warnings when calling library async functions.

We mitigate that by no longer increasing recursion depth for coroutine witness and rigid opaques when proving auto traits. See the comments for why it's okay to do so.
This fix actually makes the required depth a third of what it was before for async calls.

I've checked locally that `bors` and `triagebot` no longer have FCWs.

r? lcnr
mycodedoesnotcompile2 pushed a commit to mycodedoesnotcompile2/arti_mirror that referenced this pull request Oct 6, 2026
Current nightly fails without this.

This change is undesirable for a number of reasons - see arti#2715.
But it is required for now to allow building with nightly.  We should
revert it as soon as possible.  (I am watching the upstream ticket and
the MR rust-lang/rust/pull/162275 which may fix it.)

Also, this is a very noisy change which affects many many crates, so
we hope to revert it before the next release!

THIS IS NOT THE ONLY COMMIT TO REVERT.  When reverting, use
  git log -G 'recursion.*limit'
to find appropriate commits an d
  git grep 'recursion.*limit'
to check you're done.
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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants