4
4
use std:: borrow:: Cow ;
5
5
use std:: cell:: Cell ;
6
6
7
- use rustc:: mir:: interpret:: { InterpResult , MachineStopType , Scalar } ;
7
+ use rustc:: mir:: interpret:: { InterpResult , Scalar } ;
8
8
use rustc:: mir:: visit:: {
9
9
MutVisitor , MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor ,
10
10
} ;
@@ -39,6 +39,24 @@ use crate::transform::{MirPass, MirSource};
39
39
/// The maximum number of bytes that we'll allocate space for a return value.
40
40
const MAX_ALLOC_LIMIT : u64 = 1024 ;
41
41
42
+ /// Macro for machine-specific `InterpError` without allocation.
43
+ /// (These will never be shown to the user, but they help diagnose ICEs.)
44
+ macro_rules! throw_machine_stop_str {
45
+ ( $( $tt: tt) * ) => { {
46
+ // We make a new local type for it. The type itself does not carry any information,
47
+ // but its vtable (for the `MachineStopType` trait) does.
48
+ struct Zst ;
49
+ // Debug-printing this type shows the desired string.
50
+ impl std:: fmt:: Debug for Zst {
51
+ fn fmt( & self , f: & mut std:: fmt:: Formatter <' _>) -> std:: fmt:: Result {
52
+ write!( f, $( $tt) * )
53
+ }
54
+ }
55
+ impl rustc:: mir:: interpret:: MachineStopType for Zst { }
56
+ throw_machine_stop!( Zst )
57
+ } } ;
58
+ }
59
+
42
60
pub struct ConstProp ;
43
61
44
62
impl < ' tcx > MirPass < ' tcx > for ConstProp {
@@ -192,10 +210,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
192
210
_ret : Option < ( PlaceTy < ' tcx > , BasicBlock ) > ,
193
211
_unwind : Option < BasicBlock > ,
194
212
) -> InterpResult < ' tcx > {
195
- #[ derive( Debug ) ]
196
- struct ConstPropIntrinsic ;
197
- impl MachineStopType for ConstPropIntrinsic { }
198
- throw_machine_stop ! ( ConstPropIntrinsic )
213
+ throw_machine_stop_str ! ( "calling intrinsics isn't supported in ConstProp" )
199
214
}
200
215
201
216
fn assert_panic (
@@ -216,11 +231,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
216
231
_left : ImmTy < ' tcx > ,
217
232
_right : ImmTy < ' tcx > ,
218
233
) -> InterpResult < ' tcx , ( Scalar , bool , Ty < ' tcx > ) > {
219
- #[ derive( Debug ) ]
220
- struct ConstPropPtrOp ;
221
- impl MachineStopType for ConstPropPtrOp { }
222
234
// We can't do this because aliasing of memory can differ between const eval and llvm
223
- throw_machine_stop ! ( ConstPropPtrOp )
235
+ throw_machine_stop_str ! ( "pointer arithmetic or comparisons aren't supported in ConstProp" )
224
236
}
225
237
226
238
#[ inline( always) ]
@@ -243,10 +255,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
243
255
_ecx : & mut InterpCx < ' mir , ' tcx , Self > ,
244
256
_dest : PlaceTy < ' tcx > ,
245
257
) -> InterpResult < ' tcx > {
246
- #[ derive( Debug ) ]
247
- struct ConstPropBox ;
248
- impl MachineStopType for ConstPropBox { }
249
- throw_machine_stop ! ( ConstPropBox )
258
+ throw_machine_stop_str ! ( "can't const prop heap allocations" )
250
259
}
251
260
252
261
fn access_local (
@@ -257,10 +266,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
257
266
let l = & frame. locals [ local] ;
258
267
259
268
if l. value == LocalValue :: Uninitialized {
260
- #[ derive( Debug ) ]
261
- struct ConstPropUninitLocal ;
262
- impl MachineStopType for ConstPropUninitLocal { }
263
- throw_machine_stop ! ( ConstPropUninitLocal )
269
+ throw_machine_stop_str ! ( "tried to access an uninitialized local" )
264
270
}
265
271
266
272
l. access ( )
@@ -270,13 +276,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
270
276
_memory_extra : & ( ) ,
271
277
allocation : & Allocation < Self :: PointerTag , Self :: AllocExtra > ,
272
278
) -> InterpResult < ' tcx > {
273
- #[ derive( Debug ) ]
274
- struct ConstPropGlobalMem ;
275
- impl MachineStopType for ConstPropGlobalMem { }
276
279
// if the static allocation is mutable or if it has relocations (it may be legal to mutate
277
280
// the memory behind that in the future), then we can't const prop it
278
281
if allocation. mutability == Mutability :: Mut || allocation. relocations ( ) . len ( ) > 0 {
279
- throw_machine_stop ! ( ConstPropGlobalMem )
282
+ throw_machine_stop_str ! ( "can't eval mutable statics in ConstProp" )
280
283
}
281
284
282
285
Ok ( ( ) )
0 commit comments