@@ -13,19 +13,19 @@ use super::{parse_by_kind, PResult, ParseCtxt};
13
13
impl < ' tcx , ' body > ParseCtxt < ' tcx , ' body > {
14
14
pub fn parse_statement ( & self , expr_id : ExprId ) -> PResult < StatementKind < ' tcx > > {
15
15
parse_by_kind ! ( self , expr_id, _, "statement" ,
16
- @call( " mir_storage_live" , args) => {
16
+ @call( mir_storage_live, args) => {
17
17
Ok ( StatementKind :: StorageLive ( self . parse_local( args[ 0 ] ) ?) )
18
18
} ,
19
- @call( " mir_storage_dead" , args) => {
19
+ @call( mir_storage_dead, args) => {
20
20
Ok ( StatementKind :: StorageDead ( self . parse_local( args[ 0 ] ) ?) )
21
21
} ,
22
- @call( " mir_deinit" , args) => {
22
+ @call( mir_deinit, args) => {
23
23
Ok ( StatementKind :: Deinit ( Box :: new( self . parse_place( args[ 0 ] ) ?) ) )
24
24
} ,
25
- @call( " mir_retag" , args) => {
25
+ @call( mir_retag, args) => {
26
26
Ok ( StatementKind :: Retag ( RetagKind :: Default , Box :: new( self . parse_place( args[ 0 ] ) ?) ) )
27
27
} ,
28
- @call( " mir_set_discriminant" , args) => {
28
+ @call( mir_set_discriminant, args) => {
29
29
let place = self . parse_place( args[ 0 ] ) ?;
30
30
let var = self . parse_integer_literal( args[ 1 ] ) ? as u32 ;
31
31
Ok ( StatementKind :: SetDiscriminant {
@@ -43,24 +43,30 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
43
43
44
44
pub fn parse_terminator ( & self , expr_id : ExprId ) -> PResult < TerminatorKind < ' tcx > > {
45
45
parse_by_kind ! ( self , expr_id, expr, "terminator" ,
46
- @call( " mir_return" , _args) => {
46
+ @call( mir_return, _args) => {
47
47
Ok ( TerminatorKind :: Return )
48
48
} ,
49
- @call( " mir_goto" , args) => {
49
+ @call( mir_goto, args) => {
50
50
Ok ( TerminatorKind :: Goto { target: self . parse_block( args[ 0 ] ) ? } )
51
51
} ,
52
- @call( " mir_unreachable" , _args) => {
52
+ @call( mir_unreachable, _args) => {
53
53
Ok ( TerminatorKind :: Unreachable )
54
54
} ,
55
- @call( "mir_drop" , args) => {
55
+ @call( mir_unwind_resume, _args) => {
56
+ Ok ( TerminatorKind :: UnwindResume )
57
+ } ,
58
+ @call( mir_unwind_terminate, args) => {
59
+ Ok ( TerminatorKind :: UnwindTerminate ( self . parse_unwind_terminate_reason( args[ 0 ] ) ?) )
60
+ } ,
61
+ @call( mir_drop, args) => {
56
62
Ok ( TerminatorKind :: Drop {
57
63
place: self . parse_place( args[ 0 ] ) ?,
58
64
target: self . parse_block( args[ 1 ] ) ?,
59
- unwind: UnwindAction :: Continue ,
65
+ unwind: self . parse_unwind_action ( args [ 2 ] ) ? ,
60
66
replace: false ,
61
67
} )
62
68
} ,
63
- @call( " mir_call" , args) => {
69
+ @call( mir_call, args) => {
64
70
self . parse_call( args)
65
71
} ,
66
72
ExprKind :: Match { scrutinee, arms, .. } => {
@@ -70,6 +76,34 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
70
76
)
71
77
}
72
78
79
+ fn parse_unwind_terminate_reason ( & self , expr_id : ExprId ) -> PResult < UnwindTerminateReason > {
80
+ parse_by_kind ! ( self , expr_id, _, "unwind terminate reason" ,
81
+ @variant( mir_unwind_terminate_reason, Abi ) => {
82
+ Ok ( UnwindTerminateReason :: Abi )
83
+ } ,
84
+ @variant( mir_unwind_terminate_reason, InCleanup ) => {
85
+ Ok ( UnwindTerminateReason :: InCleanup )
86
+ } ,
87
+ )
88
+ }
89
+
90
+ fn parse_unwind_action ( & self , expr_id : ExprId ) -> PResult < UnwindAction > {
91
+ parse_by_kind ! ( self , expr_id, _, "unwind action" ,
92
+ @call( mir_unwind_continue, _args) => {
93
+ Ok ( UnwindAction :: Continue )
94
+ } ,
95
+ @call( mir_unwind_unreachable, _args) => {
96
+ Ok ( UnwindAction :: Unreachable )
97
+ } ,
98
+ @call( mir_unwind_terminate, args) => {
99
+ Ok ( UnwindAction :: Terminate ( self . parse_unwind_terminate_reason( args[ 0 ] ) ?) )
100
+ } ,
101
+ @call( mir_unwind_cleanup, args) => {
102
+ Ok ( UnwindAction :: Cleanup ( self . parse_block( args[ 0 ] ) ?) )
103
+ } ,
104
+ )
105
+ }
106
+
73
107
fn parse_match ( & self , arms : & [ ArmId ] , span : Span ) -> PResult < SwitchTargets > {
74
108
let Some ( ( otherwise, rest) ) = arms. split_last ( ) else {
75
109
return Err ( ParseError {
@@ -113,6 +147,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
113
147
) ;
114
148
let destination = self . parse_place ( destination) ?;
115
149
let target = self . parse_block ( args[ 1 ] ) ?;
150
+ let unwind = self . parse_unwind_action ( args[ 2 ] ) ?;
116
151
117
152
parse_by_kind ! ( self , call, _, "function call" ,
118
153
ExprKind :: Call { fun, args, from_hir_call, fn_span, .. } => {
@@ -126,7 +161,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
126
161
args,
127
162
destination,
128
163
target: Some ( target) ,
129
- unwind: UnwindAction :: Continue ,
164
+ unwind,
130
165
call_source: if * from_hir_call { CallSource :: Normal } else {
131
166
CallSource :: OverloadedOperator
132
167
} ,
@@ -138,25 +173,25 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
138
173
139
174
fn parse_rvalue ( & self , expr_id : ExprId ) -> PResult < Rvalue < ' tcx > > {
140
175
parse_by_kind ! ( self , expr_id, expr, "rvalue" ,
141
- @call( " mir_discriminant" , args) => self . parse_place( args[ 0 ] ) . map( Rvalue :: Discriminant ) ,
142
- @call( " mir_cast_transmute" , args) => {
176
+ @call( mir_discriminant, args) => self . parse_place( args[ 0 ] ) . map( Rvalue :: Discriminant ) ,
177
+ @call( mir_cast_transmute, args) => {
143
178
let source = self . parse_operand( args[ 0 ] ) ?;
144
179
Ok ( Rvalue :: Cast ( CastKind :: Transmute , source, expr. ty) )
145
180
} ,
146
- @call( " mir_checked" , args) => {
181
+ @call( mir_checked, args) => {
147
182
parse_by_kind!( self , args[ 0 ] , _, "binary op" ,
148
183
ExprKind :: Binary { op, lhs, rhs } => Ok ( Rvalue :: CheckedBinaryOp (
149
184
* op, Box :: new( ( self . parse_operand( * lhs) ?, self . parse_operand( * rhs) ?) )
150
185
) ) ,
151
186
)
152
187
} ,
153
- @call( " mir_offset" , args) => {
188
+ @call( mir_offset, args) => {
154
189
let ptr = self . parse_operand( args[ 0 ] ) ?;
155
190
let offset = self . parse_operand( args[ 1 ] ) ?;
156
191
Ok ( Rvalue :: BinaryOp ( BinOp :: Offset , Box :: new( ( ptr, offset) ) ) )
157
192
} ,
158
- @call( " mir_len" , args) => Ok ( Rvalue :: Len ( self . parse_place( args[ 0 ] ) ?) ) ,
159
- @call( " mir_copy_for_deref" , args) => Ok ( Rvalue :: CopyForDeref ( self . parse_place( args[ 0 ] ) ?) ) ,
193
+ @call( mir_len, args) => Ok ( Rvalue :: Len ( self . parse_place( args[ 0 ] ) ?) ) ,
194
+ @call( mir_copy_for_deref, args) => Ok ( Rvalue :: CopyForDeref ( self . parse_place( args[ 0 ] ) ?) ) ,
160
195
ExprKind :: Borrow { borrow_kind, arg } => Ok (
161
196
Rvalue :: Ref ( self . tcx. lifetimes. re_erased, * borrow_kind, self . parse_place( * arg) ?)
162
197
) ,
@@ -206,9 +241,9 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
206
241
207
242
pub fn parse_operand ( & self , expr_id : ExprId ) -> PResult < Operand < ' tcx > > {
208
243
parse_by_kind ! ( self , expr_id, expr, "operand" ,
209
- @call( " mir_move" , args) => self . parse_place( args[ 0 ] ) . map( Operand :: Move ) ,
210
- @call( " mir_static" , args) => self . parse_static( args[ 0 ] ) ,
211
- @call( " mir_static_mut" , args) => self . parse_static( args[ 0 ] ) ,
244
+ @call( mir_move, args) => self . parse_place( args[ 0 ] ) . map( Operand :: Move ) ,
245
+ @call( mir_static, args) => self . parse_static( args[ 0 ] ) ,
246
+ @call( mir_static_mut, args) => self . parse_static( args[ 0 ] ) ,
212
247
ExprKind :: Literal { .. }
213
248
| ExprKind :: NamedConst { .. }
214
249
| ExprKind :: NonHirLiteral { .. }
@@ -229,23 +264,23 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
229
264
230
265
fn parse_place_inner ( & self , expr_id : ExprId ) -> PResult < ( Place < ' tcx > , PlaceTy < ' tcx > ) > {
231
266
let ( parent, proj) = parse_by_kind ! ( self , expr_id, expr, "place" ,
232
- @call( " mir_field" , args) => {
267
+ @call( mir_field, args) => {
233
268
let ( parent, ty) = self . parse_place_inner( args[ 0 ] ) ?;
234
269
let field = FieldIdx :: from_u32( self . parse_integer_literal( args[ 1 ] ) ? as u32 ) ;
235
270
let field_ty = ty. field_ty( self . tcx, field) ;
236
271
let proj = PlaceElem :: Field ( field, field_ty) ;
237
272
let place = parent. project_deeper( & [ proj] , self . tcx) ;
238
273
return Ok ( ( place, PlaceTy :: from_ty( field_ty) ) ) ;
239
274
} ,
240
- @call( " mir_variant" , args) => {
275
+ @call( mir_variant, args) => {
241
276
( args[ 0 ] , PlaceElem :: Downcast (
242
277
None ,
243
278
VariantIdx :: from_u32( self . parse_integer_literal( args[ 1 ] ) ? as u32 )
244
279
) )
245
280
} ,
246
281
ExprKind :: Deref { arg } => {
247
282
parse_by_kind!( self , * arg, _, "does not matter" ,
248
- @call( " mir_make_place" , args) => return self . parse_place_inner( args[ 0 ] ) ,
283
+ @call( mir_make_place, args) => return self . parse_place_inner( args[ 0 ] ) ,
249
284
_ => ( * arg, PlaceElem :: Deref ) ,
250
285
)
251
286
} ,
0 commit comments