rust/compiler/stable_mir
Celina G. Val 0f81fca8ec Change rustc_driver dependency on stable_mir crate
This fixes issues with RustAnalyzer not finding stable_mir crate.
It is also part of the long term architecture plan for these crates,
since we are moving towards having stable_mir depend on rustc_smir and
not the other way around.

I believe this is an utility function that will come handy eventually
for stable_mir users, but I'm keeping it as part of rustc_internal since
it initializes the StableMir context and requires `TyCtxt`.

Finally, I added the rustc_internal crate under a feature since the APIs
from this module shall not be stabilized.
2025-04-30 15:39:52 -07:00
..
src Change rustc_driver dependency on stable_mir crate 2025-04-30 15:39:52 -07:00
Cargo.toml Change rustc_driver dependency on stable_mir crate 2025-04-30 15:39:52 -07:00
README.md Update README.md 2024-10-24 16:19:55 -07:00
rust-toolchain.toml Split out the stable part of smir into its own crate to prevent accidental usage of forever unstable things 2023-09-25 14:38:27 +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. ↩︎