Refactor vtable format.
This commit is contained in:
parent
da7d405357
commit
d2dc4276fd
5 changed files with 311 additions and 58 deletions
|
@ -2,7 +2,7 @@ use std::convert::TryFrom;
|
|||
|
||||
use crate::mir::interpret::{alloc_range, AllocId, Allocation, Pointer, Scalar, ScalarMaybeUninit};
|
||||
use crate::ty::fold::TypeFoldable;
|
||||
use crate::ty::{self, DefId, SubstsRef, Ty, TyCtxt};
|
||||
use crate::ty::{self, DefId, PolyExistentialTraitRef, SubstsRef, Ty, TyCtxt};
|
||||
use rustc_ast::Mutability;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, HashStable)]
|
||||
|
@ -12,6 +12,7 @@ pub enum VtblEntry<'tcx> {
|
|||
MetadataAlign,
|
||||
Vacant,
|
||||
Method(DefId, SubstsRef<'tcx>),
|
||||
TraitVPtr(PolyExistentialTraitRef<'tcx>),
|
||||
}
|
||||
|
||||
pub const COMMON_VTABLE_ENTRIES: &[VtblEntry<'_>] =
|
||||
|
@ -92,6 +93,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
let fn_ptr = Pointer::from(fn_alloc_id);
|
||||
ScalarMaybeUninit::from_pointer(fn_ptr, &tcx)
|
||||
}
|
||||
VtblEntry::TraitVPtr(trait_ref) => {
|
||||
let supertrait_alloc_id = self.vtable_allocation(ty, Some(*trait_ref));
|
||||
let vptr = Pointer::from(supertrait_alloc_id);
|
||||
ScalarMaybeUninit::from_pointer(vptr, &tcx)
|
||||
}
|
||||
};
|
||||
vtable
|
||||
.write_scalar(&tcx, alloc_range(ptr_size * idx, ptr_size), scalar)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue