Skip to content

Align attr fixes #143206

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
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Jules-Bertholet
Copy link
Contributor

@Jules-Bertholet Jules-Bertholet commented Jun 29, 2025

  • Remove references to the superseded repr(align) syntax
  • Allow the attribute on fn items in extern blocks
  • Test attribute in combination with async fn and dyn

r? workingjubilee

Tracking issue: #82232
@rustbot label A-attributes F-fn_align T-compiler

@rustbot
Copy link
Collaborator

rustbot commented Jun 29, 2025

r? @WaffleLapkin

rustbot has assigned @WaffleLapkin.
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 A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Jun 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 29, 2025

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

cc @jdonszelmann

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs

cc @jdonszelmann

@rustbot rustbot added the F-fn_align `#![feature(fn_align)]` label Jun 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 29, 2025

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

@bors
Copy link
Collaborator

bors commented Jul 1, 2025

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

@workingjubilee
Copy link
Member

This requires rebase.

@workingjubilee
Copy link
Member

@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 1, 2025

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

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 1, 2025
@Jules-Bertholet
Copy link
Contributor Author

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

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

This is good as-is but I would like to see more tests. You can add them now or as a followup PR or open an issue instead. r=me either way.

Comment on lines +125 to +127
#[align(32)]
#[align(256)]
extern "C" fn align_unmangled() {}
Copy link
Member

Choose a reason for hiding this comment

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

Weren't we going to warn on applying align twice?

I mean that shouldn't affect the codegen test, I'm just realizing that I don't know for sure if we have a test that does check that we warn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be nice to have a warning, but it’s not required for the MVP. It hasn’t been implemented yet.

#![feature(fn_align)]

trait Test {
#[align(4096)]
Copy link
Member

Choose a reason for hiding this comment

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

4096 is pretty big but I am realizing I don't see a test for oversized aligns that we should definitely reject, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

4096 I believe is the highest align that should work more or less everywhere. Because this test relies on converting to a function pointer, choosing a high value minimizes the chance of “getting lucky”.

Rejecting high alignments on platforms that don’t support them is being worked on by others, I think.

@workingjubilee
Copy link
Member

@bors delegate+

@bors
Copy link
Collaborator

bors commented Jul 1, 2025

✌️ @Jules-Bertholet, you can now approve this pull request!

If @workingjubilee told you to "r=me" after making some further change, please make that change, then do @bors r=@workingjubilee

@workingjubilee
Copy link
Member

It's also possible that the tests already exist and I was just too ferrisClueless.jpg to find them

@Jules-Bertholet
Copy link
Contributor Author

@bors r=@workingjubilee

@bors
Copy link
Collaborator

bors commented Jul 1, 2025

📌 Commit 440bf29 has been approved by workingjubilee

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 Jul 1, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 1, 2025
…r=workingjubilee

Align attr fixes

- Remove references to the superseded `repr(align)` syntax
- Allow the attribute on fn items in `extern` blocks
- Test attribute in combination with `async fn` and `dyn`

r? workingjubilee

`@rustbot` label A-attributes F-fn_align T-compiler
bors added a commit that referenced this pull request Jul 2, 2025
Rollup of 12 pull requests

Successful merges:

 - #141829 (Specialize sleep_until implementation for unix (except mac))
 - #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions)
 - #142138 (Add `Vec::into_chunks`)
 - #142321 (Expose elf abi on ppc64 targets)
 - #142568 (Use the .drectve section for exporting symbols from dlls on Windows)
 - #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`)
 - #143038 (avoid suggesting traits from private dependencies)
 - #143194 (fix bitcast of single-element SIMD vectors)
 - #143206 (Align attr fixes)
 - #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition)
 - #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic)
 - #143274 (ci: support optional jobs)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 2, 2025
…r=workingjubilee

Align attr fixes

- Remove references to the superseded `repr(align)` syntax
- Allow the attribute on fn items in `extern` blocks
- Test attribute in combination with `async fn` and `dyn`

r? workingjubilee

``@rustbot`` label A-attributes F-fn_align T-compiler
bors added a commit that referenced this pull request Jul 2, 2025
Rollup of 11 pull requests

Successful merges:

 - #141829 (Specialize sleep_until implementation for unix (except mac))
 - #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions)
 - #142138 (Add `Vec::into_chunks`)
 - #142321 (Expose elf abi on ppc64 targets)
 - #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`)
 - #143038 (avoid suggesting traits from private dependencies)
 - #143194 (fix bitcast of single-element SIMD vectors)
 - #143206 (Align attr fixes)
 - #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition)
 - #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic)
 - #143274 (ci: support optional jobs)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 2, 2025
…r=workingjubilee

Align attr fixes

- Remove references to the superseded `repr(align)` syntax
- Allow the attribute on fn items in `extern` blocks
- Test attribute in combination with `async fn` and `dyn`

r? workingjubilee

```@rustbot``` label A-attributes F-fn_align T-compiler
bors added a commit that referenced this pull request Jul 2, 2025
Rollup of 12 pull requests

Successful merges:

 - #141847 (Explain `TOCTOU` on the top of `std::fs`, and reference it in functions)
 - #142138 (Add `Vec::into_chunks`)
 - #142321 (Expose elf abi on ppc64 targets)
 - #142886 (ci: aarch64-gnu: Stop skipping `panic_abort_doc_tests`)
 - #143038 (avoid suggesting traits from private dependencies)
 - #143194 (fix bitcast of single-element SIMD vectors)
 - #143206 (Align attr fixes)
 - #143231 (Suggest use another lifetime specifier instead of underscore lifetime)
 - #143232 ([COMPILETEST-UNTANGLE 3/N] Use "directives" consistently within compiletest)
 - #143258 (Don't recompute `DisambiguatorState` for every RPITIT in trait definition)
 - #143260 (Use the correct export kind for __rust_alloc_error_handler_should_panic)
 - #143274 (ci: support optional jobs)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r-
#143313 (comment)

@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 Jul 2, 2025
@workingjubilee
Copy link
Member

workingjubilee commented Jul 2, 2025

what the ferris?
wasm the fuck?

@Jules-Bertholet
Copy link
Contributor Author

Jules-Bertholet commented Jul 2, 2025

Investigating further, it seems #[align(…)] on functions just doesn’t work in WASM. I think LLVM is simply ignoring it. I believe it should be possible to implement, but I’m not a WASM expert…

@RalfJung
Copy link
Member

RalfJung commented Jul 3, 2025

In wasm, functions don't have an "address", it's not a von-Neumann architecture. Instead, there is a dedicated table and one can pick an integer index into the table when doing a dynamic call.

I don't know how exactly LLVM translates fn ptrs to wasm. Is the fn ptr directly the index into that table? Then indeed #[align] on functions just doesn't make sense... LLVM would have to put functions at even indices into the table, or something like that.

Cc @alexcrichton

@Jules-Bertholet
Copy link
Contributor Author

Instead, there is a dedicated table and one can pick an integer index into the table when doing a dynamic call.

Yes. My thinking is that LLVM could fill the table with dummy entries in order to align things.

@RalfJung
Copy link
Member

RalfJung commented Jul 3, 2025

It's completely silly to "align" things in that table, though... isn't it?

@Jules-Bertholet
Copy link
Contributor Author

If you are doing function pointer tagging, it might be necessary. But yes, the usefulness is limited.

@folkertdev
Copy link
Contributor

So, should we just apply a target-specific minimum of #[align(1)] for wasm? (much like on windows targets the limit will be 8192)

@RalfJung
Copy link
Member

RalfJung commented Jul 3, 2025

We should definitely have an issue for this rather than discussing this in a PR, so I made one: #143368.

@RalfJung
Copy link
Member

RalfJung commented Jul 3, 2025

For this PR I think we can just mark the test as skipped for wasm with a link to the issue.

(I also added a link to the tracking issue, those are super useful when figuring out how a feature changed...)

@alexcrichton
Copy link
Member

Looks like this has already mostly been answered, but can confirm:

I don't know how exactly LLVM translates fn ptrs to wasm. Is the fn ptr directly the index into that table?

This is correct, function pointers in wasm are table indices (e.g. 1, 2, 3, ...). The table index 0 is skipped to provide the guarantee that function pointers are never 0/null (also that 0/null is an invalid function pointer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) F-fn_align `#![feature(fn_align)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

9 participants