From d511aac7a4c42ee824a0054fa3f83bf79922fd59 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 8 Oct 2020 23:00:01 +0800 Subject: [PATCH] Reduce max call stack size for debug. --- RELEASES.md | 1 + doc/src/safety/max-call-stack.md | 6 +++--- src/engine.rs | 2 +- tests/optimizer.rs | 2 +- tests/stack.rs | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index a3124b96..038d3b2a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -26,6 +26,7 @@ Enhancements ------------ * Many one-liners and few-liners are now marked `#[inline]` or `[inline(always)]`, just in case it helps when LTO is not turned on. +* Default call stack depth for `debug` builds is reduced to 12 (from 16). Version 0.19.0 diff --git a/doc/src/safety/max-call-stack.md b/doc/src/safety/max-call-stack.md index 2d33d653..374dc2a6 100644 --- a/doc/src/safety/max-call-stack.md +++ b/doc/src/safety/max-call-stack.md @@ -6,7 +6,7 @@ Maximum Call Stack Depth Limit How Stack Usage by Scripts ------------------------------- -Rhai by default limits function calls to a maximum depth of 128 levels (16 levels in debug build). +Rhai by default limits function calls to a maximum depth of 128 levels (12 levels in debug build). This limit may be changed via the `Engine::set_max_call_levels` method. @@ -17,9 +17,9 @@ This check can be disabled via the [`unchecked`] feature for higher performance ```rust let mut engine = Engine::new(); -engine.set_max_call_levels(10); // allow only up to 10 levels of function calls +engine.set_max_call_levels(10); // allow only up to 10 levels of function calls -engine.set_max_call_levels(0); // allow no function calls at all (max depth = zero) +engine.set_max_call_levels(0); // allow no function calls at all (max depth = zero) ``` diff --git a/src/engine.rs b/src/engine.rs index 9708f365..156551a9 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -75,7 +75,7 @@ pub type Imports = Vec<(ImmutableString, Module)>; #[cfg(not(feature = "unchecked"))] #[cfg(debug_assertions)] -pub const MAX_CALL_STACK_DEPTH: usize = 16; +pub const MAX_CALL_STACK_DEPTH: usize = 12; #[cfg(not(feature = "unchecked"))] #[cfg(debug_assertions)] pub const MAX_EXPR_DEPTH: usize = 32; diff --git a/tests/optimizer.rs b/tests/optimizer.rs index da224262..4e66552c 100644 --- a/tests/optimizer.rs +++ b/tests/optimizer.rs @@ -1,6 +1,6 @@ #![cfg(not(feature = "no_optimize"))] -use rhai::{Engine, EvalAltResult, OptimizationLevel, INT, RegisterFn}; +use rhai::{Engine, EvalAltResult, OptimizationLevel, RegisterFn, INT}; #[test] fn test_optimizer_run() -> Result<(), Box> { diff --git a/tests/stack.rs b/tests/stack.rs index b7ff9a57..03edee0e 100644 --- a/tests/stack.rs +++ b/tests/stack.rs @@ -10,10 +10,10 @@ fn test_stack_overflow_fn_calls() -> Result<(), Box> { engine.eval::( r" fn foo(n) { if n <= 1 { 0 } else { n + foo(n-1) } } - foo(8) + foo(7) ", )?, - 35 + 27 ); #[cfg(not(feature = "unchecked"))]