rust/compiler
bors 3139ff09e9 Auto merge of #128861 - khuey:mir-inlining-parameters-debuginfo, r=wesleywiser
Rework MIR inlining debuginfo so function parameters show up in debuggers.

Line numbers of multiply-inlined functions were fixed in #114643 by using a single DISubprogram. That, however, triggered assertions because parameters weren't deduplicated. The "solution" to that in #115417 was to insert a DILexicalScope below the DISubprogram and parent all of the parameters to that scope. That fixed the assertion, but debuggers (including gdb and lldb) don't recognize variables that are not parented to the subprogram itself as parameters, even if they are emitted with DW_TAG_formal_parameter.

Consider the program:

```rust
use std::env;

#[inline(always)]
fn square(n: i32) -> i32 {
    n * n
}

#[inline(never)]
fn square_no_inline(n: i32) -> i32 {
    n * n
}

fn main() {
    let x = square(env::vars().count() as i32);
    let y = square_no_inline(env::vars().count() as i32);
    println!("{x} == {y}");
}
```

When making a release build with debug=2 and rustc 1.82.0-nightly (8b3870784 2024-08-07)

```
(gdb) r
Starting program: /ephemeral/tmp/target/release/tmp [Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, tmp::square () at src/main.rs:5
5	    n * n
(gdb) info args
No arguments.
(gdb) info locals
n = 31
(gdb) c
Continuing.

Breakpoint 2, tmp::square_no_inline (n=31) at src/main.rs:10
10	    n * n
(gdb) info args
n = 31
(gdb) info locals
No locals.
```

This issue is particularly annoying because it removes arguments from stack traces.

The DWARF for the inlined function looks like this:

```
< 2><0x00002132 GOFF=0x00002132>      DW_TAG_subprogram
                                        DW_AT_linkage_name          _ZN3tmp6square17hc507052ff3d2a488E
                                        DW_AT_name                  square
                                        DW_AT_decl_file             0x0000000f /ephemeral/tmp/src/main.rs
                                        DW_AT_decl_line             0x00000004
                                        DW_AT_type                  0x00001a56<.debug_info+0x00001a56>
                                        DW_AT_inline                DW_INL_inlined
< 3><0x00002142 GOFF=0x00002142>        DW_TAG_lexical_block
< 4><0x00002143 GOFF=0x00002143>          DW_TAG_formal_parameter
                                            DW_AT_name                  n
                                            DW_AT_decl_file             0x0000000f /ephemeral/tmp/src/main.rs
                                            DW_AT_decl_line             0x00000004
                                            DW_AT_type                  0x00001a56<.debug_info+0x00001a56>
< 4><0x0000214e GOFF=0x0000214e>          DW_TAG_null
< 3><0x0000214f GOFF=0x0000214f>        DW_TAG_null
```

That DW_TAG_lexical_block inhibits every debugger I've tested from recognizing 'n' as a parameter.

This patch removes the additional lexical scope. Parameters can be easily deduplicated by a tuple of their scope and the argument index, at the trivial cost of taking a Hash + Eq bound on DIScope.
2024-08-15 11:42:15 +00:00
..
rustc Link std statically in rustc_driver 2024-08-11 04:16:53 +02:00
rustc_abi interpret: simplify pointer arithmetic logic 2024-08-01 14:25:19 +02:00
rustc_arena Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_ast Use more slice patterns inside the compiler 2024-08-07 13:37:52 +02:00
rustc_ast_ir Use dep: for crate dependencies 2024-07-15 12:40:10 -04:00
rustc_ast_lowering stabilize asm_const 2024-08-13 23:18:31 +02:00
rustc_ast_passes Rollup merge of #127921 - spastorino:stabilize-unsafe-extern-blocks, r=compiler-errors 2024-08-03 20:51:51 +02:00
rustc_ast_pretty Use more slice patterns inside the compiler 2024-08-07 13:37:52 +02:00
rustc_attr Rollup merge of #128886 - GrigorenkoPV:untranslatable-diagnostic, r=nnethercote 2024-08-12 17:09:17 +02:00
rustc_baked_icu_data
rustc_borrowck Rollup merge of #129059 - compiler-errors:subtyping-correct-type, r=lcnr 2024-08-14 21:43:08 +08:00
rustc_builtin_macros Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errors 2024-08-11 07:51:51 +02:00
rustc_codegen_cranelift Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors 2024-08-14 00:56:53 +00:00
rustc_codegen_gcc Rollup merge of #128570 - folkertdev:stabilize-asm-const, r=Amanieu 2024-08-14 21:43:07 +08:00
rustc_codegen_llvm Auto merge of #128861 - khuey:mir-inlining-parameters-debuginfo, r=wesleywiser 2024-08-15 11:42:15 +00:00
rustc_codegen_ssa Auto merge of #128861 - khuey:mir-inlining-parameters-debuginfo, r=wesleywiser 2024-08-15 11:42:15 +00:00
rustc_const_eval Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors 2024-08-14 00:56:53 +00:00
rustc_data_structures Update indexmap and use IndexMap::append 2024-08-13 16:16:57 -07:00
rustc_driver
rustc_driver_impl Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errors 2024-08-11 07:51:51 +02:00
rustc_error_codes Update E0517 message to reflect RFC 2195. 2024-08-07 23:11:30 -05:00
rustc_error_messages Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_errors Add | to make the html doc of Level rendered correctly 2024-08-14 13:38:03 +08:00
rustc_expand Rollup merge of #128886 - GrigorenkoPV:untranslatable-diagnostic, r=nnethercote 2024-08-12 17:09:17 +02:00
rustc_feature Rollup merge of #128925 - dingxiangfei2009:smart-ptr-helper-attr, r=compiler-errors 2024-08-15 00:02:25 +02:00
rustc_fluent_macro Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_fs_util Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_graphviz Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_hir Rollup merge of #128377 - veera-sivarajan:fix-128249, r=davidtwco 2024-08-06 20:23:39 +02:00
rustc_hir_analysis Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors 2024-08-14 00:56:53 +00:00
rustc_hir_pretty Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_hir_typeck Rollup merge of #129059 - compiler-errors:subtyping-correct-type, r=lcnr 2024-08-14 21:43:08 +08:00
rustc_incremental Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_index Add and use IndexVec::append 2024-08-13 13:40:05 -07:00
rustc_index_macros
rustc_infer Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors 2024-08-14 00:56:53 +00:00
rustc_interface rustc_interface: remove a redundant #[allow(rustc::untranslatable_diagnostic)] 2024-08-10 14:32:56 +03:00
rustc_lexer Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_lint Auto merge of #129076 - matthiaskrgr:rollup-rg8mi2x, r=matthiaskrgr 2024-08-14 04:17:13 +00:00
rustc_lint_defs Disallow setting built-in cfgs via set the command-line 2024-08-07 14:08:34 +02:00
rustc_llvm Auto merge of #128371 - andjo403:rangeAttribute, r=nikic 2024-08-12 10:20:00 +00:00
rustc_log Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_macros Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_metadata Rollup merge of #128886 - GrigorenkoPV:untranslatable-diagnostic, r=nnethercote 2024-08-12 17:09:17 +02:00
rustc_middle Rollup merge of #128828 - lcnr:search-graph-11, r=compiler-errors 2024-08-14 21:43:07 +08:00
rustc_mir_build Auto merge of #129060 - matthiaskrgr:rollup-s72gpif, r=matthiaskrgr 2024-08-14 06:43:26 +00:00
rustc_mir_dataflow Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors 2024-08-14 00:56:53 +00:00
rustc_mir_transform Rollup merge of #129067 - cuviper:append, r=wesleywiser 2024-08-15 00:02:27 +02:00
rustc_monomorphize Rollup merge of #129067 - cuviper:append, r=wesleywiser 2024-08-15 00:02:27 +02:00
rustc_next_trait_solver Rollup merge of #128828 - lcnr:search-graph-11, r=compiler-errors 2024-08-14 21:43:07 +08:00
rustc_parse Rollup merge of #128994 - nnethercote:fix-Parser-look_ahead-more, r=compiler-errors 2024-08-12 17:09:20 +02:00
rustc_parse_format Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_passes Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors 2024-08-14 00:56:53 +00:00
rustc_pattern_analysis Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors 2024-08-14 00:56:53 +00:00
rustc_privacy Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_query_impl Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_query_system Use more slice patterns inside the compiler 2024-08-07 13:37:52 +02:00
rustc_resolve Rollup merge of #128875 - bvanjoi:cleanup-import-used, r=petrochenkov 2024-08-11 07:51:52 +02:00
rustc_sanitizers Shrink TyKind::FnPtr. 2024-08-09 14:33:25 +10:00
rustc_serialize Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_session Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errors 2024-08-11 07:51:51 +02:00
rustc_smir Shrink TyKind::FnPtr. 2024-08-09 14:33:25 +10:00
rustc_span #[deprecated_safe_2024]: Also use the // TODO: hint in the compiler error 2024-08-13 11:32:47 +02:00
rustc_symbol_mangling Shrink TyKind::FnPtr. 2024-08-09 14:33:25 +10:00
rustc_target Rollup merge of #127905 - BKPepe:powerpc-muslspe, r=wesleywiser 2024-08-15 00:02:24 +02:00
rustc_trait_selection Rollup merge of #128828 - lcnr:search-graph-11, r=compiler-errors 2024-08-14 21:43:07 +08:00
rustc_traits Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_transmute Update std and compiler 2024-08-10 12:07:17 +02:00
rustc_ty_utils Auto merge of #129076 - matthiaskrgr:rollup-rg8mi2x, r=matthiaskrgr 2024-08-14 04:17:13 +00:00
rustc_type_ir Rollup merge of #128828 - lcnr:search-graph-11, r=compiler-errors 2024-08-14 21:43:07 +08:00
rustc_type_ir_macros Reformat use declarations. 2024-07-29 08:26:52 +10:00
stable_mir Reformat use declarations. 2024-07-29 08:26:52 +10:00