Commit graph

5254 commits

Author SHA1 Message Date
bjorn3
a03e769410 Improve standard library source remapping 2026-01-11 17:58:51 +00:00
bjorn3
4d0b725e06 Add a gdb helper for jit backtraces 2026-01-11 17:30:41 +00:00
bjorn3
c1569cc007 Lower extern "rust-cold" to default calling convention
The next Cranelift release will support for CallConv::Cold as it was
already effectively equivalent to the default calling convention.
2026-01-11 17:25:20 +00:00
bjorn3
9c369a43ce Rustup to rustc 1.94.0-nightly (fcd630976 2026-01-01) 2026-01-02 18:15:51 +00:00
bjorn3
b908e2e552 Sync from rust fcd630976c 2026-01-02 11:47:26 +00:00
bjorn3
6da1048236 Fix some divergences with the cg_clif subtree
For some reason git-subtree incorrectly synced those changes.
2025-12-24 15:16:59 +00:00
bors
fcdea4d663 Auto merge of #149114 - BoxyUwU:mgca_adt_exprs, r=lcnr
MGCA: Support struct expressions without intermediary anon consts

r? oli-obk

tracking issue: rust-lang/rust#132980

Fixes rust-lang/rust#127972
Fixes rust-lang/rust#137888
Fixes rust-lang/rust#140275

due to delaying a bug instead of ICEing in HIR ty lowering.

### High level goal

Under `feature(min_generic_const_args)` this PR adds another kind of const argument. A struct/variant construction const arg kind. We represent the values of the fields as themselves being const arguments which allows for uses of generic parameters subject to the existing restrictions present in `min_generic_const_args`:
```rust
fn foo<const N: Option<u32>>() {}

trait Trait {
    #[type_const]
    const ASSOC: usize;
}

fn bar<T: Trait, const N: u32>() {
    // the initializer of `_0` is a `N` which is a legal const argument
    // so this is ok.
    foo::<{ Some::<u32> { 0: N } }>();

    // this is allowed as mgca supports uses of assoc consts in the
    // type system. ie `<T as Trait>::ASSOC` is a legal const argument
    foo::<{ Some::<u32> { 0: <T as Trait>::ASSOC } }>();

    // this on the other hand is not allowed as `N + 1` is not a legal
    // const argument
    foo::<{ Some::<u32> { 0: N + 1 } }>();
}
```

This PR does not support uses of const ctors, e.g. `None`. And also does not support tuple constructors, e.g. `Some(N)`. I believe that it would not be difficult to add support for such functionality after this PR lands so have left it out deliberately.

We currently require that all generic parameters on the type being constructed be explicitly specified. I haven't really looked into why that is but it doesn't seem desirable to me as it should be legal to write `Some { ... }` in a const argument inside of a body and have that desugar to `Some::<_> { ... }`. Regardless this can definitely be a follow-up PR and I assume this is some underlying consistency with the way that elided args are handled with type paths elsewhere.

This PRs implementation of supporting struct expressions is somewhat incomplete. We don't handle `Foo { ..expr }` at all and aren't handling privacy/stability. The printing of `ConstArgKind::Struct` HIR nodes doesn't really exist either :')

I've tried to keep the implementation here somewhat deliberately incomplete as I think a number of these issues are actually quite small and self contained after this PR lands and I'm hoping it could be a good set of issues to mentor newer contributors on 🤔 I just wanted the "bare minimum" required to actually demonstrate that the previous changes are "necessary".

### `ValTree` now recurse through `ty::Const`

In order to actually represent struct/variant construction in `ty::Const` without going through an anon const we would need to introduce some new `ConstKind` variant. Let's say some hypothetical `ConstKind::ADT(Ty<'tcx>, List<Const<'tcx>>)`.

This variant would represent things the same way that `ValTree` does with the first element representing the `VariantIdx` of the enum (if its an enum), and then followed by a list of field values in definition order.

This *could* work but there are a few reasons why it's suboptimal.

First it would mean we have a second kind of `Const` that can be normalized. Right now we only have `ConstKind::Unevaluated` which possibly needs normalization. Similarly with `TyKind` we *only* have `TyKind::Alias`. If we introduced `ConstKind::ADT` it would need to be normalized to a `ConstKind::Value` eventually. This feels to me like it has the potential to cause bugs in the long run where only `ConstKind::Unevaluated` is handled by some code paths.

Secondly it would make type equality/inference be kind of... weird... It's desirable for `Some { 0: ?x } eq Some { 0: 1_u32 }` to result in `?x=1_u32`.  I can't see a way for this to work with this `ConstKind::ADT` design under the current architecture for how we represent types/consts and generally do equality operations.

We would need to wholly special case these two variants in type equality and have a custom recursive walker separate from the existing architecture for doing type equality. It would also be somewhat unique in that it's a non-rigid `ty::Const` (it can be normalized more later on in type inference) while also having somewhat "structural" equality behaviour.

Lastly, it's worth noting that its not *actually* `ConstKind::ADT` that we want. It's desirable to extend this setup to also support tuples and arrays, or even references if we wind up supporting those in const generics. Therefore this isn't really `ConstKind::ADT` but a more general `ConstKind::ShallowValue` or something to that effect. It represents at least one "layer" of a types value :')

Instead of doing this implementation choice we instead change `ValTree::Branch`:
```rust
enum ValTree<'tcx> {
    Leaf(ScalarInt),
    // Before this PR:
    Branch(Box<[ValTree<'tcx>]>),
    // After this PR
    Branch(Box<[Const<'tcx>]>),
}
```

The representation for so called "shallow values" is now the same as the representation for the *entire* full value. The desired inference/type equality behaviour just falls right out of this. We also don't wind up with these shallow values actually being non-rigid. And `ValTree` *already* supports references/tuples/arrays so we can handle those just fine.

I think in the future it might be worth considering inlining `ValTree` into `ty::ConstKind`. E.g:
```rust
enum ConstKind {
    Scalar(Ty<'tcx>, ScalarInt),
    ShallowValue(Ty<'tcx>, List<Const<'tcx>>),
    Unevaluated(UnevaluatedConst<'tcx>),
    ...
}
```

This would imply that the usage of `ValTree`s in patterns would now be using `ty::Const` but they already kind of are anyway and I think that's probably okay in the long run. It also would mean that the set of things we *could* represent in const patterns is greater which may be desirable in the long run for supporting things such as const patterns of const generic parameters.

Regardless, this PR doesn't actually inline `ValTree` into `ty::ConstKind`, it only changes `Branch` to recurse through `Const`. This change could be split out of this PR if desired.

I'm not sure if there'll be a perf impact from this change. It's somewhat plausible as now all const pattern values that have nesting will be interning a lot more `Ty`s. We shall see :>

### Forbidding generic parameters under mgca

Under mgca we now allow all const arguments to resolve paths to generic parameters. We then *later* actually validate that the const arg should be allowed to access generic parameters if it did wind up resolving to any.

This winds up just being a lot simpler to implement than trying to make name resolution "keep track" of whether we're inside of a non-anon-const const arg and then encounter a `const { ... }` indicating we should now stop allowing resolving to generic parameters.

It's also somewhat in line with what we'll need for a `feature(generic_const_args)` where we'll want to decide whether an anon const should have any generic parameters based off syntactically whether any generic parameters were used. Though that design is entirely hypothetical at this point :)

### Followup Work

- Make HIR ty lowering check whether lowering generic parameters is supported and if not lower to an error type/const. Should make the code cleaner, fix some other bugs, and maybe(?) recover perf since we'll be accessing less queries which I think is part of the perf regression of this PR
- Make the ValTree setup less scuffed. We should find a new name for `ConstKind::Value` and the `Val` part of `ValTree` and `ty::Value` as they no longer correspond to a fully normalized structure. It may also be worth looking into inlining `ValTreeKind` into `ConstKind` or atleast into `ty::Value` or sth 🤔
- Support tuple constructors and const constructors not just struct expressions.
- Reduce code duplication between HIR ty lowering's handling of struct expressions, and HIR typeck's handling of struct expressions
- Try fix perf https://github.com/rust-lang/rust/pull/149114#issuecomment-3668038853. Maybe this will clear up once we clean up `ValTree` a bit and stop doing double interning and whatnot
2025-12-23 23:53:55 +00:00
bjorn3
4e375db44a Merge commit '6f3f6bdacb' into sync_cg_clif-2025-12-23 2025-12-23 17:47:42 +00:00
bjorn3
6f3f6bdacb Rustup to rustc 1.94.0-nightly (4f14395c3 2025-12-22) 2025-12-23 16:22:22 +00:00
bjorn3
de4168be8c Sync from rust 4f14395c37 2025-12-23 16:07:31 +00:00
bjorn3
6bb3a40d53 Update to Cranelift 0.127 2025-12-23 15:31:24 +00:00
bjorn3
c252af5cbb Fix audit workflow 2025-12-23 15:30:38 +00:00
Boxy Uwu
50ef284125 Fix tools 2025-12-23 13:55:00 +00:00
Boxy Uwu
1acfdbb3cd Make ValTree recurse through ty::Const 2025-12-23 13:54:59 +00:00
bors
987298c392 Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin
Replace Rvalue::NullaryOp by a variant in mir::Operand.

Based on https://github.com/rust-lang/rust/pull/148151

This PR fully removes the MIR `Rvalue::NullaryOp`. After rust-lang/rust#148151, it was only useful for runtime checks like `ub_checks`, `contract_checks` and `overflow_checks`.

These are "runtime" checks, boolean constants that may only be `true` in codegen. It depends on a rustc flag passed to codegen, so we need to represent those flags cross-crate.

This PR replaces those runtime checks by special variants in MIR `ConstValue`. This allows code that expects constants to manipulate those as such, even if we may not always be able to evaluate them to actual scalars.
2025-12-22 06:58:28 +00:00
Moulins
005046ddd4 layout: Store inverse memory index in FieldsShape::Arbitrary
All usages of `memory_index` start by calling `invert_bijective_mapping`, so
storing the inverted mapping directly saves some work and simplifies the code.
2025-12-18 22:25:34 +01:00
bjorn3
f4bb7d1de1 Merge branch 'sync_from_rust' 2025-12-18 11:54:02 +00:00
bjorn3
45671b42e6 Merge commit '8de4afd39b' into sync_cg_clif-2025-12-18 2025-12-18 11:50:08 +00:00
bjorn3
8de4afd39b Fix rustc testsuite 2025-12-18 11:09:12 +00:00
bjorn3
6396521fdb Rustup to rustc 1.94.0-nightly (f794a0873 2025-12-17) 2025-12-18 10:52:32 +00:00
bjorn3
4dc8f3ebce Sync from rust f794a08738 2025-12-18 10:42:16 +00:00
bjorn3
3822cf126b Disable a bunch of rustc tests that fail with --panic-unwind-support 2025-12-16 17:00:09 +00:00
bjorn3
bb9dac5fe5 Disable linker plugin lto rustc test 2025-12-16 16:49:44 +00:00
bjorn3
49f1fa5110 Unconditionally install rustfmt
Rustfmt used to be optional for nightlies long ago, but it is now
always present. Also rename rust-toolchain to rust-toolchain.toml.
2025-12-16 16:42:17 +00:00
bjorn3
b73270f189 Fix rustc test suite 2025-12-16 16:40:44 +00:00
bjorn3
b9839eb105 Rustup to rustc 1.94.0-nightly (21ff67df1 2025-12-15) 2025-12-16 16:13:22 +00:00
bjorn3
216d1a7ad2 Sync from rust 21ff67df15 2025-12-16 16:07:44 +00:00
Stuart Cook
d57ccad63d Rollup merge of #149950 - WaffleLapkin:inlines-ur-mu-into-asm, r=jdonszelmann
Simplify how inline asm handles `MaybeUninit`

This is just better, but this is also allows it to handle changes from https://github.com/rust-lang/rust/pull/149614 (i.e. `ManuallyDrop` containing `MaybeDangle`).
2025-12-16 14:40:44 +11:00
Camille Gillot
85921620d1 Use ScalarInt from bool. 2025-12-14 17:29:59 +00:00
Camille Gillot
a3676bd0fa Introduce Operand::RuntimeChecks. 2025-12-14 17:25:53 +00:00
Camille Gillot
a0de5ae5a1 Replace Rvalue::NullaryOp by a variant in mir::ConstValue. 2025-12-14 17:25:51 +00:00
Opstic
4748c53720
Add llvm.x86.vcvtps2ph.128 (#1613)
* Add `llvm.x86.vcvtps2ph.128`

* `cargo fmt`

* Test `_mm_cvtps_ph`
2025-12-14 11:53:13 +01:00
Waffle Lapkin
6a821c5518 simplify how inline asm handles MaybeUninit 2025-12-13 15:50:02 +01:00
bors
956134622e Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Overhaul filename handling for cross-compiler consistency

This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`).

This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang/rust#148328).

In order to achieved consistency multiple steps are being taken by this PR:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
   - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue
 - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes
   - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename

In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed.

This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes.

Unblocks https://github.com/rust-lang/rust/pull/147611
Fixes https://github.com/rust-lang/rust/issues/148328
2025-12-13 14:32:09 +00:00
bjorn3
812320aa95
Merge pull request #1612 from Urgau/Urgau-patch-1
Remove `[no-mentions]` handler in the triagebot config
2025-12-12 20:34:43 +01:00
Esteban Küber
e3f9bcef74 Use let...else instead of match foo { ... _ => return }; and if let ... else return 2025-12-12 17:52:39 +00:00
Urgau
4d011efb8e
Remove [no-mentions] handler in the triagebot config
https://github.blog/changelog/2025-11-07-removing-notifications-for-mentions-in-commit-messages/
2025-12-12 18:13:08 +01:00
Matthias Krüger
2298c01a8b Rollup merge of #149791 - clubby789:cfg-bool-lints, r=jdonszelmann
Remove uses of `cfg({any()/all()})`

~~This implements the followup warning suggested in https://github.com/rust-lang/rfcs/pull/3695~~
~~Lint against an empty `cfg(any/all)`, suggest the boolean literal equivalents.~~
https://github.com/rust-lang/rust/pull/149791#issuecomment-3638624348

Tracking issue: https://github.com/rust-lang/rust/issues/131204
2025-12-12 12:19:09 +01:00
Urgau
d55b61a684 Adapt cg_cranelift to the overhauled filename handling 2025-12-12 07:34:52 +01:00
Jamie Hill-Daniel
932c939c9f Remove uses of cfg(any()/all()) 2025-12-10 23:41:19 +00:00
Matthias Krüger
51e8b6e427 Rollup merge of #149764 - Zalathar:has-zstd, r=bjorn3
Make `--print=backend-has-zstd` work by default on any backend

Using a defaulted `CodegenBackend` method that querying for zstd support should automatically print a safe value of `false` on any backend that doesn't specifically indicate the presence or absence of zstd.

This should fix the compiletest failures reported in https://github.com/rust-lang/rust/pull/149666#discussion_r2597881482, which can occur when LLVM is not the default codegen backend.
2025-12-10 17:16:48 +01:00
Matthias Krüger
77f1582a9e Rollup merge of #147725 - bjorn3:remove_oom_panic, r=Amanieu
Remove -Zoom=panic

There are major questions remaining about the reentrancy that this allows. It doesn't have any users on github outside of a single project that uses it in a panic=abort project to show backtraces. It can still be emulated through `#[alloc_error_handler]` or `set_alloc_error_hook` depending on if you use the standard library or not. And finally it makes it harder to do various improvements to the allocator shim.

With this PR the sole remaining symbol in the allocator shim that is not effectively emulating weak symbols is the symbol that prevents skipping the allocator shim on stable even when it would otherwise be empty because libstd + `#[global_allocator]` is used.

Closes https://github.com/rust-lang/rust/issues/43596
Fixes https://github.com/rust-lang/rust/issues/126683
2025-12-10 07:54:17 +01:00
Zalathar
d38a5a6d1d Make --print=backend-has-zstd work by default on any backend
Using a defaulted `CodegenBackend` method that querying for zstd support should
automatically print a safe value of `false` on any backend that doesn't
specifically indicate the presence or absence of zstd.
2025-12-09 12:57:19 +11:00
bjorn3
66381e3d79 Revert build_llvm_sysroot_for_triple back from reading the manifest to filtering
Reading the manifest doesn't work when running in the context of the
rust build system.
2025-12-08 19:11:10 +00:00
bjorn3
069016eef8 Merge branch 'sync_from_rust' 2025-12-08 16:25:15 +00:00
bjorn3
6693a568af Merge commit 'e24f0fa3c5' into sync_cg_clif-2025-12-08 2025-12-08 16:20:48 +00:00
bjorn3
e24f0fa3c5 Update dependencies 2025-12-08 11:20:15 +00:00
bjorn3
154e158a47
Merge pull request #1609 from rust-lang/line_table_only_debuginfo
Only generate line tables with -Cdebuginfo=line-table-only
2025-12-08 11:38:14 +01:00
bjorn3
8b0e6756e0 Only generate line tables with -Cdebuginfo=line-table-only 2025-12-08 10:22:41 +00:00
bjorn3
ba27d3d8a6 Fix gimli assertion for anonymous sources 2025-12-08 10:22:41 +00:00