Commit graph

318697 commits

Author SHA1 Message Date
bors
3c9faa0d03 Auto merge of #148190 - RalfJung:box_new, r=RalfJung
replace box_new with lower-level intrinsics

The `box_new` intrinsic is super special: during THIR construction it turns into an `ExprKind::Box` (formerly known as the `box` keyword), which then during MIR building turns into a special instruction sequence that invokes the exchange_malloc lang item (which has a name from a different time) and a special MIR statement to represent a shallowly-initialized `Box` (which raises [interesting opsem questions](https://github.com/rust-lang/rust/issues/97270)).

This PR is the n-th attempt to get rid of `box_new`. That's non-trivial because it usually causes a perf regression: replacing `box_new` by naive unsafe code will incur extra copies in debug builds, making the resulting binaries a lot slower, and will generate a lot more MIR, making compilation measurably slower. Furthermore, `vec!` is a macro, so the exact code it expands to is highly relevant for borrow checking, type inference, and temporary scopes.

To avoid those problems, this PR does its best to make the MIR almost exactly the same as what it was before. `box_new` is used in two places, `Box::new` and `vec!`:
- For `Box::new` that is fairly easy: the `move_by_value` intrinsic is basically all we need. However, to avoid the extra copy that would usually be generated for the argument of a function call, we need to special-case this intrinsic during MIR building. That's what the first commit does.
- `vec!` is a lot more tricky. As a macro, its details leak to stable code, so almost every variant I tried broke either type inference or the lifetimes of temporaries in some ui test or ended up accepting unsound code due to the borrow checker not enforcing all the constraints I hoped it would enforce. I ended up with a variant that involves a new intrinsic, `fn write_box_via_move<T>(b: Box<MaybeUninit<T>>, x: T) -> Box<MaybeUninit<T>>`, that writes a value into a `Box<MaybeUninit<T>>` and returns that box again. In exchange we can get rid of somewhat similar code in the lowering for `ExprKind::Box`, and the `exchange_malloc` lang item. (We can also get rid of `Rvalue::ShallowInitBox`; I didn't include that in this PR -- I think @cjgillot has a commit for this somewhere [around here](https://github.com/rust-lang/rust/pull/147862/commits).)

See [here](https://github.com/rust-lang/rust/pull/148190#issuecomment-3457454814) for the latest perf numbers. Most of the regressions are in deep-vector which consists entirely of an invocation of `vec!`, so any change to that macro affects this benchmark disproportionally.

This is my first time even looking at MIR building code, so I am very low confidence in that part of the patch, in particular when it comes to scopes and drops and things like that.

I also had do nerf some clippy tests because clippy gets confused by the new expansion of `vec!` so it makes fewer suggestions when `vec!` is involved.

### `vec!` FAQ

- Why does `write_box_via_move` return the `Box` again? Because we need to expand `vec!` to a bunch of method invocations without any blocks or let-statements, or else the temporary scopes (and type inference) don't work out.
- Why is `box_assume_init_into_vec_unsafe` (unsoundly!) a safe function? Because we can't use an unsafe block in `vec!` as that would necessarily also include the `$x` (due to it all being one big method invocation) and therefore interpret the user's code as being inside `unsafe`, which would be bad (and 10 years later, we still don't have safe blocks for macros like this).
- Why does `write_box_via_move` use `Box` as input/output type, and not, say, raw pointers? Because that is the only way to get the correct behavior when `$x` panics or has control effects: we need the `Box` to be dropped in that case. (As a nice side-effect this also makes the intrinsic safe, which is imported as explained in the previous bullet.)
- Can't we make it safe by having `write_box_via_move` return `Box<T>`? Yes we could, but there's no easy way for the intrinsic to convert its `Box<MaybeUninit<T>>` to a `Box<T>`. Transmuting would be unsound as the borrow checker would no longer properly enforce that lifetimes involved in a `vec!` invocation behave correctly.
- Is this macro truly cursed? Yes, yes it is.
2026-02-16 18:46:10 +00:00
Eric Huss
b4e645fe5a Support JSON target specs in bootstrap
JSON target specs were destabilized in
https://github.com/rust-lang/rust/pull/150151 and
https://github.com/rust-lang/rust/pull/151534. However, this broke
trying to build rustc itself with a JSON target spec. This is because in
a few places bootstrap is manually calling `rustc` without the ability
for the user to provide additional flags (primarily,
`-Zunstable-options` to enable JSON targets).

There's a few different ways to fix this. One would be to change these
calls to `rustc` to include flags provided by the user (such as
`RUSTFLAGS_NOT_BOOTSTRAP`). Just to keep things simple, this PR proposes
to just unconditionally pass `-Zunstable-options`.

Another consideration here is how maintainable this is. A possible
improvement here would be to have a function somewhere
(BootstrapCommand, TargetSelection, free function) that would handle
appropriately adding the `--target` flag. For example, that's what cargo
does in
[`CompileKind::add_target_arg`](592058c7ce/src/cargo/core/compiler/compile_kind.rs (L144-L154)).

I have only tested building the compiler and a few tools like rustdoc. I
have not tested doing things like building other tools, running tests,
etc.

This would be much easier if there was a Docker image for testing the
use case of building rustc with a custom target spec (and even better if
that ran in CI).

After the next beta branch, using target JSON specs will become more
cumbersome because target specs with the `.json` extension will now
require passing `-Zjson-target-spec` (from
https://github.com/rust-lang/cargo/pull/16557). This does not affect
target specs without the `.json` extension (such as those from
RUST_TARGET_PATH). From my testing, it should be sufficient to pass
`CARGOFLAGS_NOT_BOOTSTRAP="-Zjson-target-spec"`. I think that should be
fine, since this is not a particularly common use case AFAIK. We could
extend bootstrap to auto-detect if the target is a file path, and pass
`-Zjson-target-spec` appropriately. I tried something similar in
f0bdd35483,
which could be adapted if desired.

It would be nice if all of this is documented somewhere.
https://rustc-dev-guide.rust-lang.org/building/new-target.html does not
really say how to build the compiler with a custom json target.

Fixes https://github.com/rust-lang/rust/issues/151729
2026-02-16 08:31:00 -08:00
Ralf Jung
0df1764e60 add helper to project to a field of a place 2026-02-16 17:27:40 +01:00
Ralf Jung
e5ed8643b6 adjust clippy to fix some of the issues 2026-02-16 17:27:40 +01:00
Ralf Jung
5e65109f21 add write_box_via_move intrinsic and use it for vec!
This allows us to get rid of box_new entirely
2026-02-16 17:27:40 +01:00
Daria Sukhonina
33a8dc10cf Fix wrong par_slice implementation 2026-02-16 17:49:42 +03:00
Folkert de Vries
3b5874e570
Improve VaList stdlib docs 2026-02-16 14:50:14 +01:00
Mateusz Mikuła
1d1280aae1 Build shared LLVM lib for windows-gnullvm 2026-02-16 14:26:14 +01:00
Mateusz Mikuła
8e9a79091f Add LLVM lib location to the linker search paths 2026-02-16 14:26:14 +01:00
Nicholas Nethercote
e9288e7e90 Remove last remnants of rustc_query_system.
At this point module `ich` is the only thing left.
2026-02-16 22:56:47 +11:00
Nicholas Nethercote
47ed4526d9 Remove DEP_NODE_DEBUG.
Like the previous commit, it's no longer needed.
2026-02-16 22:48:58 +11:00
Nicholas Nethercote
74dd36a934 Remove DEP_KIND_DEBUG.
It's plumbing to work around lack of access to `rustc_middle`, which is
no longer a problem.
2026-02-16 22:48:58 +11:00
Laurențiu Nicola
e52ed9c1ba
Merge pull request #21643 from Shourya742/2026-02-13-migrate-generate-impl-to-use-astnodeedit
migrate generate_impl assist to use AstNodeEdit
2026-02-16 11:11:40 +00:00
Ralf Jung
6a3a3d4f98 try to make cargo-miri work with bootstrap cargo 2026-02-16 11:47:55 +01:00
bors
71e00273c0 Auto merge of #152701 - jhpratt:rollup-clRaY9x, r=jhpratt
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#148206 (Deduplicated float tests and unified in floats/mod.rs)
 - rust-lang/rust#150601 (support c-variadic functions in `rustc_const_eval`)
 - rust-lang/rust#152103 (Consider captures to be used by closures that unwind)
 - rust-lang/rust#152296 (Port `rust_nonnull_optimization_guaranteed` and `rustc_do_not_const_check` to the new attribute parser)
 - rust-lang/rust#152648 (Remove timing assertion from `oneshot::send_before_recv_timeout`)
 - rust-lang/rust#152686 (bootstrap: Inline the `is_tool` check for setting `-Zforce-unstable-if-unmarked`)

Failed merges:

 - rust-lang/rust#152512 (core: Implement feature `float_exact_integer_constants`)
2026-02-16 09:55:35 +00:00
Jacob Pratt
84c522a6b4
Rollup merge of #152686 - Zalathar:force-unstable, r=jieyouxu
bootstrap: Inline the `is_tool` check for setting `-Zforce-unstable-if-unmarked`

`Mode::is_tool` is the sort of method that looks general-purpose, but is only actually used for a very specific purpose, to control the setting of `-Zforce-unstable-if-unmarked`.

It is therefore clearer to inline the mode check, which makes it easier to see how the condition affects the result.

I have tried to add some comments explaining why we set that flag, but they are based on my own recent investigations, so I'm not 100% confident that they're accurate.
2026-02-16 04:28:59 -05:00
Jacob Pratt
1dd933c37e
Rollup merge of #152648 - JonathanBrouwer:debug_spurious, r=jhpratt
Remove timing assertion from `oneshot::send_before_recv_timeout`

This test regularly spuriously fails in CI, such as https://github.com/rust-lang/rust/pull/152632#issuecomment-3902778366
We can just remove the assertion but I'd like to understand why, so I'm adding more information to the assert
2026-02-16 04:28:58 -05:00
Jacob Pratt
d1f3c9eea8
Rollup merge of #152296 - jdonszelmann:port-rust-nonnull-guaranteed, r=jonathanbrouwer
Port `rust_nonnull_optimization_guaranteed` and `rustc_do_not_const_check` to the new attribute parser

r? @JonathanBrouwer another two of them :)
2026-02-16 04:28:57 -05:00
Jacob Pratt
c9a7f8afa9
Rollup merge of #152103 - eggyal:caught-divergence-not-unused, r=cjgillot
Consider captures to be used by closures that unwind

Assignments to a captured variable within a diverging closure should not be considered unused if the divergence is caught.

This patch considers such assignments/captures to be used by diverging closures irrespective of whether the divergence is caught, but better a false negative unused lint than a false positive one (the latter having caused a stable-to-stable regression).

Fixes rust-lang/rust#152079
r? compiler
2026-02-16 04:28:57 -05:00
Jacob Pratt
494c6da389
Rollup merge of #150601 - folkertdev:c-variadic-const-eval, r=RalfJung
support c-variadic functions in `rustc_const_eval`

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

The new `GlobalAlloc::VaList` is used to create an `AllocId` that represents the variable argument list of a frame. The allocation itself does not store any data, all we need is the unique identifier.

The actual variable argument list is stored in `Memory`, and keyed by the `AllocId`. The `Frame` also stores this `AllocId`, so that when a frame is popped, it can deallocate the variable arguments.

At "runtime" a `VaList` value stores a pointer to the global allocation in its first bytes. The provenance on this pointer can be used to retrieve its `AllocId`, and the offset of the pointer is used to store the index of the next argument to read from the variable argument list.

Miri does not yet support `va_arg`, but I think that can be done separetely?

r? @RalfJung
cc @workingjubilee
2026-02-16 04:28:56 -05:00
Jacob Pratt
bff3e9edcc
Rollup merge of #148206 - xonx4l:deduplicate-float-tests, r=tgross35
Deduplicated float tests and unified in floats/mod.rs

In this PR Float tests are deduplicated and are unified in floats/mod.rs, as discussed in https://github.com/rust-lang/rust/issues/141726.

The moved float tests are:

-> test_powf
-> test_exp
-> test_exp2
-> test_ln
-> test_log_generic
-> test_log2
-> test_log10
-> test_asinh
-> test_acosh
-> test_atanh
-> test_gamma
-> test_ln_gamma

Closes: https://github.com/rust-lang/rust/issues/141726
2026-02-16 04:28:55 -05:00
Nicholas Nethercote
8d56cfe4c3 Move QuerySideEffect.
From `rustc_query_system` to `rustc_middle.` I put it in `graph.rs`,
it's one of two files that uses `QuerySideEffect` and seemed as good as
anywhere else.
2026-02-16 20:04:55 +11:00
Laurențiu Nicola
71c9411b19
Merge pull request #21653 from rust-lang/rustc-pull
minor: Rustc pull update
2026-02-16 09:03:05 +00:00
Nicholas Nethercote
72c7d8640f Remove rustc_query_system README file.
It's identical to the one in `rustc_query_impl`.
2026-02-16 19:58:18 +11:00
Jana Dönszelmann
12e6628977
Port rustc_nonnull_optimization_guaranteed to the new attribute parser 2026-02-16 09:46:04 +01:00
Jana Dönszelmann
47ca78040a
Port rustc_do_not_const_check to the new attribute parser 2026-02-16 09:38:31 +01:00
Ralf Jung
93d45480aa replace box_new in Box::new with write_via_move
requires lowering write_via_move during MIR building to make it just like an assignment
2026-02-16 08:44:56 +01:00
Zalathar
125e69e862 Suppress unstable-trait notes under -Zforce-unstable-if-unmarked 2026-02-16 17:19:05 +11:00
Zalathar
0f5c2215ad Regression test for "unstable" traits in force-unstable builds 2026-02-16 17:13:47 +11:00
The rustc-josh-sync Cronjob Bot
1fb6fc177f Merge ref '139651428d' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh.

Upstream ref: rust-lang/rust@139651428d
Filtered ref: rust-lang/rust-analyzer@3efb0c2db4
Upstream diff: ba284f468c...139651428d

This merge was created using https://github.com/rust-lang/josh-sync.
2026-02-16 04:54:45 +00:00
The rustc-josh-sync Cronjob Bot
2ef5156751 Prepare for merging from rust-lang/rust
This updates the rust-version file to 139651428d.
2026-02-16 04:49:19 +00:00
bors
fef627b1eb Auto merge of #152636 - nnethercote:big-cleanups, r=Zalathar
Big query system cleanups

Recent PRs have moved a lot of code from `rustc_query_system` to `rustc_middle` and `rustc_query_impl`, where this code now has access to `TyCtxt`, e.g. rust-lang/rust#152419, rust-lang/rust#152516. As a result, a lot of abstraction and indirection that existed to work around this limitation is no longer necessary. This PR removes a lot of it.

r? @Zalathar
2026-02-16 04:20:25 +00:00
Zalathar
f1664acfbf Inline the is_tool check for setting -Zforce-unstable-if-unmarked 2026-02-16 12:35:00 +11:00
bors
139651428d Auto merge of #152452 - ShE3py:overruled-lint, r=BoxyUwU
feat: show what lint was overruled

We can't `#[allow]` a whole lint group if any of its members is forbidden, but the offending member is not currently shown if it was forbidden from the command line.

Before/after:
```diff
 $ rustc -F dead_code - <<< '#![allow(unused)]'
 error[E0453]: allow(unused) incompatible with previous forbid
  --> <anon>:1:10
   |
 1 | #![allow(unused)]
   |          ^^^^^^ overruled by previous forbid
   |
-  = note: `forbid` lint level was set on command line
+  = note: `forbid` lint level was set on command line (`-F dead_code`)
 
 error: aborting due to 1 previous error
```

@rustbot label +A-diagnostics +A-lints +D-terse
2026-02-15 20:05:05 +00:00
Folkert de Vries
981dacc34f
feature-gate c-variadic definitions and calls in const contexts 2026-02-15 19:54:25 +01:00
Trevor Gross
83794755b7 clif: Only set has_reliable_f128_math with glibc
New float tests in core are failing on clif with issues like the
following:

    Undefined symbols for architecture arm64:
        "_coshf128", referenced from:
            __RNvMNtCshY0fR2o0hOA_3std4f128C4f1284coshCs5TKtJxXQNGL_9coretests in coretests-e38519c0cc90db54.coretests.44b6247a565e10d1-cgu.10.rcgu.o
                "_exp2f128", referenced from:
            __RNvMNtCshY0fR2o0hOA_3std4f128C4f1284exp2Cs5TKtJxXQNGL_9coretests in coretests-e38519c0cc90db54.coretests.44b6247a565e10d1-cgu.10.rcgu.o
        ...

Disable f128 math unless the symbols are known to be available, which
for now is only glibc targets. This matches the LLVM backend.
2026-02-15 18:00:54 +00:00
xonx
2c1d605f21 unify and deduplicate floats 2026-02-15 18:00:41 +00:00
Ralf Jung
1f39d1f74f
Merge pull request #4859 from rust-lang/rustup-2026-02-15
Automatic Rustup
2026-02-15 17:52:14 +00:00
The Miri Cronjob Bot
702793191f fmt 2026-02-15 18:20:47 +01:00
bors
873b4beb0c Auto merge of #152671 - JonathanBrouwer:rollup-4Ov19Nw, r=JonathanBrouwer
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#152566 (Remove code for ThinLTO from cg_gcc)
 - rust-lang/rust#152278 (Fix const normalization for generic const items with trait assoc consts)
 - rust-lang/rust#152604 (Relocate some tests)
 - rust-lang/rust#152625 (Provide all lint group names to Clippy)
2026-02-15 16:52:45 +00:00
Chayim Refael Friedman
23a3e642d7
Merge pull request #21648 from alexanderkjall/borsh-error-compilation-failure
fix smol_str compilation error
2026-02-15 16:42:02 +00:00
Jonathan Brouwer
ee17e8cb7c
Rollup merge of #152625 - Alexendoo:lint-group-names, r=Kivooeo
Provide all lint group names to Clippy

Unblocks https://github.com/rust-lang/rust-clippy/pull/14689
2026-02-15 16:37:38 +01:00
Jonathan Brouwer
c5a12fbd0d
Rollup merge of #152604 - reddevilmidzy:refactor, r=Zalathar
Relocate some tests

`dynamically-sized-types` -> `dst`
`underscore-imports` -> `imports/underscore-imports`
`btreemap`, `hashmap` -> `collections/btreemap`, `collections/hashmap`
`higher-ranked-trait-bounds` -> `higher-ranked/trait-bounds`
`meta` -> `compiletest-self-test`, `bootstrap`

After the review, I'll squash.
2026-02-15 16:37:37 +01:00
Jonathan Brouwer
8b3ef9e0c7
Rollup merge of #152278 - lapla-cogito:type_const_nested, r=BoxyUwU
Fix const normalization for generic const items with trait assoc consts

In `try_fold_free_or_assoc`, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with `#[type_const]` that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck.

close rust-lang/rust#151647

r? BoxyUwU
(Based on git blame)
2026-02-15 16:37:37 +01:00
Jonathan Brouwer
4a4ea14148
Rollup merge of #152566 - bjorn3:cg_gcc_no_thin_lto, r=antoyo
Remove code for ThinLTO from cg_gcc

It was just a dummy implementation to workarround the fact that thin local lto is the default in rustc. By adding a thin_lto_supported thin local lto can be automatically disabled for cg_gcc, removing the need for this dummy implementation. This makes improvements to the LTO handling on the cg_ssa side a lot easier.

cc [#rustc-codegen-gcc > thin LTO implementation](https://rust-lang.zulipchat.com/#narrow/channel/386786-rustc-codegen-gcc/topic/thin.20LTO.20implementation/with/573625132)
This should make the work on https://github.com/rust-lang/compiler-team/issues/908 easier.

r? rust-lang/wg-gcc-backend
2026-02-15 16:37:36 +01:00
Lieselotte
d12923346c
feat: show what lint was overruled 2026-02-15 15:40:13 +01:00
Embers-of-the-Fire
d13828b2c7
fix: re-format the changes 2026-02-15 22:34:53 +08:00
Embers-of-the-Fire
a8bbacd270
fix: remove unused import 2026-02-15 22:26:54 +08:00
Chayim Refael Friedman
5ad533b09c
Merge pull request #21649 from Albab-Hasan/fix/assignment-rhs-never-coercion
fix: use `ExprIsRead::Yes` for rhs of ordinary assignments
2026-02-15 14:16:24 +00:00
Embers-of-the-Fire
40a3ca1189
fix: remove unused source span 2026-02-15 22:01:01 +08:00