diff --git a/src/eval/cache.rs b/src/eval/cache.rs index 8b552280..c792a4ff 100644 --- a/src/eval/cache.rs +++ b/src/eval/cache.rs @@ -2,9 +2,9 @@ use crate::func::CallableFunction; use crate::{Identifier, StaticVec}; -use std::collections::BTreeMap; #[cfg(feature = "no_std")] use std::prelude::v1::*; +use std::{collections::BTreeMap, marker::PhantomData}; /// _(internals)_ An entry in a function resolution cache. /// Exported under the `internals` feature only. @@ -29,14 +29,14 @@ pub type FnResolutionCache = BTreeMap>; /// The following caches are contained inside this type: /// * A stack of [function resolution caches][FnResolutionCache] #[derive(Debug, Clone)] -pub struct Caches(StaticVec); +pub struct Caches<'a>(StaticVec, PhantomData<&'a ()>); -impl Caches { +impl Caches<'_> { /// Create an empty [`Caches`]. #[inline(always)] #[must_use] pub const fn new() -> Self { - Self(StaticVec::new_const()) + Self(StaticVec::new_const(), PhantomData) } /// Get the number of function resolution cache(s) in the stack. #[inline(always)] diff --git a/src/eval/eval_context.rs b/src/eval/eval_context.rs index 42041fb7..150b19e4 100644 --- a/src/eval/eval_context.rs +++ b/src/eval/eval_context.rs @@ -7,7 +7,7 @@ use std::prelude::v1::*; /// Context of a script evaluation process. #[derive(Debug)] -pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> { +pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> { /// The current [`Engine`]. engine: &'a Engine, /// The current [`Scope`]. @@ -15,7 +15,7 @@ pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> { /// The current [`GlobalRuntimeState`]. global: &'g mut GlobalRuntimeState<'pg>, /// The current [caches][Caches], if available. - caches: Option<&'c mut Caches>, + caches: Option<&'c mut Caches<'pc>>, /// The current stack of imported [modules][Module]. lib: &'a [&'a Module], /// The current bound `this` pointer, if any. @@ -24,7 +24,7 @@ pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> { level: usize, } -impl<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> { +impl<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> { /// Create a new [`EvalContext`]. #[inline(always)] #[must_use] @@ -32,7 +32,7 @@ impl<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't engine: &'a Engine, scope: &'s mut Scope<'ps>, global: &'g mut GlobalRuntimeState<'pg>, - caches: Option<&'c mut Caches>, + caches: Option<&'c mut Caches<'pc>>, lib: &'a [&'a Module], this_ptr: &'t mut Option<&'pt mut Dynamic>, level: usize, diff --git a/src/optimizer.rs b/src/optimizer.rs index 69731719..fe3e9101 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -55,7 +55,7 @@ struct OptimizerState<'a> { /// The global runtime state. global: GlobalRuntimeState<'a>, /// Function resolution caches. - caches: Caches, + caches: Caches<'a>, /// [Module][crate::Module] containing script-defined functions. #[cfg(not(feature = "no_function"))] lib: &'a [&'a crate::Module],