Commit graph

45944 commits

Author SHA1 Message Date
mejrs
9abaa9d4df Disable usage on trait impls and aliases 2025-04-14 00:12:37 +02:00
mejrs
8586cad77c Documentation and finishing touches 2025-04-14 00:12:36 +02:00
Michael Goulet
2f96e784e2 Visit place in BackwardIncompatibleDropHint statement 2025-04-13 22:01:54 +00:00
Jacob Pratt
7ce62af35a
Rollup merge of #139741 - os-checker:smir-run-macro, r=scottmcm
fix smir's run! doc and import

This PR
* adds missing `extern crate rustc_middle` in `rustc_smir::run!` docstring
* adds missing `use rustc_smir::rustc_internal` in `run_driver!` scope
  * also adjust some tests that don't need to import rustc_internalany more
2025-04-13 17:37:56 -04:00
Jacob Pratt
1b6fcd9440
Rollup merge of #139674 - yotamofek:pr/mir_transform/index-iterators, r=compiler-errors
In `rustc_mir_transform`, iterate over index newtypes instead of ints

Just makes code more idiomatic/easier to read, IMHO.
Also, some drive-by simplifications and cleanups.
2025-04-13 17:37:55 -04:00
Jacob Pratt
388d612765
Rollup merge of #139644 - yotamofek:pr/mir_transform/instsimplify/simplify_primitive_clone, r=compiler-errors
Micro-optimize `InstSimplify`'s `simplify_primitive_clone`

r? ````@compiler-errors```` , since you already did #139411 and got randomly selected for #139638 (feel free to reassign!)

Another one similar in spirit to #139411, but this time for `simplify_primitive_clone`, which is doing a bit of redundant work. Might not show up in benches, but probably worth micro-optimizing since the transformation is run even for debug builds.

See inline comments for my reasoning for making these changes.
2025-04-13 17:37:54 -04:00
Jacob Pratt
a04a03720e
Rollup merge of #139628 - makai410:suggest-vis, r=compiler-errors
Suggest remove redundant `$()?` around `vis`

Resolves: #139480 .
2025-04-13 17:37:54 -04:00
Jacob Pratt
cd09162ac7
Rollup merge of #139582 - oli-obk:coercion-cleanups, r=compiler-errors
Various coercion cleanups

I think the commit order is the most reasonable one, but there's probably more ways to get to the same goal.

Essentially I got rid of the `simple` and `identity` helpers by adding a dedicated function for the common `identity` case and getting rid of the callbacks alltogether by realizing that all callbacks were of the pattern "use this fixed prefix list of adjustments, then add another adjustment with the unified type as the target type".

No behavioral changes intended
2025-04-13 17:37:53 -04:00
Jacob Pratt
346d33a5b7
Rollup merge of #139379 - matthewjasper:drop-elab-normalization, r=compiler-errors
Use delayed bug for normalization errors in drop elaboration

Normalization can fail due to a lot of different earlier errors, so just use span_delayed_bug if normalization failed.

Closes #137287
Closes #135668

r? compiler-errors
2025-04-13 17:37:53 -04:00
Jacob Pratt
7f691d28f1
Rollup merge of #139001 - folkertdev:naked-function-rustic-abi, r=traviscross,compiler-errors
add `naked_functions_rustic_abi` feature gate

tracking issue: https://github.com/rust-lang/rust/issues/138997

Because the details of the rust abi are unstable, and a naked function must match its stated ABI, this feature gate keeps naked functions with a rustic abi ("Rust", "rust-cold", "rust-call" and "rust-intrinsic") unstable.

r? ````@traviscross````
2025-04-13 17:37:52 -04:00
Jacob Pratt
60c76b9dfd
Rollup merge of #138962 - xizheyin:issue-138836, r=compiler-errors
Expect an array when expected and acutal types are both arrays during cast

Closes #138836
2025-04-13 17:37:52 -04:00
Jacob Pratt
d04df1cba9
Rollup merge of #137043 - Sky9x:unsafe-pinned-pt1-libs, r=tgross35,RalfJung,WaffleLapkin
Initial `UnsafePinned` implementation [Part 1: Libs]

Initial libs changes necessary to unblock further work on [RFC 3467](https://rust-lang.github.io/rfcs/3467-unsafe-pinned.html).
Tracking issue: #125735

This PR is split off from #136964, and includes just the libs changes:
- `UnsafePinned` struct
- private `UnsafeUnpin` structural auto trait
- Lang items for both
- Compiler changes necessary to block niches on `UnsafePinned`

This PR does not change codegen, miri, the existing `!Unpin` hack, or anything else. That work is to be split into later PRs.

---

cc ``@RalfJung`` ``@Noratrieb``

``@rustbot`` label F-unsafe_pinned T-libs-api
2025-04-13 17:37:51 -04:00
jyn
d50a8d5fb3 Improve -Z crate-attr diagnostics
- Show the `#![ ... ]` in the span (to make it clear that it should not
  be included in the CLI argument)
- Show more detailed errors when the crate has valid token trees but
  invalid syntax.
  Previously, `crate-attr=feature(foo),feature(bar)` would just say
  "invalid crate attribute" and point at the comma. Now, it explicitly
  says that the comma was unexpected, which is useful when using
  `--error-format=short`. It also fixes the column to show the correct
  span.
- Recover from parse errors. Previously we would abort immediately on
  syntax errors; now we go on to try and type-check the rest of the
  crate.

The new diagnostic code also happens to be slightly shorter.
2025-04-13 16:46:02 -04:00
clubby789
41a5d8ef3d JumpThreading: Bail out on interp errors 2025-04-13 20:29:51 +00:00
clubby789
9f35fe47c7 JumpThreading: Re-enable and fix Not ops on non-booleans 2025-04-13 20:29:49 +00:00
zjp
6d5f6fd293 import rustc_smir::rustc_internal in run_driver! 2025-04-13 18:09:10 +08:00
zjp
6b2262ecde add missing extern crate rustc_middle in rustc_smir::run! docstring 2025-04-13 18:07:43 +08:00
bors
65fa0ab924 Auto merge of #139734 - ChrisDenton:rollup-28qn740, r=ChrisDenton
Rollup of 6 pull requests

Successful merges:

 - #139107 (std: make `cmath` functions safe)
 - #139607 (Add regression test for #127424)
 - #139691 (Document that `opt-dist` requires metrics to be enabled)
 - #139707 (Fix comment in bootstrap)
 - #139708 (Fix name of field in doc comment)
 - #139709 (bootstrap: fix typo in doc string)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-13 07:10:43 +00:00
Sky
21b7360a9a
Initial UnsafePinned/UnsafeUnpin impl [Part 1: Libs] 2025-04-13 01:11:04 -04:00
bors
fda35a6da6 Auto merge of #139724 - ChrisDenton:rollup-zhcdtzh, r=ChrisDenton
Rollup of 8 pull requests

Successful merges:

 - #139163 (indirect-const-stabilize the `exact_div` intrinsic)
 - #139276 (Revert "Disable `f16` on Aarch64 without `neon`")
 - #139315 (Switch `time` to `jiff` for time formatting in ICE dumps)
 - #139382 (Update windows-bindgen to 0.61.0)
 - #139688 (rustdoc-search: add unbox flag to Result aliases)
 - #139701 (docs: clarify uint exponent for `is_power_of_two`)
 - #139705 (Removed outdated ui test suite README, give reasons for disabled tests)
 - #139713 (Fix typo in documentation)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-13 03:59:04 +00:00
Chris Denton
c3027182d1
Rollup merge of #139708 - samueltardieu:push-onttwlpwurov, r=petrochenkov
Fix name of field in doc comment

Trivial doc fix
2025-04-13 03:07:08 +00:00
dianne
f35eae780b store the kind of pattern adjustments in pat_adjustments
This allows us to better distinguish builtin and overloaded implicit
dereferences.
2025-04-12 17:42:09 -07:00
Folkert de Vries
f472cc8cd4
error on unsafe attributes in pre-2024 editions
the `no_mangle`, `link_section` and `export_name` attributes are exceptions, and can still be used without an unsafe in earlier editions
2025-04-13 01:22:59 +02:00
jackh726
accae530ce Move FlagComputation, PatternKind, and TypeWalker to rustc_type_ir 2025-04-12 22:46:11 +00:00
Chris Denton
e0f92bb53c
Rollup merge of #139688 - rust-lang:notriddle/io-result-unbox, r=GuillaumeGomez
rustdoc-search: add unbox flag to Result aliases

Fixes #139665
2025-04-12 21:05:30 +00:00
Chris Denton
0149a43f8a
Rollup merge of #139315 - clubby789:deranged-bump, r=Mark-Simulacrum
Switch `time` to `jiff` for time formatting in ICE dumps

Due to https://github.com/jhpratt/deranged/issues/21, Clippy, R-A and Miri currently fail to build if we bump to 0.4.1, pulled in via `time`. ~~Add some specific type annotations so we don't have to just pin it.~~

~~I can open 3 PRs to the tool repos if preferred, but I thought it might be easier to do this than to pin the transitive dep and go back and remove it once the changes are synced back.~~
2025-04-12 21:05:28 +00:00
bors
ae06b79dcb Auto merge of #139640 - Zoxc:big-file-encoder, r=saethlin
Bump `FileEncoder` buffer size to 64 kB

This helps avoid file system overhead on Windows. The improvement are probably reduced a bit on other platforms. Making the buffer size even larger does further improve performance, but that increase memory use further.

<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:unchanged</td><td align="right">0.3336s</td><td align="right">0.3242s</td><td align="right">💚  -2.82%</td><td align="right">96.97 MiB</td><td align="right">97.12 MiB</td><td align="right"> 0.16%</td><td align="right">167.87 MiB</td><td align="right">167.97 MiB</td><td align="right"> 0.06%</td></tr><tr><td>🟣 <b>hyper</b>:check:unchanged</td><td align="right">0.1331s</td><td align="right">0.1307s</td><td align="right">💚  -1.79%</td><td align="right">61.92 MiB</td><td align="right">62.05 MiB</td><td align="right"> 0.20%</td><td align="right">124.66 MiB</td><td align="right">124.74 MiB</td><td align="right"> 0.06%</td></tr><tr><td>🟣 <b>regex</b>:check:unchanged</td><td align="right">0.2485s</td><td align="right">0.2399s</td><td align="right">💚  -3.45%</td><td align="right">78.32 MiB</td><td align="right">78.55 MiB</td><td align="right"> 0.29%</td><td align="right">145.22 MiB</td><td align="right">145.45 MiB</td><td align="right"> 0.15%</td></tr><tr><td>🟣 <b>syn</b>:check:unchanged</td><td align="right">0.5321s</td><td align="right">0.5175s</td><td align="right">💚  -2.76%</td><td align="right">118.58 MiB</td><td align="right">118.77 MiB</td><td align="right"> 0.16%</td><td align="right">192.99 MiB</td><td align="right">193.17 MiB</td><td align="right"> 0.09%</td></tr><tr><td>Total</td><td align="right">1.2474s</td><td align="right">1.2123s</td><td align="right">💚  -2.81%</td><td align="right">355.78 MiB</td><td align="right">356.49 MiB</td><td align="right"> 0.20%</td><td align="right">630.74 MiB</td><td align="right">631.32 MiB</td><td align="right"> 0.09%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9729s</td><td align="right">💚  -2.71%</td><td align="right">1 byte</td><td align="right">1.00 bytes</td><td align="right"> 0.20%</td><td align="right">1 byte</td><td align="right">1.00 bytes</td><td align="right"> 0.09%</td></tr></table>
2025-04-12 20:58:04 +00:00
Michael Goulet
bc94c38d98 Proactively update coroutine drop shim's phase to account for later passes applied during shim query 2025-04-12 20:54:08 +00:00
bohan
8ae6485dad don't store opaque info during encoding 2025-04-12 23:56:48 +08:00
Yotam Ofek
c36e8fcc3c In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
Samuel Tardieu
83dd8a2c2a Fix name of field in doc comment 2025-04-12 11:34:04 +02:00
Jacob Pratt
eea366c191
Rollup merge of #139664 - oli-obk:push-tkmurytmnsyw, r=RalfJung
Reuse address-space computation from global alloc

r? `@RalfJung`

just avoiding some minor duplication
2025-04-11 21:21:02 +02:00
Jacob Pratt
2b54f9bfb1
Rollup merge of #139662 - nnethercote:tweak-DefPathData, r=compiler-errors
Tweak `DefPathData`

Some improvements in and around `DefPathData`, following on from #137977.

r? `@spastorino`
2025-04-11 21:21:01 +02:00
Jacob Pratt
2f873f96e2
Rollup merge of #139653 - nnethercote:fix-139495, r=petrochenkov
Handle a negated literal in `eat_token_lit`.

Fixes #139495.

r? `@petrochenkov`
2025-04-11 21:21:01 +02:00
Jacob Pratt
00b9060c3b
Rollup merge of #139638 - yotamofek:pr/mir_transform/instsimplify/cleanup, r=oli-obk
Cleanup the `InstSimplify` MIR transformation

Some minor cleanups and rightward-drift-protection found while working on #139411 and a future follow-up
2025-04-11 21:21:00 +02:00
Jacob Pratt
bc05aaeeaa
Rollup merge of #139584 - oli-obk:horrible-experiment-1, r=petrochenkov
Avoid a reverse map that is only used in diagnostics paths

r? `@petrochenkov`

iterating a map until a value matches and returning the key is bad obviously, but it happens very rarely and only on diagnostics paths. It would also be a lot cheaper with https://github.com/rust-lang/rust/pull/138995. Which is actually why I'm trying this out, that PR adds a new entry in `create_def`, which makes `create_def` show up in cachegrind. So I'm trying out if removing adding an entry in `create_def` is a perf improvement
2025-04-11 21:20:59 +02:00
Michael Howell
e013cf8afc rustdoc-search: add unbox flag to Result aliases
Fixes #139665
2025-04-11 11:36:40 -07:00
Matthew Jasper
ac45a67297 Use delayed bug for normalization errors in drop elaboration
Normalization can fail from errors from other items so use a delayed
bug instead of checking the body.
2025-04-11 16:31:28 +00:00
bors
e1b06f7730 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
lcnr
420390c848 eagerly initialize definitions in sub-fn 2025-04-11 15:18:30 +02:00
lcnr
5d0048303c NonGenericOpaqueTypeParam::ty to arg 2025-04-11 15:18:30 +02:00
lcnr
83033838a3 remove redundant fields 2025-04-11 15:18:29 +02:00
Mara Bos
3962069982 Replace proc_macro::SourceFile by Span::{file, local_file}. 2025-04-11 15:07:08 +02:00
Mara Bos
6788ce76c9 Remove proc_macro::SourceFile::is_real(). 2025-04-11 14:02:06 +02:00
Nicholas Nethercote
cdf5b8d4e7 Change how anonymous associated types are printed.
Give them their own symbol `anon_assoc`, as is done for all the other
anonymous `DefPathData` variants.
2025-04-11 20:13:16 +10:00
lcnr
c5fdddc7f4 don't rely on locals_are_invalidated_at_exit 2025-04-11 12:12:36 +02:00
lcnr
2c65469c27 move dump_polonius_mir 2025-04-11 12:12:34 +02:00
Oli Scherer
98d51fb44f Only compute the DefId when a diagnostic is definitely emitted 2025-04-11 10:04:27 +00:00
Oli Scherer
d35e830aad Avoid a node_id_to_def_id call by just storing DefIds instead of NodeIds 2025-04-11 10:04:27 +00:00
Oli Scherer
33a6820c2f Avoid storing the LocalDefId twice 2025-04-11 10:04:27 +00:00