Skip to content

Commit 1e7fe14

Browse files
authored
update thir output (rust-lang#1445)
1 parent 18fc34b commit 1e7fe14

File tree

1 file changed

+105
-56
lines changed

1 file changed

+105
-56
lines changed

src/thir.md

+105-56
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,18 @@ which is useful to keep peak memory in check. Having a THIR representation of
4747
all bodies of a crate in memory at the same time would be very heavy.
4848

4949
You can get a debug representation of the THIR by passing the `-Zunpretty=thir-tree` flag
50-
to `rustc`. Here is how a function with just the statement `let x = 1 + 2;` gets represented in
51-
THIR:
50+
to `rustc`.
51+
52+
To demonstrate, let's use the following example:
53+
54+
```rust
55+
fn main() {
56+
let x = 1 + 2;
57+
}
58+
```
59+
60+
Here is how that gets represented in THIR (as of <!-- date-check --> Aug 2022):
61+
5262
```rust,no_run
5363
Thir {
5464
// no match arms
@@ -57,65 +67,83 @@ Thir {
5767
// expression 0, a literal with a value of 1
5868
Expr {
5969
ty: i32,
60-
temp_lifetime: Some(Node(6)),
70+
temp_lifetime: Some(
71+
Node(1),
72+
),
6173
span: oneplustwo.rs:2:13: 2:14 (#0),
6274
kind: Literal {
63-
literal: Const {
64-
ty: i32,
65-
val: Value(Scalar(0x00000001)),
75+
lit: Spanned {
76+
node: Int(
77+
1,
78+
Unsuffixed,
79+
),
80+
span: oneplustwo.rs:2:13: 2:14 (#0),
6681
},
67-
user_ty: None,
68-
const_id: None,
82+
neg: false,
6983
},
7084
},
7185
// expression 1, scope surronding literal 1
7286
Expr {
7387
ty: i32,
74-
temp_lifetime: Some(Node(6)),
88+
temp_lifetime: Some(
89+
Node(1),
90+
),
7591
span: oneplustwo.rs:2:13: 2:14 (#0),
7692
kind: Scope {
77-
region_scope: Node(1),
78-
lint_level: Explicit(HirId {
79-
owner: DefId(0:3 ~ oneplustwo[6ccc]::main),
80-
local_id: 1,
81-
}),
8293
// reference to expression 0 above
94+
region_scope: Node(3),
95+
lint_level: Explicit(
96+
HirId {
97+
owner: DefId(0:3 ~ oneplustwo[6932]::main),
98+
local_id: 3,
99+
},
100+
),
83101
value: e0,
84102
},
85103
},
86104
// expression 2, literal 2
87105
Expr {
88106
ty: i32,
89-
temp_lifetime: Some(Node(6)),
107+
temp_lifetime: Some(
108+
Node(1),
109+
),
90110
span: oneplustwo.rs:2:17: 2:18 (#0),
91111
kind: Literal {
92-
literal: Const {
93-
ty: i32,
94-
val: Value(Scalar(0x00000002)),
112+
lit: Spanned {
113+
node: Int(
114+
2,
115+
Unsuffixed,
116+
),
117+
span: oneplustwo.rs:2:17: 2:18 (#0),
95118
},
96-
user_ty: None,
97-
const_id: None,
119+
neg: false,
98120
},
99121
},
100122
// expression 3, scope surrounding literal 2
101123
Expr {
102124
ty: i32,
103-
temp_lifetime: Some(Node(6)),
125+
temp_lifetime: Some(
126+
Node(1),
127+
),
104128
span: oneplustwo.rs:2:17: 2:18 (#0),
105129
kind: Scope {
106-
region_scope: Node(2),
107-
lint_level: Explicit(HirId {
108-
owner: DefId(0:3 ~ oneplustwo[6ccc]::main),
109-
local_id: 2,
110-
}),
130+
region_scope: Node(4),
131+
lint_level: Explicit(
132+
HirId {
133+
owner: DefId(0:3 ~ oneplustwo[6932]::main),
134+
local_id: 4,
135+
},
136+
),
111137
// reference to expression 2 above
112138
value: e2,
113139
},
114140
},
115141
// expression 4, represents 1 + 2
116142
Expr {
117143
ty: i32,
118-
temp_lifetime: Some(Node(6)),
144+
temp_lifetime: Some(
145+
Node(1),
146+
),
119147
span: oneplustwo.rs:2:13: 2:18 (#0),
120148
kind: Binary {
121149
op: Add,
@@ -127,30 +155,38 @@ Thir {
127155
// expression 5, scope surronding expression 4
128156
Expr {
129157
ty: i32,
130-
temp_lifetime: Some(Node(6)),
158+
temp_lifetime: Some(
159+
Node(1),
160+
),
131161
span: oneplustwo.rs:2:13: 2:18 (#0),
132162
kind: Scope {
133-
region_scope: Node(3),
134-
lint_level: Explicit(HirId {
135-
owner: DefId(0:3 ~ oneplustwo[6ccc]::main),
136-
local_id: 3,
137-
}),
163+
region_scope: Node(5),
164+
lint_level: Explicit(
165+
HirId {
166+
owner: DefId(0:3 ~ oneplustwo[6932]::main),
167+
local_id: 5,
168+
},
169+
),
138170
value: e4,
139171
},
140172
},
141173
// expression 6, block around statement
142174
Expr {
143175
ty: (),
144-
temp_lifetime: Some(Node(8)),
176+
temp_lifetime: Some(
177+
Node(9),
178+
),
145179
span: oneplustwo.rs:1:11: 3:2 (#0),
146180
kind: Block {
147181
body: Block {
148182
targeted_by_break: false,
149-
region_scope: Node(7),
183+
region_scope: Node(8),
150184
opt_destruction_scope: None,
151185
span: oneplustwo.rs:1:11: 3:2 (#0),
152186
// reference to statement 0 below
153-
stmts: [ s0 ],
187+
stmts: [
188+
s0,
189+
],
154190
expr: None,
155191
safety_mode: Safe,
156192
},
@@ -160,25 +196,29 @@ Thir {
160196
Expr {
161197
ty: (),
162198
temp_lifetime: Some(
163-
Node(8),
199+
Node(9),
164200
),
165201
span: oneplustwo.rs:1:11: 3:2 (#0),
166202
kind: Scope {
167-
region_scope: Node(8),
168-
lint_level: Explicit(HirId {
169-
owner: DefId(0:3 ~ oneplustwo[6ccc]::main),
170-
local_id: 8,
171-
}),
203+
region_scope: Node(9),
204+
lint_level: Explicit(
205+
HirId {
206+
owner: DefId(0:3 ~ oneplustwo[6932]::main),
207+
local_id: 9,
208+
},
209+
),
172210
value: e6,
173211
},
174212
},
175213
// destruction scope around expression 7
176214
Expr {
177215
ty: (),
178-
temp_lifetime: Some(Node(8)),
216+
temp_lifetime: Some(
217+
Node(9),
218+
),
179219
span: oneplustwo.rs:1:11: 3:2 (#0),
180220
kind: Scope {
181-
region_scope: Destruction(8),
221+
region_scope: Destruction(9),
182222
lint_level: Inherited,
183223
value: e7,
184224
},
@@ -188,31 +228,40 @@ Thir {
188228
// let statement
189229
Stmt {
190230
kind: Let {
191-
remainder_scope: Remainder { block: 7, first_statement_index: 0},
192-
init_scope: Node(6),
231+
remainder_scope: Remainder { block: 8, first_statement_index: 0},
232+
init_scope: Node(1),
193233
pattern: Pat {
194234
ty: i32,
195235
span: oneplustwo.rs:2:9: 2:10 (#0),
196236
kind: Binding {
197237
mutability: Not,
198238
name: "x",
199239
mode: ByValue,
200-
var: HirId {
201-
owner: DefId(0:3 ~ oneplustwo[6ccc]::main),
202-
local_id: 5,
203-
},
240+
var: LocalVarId(
241+
HirId {
242+
owner: DefId(0:3 ~ oneplustwo[6932]::main),
243+
local_id: 7,
244+
},
245+
),
204246
ty: i32,
205247
subpattern: None,
206248
is_primary: true,
207249
},
208250
},
209-
initializer: Some(e5),
210-
lint_level: Explicit(HirId {
211-
owner: DefId(0:3 ~ oneplustwo[6ccc]::main),
212-
local_id: 4,
213-
}),
251+
initializer: Some(
252+
e5,
253+
),
254+
else_block: None,
255+
lint_level: Explicit(
256+
HirId {
257+
owner: DefId(0:3 ~ oneplustwo[6932]::main),
258+
local_id: 6,
259+
},
260+
),
214261
},
215-
opt_destruction_scope: Some(Destruction(6)),
262+
opt_destruction_scope: Some(
263+
Destruction(1),
264+
),
216265
},
217266
],
218267
}

0 commit comments

Comments
 (0)