1
1
use rustc_middle:: mir;
2
- use rustc_middle:: ty:: layout:: HasTyCtxt ;
3
- use rustc_middle:: ty:: InstanceDef ;
4
2
use rustc_middle:: ty:: { self , Ty } ;
5
3
use std:: borrow:: Borrow ;
6
4
use std:: collections:: hash_map:: Entry ;
@@ -17,60 +15,13 @@ use rustc_span::symbol::{sym, Symbol};
17
15
use rustc_target:: abi:: { Align , Size } ;
18
16
19
17
use crate :: interpret:: {
20
- self , compile_time_machine, AllocId , Allocation , Frame , GlobalId , ImmTy , InterpCx ,
21
- InterpResult , Memory , OpTy , PlaceTy , Pointer , Scalar ,
18
+ self , compile_time_machine, AllocId , Allocation , Frame , ImmTy , InterpCx , InterpResult , Memory ,
19
+ OpTy , PlaceTy , Pointer , Scalar ,
22
20
} ;
23
21
24
22
use super :: error:: * ;
25
23
26
24
impl < ' mir , ' tcx > InterpCx < ' mir , ' tcx , CompileTimeInterpreter < ' mir , ' tcx > > {
27
- /// Evaluate a const function where all arguments (if any) are zero-sized types.
28
- /// The evaluation is memoized thanks to the query system.
29
- ///
30
- /// Returns `true` if the call has been evaluated.
31
- fn try_eval_const_fn_call (
32
- & mut self ,
33
- instance : ty:: Instance < ' tcx > ,
34
- ret : Option < ( PlaceTy < ' tcx > , mir:: BasicBlock ) > ,
35
- args : & [ OpTy < ' tcx > ] ,
36
- ) -> InterpResult < ' tcx , bool > {
37
- trace ! ( "try_eval_const_fn_call: {:?}" , instance) ;
38
- // Because `#[track_caller]` adds an implicit non-ZST argument, we also cannot
39
- // perform this optimization on items tagged with it.
40
- if instance. def . requires_caller_location ( self . tcx ( ) ) {
41
- return Ok ( false ) ;
42
- }
43
- // Only memoize instrinsics. This was added in #79594 while adding the `const_allocate` intrinsic.
44
- // We only memoize intrinsics because it would be unsound to memoize functions
45
- // which might interact with the heap.
46
- // Additionally, const_allocate intrinsic is impure and thus should not be memoized;
47
- // it will not be memoized because it has non-ZST args
48
- if !matches ! ( instance. def, InstanceDef :: Intrinsic ( _) ) {
49
- return Ok ( false ) ;
50
- }
51
- // For the moment we only do this for functions which take no arguments
52
- // (or all arguments are ZSTs) so that we don't memoize too much.
53
- if args. iter ( ) . any ( |a| !a. layout . is_zst ( ) ) {
54
- return Ok ( false ) ;
55
- }
56
-
57
- let dest = match ret {
58
- Some ( ( dest, _) ) => dest,
59
- // Don't memoize diverging function calls.
60
- None => return Ok ( false ) ,
61
- } ;
62
-
63
- let gid = GlobalId { instance, promoted : None } ;
64
-
65
- let place = self . eval_to_allocation ( gid) ?;
66
-
67
- self . copy_op ( place. into ( ) , dest) ?;
68
-
69
- self . return_to_block ( ret. map ( |r| r. 1 ) ) ?;
70
- trace ! ( "{:?}" , self . dump_place( * dest) ) ;
71
- Ok ( true )
72
- }
73
-
74
25
/// "Intercept" a function call to a panic-related function
75
26
/// because we have something special to do for it.
76
27
/// If this returns successfully (`Ok`), the function should just be evaluated normally.
@@ -253,7 +204,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
253
204
ecx : & mut InterpCx < ' mir , ' tcx , Self > ,
254
205
instance : ty:: Instance < ' tcx > ,
255
206
args : & [ OpTy < ' tcx > ] ,
256
- ret : Option < ( PlaceTy < ' tcx > , mir:: BasicBlock ) > ,
207
+ _ret : Option < ( PlaceTy < ' tcx > , mir:: BasicBlock ) > ,
257
208
_unwind : Option < mir:: BasicBlock > , // unwinding is not supported in consts
258
209
) -> InterpResult < ' tcx , Option < & ' mir mir:: Body < ' tcx > > > {
259
210
debug ! ( "find_mir_or_eval_fn: {:?}" , instance) ;
@@ -263,13 +214,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
263
214
// Execution might have wandered off into other crates, so we cannot do a stability-
264
215
// sensitive check here. But we can at least rule out functions that are not const
265
216
// at all.
266
- if ecx. tcx . is_const_fn_raw ( def. did ) {
267
- // If this function is a `const fn` then under certain circumstances we
268
- // can evaluate call via the query system, thus memoizing all future calls.
269
- if ecx. try_eval_const_fn_call ( instance, ret, args) ? {
270
- return Ok ( None ) ;
271
- }
272
- } else {
217
+ if !ecx. tcx . is_const_fn_raw ( def. did ) {
273
218
// Some functions we support even if they are non-const -- but avoid testing
274
219
// that for const fn!
275
220
ecx. hook_panic_fn ( instance, args) ?;
0 commit comments