rust-lang / project-stable-mir

Define compiler intermediate representation usable by external tools
Other
58 stars 12 forks source link

Create a StableMIR driver #69

Open celinval opened 7 months ago

celinval commented 7 months ago

This is a tracking issue for adding a Stable compiler driver that tools can use to extend the Rust compiler. This would replace the existing rustc_smir::run!() macro.

### Tasks
- [ ] Create a Stable driver interface.
- [ ] Optional: Logger customization.
- [ ] Add support for tools arguments to the Rust compiler that could be passed along to the driver (similar to `--llvm-args`).
- [ ] Allow users to hook into different stages of the compilation
sskeirik commented 4 months ago

Our org is working on building a new MIR operational semantics. Here is a basic wishlist for a stable MIR driver --- and we are also happy to contribute towards it, if there is any interest (most of this is restating points that were made on the zulip).

At a high level, we would like to serialize MIR (plus any needed metadata) so that our operational semantics engine can read the program semantics off the serialized data without needing to perform additional program transformations.

At a more detailed level, some of the following features would be useful:

  1. the ability to collect all instances of items referenced by a designated set of monomorphic "root" functions --- this requires some form of linking to handle inter-crate uses
  2. the ability to generate MIR (post-type-checking, immediately-pre-LLVM-IR-lowering) for all instances of MIR-generating-items referenced in (1) --- this seems like it is partially handled by the monomorphization pass, but const items and items in upstream crates seem like they will require special handling
  3. the ability to collect the set of types used by item instances from (1)
  4. the ability to serialize MIR and a types-to-layout map based on (2)-(3) to some structured representation