Skip to content

Conversation

folkertdev
Copy link
Contributor

@folkertdev folkertdev commented Oct 1, 2025

tracking issue: #75835
fixes #147242

Refactors some logic to be more robust in the future, and then disallows impl Trait as a return type for the cmse ABIs.

The is_valid_cmse_output_layout function disallows union values like before. That is not entirely correct, but preserves the current behavior. Some additional logic is needed for union values (and any types where parts may be uninitialized) that I'll tackle in a later PR.

can be reviewed commit-by-commit.

r? types

@folkertdev folkertdev added the F-cmse_nonsecure_entry `#![feature(cmse_nonsecure_entry)]` label Oct 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 1, 2025

HIR ty lowering was modified

cc @fmease

@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 Oct 1, 2025
@davidtwco
Copy link
Member

r? @davidtwco

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 7, 2025

📌 Commit 3571274 has been approved by davidtwco

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 Oct 7, 2025
@fmease
Copy link
Member

fmease commented Oct 7, 2025

@bors r-

Sorry, for the late r- I only looked at the contents right now (I'm subscribed due to it modifying HIR ty lowering).

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 7, 2025
@folkertdev folkertdev force-pushed the cmse-bail-impl-trait branch from 3571274 to fbdc685 Compare October 7, 2025 15:31
@fmease
Copy link
Member

fmease commented Oct 7, 2025

Thanks for addressing my concern!

@bors r=davidtwco

@bors
Copy link
Collaborator

bors commented Oct 7, 2025

📌 Commit fbdc685 has been approved by davidtwco

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 7, 2025
bors added a commit that referenced this pull request Oct 7, 2025
Rollup of 7 pull requests

Successful merges:

 - #145943 (stdlib docs: document lifetime extension for `format_args!`'s arguments)
 - #147243 (cmse: disallow `impl Trait` in `cmse-nonsecure-entry` return types)
 - #147402 ([rustdoc] Don't serialize & deserialize data that doesn't go OTW)
 - #147418 (Fix target list of `link_section`)
 - #147429 (Print tip for human error format in runtest)
 - #147441 (Fix comments error for Provenance impls)
 - #147442 (c-variadic: fix thir-print for `...` without a pattern)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7ab1fd1 into rust-lang:master Oct 7, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 7, 2025
rust-timer added a commit that referenced this pull request Oct 7, 2025
Rollup merge of #147243 - folkertdev:cmse-bail-impl-trait, r=davidtwco

cmse: disallow `impl Trait` in `cmse-nonsecure-entry` return types

tracking issue: #75835
fixes #147242

Refactors some logic to be more robust in the future, and then disallows `impl Trait` as a return type for the cmse ABIs.

The `is_valid_cmse_output_layout` function disallows `union` values like before. That is not entirely correct, but preserves the current behavior. Some additional logic is needed for `union` values (and any types where parts may be uninitialized) that I'll tackle in a later PR.

can be reviewed commit-by-commit.

r? types
Comment on lines +174 to +176
// Here we explicitly disallow `impl Trait` in the `cmse-nonsecure-entry` return type too, to
// prevent query cycles when calculating the layout. This ABI is meant to be used with
// `#[no_mangle]` or similar, so generics in the type really don't make sense.
Copy link
Member

Choose a reason for hiding this comment

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

for the record opaque types are not generics. fn foo() -> impl Trait's return type is some fully concrete non generic type, its just not explicitly written out. I think you're right that no_mangle'd functions with RPITs are silly though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

really? My intuition is that -> impl Trait is polymorphic and that it is roughly equivalent to fn foo<T: Trait>() -> T. You'd need to pick a concrete imlementation of the trait in order to actually be able to calculate the layout of the return type (and from that the ABI).

Is there some better word for "the type is not known enough to calculate the layout"?

Copy link
Member

Choose a reason for hiding this comment

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

the type of RPITs should be known enough to calculate the layout of the return type as long as opaque types are able to be properly normalized. impl Trait only desugars to a generic parameter in argument position, i.e. fn foo(a: impl Trait) desugars as you say

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh interesting, it actually looks at the body to figure out the concrete type if it occurs just in return position

https://godbolt.org/z/KhfhrxPG6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But at the point where we attempt to generate the layout for these entry functions, somehow there is a loop in the calculation

https://godbolt.org/z/K58sMorf3

(that godbolt only works with current nightly, but the same cycle is in the issue #147242)

anyway we're totally fine with just disallowing impl Trait entirely, it's a simple rule that doesn't really limit any practical use.

Copy link
Member

Choose a reason for hiding this comment

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

yeah I would be interested in seeing where the cycle comes from, but it does seem fine to just altogether forbid this as RPITs in no_mangle functions seems like a big footgun/code smell

github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Oct 9, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#145943 (stdlib docs: document lifetime extension for `format_args!`'s arguments)
 - rust-lang#147243 (cmse: disallow `impl Trait` in `cmse-nonsecure-entry` return types)
 - rust-lang#147402 ([rustdoc] Don't serialize & deserialize data that doesn't go OTW)
 - rust-lang#147418 (Fix target list of `link_section`)
 - rust-lang#147429 (Print tip for human error format in runtest)
 - rust-lang#147441 (Fix comments error for Provenance impls)
 - rust-lang#147442 (c-variadic: fix thir-print for `...` without a pattern)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-cmse_nonsecure_entry `#![feature(cmse_nonsecure_entry)]` 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.

cmse-nonsecure-entry hits query cycle when returning impl Trait
6 participants