Skip to content

Commit 558a592

Browse files
committed
Support debuginfo for assoc const bindings
1 parent 7f58193 commit 558a592

File tree

4 files changed

+71
-33
lines changed

4 files changed

+71
-33
lines changed

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl DebugContext {
242242
let generics = tcx.generics_of(enclosing_fn_def_id);
243243
let args = instance.args.truncate_to(tcx, generics);
244244

245-
type_names::push_generic_params(
245+
type_names::push_generic_args(
246246
tcx,
247247
tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), args),
248248
&mut name,

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
456456
let generics = tcx.generics_of(enclosing_fn_def_id);
457457
let args = instance.args.truncate_to(tcx, generics);
458458

459-
type_names::push_generic_params(
459+
type_names::push_generic_args(
460460
tcx,
461461
tcx.normalize_erasing_regions(self.typing_env(), args),
462462
&mut name,

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ fn push_debuginfo_type_name<'tcx>(
109109
ty_and_layout,
110110
&|output, visited| {
111111
push_item_name(tcx, def.did(), true, output);
112-
push_generic_params_internal(tcx, args, output, visited);
112+
push_generic_args_internal(tcx, args, output, visited);
113113
},
114114
output,
115115
visited,
116116
);
117117
} else {
118118
push_item_name(tcx, def.did(), qualified, output);
119-
push_generic_params_internal(tcx, args, output, visited);
119+
push_generic_args_internal(tcx, args, output, visited);
120120
}
121121
}
122122
ty::Tuple(component_types) => {
@@ -253,19 +253,18 @@ fn push_debuginfo_type_name<'tcx>(
253253
);
254254
push_item_name(tcx, principal.def_id, qualified, output);
255255
let principal_has_generic_params =
256-
push_generic_params_internal(tcx, principal.args, output, visited);
256+
push_generic_args_internal(tcx, principal.args, output, visited);
257257

258258
let projection_bounds: SmallVec<[_; 4]> = trait_data
259259
.projection_bounds()
260260
.map(|bound| {
261261
let ExistentialProjection { def_id: item_def_id, term, .. } =
262262
tcx.instantiate_bound_regions_with_erased(bound);
263-
// FIXME(mgca): allow for consts here
264-
(item_def_id, term.expect_type())
263+
(item_def_id, term)
265264
})
266265
.collect();
267266

268-
if projection_bounds.len() != 0 {
267+
if !projection_bounds.is_empty() {
269268
if principal_has_generic_params {
270269
// push_generic_params_internal() above added a `>` but we actually
271270
// want to add more items to that list, so remove that again...
@@ -279,17 +278,17 @@ fn push_debuginfo_type_name<'tcx>(
279278
output.push('<');
280279
}
281280

282-
for (item_def_id, ty) in projection_bounds {
281+
for (item_def_id, term) in projection_bounds {
283282
if cpp_like_debuginfo {
284283
output.push_str("assoc$<");
285284
push_item_name(tcx, item_def_id, false, output);
286285
push_arg_separator(cpp_like_debuginfo, output);
287-
push_debuginfo_type_name(tcx, ty, true, output, visited);
286+
push_debuginfo_term_name(tcx, term, true, output, visited);
288287
push_close_angle_bracket(cpp_like_debuginfo, output);
289288
} else {
290289
push_item_name(tcx, item_def_id, false, output);
291290
output.push('=');
292-
push_debuginfo_type_name(tcx, ty, true, output, visited);
291+
push_debuginfo_term_name(tcx, term, true, output, visited);
293292
}
294293
push_arg_separator(cpp_like_debuginfo, output);
295294
}
@@ -533,7 +532,7 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
533532
tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), trait_ref);
534533
push_item_name(tcx, trait_ref.def_id, true, &mut vtable_name);
535534
visited.clear();
536-
push_generic_params_internal(tcx, trait_ref.args, &mut vtable_name, &mut visited);
535+
push_generic_args_internal(tcx, trait_ref.args, &mut vtable_name, &mut visited);
537536
} else {
538537
vtable_name.push('_');
539538
}
@@ -631,7 +630,13 @@ fn push_unqualified_item_name(
631630
};
632631
}
633632

634-
fn push_generic_params_internal<'tcx>(
633+
pub fn push_generic_args<'tcx>(tcx: TyCtxt<'tcx>, args: GenericArgsRef<'tcx>, output: &mut String) {
634+
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
635+
let mut visited = FxHashSet::default();
636+
push_generic_args_internal(tcx, args, output, &mut visited);
637+
}
638+
639+
fn push_generic_args_internal<'tcx>(
635640
tcx: TyCtxt<'tcx>,
636641
args: GenericArgsRef<'tcx>,
637642
output: &mut String,
@@ -646,14 +651,10 @@ fn push_generic_params_internal<'tcx>(
646651

647652
output.push('<');
648653

649-
for type_parameter in args {
650-
match type_parameter {
651-
GenericArgKind::Type(type_parameter) => {
652-
push_debuginfo_type_name(tcx, type_parameter, true, output, visited);
653-
}
654-
GenericArgKind::Const(ct) => {
655-
push_const_param(tcx, ct, output);
656-
}
654+
for arg in args {
655+
match arg {
656+
GenericArgKind::Type(ty) => push_debuginfo_type_name(tcx, ty, true, output, visited),
657+
GenericArgKind::Const(ct) => push_debuginfo_const_name(tcx, ct, output),
657658
other => bug!("Unexpected non-erasable generic: {:?}", other),
658659
}
659660

@@ -665,7 +666,20 @@ fn push_generic_params_internal<'tcx>(
665666
true
666667
}
667668

668-
fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut String) {
669+
fn push_debuginfo_term_name<'tcx>(
670+
tcx: TyCtxt<'tcx>,
671+
term: ty::Term<'tcx>,
672+
qualified: bool,
673+
output: &mut String,
674+
visited: &mut FxHashSet<Ty<'tcx>>,
675+
) {
676+
match term.kind() {
677+
ty::TermKind::Ty(ty) => push_debuginfo_type_name(tcx, ty, qualified, output, visited),
678+
ty::TermKind::Const(ct) => push_debuginfo_const_name(tcx, ct, output),
679+
}
680+
}
681+
682+
fn push_debuginfo_const_name<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut String) {
669683
match ct.kind() {
670684
ty::ConstKind::Param(param) => {
671685
write!(output, "{}", param.name)
@@ -715,16 +729,6 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
715729
.unwrap();
716730
}
717731

718-
pub fn push_generic_params<'tcx>(
719-
tcx: TyCtxt<'tcx>,
720-
args: GenericArgsRef<'tcx>,
721-
output: &mut String,
722-
) {
723-
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
724-
let mut visited = FxHashSet::default();
725-
push_generic_params_internal(tcx, args, output, &mut visited);
726-
}
727-
728732
fn push_closure_or_coroutine_name<'tcx>(
729733
tcx: TyCtxt<'tcx>,
730734
def_id: DefId,
@@ -767,7 +771,7 @@ fn push_closure_or_coroutine_name<'tcx>(
767771
// FIXME(async_closures): This is probably not going to be correct w.r.t.
768772
// multiple coroutine flavors. Maybe truncate to (parent + 1)?
769773
let args = args.truncate_to(tcx, generics);
770-
push_generic_params_internal(tcx, args, output, visited);
774+
push_generic_args_internal(tcx, args, output, visited);
771775
}
772776

773777
fn push_close_angle_bracket(cpp_like_debuginfo: bool, output: &mut String) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@ compile-flags: -g
2+
//@ disable-gdb-pretty-printers
3+
//@ ignore-backends: gcc
4+
5+
//@ gdb-command:run
6+
//@ gdb-command:whatis local
7+
//@ gdb-check:type = &dyn associated_const_bindings::Trait<N=101>
8+
9+
//@ cdb-command: g
10+
//@ cdb-command:dv /t /n local
11+
//@ cdb-check:struct ref$<dyn$<associated_const_bindings::Trait<assoc$<N,101> > > > local = [...]
12+
13+
#![feature(min_generic_const_args)]
14+
#![expect(unused_variables, incomplete_features)]
15+
16+
trait Trait {
17+
#[type_const]
18+
const N: usize;
19+
}
20+
impl Trait for () {
21+
#[type_const]
22+
const N: usize = 101;
23+
}
24+
25+
fn main() {
26+
let local = &() as &dyn Trait<N = 101>;
27+
28+
zzz(); // #break
29+
}
30+
31+
#[inline(never)]
32+
fn zzz() {
33+
()
34+
}

0 commit comments

Comments
 (0)