Skip to content

Subtree sync for rustc_codegen_cranelift #142959

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

Merged
merged 62 commits into from
Jun 24, 2025

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jun 24, 2025

The main highlight this time is a Cranelift update.

r? @ghost

@rustbot label +A-codegen +A-cranelift +T-compiler

bjorn3 and others added 30 commits May 25, 2025 18:51
And move passing it to the linker to the driver code.
This deduplicates some code between codegen backends and may in the
future allow adding extra metadata that is only known at link time.
 - remove unused `llvm.aarch64.neon.frintn` from cg_clif
…bzol

Merge `compiler-builtins` as a Josh subtree

Use the Josh [1] utility to add `compiler-builtins` as a subtree, which
will allow us to stop using crates.io for updates. This is intended to
help resolve some problems when unstable features change and require
code changes in `compiler-builtins`, which sometimes gets trapped in a
bootstrap cycle.

This was done using `josh-filter` built from the r24.10.04 tag:

    git fetch https://github.com/rust-lang/compiler-builtins.git 233434412fe7eced8f1ddbfeddabef1d55e493bd
    josh-filter ":prefix=library/compiler-builtins" FETCH_HEAD
    git merge --allow-unrelated FILTERED_HEAD

The HEAD in the `compiler-builtins` repository is 233434412f ("fix an if
statement that can be collapsed").

[1]: https://github.com/josh-project/josh
…=bjorn3

Replace ad-hoc ABI "adjustments" with an `AbiMap` to `CanonAbi`

Our `conv_from_spec_abi`, `adjust_abi`, and `is_abi_supported` combine to give us a very confusing way of reasoning about what _actual_ calling convention we want to lower our code to and whether we want to compile the resulting code at all. Instead of leaving this code as a miniature adventure game in which someone tries to combine stateful mutations into a Rube Goldberg machine that will let them escape the maze and arrive at the promised land of codegen, we let `AbiMap` devour this complexity. Once you have an `AbiMap`, you can answer which `ExternAbi`s will lower to what `CanonAbi`s (and whether they will lower at all).

Removed:
- `conv_from_spec_abi` replaced by `AbiMap::canonize_abi`
- `adjust_abi` replaced by same
- `Conv::PreserveAll` as unused
- `Conv::Cold` as unused
- `enum Conv` replaced by `enum CanonAbi`

target-spec.json changes:
- If you have a target-spec.json then now your "entry-abi" key will be specified in terms of one of the `"{abi}"` strings Rust recognizes, e.g.
```json
    "entry-abi": "C",
    "entry-abi": "win64",
    "entry-abi": "aapcs",
```
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#137725 (Add `iter` macro)
 - rust-lang#141455 (std: abort the process on failure to allocate a TLS key)
 - rust-lang#141569 (Replace ad-hoc ABI "adjustments" with an `AbiMap` to `CanonAbi`)
 - rust-lang#141698 (Use the informative error as the main const eval error message)
 - rust-lang#141925 (Remove bootstrap cfgs from library/)
 - rust-lang#141943 (Remove pre-expansion AST stats.)
 - rust-lang#141945 (Remove `Path::is_ident`.)
 - rust-lang#141957 (Add missing `dyn` keywords to tests that do not test for them Part 2)

r? `@ghost`
`@rustbot` modify labels: rollup
It was already available as a generic parameter anyway, and it's not like we'll ever put a tag in the 5-billionth field.
As suggested by Ralf in 142005.
…-obk

Update `InterpCx::project_field` to take `FieldIdx`

As suggested by Ralf in rust-lang#142005 (comment)
In PR 90877 T-lang decided not to remove `intrinsics::pref_align_of`.
However, the intrinsic and its supporting code
1.  is a nightly feature, so can be removed at compiler/libs discretion
2.  requires considerable effort in the compiler to support, as it
    necessarily complicates every single site reasoning about alignment
3.  has been justified based on relevance to codegen, but it is only a
    requirement for C++ (not C, not Rust) stack frame layout for AIX,
    in ways Rust would not consider even with increased C++ interop
4.  is only used by rustc to overalign some globals, not correctness
5.  can be adequately replaced by other rules for globals, as it mostly
    affects alignments for a few types under 16 bytes of alignment
6.  has only one clear benefactor: automating C -> Rust translation
    for GNU extensions like `__alignof`
7.  such code was likely intended to be `alignof` or `_Alignof`,
    because the GNU extension is a "false friend" of the C keyword,
    which makes the choice to support such a mapping very questionable
8.  makes it easy to do incorrect codegen in the compiler by its mere
    presence as usual Rust rules of alignment (e.g. `size == align * N`)
    do not hold with preferred alignment

The implementation is clearly damaging the code quality of the compiler.
Thus it is within the compiler team's purview to simply rip it out.
If T-lang wishes to have this intrinsic restored for c2rust's benefit,
it would have to use a radically different implementation that somehow
does not cause internal incorrectness.

Until then, remove the intrinsic and its supporting code, as one tool
and an ill-considered GCC extension cannot justify risking correctness.

Because we touch a fair amount of the compiler to change this at all,
and unfortunately the duplication of AbiAndPrefAlign is deep-rooted,
we keep an "AbiAlign" type which we can wean code off later.
Also reduce visibility of a function
@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. A-codegen Area: Code generation A-cranelift Things relevant to the [future] cranelift backend labels Jun 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 24, 2025

⚠️ Warning ⚠️

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 24, 2025
@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jun 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 24, 2025

There are changes to the tidy tool.

cc @jieyouxu

The list of allowed third-party dependencies may have been modified! You must ensure that any new dependencies have compatible licenses before merging.

cc @davidtwco, @wesleywiser

@bjorn3
Copy link
Member Author

bjorn3 commented Jun 24, 2025

@bors r+ p=1 subtree sync

@bors
Copy link
Collaborator

bors commented Jun 24, 2025

📌 Commit dbe8682 has been approved by bjorn3

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. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 24, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 24, 2025
…bjorn3

Subtree sync for rustc_codegen_cranelift

The main highlight this time is a Cranelift update.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
@bors
Copy link
Collaborator

bors commented Jun 24, 2025

⌛ Testing commit dbe8682 with merge 28f1c80...

@bors
Copy link
Collaborator

bors commented Jun 24, 2025

☀️ Test successful - checks-actions
Approved by: bjorn3
Pushing 28f1c80 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 24, 2025
@bors bors merged commit 28f1c80 into rust-lang:master Jun 24, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jun 24, 2025
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 3129d37 (parent) -> 28f1c80 (this PR)

Test differences

No test diffs found

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 28f1c807911c63f08d98e7b468cfcf15a441e34b --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-apple-various: 5774.5s -> 7818.8s (35.4%)
  2. mingw-check-tidy: 69.6s -> 84.2s (21.0%)
  3. aarch64-gnu-debug: 4285.5s -> 3551.6s (-17.1%)
  4. x86_64-gnu-tools: 3824.8s -> 3319.6s (-13.2%)
  5. i686-gnu-2: 6252.4s -> 5480.6s (-12.3%)
  6. mingw-check-1: 1815.0s -> 1591.0s (-12.3%)
  7. armhf-gnu: 5042.8s -> 4470.7s (-11.3%)
  8. x86_64-gnu-llvm-19-1: 3688.4s -> 3277.8s (-11.1%)
  9. aarch64-gnu: 6880.4s -> 6138.3s (-10.8%)
  10. x86_64-rust-for-linux: 2863.0s -> 2557.4s (-10.7%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (28f1c80): comparison URL.

Overall result: ❌ regressions - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
2.9% [2.9%, 2.9%] 1
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.9% [2.9%, 2.9%] 1

Max RSS (memory usage)

Results (secondary 1.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.8% [1.5%, 3.1%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (primary 2.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.8% [2.8%, 2.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.8% [2.8%, 2.8%] 1

Binary size

Results (primary 1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.1% [1.1%, 1.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.1% [1.1%, 1.1%] 1

Bootstrap: 689.011s -> 689.458s (0.06%)
Artifact size: 372.03 MiB -> 372.01 MiB (-0.00%)

@rustbot rustbot added the perf-regression Performance regression. label Jun 25, 2025
@bjorn3 bjorn3 deleted the sync_cg_clif-2025-06-24 branch June 25, 2025 06:34
@lqd
Copy link
Member

lqd commented Jun 25, 2025

This PR didn't change the benchmarked compiler, and clap_derive is quite noisy.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-cranelift Things relevant to the [future] cranelift backend A-tidy Area: The tidy tool has-merge-commits PR has merge commits, merge with caution. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.