Add all_trait_decls to SMIR

This commit is contained in:
Santiago Pastorino 2023-08-04 17:44:41 -03:00
parent 496faa857c
commit 0e69a8ad20
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
2 changed files with 12 additions and 0 deletions

View File

@ -42,6 +42,14 @@ impl<'tcx> Context for Tables<'tcx> {
Some(self.crate_item(self.tcx.entry_fn(())?.0))
}
fn all_trait_decls(&mut self) -> stable_mir::TraitDecls {
self.tcx
.traits(LOCAL_CRATE)
.iter()
.map(|trait_def_id| self.trait_def(*trait_def_id))
.collect()
}
fn trait_decl(&mut self, trait_def: &stable_mir::ty::TraitDef) -> stable_mir::ty::TraitDecl {
let def_id = self.trait_def_id(trait_def);
let trait_def = self.tcx.trait_def(def_id);

View File

@ -32,6 +32,9 @@ pub type DefId = usize;
/// A list of crate items.
pub type CrateItems = Vec<CrateItem>;
/// A list of crate items.
pub type TraitDecls = Vec<TraitDef>;
/// Holds information about a crate.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Crate {
@ -84,6 +87,7 @@ pub trait Context {
/// Retrieve all items of the local crate that have a MIR associated with them.
fn all_local_items(&mut self) -> CrateItems;
fn mir_body(&mut self, item: &CrateItem) -> mir::Body;
fn all_trait_decls(&mut self) -> TraitDecls;
fn trait_decl(&mut self, trait_def: &TraitDef) -> TraitDecl;
/// Get information about the local crate.
fn local_crate(&self) -> Crate;