Add support to get virtual table allocation
This commit is contained in:
parent
fa5ff859e6
commit
5b3cf6610b
5 changed files with 54 additions and 3 deletions
|
@ -10,8 +10,9 @@ use rustc_span::Symbol;
|
|||
use stable_mir::mir::alloc::AllocId;
|
||||
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
|
||||
use stable_mir::ty::{
|
||||
AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const, FloatTy,
|
||||
GenericArgKind, GenericArgs, IntTy, Region, RigidTy, TraitRef, Ty, UintTy,
|
||||
AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const,
|
||||
ExistentialTraitRef, FloatTy, GenericArgKind, GenericArgs, IntTy, Region, RigidTy, TraitRef,
|
||||
Ty, UintTy,
|
||||
};
|
||||
use stable_mir::{CrateItem, DefId};
|
||||
|
||||
|
@ -229,6 +230,17 @@ impl<'tcx> RustcInternal<'tcx> for BoundVariableKind {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> RustcInternal<'tcx> for ExistentialTraitRef {
|
||||
type T = rustc_ty::ExistentialTraitRef<'tcx>;
|
||||
|
||||
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
rustc_ty::ExistentialTraitRef {
|
||||
def_id: self.def_id.0.internal(tables),
|
||||
args: self.generic_args.internal(tables),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> RustcInternal<'tcx> for TraitRef {
|
||||
type T = rustc_ty::TraitRef<'tcx>;
|
||||
|
||||
|
@ -277,3 +289,13 @@ where
|
|||
(*self).internal(tables)
|
||||
}
|
||||
}
|
||||
impl<'tcx, T> RustcInternal<'tcx> for Option<T>
|
||||
where
|
||||
T: RustcInternal<'tcx>,
|
||||
{
|
||||
type T = Option<T::T>;
|
||||
|
||||
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
self.as_ref().map(|inner| inner.internal(tables))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ impl<'tcx> Tables<'tcx> {
|
|||
self.def_ids.create_or_fetch(did)
|
||||
}
|
||||
|
||||
fn create_alloc_id(&mut self, aid: AllocId) -> stable_mir::mir::alloc::AllocId {
|
||||
pub(crate) fn create_alloc_id(&mut self, aid: AllocId) -> stable_mir::mir::alloc::AllocId {
|
||||
self.alloc_ids.create_or_fetch(aid)
|
||||
}
|
||||
|
||||
|
|
|
@ -331,6 +331,18 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
tables.tcx.global_alloc(alloc_id).stable(&mut *tables)
|
||||
}
|
||||
|
||||
fn vtable_allocation(
|
||||
&self,
|
||||
global_alloc: &GlobalAlloc,
|
||||
) -> Option<stable_mir::mir::alloc::AllocId> {
|
||||
let mut tables = self.0.borrow_mut();
|
||||
let GlobalAlloc::VTable(ty, trait_ref) = global_alloc else { return None };
|
||||
let alloc_id = tables
|
||||
.tcx
|
||||
.vtable_allocation((ty.internal(&mut *tables), trait_ref.internal(&mut *tables)));
|
||||
Some(alloc_id.stable(&mut *tables))
|
||||
}
|
||||
|
||||
fn usize_to_const(&self, val: u64) -> Result<Const, Error> {
|
||||
let mut tables = self.0.borrow_mut();
|
||||
let ty = tables.tcx.types.usize;
|
||||
|
@ -1623,6 +1635,13 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for mir::interpret::AllocId {
|
||||
type T = stable_mir::mir::alloc::AllocId;
|
||||
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||
tables.create_alloc_id(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Stable<'tcx> for mir::interpret::GlobalAlloc<'tcx> {
|
||||
type T = GlobalAlloc;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue