Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement #[rustc_align_static(N)] on statics #146178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
folkertdev wants to merge 1 commit into rust-lang:master
base: master
Choose a base branch
Loading
from folkertdev:static-align

Conversation

Copy link
Contributor

@folkertdev folkertdev commented Sep 3, 2025

Tracking issue: #146177

#![feature(static_align)]
#[rustc_align_static(64)]
static SO_ALIGNED: u64 = 0;

We need a different attribute than rustc_align because unstable attributes are tied to their feature (we can't have two unstable features use the same unstable attribute). Otherwise this uses all of the same infrastructure as #[rustc_align].

r? @traviscross

@rustbot rustbot added A-attributes Area: Attributes (`#[...]`, `#![...]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 3, 2025
Copy link
Collaborator

rustbot commented Sep 3, 2025

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Copy link
Member

RalfJung commented Sep 3, 2025

we can't have two unstable features use the same unstable attribute

What do you mean by "use"? How does a feature "use" an attribute?
All rustc_ attributes are unstable anyway...

@@ -621,6 +621,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
gated!(rustc_align, Normal, template!(List: &["alignment"]), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(rustc_align)),
gated!(rustc_align_static, Normal, template!(List: &["alignment"]), DuplicatesOk, EncodeCrossCrate::No, static_align, experimental!(rustc_align_static)),
Copy link
Contributor Author

@folkertdev folkertdev Sep 3, 2025

Choose a reason for hiding this comment

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

@RalfJung this is where the attribute gets declared, and the feature name on this line (static_align in this case) must be unique

Copy link
Member

@RalfJung RalfJung Sep 3, 2025

Choose a reason for hiding this comment

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

That's very odd, why does it have to be unique? That's not how features work anywhere else in the compiler, AFAIK.

Copy link
Contributor Author

@folkertdev folkertdev Sep 3, 2025

Choose a reason for hiding this comment

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

ah, sorry, what I meant by unique is that an attribute must be tied to one unstable feature. #[rustc_align] is already tied to fn_align, so it can't also be used for static_align.

So, one unstable feature can "contain" multiple attributes, but an attribute always is tied to only one unstable feature.

Copy link
Member

@RalfJung RalfJung Sep 4, 2025

Choose a reason for hiding this comment

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

Ah, by "attribute used for feature" you mean "attribute is gated by feature". That's a rather confusing and non-standard way of saying things.^^

So what you want is to have a separate feature gate for aligning functions vs aligning statics, and the attribute registration macro isn't flexible enough to allow that. rustc_align is for functions only, despite its name sounding more general.

Since these are all temporary names anyway, I guess it doesn't matter too much, but when it comes to stabilization we very much might need the ability to stabilize an attribute in some positions while leaving it unstable elsewhere. Otherwise we have no way of unstably extending where an existing stable attribute can be used. So this limitation of attribute feature gating seems like it could become problematic. Cc @jdonszelmann

Copy link
Contributor

This needs tests for:

  • Thread locals (#[thread_local] and thread_local!)
  • extern block statics

This comment has been minimized.

Copy link
Contributor Author

extern

Is there any interesting behavior to test here? (I'll add a test for the attribute being valid).

thread_local!

hmm, the thread_local! macro actually applies the attribute to a constant

($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $($init:tt)*) => {
$(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> =
$crate::thread::local_impl::thread_local_inner!(@key $t, $($init)*);
},

@traviscross traviscross changed the title (削除) implement #[rustc_align_static(N)] on statics (削除ここまで) (追記) Implement #[rustc_align_static(N)] on statics (追記ここまで) Sep 3, 2025
@traviscross traviscross added the F-static_align #![feature(static_align)] label Sep 3, 2025

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

Here is an implementation for thread_local!: Jules-Bertholet@ad038e6

Copy link
Collaborator

rustbot commented Sep 5, 2025

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

This comment has been minimized.

Copy link
Contributor Author

That's odd, the miri tests pass for me locally. Do those somehow cache the standard library even when you don't pass --keep-stage?

Copy link
Member

RalfJung commented Sep 5, 2025

Miri has its own standard library build but it should usually be recompiled automatically when anything changed.

Copy link
Member

RalfJung commented Sep 5, 2025

The error might only occur after merging the branch with latest master (which happens implicitly in CI).

Copy link
Contributor

Jules-Bertholet commented Sep 5, 2025
edited
Loading

which happens implicitly in CI

Doesn’t that apply only to Bors CI? (E.g. Bors try or Bors r+)

Copy link
Member

RalfJung commented Sep 5, 2025

No, Github merges the PR with the master branch for PR CI.

Pretty terrible IMO in terms of reproducibility, but well, it is what it is.

Copy link
Contributor Author

So would a miri sync fix this (or at least make it reproducible locally)?

Copy link
Member

RalfJung commented Sep 5, 2025

If my theory is correct, rebasing over the latest master commit should let you reproduce the issue.

Copy link
Member

RalfJung commented Sep 5, 2025
edited
Loading

Oh, I just noticed the target. The failure is on x86_64-pc-windows-gnu. The new thread-local macro logic is probably just broken on Windows.
./x test miri --target x86_64-pc-windows-gnu -- align should reproduce this.

EDIT: And indeed, it does.

This comment has been minimized.

Copy link
Contributor

The new thread-local macro logic is probably just broken on Windows.

Yes, it is, I’ll fix it

Copy link
Contributor

Yes, it is, I’ll fix it

Here you go: Jules-Bertholet@e0cc8eb

(It’s not complete yet; I still need to add cfg_attr support, and a few more tests.)

Copy link
Contributor Author

given how complicated the thread_local! stuff is getting, maybe that should be its own PR as a follow-up?

Copy link
Contributor

cfg_attr support

Done: Jules-Bertholet@ed2f8cd

maybe that should be its own PR as a follow-up?

Sure, if that’s what you prefer.

Copy link
Collaborator

rustbot commented Sep 6, 2025

This PR was rebased onto a different master 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.

Copy link
Contributor Author

I removed the thread_local! stuff for now, because it got quite complex and will need detailed review from T-libs I'd assume. This PR now has just the changes that are relevant to lang/compiler. Assuming CI makes it, I think this is ready, with the understanding that there will be a follow-up to add support for thread_local!.

Jules-Bertholet reacted with thumbs up emoji

Copy link
Contributor

@traviscross traviscross left a comment
edited by rustbot
Loading

Choose a reason for hiding this comment

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

Looks reasonable to me. (Noted some nits.)

r? @RalfJung

View changes since this review

@rustbot rustbot assigned RalfJung and unassigned traviscross Sep 6, 2025
Copy link
Member

RalfJung commented Sep 7, 2025

The MIR interpreter parts look fine, but I don't have time to dig into the entire thing, sorry.
r? @jdonszelmann maybe because there's a bunch of attribute logic?

jdonszelmann reacted with thumbs up emoji

Copy link
Collaborator

rustbot commented Sep 7, 2025

jdonszelmann is currently at their maximum review capacity.
They may take a while to respond.

We need a different attribute than `rustc_align` because unstable attributes are
tied to their feature (we can't have two unstable features use the same
unstable attribute). Otherwise this uses all of the same infrastructure
as `#[rustc_align]`.
@traviscross traviscross added the I-lang-radar Items that are on lang's radar and will need eventual work or consideration. label Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@RalfJung RalfJung RalfJung left review comments

@traviscross traviscross traviscross approved these changes

+1 more reviewer

@Jules-Bertholet Jules-Bertholet Jules-Bertholet left review comments

Reviewers whose approvals may not affect merge requirements
Labels
A-attributes Area: Attributes (`#[...]`, `#![...]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-static_align #![feature(static_align)] I-lang-radar Items that are on lang's radar and will need eventual work or consideration. 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
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /