diff --git a/src/api/compile.rs b/src/api/compile.rs index d10ede04..9908e4b9 100644 --- a/src/api/compile.rs +++ b/src/api/compile.rs @@ -1,7 +1,7 @@ //! Module that defines the public compilation API of [`Engine`]. use crate::parser::{ParseResult, ParseState}; -use crate::{Engine, Scope, AST}; +use crate::{Engine, OptimizationLevel, Scope, AST}; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -196,12 +196,7 @@ impl Engine { scope: &Scope, scripts: impl AsRef<[S]>, ) -> ParseResult { - self.compile_with_scope_and_optimization_level( - scope, - scripts, - #[cfg(not(feature = "no_optimize"))] - self.optimization_level, - ) + self.compile_with_scope_and_optimization_level(scope, scripts, self.optimization_level) } /// Join a list of strings and compile into an [`AST`] using own scope at a specific optimization level. /// @@ -215,7 +210,7 @@ impl Engine { &self, scope: &Scope, scripts: impl AsRef<[S]>, - #[cfg(not(feature = "no_optimize"))] optimization_level: crate::OptimizationLevel, + optimization_level: OptimizationLevel, ) -> ParseResult { let (stream, tokenizer_control) = self.lex_raw( scripts.as_ref(), @@ -226,7 +221,6 @@ impl Engine { &mut stream.peekable(), &mut state, scope, - #[cfg(not(feature = "no_optimize"))] optimization_level, ) } @@ -298,13 +292,7 @@ impl Engine { let mut peekable = stream.peekable(); let mut state = ParseState::new(self, tokenizer_control); - self.parse_global_expr( - &mut peekable, - &mut state, - scope, - #[cfg(not(feature = "no_optimize"))] - self.optimization_level, - ) + self.parse_global_expr(&mut peekable, &mut state, scope, self.optimization_level) } /// Parse a JSON string into an [object map][crate::Map]. /// This is a light-weight alternative to using, say, @@ -400,7 +388,9 @@ impl Engine { &mut state, &scope, #[cfg(not(feature = "no_optimize"))] - crate::OptimizationLevel::None, + OptimizationLevel::None, + #[cfg(feature = "no_optimize")] + OptimizationLevel::default(), )?; if has_null { scope.push_constant("null", ()); diff --git a/src/api/eval.rs b/src/api/eval.rs index 7e6eb83c..ff5c7254 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -3,7 +3,9 @@ use crate::eval::{EvalState, GlobalRuntimeState}; use crate::parser::ParseState; use crate::types::dynamic::Variant; -use crate::{Dynamic, Engine, Module, Position, RhaiResult, RhaiResultOf, Scope, AST, ERR}; +use crate::{ + Dynamic, Engine, Module, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, AST, ERR, +}; use std::any::type_name; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -64,7 +66,6 @@ impl Engine { let ast = self.compile_with_scope_and_optimization_level( scope, &[script], - #[cfg(not(feature = "no_optimize"))] self.optimization_level, )?; self.eval_ast_with_scope(scope, &ast) @@ -122,7 +123,9 @@ impl Engine { &mut state, scope, #[cfg(not(feature = "no_optimize"))] - crate::OptimizationLevel::None, + OptimizationLevel::None, + #[cfg(feature = "no_optimize")] + OptimizationLevel::default(), )?; self.eval_ast_with_scope(scope, &ast) diff --git a/src/api/run.rs b/src/api/run.rs index 7c556064..bad510a7 100644 --- a/src/api/run.rs +++ b/src/api/run.rs @@ -30,7 +30,6 @@ impl Engine { &mut stream.peekable(), &mut state, scope, - #[cfg(not(feature = "no_optimize"))] self.optimization_level, )?; diff --git a/src/bin/rhai-run.rs b/src/bin/rhai-run.rs index 567d4b45..257a7b08 100644 --- a/src/bin/rhai-run.rs +++ b/src/bin/rhai-run.rs @@ -1,8 +1,5 @@ use rhai::{Engine, EvalAltResult, Position}; -#[cfg(not(feature = "no_optimize"))] -use rhai::OptimizationLevel; - use std::{env, fs::File, io::Read, path::Path, process::exit}; fn eprint_error(input: &str, mut err: EvalAltResult) { @@ -53,7 +50,7 @@ fn main() { let mut engine = Engine::new(); #[cfg(not(feature = "no_optimize"))] - engine.set_optimization_level(OptimizationLevel::Full); + engine.set_optimization_level(rhai::OptimizationLevel::Full); let mut f = match File::open(&filename) { Err(err) => { diff --git a/src/engine.rs b/src/engine.rs index 86fb6859..e281c77c 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -8,7 +8,8 @@ use crate::packages::{Package, StandardPackage}; use crate::tokenizer::Token; use crate::types::dynamic::Union; use crate::{ - Dynamic, Identifier, ImmutableString, Module, Position, RhaiResult, Shared, StaticVec, + Dynamic, Identifier, ImmutableString, Module, OptimizationLevel, Position, RhaiResult, Shared, + StaticVec, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -131,8 +132,7 @@ pub struct Engine { pub(crate) progress: Option>, /// Optimize the [`AST`][crate::AST] after compilation. - #[cfg(not(feature = "no_optimize"))] - pub(crate) optimization_level: crate::OptimizationLevel, + pub(crate) optimization_level: OptimizationLevel, /// Language options. pub(crate) options: crate::api::options::LanguageOptions, @@ -287,8 +287,7 @@ impl Engine { #[cfg(not(feature = "unchecked"))] progress: None, - #[cfg(not(feature = "no_optimize"))] - optimization_level: crate::OptimizationLevel::default(), + optimization_level: OptimizationLevel::default(), options: crate::api::options::LanguageOptions::new(), diff --git a/src/eval/data_check.rs b/src/eval/data_check.rs index 4d5e1f78..c09197d2 100644 --- a/src/eval/data_check.rs +++ b/src/eval/data_check.rs @@ -10,7 +10,7 @@ use std::prelude::v1::*; impl Engine { /// Recursively calculate the sizes of a value. /// - /// Sizes returned are `(`[`Array`][crate::Array], [`Map`][crate::Map] and `String)`. + /// Sizes returned are `(` [`Array`][crate::Array], [`Map`][crate::Map] and [`String`] `)`. /// /// # Panics /// diff --git a/src/func/call.rs b/src/func/call.rs index e688178a..fdd6c932 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -12,7 +12,8 @@ use crate::engine::{ use crate::eval::{EvalState, GlobalRuntimeState}; use crate::{ calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnArgsVec, FnPtr, - Identifier, ImmutableString, Module, Position, RhaiResult, RhaiResultOf, Scope, ERR, + Identifier, ImmutableString, Module, OptimizationLevel, Position, RhaiResult, RhaiResultOf, + Scope, ERR, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -1450,7 +1451,9 @@ impl Engine { &Scope::new(), &[script], #[cfg(not(feature = "no_optimize"))] - crate::OptimizationLevel::None, + OptimizationLevel::None, + #[cfg(feature = "no_optimize")] + OptimizationLevel::default(), )?; // If new functions are defined within the eval string, it is an error diff --git a/src/lib.rs b/src/lib.rs index 883fe258..18061326 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -233,6 +233,10 @@ pub mod serde; #[cfg(not(feature = "no_optimize"))] pub use optimizer::OptimizationLevel; +/// Placeholder for the optimization level. +#[cfg(feature = "no_optimize")] +pub type OptimizationLevel = (); + // Expose internal data structures. #[cfg(feature = "internals")] diff --git a/src/parser.rs b/src/parser.rs index ad02c52c..c7346f05 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -16,7 +16,7 @@ use crate::types::dynamic::AccessMode; use crate::types::StringsInterner; use crate::{ calc_fn_hash, Dynamic, Engine, ExclusiveRange, Identifier, ImmutableString, InclusiveRange, - LexError, ParseError, Position, Scope, Shared, StaticVec, AST, INT, PERR, + LexError, OptimizationLevel, ParseError, Position, Scope, Shared, StaticVec, AST, INT, PERR, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -3387,9 +3387,10 @@ impl Engine { input: &mut TokenStream, state: &mut ParseState, scope: &Scope, - #[cfg(not(feature = "no_optimize"))] optimization_level: crate::OptimizationLevel, + optimization_level: OptimizationLevel, ) -> ParseResult { let _scope = scope; + let _optimization_level = optimization_level; let mut functions = BTreeMap::new(); let settings = ParseSettings { @@ -3517,9 +3518,11 @@ impl Engine { input: &mut TokenStream, state: &mut ParseState, scope: &Scope, - #[cfg(not(feature = "no_optimize"))] optimization_level: crate::OptimizationLevel, + optimization_level: OptimizationLevel, ) -> ParseResult { let _scope = scope; + let _optimization_level = optimization_level; + let (statements, _lib) = self.parse_global_level(input, state)?; #[cfg(not(feature = "no_optimize"))]