Make vtable_allocation always succeed
This commit is contained in:
parent
e9d69d9f8e
commit
b201b2f65f
@ -72,10 +72,7 @@ pub(crate) fn get_vtable<'tcx>(
|
|||||||
let vtable_ptr = if let Some(vtable_ptr) = fx.vtables.get(&(ty, trait_ref)) {
|
let vtable_ptr = if let Some(vtable_ptr) = fx.vtables.get(&(ty, trait_ref)) {
|
||||||
*vtable_ptr
|
*vtable_ptr
|
||||||
} else {
|
} else {
|
||||||
let vtable_alloc_id = match fx.tcx.vtable_allocation(ty, trait_ref) {
|
let vtable_alloc_id = fx.tcx.vtable_allocation(ty, trait_ref);
|
||||||
Ok(alloc) => alloc,
|
|
||||||
Err(_) => fx.tcx.sess.fatal("allocation of constant vtable failed"),
|
|
||||||
};
|
|
||||||
let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory();
|
let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory();
|
||||||
let vtable_ptr = pointer_for_allocation(fx, vtable_allocation);
|
let vtable_ptr = pointer_for_allocation(fx, vtable_allocation);
|
||||||
|
|
||||||
|
@ -70,10 +70,7 @@ pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
let vtable_alloc_id = match tcx.vtable_allocation(ty, trait_ref) {
|
let vtable_alloc_id = tcx.vtable_allocation(ty, trait_ref);
|
||||||
Ok(alloc) => alloc,
|
|
||||||
Err(_) => tcx.sess.fatal("allocation of constant vtable failed"),
|
|
||||||
};
|
|
||||||
let vtable_allocation = tcx.global_alloc(vtable_alloc_id).unwrap_memory();
|
let vtable_allocation = tcx.global_alloc(vtable_alloc_id).unwrap_memory();
|
||||||
let vtable_const = cx.const_data_from_alloc(vtable_allocation);
|
let vtable_const = cx.const_data_from_alloc(vtable_allocation);
|
||||||
let align = cx.data_layout().pointer_align.abi;
|
let align = cx.data_layout().pointer_align.abi;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use crate::mir::interpret::{alloc_range, AllocId, Allocation, InterpResult, Pointer, Scalar};
|
use crate::mir::interpret::{alloc_range, AllocId, Allocation, Pointer, Scalar};
|
||||||
use crate::ty::fold::TypeFoldable;
|
use crate::ty::fold::TypeFoldable;
|
||||||
use crate::ty::{self, DefId, SubstsRef, Ty, TyCtxt};
|
use crate::ty::{self, DefId, SubstsRef, Ty, TyCtxt};
|
||||||
use rustc_ast::Mutability;
|
use rustc_ast::Mutability;
|
||||||
@ -28,11 +28,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
self,
|
self,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
|
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
|
||||||
) -> InterpResult<'tcx, AllocId> {
|
) -> AllocId {
|
||||||
let tcx = self;
|
let tcx = self;
|
||||||
let vtables_cache = tcx.vtables_cache.lock();
|
let vtables_cache = tcx.vtables_cache.lock();
|
||||||
if let Some(alloc_id) = vtables_cache.get(&(ty, poly_trait_ref)).cloned() {
|
if let Some(alloc_id) = vtables_cache.get(&(ty, poly_trait_ref)).cloned() {
|
||||||
return Ok(alloc_id);
|
return alloc_id;
|
||||||
}
|
}
|
||||||
drop(vtables_cache);
|
drop(vtables_cache);
|
||||||
|
|
||||||
@ -60,7 +60,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
let ptr_align = tcx.data_layout.pointer_align.abi;
|
let ptr_align = tcx.data_layout.pointer_align.abi;
|
||||||
|
|
||||||
let vtable_size = ptr_size * u64::try_from(vtable_entries.len()).unwrap();
|
let vtable_size = ptr_size * u64::try_from(vtable_entries.len()).unwrap();
|
||||||
let mut vtable = Allocation::uninit(vtable_size, ptr_align, true)?;
|
let mut vtable =
|
||||||
|
Allocation::uninit(vtable_size, ptr_align, /* panic_on_fail */ true).unwrap();
|
||||||
|
|
||||||
// No need to do any alignment checks on the memory accesses below, because we know the
|
// No need to do any alignment checks on the memory accesses below, because we know the
|
||||||
// allocation is correctly aligned as we created it above. Also we're only offsetting by
|
// allocation is correctly aligned as we created it above. Also we're only offsetting by
|
||||||
@ -101,6 +102,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
let alloc_id = tcx.create_memory_alloc(tcx.intern_const_alloc(vtable));
|
let alloc_id = tcx.create_memory_alloc(tcx.intern_const_alloc(vtable));
|
||||||
let mut vtables_cache = self.vtables_cache.lock();
|
let mut vtables_cache = self.vtables_cache.lock();
|
||||||
vtables_cache.insert((ty, poly_trait_ref), alloc_id);
|
vtables_cache.insert((ty, poly_trait_ref), alloc_id);
|
||||||
Ok(alloc_id)
|
alloc_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||||||
ensure_monomorphic_enough(*self.tcx, ty)?;
|
ensure_monomorphic_enough(*self.tcx, ty)?;
|
||||||
ensure_monomorphic_enough(*self.tcx, poly_trait_ref)?;
|
ensure_monomorphic_enough(*self.tcx, poly_trait_ref)?;
|
||||||
|
|
||||||
let vtable_allocation = self.tcx.vtable_allocation(ty, poly_trait_ref)?;
|
let vtable_allocation = self.tcx.vtable_allocation(ty, poly_trait_ref);
|
||||||
|
|
||||||
let vtable_ptr = self.memory.global_base_pointer(Pointer::from(vtable_allocation))?;
|
let vtable_ptr = self.memory.global_base_pointer(Pointer::from(vtable_allocation))?;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user