Skip to content

Commit 76eb4f3

Browse files
Use ExistentialTraitRef throughout codegen
1 parent 1583ee2 commit 76eb4f3

File tree

16 files changed

+71
-63
lines changed

16 files changed

+71
-63
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cranelift_module::*;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
88
use rustc_middle::mir::interpret::{AllocId, GlobalAlloc, Scalar, read_target_uint};
9-
use rustc_middle::ty::{Binder, ExistentialTraitRef, ScalarInt};
9+
use rustc_middle::ty::{ExistentialTraitRef, ScalarInt};
1010

1111
use crate::prelude::*;
1212

@@ -167,7 +167,9 @@ pub(crate) fn codegen_const_value<'tcx>(
167167
&mut fx.constants_cx,
168168
fx.module,
169169
ty,
170-
dyn_ty.principal(),
170+
dyn_ty.principal().map(|principal| {
171+
fx.tcx.instantiate_bound_regions_with_erased(principal)
172+
}),
171173
);
172174
let local_data_id =
173175
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
@@ -243,12 +245,9 @@ pub(crate) fn data_id_for_vtable<'tcx>(
243245
cx: &mut ConstantCx,
244246
module: &mut dyn Module,
245247
ty: Ty<'tcx>,
246-
trait_ref: Option<Binder<'tcx, ExistentialTraitRef<'tcx>>>,
248+
trait_ref: Option<ExistentialTraitRef<'tcx>>,
247249
) -> DataId {
248-
let alloc_id = tcx.vtable_allocation((
249-
ty,
250-
trait_ref.map(|principal| tcx.instantiate_bound_regions_with_erased(principal)),
251-
));
250+
let alloc_id = tcx.vtable_allocation((ty, trait_ref));
252251
data_id_for_alloc_id(cx, module, alloc_id, Mutability::Not)
253252
}
254253

@@ -463,9 +462,15 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
463462
GlobalAlloc::Memory(target_alloc) => {
464463
data_id_for_alloc_id(cx, module, alloc_id, target_alloc.inner().mutability)
465464
}
466-
GlobalAlloc::VTable(ty, dyn_ty) => {
467-
data_id_for_vtable(tcx, cx, module, ty, dyn_ty.principal())
468-
}
465+
GlobalAlloc::VTable(ty, dyn_ty) => data_id_for_vtable(
466+
tcx,
467+
cx,
468+
module,
469+
ty,
470+
dyn_ty
471+
.principal()
472+
.map(|principal| tcx.instantiate_bound_regions_with_erased(principal)),
473+
),
469474
GlobalAlloc::Static(def_id) => {
470475
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)
471476
{

compiler/rustc_codegen_cranelift/src/unsize.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ pub(crate) fn unsized_info<'tcx>(
6161
old_info
6262
}
6363
}
64-
(_, ty::Dynamic(data, ..)) => crate::vtable::get_vtable(fx, source, data.principal()),
64+
(_, ty::Dynamic(data, ..)) => crate::vtable::get_vtable(
65+
fx,
66+
source,
67+
data.principal()
68+
.map(|principal| fx.tcx.instantiate_bound_regions_with_erased(principal)),
69+
),
6570
_ => bug!("unsized_info: invalid unsizing {:?} -> {:?}", source, target),
6671
}
6772
}

compiler/rustc_codegen_cranelift/src/vtable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
9090
pub(crate) fn get_vtable<'tcx>(
9191
fx: &mut FunctionCx<'_, '_, 'tcx>,
9292
ty: Ty<'tcx>,
93-
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
93+
trait_ref: Option<ty::ExistentialTraitRef<'tcx>>,
9494
) -> Value {
9595
let data_id = data_id_for_vtable(fx.tcx, &mut fx.constants_cx, fx.module, ty, trait_ref);
9696
let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func);

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::ty::layout::{
1414
FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError,
1515
LayoutOfHelpers,
1616
};
17-
use rustc_middle::ty::{self, Instance, PolyExistentialTraitRef, Ty, TyCtxt};
17+
use rustc_middle::ty::{self, ExistentialTraitRef, Instance, Ty, TyCtxt};
1818
use rustc_session::Session;
1919
use rustc_span::source_map::respan;
2020
use rustc_span::{DUMMY_SP, Span};
@@ -90,7 +90,7 @@ pub struct CodegenCx<'gcc, 'tcx> {
9090
pub function_instances: RefCell<FxHashMap<Instance<'tcx>, Function<'gcc>>>,
9191
/// Cache generated vtables
9292
pub vtables:
93-
RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), RValue<'gcc>>>,
93+
RefCell<FxHashMap<(Ty<'tcx>, Option<ty::ExistentialTraitRef<'tcx>>), RValue<'gcc>>>,
9494

9595
// TODO(antoyo): improve the SSA API to not require those.
9696
/// Mapping from function pointer type to indexes of on stack parameters.
@@ -400,7 +400,7 @@ impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
400400
impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
401401
fn vtables(
402402
&self,
403-
) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<PolyExistentialTraitRef<'tcx>>), RValue<'gcc>>> {
403+
) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<ExistentialTraitRef<'tcx>>), RValue<'gcc>>> {
404404
&self.vtables
405405
}
406406

compiler/rustc_codegen_gcc/src/debuginfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::sync::Lrc;
77
use rustc_index::bit_set::BitSet;
88
use rustc_index::{Idx, IndexVec};
99
use rustc_middle::mir::{self, Body, SourceScope};
10-
use rustc_middle::ty::{Instance, PolyExistentialTraitRef, Ty};
10+
use rustc_middle::ty::{ExistentialTraitRef, Instance, Ty};
1111
use rustc_session::config::DebugInfo;
1212
use rustc_span::{BytePos, Pos, SourceFile, SourceFileAndLine, Span, Symbol};
1313
use rustc_target::abi::Size;
@@ -214,7 +214,7 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
214214
fn create_vtable_debuginfo(
215215
&self,
216216
_ty: Ty<'tcx>,
217-
_trait_ref: Option<PolyExistentialTraitRef<'tcx>>,
217+
_trait_ref: Option<ExistentialTraitRef<'tcx>>,
218218
_vtable: Self::Value,
219219
) {
220220
// TODO(antoyo)

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ pub(crate) struct CodegenCx<'ll, 'tcx> {
5252
/// Cache instances of monomorphic and polymorphic items
5353
pub instances: RefCell<FxHashMap<Instance<'tcx>, &'ll Value>>,
5454
/// Cache generated vtables
55-
pub vtables:
56-
RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), &'ll Value>>,
55+
pub vtables: RefCell<FxHashMap<(Ty<'tcx>, Option<ty::ExistentialTraitRef<'tcx>>), &'ll Value>>,
5756
/// Cache of constant strings,
5857
pub const_str_cache: RefCell<FxHashMap<String, &'ll Value>>,
5958

@@ -630,15 +629,14 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
630629
impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
631630
fn vtables(
632631
&self,
633-
) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), &'ll Value>>
634-
{
632+
) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<ty::ExistentialTraitRef<'tcx>>), &'ll Value>> {
635633
&self.vtables
636634
}
637635

638636
fn apply_vcall_visibility_metadata(
639637
&self,
640638
ty: Ty<'tcx>,
641-
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
639+
poly_trait_ref: Option<ty::ExistentialTraitRef<'tcx>>,
642640
vtable: &'ll Value,
643641
) {
644642
apply_vcall_visibility_metadata(self, ty, poly_trait_ref, vtable);

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1313
use rustc_middle::bug;
1414
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf, TyAndLayout};
1515
use rustc_middle::ty::{
16-
self, AdtKind, CoroutineArgsExt, Instance, PolyExistentialTraitRef, Ty, TyCtxt, Visibility,
16+
self, AdtKind, CoroutineArgsExt, ExistentialTraitRef, Instance, Ty, TyCtxt, Visibility,
1717
};
1818
use rustc_session::config::{self, DebugInfo, Lto};
1919
use rustc_span::{DUMMY_SP, FileName, FileNameDisplayPreference, SourceFile, Symbol, hygiene};
@@ -1400,13 +1400,13 @@ pub(crate) fn build_global_var_di_node<'ll>(
14001400
fn build_vtable_type_di_node<'ll, 'tcx>(
14011401
cx: &CodegenCx<'ll, 'tcx>,
14021402
ty: Ty<'tcx>,
1403-
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
1403+
poly_trait_ref: Option<ty::ExistentialTraitRef<'tcx>>,
14041404
) -> &'ll DIType {
14051405
let tcx = cx.tcx;
14061406

14071407
let vtable_entries = if let Some(poly_trait_ref) = poly_trait_ref {
14081408
let trait_ref = poly_trait_ref.with_self_ty(tcx, ty);
1409-
let trait_ref = tcx.erase_regions(tcx.instantiate_bound_regions_with_erased(trait_ref));
1409+
let trait_ref = tcx.erase_regions(trait_ref);
14101410

14111411
tcx.vtable_entries(trait_ref)
14121412
} else {
@@ -1491,7 +1491,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
14911491
pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
14921492
cx: &CodegenCx<'ll, 'tcx>,
14931493
ty: Ty<'tcx>,
1494-
trait_ref: Option<PolyExistentialTraitRef<'tcx>>,
1494+
trait_ref: Option<ExistentialTraitRef<'tcx>>,
14951495
vtable: &'ll Value,
14961496
) {
14971497
// FIXME(flip1995): The virtual function elimination optimization only works with full LTO in
@@ -1510,7 +1510,7 @@ pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
15101510

15111511
let trait_ref_self = trait_ref.with_self_ty(cx.tcx, ty);
15121512
let trait_ref_self = cx.tcx.erase_regions(trait_ref_self);
1513-
let trait_def_id = trait_ref_self.def_id();
1513+
let trait_def_id = trait_ref_self.def_id;
15141514
let trait_vis = cx.tcx.visibility(trait_def_id);
15151515

15161516
let cgus = cx.sess().codegen_units().as_usize();
@@ -1569,7 +1569,7 @@ pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
15691569
pub(crate) fn create_vtable_di_node<'ll, 'tcx>(
15701570
cx: &CodegenCx<'ll, 'tcx>,
15711571
ty: Ty<'tcx>,
1572-
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
1572+
poly_trait_ref: Option<ty::ExistentialTraitRef<'tcx>>,
15731573
vtable: &'ll Value,
15741574
) {
15751575
if cx.dbg_cx.is_none() {

compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
77
use rustc_macros::HashStable;
88
use rustc_middle::bug;
9-
use rustc_middle::ty::{self, PolyExistentialTraitRef, Ty, TyCtxt};
9+
use rustc_middle::ty::{self, ExistentialTraitRef, Ty, TyCtxt};
1010

1111
use super::{DefinitionLocation, SmallVec, UNKNOWN_LINE_NUMBER, unknown_file_metadata};
1212
use crate::common::{AsCCharPtr, CodegenCx};
@@ -44,7 +44,7 @@ pub(super) enum UniqueTypeId<'tcx> {
4444
/// The ID for the additional wrapper struct type describing an enum variant in CPP-like mode.
4545
VariantStructTypeCppLikeWrapper(Ty<'tcx>, VariantIdx, private::HiddenZst),
4646
/// The ID of the artificial type we create for VTables.
47-
VTableTy(Ty<'tcx>, Option<PolyExistentialTraitRef<'tcx>>, private::HiddenZst),
47+
VTableTy(Ty<'tcx>, Option<ExistentialTraitRef<'tcx>>, private::HiddenZst),
4848
}
4949

5050
impl<'tcx> UniqueTypeId<'tcx> {
@@ -88,7 +88,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
8888
pub(crate) fn for_vtable_ty(
8989
tcx: TyCtxt<'tcx>,
9090
self_type: Ty<'tcx>,
91-
implemented_trait: Option<PolyExistentialTraitRef<'tcx>>,
91+
implemented_trait: Option<ExistentialTraitRef<'tcx>>,
9292
) -> Self {
9393
assert_eq!(
9494
self_type,

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
585585
fn create_vtable_debuginfo(
586586
&self,
587587
ty: Ty<'tcx>,
588-
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
588+
trait_ref: Option<ty::ExistentialTraitRef<'tcx>>,
589589
vtable: Self::Value,
590590
) {
591591
metadata::create_vtable_di_node(self, ty, trait_ref, vtable)

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
2525
use rustc_session::Session;
2626
use rustc_session::config::{self, CrateType, EntryFnType, OptLevel, OutputType};
2727
use rustc_span::{DUMMY_SP, Symbol, sym};
28-
use rustc_trait_selection::infer::at::ToTrace;
2928
use rustc_trait_selection::infer::{BoundRegionConversionTime, TyCtxtInferExt};
3029
use rustc_trait_selection::traits::{ObligationCause, ObligationCtxt};
3130
use tracing::{debug, info};
@@ -128,14 +127,9 @@ pub fn validate_trivial_unsize<'tcx>(
128127
BoundRegionConversionTime::HigherRankedType,
129128
hr_source_principal,
130129
);
131-
let Ok(()) = ocx.eq_trace(
130+
let Ok(()) = ocx.eq(
132131
&ObligationCause::dummy(),
133132
param_env,
134-
ToTrace::to_trace(
135-
&ObligationCause::dummy(),
136-
hr_target_principal,
137-
hr_source_principal,
138-
),
139133
target_principal,
140134
source_principal,
141135
) else {
@@ -210,7 +204,12 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
210204
old_info
211205
}
212206
}
213-
(_, ty::Dynamic(data, _, _)) => meth::get_vtable(cx, source, data.principal()),
207+
(_, ty::Dynamic(data, _, _)) => meth::get_vtable(
208+
cx,
209+
source,
210+
data.principal()
211+
.map(|principal| bx.tcx().instantiate_bound_regions_with_erased(principal)),
212+
),
214213
_ => bug!("unsized_info: invalid unsizing {:?} -> {:?}", source, target),
215214
}
216215
}

0 commit comments

Comments
 (0)