Commit Graph

151 Commits

Author SHA1 Message Date
Jacob Pratt
edb63697e3 Rollup merge of #160676 - makai410:rpub/cleanup, r=celinval
rustc_public: split `def`s out of `ty`

This is more of an "I feel like this should be like this" kind of change. I suppose that we might need to make the `ty` a bit more fine-grained as the coverage expands. That said, I don't have a strong opinion on whether it's necessary, so feel free to close this PR if you find it not convincing enough.

The diff looks so scary, though... I just split `ty.rs` into `def.rs` and `tys.rs` and changed `crate_def!` and `crate_def_with_ty!`.
2026-08-12 20:17:31 -04:00
mejrs
b588ef3b37 Move rustc_session cstore module to its own crate 2026-08-11 17:12:12 +02:00
Makai
83012a43ba rustc_public: split defs out of ty 2026-08-07 15:29:20 +08:00
Ada Alakbarova
c99698344d rename OutlivesPredicate to OutlivesClause 2026-08-05 11:07:35 +02:00
Jonathan Brouwer
9956011498 Rollup merge of #160012 - RalfJung:deref-validity, r=oli-obk
miri: ensure validity of references and pointers we dereference and cast

Conceptually, when we evaluate the place expression `*place`, there are two steps that happen:
- perform a (typed) load from `place`, which yields a value of pointer/ref type
- construct a new place from that value

Since this is a typed load, we have to ensure that the value satisfies the validity invariant. We forgot to do that, which led to Miri missing a bunch of UB. This PR fixes that by adding the missing checks.

Triggering this UB is a bit non-trivial: you cannot just store an invalid value into `place` using regular assignment (that would already be caught as part of the assignment). However, you can take a raw pointer to `place` and then use that to mutate the contents of `place` in a way that its validity invariant no longer holds. For example:
```rust
fn main() {
    let mut x = &();
    // Overwrite `x` with null.
    unsafe { (&raw mut x).cast::<usize>().write(0) };
    let _val = *x; //~ERROR: null reference
}
```
This program clearly (IMO) should have UB, and has UB in MiniRust, but Miri accepted that program before this PR. The same applies to references that are invalid because they are unaligned (even if we end up only accessing a 1-aligned field, i.e. the rest of the place expression evaluates just fine), and to references that are invalid because they are not dereferenceable (even if we end up projecting to a zero-sized field, i.e., the rest of the place expression evaluates just fine).

Even raw pointers have this problem: a raw pointer can be invalid if its vtable pointer is wrong, and we did not check that.

And finally, this also affects `Box`, and this is where things get tricky. `Box` derefs are not even present any more in the MIR Miri sees; they have been replaced by derefs of the underlying raw pointer. But that means we have no way to know that we should check all those things. So to fix that I adjusted the ElaborateBoxDerefs to emit a new special kind of cast that's almost a transmute but also checks `Box` validity.

Fixes https://github.com/rust-lang/miri/issues/5226
Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/617
Cc @rust-lang/opsem
2026-08-01 15:56:37 +02:00
Ralf Jung
fcf68f21cf introduce a new CastKind for ElaborateBoxDerefs 2026-08-01 09:27:16 +02: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
teor
e574edfbac Automatically rename rustc_splat attribute
fastmod --fixed-strings '#[splat]' '#[rustc_splat]'
fastmod --fixed-strings '`splat` attribute' '`rustc_splat` attribute'
fastmod --fixed-strings '$splat$' '$rustc_splat$'
fastmod 'v0(.*)#\[rustc_splat\]' 'v0${1}#[splat]' tests/ui/splat/splat-mangling.rs
2026-07-30 10:59:40 +10: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
Jacob Pratt
f41072ca48 Rollup merge of #159204 - celinval:feat/caller_location, r=makai410
Add support to caller_location to rustc_public

This PR has two small commits that add APIs to help handle caller location.
1. `Instance::requires_caller_location`
2. `Span::as_caller_location`

Fixes https://github.com/rust-lang/rustc_public/issues/62
Fixes https://github.com/rust-lang/rustc_public/issues/123

r? @makai410

disclaimer: I used AI to help me write this code.
2026-07-26 00:21:51 -04:00
Jacob Pratt
f65144191d Rollup merge of #159472 - hkalbasi:rustc_public_float, r=celinval
Support creating float constants in rustc_public mir

This PR adds a `try_from_float` similar to `try_from_uint` to the `rustc_public::ty::MirConst`.

It takes `u128` and users need a `.to_bits() as u128` to call this function. I did this because `f64` couldn't capture a `f128` const completely, and `f128` needs to cast and a branch on the input types, making the code complex. Another alternative is adding 4 functions `try_from_f16` to `try_from_f128`, which I don't like, but that's also an option.
2026-07-20 23:38:04 -04:00
hkalbasi
c4bda511e3 Support creating float constants in rustc_public mir 2026-07-20 21:48:08 +03:30
Jonathan Brouwer
44765b67e4 Rollup merge of #159347 - celinval:docs/rpub-lib, r=mejrs
Document rustc_public lib.rs and update README

Add module-level documentation with usage example, crate discovery guide, and status section. Document all public types, methods, and free functions in lib.rs. Update README to reflect the crate rename from `stable_mir`/`rustc_smir` to `rustc_public`/`rustc_public_bridge`.

Disclaimer: I used AI to help me generate the documentation.
2026-07-19 17:04:34 +02:00
Celina G. Val
adac776a9e [rpub] Address review comments on rustc_public doc
- Add a concrete code example (duplicate crate detection)
- Clarify requires_monomorphization doc
- Add FIXME for Symbol type alias

Co-authored-by: Bruno Kolenbrander <59372212+mejrs@users.noreply.github.com>
2026-07-17 22:26:06 +00:00
Celina G. Val
5c88a1c75a [rpub] Replace Span::caller_location by Body's one
Add a method Body::caller_location that resolves the correct caller
location constant for a call to a #[track_caller] function, walking
inlined source scopes to handle MIR inlining correctly.

Body now stores source scope data as a public field. Body::new
populates it with empty entries (no inlining info); bodies obtained
from the compiler have full scope data populated.

Span::as_caller_location is now pub(crate) since users should use
Body::caller_location instead, which handles inlining correctly.
2026-07-17 21:24:03 +00:00
Celina G. Val
87b01b0987 Document rustc_public lib.rs and update README
Add module-level documentation with usage example, crate discovery
guide, and status section. Document all public types, methods, and
free functions in lib.rs. Update README to reflect the crate rename
from stable_mir/rustc_smir to rustc_public/rustc_public_bridge.
2026-07-15 06:14:57 +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
Jonathan Brouwer
c6e564426d Rollup merge of #157993 - erickt:rustc-public, r=makai410
Expose more info about ADTs and functions in rustc_public

This allows users of `rustc_public` to do more complex navigation through data structures by exposing the following info:

* `AdtDef::generics_of` - Get the generics for the ADT.
* `AdtDef::inherent_impls` - Get all the impls for the ADT.
* `FnDef::associated_item` - Get the trait or impl block that contains the function if it exists.
* `FnDef::generics_of` - get the generics for a given function.
* `ImplDef::generics_of` - Get the generics for the impl block.
* `ImplDef` implements `CrateDefType` - figure out the type of the impl block with `CrateDefType::ty()` or get the normalized type with `CrateDefType::ty_with_args()`.

This was partially written with the help of Gemini, but I reviewed the code it generated.
2026-07-13 20:18:04 +02: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
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
Celina G. Val
a924b6de4c Add Span::caller_location to rustc_public
Add an API to construct the `&'static Location<'static>` constant
that must be passed as the implicit extra argument when calling a
`#[track_caller]` function. Users provide the span of the call
site (or the callee's definition span for reify shim fallback).

Fixes https://github.com/rust-lang/rustc_public/issues/62
2026-07-13 04:56:40 +00:00
Celina G. Val
60f100b497 Add Instance::requires_caller_location to rustc_public
Expose the internal `requires_caller_location` query through
rustc_public so tools can detect when an instance has an implicit
extra `&'static Location<'static>` argument in its ABI that is
not present in the MIR body signature.

Fixes https://github.com/rust-lang/rustc_public/issues/123
2026-07-13 04:53:15 +00: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
Erick Tryzelaar
5f4114c964 Expose more info about ADTs and functions in rustc_public
This allows users of `rustc_public` to do more complex navigation
through data structures by exposing the following info:

* `AdtDef::generics_of` - Get the generics for the ADT.
* `AdtDef::inherent_impls` - Get all the impls for the ADT.
* `FnDef::associated_item` - Get the trait or impl block that contains the
  function if it exists.
* `FnDef::generics_of` - get the generics for a given function.
* `ImplDef::generics_of` - Get the generics for the impl block.
* `ImplDef` implements `CrateDefType` - figure out the type of the impl
  block with `CrateDefType::ty()` or get the normalized type with
`CrateDefType::ty_with_args()`.

This was partially written with the help of Gemini, but I reviewed the
code it generated.
2026-07-09 14:35:38 +00:00
Scott McMurray
2efdc665a7 Carry the b_offset inside BackendRepr::ScalarPair 2026-07-07 01:15:36 -07:00
Jacob Pratt
91fc16bab6 Rollup merge of #158796 - raushan728:issues/154044, r=saethlin
Distinguish null reference production from null pointer dereference in UB checks

Closes rust-lang/rust#154044

This change distinguishes null reference production from actual null pointer dereferences in the UB checks.

Producing a reference from a null pointer (for example, `&*ptr`) is undefined behavior even if no memory is dereferenced. This change introduces a dedicated `AssertKind::NullReferenceConstructed` and runtime panic so these cases produce a more accurate diagnostic while preserving the existing panic for actual null pointer dereferences.

Summary
- Add `AssertKind::NullReferenceConstructed`.
- Emit it for null reference production in the MIR null check pass.
- Add `panic_null_reference_constructed` and its lang item.
- Keep `NullPointerDereference` for actual dereferences.
- Update the affected UI tests.
2026-07-06 22:17:40 -04:00
Jonathan Brouwer
2ff23c3803 Rollup merge of #158381 - hkalbasi:main, r=makai410
Expose debug scope of statement and terminator in rustc_public

Currently, `scope` is exposed for variables, but it is a meaningless number since the boundary of each scope is not available. This PR changes `span` fields of statement and terminator to `source_info` which includes scope as well.

Disclaimer: Written by LLM
2026-07-06 17:09:13 +02:00
Raushan kumar
1a982425b6 Distinguish null reference production from null pointer dereference
Introduce a dedicated panic for null reference production to distinguish
producing a reference from a null pointer from an actual null pointer
dereference.

This emits a dedicated panic message for null reference production while
preserving the existing panic for actual dereferences.
2026-07-05 17:09:30 +00:00
khyperia
e9df4e03c8 yeet AliasRelate 2026-06-30 15:38:01 +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
teor
5d0c6bad94 Impl HIR FnSig for #[splat] 2026-06-26 10:44:14 +02:00
bit-aloo
cfb7508f82 Rename uv to alias_const 2026-06-26 07:12:27 +00: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
Adwin White
3dbe96a5a1 add IsRigid marker to TyKind::Alias and constants 2026-06-25 17:12:10 +08:00
hkalbasi
515395bce0 Expose debug scope of statement and terminator in rustc_public 2026-06-25 03:25:08 +03:30
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
bors
f28ac764c3 Auto merge of #158013 - khyperia:AliasTy-def_id, r=BoxyUwU
remove AliasTy::def_id()



this is part of https://github.com/rust-lang/rust/issues/156181

as well as part of https://github.com/rust-lang/rust/issues/152245

this immediately uses [the recently-introduced `Alias<>` type](https://github.com/rust-lang/rust/pull/156538) to narrow the kinds of aliases allowed in various places in code

fyi @lcnr

r? @BoxyUwU
2026-06-23 17:44:39 +00:00
Noah Lev
0eb146cbab 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`).

Many of the shim variants still have `Shim` at the end of their names.
To make the refactoring easier and keep the diff clean, I will trim
those suffixes off in the next commit.
2026-06-22 19:28:42 +00:00
khyperia
992c2de84a remove AliasTy::def_id() 2026-06-21 13:32:47 +02:00
Makai
1ef529db4a Rename project-stable-mir to project-rustc-public 2026-06-17 21:06:47 +08:00
Jacob Pratt
6c6bd7a358 Rollup merge of #157748 - makai410:var-def-idx, r=celinval
rustc_public: make sure hidden fields have their accessors

Per [the discussion](https://rust-lang.zulipchat.com/#narrow/channel/320896-project-rustc-public/topic/Do.20we.20want.20DefId.20to.20be.20publicly.20visible.20in.20our.20def.20wrappers.3F/with/600656013), we should make sure hidden fields have their corresponding accessors.
2026-06-15 21:36:44 -04:00
Jacob Pratt
e8a16bc54a Rollup merge of #157812 - makai410:alias-ty, r=scottmcm
rustc_public: implement `ty::Alias` conversion

I don't know why there is a `todo!()` here. Am I overlooking anything?
2026-06-13 04:06:06 -04:00
Makai
a5ab40f7a6 rustc_public: implement ty::Alias conversion 2026-06-12 21:05:40 +08:00
khyperia
9cefd68c1e remove AliasTerm::def_id() 2026-06-12 09:07:59 +02:00
Makai
01d1fee105 rustc_public: add adt_def() to VariantDef 2026-06-11 15:26:28 +08:00
Makai
79487a6705 rustc_public: add idx() to VariantDef 2026-06-11 15:22:02 +08:00
Jacob Pratt
651a6c1711 Rollup merge of #157410 - erickt:rustc-public, r=makai410
Implement rustc_public::CrateDef{,Type} for FieldDef

This makes a few changes to rustc_public to make it a little easier to analyze ADT types.

* It implements `CrateDef` and `CrateDefType` for `FieldDef`, which allows easy access to the underlying `DefId`, names, and tool annotations.
* It adds `Crate::adts` to simplify stepping through all the ADTs in the crate.

Note that I did use Gemini to assist with writing this patch, but I wrote most of it, reviewed all the vode, and verified the tests pass locally.
2026-06-09 16:53:01 -04:00