Skip to content

Conversation

@eggyal
Copy link
Contributor

@eggyal eggyal commented Jan 29, 2026

Ever since #103172, fn_abi_of_instance might look at a function's body to deduce certain codegen optimization attributes for its indirectly-passed parameters beyond what can be determined purely from its signature (namely today ArgAttribute::ReadOnly and ArgAttribute::CapturesNone). Since #130201, looking at a function's body in this way entails generating, for any coroutine-closures, additional by-move MIR bodies (which aren't represented in the HIR)—but this requires knowing the types of their context and consequently cycles can ensue if such bodies are generated before typeck is complete (such as during CTFE).

Since they have no bearing on the evaluation result, this patch breaks a subquery out from fn_abi_of_instance, fn_abi_of_instance_no_deduced_attrs, which returns the ABI before such parameter attributes are deduced; and that new subquery is used in CTFE instead (however, since parameter attributes are only deduced in optimized builds, as a performance optimization we avoid calling the new subquery unless we are performing such a build).

Fixes #151748
Fixes #152497

@rustbot
Copy link
Collaborator

rustbot commented Jan 29, 2026

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 29, 2026
@eggyal eggyal force-pushed the skip-deducing-parameter-attrs-during-ctfe branch from 5650820 to ea095f5 Compare January 29, 2026 22:26
@rust-log-analyzer

This comment has been minimized.

@eggyal

This comment was marked as outdated.

@rustbot rustbot 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 Jan 29, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 29, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@eggyal eggyal force-pushed the skip-deducing-parameter-attrs-during-ctfe branch from ea095f5 to de839fc Compare January 30, 2026 06:50
@RalfJung
Copy link
Member

Note that ABI "adjustments" typically do more than just deducing parameter attributes. So if "unadjusted" just refers to the attributes, that's confusing naming.

Also, having the full signature might be relevant for the UB checking that const-eval and Miri are doing. So it's at least slightly concerning that we shouldn't be able to access some of that info any more. What exactly is the difference between the signatures we obtain this way?

@eggyal

This comment was marked as outdated.

@RalfJung
Copy link
Member

RalfJung commented Jan 30, 2026

Looking at #151748, it seems like the underlying issue is that fn_sig_of_instance looks at the body of the function. That is indeed somewhat sus -- at least all the UB-relevant information should be deducible without the body. Please extend the PR description to explain this; it currently takes a bit of digging to fiure out what problem you're actually solving.

If we end up resolving this by splitting the query, it is very important that the queries have good documentation explaining their relationship. We want to avoid someone changing this code in the future in a way that removes too much information from the "unadjusted" signature.

@eggyal

This comment was marked as outdated.

@eggyal

This comment was marked as outdated.

@eggyal eggyal force-pushed the skip-deducing-parameter-attrs-during-ctfe branch from de839fc to 6a5ec89 Compare January 30, 2026 08:19
@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 Jan 30, 2026
@rust-log-analyzer

This comment has been minimized.

@eggyal eggyal force-pushed the skip-deducing-parameter-attrs-during-ctfe branch from 6a5ec89 to 132a633 Compare January 30, 2026 08:27
@RalfJung
Copy link
Member

That name and PR description are much better, thank you!

@RalfJung
Copy link
Member

@bors try
@rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Jan 30, 2026
…tfe, r=<try>

Do not deduce parameter attributes during CTFE
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 30, 2026
@RalfJung
Copy link
Member

I gave some feedback on the comments. I have not looked at the actual code changes at all.

@tmiasko
Copy link
Contributor

tmiasko commented Feb 12, 2026

Annoyingly the fix that I originally proposed (most recently in 132a633)—that did not perform parameter deduction during CTFE but had a perf regression, would have also fixed the new case in #152497.

I think the compile time impact for debug and incremental is because tcx.sess.opts.optimize != OptLevel::No && tcx.sess.opts.incremental.is_none() condition is evaluated too late. That is, the code ends up evaluating both fn_abi_of_instance and fn_abi_of_instance_no_deduced_attrs queries. I would try to organize the code so that when this condition is false we effectively end up using only one of the queries.

@eggyal

This comment has been minimized.

@tmiasko
Copy link
Contributor

tmiasko commented Feb 12, 2026

When deduced attributes are ignored, i.e., tcx.sess.opts.optimize != OptLevel::No && tcx.sess.opts.incremental.is_none() is false, the behavior of both queries is equivalent. In that case we can choose one query and use it consistently in both code generation and CTFE to avoid the overhead of a query system.

@eggyal

This comment has been minimized.

@eggyal eggyal force-pushed the skip-deducing-parameter-attrs-during-ctfe branch from 1077d1e to 53e5caf Compare February 12, 2026 12:44
@rustbot

This comment has been minimized.

@eggyal eggyal force-pushed the skip-deducing-parameter-attrs-during-ctfe branch from 53e5caf to 4acdb3a Compare February 12, 2026 12:58
@rustbot
Copy link
Collaborator

rustbot commented Feb 12, 2026

Some changes occurred in src/tools/cargo

cc @ehuss

@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Feb 12, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 12, 2026

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.

@rustbot

This comment has been minimized.

@eggyal
Copy link
Contributor Author

eggyal commented Feb 12, 2026

Ugh. I appear to have messed up that rebase. Apologies...

@rustbot label: -A-LLVM

`fn_abi_of_instance` can look at function bodies to deduce codegen
optimization attributes (namely `ArgAttribute::ReadOnly` and
`ArgAttribute::CapturesNone`) of indirectly-passed parameters.  This can
lead to cycles when performed during typeck, when such attributes are
irrelevant.

This patch breaks a subquery out from `fn_abi_of_instance`,
`fn_abi_of_instance_no_deduced_attrs`, which returns the ABI before such
parameter attributes are deduced; and that new subquery is used in CTFE
instead.
As a performance optimization, we altogether avoid ever invoking the
`fn_abi_of_instance_no_deduced_attrs` query in cases where the build
will not deduce parameter attributes.
@eggyal eggyal force-pushed the skip-deducing-parameter-attrs-during-ctfe branch from 4acdb3a to b5f8205 Compare February 12, 2026 13:01
@eggyal

This comment was marked as resolved.

@RalfJung
Copy link
Member

@bors try
@rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 12, 2026
…tfe, r=<try>

Avoid generating by-move coroutine MIR during parameter deduction
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 12, 2026
@eggyal eggyal changed the title Avoid generating by-move coroutine MIR during parameter deduction Do not deduce parameter attributes during CTFE Feb 12, 2026
@rustbot rustbot removed the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Feb 12, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 12, 2026

☀️ Try build successful (CI)
Build commit: 2a788d9 (2a788d90a94638c4928810c15d9ba4d807467a1e, parent: 7ad4e69ad585d8ff214f7b42d01f1959eda08f40)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2a788d9): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@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
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.1%] 4
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary -0.8%)

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

Cycles

Results (secondary 0.1%)

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)
8.3% [2.9%, 13.6%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.4% [-6.9%, -3.6%] 3
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 480.915s -> 480.739s (-0.04%)
Artifact size: 398.15 MiB -> 396.14 MiB (-0.50%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 12, 2026
@eggyal
Copy link
Contributor Author

eggyal commented Feb 12, 2026

Thanks @tmiasko ! 🎉

@rustbot ready

@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 Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

regression/1.93: async closures - error[E0391]: cycle detected when evaluating type-level constant 1.93 regression satisfying send obligation