Skip to content

Commit 19e8495

Browse files
committed
debuginfo: add type metadata for params
This commit adds type metadata for generic parameters (that arise from polymorphization). Generic parameter metadata is considered zero-sized and named after the generic parameter. Signed-off-by: David Wood <[email protected]>
1 parent 5bf2c7d commit 19e8495

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp
700700
prepare_tuple_metadata(cx, t, &tys, unique_type_id, usage_site_span, NO_SCOPE_METADATA)
701701
.finalize(cx)
702702
}
703+
// Type parameters from polymorphized functions.
704+
ty::Param(_) => MetadataCreationResult::new(param_type_metadata(cx, t), false),
703705
_ => bug!("debuginfo: unexpected type in type_metadata: {:?}", t),
704706
};
705707

@@ -955,6 +957,20 @@ fn pointer_type_metadata(
955957
}
956958
}
957959

960+
fn param_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
961+
debug!("param_type_metadata: {:?}", t);
962+
let name = format!("{:?}", t);
963+
return unsafe {
964+
llvm::LLVMRustDIBuilderCreateBasicType(
965+
DIB(cx),
966+
name.as_ptr().cast(),
967+
name.len(),
968+
Size::ZERO.bits(),
969+
DW_ATE_unsigned,
970+
)
971+
};
972+
}
973+
958974
pub fn compile_unit_metadata(
959975
tcx: TyCtxt<'_>,
960976
codegen_unit_name: &str,

src/librustc_codegen_ssa/debuginfo/type_names.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,17 @@ pub fn push_debuginfo_type_name<'tcx>(
205205
tcx.def_key(def_id).disambiguated_data.disambiguator
206206
));
207207
}
208+
// Type parameters from polymorphized functions.
209+
ty::Param(_) => {
210+
output.push_str(&format!("{:?}", t));
211+
}
208212
ty::Error(_)
209213
| ty::Infer(_)
210214
| ty::Placeholder(..)
211215
| ty::Projection(..)
212216
| ty::Bound(..)
213217
| ty::Opaque(..)
214-
| ty::GeneratorWitness(..)
215-
| ty::Param(_) => {
218+
| ty::GeneratorWitness(..) => {
216219
bug!(
217220
"debuginfo: Trying to create type name for \
218221
unexpected type: {:?}",

0 commit comments

Comments
 (0)