Skip to content

Commit 443ab20

Browse files
Remove support for dyn*
1 parent d14d202 commit 443ab20

File tree

143 files changed

+100
-2188
lines changed

Some content is hidden

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

143 files changed

+100
-2188
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,8 +2577,7 @@ pub enum TyPatKind {
25772577
pub enum TraitObjectSyntax {
25782578
// SAFETY: When adding new variants make sure to update the `Tag` impl.
25792579
Dyn = 0,
2580-
DynStar = 1,
2581-
None = 2,
2580+
None = 1,
25822581
}
25832582

25842583
/// SAFETY: `TraitObjectSyntax` only has 3 data-less variants which means
@@ -2594,8 +2593,7 @@ unsafe impl Tag for TraitObjectSyntax {
25942593
unsafe fn from_usize(tag: usize) -> Self {
25952594
match tag {
25962595
0 => TraitObjectSyntax::Dyn,
2597-
1 => TraitObjectSyntax::DynStar,
2598-
2 => TraitObjectSyntax::None,
2596+
1 => TraitObjectSyntax::None,
25992597
_ => unreachable!(),
26002598
}
26012599
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
505505
);
506506
gate_all!(associated_const_equality, "associated const equality is incomplete");
507507
gate_all!(yeet_expr, "`do yeet` expression is experimental");
508-
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
509508
gate_all!(const_closures, "const closures are experimental");
510509
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
511510
gate_all!(ergonomic_clones, "ergonomic clones are experimental");

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,6 @@ impl<'a> State<'a> {
13031303
ast::TyKind::TraitObject(bounds, syntax) => {
13041304
match syntax {
13051305
ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"),
1306-
ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"),
13071306
ast::TraitObjectSyntax::None => {}
13081307
}
13091308
self.print_type_bounds(bounds);

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use rustc_middle::traits::query::NoSolution;
2525
use rustc_middle::ty::adjustment::PointerCoercion;
2626
use rustc_middle::ty::cast::CastTy;
2727
use rustc_middle::ty::{
28-
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt,
29-
Dynamic, GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt,
30-
TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions,
28+
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt,
29+
GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, TypeVisitableExt,
30+
UserArgs, UserTypeAnnotationIndex, fold_regions,
3131
};
3232
use rustc_middle::{bug, span_bug};
3333
use rustc_mir_dataflow::move_paths::MoveData;
@@ -1233,38 +1233,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
12331233
);
12341234
}
12351235

1236-
CastKind::PointerCoercion(PointerCoercion::DynStar, coercion_source) => {
1237-
// get the constraints from the target type (`dyn* Clone`)
1238-
//
1239-
// apply them to prove that the source type `Foo` implements `Clone` etc
1240-
let (existential_predicates, region) = match ty.kind() {
1241-
Dynamic(predicates, region, ty::DynStar) => (predicates, region),
1242-
_ => panic!("Invalid dyn* cast_ty"),
1243-
};
1244-
1245-
let self_ty = op.ty(self.body, tcx);
1246-
1247-
let is_implicit_coercion = coercion_source == CoercionSource::Implicit;
1248-
self.prove_predicates(
1249-
existential_predicates
1250-
.iter()
1251-
.map(|predicate| predicate.with_self_ty(tcx, self_ty)),
1252-
location.to_locations(),
1253-
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
1254-
);
1255-
1256-
let outlives_predicate = tcx.mk_predicate(Binder::dummy(
1257-
ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(
1258-
ty::OutlivesPredicate(self_ty, *region),
1259-
)),
1260-
));
1261-
self.prove_predicate(
1262-
outlives_predicate,
1263-
location.to_locations(),
1264-
ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None },
1265-
);
1266-
}
1267-
12681236
CastKind::PointerCoercion(
12691237
PointerCoercion::MutToConstPointer,
12701238
coercion_source,

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -753,51 +753,6 @@ pub(crate) fn codegen_drop<'tcx>(
753753
fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]);
754754
fx.bcx.ins().jump(ret_block, &[]);
755755
}
756-
ty::Dynamic(_, _, ty::DynStar) => {
757-
// IN THIS ARM, WE HAVE:
758-
// ty = *mut (dyn* Trait)
759-
// which is: *mut exists<T: sizeof(T) == sizeof(usize)> (T, Vtable<T: Trait>)
760-
//
761-
// args = [ * ]
762-
// |
763-
// v
764-
// ( Data, Vtable )
765-
// |
766-
// v
767-
// /-------\
768-
// | ... |
769-
// \-------/
770-
//
771-
//
772-
// WE CAN CONVERT THIS INTO THE ABOVE LOGIC BY DOING
773-
//
774-
// data = &(*args[0]).0 // gives a pointer to Data above (really the same pointer)
775-
// vtable = (*args[0]).1 // loads the vtable out
776-
// (data, vtable) // an equivalent Rust `*mut dyn Trait`
777-
//
778-
// SO THEN WE CAN USE THE ABOVE CODE.
779-
let (data, vtable) = drop_place.to_cvalue(fx).dyn_star_force_data_on_stack(fx);
780-
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable);
781-
782-
let is_null = fx.bcx.ins().icmp_imm(IntCC::Equal, drop_fn, 0);
783-
let target_block = fx.get_block(target);
784-
let continued = fx.bcx.create_block();
785-
fx.bcx.ins().brif(is_null, target_block, &[], continued, &[]);
786-
fx.bcx.switch_to_block(continued);
787-
788-
let virtual_drop = Instance {
789-
def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0),
790-
args: drop_instance.args,
791-
};
792-
let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx)
793-
.fn_abi_of_instance(virtual_drop, ty::List::empty());
794-
795-
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi);
796-
let sig = fx.bcx.import_signature(sig);
797-
fx.bcx.ins().call_indirect(sig, drop_fn, &[data]);
798-
// FIXME implement cleanup on exceptions
799-
fx.bcx.ins().jump(ret_block, &[]);
800-
}
801756
_ => {
802757
assert!(!matches!(drop_instance.def, InstanceKind::Virtual(_, _)));
803758

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -778,14 +778,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
778778
let operand = codegen_operand(fx, operand);
779779
crate::unsize::coerce_unsized_into(fx, operand, lval);
780780
}
781-
Rvalue::Cast(
782-
CastKind::PointerCoercion(PointerCoercion::DynStar, _),
783-
ref operand,
784-
_,
785-
) => {
786-
let operand = codegen_operand(fx, operand);
787-
crate::unsize::coerce_dyn_star(fx, operand, lval);
788-
}
789781
Rvalue::Cast(CastKind::Transmute, ref operand, _to_ty) => {
790782
let operand = codegen_operand(fx, operand);
791783
lval.write_cvalue_transmute(fx, operand);

compiler/rustc_codegen_cranelift/src/unsize.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,6 @@ fn unsize_ptr<'tcx>(
112112
}
113113
}
114114

115-
/// Coerces `src` to `dst_ty` which is guaranteed to be a `dyn*` type.
116-
pub(crate) fn cast_to_dyn_star<'tcx>(
117-
fx: &mut FunctionCx<'_, '_, 'tcx>,
118-
src: Value,
119-
src_ty_and_layout: TyAndLayout<'tcx>,
120-
dst_ty: Ty<'tcx>,
121-
old_info: Option<Value>,
122-
) -> (Value, Value) {
123-
assert!(
124-
matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)),
125-
"destination type must be a dyn*"
126-
);
127-
(src, unsized_info(fx, src_ty_and_layout.ty, dst_ty, old_info))
128-
}
129-
130115
/// Coerce `src`, which is a reference to a value of type `src_ty`,
131116
/// to a value of type `dst_ty` and store the result in `dst`
132117
pub(crate) fn coerce_unsized_into<'tcx>(
@@ -174,24 +159,6 @@ pub(crate) fn coerce_unsized_into<'tcx>(
174159
}
175160
}
176161

177-
pub(crate) fn coerce_dyn_star<'tcx>(
178-
fx: &mut FunctionCx<'_, '_, 'tcx>,
179-
src: CValue<'tcx>,
180-
dst: CPlace<'tcx>,
181-
) {
182-
let (data, extra) = if let ty::Dynamic(_, _, ty::DynStar) = src.layout().ty.kind() {
183-
let (data, vtable) = src.load_scalar_pair(fx);
184-
(data, Some(vtable))
185-
} else {
186-
let data = src.load_scalar(fx);
187-
(data, None)
188-
};
189-
190-
let (data, vtable) = cast_to_dyn_star(fx, data, src.layout(), dst.layout().ty, extra);
191-
192-
dst.write_cvalue(fx, CValue::by_val_pair(data, vtable, dst.layout()));
193-
}
194-
195162
// Adapted from https://github.com/rust-lang/rust/blob/2a663555ddf36f6b041445894a8c175cd1bc718c/src/librustc_codegen_ssa/glue.rs
196163

197164
pub(crate) fn size_and_align_of<'tcx>(

compiler/rustc_codegen_cranelift/src/value_and_place.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -121,43 +121,6 @@ impl<'tcx> CValue<'tcx> {
121121
}
122122
}
123123

124-
// FIXME remove
125-
/// Forces the data value of a dyn* value to the stack and returns a pointer to it as well as the
126-
/// vtable pointer.
127-
pub(crate) fn dyn_star_force_data_on_stack(
128-
self,
129-
fx: &mut FunctionCx<'_, '_, 'tcx>,
130-
) -> (Value, Value) {
131-
assert!(self.1.ty.is_dyn_star());
132-
133-
match self.0 {
134-
CValueInner::ByRef(ptr, None) => {
135-
let (a_scalar, b_scalar) = match self.1.backend_repr {
136-
BackendRepr::ScalarPair(a, b) => (a, b),
137-
_ => unreachable!("dyn_star_force_data_on_stack({:?})", self),
138-
};
139-
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
140-
let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar);
141-
let mut flags = MemFlags::new();
142-
flags.set_notrap();
143-
let vtable = ptr.offset(fx, b_offset).load(fx, clif_ty2, flags);
144-
(ptr.get_addr(fx), vtable)
145-
}
146-
CValueInner::ByValPair(data, vtable) => {
147-
let data_ptr = fx.create_stack_slot(
148-
u32::try_from(fx.target_config.pointer_type().bytes()).unwrap(),
149-
u32::try_from(fx.target_config.pointer_type().bytes()).unwrap(),
150-
);
151-
data_ptr.store(fx, data, MemFlags::trusted());
152-
153-
(data_ptr.get_addr(fx), vtable)
154-
}
155-
CValueInner::ByRef(_, Some(_)) | CValueInner::ByVal(_) => {
156-
unreachable!("dyn_star_force_data_on_stack({:?})", self)
157-
}
158-
}
159-
}
160-
161124
pub(crate) fn try_to_ptr(self) -> Option<(Pointer, Option<Value>)> {
162125
match self.0 {
163126
CValueInner::ByRef(ptr, meta) => Some((ptr, meta)),

compiler/rustc_codegen_cranelift/src/vtable.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
5757
}
5858
}
5959

60-
if let ty::Ref(_, ty, _) = arg.layout().ty.kind() {
61-
if ty.is_dyn_star() {
62-
let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap());
63-
let dyn_star = CPlace::for_ptr(Pointer::new(arg.load_scalar(fx)), inner_layout);
64-
let ptr = dyn_star.place_field(fx, FieldIdx::ZERO).to_ptr();
65-
let vtable = dyn_star.place_field(fx, FieldIdx::ONE).to_cvalue(fx).load_scalar(fx);
66-
break 'block (ptr, vtable);
67-
}
68-
}
69-
7060
if let BackendRepr::ScalarPair(_, _) = arg.layout().backend_repr {
7161
let (ptr, vtable) = arg.load_scalar_pair(fx);
7262
(Pointer::new(ptr), vtable)

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -262,28 +262,6 @@ pub(crate) fn unsize_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
262262
}
263263
}
264264

265-
/// Coerces `src` to `dst_ty` which is guaranteed to be a `dyn*` type.
266-
pub(crate) fn cast_to_dyn_star<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
267-
bx: &mut Bx,
268-
src: Bx::Value,
269-
src_ty_and_layout: TyAndLayout<'tcx>,
270-
dst_ty: Ty<'tcx>,
271-
old_info: Option<Bx::Value>,
272-
) -> (Bx::Value, Bx::Value) {
273-
debug!("cast_to_dyn_star: {:?} => {:?}", src_ty_and_layout.ty, dst_ty);
274-
assert!(
275-
matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)),
276-
"destination type must be a dyn*"
277-
);
278-
let src = match bx.cx().type_kind(bx.cx().backend_type(src_ty_and_layout)) {
279-
TypeKind::Pointer => src,
280-
TypeKind::Integer => bx.inttoptr(src, bx.type_ptr()),
281-
// FIXME(dyn-star): We probably have to do a bitcast first, then inttoptr.
282-
kind => bug!("unexpected TypeKind for left-hand side of `dyn*` cast: {kind:?}"),
283-
};
284-
(src, unsized_info(bx, src_ty_and_layout.ty, dst_ty, old_info))
285-
}
286-
287265
/// Coerces `src`, which is a reference to a value of type `src_ty`,
288266
/// to a value of type `dst_ty`, and stores the result in `dst`.
289267
pub(crate) fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -628,50 +628,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
628628
virtual_drop,
629629
)
630630
}
631-
ty::Dynamic(_, _, ty::DynStar) => {
632-
// IN THIS ARM, WE HAVE:
633-
// ty = *mut (dyn* Trait)
634-
// which is: *mut exists<T: sizeof(T) == sizeof(usize)> (T, Vtable<T: Trait>)
635-
//
636-
// args = [ * ]
637-
// |
638-
// v
639-
// ( Data, Vtable )
640-
// |
641-
// v
642-
// /-------\
643-
// | ... |
644-
// \-------/
645-
//
646-
//
647-
// WE CAN CONVERT THIS INTO THE ABOVE LOGIC BY DOING
648-
//
649-
// data = &(*args[0]).0 // gives a pointer to Data above (really the same pointer)
650-
// vtable = (*args[0]).1 // loads the vtable out
651-
// (data, vtable) // an equivalent Rust `*mut dyn Trait`
652-
//
653-
// SO THEN WE CAN USE THE ABOVE CODE.
654-
let virtual_drop = Instance {
655-
def: ty::InstanceKind::Virtual(drop_fn.def_id(), 0), // idx 0: the drop function
656-
args: drop_fn.args,
657-
};
658-
debug!("ty = {:?}", ty);
659-
debug!("drop_fn = {:?}", drop_fn);
660-
debug!("args = {:?}", args);
661-
let fn_abi = bx.fn_abi_of_instance(virtual_drop, ty::List::empty());
662-
let meta_ptr = place.project_field(bx, 1);
663-
let meta = bx.load_operand(meta_ptr);
664-
// Truncate vtable off of args list
665-
args = &args[..1];
666-
debug!("args' = {:?}", args);
667-
(
668-
true,
669-
meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_DROPINPLACE)
670-
.get_optional_fn(bx, meta.immediate(), ty, fn_abi),
671-
fn_abi,
672-
virtual_drop,
673-
)
674-
}
675631
_ => (
676632
false,
677633
bx.get_fn_addr(drop_fn),
@@ -1102,33 +1058,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11021058
llargs.push(data_ptr);
11031059
continue;
11041060
}
1105-
Immediate(_) => {
1106-
// See comment above explaining why we peel these newtypes
1107-
while !op.layout.ty.is_raw_ptr() && !op.layout.ty.is_ref() {
1108-
let (idx, _) = op.layout.non_1zst_field(bx).expect(
1109-
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
1110-
);
1111-
op = op.extract_field(self, bx, idx.as_usize());
1112-
}
1113-
1114-
// Make sure that we've actually unwrapped the rcvr down
1115-
// to a pointer or ref to `dyn* Trait`.
1116-
if !op.layout.ty.builtin_deref(true).unwrap().is_dyn_star() {
1117-
span_bug!(fn_span, "can't codegen a virtual call on {:#?}", op);
1118-
}
1119-
let place = op.deref(bx.cx());
1120-
let data_place = place.project_field(bx, 0);
1121-
let meta_place = place.project_field(bx, 1);
1122-
let meta = bx.load_operand(meta_place);
1123-
llfn = Some(meth::VirtualIndex::from_index(idx).get_fn(
1124-
bx,
1125-
meta.immediate(),
1126-
op.layout.ty,
1127-
fn_abi,
1128-
));
1129-
llargs.push(data_place.val.llval);
1130-
continue;
1131-
}
11321061
_ => {
11331062
span_bug!(fn_span, "can't codegen a virtual call on {:#?}", op);
11341063
}

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
468468
bug!("unexpected non-pair operand");
469469
}
470470
}
471-
mir::CastKind::PointerCoercion(PointerCoercion::DynStar, _) => {
472-
let (lldata, llextra) = operand.val.pointer_parts();
473-
let (lldata, llextra) =
474-
base::cast_to_dyn_star(bx, lldata, operand.layout, cast.ty, llextra);
475-
OperandValue::Pair(lldata, llextra)
476-
}
477471
| mir::CastKind::IntToInt
478472
| mir::CastKind::FloatToInt
479473
| mir::CastKind::FloatToFloat

0 commit comments

Comments
 (0)