@@ -10,16 +10,15 @@ use rustc::hir::{self, def_id::DefId};
10
10
use rustc:: hir:: def:: Def ;
11
11
use rustc:: mir:: interpret:: { ConstEvalErr , ErrorHandled } ;
12
12
use rustc:: mir;
13
- use rustc:: ty:: { self , TyCtxt , Instance , query:: TyCtxtAt } ;
13
+ use rustc:: ty:: { self , TyCtxt , query:: TyCtxtAt } ;
14
14
use rustc:: ty:: layout:: { self , LayoutOf , TyLayout , VariantIdx } ;
15
15
use rustc:: ty:: subst:: Subst ;
16
16
use rustc:: traits:: Reveal ;
17
- use rustc_data_structures:: indexed_vec:: IndexVec ;
18
17
use rustc_data_structures:: fx:: FxHashMap ;
19
18
use rustc:: util:: common:: ErrorReported ;
20
19
21
20
use syntax:: ast:: Mutability ;
22
- use syntax:: source_map:: { Span , DUMMY_SP } ;
21
+ use syntax:: source_map:: DUMMY_SP ;
23
22
24
23
use crate :: interpret:: { self ,
25
24
PlaceTy , MPlaceTy , MemPlace , OpTy , Operand , Immediate , Scalar , RawConst , ConstValue , Pointer ,
@@ -35,72 +34,19 @@ const STEPS_UNTIL_DETECTOR_ENABLED: isize = 1_000_000;
35
34
/// Should be a power of two for performance reasons.
36
35
const DETECTOR_SNAPSHOT_PERIOD : isize = 256 ;
37
36
38
- /// Warning: do not use this function if you expect to start interpreting the given `Mir`.
39
- /// The `EvalContext` is only meant to be used to query values from constants and statics.
40
- ///
41
- /// This function is used during const propagation. We cannot use `mk_eval_cx`, because copy
42
- /// propagation happens *during* the computation of the MIR of the current function. So if we
43
- /// tried to call the `optimized_mir` query, we'd get a cycle error because we are (transitively)
44
- /// inside the `optimized_mir` query of the `Instance` given.
45
- ///
46
- /// Since we are looking at the MIR of the function in an abstract manner, we don't have a
47
- /// `ParamEnv` available to us. This function creates a `ParamEnv` for the given instance.
48
- pub fn mk_borrowck_eval_cx < ' a , ' mir , ' tcx > (
49
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
50
- instance : Instance < ' tcx > ,
51
- mir : & ' mir mir:: Mir < ' tcx > ,
52
- span : Span ,
53
- ) -> EvalResult < ' tcx , CompileTimeEvalContext < ' a , ' mir , ' tcx > > {
54
- debug ! ( "mk_borrowck_eval_cx: {:?}" , instance) ;
55
- let param_env = tcx. param_env ( instance. def_id ( ) ) ;
56
- mk_eval_cx_inner ( tcx, instance, mir, span, param_env)
57
- }
58
-
59
- /// This is just a helper function to reduce code duplication between `mk_borrowck_eval_cx` and
60
- /// `mk_eval_cx`. Do not call this function directly.
61
- fn mk_eval_cx_inner < ' a , ' mir , ' tcx > (
62
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
63
- instance : Instance < ' tcx > ,
64
- mir : & ' mir mir:: Mir < ' tcx > ,
65
- span : Span ,
66
- param_env : ty:: ParamEnv < ' tcx > ,
67
- ) -> EvalResult < ' tcx , CompileTimeEvalContext < ' a , ' mir , ' tcx > > {
68
- let mut ecx = EvalContext :: new ( tcx. at ( span) , param_env, CompileTimeInterpreter :: new ( ) ) ;
69
- // Insert a stack frame so any queries have the correct substs.
70
- // We also avoid all the extra work performed by push_stack_frame,
71
- // like initializing local variables
72
- ecx. stack . push ( interpret:: Frame {
73
- block : mir:: START_BLOCK ,
74
- locals : IndexVec :: new ( ) ,
75
- local_layouts : IndexVec :: new ( ) ,
76
- instance,
77
- span,
78
- mir,
79
- return_place : None ,
80
- return_to_block : StackPopCleanup :: Goto ( None ) , // never pop
81
- stmt : 0 ,
82
- extra : ( ) ,
83
- } ) ;
84
- Ok ( ecx)
85
- }
86
-
87
- /// Warning: do not use this function if you expect to start interpreting the given `Mir`.
88
37
/// The `EvalContext` is only meant to be used to do field and index projections into constants for
89
38
/// `simd_shuffle` and const patterns in match arms.
90
39
///
91
40
/// The function containing the `match` that is currently being analyzed may have generic bounds
92
41
/// that inform us about the generic bounds of the constant. E.g. using an associated constant
93
42
/// of a function's generic parameter will require knowledge about the bounds on the generic
94
43
/// parameter. These bounds are passed to `mk_eval_cx` via the `ParamEnv` argument.
95
- fn mk_eval_cx < ' a , ' tcx > (
44
+ pub ( crate ) fn mk_eval_cx < ' a , ' mir , ' tcx > (
96
45
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
97
- instance : Instance < ' tcx > ,
98
46
param_env : ty:: ParamEnv < ' tcx > ,
99
- ) -> EvalResult < ' tcx , CompileTimeEvalContext < ' a , ' tcx , ' tcx > > {
100
- debug ! ( "mk_eval_cx: {:?}, {:?}" , instance, param_env) ;
101
- let span = tcx. def_span ( instance. def_id ( ) ) ;
102
- let mir = tcx. optimized_mir ( instance. def . def_id ( ) ) ;
103
- mk_eval_cx_inner ( tcx, instance, mir, span, param_env)
47
+ ) -> CompileTimeEvalContext < ' a , ' mir , ' tcx > {
48
+ debug ! ( "mk_eval_cx: {:?}" , param_env) ;
49
+ EvalContext :: new ( tcx. at ( DUMMY_SP ) , param_env, CompileTimeInterpreter :: new ( ) )
104
50
}
105
51
106
52
pub ( crate ) fn eval_promoted < ' a , ' mir , ' tcx > (
@@ -109,7 +55,7 @@ pub(crate) fn eval_promoted<'a, 'mir, 'tcx>(
109
55
mir : & ' mir mir:: Mir < ' tcx > ,
110
56
param_env : ty:: ParamEnv < ' tcx > ,
111
57
) -> EvalResult < ' tcx , MPlaceTy < ' tcx > > {
112
- let mut ecx = mk_borrowck_eval_cx ( tcx, cid . instance , mir , DUMMY_SP ) . unwrap ( ) ;
58
+ let mut ecx = mk_eval_cx ( tcx, param_env ) ;
113
59
eval_body_using_ecx ( & mut ecx, cid, Some ( mir) , param_env)
114
60
}
115
61
@@ -530,13 +476,12 @@ impl<'a, 'mir, 'tcx> interpret::Machine<'a, 'mir, 'tcx>
530
476
pub fn const_field < ' a , ' tcx > (
531
477
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
532
478
param_env : ty:: ParamEnv < ' tcx > ,
533
- instance : ty:: Instance < ' tcx > ,
534
479
variant : Option < VariantIdx > ,
535
480
field : mir:: Field ,
536
481
value : ty:: Const < ' tcx > ,
537
482
) -> :: rustc:: mir:: interpret:: ConstEvalResult < ' tcx > {
538
- trace ! ( "const_field: {:?}, {:?}, {:?}" , instance , field, value) ;
539
- let ecx = mk_eval_cx ( tcx, instance , param_env) . unwrap ( ) ;
483
+ trace ! ( "const_field: {:?}, {:?}" , field, value) ;
484
+ let ecx = mk_eval_cx ( tcx, param_env) ;
540
485
let result = ( || {
541
486
// get the operand again
542
487
let op = lazy_const_to_op ( & ecx, ty:: LazyConst :: Evaluated ( value) , value. ty ) ?;
@@ -561,11 +506,10 @@ pub fn const_field<'a, 'tcx>(
561
506
pub fn const_variant_index < ' a , ' tcx > (
562
507
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
563
508
param_env : ty:: ParamEnv < ' tcx > ,
564
- instance : ty:: Instance < ' tcx > ,
565
509
val : ty:: Const < ' tcx > ,
566
510
) -> EvalResult < ' tcx , VariantIdx > {
567
- trace ! ( "const_variant_index: {:?}, {:?}" , instance , val) ;
568
- let ecx = mk_eval_cx ( tcx, instance , param_env) . unwrap ( ) ;
511
+ trace ! ( "const_variant_index: {:?}" , val) ;
512
+ let ecx = mk_eval_cx ( tcx, param_env) ;
569
513
let op = lazy_const_to_op ( & ecx, ty:: LazyConst :: Evaluated ( val) , val. ty ) ?;
570
514
Ok ( ecx. read_discriminant ( op) ?. 1 )
571
515
}
@@ -585,7 +529,7 @@ fn validate_and_turn_into_const<'a, 'tcx>(
585
529
key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
586
530
) -> :: rustc:: mir:: interpret:: ConstEvalResult < ' tcx > {
587
531
let cid = key. value ;
588
- let ecx = mk_eval_cx ( tcx, cid . instance , key. param_env ) . unwrap ( ) ;
532
+ let ecx = mk_eval_cx ( tcx, key. param_env ) ;
589
533
let val = ( || {
590
534
let op = ecx. raw_const_to_mplace ( constant) ?. into ( ) ;
591
535
// FIXME: Once the visitor infrastructure landed, change validation to
0 commit comments