Skip to content

Commit 34b8fe4

Browse files
committed
Create a new TyKind::DynStar variant
Not finished yet, just enough to make it compile.
1 parent 2773383 commit 34b8fe4

File tree

67 files changed

+270
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+270
-168
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use rustc_middle::ty::cast::CastTy;
3232
use rustc_middle::ty::subst::{SubstsRef, UserSubsts};
3333
use rustc_middle::ty::visit::TypeVisitable;
3434
use rustc_middle::ty::{
35-
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, Dynamic,
36-
OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
35+
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, OpaqueHiddenType,
36+
OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
3737
};
3838
use rustc_span::def_id::CRATE_DEF_ID;
3939
use rustc_span::{Span, DUMMY_SP};
@@ -1928,7 +1928,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19281928
//
19291929
// apply them to prove that the source type `Foo` implements `Clone` etc
19301930
let (existential_predicates, region) = match ty.kind() {
1931-
Dynamic(predicates, region, ty::DynStar) => (predicates, region),
1931+
ty::DynStar(predicates, region) => (predicates, region),
19321932
_ => panic!("Invalid dyn* cast_ty"),
19331933
};
19341934

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use rustc_span::symbol::sym;
4040
use rustc_span::Symbol;
4141
use rustc_span::{DebuggerVisualizerFile, DebuggerVisualizerType};
4242
use rustc_target::abi::{Align, Size, VariantIdx};
43+
use rustc_type_ir::DynKind;
4344

4445
use std::collections::BTreeSet;
4546
use std::time::{Duration, Instant};
@@ -150,10 +151,8 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
150151
(&ty::Array(_, len), &ty::Slice(_)) => {
151152
cx.const_usize(len.eval_usize(cx.tcx(), ty::ParamEnv::reveal_all()))
152153
}
153-
(
154-
&ty::Dynamic(ref data_a, _, src_dyn_kind),
155-
&ty::Dynamic(ref data_b, _, target_dyn_kind),
156-
) if src_dyn_kind == target_dyn_kind => {
154+
(&ty::Dynamic(ref data_a, _), &ty::Dynamic(ref data_b, _))
155+
| (&ty::DynStar(ref data_a, _), &ty::DynStar(ref data_b, _)) => {
157156
let old_info =
158157
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
159158
if data_a.principal_def_id() == data_b.principal_def_id() {
@@ -169,7 +168,15 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
169168
if let Some(entry_idx) = vptr_entry_idx {
170169
let ptr_ty = cx.type_i8p();
171170
let ptr_align = cx.tcx().data_layout.pointer_align.abi;
172-
let vtable_ptr_ty = vtable_ptr_ty(cx, target, target_dyn_kind);
171+
let vtable_ptr_ty = vtable_ptr_ty(
172+
cx,
173+
target,
174+
match target.kind() {
175+
ty::Dynamic(..) => DynKind::Dyn,
176+
ty::DynStar(..) => DynKind::DynStar,
177+
_ => unreachable!(),
178+
},
179+
);
173180
let llvtable = bx.pointercast(old_info, bx.type_ptr_to(ptr_ty));
174181
let gep = bx.inbounds_gep(
175182
ptr_ty,
@@ -185,8 +192,12 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
185192
old_info
186193
}
187194
}
188-
(_, &ty::Dynamic(ref data, _, target_dyn_kind)) => {
189-
let vtable_ptr_ty = vtable_ptr_ty(cx, target, target_dyn_kind);
195+
(_, &ty::Dynamic(ref data, _)) => {
196+
let vtable_ptr_ty = vtable_ptr_ty(cx, target, DynKind::Dyn);
197+
cx.const_ptrcast(meth::get_vtable(cx, source, data.principal()), vtable_ptr_ty)
198+
}
199+
(_, &ty::DynStar(ref data, _)) => {
200+
let vtable_ptr_ty = vtable_ptr_ty(cx, target, DynKind::DynStar);
190201
cx.const_ptrcast(meth::get_vtable(cx, source, data.principal()), vtable_ptr_ty)
191202
}
192203
_ => bug!("unsized_info: invalid unsizing {:?} -> {:?}", source, target),
@@ -197,14 +208,15 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
197208
fn vtable_ptr_ty<'tcx, Cx: CodegenMethods<'tcx>>(
198209
cx: &Cx,
199210
target: Ty<'tcx>,
211+
// FIXME(dyn-star): This should be only place we need a `DynKind`, so move its definition here.
200212
kind: ty::DynKind,
201213
) -> <Cx as BackendTypes>::Type {
202214
cx.scalar_pair_element_backend_type(
203215
cx.layout_of(match kind {
204216
// vtable is the second field of `*mut dyn Trait`
205-
ty::Dyn => cx.tcx().mk_mut_ptr(target),
217+
DynKind::Dyn => cx.tcx().mk_mut_ptr(target),
206218
// vtable is the second field of `dyn* Trait`
207-
ty::DynStar => target,
219+
DynKind::DynStar => target,
208220
}),
209221
1,
210222
true,
@@ -269,10 +281,7 @@ pub fn cast_to_dyn_star<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
269281
old_info: Option<Bx::Value>,
270282
) -> (Bx::Value, Bx::Value) {
271283
debug!("cast_to_dyn_star: {:?} => {:?}", src_ty_and_layout.ty, dst_ty);
272-
assert!(
273-
matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)),
274-
"destination type must be a dyn*"
275-
);
284+
assert!(matches!(dst_ty.kind(), ty::DynStar(_, _)), "destination type must be a dyn*");
276285
// FIXME(dyn-star): this is probably not the best way to check if this is
277286
// a pointer, and really we should ensure that the value is a suitable
278287
// pointer earlier in the compilation process.

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ fn push_debuginfo_type_name<'tcx>(
209209
output.push(']');
210210
}
211211
}
212+
ty::DynStar(..) => unimplemented!(),
212213
ty::Dynamic(ref trait_data, ..) => {
213214
let auto_traits: SmallVec<[DefId; 4]> = trait_data.auto_traits().collect();
214215

compiler/rustc_codegen_ssa/src/meth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'a, 'tcx> VirtualIndex {
6868
fn expect_dyn_trait_in_self(ty: Ty<'_>) -> ty::PolyExistentialTraitRef<'_> {
6969
for arg in ty.peel_refs().walk() {
7070
if let GenericArgKind::Type(ty) = arg.unpack() {
71-
if let ty::Dynamic(data, _, _) = ty.kind() {
71+
if let ty::Dynamic(data, _) | ty::DynStar(data, _) = ty.kind() {
7272
return data.principal().expect("expected principal trait object");
7373
}
7474
}

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
455455
let (drop_fn, fn_abi) = match ty.kind() {
456456
// FIXME(eddyb) perhaps move some of this logic into
457457
// `Instance::resolve_drop_in_place`?
458-
ty::Dynamic(_, _, ty::Dyn) => {
458+
ty::Dynamic(_, _) => {
459459
// IN THIS ARM, WE HAVE:
460460
// ty = *mut (dyn Trait)
461461
// which is: exists<T> ( *mut T, Vtable<T: Trait> )
@@ -485,7 +485,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
485485
fn_abi,
486486
)
487487
}
488-
ty::Dynamic(_, _, ty::DynStar) => {
488+
ty::DynStar(..) => {
489489
// IN THIS ARM, WE HAVE:
490490
// ty = *mut (dyn* Trait)
491491
// which is: *mut exists<T: sizeof(T) == sizeof(usize)> (T, Vtable<T: Trait>)

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
118118
// resolving their backing type, even if we can do that at const eval time. We may
119119
// hypothetically be able to allow `dyn StructuralEq` trait objects in the future,
120120
// but it is unclear if this is useful.
121-
ty::Dynamic(..) => Err(ValTreeCreationError::NonSupportedType),
121+
ty::Dynamic(..) | ty::DynStar(..) => Err(ValTreeCreationError::NonSupportedType),
122122

123123
ty::Tuple(elem_tys) => {
124124
branches(ecx, place, elem_tys.len(), None, num_nodes)
@@ -319,7 +319,8 @@ pub fn valtree_to_const_value<'tcx>(
319319
| ty::RawPtr(_)
320320
| ty::Str
321321
| ty::Slice(_)
322-
| ty::Dynamic(..) => bug!("no ValTree should have been created for type {:?}", ty.kind()),
322+
| ty::Dynamic(..)
323+
| ty::DynStar(..) => bug!("no ValTree should have been created for type {:?}", ty.kind()),
323324
}
324325
}
325326

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
121121
}
122122

123123
DynStar => {
124-
if let ty::Dynamic(data, _, ty::DynStar) = cast_ty.kind() {
124+
if let ty::DynStar(data, _) = cast_ty.kind() {
125125
// Initial cast from sized to dyn trait
126126
let vtable = self.get_vtable_ptr(src.layout.ty, data.principal())?;
127127
let vtable = Scalar::from_maybe_pointer(vtable, self);
@@ -347,7 +347,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
347347
let new_vptr = self.get_vtable_ptr(ty, data_b.principal())?;
348348
self.write_immediate(Immediate::new_dyn_trait(old_data, new_vptr, self), dest)
349349
}
350-
(_, &ty::Dynamic(data, _, ty::Dyn)) => {
350+
(_, &ty::Dynamic(data, _)) => {
351351
// Initial cast from sized to dyn trait
352352
let vtable = self.get_vtable_ptr(src_pointee_ty, data.principal())?;
353353
let ptr = self.read_scalar(src)?;

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
9797
| ty::Ref(_, _, _)
9898
| ty::FnDef(_, _)
9999
| ty::FnPtr(_)
100-
| ty::Dynamic(_, _, _)
100+
| ty::Dynamic(_, _)
101+
| ty::DynStar(_, _)
101102
| ty::Closure(_, _)
102103
| ty::Generator(_, _, _)
103104
| ty::GeneratorWitness(_)

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
592592
| ty::Slice(..)
593593
| ty::Str
594594
| ty::Dynamic(..)
595+
| ty::DynStar(..)
595596
| ty::Closure(..)
596597
| ty::Generator(..) => Ok(false),
597598
// Some types only occur during typechecking, they have no layout.

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
4747
| ty::FnPtr(_)
4848
| ty::Never
4949
| ty::Tuple(_)
50-
| ty::Dynamic(_, _, _) => self.pretty_print_type(ty),
50+
| ty::Dynamic(_, _)
51+
| ty::DynStar(_, _) => self.pretty_print_type(ty),
5152

5253
// Placeholders (all printed as `_` to uniformize them).
5354
ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => {

0 commit comments

Comments
 (0)