rust/compiler/rustc_public
Stuart Cook 3a0187ec5d
Rollup merge of #144000 - jacob-greenfield:stable-defid-parent, r=celinval
Add `DefId::parent()` accessor for `rustc_public`

Adds a `parent()` method to `DefId` (the `rustc_pub` version) which exposes the parent path, ie. `foo::bar::baz` -> `foo::bar`.

This is useful for organizing/grouping definitions into a tree, and is probably simpler and less brittle than attempting to parse the fully-qualified name into path components (e.g. especially when handling path components with qualified generic parameters).
2025-11-29 21:12:25 +11:00
..
src Rollup merge of #144000 - jacob-greenfield:stable-defid-parent, r=celinval 2025-11-29 21:12:25 +11:00
Cargo.toml rustc_public: Make Id types !Send / !Sync 2025-11-19 19:46:18 +00:00
README.md rename stable_mir to rustc_public, and rustc_smir to rustc_public_bridge 2025-07-14 09:25:54 +00:00
rust-toolchain.toml rename stable_mir to rustc_public, and rustc_smir to rustc_public_bridge 2025-07-14 09:25:54 +00:00

This crate is currently developed in-tree together with the compiler.

Our goal is to start publishing stable_mir into crates.io. Until then, users will use this as any other rustc crate, by installing the rustup component rustc-dev, and declaring stable-mir as an external crate.

See the StableMIR "Getting Started" guide for more information.

Stable MIR Design

The stable-mir will follow a similar approach to proc-macro2. Its implementation is split between two main crates:

  • stable_mir: Public crate, to be published on crates.io, which will contain the stable data structure as well as calls to rustc_smir APIs. The translation between stable and internal constructs will also be done in this crate, however, this is currently implemented in the rustc_smir crate.1.
  • rustc_smir: This crate implements the public APIs to the compiler. It is responsible for gathering all the information requested, and providing the data in its unstable form.

I.e., tools will depend on stable_mir crate, which will invoke the compiler using APIs defined in rustc_smir.

I.e.:

    ┌──────────────────────────────────┐           ┌──────────────────────────────────┐
    │   External Tool     ┌──────────┐ │           │ ┌──────────┐   Rust Compiler     │
    │                     │          │ │           │ │          │                     │
    │                     │stable_mir| │           │ │rustc_smir│                     │
    │                     │          │ ├──────────►| │          │                     │
    │                     │          │ │◄──────────┤ │          │                     │
    │                     │          │ │           │ │          │                     │
    │                     │          │ │           │ │          │                     │
    │                     └──────────┘ │           │ └──────────┘                     │
    └──────────────────────────────────┘           └──────────────────────────────────┘

More details can be found here: https://hackmd.io/XhnYHKKuR6-LChhobvlT-g?view


  1. This is currently implemented in the rustc_smir crate, but we are working to change that. ↩︎