Skip to content

Commit 6a9f1c0

Browse files
committed
Revert "Deduplicate template parameter creation"
This reverts commit 6adc2c1.
1 parent b956ce7 commit 6a9f1c0

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -1291,31 +1291,21 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
12911291
ty: Ty<'tcx>,
12921292
) -> SmallVec<Option<&'ll DIType>> {
12931293
if let ty::Adt(def, args) = *ty.kind() {
1294-
let generics = cx.tcx.generics_of(def.did());
1295-
return get_template_parameters(cx, generics, args);
1296-
}
1297-
1298-
return smallvec![];
1299-
}
1300-
1301-
pub(super) fn get_template_parameters<'ll, 'tcx>(
1302-
cx: &CodegenCx<'ll, 'tcx>,
1303-
generics: &ty::Generics,
1304-
args: ty::GenericArgsRef<'tcx>,
1305-
) -> SmallVec<Option<&'ll DIType>> {
1306-
if args.types().next().is_some() {
1307-
let names = get_parameter_names(cx, generics);
1308-
let template_params: SmallVec<_> = iter::zip(args, names)
1309-
.filter_map(|(kind, name)| {
1310-
kind.as_type().map(|ty| {
1311-
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
1312-
let actual_type_di_node = type_di_node(cx, actual_type);
1313-
Some(cx.create_template_type_parameter(name.as_str(), actual_type_di_node))
1294+
if args.types().next().is_some() {
1295+
let generics = cx.tcx.generics_of(def.did());
1296+
let names = get_parameter_names(cx, generics);
1297+
let template_params: SmallVec<_> = iter::zip(args, names)
1298+
.filter_map(|(kind, name)| {
1299+
kind.as_type().map(|ty| {
1300+
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
1301+
let actual_type_di_node = type_di_node(cx, actual_type);
1302+
Some(cx.create_template_type_parameter(name.as_str(), actual_type_di_node))
1303+
})
13141304
})
1315-
})
1316-
.collect();
1305+
.collect();
13171306

1318-
return template_params;
1307+
return template_params;
1308+
}
13191309
}
13201310

13211311
return smallvec![];

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>(
363363

364364
state_specific_fields.into_iter().chain(common_fields).collect()
365365
},
366-
// FIXME: this is a no-op. `build_generic_type_param_di_nodes` only works for Adts.
367366
|cx| build_generic_type_param_di_nodes(cx, coroutine_type_and_layout.ty),
368367
)
369368
.di_node

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+32-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
use std::cell::{OnceCell, RefCell};
44
use std::ops::Range;
5-
use std::ptr;
65
use std::sync::Arc;
6+
use std::{iter, ptr};
77

88
use libc::c_uint;
99
use rustc_abi::Size;
@@ -487,10 +487,40 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
487487
generics: &ty::Generics,
488488
args: GenericArgsRef<'tcx>,
489489
) -> &'ll DIArray {
490-
let template_params = metadata::get_template_parameters(cx, generics, args);
490+
if args.types().next().is_none() {
491+
return create_DIArray(DIB(cx), &[]);
492+
}
493+
494+
// Again, only create type information if full debuginfo is enabled
495+
let template_params: Vec<_> = if cx.sess().opts.debuginfo == DebugInfo::Full {
496+
let names = get_parameter_names(cx, generics);
497+
iter::zip(args, names)
498+
.filter_map(|(kind, name)| {
499+
kind.as_type().map(|ty| {
500+
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
501+
let actual_type_metadata = type_di_node(cx, actual_type);
502+
Some(cx.create_template_type_parameter(
503+
name.as_str(),
504+
actual_type_metadata,
505+
))
506+
})
507+
})
508+
.collect()
509+
} else {
510+
vec![]
511+
};
512+
491513
create_DIArray(DIB(cx), &template_params)
492514
}
493515

516+
fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
517+
let mut names = generics.parent.map_or_else(Vec::new, |def_id| {
518+
get_parameter_names(cx, cx.tcx.generics_of(def_id))
519+
});
520+
names.extend(generics.own_params.iter().map(|param| param.name));
521+
names
522+
}
523+
494524
/// Returns a scope, plus `true` if that's a type scope for "class" methods,
495525
/// otherwise `false` for plain namespace scopes.
496526
fn get_containing_scope<'ll, 'tcx>(

0 commit comments

Comments
 (0)