mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Allow fetching the SMIR body of FnDefs
This commit is contained in:
parent
98d26d9c4d
commit
202fbed1a6
@ -78,8 +78,8 @@ impl<'tcx> Context for Tables<'tcx> {
|
||||
impl_trait.stable(self)
|
||||
}
|
||||
|
||||
fn mir_body(&mut self, item: &stable_mir::CrateItem) -> stable_mir::mir::Body {
|
||||
let def_id = self[item.0];
|
||||
fn mir_body(&mut self, item: stable_mir::DefId) -> stable_mir::mir::Body {
|
||||
let def_id = self[item];
|
||||
let mir = self.tcx.optimized_mir(def_id);
|
||||
stable_mir::mir::Body {
|
||||
blocks: mir
|
||||
|
@ -87,7 +87,7 @@ pub struct CrateItem(pub(crate) DefId);
|
||||
|
||||
impl CrateItem {
|
||||
pub fn body(&self) -> mir::Body {
|
||||
with(|cx| cx.mir_body(self))
|
||||
with(|cx| cx.mir_body(self.0))
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ pub trait Context {
|
||||
fn entry_fn(&mut self) -> Option<CrateItem>;
|
||||
/// 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 mir_body(&mut self, item: DefId) -> mir::Body;
|
||||
fn all_trait_decls(&mut self) -> TraitDecls;
|
||||
fn trait_decl(&mut self, trait_def: &TraitDef) -> TraitDecl;
|
||||
fn all_trait_impls(&mut self) -> ImplTraitDecls;
|
||||
|
@ -1,4 +1,8 @@
|
||||
use super::{mir::Mutability, mir::Safety, with, AllocId, DefId};
|
||||
use super::{
|
||||
mir::Safety,
|
||||
mir::{Body, Mutability},
|
||||
with, AllocId, DefId,
|
||||
};
|
||||
use crate::rustc_internal::Opaque;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
@ -95,6 +99,12 @@ pub struct ForeignDef(pub(crate) DefId);
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub struct FnDef(pub(crate) DefId);
|
||||
|
||||
impl FnDef {
|
||||
pub fn body(&self) -> Body {
|
||||
with(|ctx| ctx.mir_body(self.0))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub struct ClosureDef(pub(crate) DefId);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user