Commit graph

4859 commits

Author SHA1 Message Date
Folkert de Vries
0103c583fa
support -Zmin-function-alignment (#1572) 2025-04-21 22:19:19 +02:00
bjorn3
de372d3fff Update to Cranelift 0.119 2025-04-21 15:24:18 +00:00
bjorn3
91114bd289 Fix rustc test suite 2025-04-21 10:48:40 +00:00
bjorn3
4cfecfdfa6 Rustup to rustc 1.88.0-nightly (b8c54d635 2025-04-20) 2025-04-21 10:37:10 +00:00
bjorn3
934931b079 Sync from rust b8c54d6358 2025-04-21 10:21:28 +00:00
Folkert de Vries
59c5ed0ba8 Make #[naked] an unsafe attribute 2025-04-19 00:03:35 +02:00
bjorn3
49bfa1aaf5 Fix simd_insert_dyn and simd_extract_dyn intrinsics with non-pointer sized indices 2025-04-18 10:30:44 +00:00
bjorn3
c8c87421a5 Nicer formatting for verifier errors during define_function 2025-04-18 09:02:00 +00:00
bjorn3
1afce7c354 Implement simd_insert_dyn and simd_extract_dyn intrinsics 2025-04-14 09:13:37 +00:00
bjorn3
f99bdfef83 Rustup to rustc 1.88.0-nightly (092a284ba 2025-04-13) 2025-04-14 08:47:01 +00:00
bjorn3
62c72fc381 Sync from rust 092a284ba0 2025-04-14 08:30:14 +00:00
Nicholas Nethercote
bc9dacdf9a Move has_self field to hir::AssocKind::Fn.
`hir::AssocItem` currently has a boolean `fn_has_self_parameter` field,
which is misplaced, because it's only relevant for associated fns, not
for associated consts or types. This commit moves it (and renames it) to
the `AssocKind::Fn` variant, where it belongs.

This requires introducing a new C-style enum, `AssocTag`, which is like
`AssocKind` but without the fields. This is because `AssocKind` values
are passed to various functions like `find_by_ident_and_kind` to
indicate what kind of associated item should be searched for, and having
to specify `has_self` isn't relevant there.

New methods:
- Predicates `AssocItem::is_fn` and `AssocItem::is_method`.
- `AssocItem::as_tag` which converts `AssocItem::kind` to `AssocTag`.

Removed `find_by_name_and_kinds`, which is unused.

`AssocItem::descr` can now distinguish between methods and associated
functions, which slightly improves some error messages.
2025-04-14 16:13:04 +10:00
bors
322bba0ae4 Auto merge of #139453 - compiler-errors:incr, r=jieyouxu
Prepend temp files with per-invocation random string to avoid temp filename conflicts

https://github.com/rust-lang/rust/issues/139407 uncovered a very subtle unsoundness with incremental codegen, failing compilation sessions (due to assembler errors), and the "prefer hard linking over copying files" strategy we use in the compiler for file management.

Specifically, imagine we're building a single file 3 times, all with `-Csave-temps -Cincremental=...`. Let's call the object file we're building for the codegen unit for `main` "`XXX.o`" just for clarity since it's probably some gigantic hash name:

```
#[inline(never)]
#[cfg(any(rpass1, rpass3))]
fn a() -> i32 {
    0
}

#[cfg(any(cfail2))]
fn a() -> i32 {
    1
}

fn main() {
    evil::evil();
    assert_eq!(a(), 0);
}

mod evil {
    #[cfg(any(rpass1, rpass3))]
    pub fn evil() {
        unsafe {
            std::arch::asm!("/*  */");
        }
    }

    #[cfg(any(cfail2))]
    pub fn evil() {
        unsafe {
            std::arch::asm!("missing");
        }
    }
}
```

Session 1 (`rpass1`):
* Type-check, borrow-check, etc.
* Serialize the dep graph to the incremental working directory `.../s-...-working/`.
* Codegen object file to a temp file `XXX.rcgu.o` which is spit out in the cwd.
* Hard-link[^1] `XXX.rcgu.o` to the incremental working directory `.../s-...-working/XXX.o`.
* Save-temps option means we don't delete `XXX.rgcu.o`.
* Link the binary and stuff.
* Finalize[^2] the working incremental session by renaming `.../s-...-working` to ` s-...-asjkdhsjakd` (some other finalized incr comp session dir name).

Session 2 (`cfail2`):
* Load artifacts from the previous *finalized* incremental session, namely the dep graph.
* Type-check, borrow-check, etc. since the file has changed, so most dep graph nodes are red.
* Serialize the dep graph to the incremental working directory `.../s-...-working/`.
* Codegen object file to a temp file `XXX.rcgu.o`. **HERE IS THE PROBLEM**: The hard-link is still set up to point to the inode from `XXX.o` from the first session, so this also modifies the `XXX.o` in the previous finalized session directory.
* Codegen emits an error b/c `missing` is not an instruction, so we abort before finalizing the incremental session. Specifically, this means that the *previous* session is the last finalized session.

Session 3 (`rpass3`):
* Load artifacts from the previous *finalized* incremental session, namely the dep graph. NOTE that this is from session 1.
* All the dep graph nodes are green since we are basically replaying session 1.
* codegen object file `XXX.o`, which is detected as *reused* from session 1 since dep nodes were green. That means we **reuse** `XXX.o` which had been dirtied from session 2.
* Link the binary and stuff.

This results in a binary which reuses some of the build artifacts from session 2, but thinks it's from session 1.

At this point, I hope it's clear to see that the incremental results from session 1 were dirtied from session 2, but we reuse them as if session 1 was the previous (finalized) incremental session we ran. This is at best really buggy, and at worst **unsound**.

This isn't limited to `-C save-temps`, since there are other combinations of flags that may keep around temporary files (hard linked) in the working directory (like `-C debuginfo=1 -C split-debuginfo=unpacked` on darwin, for example).

---

This PR implements a fix which is to prepend temp filenames with a random string that is generated per invocation of rustc. This string is not *deterministic*, but temporary files are transient anyways, so I don't believe this is a problem.

That means that temp files are now something like... `{crate-name}.{cgu}.{invocation_temp}.rcgu.o`, where `{invocation_temp}` is the new temporary string we generate per invocation of rustc.

Fixes https://github.com/rust-lang/rust/issues/139407

[^1]: 175dcc7773/compiler/rustc_fs_util/src/lib.rs (L60)
[^2]: 175dcc7773/compiler/rustc_incremental/src/persist/fs.rs (L1-L40)
2025-04-11 13:59:33 +00:00
bors
cd8a1ad3cc Auto merge of #139011 - Zoxc:no-rayon-iters, r=oli-obk
Remove the use of Rayon iterators

This removes the use of Rayon iterators and the use of the `rustc-rayon` crate.  `rustc-rayon-core` is still used however.

In parallel loops, instead of a Rayon iterator a serial iterator are used to collect items into a `Vec` and we use a parallel loop over its elements using the new `par_slice` function which is built on `rustc-rayon-core`'s `join`.

This change makes it easier to bring `rustc-rayon-core` in-tree.

Tests using 7 threads:
<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th><td align="right">Physical Memory</td><td align="right">Physical Memory</td><td align="right">%</th><td align="right">Committed Memory</td><td align="right">Committed Memory</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check</td><td align="right">0.4827s</td><td align="right">0.4828s</td><td align="right"> 0.02%</td><td align="right">201.23 MiB</td><td align="right">201.31 MiB</td><td align="right"> 0.04%</td><td align="right">279.03 MiB</td><td align="right">279.46 MiB</td><td align="right"> 0.15%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.1443s</td><td align="right">0.1401s</td><td align="right">💚  -2.91%</td><td align="right">126.42 MiB</td><td align="right">126.70 MiB</td><td align="right"> 0.22%</td><td align="right">199.79 MiB</td><td align="right">199.99 MiB</td><td align="right"> 0.10%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">0.3252s</td><td align="right">0.3065s</td><td align="right">💚  -5.78%</td><td align="right">161.87 MiB</td><td align="right">161.78 MiB</td><td align="right"> -0.05%</td><td align="right">229.59 MiB</td><td align="right">230.23 MiB</td><td align="right"> 0.28%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">0.5845s</td><td align="right">0.5876s</td><td align="right"> 0.53%</td><td align="right">197.01 MiB</td><td align="right">196.89 MiB</td><td align="right"> -0.06%</td><td align="right">267.62 MiB</td><td align="right">267.47 MiB</td><td align="right"> -0.06%</td></tr><tr><td>Total</td><td align="right">1.5367s</td><td align="right">1.5169s</td><td align="right">💚  -1.29%</td><td align="right">686.53 MiB</td><td align="right">686.68 MiB</td><td align="right"> 0.02%</td><td align="right">976.04 MiB</td><td align="right">977.14 MiB</td><td align="right"> 0.11%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9796s</td><td align="right">💚  -2.04%</td><td align="right">1 byte</td><td align="right">1.00 bytes</td><td align="right"> 0.04%</td><td align="right">1 byte</td><td align="right">1.00 bytes</td><td align="right"> 0.12%</td></tr></table>

<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th><td align="right">Physical Memory</td><td align="right">Physical Memory</td><td align="right">%</th><td align="right">Committed Memory</td><td align="right">Committed Memory</td><td align="right">%</th></tr><tr><td>🟠 <b>clap</b>:debug</td><td align="right">1.6371s</td><td align="right">1.6529s</td><td align="right"> 0.96%</td><td align="right">395.58 MiB</td><td align="right">396.21 MiB</td><td align="right"> 0.16%</td><td align="right">460.98 MiB</td><td align="right">461.52 MiB</td><td align="right"> 0.12%</td></tr><tr><td>🟠 <b>hyper</b>:debug</td><td align="right">0.3248s</td><td align="right">0.3210s</td><td align="right">💚  -1.16%</td><td align="right">155.16 MiB</td><td align="right">155.19 MiB</td><td align="right"> 0.02%</td><td align="right">219.21 MiB</td><td align="right">219.30 MiB</td><td align="right"> 0.04%</td></tr><tr><td>🟠 <b>regex</b>:debug</td><td align="right">1.0148s</td><td align="right">0.9929s</td><td align="right">💚  -2.16%</td><td align="right">297.96 MiB</td><td align="right">295.07 MiB</td><td align="right"> -0.97%</td><td align="right">354.53 MiB</td><td align="right">351.58 MiB</td><td align="right"> -0.83%</td></tr><tr><td>🟠 <b>syn</b>:debug</td><td align="right">1.3614s</td><td align="right">1.3717s</td><td align="right"> 0.76%</td><td align="right">319.10 MiB</td><td align="right">321.19 MiB</td><td align="right"> 0.65%</td><td align="right">378.90 MiB</td><td align="right">381.27 MiB</td><td align="right"> 0.62%</td></tr><tr><td>Total</td><td align="right">4.3381s</td><td align="right">4.3386s</td><td align="right"> 0.01%</td><td align="right">1.14 GiB</td><td align="right">1.14 GiB</td><td align="right"> -0.01%</td><td align="right">1.38 GiB</td><td align="right">1.38 GiB</td><td align="right"> 0.00%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9960s</td><td align="right"> -0.40%</td><td align="right">1 byte</td><td align="right">1.00 bytes</td><td align="right"> -0.03%</td><td align="right">1 byte</td><td align="right">1.00 bytes</td><td align="right"> -0.01%</td></tr></table>
2025-04-11 07:34:27 +00:00
John Kåre Alsaker
180bc6c8f1 Remove the use of Rayon iterators 2025-04-10 22:05:06 +02:00
Nicholas Nethercote
547a31016d Rename some name variables as ident.
It bugs me when variables of type `Ident` are called `name`. It leads to
silly things like `name.name`. `Ident` variables should be called
`ident`, and `name` should be used for variables of type `Symbol`.

This commit improves things by by doing `s/name/ident/` on a bunch of
`Ident` variables. Not all of them, but a decent chunk.
2025-04-10 09:30:55 +10:00
bjorn3
9495eb517e Pass Module to UnwindContext
Once writing the LSDA, it will need access to the Module to get a
reference to the personality function and to define a data object for
the LSDA.

Part of rust-lang/rustc_codegen_cranelift#1567
2025-04-09 14:40:23 +00:00
bjorn3
ab514c9596 Pass UnwindAction to a couple of functions
In preparation for future unwinding support.

Part of rust-lang/rustc_codegen_cranelift#1567
2025-04-09 14:40:22 +00:00
bjorn3
420e44f578 Reduce visibility of a couple of functions 2025-04-08 18:41:42 +00:00
bjorn3
91c9660171
Merge pull request #1568 from rust-lang/better_unsupported_intrinsic_error
Replace trap_unimplemented calls with codegen_panic_nounwind
2025-04-08 13:18:34 +02:00
bjorn3
6424f0a7ba Replace trap_unimplemented calls with codegen_panic_nounwind
This will show a backtrace. Also added a reference to
rust-lang/rustc_codegen_cranelift#171 in the unimplemented intrinsic
error message.
2025-04-08 10:26:12 +00:00
bjorn3
b69a4787b4 Rustup to rustc 1.88.0-nightly (e643f59f6 2025-04-07) 2025-04-08 09:47:26 +00:00
bjorn3
44bbe63739 Sync from rust e643f59f6d 2025-04-08 09:40:30 +00:00
Michael Goulet
68dd8b344a Prepend temp files with a string per invocation of rustc 2025-04-07 20:48:40 +00:00
Michael Goulet
ab84fe61ed Simplify temp path creation a bit 2025-04-07 20:48:40 +00:00
bjorn3
0e9a8540b0 Preserve rustc_literal_escaper with --sysroot llvm 2025-04-07 20:28:24 +00:00
bjorn3
25f263ded7 Rustup to rustc 1.88.0-nightly (2fa8b11f0 2025-04-06) 2025-04-07 19:40:28 +00:00
bjorn3
6b06289a16 Sync from rust 2fa8b11f09 2025-04-07 19:35:39 +00:00
Bennet Bleßmann
4a8026ce63 update docs
- src\doc\nomicon\src\ffi.md should also have its ABI list updated
2025-04-06 21:41:47 +02:00
bors
07006965d2 Auto merge of #139213 - bjorn3:cg_clif_test_coretests, r=jieyouxu
Run coretests and alloctests with cg_clif in CI

Part of https://github.com/rust-lang/rustc_codegen_cranelift/issues/1290
2025-04-04 11:59:59 +00:00
bjorn3
829413d208 Tell rustfmt to use the 2024 edition 2025-04-04 10:46:47 +00:00
bjorn3
b0c23f78c9 Fix rustc test suite 2025-04-04 10:41:27 +00:00
bjorn3
4807c29d08 Rustup to rustc 1.88.0-nightly (00095b3da 2025-04-03) 2025-04-04 10:30:15 +00:00
bjorn3
43f423262f Sync from rust 00095b3da4 2025-04-04 09:53:05 +00:00
Matthias Krüger
d7a6a71597 Rollup merge of #138949 - madsmtm:rename-to-darwin, r=WaffleLapkin
Rename `is_like_osx` to `is_like_darwin`

Replace `is_like_osx` with `is_like_darwin`, which more closely describes reality (OS X is the pre-2016 name for macOS, and is by now quite outdated; Darwin is the overall name for the OS underlying Apple's macOS, iOS, etc.).

``@rustbot`` label O-apple
r? compiler
2025-04-04 08:02:05 +02:00
bjorn3
e3a8d9c6a3 Fix testing with randomized layouts enabled 2025-04-03 15:30:01 +00:00
bjorn3
bb2b3d04c3 Run coretests and alloctests with cg_clif in CI 2025-04-03 12:07:14 +00:00
bjorn3
e58dd2568b Unset RUSTC_WRAPPER in cg_clif's build system 2025-04-03 08:53:15 +00:00
bjorn3
625b8000f7 Allow formatting example/gen_block_iterate.rs 2025-04-01 14:49:15 +00:00
bjorn3
4a49ff0f33 Merge branch 'sync_from_rust' 2025-03-30 16:05:46 +00:00
bjorn3
15dbafa81e Merge commit 'ba315abda7' into sync_cg_clif-2025-03-30 2025-03-30 15:43:48 +00:00
bjorn3
ba315abda7 Fix rustc test suite 2025-03-30 15:01:56 +00:00
bjorn3
66b1f3ba0c Rustup to rustc 1.88.0-nightly (1799887bb 2025-03-29) 2025-03-30 15:01:56 +00:00
bjorn3
8364234af6
Merge pull request #1566 from rust-lang/arm64_fixes
Fix the half and bytecount crates on arm64
2025-03-27 14:50:23 +01:00
Mads Marquart
c56c2b7a0d Rename is_like_osx to is_like_darwin 2025-03-25 21:53:52 +01:00
bjorn3
1875905a94 Rustup to rustc 1.87.0-nightly (f8c27dfe1 2025-03-24) 2025-03-25 17:14:58 +00:00
bjorn3
7a9c428d82 Sync from rust f8c27dfe1a 2025-03-25 17:10:26 +00:00
Trevor Gross
0b2acddf01 Update compiler-builtins to 0.1.152
Includes the following changes related to unordered atomics:

* Remove element_unordered_atomic intrinsics [1]
* Remove use of `atomic_load_unordered` and undefined behaviour [2]

There are a handful of other small changes, but nothing else
user-visible.

[1]: https://github.com/rust-lang/compiler-builtins/pull/789
[2]: https://github.com/rust-lang/compiler-builtins/pull/790
2025-03-24 00:29:21 +00:00
bjorn3
542dbbdcfe Fix rustc testsuite 2025-03-23 17:36:31 +00:00
bjorn3
264e1addfd Rustup to rustc 1.87.0-nightly (b48576b4d 2025-03-22) 2025-03-23 16:26:03 +00:00