1
Fork 0

Refactor vtable format.

This commit is contained in:
Charles Lew 2021-06-17 12:20:18 +08:00
parent da7d405357
commit d2dc4276fd
5 changed files with 311 additions and 58 deletions

View file

@ -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)