Skip to content

peel_transparent_wrappers only works on non-1ZST - #162000

Open
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:peel_transparent_wrappers
Open

peel_transparent_wrappers only works on non-1ZST#162000
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:peel_transparent_wrappers

Conversation

@RalfJung

Copy link
Copy Markdown
Member

@rustbot

rustbot commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

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 Aug 30, 2026
Comment on lines +115 to +116
// Scalable vector are never 1-ZST. FIXME: is that correct?
if layout.peel_transparent_wrappers_from_non_1zst(bx).deref().is_scalable_vector() {

@RalfJung RalfJung Aug 30, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@davidtwco is it correct that scalable vectors are never 1ZST?
What does is_sized even say for them?

View changes since the review

Comment on lines +532 to +536
if layout.peel_transparent_wrappers_from_non_1zst(self).ty.is_scalable_vector() {
let vscale = self.vscale(self.type_i64());
self.mul(vscale, bytes)
} else {
bytes

@RalfJung RalfJung Aug 30, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This code seems quite fragile, why does it need to special-case scalable vectors and how do we know there aren't any other special cases that have been forgotten here?

But that's pre-existing... still, quite concerning IMO. Cc @davidtwco @ZuseZ4

View changes since the review

// Accept (transparently wrapped) scalar 64-bit primitives.
matches!(
layout.peel_transparent_wrappers(&cx).ty.kind(),
layout.peel_transparent_wrappers_from_non_1zst(&cx).ty.kind(),

@RalfJung RalfJung Aug 30, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

HIR uses layout?!? That's a pretty stark layering violation, isn't it?

View changes since the review

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.

With CMSE we can ensure that this works out. We need to know how many registers will be used by the signature to error (even in cargo check builds) when the arguments don't fit in the available space.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't doubt that it works, but it's a hack in terms of compiler layering. It's one more step towards an unmaintainable spaghetti mess.

@rust-log-analyzer

This comment has been minimized.

@RalfJung
RalfJung force-pushed the peel_transparent_wrappers branch from f539126 to 973ef1d Compare August 30, 2026 08:05
// So we never treat 1-ZST indirectly.
if self.is_1zst() {
return false;
}

@RalfJung RalfJung Aug 30, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This basically says that the #[rustc_pass_indirectly_in_non_rustic_abis] attribute is a NOP on 1-ZST. I think that's reasonable. A better approach would be to have a non_trivial_abi_field and declare the attribute to make the ABI non-trivial, but before #157973 lands I don't think it makes sense to implement anything like that and anyway the attribute is perma-unstable.

But I am not sure where to document it, the attribute seems wholly undocumented?

View changes since the review

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 think leaving a FIXME for making this non_trivial_abi_field after #157973 is merged (since it's already in proposed FCP) is fine for now. I think #[rustc_pass_indirectly_in_non_rustic_abis] is primarily documented on TyAndLayout::pass_indirectly_in_non_rustic_abis and in the VaList implementation at the moment.

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.

At the moment it's just an implementation detail of c-variadic functions.

@RalfJung RalfJung Aug 30, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

At the moment it's just an implementation detail of c-variadic functions.

I know that's the intent, but even then it needs docs that say that. ;)
But we're generally not doing great regarding documentation of rustc attributes.

I can add a FIXME.

@RalfJung
RalfJung force-pushed the peel_transparent_wrappers branch from 973ef1d to e7b7d5b Compare August 30, 2026 12:33
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.

5 participants