Index def_ids directly

This commit is contained in:
Santiago Pastorino 2023-08-28 15:58:48 -03:00
parent af6299a1f7
commit 17ffb59d39
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
2 changed files with 4 additions and 20 deletions

View File

@ -21,7 +21,7 @@ fn with_tables<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
}
pub fn item_def_id(item: &stable_mir::CrateItem) -> DefId {
with_tables(|t| t.item_def_id(item))
with_tables(|t| t[item.0])
}
pub fn crate_item(did: DefId) -> stable_mir::CrateItem {
@ -78,22 +78,6 @@ impl<'tcx> Index<stable_mir::DefId> for Tables<'tcx> {
}
impl<'tcx> Tables<'tcx> {
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
self[item.0]
}
pub fn trait_def_id(&self, trait_def: &stable_mir::ty::TraitDef) -> DefId {
self[trait_def.0]
}
pub fn impl_trait_def_id(&self, impl_def: &stable_mir::ty::ImplDef) -> DefId {
self[impl_def.0]
}
pub fn generic_def_id(&self, generic_def: &stable_mir::ty::GenericDef) -> DefId {
self[generic_def.0]
}
pub fn crate_item(&mut self, did: DefId) -> stable_mir::CrateItem {
stable_mir::CrateItem(self.create_def_id(did))
}

View File

@ -54,7 +54,7 @@ impl<'tcx> Context for Tables<'tcx> {
}
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 def_id = self[trait_def.0];
let trait_def = self.tcx.trait_def(def_id);
trait_def.stable(self)
}
@ -68,13 +68,13 @@ impl<'tcx> Context for Tables<'tcx> {
}
fn trait_impl(&mut self, impl_def: &stable_mir::ty::ImplDef) -> stable_mir::ty::ImplTrait {
let def_id = self.impl_trait_def_id(impl_def);
let def_id = self[impl_def.0];
let impl_trait = self.tcx.impl_trait_ref(def_id).unwrap();
impl_trait.stable(self)
}
fn mir_body(&mut self, item: &stable_mir::CrateItem) -> stable_mir::mir::Body {
let def_id = self.item_def_id(item);
let def_id = self[item.0];
let mir = self.tcx.optimized_mir(def_id);
stable_mir::mir::Body {
blocks: mir