Skip to content

Commit ef78e98

Browse files
Remove support for dyn*
1 parent d8c129a commit ef78e98

File tree

5 files changed

+14
-149
lines changed

5 files changed

+14
-149
lines changed

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

src/base.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -790,14 +790,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
790790
let operand = codegen_operand(fx, operand);
791791
crate::unsize::coerce_unsized_into(fx, operand, lval);
792792
}
793-
Rvalue::Cast(
794-
CastKind::PointerCoercion(PointerCoercion::DynStar, _),
795-
ref operand,
796-
_,
797-
) => {
798-
let operand = codegen_operand(fx, operand);
799-
crate::unsize::coerce_dyn_star(fx, operand, lval);
800-
}
801793
Rvalue::Cast(CastKind::Transmute, ref operand, _to_ty) => {
802794
let operand = codegen_operand(fx, operand);
803795
lval.write_cvalue_transmute(fx, operand);

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>(

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)),

src/vtable.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,22 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
4646
mut arg: CValue<'tcx>,
4747
idx: usize,
4848
) -> (Pointer, Value) {
49-
let (ptr, vtable) = 'block: {
50-
if let BackendRepr::Scalar(_) = arg.layout().backend_repr {
51-
while !arg.layout().ty.is_raw_ptr() && !arg.layout().ty.is_ref() {
52-
let (idx, _) = arg
53-
.layout()
54-
.non_1zst_field(fx)
55-
.expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type");
56-
arg = arg.value_field(fx, idx);
57-
}
58-
}
59-
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-
}
49+
if let BackendRepr::Scalar(_) = arg.layout().backend_repr {
50+
while !arg.layout().ty.is_raw_ptr() && !arg.layout().ty.is_ref() {
51+
let (idx, _) = arg
52+
.layout()
53+
.non_1zst_field(fx)
54+
.expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type");
55+
arg = arg.value_field(fx, idx);
6856
}
57+
}
6958

70-
if let BackendRepr::ScalarPair(_, _) = arg.layout().backend_repr {
71-
let (ptr, vtable) = arg.load_scalar_pair(fx);
72-
(Pointer::new(ptr), vtable)
73-
} else {
74-
let (ptr, vtable) = arg.try_to_ptr().unwrap();
75-
(ptr, vtable.unwrap())
76-
}
59+
let (ptr, vtable) = if let BackendRepr::ScalarPair(_, _) = arg.layout().backend_repr {
60+
let (ptr, vtable) = arg.load_scalar_pair(fx);
61+
(Pointer::new(ptr), vtable)
62+
} else {
63+
let (ptr, vtable) = arg.try_to_ptr().unwrap();
64+
(ptr, vtable.unwrap())
7765
};
7866

7967
let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes();

0 commit comments

Comments
 (0)