@@ -17,6 +17,46 @@ use crate::interpret::{
17
17
18
18
use super :: error:: * ;
19
19
20
+ impl < ' mir , ' tcx > InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > {
21
+ /// Evaluate a const function where all arguments (if any) are zero-sized types.
22
+ /// The evaluation is memoized thanks to the query system.
23
+ ///
24
+ /// Returns `true` if the call has been evaluated.
25
+ fn try_eval_const_fn_call (
26
+ & mut self ,
27
+ instance : ty:: Instance < ' tcx > ,
28
+ ret : Option < ( PlaceTy < ' tcx > , mir:: BasicBlock ) > ,
29
+ args : & [ OpTy < ' tcx > ] ,
30
+ ) -> InterpResult < ' tcx , bool > {
31
+ trace ! ( "try_eval_const_fn_call: {:?}" , instance) ;
32
+ // Because `#[track_caller]` adds an implicit non-ZST argument, we also cannot
33
+ // perform this optimization on items tagged with it.
34
+ if instance. def . requires_caller_location ( self . tcx ( ) ) {
35
+ return Ok ( false ) ;
36
+ }
37
+ // For the moment we only do this for functions which take no arguments
38
+ // (or all arguments are ZSTs) so that we don't memoize too much.
39
+ if args. iter ( ) . any ( |a| !a. layout . is_zst ( ) ) {
40
+ return Ok ( false ) ;
41
+ }
42
+
43
+ let gid = GlobalId { instance, promoted : None } ;
44
+
45
+ let place = self . const_eval_raw ( gid) ?;
46
+ let dest = match ret {
47
+ Some ( ( dest, _) ) => dest,
48
+ // Don't memoize diverging function calls.
49
+ None => return Ok ( false ) ,
50
+ } ;
51
+
52
+ self . copy_op ( place. into ( ) , dest) ?;
53
+
54
+ self . return_to_block ( ret. map ( |r| r. 1 ) ) ?;
55
+ self . dump_place ( * dest) ;
56
+ return Ok ( true ) ;
57
+ }
58
+ }
59
+
20
60
/// Number of steps until the detector even starts doing anything.
21
61
/// Also, a warning is shown to the user when this number is reached.
22
62
const STEPS_UNTIL_DETECTOR_ENABLED : isize = 1_000_000 ;
@@ -318,42 +358,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
318
358
}
319
359
}
320
360
321
- impl < ' mir , ' tcx > InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > {
322
- /// Evaluate a const function where all arguments (if any) are zero-sized types.
323
- /// The evaluation is memoized thanks to the query system.
324
- ///
325
- /// Returns `true` if the call has been evaluated.
326
- fn try_eval_const_fn_call (
327
- & mut self ,
328
- instance : ty:: Instance < ' tcx > ,
329
- ret : Option < ( PlaceTy < ' tcx > , mir:: BasicBlock ) > ,
330
- args : & [ OpTy < ' tcx > ] ,
331
- ) -> InterpResult < ' tcx , bool > {
332
- trace ! ( "try_eval_const_fn_call: {:?}" , instance) ;
333
- // Because `#[track_caller]` adds an implicit non-ZST argument, we also cannot
334
- // perform this optimization on items tagged with it.
335
- if instance. def . requires_caller_location ( self . tcx ( ) ) {
336
- return Ok ( false ) ;
337
- }
338
- // For the moment we only do this for functions which take no arguments
339
- // (or all arguments are ZSTs) so that we don't memoize too much.
340
- if args. iter ( ) . any ( |a| !a. layout . is_zst ( ) ) {
341
- return Ok ( false ) ;
342
- }
343
-
344
- let gid = GlobalId { instance, promoted : None } ;
345
-
346
- let place = self . const_eval_raw ( gid) ?;
347
- let dest = match ret {
348
- Some ( ( dest, _) ) => dest,
349
- // Don't memoize diverging function calls.
350
- None => return Ok ( false ) ,
351
- } ;
352
-
353
- self . copy_op ( place. into ( ) , dest) ?;
354
-
355
- self . return_to_block ( ret. map ( |r| r. 1 ) ) ?;
356
- self . dump_place ( * dest) ;
357
- return Ok ( true ) ;
358
- }
359
- }
361
+ // Please do not add any code below the above `Machine` trait impl. I (oli-obk) plan more cleanups
362
+ // so we can end up having a file with just that impl, but for now, let's keep the impl discoverable
363
+ // at the bottom of this file.
0 commit comments