diff --git a/src/api/call_fn.rs b/src/api/call_fn.rs index 1a9e2347..32510f60 100644 --- a/src/api/call_fn.rs +++ b/src/api/call_fn.rs @@ -4,8 +4,8 @@ use crate::eval::{Caches, GlobalRuntimeState}; use crate::types::dynamic::Variant; use crate::{ - reify, Dynamic, Engine, FuncArgs, Position, RhaiResult, RhaiResultOf, Scope, StaticVec, AST, - ERR, + reify, Dynamic, Engine, FuncArgs, Position, RhaiResult, RhaiResultOf, Scope, Shared, StaticVec, + AST, ERR, }; use std::any::{type_name, TypeId}; #[cfg(feature = "no_std")] @@ -248,7 +248,7 @@ impl Engine { arg_values: &mut [Dynamic], ) -> RhaiResult { let statements = ast.statements(); - let lib = &[ast.as_ref()]; + let lib = &[AsRef::>::as_ref(ast).clone()]; let mut this_ptr = this_ptr; let orig_scope_len = scope.len(); diff --git a/src/api/eval.rs b/src/api/eval.rs index ffef8623..02f21831 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -195,7 +195,7 @@ impl Engine { global.debugger.status = crate::eval::DebuggerStatus::Terminate; let lib = &[ #[cfg(not(feature = "no_function"))] - ast.as_ref(), + AsRef::>::as_ref(ast).clone(), ]; let node = &crate::ast::Stmt::Noop(Position::NONE); self.run_debugger(global, caches, lib, 0, scope, &mut None, node)?; @@ -234,7 +234,7 @@ impl Engine { let mut _lib = &[ #[cfg(not(feature = "no_function"))] - ast.as_ref(), + AsRef::>::as_ref(ast).clone(), ][..]; #[cfg(not(feature = "no_function"))] if !ast.has_functions() { @@ -264,7 +264,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&crate::Module], + lib: &[crate::Shared], level: usize, scope: &mut Scope, statements: &[crate::ast::Stmt], diff --git a/src/api/run.rs b/src/api/run.rs index effdd4b6..96faee2e 100644 --- a/src/api/run.rs +++ b/src/api/run.rs @@ -2,7 +2,7 @@ use crate::eval::{Caches, GlobalRuntimeState}; use crate::parser::ParseState; -use crate::{Engine, Module, RhaiResultOf, Scope, AST}; +use crate::{Engine, RhaiResultOf, Scope, AST}; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -124,9 +124,9 @@ impl Engine { if !statements.is_empty() { let lib = [ #[cfg(not(feature = "no_function"))] - ast.as_ref(), + AsRef::>::as_ref(ast).clone(), ]; - let lib = if lib.first().map_or(true, |m: &&Module| m.is_empty()) { + let lib = if lib.first().map_or(true, |m| m.is_empty()) { &lib[0..0] } else { &lib @@ -139,7 +139,7 @@ impl Engine { global.debugger.status = crate::eval::DebuggerStatus::Terminate; let lib = &[ #[cfg(not(feature = "no_function"))] - ast.as_ref(), + AsRef::>::as_ref(ast).clone(), ]; let node = &crate::ast::Stmt::Noop(crate::Position::NONE); self.run_debugger(global, caches, lib, 0, scope, &mut None, node)?; diff --git a/src/eval/cache.rs b/src/eval/cache.rs index b71eb8cf..ee4f07a3 100644 --- a/src/eval/cache.rs +++ b/src/eval/cache.rs @@ -3,7 +3,6 @@ use crate::func::{CallableFunction, StraightHashMap}; use crate::types::BloomFilterU64; use crate::{ImmutableString, StaticVec}; -use std::marker::PhantomData; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -45,21 +44,18 @@ impl FnResolutionCache { /// The following caches are contained inside this type: /// * A stack of [function resolution caches][FnResolutionCache] #[derive(Debug, Clone)] -pub struct Caches<'a> { +pub struct Caches { /// Stack of [function resolution caches][FnResolutionCache]. stack: StaticVec, - /// Take care of the lifetime parameter. - dummy: PhantomData<&'a ()>, } -impl Caches<'_> { +impl Caches { /// Create an empty [`Caches`]. #[inline(always)] #[must_use] pub const fn new() -> Self { Self { stack: StaticVec::new_const(), - dummy: PhantomData, } } /// Get the number of function resolution cache(s) in the stack. diff --git a/src/eval/chaining.rs b/src/eval/chaining.rs index ecc40fc7..cf51a465 100644 --- a/src/eval/chaining.rs +++ b/src/eval/chaining.rs @@ -4,7 +4,9 @@ use super::{Caches, GlobalRuntimeState, Target}; use crate::ast::{ASTFlags, Expr, OpAssignment}; use crate::types::dynamic::Union; -use crate::{Dynamic, Engine, FnArgsVec, Module, Position, RhaiResult, RhaiResultOf, Scope, ERR}; +use crate::{ + Dynamic, Engine, FnArgsVec, Module, Position, RhaiResult, RhaiResultOf, Scope, Shared, ERR, +}; use std::hash::Hash; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -40,7 +42,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, this_ptr: &mut Option<&mut Dynamic>, target: &mut Target, @@ -555,7 +557,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -646,7 +648,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -758,7 +760,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, target: &mut Dynamic, idx: &mut Dynamic, @@ -781,7 +783,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, target: &mut Dynamic, idx: &mut Dynamic, @@ -805,7 +807,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, target: &'t mut Dynamic, idx: &mut Dynamic, diff --git a/src/eval/debugger.rs b/src/eval/debugger.rs index 9b516fdf..3048e5bc 100644 --- a/src/eval/debugger.rs +++ b/src/eval/debugger.rs @@ -4,7 +4,7 @@ use super::{Caches, EvalContext, GlobalRuntimeState}; use crate::ast::{ASTNode, Expr, Stmt}; use crate::{ - Dynamic, Engine, EvalAltResult, ImmutableString, Module, Position, RhaiResultOf, Scope, + Dynamic, Engine, EvalAltResult, ImmutableString, Module, Position, RhaiResultOf, Scope, Shared, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -413,7 +413,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -440,7 +440,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -463,7 +463,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -510,7 +510,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, diff --git a/src/eval/eval_context.rs b/src/eval/eval_context.rs index 172720cd..99456ce1 100644 --- a/src/eval/eval_context.rs +++ b/src/eval/eval_context.rs @@ -1,39 +1,39 @@ //! Evaluation context. use super::{Caches, GlobalRuntimeState}; -use crate::{Dynamic, Engine, Module, Scope}; +use crate::{Dynamic, Engine, Module, Scope, Shared}; #[cfg(feature = "no_std")] use std::prelude::v1::*; /// Context of a script evaluation process. #[derive(Debug)] #[allow(dead_code)] -pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> { +pub struct EvalContext<'a, 's, 'ps, 'g, 'c, 't, 'pt> { /// The current [`Engine`]. engine: &'a Engine, /// The current [`Scope`]. scope: &'s mut Scope<'ps>, /// The current [`GlobalRuntimeState`]. - global: &'g mut GlobalRuntimeState<'pg>, + global: &'g mut GlobalRuntimeState, /// The current [caches][Caches], if available. - caches: Option<&'c mut Caches<'pc>>, + caches: Option<&'c mut Caches>, /// The current stack of imported [modules][Module]. - lib: &'a [&'a Module], + lib: &'a [Shared], /// The current bound `this` pointer, if any. this_ptr: &'t mut Option<&'pt mut Dynamic>, /// The current nesting level of function calls. level: usize, } -impl<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> { +impl<'a, 's, 'ps, 'g, 'c, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'c, 't, 'pt> { /// Create a new [`EvalContext`]. #[inline(always)] #[must_use] pub fn new( engine: &'a Engine, - global: &'g mut GlobalRuntimeState<'pg>, - caches: Option<&'c mut Caches<'pc>>, - lib: &'a [&'a Module], + global: &'g mut GlobalRuntimeState, + caches: Option<&'c mut Caches>, + lib: &'a [Shared], level: usize, scope: &'s mut Scope<'ps>, this_ptr: &'t mut Option<&'pt mut Dynamic>, @@ -104,20 +104,20 @@ impl<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, ' #[cfg(feature = "internals")] #[inline(always)] #[must_use] - pub fn global_runtime_state_mut(&mut self) -> &mut &'g mut GlobalRuntimeState<'pg> { + pub fn global_runtime_state_mut(&mut self) -> &mut &'g mut GlobalRuntimeState { &mut self.global } /// Get an iterator over the namespaces containing definition of all script-defined functions. #[inline] pub fn iter_namespaces(&self) -> impl Iterator { - self.lib.iter().copied() + self.lib.iter().map(|m| m.as_ref()) } /// _(internals)_ The current set of namespaces containing definitions of all script-defined functions. /// Exported under the `internals` feature only. #[cfg(feature = "internals")] #[inline(always)] #[must_use] - pub const fn namespaces(&self) -> &[&Module] { + pub const fn namespaces(&self) -> &[Shared] { self.lib } /// The current bound `this` pointer, if any. diff --git a/src/eval/expr.rs b/src/eval/expr.rs index 0a9558da..afa47ce4 100644 --- a/src/eval/expr.rs +++ b/src/eval/expr.rs @@ -4,7 +4,7 @@ use super::{Caches, EvalContext, GlobalRuntimeState, Target}; use crate::ast::{Expr, OpAssignment}; use crate::engine::{KEYWORD_THIS, OP_CONCAT}; use crate::types::dynamic::AccessMode; -use crate::{Dynamic, Engine, Module, Position, RhaiResult, RhaiResultOf, Scope, ERR}; +use crate::{Dynamic, Engine, Module, Position, RhaiResult, RhaiResultOf, Scope, Shared, ERR}; use std::num::NonZeroUsize; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -18,7 +18,7 @@ impl Engine { &self, global: &GlobalRuntimeState, namespace: &crate::ast::Namespace, - ) -> Option> { + ) -> Option> { assert!(!namespace.is_empty()); let root = namespace.root(); @@ -51,7 +51,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &'s mut Scope, this_ptr: &'s mut Option<&mut Dynamic>, @@ -137,7 +137,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &'s mut Scope, this_ptr: &'s mut Option<&mut Dynamic>, @@ -160,7 +160,7 @@ impl Engine { Expr::Variable(v, None, pos) if lib .iter() - .flat_map(|&m| m.iter_script_fn()) + .flat_map(|m| m.iter_script_fn()) .any(|(_, _, f, ..)| f == v.3.as_str()) => { let val: Dynamic = @@ -221,7 +221,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, diff --git a/src/eval/global_state.rs b/src/eval/global_state.rs index db4c5332..935434ef 100644 --- a/src/eval/global_state.rs +++ b/src/eval/global_state.rs @@ -1,9 +1,9 @@ //! Global runtime state. use crate::{Dynamic, Engine, ImmutableString}; +use std::fmt; #[cfg(feature = "no_std")] use std::prelude::v1::*; -use std::{fmt, marker::PhantomData}; /// Collection of globally-defined constants. #[cfg(not(feature = "no_module"))] @@ -22,7 +22,7 @@ pub type GlobalConstants = // Most usage will be looking up a particular key from the list and then getting the module that // corresponds to that key. #[derive(Clone)] -pub struct GlobalRuntimeState<'a> { +pub struct GlobalRuntimeState { /// Names of imported [modules][crate::Module]. #[cfg(not(feature = "no_module"))] imports: crate::StaticVec, @@ -70,11 +70,9 @@ pub struct GlobalRuntimeState<'a> { /// Debugging interface. #[cfg(feature = "debugging")] pub debugger: super::Debugger, - /// Take care of the lifetime parameter. - dummy: PhantomData<&'a ()>, } -impl GlobalRuntimeState<'_> { +impl GlobalRuntimeState { /// Create a new [`GlobalRuntimeState`] based on an [`Engine`]. #[inline(always)] #[must_use] @@ -112,8 +110,6 @@ impl GlobalRuntimeState<'_> { None => Dynamic::UNIT, }, ), - - dummy: PhantomData::default(), } } /// Get the length of the stack of globally-imported [modules][crate::Module]. @@ -319,7 +315,7 @@ impl GlobalRuntimeState<'_> { } #[cfg(not(feature = "no_module"))] -impl IntoIterator for GlobalRuntimeState<'_> { +impl IntoIterator for GlobalRuntimeState { type Item = (ImmutableString, crate::Shared); type IntoIter = std::iter::Rev< std::iter::Zip< @@ -334,7 +330,7 @@ impl IntoIterator for GlobalRuntimeState<'_> { } #[cfg(not(feature = "no_module"))] -impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> { +impl<'a> IntoIterator for &'a GlobalRuntimeState { type Item = (&'a ImmutableString, &'a crate::Shared); type IntoIter = std::iter::Rev< std::iter::Zip< @@ -350,7 +346,7 @@ impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> { #[cfg(not(feature = "no_module"))] impl, M: Into>> Extend<(K, M)> - for GlobalRuntimeState<'_> + for GlobalRuntimeState { #[inline] fn extend>(&mut self, iter: T) { @@ -361,7 +357,7 @@ impl, M: Into>> Extend<(K, } } -impl fmt::Debug for GlobalRuntimeState<'_> { +impl fmt::Debug for GlobalRuntimeState { #[cold] #[inline(never)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/eval/stmt.rs b/src/eval/stmt.rs index 5bf03093..9ccde0a0 100644 --- a/src/eval/stmt.rs +++ b/src/eval/stmt.rs @@ -8,7 +8,8 @@ use crate::ast::{ use crate::func::{get_builtin_op_assignment_fn, get_hasher}; use crate::types::dynamic::{AccessMode, Union}; use crate::{ - Dynamic, Engine, ImmutableString, Module, Position, RhaiResult, RhaiResultOf, Scope, ERR, INT, + Dynamic, Engine, ImmutableString, Module, Position, RhaiResult, RhaiResultOf, Scope, Shared, + ERR, INT, }; use std::hash::{Hash, Hasher}; #[cfg(feature = "no_std")] @@ -27,7 +28,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -112,7 +113,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, op_info: &OpAssignment, target: &mut Target, @@ -196,7 +197,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -1018,7 +1019,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, statements: &[Stmt], diff --git a/src/func/call.rs b/src/func/call.rs index 817a8d7b..ff95e3a4 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -11,7 +11,7 @@ use crate::eval::{Caches, FnResolutionCacheEntry, GlobalRuntimeState}; use crate::tokenizer::{is_valid_function_name, Token}; use crate::{ calc_fn_hash, calc_fn_hash_full, Dynamic, Engine, FnArgsVec, FnPtr, ImmutableString, Module, - OptimizationLevel, Position, RhaiError, RhaiResult, RhaiResultOf, Scope, ERR, + OptimizationLevel, Position, RhaiError, RhaiResult, RhaiResultOf, Scope, Shared, ERR, }; #[cfg(feature = "no_std")] use hashbrown::hash_map::Entry; @@ -166,7 +166,7 @@ impl Engine { _global: &GlobalRuntimeState, caches: &'s mut Caches, local_entry: &'s mut Option, - lib: &[&Module], + lib: &[Shared], op_token: Option<&Token>, hash_base: u64, args: Option<&mut FnCallArgs>, @@ -193,8 +193,7 @@ impl Engine { loop { let func = lib .iter() - .copied() - .chain(self.global_modules.iter().map(|m| m.as_ref())) + .chain(self.global_modules.iter()) .find_map(|m| m.get_fn(hash).map(|f| (f, m.id_raw()))); #[cfg(not(feature = "no_module"))] @@ -323,7 +322,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, name: &str, op_token: Option<&Token>, @@ -538,7 +537,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, _scope: Option<&mut Scope>, fn_name: &str, @@ -705,7 +704,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -742,7 +741,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, fn_name: &str, mut hash: FnCallHashes, @@ -967,7 +966,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -1258,7 +1257,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -1442,7 +1441,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, script: &str, @@ -1487,7 +1486,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, diff --git a/src/func/mod.rs b/src/func/mod.rs index 6120764d..d5659854 100644 --- a/src/func/mod.rs +++ b/src/func/mod.rs @@ -22,6 +22,8 @@ pub use callable_function::CallableFunction; #[cfg(not(feature = "no_function"))] pub use func::Func; pub use hashing::{calc_fn_hash, calc_fn_hash_full, calc_var_hash, get_hasher, StraightHashMap}; +#[cfg(feature = "internals")] +pub use native::NativeCallContextStore; pub use native::{ locked_read, locked_write, shared_get_mut, shared_make_mut, shared_take, shared_take_or_clone, shared_try_take, FnAny, FnPlugin, IteratorFn, Locked, NativeCallContext, SendSync, Shared, diff --git a/src/func/script.rs b/src/func/script.rs index b80d74ae..06fa916a 100644 --- a/src/func/script.rs +++ b/src/func/script.rs @@ -4,7 +4,7 @@ use super::call::FnCallArgs; use crate::ast::ScriptFnDef; use crate::eval::{Caches, GlobalRuntimeState}; -use crate::{Dynamic, Engine, Module, Position, RhaiError, RhaiResult, Scope, ERR}; +use crate::{Dynamic, Engine, Module, Position, RhaiError, RhaiResult, Scope, Shared, ERR}; use std::mem; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -26,7 +26,7 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], level: usize, scope: &mut Scope, this_ptr: &mut Option<&mut Dynamic>, @@ -127,8 +127,8 @@ impl Engine { lib } else { caches.push_fn_resolution_cache(); - lib_merged.push(&**fn_lib); - lib_merged.extend(lib.iter().copied()); + lib_merged.push(fn_lib.clone()); + lib_merged.extend(lib.iter().cloned()); &lib_merged }, Some(mem::replace(&mut global.constants, constants.clone())), @@ -230,7 +230,7 @@ impl Engine { &self, _global: Option<&GlobalRuntimeState>, caches: &mut Caches, - lib: &[&Module], + lib: &[Shared], hash_script: u64, ) -> bool { let cache = caches.fn_resolution_cache_mut(); diff --git a/src/optimizer.rs b/src/optimizer.rs index 4428c6da..aa204777 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -56,12 +56,12 @@ struct OptimizerState<'a> { /// An [`Engine`] instance for eager function evaluation. engine: &'a Engine, /// The global runtime state. - global: GlobalRuntimeState<'a>, + global: GlobalRuntimeState, /// Function resolution caches. - caches: Caches<'a>, + caches: Caches, /// [Module][crate::Module] containing script-defined functions. #[cfg(not(feature = "no_function"))] - lib: &'a [&'a crate::Module], + lib: &'a [crate::Shared], /// Optimization level. optimization_level: OptimizationLevel, } @@ -71,7 +71,7 @@ impl<'a> OptimizerState<'a> { #[inline(always)] pub fn new( engine: &'a Engine, - #[cfg(not(feature = "no_function"))] lib: &'a [&'a crate::Module], + #[cfg(not(feature = "no_function"))] lib: &'a [crate::Shared], optimization_level: OptimizationLevel, ) -> Self { Self { @@ -1189,7 +1189,7 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) { => { // First search for script-defined functions (can override built-in) #[cfg(not(feature = "no_function"))] - let has_script_fn = !x.hashes.is_native_only() && state.lib.iter().find_map(|&m| m.get_script_fn(&x.name, x.args.len())).is_some(); + let has_script_fn = !x.hashes.is_native_only() && state.lib.iter().find_map(|m| m.get_script_fn(&x.name, x.args.len())).is_some(); #[cfg(feature = "no_function")] let has_script_fn = false; @@ -1263,7 +1263,7 @@ fn optimize_top_level( statements: StmtBlockContainer, engine: &Engine, scope: &Scope, - #[cfg(not(feature = "no_function"))] lib: &[&crate::Module], + #[cfg(not(feature = "no_function"))] lib: &[crate::Shared], optimization_level: OptimizationLevel, ) -> StmtBlockContainer { let mut statements = statements; @@ -1317,7 +1317,7 @@ pub fn optimize_into_ast( let mut statements = statements; #[cfg(not(feature = "no_function"))] - let lib = { + let lib: crate::Shared<_> = { let mut module = crate::Module::new(); if optimization_level != OptimizationLevel::None { @@ -1338,7 +1338,7 @@ pub fn optimize_into_ast( }); } - let lib2 = &[&lib2]; + let lib2 = &[lib2.into()]; for fn_def in functions { let mut fn_def = crate::func::shared_take_or_clone(fn_def); @@ -1356,7 +1356,7 @@ pub fn optimize_into_ast( } } - module + module.into() }; statements.shrink_to_fit(); @@ -1369,7 +1369,7 @@ pub fn optimize_into_ast( engine, scope, #[cfg(not(feature = "no_function"))] - &[&lib], + &[lib.clone()], optimization_level, ), }, diff --git a/src/parser.rs b/src/parser.rs index f0c3843f..ee107089 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -55,7 +55,7 @@ pub struct ParseState<'e> { /// External [scope][Scope] with constants. pub scope: &'e Scope<'e>, /// Global runtime state. - pub global: GlobalRuntimeState<'e>, + pub global: GlobalRuntimeState, /// Encapsulates a local stack with variable names to simulate an actual runtime scope. pub stack: Scope<'e>, /// Size of the local variables stack upon entry of the current block scope. diff --git a/src/types/fn_ptr.rs b/src/types/fn_ptr.rs index 5938b7a6..810dd5a8 100644 --- a/src/types/fn_ptr.rs +++ b/src/types/fn_ptr.rs @@ -3,8 +3,8 @@ use crate::tokenizer::is_valid_function_name; use crate::types::dynamic::Variant; use crate::{ - Dynamic, Engine, FuncArgs, ImmutableString, Module, NativeCallContext, Position, RhaiError, - RhaiResult, RhaiResultOf, StaticVec, AST, ERR, + Dynamic, Engine, FuncArgs, ImmutableString, NativeCallContext, Position, RhaiError, RhaiResult, + RhaiResultOf, StaticVec, AST, ERR, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -152,13 +152,16 @@ impl FnPtr { let lib = [ #[cfg(not(feature = "no_function"))] - _ast.as_ref(), + AsRef::>::as_ref(ast).clone(), ]; - let lib = if lib.first().map_or(true, |m: &&Module| m.is_empty()) { + let lib = if lib.first().map_or(true, |m| m.is_empty()) { &lib[0..0] } else { &lib }; + #[cfg(feature = "no_function")] + let lib = &[]; + #[allow(deprecated)] let ctx = NativeCallContext::new(engine, self.fn_name(), lib);