Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #107946

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make first component of dyn* use pointer layout+type, and adjust DynS…
…tar comment
RalfJung authored and compiler-errors committed Feb 11, 2023
commit e99a1bc09e8611e151319c12b8d3b6d8b7b30ac7
9 changes: 1 addition & 8 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
@@ -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))
}

2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
@@ -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(
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 3 additions & 5 deletions compiler/rustc_type_ir/src/sty.rs
Original file line number Diff line number Diff line change
@@ -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,
}