From 4fc088a0f10e5991b0d7bfb0dfe1a228828f8972 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 27 Nov 2021 23:20:05 +0800 Subject: [PATCH] Fix feature builds. --- src/api/call_fn.rs | 16 +++++++++------- src/api/mod.rs | 3 --- src/func/args.rs | 1 - src/func/mod.rs | 3 --- src/lib.rs | 5 ++--- src/module/resolvers/file.rs | 5 +++-- src/module/resolvers/mod.rs | 2 -- src/optimizer.rs | 16 +++++++++------- src/packages/mod.rs | 4 ---- src/packages/time_basic.rs | 2 -- 10 files changed, 23 insertions(+), 34 deletions(-) diff --git a/src/api/call_fn.rs b/src/api/call_fn.rs index 28b43e1d..67deb9da 100644 --- a/src/api/call_fn.rs +++ b/src/api/call_fn.rs @@ -1,8 +1,12 @@ //! Module that defines the `call_fn` API of [`Engine`]. +#![cfg(not(feature = "no_function"))] use crate::engine::{EvalState, Imports}; +use crate::func::call::ensure_no_data_race; use crate::types::dynamic::Variant; -use crate::{Dynamic, Engine, EvalAltResult, Position, RhaiResult, Scope, AST}; +use crate::{ + Dynamic, Engine, EvalAltResult, FuncArgs, Position, RhaiResult, Scope, StaticVec, AST, +}; use std::any::type_name; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -50,16 +54,15 @@ impl Engine { /// # Ok(()) /// # } /// ``` - #[cfg(not(feature = "no_function"))] #[inline] pub fn call_fn( &self, scope: &mut Scope, ast: &AST, name: impl AsRef, - args: impl crate::FuncArgs, + args: impl FuncArgs, ) -> Result> { - let mut arg_values = crate::StaticVec::new_const(); + let mut arg_values = StaticVec::new_const(); args.parse(&mut arg_values); let result = self.call_fn_raw(scope, ast, true, true, name, None, arg_values)?; @@ -135,7 +138,6 @@ impl Engine { /// # Ok(()) /// # } /// ``` - #[cfg(not(feature = "no_function"))] #[inline] pub fn call_fn_raw( &self, @@ -165,7 +167,7 @@ impl Engine { let name = name.as_ref(); let mut this_ptr = this_ptr; let mut arg_values = arg_values; - let mut args: crate::StaticVec<_> = arg_values.as_mut().iter_mut().collect(); + let mut args: StaticVec<_> = arg_values.as_mut().iter_mut().collect(); let fn_def = ast .lib() @@ -174,7 +176,7 @@ impl Engine { // Check for data race. #[cfg(not(feature = "no_closure"))] - crate::func::call::ensure_no_data_race(name, &mut args, false)?; + ensure_no_data_race(name, &mut args, false)?; let result = self.call_script_fn( scope, diff --git a/src/api/mod.rs b/src/api/mod.rs index 5062496c..14248fe6 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -6,15 +6,12 @@ pub mod run; pub mod compile; -#[cfg(not(feature = "no_std"))] -#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] pub mod files; pub mod register; pub mod call_fn; -#[cfg(not(feature = "unchecked"))] pub mod limits; pub mod events; diff --git a/src/func/args.rs b/src/func/args.rs index 46653724..53538a2f 100644 --- a/src/func/args.rs +++ b/src/func/args.rs @@ -1,6 +1,5 @@ //! Helper module which defines [`FuncArgs`] to make function calling easier. -#![cfg(not(feature = "no_function"))] #![allow(non_snake_case)] use crate::types::dynamic::Variant; diff --git a/src/func/mod.rs b/src/func/mod.rs index 55c7964f..70596732 100644 --- a/src/func/mod.rs +++ b/src/func/mod.rs @@ -1,17 +1,14 @@ //! Module defining mechanisms to handle function calls in Rhai. -#[cfg(not(feature = "no_function"))] pub mod args; pub mod builtin; pub mod call; -#[cfg(not(feature = "no_function"))] pub mod func; pub mod hashing; pub mod native; pub mod plugin; pub mod register; -#[cfg(not(feature = "no_function"))] pub use args::FuncArgs; pub use builtin::{get_builtin_binary_op_fn, get_builtin_op_assignment_fn}; pub use call::FnCallArgs; diff --git a/src/lib.rs b/src/lib.rs index 4aef3c70..55f86a59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,7 +75,6 @@ mod custom_syntax; mod engine; mod func; mod module; -#[cfg(not(feature = "no_optimize"))] mod optimizer; pub mod packages; mod parser; @@ -150,10 +149,10 @@ pub(crate) use func::{ pub use rhai_codegen::*; -pub use func::plugin; +pub use func::{plugin, FuncArgs}; #[cfg(not(feature = "no_function"))] -pub use func::{Func, FuncArgs}; +pub use func::Func; #[cfg(not(feature = "no_function"))] pub use ast::ScriptFnMetadata; diff --git a/src/module/resolvers/file.rs b/src/module/resolvers/file.rs index f5f1717a..d9d567e7 100644 --- a/src/module/resolvers/file.rs +++ b/src/module/resolvers/file.rs @@ -1,8 +1,9 @@ +#![cfg(not(feature = "no_std"))] +#![cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] + use crate::func::native::shared_write_lock; use crate::{Engine, EvalAltResult, Identifier, Module, ModuleResolver, Position, Scope, Shared}; -#[cfg(feature = "no_std")] -use std::prelude::v1::*; use std::{ collections::BTreeMap, io::Error as IoError, diff --git a/src/module/resolvers/mod.rs b/src/module/resolvers/mod.rs index 17f48f99..ed46a379 100644 --- a/src/module/resolvers/mod.rs +++ b/src/module/resolvers/mod.rs @@ -9,8 +9,6 @@ pub use dummy::DummyModuleResolver; mod collection; pub use collection::ModuleResolversCollection; -#[cfg(not(feature = "no_std"))] -#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] mod file; #[cfg(not(feature = "no_std"))] diff --git a/src/optimizer.rs b/src/optimizer.rs index 70094205..36629c6b 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -1,16 +1,18 @@ //! Module implementing the [`AST`] optimizer. +#![cfg(not(feature = "no_optimize"))] -use crate::ast::{Expr, OpAssignment, Stmt, AST_OPTION_FLAGS::*}; +use crate::ast::{Expr, OpAssignment, ScriptFnDef, Stmt, StmtBlock, AST_OPTION_FLAGS::*}; use crate::engine::{ EvalState, Imports, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_PRINT, KEYWORD_TYPE_OF, }; use crate::func::builtin::get_builtin_binary_op_fn; use crate::func::hashing::get_hasher; +use crate::func::native::shared_take_or_clone; use crate::tokenizer::Token; use crate::types::dynamic::AccessMode; use crate::{ calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnPtr, ImmutableString, - Module, Position, Scope, StaticVec, AST, + Module, Position, Scope, Shared, StaticVec, AST, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -1122,7 +1124,7 @@ pub fn optimize_into_ast( engine: &Engine, scope: &Scope, statements: StaticVec, - functions: StaticVec>, + functions: StaticVec>, optimization_level: OptimizationLevel, ) -> AST { let level = if cfg!(feature = "no_optimize") { @@ -1144,14 +1146,14 @@ pub fn optimize_into_ast( _functions .iter() - .map(|fn_def| crate::ast::ScriptFnDef { + .map(|fn_def| ScriptFnDef { name: fn_def.name.clone(), access: fn_def.access, - body: crate::ast::StmtBlock::NONE, + body: StmtBlock::NONE, params: fn_def.params.clone(), lib: None, #[cfg(not(feature = "no_module"))] - mods: crate::engine::Imports::new(), + mods: Imports::new(), #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] comments: None, @@ -1165,7 +1167,7 @@ pub fn optimize_into_ast( _functions .into_iter() .map(|fn_def| { - let mut fn_def = crate::func::native::shared_take_or_clone(fn_def); + let mut fn_def = shared_take_or_clone(fn_def); // Optimize the function body let body = mem::take(fn_def.body.deref_mut()); diff --git a/src/packages/mod.rs b/src/packages/mod.rs index 36344cb3..63bfc5d4 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -3,22 +3,18 @@ use crate::{Module, Shared}; pub(crate) mod arithmetic; -#[cfg(not(feature = "no_index"))] mod array_basic; -#[cfg(not(feature = "no_index"))] mod blob_basic; mod fn_basic; mod iter_basic; mod lang_core; mod logic; -#[cfg(not(feature = "no_object"))] mod map_basic; mod math_basic; mod pkg_core; mod pkg_std; mod string_basic; mod string_more; -#[cfg(not(feature = "no_std"))] mod time_basic; pub use arithmetic::ArithmeticPackage; diff --git a/src/packages/time_basic.rs b/src/packages/time_basic.rs index 7b5bbbcd..c51e340b 100644 --- a/src/packages/time_basic.rs +++ b/src/packages/time_basic.rs @@ -3,8 +3,6 @@ use super::{arithmetic::make_err as make_arithmetic_err, math_basic::MAX_INT}; use crate::plugin::*; use crate::{def_package, Dynamic, EvalAltResult, INT}; -#[cfg(feature = "no_std")] -use std::prelude::v1::*; #[cfg(not(feature = "no_float"))] use crate::FLOAT;