Skip to content

Commit 4782bbc

Browse files
petrochenkovcuviper
authored andcommitted
Revert "Deduplicate template parameter creation"
This reverts commit 6adc2c1. (cherry picked from commit 38f7060)
1 parent d1cd5ee commit 4782bbc

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,31 +1314,21 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
13141314
ty: Ty<'tcx>,
13151315
) -> SmallVec<Option<&'ll DIType>> {
13161316
if let ty::Adt(def, args) = *ty.kind() {
1317-
let generics = cx.tcx.generics_of(def.did());
1318-
return get_template_parameters(cx, generics, args);
1319-
}
1320-
1321-
return smallvec![];
1322-
}
1323-
1324-
pub(super) fn get_template_parameters<'ll, 'tcx>(
1325-
cx: &CodegenCx<'ll, 'tcx>,
1326-
generics: &ty::Generics,
1327-
args: ty::GenericArgsRef<'tcx>,
1328-
) -> SmallVec<Option<&'ll DIType>> {
1329-
if args.types().next().is_some() {
1330-
let names = get_parameter_names(cx, generics);
1331-
let template_params: SmallVec<_> = iter::zip(args, names)
1332-
.filter_map(|(kind, name)| {
1333-
kind.as_type().map(|ty| {
1334-
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
1335-
let actual_type_di_node = type_di_node(cx, actual_type);
1336-
Some(cx.create_template_type_parameter(name.as_str(), actual_type_di_node))
1317+
if args.types().next().is_some() {
1318+
let generics = cx.tcx.generics_of(def.did());
1319+
let names = get_parameter_names(cx, generics);
1320+
let template_params: SmallVec<_> = iter::zip(args, names)
1321+
.filter_map(|(kind, name)| {
1322+
kind.as_type().map(|ty| {
1323+
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
1324+
let actual_type_di_node = type_di_node(cx, actual_type);
1325+
Some(cx.create_template_type_parameter(name.as_str(), actual_type_di_node))
1326+
})
13371327
})
1338-
})
1339-
.collect();
1328+
.collect();
13401329

1341-
return template_params;
1330+
return template_params;
1331+
}
13421332
}
13431333

13441334
return smallvec![];

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

Lines changed: 0 additions & 1 deletion
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

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

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

0 commit comments

Comments
 (0)