Skip to content
/ rust Public
forked from rust-lang/rust

Commit cacb9ee

Browse files
committed
Auto merge of rust-lang#139878 - petrochenkov:revllvmclean2, r=compiler-errors
Revert "Deduplicate template parameter creation" This reverts commit 6adc2c1. More precise subset of rust-lang#139874.
2 parents 38c560a + 38f7060 commit cacb9ee

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
@@ -1315,31 +1315,21 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
13151315
ty: Ty<'tcx>,
13161316
) -> SmallVec<Option<&'ll DIType>> {
13171317
if let ty::Adt(def, args) = *ty.kind() {
1318-
let generics = cx.tcx.generics_of(def.did());
1319-
return get_template_parameters(cx, generics, args);
1320-
}
1321-
1322-
return smallvec![];
1323-
}
1324-
1325-
pub(super) fn get_template_parameters<'ll, 'tcx>(
1326-
cx: &CodegenCx<'ll, 'tcx>,
1327-
generics: &ty::Generics,
1328-
args: ty::GenericArgsRef<'tcx>,
1329-
) -> SmallVec<Option<&'ll DIType>> {
1330-
if args.types().next().is_some() {
1331-
let names = get_parameter_names(cx, generics);
1332-
let template_params: SmallVec<_> = iter::zip(args, names)
1333-
.filter_map(|(kind, name)| {
1334-
kind.as_type().map(|ty| {
1335-
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
1336-
let actual_type_di_node = type_di_node(cx, actual_type);
1337-
Some(cx.create_template_type_parameter(name.as_str(), actual_type_di_node))
1318+
if args.types().next().is_some() {
1319+
let generics = cx.tcx.generics_of(def.did());
1320+
let names = get_parameter_names(cx, generics);
1321+
let template_params: SmallVec<_> = iter::zip(args, names)
1322+
.filter_map(|(kind, name)| {
1323+
kind.as_type().map(|ty| {
1324+
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
1325+
let actual_type_di_node = type_di_node(cx, actual_type);
1326+
Some(cx.create_template_type_parameter(name.as_str(), actual_type_di_node))
1327+
})
13381328
})
1339-
})
1340-
.collect();
1329+
.collect();
13411330

1342-
return template_params;
1331+
return template_params;
1332+
}
13431333
}
13441334

13451335
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 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)