refactor: unify Tables implementation with bridge types and re-export IndexedVal
define bridge types for `***Def`s. consolidate scattered `Tables` implementations into single inherent impl.
This commit is contained in:
parent
45cf29d651
commit
62d60319d6
13 changed files with 285 additions and 194 deletions
|
|
@ -10,11 +10,8 @@ use std::ops::Index;
|
|||
|
||||
use rustc_data_structures::fx;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_middle::mir::interpret::AllocId;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::def_id::{CrateNum, DefId};
|
||||
use rustc_span::def_id::CrateNum;
|
||||
use scoped_tls::scoped_thread_local;
|
||||
use stable_mir::Error;
|
||||
use stable_mir::convert::{RustcInternal, Stable};
|
||||
|
|
@ -58,37 +55,6 @@ where
|
|||
with_container(|tables, cx| item.internal(tables, cx))
|
||||
}
|
||||
|
||||
impl<'tcx, B: Bridge> Index<B::DefId> for Tables<'tcx, B> {
|
||||
type Output = DefId;
|
||||
|
||||
#[inline(always)]
|
||||
fn index(&self, index: B::DefId) -> &Self::Output {
|
||||
&self.def_ids[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, B: Bridge> Tables<'tcx, B> {
|
||||
pub fn create_def_id(&mut self, did: DefId) -> B::DefId {
|
||||
self.def_ids.create_or_fetch(did)
|
||||
}
|
||||
|
||||
pub fn create_alloc_id(&mut self, aid: AllocId) -> B::AllocId {
|
||||
self.alloc_ids.create_or_fetch(aid)
|
||||
}
|
||||
|
||||
pub fn create_span(&mut self, span: Span) -> B::Span {
|
||||
self.spans.create_or_fetch(span)
|
||||
}
|
||||
|
||||
pub fn instance_def(&mut self, instance: ty::Instance<'tcx>) -> B::InstanceDef {
|
||||
self.instances.create_or_fetch(instance)
|
||||
}
|
||||
|
||||
pub fn layout_id(&mut self, layout: rustc_abi::Layout<'tcx>) -> B::Layout {
|
||||
self.layouts.create_or_fetch(layout)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
|
||||
item.id.into()
|
||||
}
|
||||
|
|
|
|||
47
compiler/rustc_smir/src/rustc_smir/bridge.rs
Normal file
47
compiler/rustc_smir/src/rustc_smir/bridge.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
//! Defines a set of traits that is used for abstracting
|
||||
//! stable_mir's components that are needed in rustc_smir.
|
||||
//!
|
||||
//! These traits are really useful when programming
|
||||
//! in stable_mir-agnostic settings.
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use super::Bridge;
|
||||
|
||||
pub trait SmirError {
|
||||
fn new(msg: String) -> Self;
|
||||
fn from_internal<T: Debug>(err: T) -> Self;
|
||||
}
|
||||
|
||||
pub trait Prov<B: Bridge> {
|
||||
fn new(aid: B::AllocId) -> Self;
|
||||
}
|
||||
|
||||
macro_rules! make_bridge_trait {
|
||||
($name:ident) => {
|
||||
pub trait $name<B: Bridge> {
|
||||
fn new(did: B::DefId) -> Self;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
make_bridge_trait!(CrateItem);
|
||||
make_bridge_trait!(AdtDef);
|
||||
make_bridge_trait!(ForeignModuleDef);
|
||||
make_bridge_trait!(ForeignDef);
|
||||
make_bridge_trait!(FnDef);
|
||||
make_bridge_trait!(ClosureDef);
|
||||
make_bridge_trait!(CoroutineDef);
|
||||
make_bridge_trait!(CoroutineClosureDef);
|
||||
make_bridge_trait!(AliasDef);
|
||||
make_bridge_trait!(ParamDef);
|
||||
make_bridge_trait!(BrNamedDef);
|
||||
make_bridge_trait!(TraitDef);
|
||||
make_bridge_trait!(GenericDef);
|
||||
make_bridge_trait!(ConstDef);
|
||||
make_bridge_trait!(ImplDef);
|
||||
make_bridge_trait!(RegionDef);
|
||||
make_bridge_trait!(CoroutineWitnessDef);
|
||||
make_bridge_trait!(AssocDef);
|
||||
make_bridge_trait!(OpaqueDef);
|
||||
make_bridge_trait!(StaticDef);
|
||||
|
|
@ -9,17 +9,21 @@
|
|||
|
||||
use std::cell::RefCell;
|
||||
use std::fmt::Debug;
|
||||
use std::ops::Index;
|
||||
|
||||
use bridge::*;
|
||||
use context::SmirCtxt;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::interpret::AllocId;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
|
||||
use crate::rustc_internal::IndexMap;
|
||||
|
||||
pub mod alloc;
|
||||
pub mod bridge;
|
||||
mod builder;
|
||||
pub mod context;
|
||||
|
||||
|
|
@ -30,14 +34,14 @@ pub struct SmirContainer<'tcx, B: Bridge> {
|
|||
}
|
||||
|
||||
pub struct Tables<'tcx, B: Bridge> {
|
||||
pub(crate) def_ids: IndexMap<DefId, B::DefId>,
|
||||
pub(crate) alloc_ids: IndexMap<AllocId, B::AllocId>,
|
||||
pub(crate) spans: IndexMap<rustc_span::Span, B::Span>,
|
||||
pub(crate) types: IndexMap<Ty<'tcx>, B::Ty>,
|
||||
pub(crate) instances: IndexMap<ty::Instance<'tcx>, B::InstanceDef>,
|
||||
pub(crate) ty_consts: IndexMap<ty::Const<'tcx>, B::TyConstId>,
|
||||
pub(crate) mir_consts: IndexMap<mir::Const<'tcx>, B::MirConstId>,
|
||||
pub(crate) layouts: IndexMap<rustc_abi::Layout<'tcx>, B::Layout>,
|
||||
pub def_ids: IndexMap<DefId, B::DefId>,
|
||||
pub alloc_ids: IndexMap<AllocId, B::AllocId>,
|
||||
pub spans: IndexMap<rustc_span::Span, B::Span>,
|
||||
pub types: IndexMap<Ty<'tcx>, B::Ty>,
|
||||
pub instances: IndexMap<ty::Instance<'tcx>, B::InstanceDef>,
|
||||
pub ty_consts: IndexMap<ty::Const<'tcx>, B::TyConstId>,
|
||||
pub mir_consts: IndexMap<mir::Const<'tcx>, B::MirConstId>,
|
||||
pub layouts: IndexMap<rustc_abi::Layout<'tcx>, B::Layout>,
|
||||
}
|
||||
|
||||
impl<'tcx, B: Bridge> Default for Tables<'tcx, B> {
|
||||
|
|
@ -55,23 +59,142 @@ impl<'tcx, B: Bridge> Default for Tables<'tcx, B> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx, B: Bridge> Index<B::DefId> for Tables<'tcx, B> {
|
||||
type Output = DefId;
|
||||
|
||||
#[inline(always)]
|
||||
fn index(&self, index: B::DefId) -> &Self::Output {
|
||||
&self.def_ids[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, B: Bridge> Tables<'tcx, B> {
|
||||
pub(crate) fn intern_ty(&mut self, ty: Ty<'tcx>) -> B::Ty {
|
||||
pub fn intern_ty(&mut self, ty: Ty<'tcx>) -> B::Ty {
|
||||
self.types.create_or_fetch(ty)
|
||||
}
|
||||
|
||||
pub(crate) fn intern_ty_const(&mut self, ct: ty::Const<'tcx>) -> B::TyConstId {
|
||||
pub fn intern_ty_const(&mut self, ct: ty::Const<'tcx>) -> B::TyConstId {
|
||||
self.ty_consts.create_or_fetch(ct)
|
||||
}
|
||||
|
||||
pub(crate) fn intern_mir_const(&mut self, constant: mir::Const<'tcx>) -> B::MirConstId {
|
||||
pub fn intern_mir_const(&mut self, constant: mir::Const<'tcx>) -> B::MirConstId {
|
||||
self.mir_consts.create_or_fetch(constant)
|
||||
}
|
||||
|
||||
pub fn create_def_id(&mut self, did: DefId) -> B::DefId {
|
||||
self.def_ids.create_or_fetch(did)
|
||||
}
|
||||
|
||||
pub fn create_alloc_id(&mut self, aid: AllocId) -> B::AllocId {
|
||||
self.alloc_ids.create_or_fetch(aid)
|
||||
}
|
||||
|
||||
pub fn create_span(&mut self, span: Span) -> B::Span {
|
||||
self.spans.create_or_fetch(span)
|
||||
}
|
||||
|
||||
pub fn instance_def(&mut self, instance: ty::Instance<'tcx>) -> B::InstanceDef {
|
||||
self.instances.create_or_fetch(instance)
|
||||
}
|
||||
|
||||
pub fn layout_id(&mut self, layout: rustc_abi::Layout<'tcx>) -> B::Layout {
|
||||
self.layouts.create_or_fetch(layout)
|
||||
}
|
||||
|
||||
pub fn crate_item(&mut self, did: rustc_span::def_id::DefId) -> B::CrateItem {
|
||||
B::CrateItem::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn adt_def(&mut self, did: rustc_span::def_id::DefId) -> B::AdtDef {
|
||||
B::AdtDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn foreign_module_def(&mut self, did: rustc_span::def_id::DefId) -> B::ForeignModuleDef {
|
||||
B::ForeignModuleDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn foreign_def(&mut self, did: rustc_span::def_id::DefId) -> B::ForeignDef {
|
||||
B::ForeignDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn fn_def(&mut self, did: rustc_span::def_id::DefId) -> B::FnDef {
|
||||
B::FnDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn closure_def(&mut self, did: rustc_span::def_id::DefId) -> B::ClosureDef {
|
||||
B::ClosureDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn coroutine_def(&mut self, did: rustc_span::def_id::DefId) -> B::CoroutineDef {
|
||||
B::CoroutineDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn coroutine_closure_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> B::CoroutineClosureDef {
|
||||
B::CoroutineClosureDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn alias_def(&mut self, did: rustc_span::def_id::DefId) -> B::AliasDef {
|
||||
B::AliasDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn param_def(&mut self, did: rustc_span::def_id::DefId) -> B::ParamDef {
|
||||
B::ParamDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn br_named_def(&mut self, did: rustc_span::def_id::DefId) -> B::BrNamedDef {
|
||||
B::BrNamedDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn trait_def(&mut self, did: rustc_span::def_id::DefId) -> B::TraitDef {
|
||||
B::TraitDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn generic_def(&mut self, did: rustc_span::def_id::DefId) -> B::GenericDef {
|
||||
B::GenericDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn const_def(&mut self, did: rustc_span::def_id::DefId) -> B::ConstDef {
|
||||
B::ConstDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn impl_def(&mut self, did: rustc_span::def_id::DefId) -> B::ImplDef {
|
||||
B::ImplDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn region_def(&mut self, did: rustc_span::def_id::DefId) -> B::RegionDef {
|
||||
B::RegionDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn coroutine_witness_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> B::CoroutineWitnessDef {
|
||||
B::CoroutineWitnessDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn assoc_def(&mut self, did: rustc_span::def_id::DefId) -> B::AssocDef {
|
||||
B::AssocDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn opaque_def(&mut self, did: rustc_span::def_id::DefId) -> B::OpaqueDef {
|
||||
B::OpaqueDef::new(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub fn prov(&mut self, aid: rustc_middle::mir::interpret::AllocId) -> B::Prov {
|
||||
B::Prov::new(self.create_alloc_id(aid))
|
||||
}
|
||||
|
||||
pub fn static_def(&mut self, did: rustc_span::def_id::DefId) -> B::StaticDef {
|
||||
B::StaticDef::new(self.create_def_id(did))
|
||||
}
|
||||
}
|
||||
|
||||
/// A trait defining types that are used to emulate StableMIR components, which is really
|
||||
/// useful when programming in stable_mir-agnostic settings.
|
||||
pub trait Bridge {
|
||||
pub trait Bridge: Sized {
|
||||
type DefId: Copy + Debug + PartialEq + IndexedVal;
|
||||
type AllocId: Copy + Debug + PartialEq + IndexedVal;
|
||||
type Span: Copy + Debug + PartialEq + IndexedVal;
|
||||
|
|
@ -80,12 +203,29 @@ pub trait Bridge {
|
|||
type TyConstId: Copy + Debug + PartialEq + IndexedVal;
|
||||
type MirConstId: Copy + Debug + PartialEq + IndexedVal;
|
||||
type Layout: Copy + Debug + PartialEq + IndexedVal;
|
||||
type Error: SmirError;
|
||||
}
|
||||
|
||||
pub trait SmirError {
|
||||
fn new(msg: String) -> Self;
|
||||
fn from_internal<T: Debug>(err: T) -> Self;
|
||||
type Error: SmirError;
|
||||
type CrateItem: CrateItem<Self>;
|
||||
type AdtDef: AdtDef<Self>;
|
||||
type ForeignModuleDef: ForeignModuleDef<Self>;
|
||||
type ForeignDef: ForeignDef<Self>;
|
||||
type FnDef: FnDef<Self>;
|
||||
type ClosureDef: ClosureDef<Self>;
|
||||
type CoroutineDef: CoroutineDef<Self>;
|
||||
type CoroutineClosureDef: CoroutineClosureDef<Self>;
|
||||
type AliasDef: AliasDef<Self>;
|
||||
type ParamDef: ParamDef<Self>;
|
||||
type BrNamedDef: BrNamedDef<Self>;
|
||||
type TraitDef: TraitDef<Self>;
|
||||
type GenericDef: GenericDef<Self>;
|
||||
type ConstDef: ConstDef<Self>;
|
||||
type ImplDef: ImplDef<Self>;
|
||||
type RegionDef: RegionDef<Self>;
|
||||
type CoroutineWitnessDef: CoroutineWitnessDef<Self>;
|
||||
type AssocDef: AssocDef<Self>;
|
||||
type OpaqueDef: OpaqueDef<Self>;
|
||||
type Prov: Prov<Self>;
|
||||
type StaticDef: StaticDef<Self>;
|
||||
}
|
||||
|
||||
pub trait IndexedVal {
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ impl Layout {
|
|||
}
|
||||
}
|
||||
|
||||
impl crate::rustc_smir::IndexedVal for Layout {
|
||||
impl stable_mir::IndexedVal for Layout {
|
||||
fn to_val(index: usize) -> Self {
|
||||
Layout(index)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@
|
|||
use rustc_abi::Align;
|
||||
use rustc_middle::mir::ConstValue;
|
||||
use rustc_middle::mir::interpret::AllocRange;
|
||||
use rustc_smir::bridge::SmirError;
|
||||
use rustc_smir::context::SmirCtxt;
|
||||
use rustc_smir::{SmirError, Tables, alloc};
|
||||
use rustc_smir::{Tables, alloc};
|
||||
|
||||
use super::Error;
|
||||
use super::compiler_interface::BridgeTys;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
use std::cell::Cell;
|
||||
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_smir::{Bridge, SmirContainer, Tables};
|
||||
use rustc_smir::{Bridge, SmirContainer};
|
||||
use stable_mir::abi::{FnAbi, Layout, LayoutShape, ReprOptions};
|
||||
use stable_mir::convert::{RustcInternal, Stable};
|
||||
use stable_mir::crate_def::Attribute;
|
||||
|
|
@ -39,131 +39,29 @@ impl Bridge for BridgeTys {
|
|||
type TyConstId = stable_mir::ty::TyConstId;
|
||||
type MirConstId = stable_mir::ty::MirConstId;
|
||||
type Layout = stable_mir::abi::Layout;
|
||||
|
||||
type Error = stable_mir::Error;
|
||||
}
|
||||
|
||||
impl<'tcx> Tables<'tcx, BridgeTys> {
|
||||
pub(crate) fn crate_item(&mut self, did: rustc_span::def_id::DefId) -> stable_mir::CrateItem {
|
||||
stable_mir::CrateItem(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn adt_def(&mut self, did: rustc_span::def_id::DefId) -> stable_mir::ty::AdtDef {
|
||||
stable_mir::ty::AdtDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn foreign_module_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::ty::ForeignModuleDef {
|
||||
stable_mir::ty::ForeignModuleDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn foreign_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::ty::ForeignDef {
|
||||
stable_mir::ty::ForeignDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn fn_def(&mut self, did: rustc_span::def_id::DefId) -> stable_mir::ty::FnDef {
|
||||
stable_mir::ty::FnDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn closure_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::ty::ClosureDef {
|
||||
stable_mir::ty::ClosureDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn coroutine_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::ty::CoroutineDef {
|
||||
stable_mir::ty::CoroutineDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn coroutine_closure_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::ty::CoroutineClosureDef {
|
||||
stable_mir::ty::CoroutineClosureDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn alias_def(&mut self, did: rustc_span::def_id::DefId) -> stable_mir::ty::AliasDef {
|
||||
stable_mir::ty::AliasDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn param_def(&mut self, did: rustc_span::def_id::DefId) -> stable_mir::ty::ParamDef {
|
||||
stable_mir::ty::ParamDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn br_named_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::ty::BrNamedDef {
|
||||
stable_mir::ty::BrNamedDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn trait_def(&mut self, did: rustc_span::def_id::DefId) -> stable_mir::ty::TraitDef {
|
||||
stable_mir::ty::TraitDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn generic_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::ty::GenericDef {
|
||||
stable_mir::ty::GenericDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn const_def(&mut self, did: rustc_span::def_id::DefId) -> stable_mir::ty::ConstDef {
|
||||
stable_mir::ty::ConstDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn impl_def(&mut self, did: rustc_span::def_id::DefId) -> stable_mir::ty::ImplDef {
|
||||
stable_mir::ty::ImplDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
/*
|
||||
pub(crate) fn region_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::ty::RegionDef {
|
||||
stable_mir::ty::RegionDef(self.create_def_id(did))
|
||||
}
|
||||
*/
|
||||
|
||||
pub(crate) fn coroutine_witness_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::ty::CoroutineWitnessDef {
|
||||
stable_mir::ty::CoroutineWitnessDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn assoc_def(&mut self, did: rustc_span::def_id::DefId) -> stable_mir::ty::AssocDef {
|
||||
stable_mir::ty::AssocDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn opaque_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::ty::OpaqueDef {
|
||||
stable_mir::ty::OpaqueDef(self.create_def_id(did))
|
||||
}
|
||||
|
||||
pub(crate) fn prov(
|
||||
&mut self,
|
||||
aid: rustc_middle::mir::interpret::AllocId,
|
||||
) -> stable_mir::ty::Prov {
|
||||
stable_mir::ty::Prov(self.create_alloc_id(aid))
|
||||
}
|
||||
|
||||
pub(crate) fn static_def(
|
||||
&mut self,
|
||||
did: rustc_span::def_id::DefId,
|
||||
) -> stable_mir::mir::mono::StaticDef {
|
||||
stable_mir::mir::mono::StaticDef(self.create_def_id(did))
|
||||
}
|
||||
type CrateItem = stable_mir::CrateItem;
|
||||
type AdtDef = stable_mir::ty::AdtDef;
|
||||
type ForeignModuleDef = stable_mir::ty::ForeignModuleDef;
|
||||
type ForeignDef = stable_mir::ty::ForeignDef;
|
||||
type FnDef = stable_mir::ty::FnDef;
|
||||
type ClosureDef = stable_mir::ty::ClosureDef;
|
||||
type CoroutineDef = stable_mir::ty::CoroutineDef;
|
||||
type CoroutineClosureDef = stable_mir::ty::CoroutineClosureDef;
|
||||
type AliasDef = stable_mir::ty::AliasDef;
|
||||
type ParamDef = stable_mir::ty::ParamDef;
|
||||
type BrNamedDef = stable_mir::ty::BrNamedDef;
|
||||
type TraitDef = stable_mir::ty::TraitDef;
|
||||
type GenericDef = stable_mir::ty::GenericDef;
|
||||
type ConstDef = stable_mir::ty::ConstDef;
|
||||
type ImplDef = stable_mir::ty::ImplDef;
|
||||
type RegionDef = stable_mir::ty::RegionDef;
|
||||
type CoroutineWitnessDef = stable_mir::ty::CoroutineWitnessDef;
|
||||
type AssocDef = stable_mir::ty::AssocDef;
|
||||
type OpaqueDef = stable_mir::ty::OpaqueDef;
|
||||
type Prov = stable_mir::ty::Prov;
|
||||
type StaticDef = stable_mir::mir::mono::StaticDef;
|
||||
}
|
||||
|
||||
/// Stable public API for querying compiler information.
|
||||
|
|
@ -1138,7 +1036,7 @@ impl<'tcx> SmirInterface for SmirContainer<'tcx, BridgeTys> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> SmirContainer<'tcx, BridgeTys> {
|
||||
impl<'tcx> Helper for SmirContainer<'tcx, BridgeTys> {
|
||||
fn smir_crate(&self, crate_num: rustc_span::def_id::CrateNum) -> Crate {
|
||||
let cx = &*self.cx.borrow();
|
||||
let name = cx.crate_name(crate_num);
|
||||
|
|
@ -1149,6 +1047,10 @@ impl<'tcx> SmirContainer<'tcx, BridgeTys> {
|
|||
}
|
||||
}
|
||||
|
||||
trait Helper {
|
||||
fn smir_crate(&self, crate_num: rustc_span::def_id::CrateNum) -> Crate;
|
||||
}
|
||||
|
||||
// A thread local variable that stores a pointer to [`SmirInterface`].
|
||||
scoped_tls::scoped_thread_local!(static TLV: Cell<*const ()>);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
use rustc_middle::mir::mono::MonoItem;
|
||||
use rustc_middle::{bug, mir};
|
||||
use rustc_smir::Tables;
|
||||
use rustc_smir::bridge::SmirError;
|
||||
use rustc_smir::context::SmirCtxt;
|
||||
use rustc_smir::{SmirError, Tables};
|
||||
use stable_mir::compiler_interface::BridgeTys;
|
||||
use stable_mir::convert::Stable;
|
||||
use stable_mir::mir::alloc::GlobalAlloc;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
use std::fmt::{Debug, Display, Formatter};
|
||||
use std::{fmt, io};
|
||||
|
||||
use rustc_smir::SmirError;
|
||||
use rustc_smir::bridge::SmirError;
|
||||
|
||||
use crate::rustc_smir;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@
|
|||
|
||||
use std::io::Read;
|
||||
|
||||
use rustc_smir::IndexedVal;
|
||||
use serde::Serialize;
|
||||
use stable_mir::mir::mono::{Instance, StaticDef};
|
||||
use stable_mir::target::{Endian, MachineInfo};
|
||||
use stable_mir::ty::{Allocation, Binder, ExistentialTraitRef, Ty};
|
||||
use stable_mir::{Error, with};
|
||||
use stable_mir::{Error, IndexedVal, with};
|
||||
|
||||
use crate::{rustc_smir, stable_mir};
|
||||
use crate::stable_mir;
|
||||
|
||||
/// An allocation in the SMIR global memory can be either a function pointer,
|
||||
/// a static, or a "real" allocation with some data in it.
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use std::fmt::{Debug, Formatter};
|
||||
use std::io;
|
||||
|
||||
use rustc_smir::{IndexedVal, SmirError};
|
||||
use rustc_smir::bridge::SmirError;
|
||||
use serde::Serialize;
|
||||
use stable_mir::abi::FnAbi;
|
||||
use stable_mir::crate_def::CrateDef;
|
||||
use stable_mir::mir::Body;
|
||||
use stable_mir::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, Ty};
|
||||
use stable_mir::{CrateItem, DefId, Error, ItemKind, Opaque, Symbol, with};
|
||||
use stable_mir::{CrateItem, DefId, Error, IndexedVal, ItemKind, Opaque, Symbol, with};
|
||||
|
||||
use crate::{rustc_smir, stable_mir};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,14 @@ use std::io::Write;
|
|||
use std::{fmt, io, iter};
|
||||
|
||||
use fmt::{Display, Formatter};
|
||||
use rustc_smir::IndexedVal;
|
||||
use stable_mir::mir::{
|
||||
Operand, Place, RawPtrKind, Rvalue, StatementKind, UnwindAction, VarDebugInfoContents,
|
||||
};
|
||||
use stable_mir::ty::{AdtKind, AssocKind, MirConst, Ty, TyConst};
|
||||
use stable_mir::{Body, CrateDef, Mutability, with};
|
||||
use stable_mir::{Body, CrateDef, IndexedVal, Mutability, with};
|
||||
|
||||
use super::{AggregateKind, AssertMessage, BinOp, BorrowKind, FakeBorrowKind, TerminatorKind};
|
||||
use crate::{rustc_smir, stable_mir};
|
||||
use crate::stable_mir;
|
||||
|
||||
impl Display for Ty {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
|
|
|
|||
|
|
@ -278,3 +278,40 @@ impl std::fmt::Debug for Opaque {
|
|||
pub fn opaque<T: Debug>(value: &T) -> Opaque {
|
||||
Opaque(format!("{value:?}"))
|
||||
}
|
||||
|
||||
macro_rules! bridge_impl {
|
||||
($name: ident, $ty: ty) => {
|
||||
impl rustc_smir::bridge::$name<compiler_interface::BridgeTys> for $ty {
|
||||
fn new(def: stable_mir::DefId) -> Self {
|
||||
Self(def)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bridge_impl!(CrateItem, stable_mir::CrateItem);
|
||||
bridge_impl!(AdtDef, stable_mir::ty::AdtDef);
|
||||
bridge_impl!(ForeignModuleDef, stable_mir::ty::ForeignModuleDef);
|
||||
bridge_impl!(ForeignDef, stable_mir::ty::ForeignDef);
|
||||
bridge_impl!(FnDef, stable_mir::ty::FnDef);
|
||||
bridge_impl!(ClosureDef, stable_mir::ty::ClosureDef);
|
||||
bridge_impl!(CoroutineDef, stable_mir::ty::CoroutineDef);
|
||||
bridge_impl!(CoroutineClosureDef, stable_mir::ty::CoroutineClosureDef);
|
||||
bridge_impl!(AliasDef, stable_mir::ty::AliasDef);
|
||||
bridge_impl!(ParamDef, stable_mir::ty::ParamDef);
|
||||
bridge_impl!(BrNamedDef, stable_mir::ty::BrNamedDef);
|
||||
bridge_impl!(TraitDef, stable_mir::ty::TraitDef);
|
||||
bridge_impl!(GenericDef, stable_mir::ty::GenericDef);
|
||||
bridge_impl!(ConstDef, stable_mir::ty::ConstDef);
|
||||
bridge_impl!(ImplDef, stable_mir::ty::ImplDef);
|
||||
bridge_impl!(RegionDef, stable_mir::ty::RegionDef);
|
||||
bridge_impl!(CoroutineWitnessDef, stable_mir::ty::CoroutineWitnessDef);
|
||||
bridge_impl!(AssocDef, stable_mir::ty::AssocDef);
|
||||
bridge_impl!(OpaqueDef, stable_mir::ty::OpaqueDef);
|
||||
bridge_impl!(StaticDef, stable_mir::mir::mono::StaticDef);
|
||||
|
||||
impl rustc_smir::bridge::Prov<compiler_interface::BridgeTys> for stable_mir::ty::Prov {
|
||||
fn new(aid: stable_mir::mir::alloc::AllocId) -> Self {
|
||||
Self(aid)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
use std::fmt::{self, Debug, Display, Formatter};
|
||||
use std::ops::Range;
|
||||
|
||||
use rustc_smir::IndexedVal;
|
||||
use serde::Serialize;
|
||||
use stable_mir::abi::{FnAbi, Layout};
|
||||
use stable_mir::crate_def::{CrateDef, CrateDefItems, CrateDefType};
|
||||
use stable_mir::mir::alloc::{AllocId, read_target_int, read_target_uint};
|
||||
use stable_mir::mir::mono::StaticDef;
|
||||
use stable_mir::target::MachineInfo;
|
||||
use stable_mir::{Filename, Opaque};
|
||||
use stable_mir::{Filename, IndexedVal, Opaque};
|
||||
|
||||
use super::abi::ReprOptions;
|
||||
use super::mir::{Body, Mutability, Safety};
|
||||
use super::{DefId, Error, Symbol, with};
|
||||
use crate::{rustc_smir, stable_mir};
|
||||
use crate::stable_mir;
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize)]
|
||||
pub struct Ty(usize);
|
||||
|
|
@ -1566,7 +1565,7 @@ pub enum PredicatePolarity {
|
|||
|
||||
macro_rules! index_impl {
|
||||
($name:ident) => {
|
||||
impl crate::rustc_smir::IndexedVal for $name {
|
||||
impl stable_mir::IndexedVal for $name {
|
||||
fn to_val(index: usize) -> Self {
|
||||
$name(index)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue