Commit Graph

1303 Commits

Author SHA1 Message Date
bjorn3
12ac752844 Don't compute FnAbi for LLVM intrinsics 2026-08-13 14:20:02 +02:00
mejrs
196dd2a174 Fix up lang_items import paths 2026-08-09 15:20:29 +02:00
Chayim Refael Friedman
5491ec85e2 Instead of representing trait errors as Vec<Error>, use a special type
This has multiple advantages:

 - Performance. The new type is 1/3 the size of `Vec` (being equivalent in layout to `Option<ThinVec>`) and can be kept in a register.
 - Type safety. We mark the type `#[must_use]`, and thinks requiring errors take `ThinVec`, which requires unwrapping the type and verifying there is indeed an error. We still provide conversions to slices, `ThinVec`, and iteration, because some code needs this and I saw no benefit in changing it, but we deliberately do not provide `Deref<Target = [E]>` or things like that.
2026-08-06 07:18:55 +03:00
Jonathan Brouwer
4c08ad5b0c Rollup merge of #160362 - joshtriplett:ty-walk-crate, r=fee1-dead
Split `SpannedTypeVisitor` into its own crate, `rustc_ty_walk`

`rustc_privacy` pulls in all of `rustc_ty_utils`, but only wants `SpannedTypeVisitor` and `walk_types`. Move those to a small `rustc_ty_walk` crate.

This allows `rustc_privacy` to start building much sooner.
2026-08-05 13:36:14 +02:00
Ada Alakbarova
c99698344d rename OutlivesPredicate to OutlivesClause 2026-08-05 11:07:35 +02:00
Josh Triplett
82317b3f68 Split SpannedTypeVisitor into its own crate, rustc_ty_walk
`rustc_privacy` pulls in all of `rustc_ty_utils`, but only wants
`SpannedTypeVisitor` and `walk_types`. Move those to a small
`rustc_ty_walk` crate.

This allows `rustc_privacy` to start building much sooner.
2026-08-03 21:47:29 -07:00
Jacob Pratt
31e12ee467 Rollup merge of #160124 - scottmcm:simd-count, r=oli-obk
Structurally prevent zero-count `BackendRepr::SimdVector`s

This is already *supposed* to be impossible in layout, but this emphasizes that better.  This PR makes no behaviour changes; just `BackendLaneCount` instead of `u64` in https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.BackendRepr.html

Ironically I was inspired to do this as part of [looking at making `Simd<T, 0>` *work*](https://rust-lang.zulipchat.com/#narrow/channel/257879-project-portable-simd/topic/Allow.20N.3D.3D0.3F/with/613345298), but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
2026-07-31 22:25:12 -04:00
Scott McMurray
6da3077db9 Structurally prevent zero-count BackendRepr::SimdVectors
This is already *supposed* to be impossible in layout, but this emphasizes that better.

Ironically I was inspired to do this as part of looking at making `Simd<T, 0>` *work*, but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
2026-07-30 19:48:24 -07:00
Ada Alakbarova
952cbef562 A few more "predicate"-to-"clause" renamings
Follow-up to https://github.com/rust-lang/rust/pull/159990. This should
cover all the files that I didn't get to reviewing in that PR.
2026-07-29 23:57:47 +02:00
Jonathan Brouwer
bb97a9c5ac Rollup merge of #159509 - scottmcm:redo-valid-range, r=oli-obk
Generate `valid_range`s for enums sign-agnostically

Prompted by https://github.com/rust-lang/rust/issues/159438#issuecomment-5007170897, this reworks the generation of the tag layout information for enums.

Having gone down the wrong path at first here, I think the core trouble this is having is that the current calculation is trying to serve two incompatible desires:
- When picking the `value: Primitive`, we need to respect the signedness of the original *discriminant* numbers as typed in Rust.
- When picking the `valid_range: WrappingRange`, we want to *ignore* the signedness (and size!) of the discriminants and look only at the bit values (and size) of the *tags* themselves.

This thus splits the handling in `layout_of_enum` into those two parts, handled differently.
- When looking at *discriminants* (to eventually call [`discr_range_of_repr`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/layout/trait.IntegerExt.html#tymethod.discr_range_of_repr)), we obey the signedness of the inputs to find the smallest negative discriminant and largest positive discriminant -- notably *without* any wraparound logic.
- Then after having used the discriminants to pick a *tag* size, then we run a wrapping-aware check to pick the best `WrappingRange` to represent those tags (which can be a different range than we'd have picked on the discriminants, especially for `repr(Rust)` where the discriminants are `isize`).

With apologies for sending this when you'd said you'd look at it, but I got inspired 😅
r? @oli-obk

Fixes rust-lang/rust#159438

---

I have a bunch of commits in here; it's probably best reviewed one at a time.

1. Just moving `WrappingRange` to its own file, since the `lib.rs` is over 2000 lines already so if I was going to add stuff I figured some reorganizing could help.
2. Adding a new constructor to `WrappingRange` that takes an iterator of values and returns a range containing those values.  Dealing just in `u128` + `Size`, like `WrappingRange` does in other places, it doesn't even *have* signedness information so structurally is prevented from having any "why are `repr(u8)` and `repr(i8) picking different ranges?" issues.  I found it helpful to have this split out from the layout code, for example that it let me put some examples on the doc-comment.  Nothing actually *uses* the new function in this commit though.
3. Stop giving layout discriminants as `i128` since <https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/util/struct.Discr.html#structfield.val> points out that they're generated as `u128` in the same way that `WrappingRange` uses already -- even with the field doc that `-1_i8` is generated as `255_u128`, so the `as i128`ing was probably just making everything more confusing here than it needed to be.
4. Adding some tests looking at the generated `Primitive` and `valid_range`, along with rustc support for `#[rustc_dump_layout(largest_niche)]` to help have these tests include specific ERROR annotations rather than just the stderr.  The tests pass at this point, so the next commit can update them to show the change.
5. This one actually updates layout code, including using the `WrappingRange` constructor added earlier.
2026-07-29 14:10:30 +02:00
Nicholas Nethercote
ff161b18b5 Many "predicate"-to-"clause" renamings
Lots of names weren't changed to account for the introduction of the
`Clause` type as a specialized form of `Predicate`, presumably because
it was tedious. This commit converts as many of them as I could find.
It's mostly very tedious renamings of types, functions, variables, and
queries. The more interesting ones are a couple of files
(`predicates_of.rs`, `impossible_predicates.rs`) and a MIR pass
(`ImpossiblePredicates`).
2026-07-28 11:48:45 +10:00
bors
ad0c9dce27 Auto merge of #159317 - workingjubilee:aarch64-bool-callconv, r=davidtwco
Fix `bool` calling convention for aarch64, etc.



We have been making a broad assumption about the way `bool` should be handled that *may* be correct for Rust calling Rust but is wildly incorrect for cross-language FFI calls. The ABI of `bool` is generally poorly-specified in any C psABI, and often deliberately allows for deviation after the first 8 bits.

This has surfaced as a bug that can corrupt Rust programs on aarch64, but it is a potential latent bug when it comes to every ABI. The simplest solution is to simply stop applying the special case when generating `bool`'s ArgAttributes. This yields control to the later ABI implementations, which may then sign or zero extend the `bool` (or not) according to their needs.
2026-07-27 09:35:03 +00:00
Oli Scherer
e9ad00c5af Remove 'static requirement on try_as_dyn 2026-07-23 10:59:01 +02:00
Jonathan Brouwer
92190394b9 Rollup merge of #159659 - mejrs:limit, r=petrochenkov
Move `Limit` out of `rustc_hir`

It feels rather out of place in `rustc_hir`, so this PR moves it to `rustc_data_structures`. Part of hopefully moving attributes from `rustc_hir` to their own crate.

~~This also lets `rustc_type_ir` use it~~ actually rustc_type_ir needs to compile on stable and `rustc_data_structures` uses like 30 features 😢
2026-07-22 18:02:21 +02:00
Scott McMurray
9cbba6e19e Fix signedness handling when picking enum ranges 2026-07-21 20:40:05 -07:00
Scott McMurray
e5f0680ee2 Stop passing the discriminant as i128 when Discr makes it as u128 2026-07-21 20:40:04 -07:00
mejrs
ac91844c53 Fixup Limit imports 2026-07-21 15:26:08 +02:00
James Barford-Evans
80d18b365d Import extension traits and region 2026-07-21 12:05:14 +01:00
Jonathan Brouwer
f62edc7b8d Rollup merge of #156650 - dingxiangfei2009:coro-no-prefix-tys, r=cjgillot
Stop using prefix_tys

*This is a member of a patch series to replace rust-lang/rust#135527.*

This function hints at an early commitment to coroutine memory layout. We should not give promises on how upvars are allocated.
2026-07-18 23:12:20 +02:00
Jubilee Young
444dd284f8 compiler: Remove the bool special-case in ty_utils
We still attach `noundef` using the code that immediately follows.
It will be fine, trust.
2026-07-15 16:44:32 -07:00
Ralf Jung
88ff4b0213 interpret: properly check for inhabitedness of nested references 2026-07-15 23:35:36 +02:00
Xiangfei Ding
cf188034a0 Stop using prefix_tys
This function hints at an early commitment to coroutine memory layout.
We should not give promises on how upvars are allocated.

Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
2026-07-15 13:36:35 +00:00
Jonathan Brouwer
09e4f79388 Rollup merge of #159183 - bjorn3:instance_llvm_intrinsic, r=RalfJung,folkertdev
Introduce InstanceKind::LlvmIntrinsic

This way codegen backends don't have to check for a magic symbol name prefix to detect LLVM intrinsic calls and thus can more easily handle them separately as necessary.
2026-07-14 16:49:04 +02:00
Jacob Pratt
e59b99943f Rollup merge of #159248 - workingjubilee:remove-mutable-noalias, r=Urgau
compiler: Remove `-Zmutable-noalias`

Let us mark the end of an era. The `noalias` optimization has been working relatively well for some time now. There may still be issues to sort out with `noalias`. If so, those are mostly on LLVM's side, where it may need to have a better model of what `noalias` means as that is necessary for soundly inferring it. We also may need to not add `noalias` somewhere we currently do, if our semantics do not actually match that. Either way, it doesn't seem useful to configure on a compilation-wide basis.
2026-07-14 00:15:24 -04:00
Jonathan Brouwer
3bb66d7229 Rollup merge of #158632 - addiesh:superfisher, r=oli-obk
First steps of late-bound turbofishing (place FnDef behind a dummy binder)

r? oli-obk

This PR is part of rust-lang/rust#156581. This should be functionally identical to prior behavior, with the added fact that FnDef now places its arguments behind a binder.

most changes boil down to
- replacing `args` from `FnDef` with `args.no_bound_vars().unwrap()`
- replacing `Ty::new_fn_def(/* ... */, args)` with `Ty::new_fn_def(/* ... */, ty::Binder::dummy(args))`
2026-07-13 20:18:00 +02:00
Jubilee Young
7e1c0b6ebb compiler: Remove -Zmutable-noalias 2026-07-13 10:13:02 -07:00
bjorn3
8c2ed2f9a1 Introduce InstanceKind::LlvmIntrinsic
This way codegen backends don't have to check for a magic symbol name
prefix to detect LLVM intrinsic calls and thus can more easily handle
them separately as necessary.
2026-07-13 14:20:37 +00:00
Jana Dönszelmann
91311aecb9 Fixup all current uses of todo!() in the compiler 2026-07-13 10:47:09 +02:00
addie.sh
8fb83aba33 place FnDef behind a binder, instantiate w/ Dummy 2026-07-10 14:53:35 -04:00
khyperia
64c7dce072 merge DefKind::InlineConst into AnonConst 2026-07-10 13:43:56 +02:00
Jacob Pratt
c6881304fb Rollup merge of #158666 - scottmcm:scalar-but-packed, r=workingjubilee
Carry the `b_offset` inside `BackendRepr::ScalarPair`

Inspired by https://github.com/rust-lang/compiler-team/issues/1007 but doesn't actually change any of the layout rules just yet.

This turned out to be a nice change even if we didn't use the extra flexibility, IMHO, because it allowed so many things like

```diff
@@ -222,12 +224,12 @@ fn from_const_alloc<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
                 let val = read_scalar(offset, size, s, bx.immediate_backend_type(layout));
                 OperandRef { val: OperandValue::Immediate(val), layout, move_annotation: None }
             }
-            BackendRepr::ScalarPair(
-                a @ abi::Scalar::Initialized { .. },
-                b @ abi::Scalar::Initialized { .. },
-            ) => {
+            BackendRepr::ScalarPair {
+                a: a @ abi::Scalar::Initialized { .. },
+                b: b @ abi::Scalar::Initialized { .. },
+                b_offset,
+            } => {
                 let (a_size, b_size) = (a.size(bx), b.size(bx));
-                let b_offset = (offset + a_size).align_to(b.default_align(bx).abi);
                 assert!(b_offset.bytes() > 0);
                 let a_val = read_scalar(
                     offset,
```

as *oh my* was that little magic incantation copy-pasted all over the place.

Apologies for the pretty-giant PR.  I tried to make it as direct a change as I could: if it was `(..)` before it's `{ .. }` now, if it was `(_, _)` before it's `{ a: _, b: _, b_offset: _ }` now.  I kept the names the same so the code lines were unchanged even if normally I might have just renamed things, etc.  I'll add some inline notes for places of particular interest.

r? @workingjubilee
2026-07-08 22:45:49 -04:00
Scott McMurray
2efdc665a7 Carry the b_offset inside BackendRepr::ScalarPair 2026-07-07 01:15:36 -07:00
Cameron Steffen
f13657cad6 Rename some body_id vars to body_def_id
`body_id` is often used to mean "ID of a body-owning node", which is
confusing since the obvious reading of "body ID" is wrong.

`body_def_id` is easier to read as "body-owning definition ID".
2026-07-06 17:03:14 -05:00
Jonathan Brouwer
3dad78a3e4 Rollup merge of #158627 - cuviper:option-iterator-flattening, r=nnethercote
Simplify option-iterator flattening in the compiler

In many cases where we are flattening `option::IntoIter<I>`, we can use
`Option::into_flat_iter()` instead for a simpler implementation. A few
other cases have more direct constructs available.
2026-07-05 08:47:04 +02:00
Jacob Pratt
9272c6d92a Rollup merge of #158542 - scottmcm:scalar-but-packed, r=workingjubilee
Rename `align` to `default_align` on `Scalar` and `Primitive`

To emphasize that just because you see a `Scalar(I32)` that doesn't really tell you anything about the alignment it has -- one should be looking at the type (well, the place) for that.

(The `size` method doesn't really have that problem -- i32 is always 4 bytes, no matter the context -- so is left untouched.)

No actual layout or behaviour changes in *this* PR.  Just the rename and some comments.

r? @workingjubilee
2026-07-01 01:03:18 -04:00
Josh Stone
4480d7859f Use Option::into_flat_iter in the compiler
In many cases where we are flattening `option::IntoIter<I>`, we can use
`into_flat_iter()` instead for a simpler implementation.
2026-06-30 12:21:16 -07:00
Jonathan Brouwer
0c58e97926 Rollup merge of #158375 - khyperia:inline-consts-in-type-system, r=BoxyUwU
Support `DefKind::InlineConst` in `ConstKind::Unevaluated`

fixes https://github.com/rust-lang/project-const-generics/issues/101

required for https://github.com/rust-lang/project-const-generics/issues/108

consider: `Struct<{ (some, stuff, const { hi }) }>`. The following is very pseudocode-y, the important parts are whether it says AnonConst or InlineConst, not the Tuple stuff

- On stable, we represent this with: `AnonConst(Tuple(some, stuff, InlineConst(hi)))`
- Under mGCA, with "direct" arguments, before this PR, it was `Tuple(some, stuff, AnonConst(hi))`. The inner InlineConst got intercepted in the def_collector with hacks (`ConstArgContext`) and converted into an AnonConst, even though it has inline const syntax.

It would be nice to keep it as an InlineConst under mGCA, i.e. `Tuple(some, stuff, InlineConst(hi))`, and have the type system support passing around InlineConsts in `ConstKind::Unevaluated` (soon to be renamed `ConstKind::Alias`). This would allow the def collector to not need to know if we are in a "direct" or "regular/anon" context, which it turns out is extremely useful for implementing https://github.com/rust-lang/project-const-generics/issues/108. Supporting InlineConsts in the type system are also useful for other things, for example, mentioned in https://github.com/rust-lang/project-const-generics/issues/101 is arg position const generics experiments.

This PR does two things:

- support InlineConsts in the type system (i.e. in `ConstKind::Unevaluated`)
- exercise that support, by no longer intercepting mGCA "direct" argument inline consts to be anon consts

r? @BoxyUwU
2026-06-30 03:41:33 +02:00
Scott McMurray
f98365f1f3 Rename align to platform_align on Scalar and Primitive
To emphasize that just because you see a `Scalar(I32)` that doesn't really tell you anything about the alignment it has -- one should be looking at the type (well, the place) for that.

No actual layout or behaviour changes in *this* PR.
2026-06-29 09:48:16 -07:00
Jonathan Brouwer
42d784a0c4 Rollup merge of #156419 - jakubadamw:update-itertools-to-0.15, r=Mark-Simulacrum
Update itertools to 0.15

This bumps the itertools dependency to [0.15](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md#0150).

There’s a breaking change upstream in the shape of `itertools::Position`, so this updates the use sites of it as well, aside from submodules like clippy, which will be handled [separately](https://github.com/rust-lang/rust-clippy/pull/16805).
2026-06-28 20:45:49 +02:00
khyperia
f31f522f45 Support DefKind::InlineConst in UnevaluatedConst 2026-06-27 17:49:30 +02:00
bors
cb41b6d3da Auto merge of #158115 - Shourya742:2026-06-19-rename-unevaluatedConst-to-aliasconst, r=BoxyUwU,khyperia
Rename UnevaluatedConst to AliasConst



refer: https://github.com/rust-lang/project-const-generics/issues/115

r? @khyperia 


I only renamed the type system version to `AliasConst`/`AliasConstKind`. I did not rename MIR’s `UnevaluatedConst`, it currently holds direct def_id instead of kind variant we have in type-system. I also left `rustc_public`’s `UnevaluatedConst` unchanged.
2026-06-27 11:04:54 +00:00
Jonathan Brouwer
64f56e793b Rollup merge of #158360 - oli-obk:borrowck-cleanups, r=lcnr
Various borrowck cleanups and param_env/opaque_types_defined_by query simplifications for typeck children

Various things I noticed while figuring out how to best allow changing some borrowck errors into FCWs

cc @rust-lang/types for the typeck children stuff, in case I missed some memo and am undoing some work

r? @ghost need perf first
2026-06-26 20:22:17 +02:00
bit-aloo
0af46a845c * ConstKind::Unevaluated -> ConstKind::Alias
* Const::new_unevaluated / interner method -> new_alias
* Interner::UnevaluatedConstId -> AnonConstId, since assoc type is only used for anonnymous consts
2026-06-26 06:51:27 +00:00
bit-aloo
8461b0dd61 Rename unevaluatedConst to AliasConst and UnevaluatedConstKind to AliasConstKind 2026-06-26 06:14:50 +00:00
Adwin White
3dbe96a5a1 add IsRigid marker to TyKind::Alias and constants 2026-06-25 17:12:10 +08:00
Jacob Adam
efce3046cd Update itertools to 0.15 2026-06-24 23:18:10 +01:00
Oli Scherer
7cb94f0f36 Don't compute opaque types for typeck children. They are always the same as their parent 2026-06-24 16:36:39 +02:00
Oli Scherer
7102a6ca9f Typeck children always have the same param env as their parent 2026-06-24 13:12:01 +02:00
Jacob Pratt
b924098bc9 Rollup merge of #158105 - camelid:group-shims, r=oli-obk
Extract all instance shim variants into new `ShimKind` enum

They tend to have similar handling -- e.g., they should be the only
input to the `mir_shims` query -- so it's cleaner to group them
together. This will also make potential future refactorings easier, such
as only carrying `GenericArgsRef` for instances that actually use it
(e.g., `Item`) but not others (e.g., `CloneShim`).

cc https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/moving.20ty.3A.3AInstance.2Eargs.20into.20ty.3A.3AInstanceKind.20variants
r? @oli-obk
2026-06-24 00:40:18 -04:00
Jacob Pratt
20dc5b4114 Rollup merge of #157983 - folkertdev:tailcc-lift-same-signature-restriction, r=WaffleLapkin
Lift the same-signature restriction for `extern "tail"`

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

The `extern "tail"` calling convention uses callee cleanup (i.e. the callee restores the stack, not the caller). Hence, the same-signature restriction that is normally required to codegen tail calls does not apply.

We need the ABI to deviate from `extern "Rust"` to make sure indirect arguments are passed by stack offset, not via a pointer into the caller's stack frame (the value would potentially be overwritten). For standard tail calls we work around this problem by storing the value in the caller's caller, but for `extern "tail"` that doesn't work reliably because the signatures can be different.

I'm not sure about unsized arguments. That feature seems really broken, so I'm not sure how much work we should put into trying to do something reasonable there. Fundamentally I don't think we can support unsized arguments in `extern "tail"` calls.

Also we can't really promote using this yet due to `tailcc` being a bit broken on LLVM 22 on x86_64.

r? WaffleLapkin
cc @bjorn3
2026-06-24 00:40:16 -04:00