Refactor to make interpreter and codegen backend neutral to vtable internal representation.

This commit is contained in:
Charles Lew
2021-06-14 18:02:53 +08:00
parent 14831568d5
commit a86d3a7e45
10 changed files with 246 additions and 177 deletions

View File

@@ -396,19 +396,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let mut nested = vec![];
let mut supertraits = util::supertraits(tcx, ty::Binder::dummy(object_trait_ref));
// For each of the non-matching predicates that
// we pass over, we sum up the set of number of vtable
// entries, so that we can compute the offset for the selected
// trait.
let vtable_base = supertraits
.by_ref()
.take(index)
.map(|t| super::util::count_own_vtable_entries(tcx, t))
.sum();
let unnormalized_upcast_trait_ref =
supertraits.next().expect("supertraits iterator no longer has as many elements");
supertraits.nth(index).expect("supertraits iterator no longer has as many elements");
let upcast_trait_ref = normalize_with_depth_to(
self,
@@ -490,6 +479,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
debug!(?nested, "object nested obligations");
let vtable_base = super::super::vtable_trait_first_method_offset(
tcx,
(unnormalized_upcast_trait_ref, ty::Binder::dummy(object_trait_ref)),
);
Ok(ImplSourceObjectData { upcast_trait_ref, vtable_base, nested })
}