From c1e70fb106138e7cbd9ff7d68c31cc74cff7aaf3 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 19 Nov 2018 17:59:20 -0500 Subject: [PATCH 1/2] Wrap const_eval_stack_frame_limit in a OneThread This allows Miri to set const_eval_stack_frame_limit as needed, while still keeping Session thread-safe --- src/librustc/session/mod.rs | 4 ++-- src/librustc_mir/interpret/eval_context.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 8582900b72c83..fadae2c9b9b46 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -107,7 +107,7 @@ pub struct Session { pub type_length_limit: Once, /// The maximum number of stackframes allowed in const eval - pub const_eval_stack_frame_limit: usize, + pub const_eval_stack_frame_limit: OneThread>, /// The metadata::creader module may inject an allocator/panic_runtime /// dependency if it didn't already find one, and this tracks what was @@ -1159,7 +1159,7 @@ pub fn build_session_( features: Once::new(), recursion_limit: Once::new(), type_length_limit: Once::new(), - const_eval_stack_frame_limit: 100, + const_eval_stack_frame_limit: OneThread::new(Cell::new(100)), next_node_id: OneThread::new(Cell::new(NodeId::from_u32(1))), allocator_kind: Once::new(), injected_panic_runtime: Once::new(), diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index ce7269d1e7839..46598164d568c 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -489,7 +489,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc debug!("ENTERING({}) {}", self.cur_frame(), self.frame().instance); } - if self.stack.len() > self.tcx.sess.const_eval_stack_frame_limit { + if self.stack.len() > self.tcx.sess.const_eval_stack_frame_limit.get() { err!(StackFrameLimitReached) } else { Ok(()) From 038727fcb61304bab0981eb81540d0482e691246 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 20 Nov 2018 11:44:00 -0500 Subject: [PATCH 2/2] Use LockCell instead of OneThread Miri can be run from multiple rustc threads --- src/librustc/session/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index fadae2c9b9b46..6b2124fdc7a73 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -107,7 +107,7 @@ pub struct Session { pub type_length_limit: Once, /// The maximum number of stackframes allowed in const eval - pub const_eval_stack_frame_limit: OneThread>, + pub const_eval_stack_frame_limit: LockCell, /// The metadata::creader module may inject an allocator/panic_runtime /// dependency if it didn't already find one, and this tracks what was @@ -1159,7 +1159,7 @@ pub fn build_session_( features: Once::new(), recursion_limit: Once::new(), type_length_limit: Once::new(), - const_eval_stack_frame_limit: OneThread::new(Cell::new(100)), + const_eval_stack_frame_limit: LockCell::new(100), next_node_id: OneThread::new(Cell::new(NodeId::from_u32(1))), allocator_kind: Once::new(), injected_panic_runtime: Once::new(),