diff options
| -rw-r--r-- | src/librustc/session/mod.rs | 10 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/const_eval.rs | 9 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/eval_context.rs | 28 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/memory.rs | 4 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/step.rs | 2 |
6 files changed, 22 insertions, 33 deletions
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 5e9eeb97300..232344a0367 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -103,6 +103,13 @@ pub struct Session { /// The maximum length of types during monomorphization. pub type_length_limit: Cell<usize>, + /// The maximum number of stackframes allowed in const eval + pub const_eval_stack_frame_limit: Cell<usize>, + /// The maximum number miri steps per constant + pub const_eval_step_limit: Cell<usize>, + /// The maximum number of virtual bytes per constant + pub const_eval_memory_limit: Cell<u64>, + /// The metadata::creader module may inject an allocator/panic_runtime /// dependency if it didn't already find one, and this tracks what was /// injected. @@ -1004,6 +1011,9 @@ pub fn build_session_(sopts: config::Options, features: RefCell::new(None), recursion_limit: Cell::new(64), type_length_limit: Cell::new(1048576), + const_eval_stack_frame_limit: Cell::new(100), + const_eval_step_limit: Cell::new(1_000_000), + const_eval_memory_limit: Cell::new(100 * 1024 * 1024), // 100 MB next_node_id: Cell::new(NodeId::new(1)), injected_allocator: Cell::new(None), allocator_kind: Cell::new(None), diff --git a/src/librustc_mir/interpret/const_eval.rs b/src/librustc_mir/interpret/const_eval.rs index c2f9690b9f1..e216f5c4d8a 100644 --- a/src/librustc_mir/interpret/const_eval.rs +++ b/src/librustc_mir/interpret/const_eval.rs @@ -24,8 +24,7 @@ pub fn mk_borrowck_eval_cx<'a, 'mir, 'tcx>( ) -> EvalResult<'tcx, EvalContext<'a, 'mir, 'tcx, CompileTimeEvaluator>> { debug!("mk_borrowck_eval_cx: {:?}", instance); let param_env = tcx.param_env(instance.def_id()); - let limits = super::ResourceLimits::default(); - let mut ecx = EvalContext::new(tcx, param_env, limits, CompileTimeEvaluator, ()); + let mut ecx = EvalContext::new(tcx, param_env, CompileTimeEvaluator, ()); // insert a stack frame so any queries have the correct substs ecx.push_stack_frame( instance, @@ -43,8 +42,7 @@ pub fn mk_eval_cx<'a, 'tcx>( param_env: ty::ParamEnv<'tcx>, ) -> EvalResult<'tcx, EvalContext<'a, 'tcx, 'tcx, CompileTimeEvaluator>> { debug!("mk_eval_cx: {:?}, {:?}", instance, param_env); - let limits = super::ResourceLimits::default(); - let mut ecx = EvalContext::new(tcx, param_env, limits, CompileTimeEvaluator, ()); + let mut ecx = EvalContext::new(tcx, param_env, CompileTimeEvaluator, ()); let mir = ecx.load_mir(instance.def)?; // insert a stack frame so any queries have the correct substs ecx.push_stack_frame( @@ -95,8 +93,7 @@ fn eval_body_and_ecx<'a, 'mir, 'tcx>( param_env: ty::ParamEnv<'tcx>, ) -> (EvalResult<'tcx, (Value, Pointer, Ty<'tcx>)>, EvalContext<'a, 'mir, 'tcx, CompileTimeEvaluator>) { debug!("eval_body: {:?}, {:?}", cid, param_env); - let limits = super::ResourceLimits::default(); - let mut ecx = EvalContext::new(tcx, param_env, limits, CompileTimeEvaluator, ()); + let mut ecx = EvalContext::new(tcx, param_env, CompileTimeEvaluator, ()); let res = (|| { let mut mir = match mir { Some(mir) => mir, diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 71450f42665..676f99ea6be 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -43,7 +43,7 @@ pub struct EvalContext<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> { /// The maximum number of operations that may be executed. /// This prevents infinite loops and huge computations from freezing up const eval. /// Remove once halting problem is solved. - pub(crate) steps_remaining: u64, + pub(crate) steps_remaining: usize, } /// A stack frame. @@ -103,23 +103,6 @@ pub enum StackPopCleanup { } #[derive(Copy, Clone, Debug)] -pub struct ResourceLimits { - pub memory_size: u64, - pub step_limit: u64, - pub stack_limit: usize, -} - -impl Default for ResourceLimits { - fn default() -> Self { - ResourceLimits { - memory_size: 100 * 1024 * 1024, // 100 MB - step_limit: 1_000_000, - stack_limit: 100, - } - } -} - -#[derive(Copy, Clone, Debug)] pub struct TyAndPacked<'tcx> { pub ty: Ty<'tcx>, pub packed: bool, @@ -200,7 +183,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M pub fn new( tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, - limits: ResourceLimits, machine: M, memory_data: M::MemoryData, ) -> Self { @@ -208,10 +190,10 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M machine, tcx, param_env, - memory: Memory::new(tcx, limits.memory_size, memory_data), + memory: Memory::new(tcx, memory_data), stack: Vec::new(), - stack_limit: limits.stack_limit, - steps_remaining: limits.step_limit, + stack_limit: tcx.sess.const_eval_stack_frame_limit.get(), + steps_remaining: tcx.sess.const_eval_step_limit.get(), } } @@ -559,7 +541,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M } Aggregate(ref kind, ref operands) => { - self.inc_step_counter_and_check_limit(operands.len() as u64)?; + self.inc_step_counter_and_check_limit(operands.len())?; let (dest, active_field_index) = match **kind { mir::AggregateKind::Adt(adt_def, variant_index, _, active_field_index) => { diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index e67c3677911..da8ff11e3d0 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -55,14 +55,14 @@ pub struct Memory<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'mir, 'tcx>> { } impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { - pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, max_memory: u64, data: M::MemoryData) -> Self { + pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, data: M::MemoryData) -> Self { Memory { data, alloc_kind: HashMap::new(), alloc_map: HashMap::new(), uninitialized_statics: HashMap::new(), tcx, - memory_size: max_memory, + memory_size: tcx.sess.const_eval_memory_limit.get(), memory_usage: 0, cur_frame: usize::max_value(), } diff --git a/src/librustc_mir/interpret/mod.rs b/src/librustc_mir/interpret/mod.rs index f23ba90fd4c..8e0158569a8 100644 --- a/src/librustc_mir/interpret/mod.rs +++ b/src/librustc_mir/interpret/mod.rs @@ -11,7 +11,7 @@ mod step; mod terminator; mod traits; -pub use self::eval_context::{EvalContext, Frame, ResourceLimits, StackPopCleanup, +pub use self::eval_context::{EvalContext, Frame, StackPopCleanup, TyAndPacked, ValTy}; pub use self::place::{Place, PlaceExtra}; diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs index 21e81ff668e..94fe3d1c67b 100644 --- a/src/librustc_mir/interpret/step.rs +++ b/src/librustc_mir/interpret/step.rs @@ -8,7 +8,7 @@ use rustc::mir::interpret::EvalResult; use super::{EvalContext, Machine}; impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> { - pub fn inc_step_counter_and_check_limit(&mut self, n: u64) -> EvalResult<'tcx> { + pub fn inc_step_counter_and_check_limit(&mut self, n: usize) -> EvalResult<'tcx> { self.steps_remaining = self.steps_remaining.saturating_sub(n); if self.steps_remaining > 0 { Ok(()) |
