|
| 1 | +//! Module that implements the public interface to the Stable MIR. |
| 2 | +//! |
| 3 | +//! This module shall contain all type definitions and APIs that we expect 3P tools to invoke to |
| 4 | +//! interact with the compiler. |
| 5 | +//! |
| 6 | +//! The goal is to eventually move this module to its own crate which shall be published on |
| 7 | +//! [crates.io](https://crates.io). |
| 8 | +//! |
| 9 | +//! ## Note: |
| 10 | +//! |
| 11 | +//! There shouldn't be any direct references to internal compiler constructs in this module. |
| 12 | +//! If you need an internal construct, consider using `rustc_internal` or `rustc_smir`. |
| 13 | +
|
| 14 | +use crate::rustc_internal; |
| 15 | + |
| 16 | +/// Use String for now but we should replace it. |
| 17 | +pub type Symbol = String; |
| 18 | + |
| 19 | +/// The number that identifies a crate. |
| 20 | +pub type CrateNum = usize; |
| 21 | + |
| 22 | +/// A unique identification number for each item accessible for the current compilation unit. |
| 23 | +pub type DefId = usize; |
| 24 | + |
| 25 | +/// A list of crate items. |
| 26 | +pub type CrateItems = Vec<CrateItem>; |
| 27 | + |
| 28 | +/// Holds information about a crate. |
| 29 | +#[derive(Clone, PartialEq, Eq, Debug)] |
| 30 | +pub struct Crate { |
| 31 | + pub(crate) id: CrateNum, |
| 32 | + pub name: Symbol, |
| 33 | + pub is_local: bool, |
| 34 | +} |
| 35 | + |
| 36 | +/// Holds information about an item in the crate. |
| 37 | +/// For now, it only stores the item DefId. Use functions inside `rustc_internal` module to |
| 38 | +/// use this item. |
| 39 | +#[derive(Clone, PartialEq, Eq, Debug)] |
| 40 | +pub struct CrateItem(pub(crate) rustc_internal::DefId); |
| 41 | + |
| 42 | +/// Access to the local crate. |
| 43 | +pub fn local_crate() -> Crate { |
| 44 | + crate::rustc_smir::local_crate() |
| 45 | +} |
| 46 | + |
| 47 | +/// Try to find a crate with the given name. |
| 48 | +pub fn find_crate(name: &str) -> Option<Crate> { |
| 49 | + crate::rustc_smir::find_crate(name) |
| 50 | +} |
| 51 | + |
| 52 | +/// Try to find a crate with the given name. |
| 53 | +pub fn external_crates() -> Vec<Crate> { |
| 54 | + crate::rustc_smir::external_crates() |
| 55 | +} |
| 56 | + |
| 57 | +/// Retrieve all items in the local crate that have a MIR associated with them. |
| 58 | +pub fn all_local_items() -> CrateItems { |
| 59 | + crate::rustc_smir::all_local_items() |
| 60 | +} |
0 commit comments