Refactor type_map::stub parameters
Push span lookup into `type_map::stub` and pass the `DefId` instead of doing the lookup outside and passing in the location metadata.
This commit is contained in:
@@ -199,8 +199,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
|
||||
type_map::Stub::Union,
|
||||
unique_type_id,
|
||||
&enum_type_name,
|
||||
unknown_file_metadata(cx),
|
||||
UNKNOWN_LINE_NUMBER,
|
||||
Some(enum_adt_def.did()),
|
||||
cx.size_and_align_of(enum_type),
|
||||
NO_SCOPE_METADATA,
|
||||
visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()),
|
||||
@@ -276,8 +275,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
|
||||
type_map::Stub::Union,
|
||||
unique_type_id,
|
||||
&coroutine_type_name,
|
||||
unknown_file_metadata(cx),
|
||||
UNKNOWN_LINE_NUMBER,
|
||||
None,
|
||||
size_and_align_of(coroutine_type_and_layout),
|
||||
NO_SCOPE_METADATA,
|
||||
DIFlags::FlagZero,
|
||||
@@ -332,6 +330,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>(
|
||||
variant_index,
|
||||
Cow::from(enum_adt_def.variant(variant_index).name.as_str()),
|
||||
)),
|
||||
enum_adt_def.did(),
|
||||
);
|
||||
|
||||
let variant_struct_type_wrapper_di_node = build_variant_struct_wrapper_type_di_node(
|
||||
@@ -394,6 +393,7 @@ fn build_union_fields_for_enum<'ll, 'tcx>(
|
||||
let variant_name = Cow::from(enum_adt_def.variant(variant_index).name.as_str());
|
||||
(variant_index, variant_name)
|
||||
}),
|
||||
enum_adt_def.did(),
|
||||
);
|
||||
let visibility_flags = visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did());
|
||||
|
||||
@@ -451,6 +451,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>(
|
||||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
containing_scope: &'ll DIType,
|
||||
variants: impl Iterator<Item = (VariantIdx, Cow<'tcx, str>)>,
|
||||
enum_def_id: rustc_span::def_id::DefId,
|
||||
) -> &'ll DIType {
|
||||
// Create an enumerator for each variant.
|
||||
super::build_enumeration_type_di_node(
|
||||
@@ -458,6 +459,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>(
|
||||
"VariantNames",
|
||||
variant_names_enum_base_type(cx),
|
||||
variants.map(|(variant_index, variant_name)| (variant_name, variant_index.as_u32().into())),
|
||||
enum_def_id,
|
||||
containing_scope,
|
||||
)
|
||||
}
|
||||
@@ -485,8 +487,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
|
||||
variant_index,
|
||||
),
|
||||
&variant_struct_wrapper_type_name(variant_index),
|
||||
unknown_file_metadata(cx),
|
||||
UNKNOWN_LINE_NUMBER,
|
||||
None,
|
||||
// NOTE: We use size and align of enum_type, not from variant_layout:
|
||||
size_and_align_of(enum_or_coroutine_type_and_layout),
|
||||
Some(enum_or_coroutine_type_di_node),
|
||||
@@ -690,6 +691,7 @@ fn build_union_fields_for_direct_tag_coroutine<'ll, 'tcx>(
|
||||
variant_range
|
||||
.clone()
|
||||
.map(|variant_index| (variant_index, CoroutineArgs::variant_name(variant_index))),
|
||||
coroutine_def_id,
|
||||
);
|
||||
|
||||
let discriminants: IndexVec<VariantIdx, DiscrResult> = {
|
||||
|
||||
@@ -16,8 +16,8 @@ use super::{SmallVec, size_and_align_of};
|
||||
use crate::common::{AsCCharPtr, CodegenCx};
|
||||
use crate::debuginfo::metadata::type_map::{self, Stub};
|
||||
use crate::debuginfo::metadata::{
|
||||
UNKNOWN_LINE_NUMBER, build_field_di_node, build_generic_type_param_di_nodes, type_di_node,
|
||||
unknown_file_metadata,
|
||||
UNKNOWN_LINE_NUMBER, build_field_di_node, build_generic_type_param_di_nodes,
|
||||
file_metadata_from_def_id, type_di_node, unknown_file_metadata,
|
||||
};
|
||||
use crate::debuginfo::utils::{DIB, create_DIArray, get_namespace_for_item};
|
||||
use crate::llvm::debuginfo::{DIFlags, DIType};
|
||||
@@ -77,6 +77,7 @@ fn build_c_style_enum_di_node<'ll, 'tcx>(
|
||||
let name = Cow::from(enum_adt_def.variant(variant_index).name.as_str());
|
||||
(name, discr.val)
|
||||
}),
|
||||
enum_adt_def.did(),
|
||||
containing_scope,
|
||||
),
|
||||
already_stored_in_typemap: false,
|
||||
@@ -92,6 +93,7 @@ fn build_enumeration_type_di_node<'ll, 'tcx>(
|
||||
type_name: &str,
|
||||
base_type: Ty<'tcx>,
|
||||
enumerators: impl Iterator<Item = (Cow<'tcx, str>, u128)>,
|
||||
def_id: rustc_span::def_id::DefId,
|
||||
containing_scope: &'ll DIType,
|
||||
) -> &'ll DIType {
|
||||
let is_unsigned = match base_type.kind() {
|
||||
@@ -115,14 +117,16 @@ fn build_enumeration_type_di_node<'ll, 'tcx>(
|
||||
})
|
||||
.collect();
|
||||
|
||||
let (file_metadata, line_number) = file_metadata_from_def_id(cx, Some(def_id));
|
||||
|
||||
unsafe {
|
||||
llvm::LLVMRustDIBuilderCreateEnumerationType(
|
||||
DIB(cx),
|
||||
containing_scope,
|
||||
type_name.as_c_char_ptr(),
|
||||
type_name.len(),
|
||||
unknown_file_metadata(cx),
|
||||
UNKNOWN_LINE_NUMBER,
|
||||
file_metadata,
|
||||
line_number,
|
||||
size.bits(),
|
||||
align.bits() as u32,
|
||||
create_DIArray(DIB(cx), &enumerator_di_nodes[..]),
|
||||
@@ -204,8 +208,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>(
|
||||
variant_index,
|
||||
),
|
||||
variant_def.name.as_str(),
|
||||
unknown_file_metadata(cx),
|
||||
UNKNOWN_LINE_NUMBER,
|
||||
None,
|
||||
// NOTE: We use size and align of enum_type, not from variant_layout:
|
||||
size_and_align_of(enum_type_and_layout),
|
||||
Some(enum_type_di_node),
|
||||
@@ -288,8 +291,7 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>(
|
||||
Stub::Struct,
|
||||
unique_type_id,
|
||||
&variant_name,
|
||||
unknown_file_metadata(cx),
|
||||
UNKNOWN_LINE_NUMBER,
|
||||
None,
|
||||
size_and_align_of(coroutine_type_and_layout),
|
||||
Some(coroutine_type_di_node),
|
||||
DIFlags::FlagZero,
|
||||
@@ -355,11 +357,7 @@ enum DiscrResult {
|
||||
|
||||
impl DiscrResult {
|
||||
fn opt_single_val(&self) -> Option<u128> {
|
||||
if let Self::Value(d) = *self {
|
||||
Some(d)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if let Self::Value(d) = *self { Some(d) } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,8 +62,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
|
||||
Stub::Struct,
|
||||
unique_type_id,
|
||||
&enum_type_name,
|
||||
unknown_file_metadata(cx),
|
||||
UNKNOWN_LINE_NUMBER,
|
||||
Some(enum_adt_def.did()),
|
||||
size_and_align_of(enum_type_and_layout),
|
||||
Some(containing_scope),
|
||||
visibility_flags,
|
||||
@@ -143,8 +142,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
|
||||
Stub::Struct,
|
||||
unique_type_id,
|
||||
&coroutine_type_name,
|
||||
unknown_file_metadata(cx),
|
||||
UNKNOWN_LINE_NUMBER,
|
||||
None,
|
||||
size_and_align_of(coroutine_type_and_layout),
|
||||
Some(containing_scope),
|
||||
DIFlags::FlagZero,
|
||||
|
||||
@@ -8,10 +8,10 @@ use rustc_macros::HashStable;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
|
||||
|
||||
use super::{SmallVec, UNKNOWN_LINE_NUMBER, unknown_file_metadata};
|
||||
use super::{SmallVec, UNKNOWN_LINE_NUMBER, file_metadata, unknown_file_metadata};
|
||||
use crate::common::{AsCCharPtr, CodegenCx};
|
||||
use crate::debuginfo::utils::{DIB, create_DIArray, debug_context};
|
||||
use crate::llvm::debuginfo::{DIFile, DIFlags, DIScope, DIType};
|
||||
use crate::llvm::debuginfo::{DIFlags, DIScope, DIType};
|
||||
use crate::llvm::{self};
|
||||
|
||||
mod private {
|
||||
@@ -174,8 +174,7 @@ pub(super) fn stub<'ll, 'tcx>(
|
||||
kind: Stub<'ll>,
|
||||
unique_type_id: UniqueTypeId<'tcx>,
|
||||
name: &str,
|
||||
file_metadata: &'ll DIFile,
|
||||
line_number: u32,
|
||||
def_id: Option<rustc_span::def_id::DefId>,
|
||||
(size, align): (Size, Align),
|
||||
containing_scope: Option<&'ll DIScope>,
|
||||
flags: DIFlags,
|
||||
@@ -183,6 +182,18 @@ pub(super) fn stub<'ll, 'tcx>(
|
||||
let empty_array = create_DIArray(DIB(cx), &[]);
|
||||
let unique_type_id_str = unique_type_id.generate_unique_id_string(cx.tcx);
|
||||
|
||||
let (file_metadata, line_number) = if let Some(def_id) = def_id {
|
||||
let span = cx.tcx.def_span(def_id);
|
||||
if !span.is_dummy() {
|
||||
let loc = cx.lookup_debug_loc(span.lo());
|
||||
(file_metadata(cx, &loc.file), loc.line)
|
||||
} else {
|
||||
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
|
||||
}
|
||||
} else {
|
||||
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
|
||||
};
|
||||
|
||||
let metadata = match kind {
|
||||
Stub::Struct | Stub::VTableTy { .. } => {
|
||||
let vtable_holder = match kind {
|
||||
|
||||
Reference in New Issue
Block a user