Skip to content

Rename align to default_align on Scalar and Primitive#158542

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
scottmcm:scalar-but-packed
Jul 1, 2026
Merged

Rename align to default_align on Scalar and Primitive#158542
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
scottmcm:scalar-but-packed

Conversation

@scottmcm

Copy link
Copy Markdown
Member

To emphasize that just because you see a Scalar(I32) that doesn't really tell you anything about the alignment it has -- one should be looking at the type (well, the place) for that.

(The size method doesn't really have that problem -- i32 is always 4 bytes, no matter the context -- so is left untouched.)

No actual layout or behaviour changes in this PR. Just the rename and some comments.

r? @workingjubilee

@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

@rustbot rustbot added 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 Jun 29, 2026
@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

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

@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the scalar-but-packed branch from 4edeed7 to 2aaf9e0 Compare June 29, 2026 06:59
@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

miri is developed in its own repository. If possible, consider making this change to rust-lang/miri instead.

cc @rust-lang/miri

Comment thread compiler/rustc_abi/src/lib.rs Outdated
///
/// This is the type alignment for the corresponding built-in.
/// In other contexts it might have different alignment.
pub fn platform_align<C: HasDataLayout>(self, cx: &C) -> AbiAlign {

@RalfJung RalfJung Jun 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Naming bikeshed: what about default_align?

View changes since the review

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.

Sounds good -- better conveys "might not the the default" elsewhere than "platform" does since of course we're always targeting just one platform.

Comment thread compiler/rustc_abi/src/lib.rs Outdated
Comment thread compiler/rustc_abi/src/lib.rs Outdated
To emphasize that just because you see a `Scalar(I32)` that doesn't really tell you anything about the alignment it has -- one should be looking at the type (well, the place) for that.

No actual layout or behaviour changes in *this* PR.
@scottmcm scottmcm force-pushed the scalar-but-packed branch from 2aaf9e0 to f98365f Compare June 29, 2026 16:48
@scottmcm scottmcm changed the title Rename align to platform_align on Scalar and Primitive Rename align to default_align on Scalar and Primitive Jun 29, 2026
Co-authored-by: Ralf Jung <post@ralfj.de>
///
/// This is the type alignment for the corresponding built-in.
/// In other contexts it might have different alignment.
pub fn default_align<C: HasDataLayout>(self, cx: &C) -> AbiAlign {

@workingjubilee workingjubilee Jun 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we be changing this into Align now that we're diffing every line where this is called anyways?

(feel free to answer "no", I haven't checked whether that's a reasonable, nevermind good idea. I only raise it because it should be functionally no-op)

View changes since the review

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 think I'm inclined to leave it matching https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/struct.LayoutData.html#structfield.align as AbiAlign for now. Arguably the default alignment is an ABI alignment (as opposed to a preferred one or an arbitrary one) so it's not unreasonable.

And really I'm hoping to actually just delete the vast majority of these anyway by not needing to do that align_to all over the place anyway 🙂

I'll add it to the list of things to think about if I can't just delete it, though.

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 started on the next PR to do this:

-    ScalarPair(Scalar, Scalar),
+    ScalarPair {
+        a: Scalar,
+        b: Scalar,
+        b_offset: Size,
+    },

and it looks like it removes all the default_align calls from codegen and CTFE -- it's only left in rustc_abi and the checks in compiler/rustc_ty_utils\src\layout\invariant.rs (the latter of which the MCP would probably also remove).

So looking promising.

@workingjubilee workingjubilee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good, I agree "default" is more edifying than "platform". r=me once you've answered my review question, whether positively or negatively

View changes since this review

@scottmcm

scottmcm commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

@bors r=workingjubilee rollup

@rust-bors

rust-bors Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e0b5121 has been approved by workingjubilee

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 1, 2026
…ingjubilee

Rename `align` to `default_align` on `Scalar` and `Primitive`

To emphasize that just because you see a `Scalar(I32)` that doesn't really tell you anything about the alignment it has -- one should be looking at the type (well, the place) for that.

(The `size` method doesn't really have that problem -- i32 is always 4 bytes, no matter the context -- so is left untouched.)

No actual layout or behaviour changes in *this* PR.  Just the rename and some comments.

r? @workingjubilee
rust-bors Bot pushed a commit that referenced this pull request Jul 1, 2026
Rollup of 6 pull requests

Successful merges:

 - #157718 (Do not increase depth when evaluating nested goals of `NormalizesTo`)
 - #158449 (QNX target renaming)
 - #158483 (signed strict division: just use normal division)
 - #158516 ( Deduplicate codegen backends in bootstrap config)
 - #158542 (Rename `align` to `default_align` on `Scalar` and `Primitive`)
 - #158636 (linkchecker: upgrade to `html5ever v0.39`)
@rust-bors rust-bors Bot merged commit 9272c6d into rust-lang:main Jul 1, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jul 1, 2026
rust-timer added a commit that referenced this pull request Jul 1, 2026
Rollup merge of #158542 - scottmcm:scalar-but-packed, r=workingjubilee

Rename `align` to `default_align` on `Scalar` and `Primitive`

To emphasize that just because you see a `Scalar(I32)` that doesn't really tell you anything about the alignment it has -- one should be looking at the type (well, the place) for that.

(The `size` method doesn't really have that problem -- i32 is always 4 bytes, no matter the context -- so is left untouched.)

No actual layout or behaviour changes in *this* PR.  Just the rename and some comments.

r? @workingjubilee
@scottmcm scottmcm deleted the scalar-but-packed branch July 1, 2026 15:06
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jul 2, 2026
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#157718 (Do not increase depth when evaluating nested goals of `NormalizesTo`)
 - rust-lang/rust#158449 (QNX target renaming)
 - rust-lang/rust#158483 (signed strict division: just use normal division)
 - rust-lang/rust#158516 ( Deduplicate codegen backends in bootstrap config)
 - rust-lang/rust#158542 (Rename `align` to `default_align` on `Scalar` and `Primitive`)
 - rust-lang/rust#158636 (linkchecker: upgrade to `html5ever v0.39`)
Kobzol pushed a commit to Kobzol/rust that referenced this pull request Jul 4, 2026
…ingjubilee

Rename `align` to `default_align` on `Scalar` and `Primitive`

To emphasize that just because you see a `Scalar(I32)` that doesn't really tell you anything about the alignment it has -- one should be looking at the type (well, the place) for that.

(The `size` method doesn't really have that problem -- i32 is always 4 bytes, no matter the context -- so is left untouched.)

No actual layout or behaviour changes in *this* PR.  Just the rename and some comments.

r? @workingjubilee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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