Skip to content

Commit d2dc427

Browse files
committed
Refactor vtable format.
1 parent da7d405 commit d2dc427

File tree

5 files changed

+314
-61
lines changed

5 files changed

+314
-61
lines changed

compiler/rustc_infer/src/traits/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ pub fn anonymize_predicate<'tcx>(
1414
tcx.reuse_or_mk_predicate(pred, new)
1515
}
1616

17-
struct PredicateSet<'tcx> {
17+
pub struct PredicateSet<'tcx> {
1818
tcx: TyCtxt<'tcx>,
1919
set: FxHashSet<ty::Predicate<'tcx>>,
2020
}
2121

2222
impl PredicateSet<'tcx> {
23-
fn new(tcx: TyCtxt<'tcx>) -> Self {
23+
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
2424
Self { tcx, set: Default::default() }
2525
}
2626

27-
fn insert(&mut self, pred: ty::Predicate<'tcx>) -> bool {
27+
pub fn insert(&mut self, pred: ty::Predicate<'tcx>) -> bool {
2828
// We have to be careful here because we want
2929
//
3030
// for<'a> Foo<&'a i32>

compiler/rustc_middle/src/ty/vtable.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::convert::TryFrom;
22

33
use crate::mir::interpret::{alloc_range, AllocId, Allocation, Pointer, Scalar, ScalarMaybeUninit};
44
use crate::ty::fold::TypeFoldable;
5-
use crate::ty::{self, DefId, SubstsRef, Ty, TyCtxt};
5+
use crate::ty::{self, DefId, PolyExistentialTraitRef, SubstsRef, Ty, TyCtxt};
66
use rustc_ast::Mutability;
77

88
#[derive(Clone, Copy, Debug, PartialEq, HashStable)]
@@ -12,6 +12,7 @@ pub enum VtblEntry<'tcx> {
1212
MetadataAlign,
1313
Vacant,
1414
Method(DefId, SubstsRef<'tcx>),
15+
TraitVPtr(PolyExistentialTraitRef<'tcx>),
1516
}
1617

1718
pub const COMMON_VTABLE_ENTRIES: &[VtblEntry<'_>] =
@@ -92,6 +93,11 @@ impl<'tcx> TyCtxt<'tcx> {
9293
let fn_ptr = Pointer::from(fn_alloc_id);
9394
ScalarMaybeUninit::from_pointer(fn_ptr, &tcx)
9495
}
96+
VtblEntry::TraitVPtr(trait_ref) => {
97+
let supertrait_alloc_id = self.vtable_allocation(ty, Some(*trait_ref));
98+
let vptr = Pointer::from(supertrait_alloc_id);
99+
ScalarMaybeUninit::from_pointer(vptr, &tcx)
100+
}
95101
};
96102
vtable
97103
.write_scalar(&tcx, alloc_range(ptr_size * idx, ptr_size), scalar)

compiler/rustc_mir/src/monomorphize/collector.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,10 @@ fn create_mono_items_for_vtable_methods<'tcx>(
11161116
| VtblEntry::MetadataSize
11171117
| VtblEntry::MetadataAlign
11181118
| VtblEntry::Vacant => None,
1119+
VtblEntry::TraitVPtr(_) => {
1120+
// all super trait items already covered, so skip them.
1121+
None
1122+
}
11191123
VtblEntry::Method(def_id, substs) => ty::Instance::resolve_for_vtable(
11201124
tcx,
11211125
ty::ParamEnv::reveal_all(),

compiler/rustc_trait_selection/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ extern crate rustc_data_structures;
3131
extern crate tracing;
3232
#[macro_use]
3333
extern crate rustc_middle;
34+
#[macro_use]
35+
extern crate smallvec;
3436

3537
pub mod autoderef;
3638
pub mod infer;

0 commit comments

Comments
 (0)