Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl<'tcx> BorrowExplanation<'tcx> {

let elaborated_args =
std::iter::zip(*args, &generics.own_params).map(|(arg, param)| {
if let Some(ty::Dynamic(obj, _, ty::Dyn)) = arg.as_type().map(Ty::kind) {
if let Some(ty::Dynamic(obj, _)) = arg.as_type().map(Ty::kind) {
let default = tcx.object_lifetime_default(param.def_id);

let re_static = tcx.lifetimes.re_static;
Expand All @@ -464,7 +464,7 @@ impl<'tcx> BorrowExplanation<'tcx> {

has_dyn = true;

Ty::new_dynamic(tcx, obj, implied_region, ty::Dyn).into()
Ty::new_dynamic(tcx, obj, implied_region).into()
} else {
arg
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
| ty::Slice(_)
| ty::FnDef(_, _)
| ty::FnPtr(..)
| ty::Dynamic(_, _, _)
| ty::Dynamic(_, _)
| ty::Closure(_, _)
| ty::CoroutineClosure(_, _)
| ty::Coroutine(_, _)
Expand Down Expand Up @@ -1949,7 +1949,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
| ty::Ref(_, _, _)
| ty::FnDef(_, _)
| ty::FnPtr(..)
| ty::Dynamic(_, _, _)
| ty::Dynamic(_, _)
| ty::CoroutineWitness(..)
| ty::Never
| ty::UnsafeBinder(_)
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,9 +1487,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
unsize_to: None,
},
);
} else if let ty::Dynamic(src_tty, _src_lt, ty::Dyn) =
} else if let ty::Dynamic(src_tty, _src_lt) =
*self.struct_tail(src.ty, location).kind()
&& let ty::Dynamic(dst_tty, dst_lt, ty::Dyn) =
&& let ty::Dynamic(dst_tty, dst_lt) =
*self.struct_tail(dst.ty, location).kind()
&& src_tty.principal().is_some()
&& dst_tty.principal().is_some()
Expand All @@ -1511,15 +1511,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
// FIXME: Once we disallow casting `*const dyn Trait + 'short`
// to `*const dyn Trait + 'long`, then this can just be `src_lt`.
dst_lt,
ty::Dyn,
);
let dst_obj = Ty::new_dynamic(
tcx,
tcx.mk_poly_existential_predicates(
&dst_tty.without_auto_traits().collect::<Vec<_>>(),
),
dst_lt,
ty::Dyn,
);

debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ pub(crate) fn codegen_drop<'tcx>(
fx.bcx.ins().jump(ret_block, &[]);
} else {
match ty.kind() {
ty::Dynamic(_, _, ty::Dyn) => {
ty::Dynamic(_, _) => {
// IN THIS ARM, WE HAVE:
// ty = *mut (dyn Trait)
// which is: exists<T> ( *mut T, Vtable<T: Trait> )
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_cranelift/src/unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ pub(crate) fn unsized_info<'tcx>(
fx.pointer_type,
len.try_to_target_usize(fx.tcx).expect("expected monomorphic const in codegen") as i64,
),
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
if src_dyn_kind == target_dyn_kind =>
{
(&ty::Dynamic(data_a, _), &ty::Dynamic(data_b, _)) => {
let old_info =
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
let b_principal_def_id = data_b.principal_def_id();
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_cranelift/src/value_and_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,7 @@ pub(crate) fn assert_assignable<'tcx>(
);
// fn(&T) -> for<'l> fn(&'l T) is allowed
}
(&ty::Dynamic(from_traits, _, _from_kind), &ty::Dynamic(to_traits, _, _to_kind)) => {
// FIXME(dyn-star): Do the right thing with DynKinds
(&ty::Dynamic(from_traits, _), &ty::Dynamic(to_traits, _)) => {
for (from, to) in from_traits.iter().zip(to_traits) {
let from = fx.tcx.normalize_erasing_late_bound_regions(fx.typing_env(), from);
let to = fx.tcx.normalize_erasing_late_bound_regions(fx.typing_env(), to);
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,15 @@ fn build_basic_type_di_node<'ll, 'tcx>(
};

let typedef_di_node = unsafe {
llvm::LLVMRustDIBuilderCreateTypedef(
llvm::LLVMDIBuilderCreateTypedef(
DIB(cx),
ty_di_node,
typedef_name.as_c_char_ptr(),
typedef_name.as_ptr(),
typedef_name.len(),
unknown_file_metadata(cx),
0,
None,
0, // (no line number)
None, // (no scope)
0u32, // (no alignment specified)
)
};

Expand Down Expand Up @@ -1034,10 +1035,10 @@ fn create_member_type<'ll, 'tcx>(
type_di_node: &'ll DIType,
) -> &'ll DIType {
unsafe {
llvm::LLVMRustDIBuilderCreateMemberType(
llvm::LLVMDIBuilderCreateMemberType(
DIB(cx),
owner,
name.as_c_char_ptr(),
name.as_ptr(),
name.len(),
file_metadata,
line_number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, AdtDef, CoroutineArgs, CoroutineArgsExt, Ty};
use smallvec::smallvec;

use crate::common::{AsCCharPtr, CodegenCx};
use crate::common::CodegenCx;
use crate::debuginfo::dwarf_const::DW_TAG_const_type;
use crate::debuginfo::metadata::enums::DiscrResult;
use crate::debuginfo::metadata::type_map::{self, Stub, UniqueTypeId};
Expand Down Expand Up @@ -378,20 +378,17 @@ fn build_single_variant_union_fields<'ll, 'tcx>(
variant_struct_type_wrapper_di_node,
None,
),
unsafe {
llvm::LLVMRustDIBuilderCreateStaticMemberType(
DIB(cx),
enum_type_di_node,
TAG_FIELD_NAME.as_c_char_ptr(),
TAG_FIELD_NAME.len(),
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
variant_names_type_di_node,
visibility_flags,
Some(cx.const_u64(SINGLE_VARIANT_VIRTUAL_DISR)),
tag_base_type_align.bits() as u32,
)
}
create_static_member_type(
cx,
enum_type_di_node,
TAG_FIELD_NAME,
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
variant_names_type_di_node,
visibility_flags,
Some(cx.const_u64(SINGLE_VARIANT_VIRTUAL_DISR)),
tag_base_type_align,
),
]
}

Expand Down Expand Up @@ -570,27 +567,28 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
let build_assoc_const = |name: &str,
type_di_node_: &'ll DIType,
value: u64,
align: Align| unsafe {
align: Align|
-> &'ll llvm::Metadata {
// FIXME: Currently we force all DISCR_* values to be u64's as LLDB seems to have
// problems inspecting other value types. Since DISCR_* is typically only going to be
// directly inspected via the debugger visualizer - which compares it to the `tag` value
// (whose type is not modified at all) it shouldn't cause any real problems.
let (t_di, align) = if name == ASSOC_CONST_DISCR_NAME {
(type_di_node_, align.bits() as u32)
(type_di_node_, align)
} else {
let ty_u64 = Ty::new_uint(cx.tcx, ty::UintTy::U64);
(type_di_node(cx, ty_u64), Align::EIGHT.bits() as u32)
(type_di_node(cx, ty_u64), Align::EIGHT)
};

// must wrap type in a `const` modifier for LLDB to be able to inspect the value of the member
let field_type =
llvm::LLVMRustDIBuilderCreateQualifiedType(DIB(cx), DW_TAG_const_type, t_di);
let field_type = unsafe {
llvm::LLVMDIBuilderCreateQualifiedType(DIB(cx), DW_TAG_const_type, t_di)
};

llvm::LLVMRustDIBuilderCreateStaticMemberType(
DIB(cx),
create_static_member_type(
cx,
wrapper_struct_type_di_node,
name.as_c_char_ptr(),
name.len(),
name,
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
field_type,
Expand Down Expand Up @@ -975,3 +973,30 @@ fn variant_struct_wrapper_type_name(variant_index: VariantIdx) -> Cow<'static, s
.map(|&s| Cow::from(s))
.unwrap_or_else(|| format!("Variant{}", variant_index.as_usize()).into())
}

fn create_static_member_type<'ll>(
cx: &CodegenCx<'ll, '_>,
scope: &'ll llvm::Metadata,
name: &str,
file: &'ll llvm::Metadata,
line_number: c_uint,
ty: &'ll llvm::Metadata,
flags: DIFlags,
value: Option<&'ll llvm::Value>,
align: Align,
) -> &'ll llvm::Metadata {
unsafe {
llvm::LLVMDIBuilderCreateStaticMemberType(
DIB(cx),
scope,
name.as_ptr(),
name.len(),
file,
line_number,
ty,
flags,
value,
align.bits() as c_uint,
)
}
}
91 changes: 47 additions & 44 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc_target::spec::SymbolVisibility;

use super::RustString;
use super::debuginfo::{
DIArray, DIBasicType, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags,
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags,
DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram, DISubrange,
DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind, DebugNameTableKind,
};
Expand Down Expand Up @@ -1943,6 +1943,52 @@ unsafe extern "C" {
UniqueId: *const c_uchar, // See "PTR_LEN_STR".
UniqueIdLen: size_t,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateMemberType<'ll>(
Builder: &DIBuilder<'ll>,
Scope: &'ll Metadata,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
File: &'ll Metadata,
LineNo: c_uint,
SizeInBits: u64,
AlignInBits: u32,
OffsetInBits: u64,
Flags: DIFlags,
Ty: &'ll Metadata,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateStaticMemberType<'ll>(
Builder: &DIBuilder<'ll>,
Scope: &'ll Metadata,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
File: &'ll Metadata,
LineNumber: c_uint,
Type: &'ll Metadata,
Flags: DIFlags,
ConstantVal: Option<&'ll Value>,
AlignInBits: u32,
) -> &'ll Metadata;

/// Creates a "qualified type" in the C/C++ sense, by adding modifiers
/// like `const` or `volatile`.
pub(crate) fn LLVMDIBuilderCreateQualifiedType<'ll>(
Builder: &DIBuilder<'ll>,
Tag: c_uint, // (DWARF tag, e.g. `DW_TAG_const_type`)
Type: &'ll Metadata,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateTypedef<'ll>(
Builder: &DIBuilder<'ll>,
Type: &'ll Metadata,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
File: &'ll Metadata,
LineNo: c_uint,
Scope: Option<&'ll Metadata>,
AlignInBits: u32, // (optional; default is 0)
) -> &'ll Metadata;
}

#[link(name = "llvm-wrapper", kind = "static")]
Expand Down Expand Up @@ -2278,30 +2324,6 @@ unsafe extern "C" {
TParam: &'a DIArray,
) -> &'a DISubprogram;

pub(crate) fn LLVMRustDIBuilderCreateTypedef<'a>(
Builder: &DIBuilder<'a>,
Type: &'a DIBasicType,
Name: *const c_char,
NameLen: size_t,
File: &'a DIFile,
LineNo: c_uint,
Scope: Option<&'a DIScope>,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateMemberType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIDescriptor,
Name: *const c_char,
NameLen: size_t,
File: &'a DIFile,
LineNo: c_uint,
SizeInBits: u64,
AlignInBits: u32,
OffsetInBits: u64,
Flags: DIFlags,
Ty: &'a DIType,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
Expand All @@ -2317,25 +2339,6 @@ unsafe extern "C" {
Ty: &'a DIType,
) -> &'a DIType;

pub(crate) fn LLVMRustDIBuilderCreateStaticMemberType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIDescriptor,
Name: *const c_char,
NameLen: size_t,
File: &'a DIFile,
LineNo: c_uint,
Ty: &'a DIType,
Flags: DIFlags,
val: Option<&'a Value>,
AlignInBits: u32,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateQualifiedType<'a>(
Builder: &DIBuilder<'a>,
Tag: c_uint,
Type: &'a DIType,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateStaticVariable<'a>(
Builder: &DIBuilder<'a>,
Context: Option<&'a DIScope>,
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
(&ty::Array(_, len), &ty::Slice(_)) => cx.const_usize(
len.try_to_target_usize(cx.tcx()).expect("expected monomorphic const in codegen"),
),
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
if src_dyn_kind == target_dyn_kind =>
{
(&ty::Dynamic(data_a, _), &ty::Dynamic(data_b, _)) => {
let old_info =
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
let b_principal_def_id = data_b.principal_def_id();
Expand Down Expand Up @@ -208,7 +206,7 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
old_info
}
}
(_, ty::Dynamic(data, _, _)) => meth::get_vtable(
(_, ty::Dynamic(data, _)) => meth::get_vtable(
cx,
source,
data.principal()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn dyn_trait_in_self<'tcx>(
) -> Option<ty::ExistentialTraitRef<'tcx>> {
for arg in ty.peel_refs().walk() {
if let GenericArgKind::Type(ty) = arg.kind()
&& let ty::Dynamic(data, _, _) = ty.kind()
&& let ty::Dynamic(data, _) = ty.kind()
{
// FIXME(arbitrary_self_types): This is likely broken for receivers which
// have a "non-self" trait objects as a generic argument.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let (maybe_null, drop_fn, fn_abi, drop_instance) = match ty.kind() {
// FIXME(eddyb) perhaps move some of this logic into
// `Instance::resolve_drop_in_place`?
ty::Dynamic(_, _, ty::Dyn) => {
ty::Dynamic(_, _) => {
// IN THIS ARM, WE HAVE:
// ty = *mut (dyn Trait)
// which is: exists<T> ( *mut T, Vtable<T: Trait> )
Expand Down
Loading
Loading