Skip to content

Encode coroutine_by_move_body_def_id in crate metadata#130201

Merged
bors merged 3 commits intorust-lang:masterfrom
compiler-errors:foreign-synthetic-body
Sep 17, 2024
Merged

Encode coroutine_by_move_body_def_id in crate metadata#130201
bors merged 3 commits intorust-lang:masterfrom
compiler-errors:foreign-synthetic-body

Conversation

@compiler-errors
Copy link
Contributor

@compiler-errors compiler-errors commented Sep 10, 2024

We synthesize the MIR for a by-move body for the FnOnce implementation of async closures. It can be accessed with the coroutine_by_move_body_def_id query. We weren't encoding this query in the metadata though, nor were we properly recording that synthetic MIR in mir_keys, so the optimized_mir wasn't getting encoded either!

Stacked on top is a fix to consider DefKind::SyntheticCoroutineBody to return true in several places I missed. Specifically, we should consider the def-kind in fn DefKind::is_fn_like(), since that's what we were using to make sure we ensure query mir_inliner_callees before the MIR gets stolen for the body. This led to some CI failures that were caught by miri but which I added a test for.

@rustbot
Copy link
Collaborator

rustbot commented Sep 10, 2024

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Sep 10, 2024
@rustbot
Copy link
Collaborator

rustbot commented Sep 10, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Contributor Author

hahah this is blocked on #130199, that's where the ci test failure comes from.

@bors
Copy link
Collaborator

bors commented Sep 10, 2024

☔ The latest upstream changes (presumably #130200) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Contributor

lcnr commented Sep 17, 2024

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 17, 2024

📌 Commit 4beb1cf has been approved by lcnr

It is now in the queue for this repository.

@bors bors 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 17, 2024
fee1-dead added a commit to fee1-dead-contrib/rust that referenced this pull request Sep 17, 2024
…body, r=lcnr

Encode `coroutine_by_move_body_def_id` in crate metadata

We synthesize the MIR for a by-move body for the `FnOnce` implementation of async closures. It can be accessed with the `coroutine_by_move_body_def_id` query. We weren't encoding this query in the metadata though, nor were we properly recording that synthetic MIR in `mir_keys`, so the `optimized_mir` wasn't getting encoded either!

Stacked on top is a fix to consider `DefKind::SyntheticCoroutineBody` to return true in several places I missed. Specifically, we should consider the def-kind in `fn DefKind::is_fn_like()`, since that's what we were using to make sure we ensure `query mir_inliner_callees` before the MIR gets stolen for the body. This led to some CI failures that were caught by miri but which I added a test for.
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 17, 2024
…fee1-dead

Rollup of 8 pull requests

Successful merges:

 - rust-lang#128961 (Fix rust-lang#128930: Print documentation of CLI options missing their arg)
 - rust-lang#129073 (Relate receiver invariantly in method probe for `Mode::Path`)
 - rust-lang#129674 (Add new_cyclic_in for Rc and Arc)
 - rust-lang#130201 (Encode `coroutine_by_move_body_def_id` in crate metadata)
 - rust-lang#130275 (Don't call `extern_crate` when local crate name is the same as a dependency and we have a trait error)
 - rust-lang#130440 (Don't ICE in `opaque_hidden_inferred_bound` lint for RPITIT in trait with no default method body)
 - rust-lang#130454 (tests: allow trunc/select instructions to be missing)
 - rust-lang#130458 (`rustc_codegen_ssa` cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 17, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#128535 (Format `std::env::consts` docstrings with markdown backticks)
 - rust-lang#128961 (Fix rust-lang#128930: Print documentation of CLI options missing their arg)
 - rust-lang#129988 (Use `Vec` in `rustc_interface::Config::locale_resources`)
 - rust-lang#130201 (Encode `coroutine_by_move_body_def_id` in crate metadata)
 - rust-lang#130275 (Don't call `extern_crate` when local crate name is the same as a dependency and we have a trait error)
 - rust-lang#130314 (Use the same precedence for all macro-like exprs)
 - rust-lang#130440 (Don't ICE in `opaque_hidden_inferred_bound` lint for RPITIT in trait with no default method body)
 - rust-lang#130458 (`rustc_codegen_ssa` cleanups)
 - rust-lang#130469 (Mark `where_clauses_object_safety` as removed)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ddcb9c1 into rust-lang:master Sep 17, 2024
@rustbot rustbot added this to the 1.83.0 milestone Sep 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 17, 2024
Rollup merge of rust-lang#130201 - compiler-errors:foreign-synthetic-body, r=lcnr

Encode `coroutine_by_move_body_def_id` in crate metadata

We synthesize the MIR for a by-move body for the `FnOnce` implementation of async closures. It can be accessed with the `coroutine_by_move_body_def_id` query. We weren't encoding this query in the metadata though, nor were we properly recording that synthetic MIR in `mir_keys`, so the `optimized_mir` wasn't getting encoded either!

Stacked on top is a fix to consider `DefKind::SyntheticCoroutineBody` to return true in several places I missed. Specifically, we should consider the def-kind in `fn DefKind::is_fn_like()`, since that's what we were using to make sure we ensure `query mir_inliner_callees` before the MIR gets stolen for the body. This led to some CI failures that were caught by miri but which I added a test for.
eggyal added a commit to eggyal/rust that referenced this pull request Feb 6, 2026
Ever since rust-lang#130201, the `mir_keys` query generates additional by-move
MIR bodies (that aren't in the HIR) for coroutine-closures. However,
computing such bodies before typeck is complete can lead to cycles.

Ever since rust-lang#103172, in order to compute a function's ABI (which happens
during CTFE), it may be necessary to look at the function's body in
order 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`).

Prior to this patch, such parameter deduction is bypassed for functions
that have no body by calling upon the `is_mir_available` query, which in
turn calls upon `mir_keys`, and cycles can ensue. This patch breaks such
cycles by using instead a new query, `is_mir_for_hir_available`, which
only considers MIR bodies from the HIR without calling upon `mir_keys`.
eggyal added a commit to eggyal/rust that referenced this pull request Feb 6, 2026
Ever since `rust-lang#130201`, the `mir_keys` query generates additional by-move
MIR bodies (that aren't in the HIR) for coroutine-closures. However,
computing such bodies before typeck is complete can lead to cycles.

Ever since `rust-lang#103172`, in order to compute a function's ABI (which
happens during CTFE), it may be necessary to look at the function's body
in order 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`).

Prior to this patch, such parameter deduction is bypassed for functions
that have no body by calling upon the `is_mir_available` query, which in
turn calls upon `mir_keys`, and cycles can ensue. This patch breaks such
cycles by using instead a new query, `is_mir_for_hir_available`, which
only considers MIR bodies from the HIR without calling upon `mir_keys`.
rust-bors bot pushed a commit that referenced this pull request Mar 4, 2026
…tfe, r=RalfJung

Do not deduce parameter attributes during CTFE

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/151842)*

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 original query unless we are performing such a build).

Fixes #151748
Fixes #152497
rust-bors bot pushed a commit that referenced this pull request Mar 4, 2026
…tfe, r=RalfJung

Do not deduce parameter attributes during CTFE

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/151842)*

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 original query unless we are performing such a build).

Fixes #151748
Fixes #152497
github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Mar 5, 2026
…tfe, r=RalfJung

Do not deduce parameter attributes during CTFE

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/151842)*

Ever since rust-lang/rust#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 rust-lang/rust#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 original query unless we are performing such a build).

Fixes rust-lang/rust#151748
Fixes rust-lang/rust#152497
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Mar 5, 2026
…tfe, r=RalfJung

Do not deduce parameter attributes during CTFE

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/151842)*

Ever since rust-lang/rust#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 rust-lang/rust#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 original query unless we are performing such a build).

Fixes rust-lang/rust#151748
Fixes rust-lang/rust#152497
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.

5 participants