Add lifetime to Caches.
This commit is contained in:
parent
e4d492c727
commit
07d3dd6882
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
use crate::func::CallableFunction;
|
use crate::func::CallableFunction;
|
||||||
use crate::{Identifier, StaticVec};
|
use crate::{Identifier, StaticVec};
|
||||||
use std::collections::BTreeMap;
|
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
|
use std::{collections::BTreeMap, marker::PhantomData};
|
||||||
|
|
||||||
/// _(internals)_ An entry in a function resolution cache.
|
/// _(internals)_ An entry in a function resolution cache.
|
||||||
/// Exported under the `internals` feature only.
|
/// Exported under the `internals` feature only.
|
||||||
@ -29,14 +29,14 @@ pub type FnResolutionCache = BTreeMap<u64, Option<FnResolutionCacheEntry>>;
|
|||||||
/// The following caches are contained inside this type:
|
/// The following caches are contained inside this type:
|
||||||
/// * A stack of [function resolution caches][FnResolutionCache]
|
/// * A stack of [function resolution caches][FnResolutionCache]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Caches(StaticVec<FnResolutionCache>);
|
pub struct Caches<'a>(StaticVec<FnResolutionCache>, PhantomData<&'a ()>);
|
||||||
|
|
||||||
impl Caches {
|
impl Caches<'_> {
|
||||||
/// Create an empty [`Caches`].
|
/// Create an empty [`Caches`].
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn new() -> Self {
|
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.
|
/// Get the number of function resolution cache(s) in the stack.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -7,7 +7,7 @@ use std::prelude::v1::*;
|
|||||||
|
|
||||||
/// Context of a script evaluation process.
|
/// Context of a script evaluation process.
|
||||||
#[derive(Debug)]
|
#[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`].
|
/// The current [`Engine`].
|
||||||
engine: &'a Engine,
|
engine: &'a Engine,
|
||||||
/// The current [`Scope`].
|
/// The current [`Scope`].
|
||||||
@ -15,7 +15,7 @@ pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> {
|
|||||||
/// The current [`GlobalRuntimeState`].
|
/// The current [`GlobalRuntimeState`].
|
||||||
global: &'g mut GlobalRuntimeState<'pg>,
|
global: &'g mut GlobalRuntimeState<'pg>,
|
||||||
/// The current [caches][Caches], if available.
|
/// The current [caches][Caches], if available.
|
||||||
caches: Option<&'c mut Caches>,
|
caches: Option<&'c mut Caches<'pc>>,
|
||||||
/// The current stack of imported [modules][Module].
|
/// The current stack of imported [modules][Module].
|
||||||
lib: &'a [&'a Module],
|
lib: &'a [&'a Module],
|
||||||
/// The current bound `this` pointer, if any.
|
/// The current bound `this` pointer, if any.
|
||||||
@ -24,7 +24,7 @@ pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 't, 'pt> {
|
|||||||
level: usize,
|
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`].
|
/// Create a new [`EvalContext`].
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[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,
|
engine: &'a Engine,
|
||||||
scope: &'s mut Scope<'ps>,
|
scope: &'s mut Scope<'ps>,
|
||||||
global: &'g mut GlobalRuntimeState<'pg>,
|
global: &'g mut GlobalRuntimeState<'pg>,
|
||||||
caches: Option<&'c mut Caches>,
|
caches: Option<&'c mut Caches<'pc>>,
|
||||||
lib: &'a [&'a Module],
|
lib: &'a [&'a Module],
|
||||||
this_ptr: &'t mut Option<&'pt mut Dynamic>,
|
this_ptr: &'t mut Option<&'pt mut Dynamic>,
|
||||||
level: usize,
|
level: usize,
|
||||||
|
@ -55,7 +55,7 @@ struct OptimizerState<'a> {
|
|||||||
/// The global runtime state.
|
/// The global runtime state.
|
||||||
global: GlobalRuntimeState<'a>,
|
global: GlobalRuntimeState<'a>,
|
||||||
/// Function resolution caches.
|
/// Function resolution caches.
|
||||||
caches: Caches,
|
caches: Caches<'a>,
|
||||||
/// [Module][crate::Module] containing script-defined functions.
|
/// [Module][crate::Module] containing script-defined functions.
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
lib: &'a [&'a crate::Module],
|
lib: &'a [&'a crate::Module],
|
||||||
|
Loading…
Reference in New Issue
Block a user