|
1 | 1 | //! Propagates constants for early reporting of statically known |
2 | 2 | //! assertion failures |
3 | 3 |
|
4 | | -use rustc_const_eval::interpret::{ |
5 | | - self, compile_time_machine, AllocId, ConstAllocation, FnArg, Frame, ImmTy, InterpCx, |
6 | | - InterpResult, OpTy, PlaceTy, Pointer, |
7 | | -}; |
8 | 4 | use rustc_index::bit_set::BitSet; |
9 | 5 | use rustc_index::IndexVec; |
10 | 6 | use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; |
11 | 7 | use rustc_middle::mir::*; |
12 | | -use rustc_middle::query::TyCtxtAt; |
13 | | -use rustc_middle::ty::layout::TyAndLayout; |
14 | | -use rustc_middle::ty::{self, ParamEnv, TyCtxt}; |
15 | | -use rustc_span::def_id::DefId; |
| 8 | +use rustc_middle::ty::{ParamEnv, TyCtxt}; |
16 | 9 | use rustc_target::abi::Size; |
17 | | -use rustc_target::spec::abi::Abi as CallAbi; |
18 | 10 |
|
19 | 11 | /// The maximum number of bytes that we'll allocate space for a local or the return value. |
20 | 12 | /// Needed for #66397, because otherwise we eval into large places and that can cause OOM or just |
@@ -48,135 +40,6 @@ pub(crate) macro throw_machine_stop_str($($tt:tt)*) {{ |
48 | 40 | throw_machine_stop!(Zst) |
49 | 41 | }} |
50 | 42 |
|
51 | | -pub(crate) struct ConstPropMachine; |
52 | | - |
53 | | -impl<'mir, 'tcx: 'mir> interpret::Machine<'mir, 'tcx> for ConstPropMachine { |
54 | | - compile_time_machine!(<'mir, 'tcx>); |
55 | | - |
56 | | - const PANIC_ON_ALLOC_FAIL: bool = true; // all allocations are small (see `MAX_ALLOC_LIMIT`) |
57 | | - |
58 | | - const POST_MONO_CHECKS: bool = false; // this MIR is still generic! |
59 | | - |
60 | | - type MemoryKind = !; |
61 | | - |
62 | | - #[inline(always)] |
63 | | - fn enforce_alignment(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { |
64 | | - false // no reason to enforce alignment |
65 | | - } |
66 | | - |
67 | | - #[inline(always)] |
68 | | - fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>, _layout: TyAndLayout<'tcx>) -> bool { |
69 | | - false // for now, we don't enforce validity |
70 | | - } |
71 | | - |
72 | | - fn load_mir( |
73 | | - _ecx: &InterpCx<'mir, 'tcx, Self>, |
74 | | - _instance: ty::InstanceDef<'tcx>, |
75 | | - ) -> InterpResult<'tcx, &'tcx Body<'tcx>> { |
76 | | - throw_machine_stop_str!("calling functions isn't supported in ConstProp") |
77 | | - } |
78 | | - |
79 | | - fn panic_nounwind(_ecx: &mut InterpCx<'mir, 'tcx, Self>, _msg: &str) -> InterpResult<'tcx> { |
80 | | - throw_machine_stop_str!("panicking isn't supported in ConstProp") |
81 | | - } |
82 | | - |
83 | | - fn find_mir_or_eval_fn( |
84 | | - _ecx: &mut InterpCx<'mir, 'tcx, Self>, |
85 | | - _instance: ty::Instance<'tcx>, |
86 | | - _abi: CallAbi, |
87 | | - _args: &[FnArg<'tcx>], |
88 | | - _destination: &PlaceTy<'tcx>, |
89 | | - _target: Option<BasicBlock>, |
90 | | - _unwind: UnwindAction, |
91 | | - ) -> InterpResult<'tcx, Option<(&'mir Body<'tcx>, ty::Instance<'tcx>)>> { |
92 | | - Ok(None) |
93 | | - } |
94 | | - |
95 | | - fn call_intrinsic( |
96 | | - _ecx: &mut InterpCx<'mir, 'tcx, Self>, |
97 | | - _instance: ty::Instance<'tcx>, |
98 | | - _args: &[OpTy<'tcx>], |
99 | | - _destination: &PlaceTy<'tcx>, |
100 | | - _target: Option<BasicBlock>, |
101 | | - _unwind: UnwindAction, |
102 | | - ) -> InterpResult<'tcx> { |
103 | | - throw_machine_stop_str!("calling intrinsics isn't supported in ConstProp") |
104 | | - } |
105 | | - |
106 | | - fn assert_panic( |
107 | | - _ecx: &mut InterpCx<'mir, 'tcx, Self>, |
108 | | - _msg: &rustc_middle::mir::AssertMessage<'tcx>, |
109 | | - _unwind: rustc_middle::mir::UnwindAction, |
110 | | - ) -> InterpResult<'tcx> { |
111 | | - bug!("panics terminators are not evaluated in ConstProp") |
112 | | - } |
113 | | - |
114 | | - fn binary_ptr_op( |
115 | | - _ecx: &InterpCx<'mir, 'tcx, Self>, |
116 | | - _bin_op: BinOp, |
117 | | - _left: &ImmTy<'tcx>, |
118 | | - _right: &ImmTy<'tcx>, |
119 | | - ) -> InterpResult<'tcx, (ImmTy<'tcx>, bool)> { |
120 | | - // We can't do this because aliasing of memory can differ between const eval and llvm |
121 | | - throw_machine_stop_str!("pointer arithmetic or comparisons aren't supported in ConstProp") |
122 | | - } |
123 | | - |
124 | | - fn before_access_local_mut<'a>( |
125 | | - _ecx: &'a mut InterpCx<'mir, 'tcx, Self>, |
126 | | - _frame: usize, |
127 | | - _local: Local, |
128 | | - ) -> InterpResult<'tcx> { |
129 | | - unreachable!() |
130 | | - } |
131 | | - |
132 | | - fn before_access_global( |
133 | | - _tcx: TyCtxtAt<'tcx>, |
134 | | - _machine: &Self, |
135 | | - _alloc_id: AllocId, |
136 | | - alloc: ConstAllocation<'tcx>, |
137 | | - _static_def_id: Option<DefId>, |
138 | | - is_write: bool, |
139 | | - ) -> InterpResult<'tcx> { |
140 | | - if is_write { |
141 | | - throw_machine_stop_str!("can't write to global"); |
142 | | - } |
143 | | - // If the static allocation is mutable, then we can't const prop it as its content |
144 | | - // might be different at runtime. |
145 | | - if alloc.inner().mutability.is_mut() { |
146 | | - throw_machine_stop_str!("can't access mutable globals in ConstProp"); |
147 | | - } |
148 | | - |
149 | | - Ok(()) |
150 | | - } |
151 | | - |
152 | | - #[inline(always)] |
153 | | - fn expose_ptr(_ecx: &mut InterpCx<'mir, 'tcx, Self>, _ptr: Pointer) -> InterpResult<'tcx> { |
154 | | - throw_machine_stop_str!("exposing pointers isn't supported in ConstProp") |
155 | | - } |
156 | | - |
157 | | - #[inline(always)] |
158 | | - fn init_frame_extra( |
159 | | - _ecx: &mut InterpCx<'mir, 'tcx, Self>, |
160 | | - frame: Frame<'mir, 'tcx>, |
161 | | - ) -> InterpResult<'tcx, Frame<'mir, 'tcx>> { |
162 | | - Ok(frame) |
163 | | - } |
164 | | - |
165 | | - #[inline(always)] |
166 | | - fn stack<'a>( |
167 | | - _ecx: &'a InterpCx<'mir, 'tcx, Self>, |
168 | | - ) -> &'a [Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>] { |
169 | | - &[] |
170 | | - } |
171 | | - |
172 | | - #[inline(always)] |
173 | | - fn stack_mut<'a>( |
174 | | - _ecx: &'a mut InterpCx<'mir, 'tcx, Self>, |
175 | | - ) -> &'a mut Vec<Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>> { |
176 | | - unreachable!() |
177 | | - } |
178 | | -} |
179 | | - |
180 | 43 | /// The mode that `ConstProp` is allowed to run in for a given `Local`. |
181 | 44 | #[derive(Clone, Copy, Debug, PartialEq)] |
182 | 45 | pub enum ConstPropMode { |
|
0 commit comments