mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
make first component of dyn* use pointer layout+type, and adjust DynStar comment
This commit is contained in:
parent
3eb5c4581a
commit
88e39ee314
@ -39,7 +39,7 @@ use rustc_session::Session;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_span::{DebuggerVisualizerFile, DebuggerVisualizerType};
|
||||
use rustc_target::abi::{Align, Size, VariantIdx};
|
||||
use rustc_target::abi::{Align, VariantIdx};
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
use std::time::{Duration, Instant};
|
||||
@ -273,13 +273,6 @@ pub fn cast_to_dyn_star<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)),
|
||||
"destination type must be a dyn*"
|
||||
);
|
||||
// FIXME(dyn-star): this is probably not the best way to check if this is
|
||||
// a pointer, and really we should ensure that the value is a suitable
|
||||
// pointer earlier in the compilation process.
|
||||
let src = match src_ty_and_layout.pointee_info_at(bx.cx(), Size::ZERO) {
|
||||
Some(_) => bx.ptrtoint(src, bx.cx().type_isize()),
|
||||
None => bx.bitcast(src, bx.type_isize()),
|
||||
};
|
||||
(src, unsized_info(bx, src_ty_and_layout.ty, dst_ty, old_info))
|
||||
}
|
||||
|
||||
|
@ -770,7 +770,7 @@ where
|
||||
|
||||
ty::Dynamic(_, _, ty::DynStar) => {
|
||||
if i == 0 {
|
||||
TyMaybeWithLayout::Ty(tcx.types.usize)
|
||||
TyMaybeWithLayout::Ty(tcx.mk_mut_ptr(tcx.types.unit))
|
||||
} else if i == 1 {
|
||||
// FIXME(dyn-star) same FIXME as above applies here too
|
||||
TyMaybeWithLayout::Ty(
|
||||
|
@ -193,7 +193,7 @@ fn layout_of_uncached<'tcx>(
|
||||
}
|
||||
|
||||
ty::Dynamic(_, _, ty::DynStar) => {
|
||||
let mut data = scalar_unit(Int(dl.ptr_sized_integer(), false));
|
||||
let mut data = scalar_unit(Pointer(AddressSpace::DATA));
|
||||
data.valid_range_mut().start = 0;
|
||||
let mut vtable = scalar_unit(Pointer(AddressSpace::DATA));
|
||||
vtable.valid_range_mut().start = 1;
|
||||
|
@ -26,11 +26,9 @@ pub enum DynKind {
|
||||
Dyn,
|
||||
/// A sized `dyn* Trait` object
|
||||
///
|
||||
/// These objects are represented as a `(data, vtable)` pair where `data` is a ptr-sized value
|
||||
/// (often a pointer to the real object, but not necessarily) and `vtable` is a pointer to
|
||||
/// the vtable for `dyn* Trait`. The representation is essentially the same as `&dyn Trait`
|
||||
/// or similar, but the drop function included in the vtable is responsible for freeing the
|
||||
/// underlying storage if needed. This allows a `dyn*` object to be treated agnostically with
|
||||
/// These objects are represented as a `(data, vtable)` pair where `data` is a value of some
|
||||
/// ptr-sized and ptr-aligned dynamically determined type `T` and `vtable` is a pointer to the
|
||||
/// vtable of `impl T for Trait`. This allows a `dyn*` object to be treated agnostically with
|
||||
/// respect to whether it points to a `Box<T>`, `Rc<T>`, etc.
|
||||
DynStar,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user