/// 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.
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),
) -> 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,
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(
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,
/// 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.
None,
}
-#[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 fn new(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
- limits: ResourceLimits,
machine: M,
memory_data: M::MemoryData,
) -> Self {
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(),
}
}
}
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) => {
}
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(),
}
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};
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(())