Skip to content

Commit e99a1bc

Browse files
RalfJungcompiler-errors
authored andcommitted
make first component of dyn* use pointer layout+type, and adjust DynStar comment
1 parent 2b3f260 commit e99a1bc

File tree

4 files changed

+6
-15
lines changed

4 files changed

+6
-15
lines changed

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustc_session::Session;
3939
use rustc_span::symbol::sym;
4040
use rustc_span::Symbol;
4141
use rustc_span::{DebuggerVisualizerFile, DebuggerVisualizerType};
42-
use rustc_target::abi::{Align, Size, VariantIdx};
42+
use rustc_target::abi::{Align, VariantIdx};
4343

4444
use std::collections::BTreeSet;
4545
use std::time::{Duration, Instant};
@@ -273,13 +273,6 @@ pub fn cast_to_dyn_star<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
273273
matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)),
274274
"destination type must be a dyn*"
275275
);
276-
// FIXME(dyn-star): this is probably not the best way to check if this is
277-
// a pointer, and really we should ensure that the value is a suitable
278-
// pointer earlier in the compilation process.
279-
let src = match src_ty_and_layout.pointee_info_at(bx.cx(), Size::ZERO) {
280-
Some(_) => bx.ptrtoint(src, bx.cx().type_isize()),
281-
None => bx.bitcast(src, bx.type_isize()),
282-
};
283276
(src, unsized_info(bx, src_ty_and_layout.ty, dst_ty, old_info))
284277
}
285278

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ where
770770

771771
ty::Dynamic(_, _, ty::DynStar) => {
772772
if i == 0 {
773-
TyMaybeWithLayout::Ty(tcx.types.usize)
773+
TyMaybeWithLayout::Ty(tcx.mk_mut_ptr(tcx.types.unit))
774774
} else if i == 1 {
775775
// FIXME(dyn-star) same FIXME as above applies here too
776776
TyMaybeWithLayout::Ty(

compiler/rustc_ty_utils/src/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn layout_of_uncached<'tcx>(
193193
}
194194

195195
ty::Dynamic(_, _, ty::DynStar) => {
196-
let mut data = scalar_unit(Int(dl.ptr_sized_integer(), false));
196+
let mut data = scalar_unit(Pointer(AddressSpace::DATA));
197197
data.valid_range_mut().start = 0;
198198
let mut vtable = scalar_unit(Pointer(AddressSpace::DATA));
199199
vtable.valid_range_mut().start = 1;

compiler/rustc_type_ir/src/sty.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ pub enum DynKind {
2626
Dyn,
2727
/// A sized `dyn* Trait` object
2828
///
29-
/// These objects are represented as a `(data, vtable)` pair where `data` is a ptr-sized value
30-
/// (often a pointer to the real object, but not necessarily) and `vtable` is a pointer to
31-
/// the vtable for `dyn* Trait`. The representation is essentially the same as `&dyn Trait`
32-
/// or similar, but the drop function included in the vtable is responsible for freeing the
33-
/// underlying storage if needed. This allows a `dyn*` object to be treated agnostically with
29+
/// These objects are represented as a `(data, vtable)` pair where `data` is a value of some
30+
/// ptr-sized and ptr-aligned dynamically determined type `T` and `vtable` is a pointer to the
31+
/// vtable of `impl T for Trait`. This allows a `dyn*` object to be treated agnostically with
3432
/// respect to whether it points to a `Box<T>`, `Rc<T>`, etc.
3533
DynStar,
3634
}

0 commit comments

Comments
 (0)