From 31ef7e6c69174bede1d27da320d0a8e5a4d5e385 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 8 Nov 2021 12:07:49 +0800 Subject: [PATCH] Fix builds. --- src/dynamic.rs | 4 ++-- src/engine.rs | 24 ++++++++++++++++++------ src/fn_native.rs | 22 ++++++++++------------ src/lib.rs | 4 ++-- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/dynamic.rs b/src/dynamic.rs index b3eefbc8..ae530593 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -1,6 +1,6 @@ //! Helper module which defines the [`Any`] trait to to allow dynamic value handling. -use crate::fn_native::{shared_write_lock, SendSync}; +use crate::fn_native::SendSync; use crate::r#unsafe::{unsafe_cast_box, unsafe_try_cast}; use crate::{FnPtr, ImmutableString, INT}; #[cfg(feature = "no_std")] @@ -1590,7 +1590,7 @@ impl Dynamic { match self.0 { #[cfg(not(feature = "no_closure"))] Union::Shared(ref cell, _, _) => { - let value = shared_write_lock(cell); + let value = crate::fn_native::shared_write_lock(cell); if (*value).type_id() != TypeId::of::() && TypeId::of::() != TypeId::of::() diff --git a/src/engine.rs b/src/engine.rs index 2a762cf3..19f6b9ad 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -5,8 +5,8 @@ use crate::custom_syntax::CustomSyntax; use crate::dynamic::{map_std_type_name, AccessMode, Union, Variant}; use crate::fn_hash::get_hasher; use crate::fn_native::{ - shared_write_lock, CallableFunction, IteratorFn, Locked, OnDebugCallback, OnParseTokenCallback, - OnPrintCallback, OnVarCallback, + CallableFunction, IteratorFn, OnDebugCallback, OnParseTokenCallback, OnPrintCallback, + OnVarCallback, }; use crate::module::NamespaceRef; use crate::packages::{Package, StandardPackage}; @@ -73,10 +73,14 @@ pub struct Imports { #[cfg(any(not(feature = "no_index"), not(feature = "no_object")))] fn_hash_indexing: (u64, u64), /// Embedded module resolver. + /// + /// Not available under `no_module`. #[cfg(not(feature = "no_module"))] pub embedded_module_resolver: Option>, /// Cache of globally-defined constants. - global_constants: Option>>>, + #[cfg(not(feature = "no_module"))] + #[cfg(not(feature = "no_function"))] + global_constants: Option>>>, } impl Imports { @@ -94,6 +98,8 @@ impl Imports { embedded_module_resolver: None, #[cfg(any(not(feature = "no_index"), not(feature = "no_object")))] fn_hash_indexing: (0, 0), + #[cfg(not(feature = "no_module"))] + #[cfg(not(feature = "no_function"))] global_constants: None, } } @@ -201,24 +207,28 @@ impl Imports { .find_map(|m| m.get_qualified_iter(id)) } /// Get a mutable reference to the cache of globally-defined constants. + #[cfg(not(feature = "no_module"))] + #[cfg(not(feature = "no_function"))] #[must_use] pub(crate) fn global_constants_mut<'a>( &'a mut self, ) -> Option> + 'a> { if let Some(ref global_constants) = self.global_constants { - Some(shared_write_lock(global_constants)) + Some(crate::fn_native::shared_write_lock(global_constants)) } else { None } } /// Set a constant into the cache of globally-defined constants. + #[cfg(not(feature = "no_module"))] + #[cfg(not(feature = "no_function"))] pub(crate) fn set_global_constant(&mut self, name: &str, value: Dynamic) { if self.global_constants.is_none() { - let dict: Locked<_> = BTreeMap::new().into(); + let dict: crate::Locked<_> = BTreeMap::new().into(); self.global_constants = Some(dict.into()); } - shared_write_lock( + crate::fn_native::shared_write_lock( self.global_constants .as_mut() .expect("`global_constants` is `Some`"), @@ -1204,6 +1214,7 @@ impl Engine { Expr::Variable(None, _var_pos, v) => match v.as_ref() { // Normal variable access (_, None, _) => self.search_scope_only(scope, mods, state, lib, this_ptr, expr), + // Qualified variable access #[cfg(not(feature = "no_module"))] (_, Some((namespace, hash_var)), var_name) => { @@ -1265,6 +1276,7 @@ impl Engine { .into(), ) } + #[cfg(feature = "no_module")] (_, Some((_, _)), _) => unreachable!("qualified access under no_module"), }, diff --git a/src/fn_native.rs b/src/fn_native.rs index fd3063ff..9d8dab30 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -34,31 +34,23 @@ pub use std::rc::Rc as Shared; pub use std::sync::Arc as Shared; /// Synchronized shared object. -/// -/// Not available under `no_closure`. -#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "sync"))] +#[allow(dead_code)] pub use std::cell::RefCell as Locked; /// Lock guard for synchronized shared object. -/// -/// Not available under `no_closure`. -#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "sync"))] +#[allow(dead_code)] pub type LockGuard<'a, T> = std::cell::RefMut<'a, T>; /// Synchronized shared object. -/// -/// Not available under `no_closure`. -#[cfg(not(feature = "no_closure"))] #[cfg(feature = "sync")] +#[allow(dead_code)] pub use std::sync::RwLock as Locked; /// Lock guard for synchronized shared object. -/// -/// Not available under `no_closure`. -#[cfg(not(feature = "no_closure"))] #[cfg(feature = "sync")] +#[allow(dead_code)] pub type LockGuard<'a, T> = std::sync::RwLockWriteGuard<'a, T>; /// Context of a native Rust function call. @@ -277,6 +269,7 @@ impl<'a> NativeCallContext<'a> { /// If the resource is shared (i.e. has other outstanding references), a cloned copy is used. #[inline(always)] #[must_use] +#[allow(dead_code)] pub fn shared_make_mut(value: &mut Shared) -> &mut T { Shared::make_mut(value) } @@ -284,12 +277,14 @@ pub fn shared_make_mut(value: &mut Shared) -> &mut T { /// Consume a [`Shared`] resource if is unique (i.e. not shared), or clone it otherwise. #[inline] #[must_use] +#[allow(dead_code)] pub fn shared_take_or_clone(value: Shared) -> T { shared_try_take(value).unwrap_or_else(|v| v.as_ref().clone()) } /// Consume a [`Shared`] resource if is unique (i.e. not shared). #[inline(always)] +#[allow(dead_code)] pub fn shared_try_take(value: Shared) -> Result> { Shared::try_unwrap(value) } @@ -301,14 +296,17 @@ pub fn shared_try_take(value: Shared) -> Result> { /// Panics if the resource is shared (i.e. has other outstanding references). #[inline] #[must_use] +#[allow(dead_code)] pub fn shared_take(value: Shared) -> T { shared_try_take(value) .ok() .expect("no outstanding references") } +/// Lock a [`Shared`] resource. #[inline(always)] #[must_use] +#[allow(dead_code)] pub fn shared_write_lock<'a, T>(value: &'a Locked) -> LockGuard<'a, T> { #[cfg(not(feature = "sync"))] return value.borrow_mut(); diff --git a/src/lib.rs b/src/lib.rs index 4a89ced2..96c1391e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,8 +171,8 @@ pub type Identifier = ImmutableString; /// Alias to [`Rc`][std::rc::Rc] or [`Arc`][std::sync::Arc] depending on the `sync` feature flag. pub use fn_native::Shared; -#[cfg(not(feature = "no_closure"))] -use fn_native::Locked; +//// Alias to [`RefCell`][std::cell::RefCell] or [`RwLock`][std::sync::RwLock] depending on the `sync` feature flag. +pub use fn_native::Locked; pub(crate) use fn_hash::{ calc_fn_hash, calc_fn_params_hash, calc_qualified_fn_hash, calc_qualified_var_hash,