Skip to content

Commit 896425a

Browse files
authored
Unrolled build for rust-lang#133625
Rollup merge of rust-lang#133625 - RalfJung:custom-mir-debug-info, r=compiler-errors custom MIR: add doc comment for debuginfo This is a revival of rust-lang#117015
2 parents e48ddd8 + 6e449e1 commit 896425a

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

Diff for: library/core/src/intrinsics/mir.rs

+33
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,39 @@
249249
//! `Call(ret_val = function(arg1, arg2, ...), ReturnTo(next_block), UnwindContinue())`.
250250
//! - [`TailCall`] does not have a return destination or next block, so its syntax is just
251251
//! `TailCall(function(arg1, arg2, ...))`.
252+
//!
253+
//! #### Debuginfo
254+
//!
255+
//! Debuginfo associates source code variable names (of variables that may not exist any more) with
256+
//! MIR expressions that indicate where the value of that variable is stored. The syntax to do so
257+
//! is:
258+
//! ```text
259+
//! debug source_var_name => expression;
260+
//! ```
261+
//! Both places and constants are supported in the `expression`.
262+
//!
263+
//! ```rust
264+
//! #![allow(internal_features)]
265+
//! #![feature(core_intrinsics, custom_mir)]
266+
//!
267+
//! use core::intrinsics::mir::*;
268+
//!
269+
//! #[custom_mir(dialect = "built")]
270+
//! fn debuginfo(arg: Option<&i32>) {
271+
//! mir!(
272+
//! // Debuginfo for a source variable `plain_local` that just duplicates `arg`.
273+
//! debug plain_local => arg;
274+
//! // Debuginfo for a source variable `projection` that can be computed by dereferencing
275+
//! // a field of `arg`.
276+
//! debug projection => *Field::<&i32>(Variant(arg, 1), 0);
277+
//! // Debuginfo for a source variable `constant` that always holds the value `5`.
278+
//! debug constant => 5_usize;
279+
//! {
280+
//! Return()
281+
//! }
282+
//! )
283+
//! }
284+
//! ```
252285
253286
#![unstable(
254287
feature = "custom_mir",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// MIR for `constant` after built
2+
3+
fn constant() -> () {
4+
debug scalar => const 5_usize;
5+
let mut _0: ();
6+
7+
bb0: {
8+
return;
9+
}
10+
}

Diff for: tests/mir-opt/building/custom/debuginfo.numbered.built.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
fn numbered(_1: (u32, i32)) -> () {
44
debug first => (_1.0: u32);
5-
debug second => (_1.0: u32);
5+
debug second => (_1.1: i32);
66
let mut _0: ();
77

88
bb0: {

Diff for: tests/mir-opt/building/custom/debuginfo.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
#![feature(custom_mir, core_intrinsics)]
32

43
extern crate core;
@@ -7,6 +6,8 @@ use core::intrinsics::mir::*;
76
// EMIT_MIR debuginfo.pointee.built.after.mir
87
#[custom_mir(dialect = "built")]
98
fn pointee(opt: &mut Option<i32>) {
9+
// CHECK-LABEL: fn pointee(
10+
// CHECK: debug foo => (((*_1) as variant#1).0: i32);
1011
mir! {
1112
debug foo => Field::<i32>(Variant(*opt, 1), 0);
1213
{
@@ -18,9 +19,12 @@ fn pointee(opt: &mut Option<i32>) {
1819
// EMIT_MIR debuginfo.numbered.built.after.mir
1920
#[custom_mir(dialect = "analysis", phase = "post-cleanup")]
2021
fn numbered(i: (u32, i32)) {
22+
// CHECK-LABEL: fn numbered(
23+
// CHECK: debug first => (_1.0: u32);
24+
// CHECK: debug second => (_1.1: i32);
2125
mir! {
2226
debug first => i.0;
23-
debug second => i.0;
27+
debug second => i.1;
2428
{
2529
Return()
2630
}
@@ -34,6 +38,8 @@ struct S {
3438
// EMIT_MIR debuginfo.structured.built.after.mir
3539
#[custom_mir(dialect = "analysis", phase = "post-cleanup")]
3640
fn structured(i: S) {
41+
// CHECK-LABEL: fn structured(
42+
// CHECK: debug x => (_1.0: f32);
3743
mir! {
3844
debug x => i.x;
3945
{
@@ -45,6 +51,8 @@ fn structured(i: S) {
4551
// EMIT_MIR debuginfo.variant.built.after.mir
4652
#[custom_mir(dialect = "built")]
4753
fn variant(opt: Option<i32>) {
54+
// CHECK-LABEL: fn variant(
55+
// CHECK: debug inner => ((_1 as variant#1).0: i32);
4856
mir! {
4957
debug inner => Field::<i32>(Variant(opt, 1), 0);
5058
{
@@ -56,6 +64,9 @@ fn variant(opt: Option<i32>) {
5664
// EMIT_MIR debuginfo.variant_deref.built.after.mir
5765
#[custom_mir(dialect = "built")]
5866
fn variant_deref(opt: Option<&i32>) {
67+
// CHECK-LABEL: fn variant_deref(
68+
// CHECK: debug pointer => ((_1 as variant#1).0: &i32);
69+
// CHECK: debug deref => (*((_1 as variant#1).0: &i32));
5970
mir! {
6071
debug pointer => Field::<&i32>(Variant(opt, 1), 0);
6172
debug deref => *Field::<&i32>(Variant(opt, 1), 0);
@@ -65,10 +76,24 @@ fn variant_deref(opt: Option<&i32>) {
6576
}
6677
}
6778

79+
// EMIT_MIR debuginfo.constant.built.after.mir
80+
#[custom_mir(dialect = "built")]
81+
fn constant() {
82+
// CHECK-LABEL: fn constant(
83+
// CHECK: debug scalar => const 5_usize;
84+
mir!(
85+
debug scalar => 5_usize;
86+
{
87+
Return()
88+
}
89+
)
90+
}
91+
6892
fn main() {
6993
numbered((5, 6));
7094
structured(S { x: 5. });
7195
variant(Some(5));
7296
variant_deref(Some(&5));
7397
pointee(&mut Some(5));
98+
constant();
7499
}

0 commit comments

Comments
 (0)