Skip to content

Commit aff004b

Browse files
make vtable_allocation return an Allocation, not an AllocId
1 parent ad88831 commit aff004b

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

compiler/rustc_codegen_cranelift/src/vtable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ pub(crate) fn get_vtable<'tcx>(
6868
ty: Ty<'tcx>,
6969
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
7070
) -> Value {
71-
let alloc_id = fx.tcx.vtable_allocation((ty, trait_ref));
71+
let alloc = fx.tcx.vtable_allocation((ty, trait_ref));
72+
let alloc_id = fx.tcx.create_memory_alloc(alloc);
7273
let data_id =
7374
data_id_for_alloc_id(&mut fx.constants_cx, &mut *fx.module, alloc_id, Mutability::Not);
7475
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);

compiler/rustc_codegen_ssa/src/meth.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ pub fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
7272
return val;
7373
}
7474

75-
let vtable_alloc_id = tcx.vtable_allocation((ty, trait_ref));
76-
let vtable_allocation = tcx.global_alloc(vtable_alloc_id).unwrap_memory();
75+
let vtable_allocation = tcx.vtable_allocation((ty, trait_ref));
7776
let vtable_const = cx.const_data_from_alloc(vtable_allocation);
7877
let align = cx.data_layout().pointer_align.abi;
7978
let vtable = cx.static_addr_of(vtable_const, align, Some("vtable"));

compiler/rustc_const_eval/src/interpret/traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3131
ensure_monomorphic_enough(*self.tcx, poly_trait_ref)?;
3232

3333
let vtable_allocation = self.tcx.vtable_allocation((ty, poly_trait_ref));
34-
35-
let vtable_ptr = self.memory.global_base_pointer(Pointer::from(vtable_allocation))?;
34+
let vtable_allocation_id = self.tcx.create_memory_alloc(vtable_allocation);
35+
let vtable_ptr = self.memory.global_base_pointer(Pointer::from(vtable_allocation_id))?;
3636

3737
Ok(vtable_ptr.into())
3838
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ rustc_queries! {
10661066
key.1, key.0 }
10671067
}
10681068

1069-
query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> mir::interpret::AllocId {
1069+
query vtable_allocation(key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>)) -> &'tcx mir::interpret::Allocation {
10701070
desc { |tcx| "vtable const allocation for <{} as {}>",
10711071
key.0,
10721072
key.1.map(|trait_ref| format!("{}", trait_ref)).unwrap_or("_".to_owned())

compiler/rustc_middle/src/ty/vtable.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::convert::TryFrom;
22
use std::fmt;
33

4-
use crate::mir::interpret::{alloc_range, AllocId, Allocation, Pointer, Scalar, ScalarMaybeUninit};
4+
use crate::mir::interpret::{alloc_range, Allocation, Pointer, Scalar, ScalarMaybeUninit};
55
use crate::ty::{self, Instance, PolyTraitRef, Ty, TyCtxt};
66
use rustc_ast::Mutability;
77

@@ -48,7 +48,7 @@ pub const COMMON_VTABLE_ENTRIES_ALIGN: usize = 2;
4848
pub(super) fn vtable_allocation_provider<'tcx>(
4949
tcx: TyCtxt<'tcx>,
5050
key: (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>),
51-
) -> AllocId {
51+
) -> &'tcx Allocation {
5252
let (ty, poly_trait_ref) = key;
5353

5454
let vtable_entries = if let Some(poly_trait_ref) = poly_trait_ref {
@@ -99,7 +99,8 @@ pub(super) fn vtable_allocation_provider<'tcx>(
9999
VtblEntry::TraitVPtr(trait_ref) => {
100100
let super_trait_ref = trait_ref
101101
.map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref));
102-
let supertrait_alloc_id = tcx.vtable_allocation((ty, Some(super_trait_ref)));
102+
let supertrait_alloc = tcx.vtable_allocation((ty, Some(super_trait_ref)));
103+
let supertrait_alloc_id = tcx.create_memory_alloc(supertrait_alloc);
103104
let vptr = Pointer::from(supertrait_alloc_id);
104105
ScalarMaybeUninit::from_pointer(vptr, &tcx)
105106
}
@@ -110,5 +111,5 @@ pub(super) fn vtable_allocation_provider<'tcx>(
110111
}
111112

112113
vtable.mutability = Mutability::Not;
113-
tcx.create_memory_alloc(tcx.intern_const_alloc(vtable))
114+
tcx.intern_const_alloc(vtable)
114115
}

0 commit comments

Comments
 (0)