Simplify to calc_fn_hash.
This commit is contained in:
parent
d7ae65c425
commit
5d275b5307
@ -666,7 +666,7 @@ impl Expr {
|
|||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
namespace: super::Namespace::NONE,
|
namespace: super::Namespace::NONE,
|
||||||
name: KEYWORD_FN_PTR.into(),
|
name: KEYWORD_FN_PTR.into(),
|
||||||
hashes: calc_fn_hash(f.fn_name(), 1).into(),
|
hashes: calc_fn_hash(None, f.fn_name(), 1).into(),
|
||||||
args: once(Self::StringConstant(f.fn_name().into(), pos)).collect(),
|
args: once(Self::StringConstant(f.fn_name().into(), pos)).collect(),
|
||||||
capture_parent_scope: false,
|
capture_parent_scope: false,
|
||||||
is_native_operator: false,
|
is_native_operator: false,
|
||||||
|
@ -74,8 +74,8 @@ impl OpAssignment {
|
|||||||
.expect("op-assignment operator")
|
.expect("op-assignment operator")
|
||||||
.literal_syntax();
|
.literal_syntax();
|
||||||
Self {
|
Self {
|
||||||
hash_op_assign: calc_fn_hash(op.literal_syntax(), 2),
|
hash_op_assign: calc_fn_hash(None, op.literal_syntax(), 2),
|
||||||
hash_op: calc_fn_hash(op_raw, 2),
|
hash_op: calc_fn_hash(None, op_raw, 2),
|
||||||
op_assign: op.literal_syntax(),
|
op_assign: op.literal_syntax(),
|
||||||
op: op_raw,
|
op: op_raw,
|
||||||
pos,
|
pos,
|
||||||
|
@ -285,8 +285,8 @@ impl GlobalRuntimeState<'_> {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn hash_idx_get(&mut self) -> u64 {
|
pub(crate) fn hash_idx_get(&mut self) -> u64 {
|
||||||
if self.fn_hash_indexing == (0, 0) {
|
if self.fn_hash_indexing == (0, 0) {
|
||||||
let n1 = crate::calc_fn_hash(crate::engine::FN_IDX_GET, 2);
|
let n1 = crate::calc_fn_hash(None, crate::engine::FN_IDX_GET, 2);
|
||||||
let n2 = crate::calc_fn_hash(crate::engine::FN_IDX_SET, 3);
|
let n2 = crate::calc_fn_hash(None, crate::engine::FN_IDX_SET, 3);
|
||||||
self.fn_hash_indexing = (n1, n2);
|
self.fn_hash_indexing = (n1, n2);
|
||||||
n1
|
n1
|
||||||
} else {
|
} else {
|
||||||
@ -298,8 +298,8 @@ impl GlobalRuntimeState<'_> {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn hash_idx_set(&mut self) -> u64 {
|
pub(crate) fn hash_idx_set(&mut self) -> u64 {
|
||||||
if self.fn_hash_indexing == (0, 0) {
|
if self.fn_hash_indexing == (0, 0) {
|
||||||
let n1 = crate::calc_fn_hash(crate::engine::FN_IDX_GET, 2);
|
let n1 = crate::calc_fn_hash(None, crate::engine::FN_IDX_GET, 2);
|
||||||
let n2 = crate::calc_fn_hash(crate::engine::FN_IDX_SET, 3);
|
let n2 = crate::calc_fn_hash(None, crate::engine::FN_IDX_SET, 3);
|
||||||
self.fn_hash_indexing = (n1, n2);
|
self.fn_hash_indexing = (n1, n2);
|
||||||
n2
|
n2
|
||||||
} else {
|
} else {
|
||||||
|
@ -198,10 +198,8 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut hash = args.as_ref().map_or(hash_base, |args| {
|
let mut hash = args.as_ref().map_or(hash_base, |args| {
|
||||||
combine_hashes(
|
let hash_params = calc_fn_params_hash(args.iter().map(|a| a.type_id()));
|
||||||
hash_base,
|
combine_hashes(hash_base, hash_params)
|
||||||
calc_fn_params_hash(args.iter().map(|a| a.type_id())),
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let cache = caches.fn_resolution_cache_mut();
|
let cache = caches.fn_resolution_cache_mut();
|
||||||
@ -611,7 +609,7 @@ impl Engine {
|
|||||||
if num_params < 0 || num_params > crate::MAX_USIZE_INT {
|
if num_params < 0 || num_params > crate::MAX_USIZE_INT {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
let hash_script = calc_fn_hash(fn_name.as_str(), num_params as usize);
|
let hash_script = calc_fn_hash(None, fn_name.as_str(), num_params as usize);
|
||||||
self.has_script_fn(Some(global), caches, lib, hash_script)
|
self.has_script_fn(Some(global), caches, lib, hash_script)
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
@ -815,7 +813,7 @@ impl Engine {
|
|||||||
let fn_name = fn_ptr.fn_name();
|
let fn_name = fn_ptr.fn_name();
|
||||||
let args_len = call_args.len() + fn_ptr.curry().len();
|
let args_len = call_args.len() + fn_ptr.curry().len();
|
||||||
// Recalculate hashes
|
// Recalculate hashes
|
||||||
let new_hash = calc_fn_hash(fn_name, args_len).into();
|
let new_hash = calc_fn_hash(None, fn_name, args_len).into();
|
||||||
// Arguments are passed as-is, adding the curried arguments
|
// Arguments are passed as-is, adding the curried arguments
|
||||||
let mut curry = FnArgsVec::with_capacity(fn_ptr.curry().len());
|
let mut curry = FnArgsVec::with_capacity(fn_ptr.curry().len());
|
||||||
curry.extend(fn_ptr.curry().iter().cloned());
|
curry.extend(fn_ptr.curry().iter().cloned());
|
||||||
@ -857,8 +855,8 @@ impl Engine {
|
|||||||
// Recalculate hash
|
// Recalculate hash
|
||||||
let new_hash = FnCallHashes::from_all(
|
let new_hash = FnCallHashes::from_all(
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
calc_fn_hash(fn_name, args_len),
|
calc_fn_hash(None, fn_name, args_len),
|
||||||
calc_fn_hash(fn_name, args_len + 1),
|
calc_fn_hash(None, fn_name, args_len + 1),
|
||||||
);
|
);
|
||||||
// Replace the first argument with the object pointer, adding the curried arguments
|
// Replace the first argument with the object pointer, adding the curried arguments
|
||||||
let mut curry = FnArgsVec::with_capacity(fn_ptr.curry().len());
|
let mut curry = FnArgsVec::with_capacity(fn_ptr.curry().len());
|
||||||
@ -944,8 +942,8 @@ impl Engine {
|
|||||||
// Recalculate the hash based on the new function name and new arguments
|
// Recalculate the hash based on the new function name and new arguments
|
||||||
hash = FnCallHashes::from_all(
|
hash = FnCallHashes::from_all(
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
calc_fn_hash(fn_name, call_args.len()),
|
calc_fn_hash(None, fn_name, call_args.len()),
|
||||||
calc_fn_hash(fn_name, call_args.len() + 1),
|
calc_fn_hash(None, fn_name, call_args.len() + 1),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1036,9 +1034,9 @@ impl Engine {
|
|||||||
// Recalculate hash
|
// Recalculate hash
|
||||||
let args_len = total_args + curry.len();
|
let args_len = total_args + curry.len();
|
||||||
hashes = if hashes.is_native_only() {
|
hashes = if hashes.is_native_only() {
|
||||||
FnCallHashes::from_native(calc_fn_hash(name, args_len))
|
FnCallHashes::from_native(calc_fn_hash(None, name, args_len))
|
||||||
} else {
|
} else {
|
||||||
calc_fn_hash(name, args_len).into()
|
calc_fn_hash(None, name, args_len).into()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Handle Fn()
|
// Handle Fn()
|
||||||
@ -1110,7 +1108,7 @@ impl Engine {
|
|||||||
return Ok(if num_params < 0 || num_params > crate::MAX_USIZE_INT {
|
return Ok(if num_params < 0 || num_params > crate::MAX_USIZE_INT {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
let hash_script = calc_fn_hash(&fn_name, num_params as usize);
|
let hash_script = calc_fn_hash(None, &fn_name, num_params as usize);
|
||||||
self.has_script_fn(Some(global), caches, lib, hash_script)
|
self.has_script_fn(Some(global), caches, lib, hash_script)
|
||||||
}
|
}
|
||||||
.into());
|
.into());
|
||||||
|
@ -91,7 +91,7 @@ pub fn get_hasher() -> ahash::AHasher {
|
|||||||
/// The first module name is skipped. Hashing starts from the _second_ module in the chain.
|
/// The first module name is skipped. Hashing starts from the _second_ module in the chain.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn calc_qualified_var_hash<'a>(
|
pub fn calc_var_hash<'a>(
|
||||||
modules: impl IntoIterator<Item = &'a str, IntoIter = impl ExactSizeIterator<Item = &'a str>>,
|
modules: impl IntoIterator<Item = &'a str, IntoIter = impl ExactSizeIterator<Item = &'a str>>,
|
||||||
var_name: &str,
|
var_name: &str,
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
@ -113,9 +113,11 @@ pub fn calc_qualified_var_hash<'a>(
|
|||||||
/// Calculate a non-zero [`u64`] hash key from a namespace-qualified function name
|
/// Calculate a non-zero [`u64`] hash key from a namespace-qualified function name
|
||||||
/// and the number of parameters, but no parameter types.
|
/// and the number of parameters, but no parameter types.
|
||||||
///
|
///
|
||||||
/// Module names are passed in via `&str` references from an iterator.
|
/// Module names making up the namespace are passed in via `&str` references from an iterator.
|
||||||
/// Parameter types are passed in via [`TypeId`] values from an iterator.
|
/// Parameter types are passed in via [`TypeId`] values from an iterator.
|
||||||
///
|
///
|
||||||
|
/// If the function is not namespace-qualified, pass [`None`] as the namespace.
|
||||||
|
///
|
||||||
/// # Zeros
|
/// # Zeros
|
||||||
///
|
///
|
||||||
/// If the hash happens to be zero, it is mapped to `DEFAULT_HASH`.
|
/// If the hash happens to be zero, it is mapped to `DEFAULT_HASH`.
|
||||||
@ -125,15 +127,15 @@ pub fn calc_qualified_var_hash<'a>(
|
|||||||
/// The first module name is skipped. Hashing starts from the _second_ module in the chain.
|
/// The first module name is skipped. Hashing starts from the _second_ module in the chain.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn calc_qualified_fn_hash<'a>(
|
pub fn calc_fn_hash<'a>(
|
||||||
modules: impl IntoIterator<Item = &'a str, IntoIter = impl ExactSizeIterator<Item = &'a str>>,
|
namespace: impl IntoIterator<Item = &'a str, IntoIter = impl ExactSizeIterator<Item = &'a str>>,
|
||||||
fn_name: &str,
|
fn_name: &str,
|
||||||
num: usize,
|
num: usize,
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
let s = &mut get_hasher();
|
let s = &mut get_hasher();
|
||||||
|
|
||||||
// We always skip the first module
|
// We always skip the first module
|
||||||
let iter = modules.into_iter();
|
let iter = namespace.into_iter();
|
||||||
let len = iter.len();
|
let len = iter.len();
|
||||||
iter.skip(1).for_each(|m| m.hash(s));
|
iter.skip(1).for_each(|m| m.hash(s));
|
||||||
len.hash(s);
|
len.hash(s);
|
||||||
@ -146,20 +148,6 @@ pub fn calc_qualified_fn_hash<'a>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate a non-zero [`u64`] hash key from a non-namespace-qualified function name
|
|
||||||
/// and the number of parameters, but no parameter types.
|
|
||||||
///
|
|
||||||
/// Parameter types are passed in via [`TypeId`] values from an iterator.
|
|
||||||
///
|
|
||||||
/// # Zeros
|
|
||||||
///
|
|
||||||
/// If the hash happens to be zero, it is mapped to `DEFAULT_HASH`.
|
|
||||||
#[inline(always)]
|
|
||||||
#[must_use]
|
|
||||||
pub fn calc_fn_hash(fn_name: &str, num: usize) -> u64 {
|
|
||||||
calc_qualified_fn_hash(None, fn_name, num)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Calculate a non-zero [`u64`] hash key from a list of parameter types.
|
/// Calculate a non-zero [`u64`] hash key from a list of parameter types.
|
||||||
///
|
///
|
||||||
/// Parameter types are passed in via [`TypeId`] values from an iterator.
|
/// Parameter types are passed in via [`TypeId`] values from an iterator.
|
||||||
|
@ -20,8 +20,7 @@ pub use callable_function::CallableFunction;
|
|||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
pub use func::Func;
|
pub use func::Func;
|
||||||
pub use hashing::{
|
pub use hashing::{
|
||||||
calc_fn_hash, calc_fn_params_hash, calc_qualified_fn_hash, calc_qualified_var_hash,
|
calc_fn_hash, calc_fn_params_hash, calc_var_hash, combine_hashes, get_hasher, StraightHashMap,
|
||||||
combine_hashes, get_hasher, StraightHashMap,
|
|
||||||
};
|
};
|
||||||
pub use native::{
|
pub use native::{
|
||||||
locked_read, locked_write, shared_get_mut, shared_make_mut, shared_take, shared_take_or_clone,
|
locked_read, locked_write, shared_get_mut, shared_make_mut, shared_take, shared_take_or_clone,
|
||||||
|
@ -321,11 +321,11 @@ impl<'a> NativeCallContext<'a> {
|
|||||||
let hash = if is_method_call {
|
let hash = if is_method_call {
|
||||||
FnCallHashes::from_all(
|
FnCallHashes::from_all(
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
calc_fn_hash(fn_name, args_len - 1),
|
calc_fn_hash(None, fn_name, args_len - 1),
|
||||||
calc_fn_hash(fn_name, args_len),
|
calc_fn_hash(None, fn_name, args_len),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
calc_fn_hash(fn_name, args_len).into()
|
calc_fn_hash(None, fn_name, args_len).into()
|
||||||
};
|
};
|
||||||
|
|
||||||
self.engine()
|
self.engine()
|
||||||
|
@ -237,10 +237,7 @@ pub use func::Shared;
|
|||||||
/// Alias to [`RefCell`][std::cell::RefCell] or [`RwLock`][std::sync::RwLock] depending on the `sync` feature flag.
|
/// Alias to [`RefCell`][std::cell::RefCell] or [`RwLock`][std::sync::RwLock] depending on the `sync` feature flag.
|
||||||
pub use func::Locked;
|
pub use func::Locked;
|
||||||
|
|
||||||
pub(crate) use func::{
|
pub(crate) use func::{calc_fn_hash, calc_fn_params_hash, calc_var_hash, combine_hashes};
|
||||||
calc_fn_hash, calc_fn_params_hash, calc_qualified_fn_hash, calc_qualified_var_hash,
|
|
||||||
combine_hashes,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub use rhai_codegen::*;
|
pub use rhai_codegen::*;
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ use crate::func::{
|
|||||||
};
|
};
|
||||||
use crate::types::{dynamic::Variant, BloomFilterU64, CustomTypesCollection};
|
use crate::types::{dynamic::Variant, BloomFilterU64, CustomTypesCollection};
|
||||||
use crate::{
|
use crate::{
|
||||||
calc_fn_hash, calc_fn_params_hash, calc_qualified_fn_hash, combine_hashes, Dynamic, Identifier,
|
calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Identifier, ImmutableString,
|
||||||
ImmutableString, NativeCallContext, RhaiResultOf, Shared, SmartString, StaticVec,
|
NativeCallContext, RhaiResultOf, Shared, SmartString, StaticVec,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
@ -150,7 +150,7 @@ pub fn calc_native_fn_hash<'a>(
|
|||||||
fn_name: &str,
|
fn_name: &str,
|
||||||
params: &[TypeId],
|
params: &[TypeId],
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
let hash_script = calc_qualified_fn_hash(modules, fn_name, params.len());
|
let hash_script = calc_fn_hash(modules, fn_name, params.len());
|
||||||
let hash_params = calc_fn_params_hash(params.iter().copied());
|
let hash_params = calc_fn_params_hash(params.iter().copied());
|
||||||
combine_hashes(hash_script, hash_params)
|
combine_hashes(hash_script, hash_params)
|
||||||
}
|
}
|
||||||
@ -662,7 +662,7 @@ impl Module {
|
|||||||
let value = Dynamic::from(value);
|
let value = Dynamic::from(value);
|
||||||
|
|
||||||
if self.indexed {
|
if self.indexed {
|
||||||
let hash_var = crate::calc_qualified_var_hash(Some(""), &ident);
|
let hash_var = crate::calc_var_hash(Some(""), &ident);
|
||||||
self.all_variables
|
self.all_variables
|
||||||
.get_or_insert_with(|| Default::default())
|
.get_or_insert_with(|| Default::default())
|
||||||
.insert(hash_var, value.clone());
|
.insert(hash_var, value.clone());
|
||||||
@ -692,7 +692,7 @@ impl Module {
|
|||||||
|
|
||||||
// None + function name + number of arguments.
|
// None + function name + number of arguments.
|
||||||
let num_params = fn_def.params.len();
|
let num_params = fn_def.params.len();
|
||||||
let hash_script = crate::calc_fn_hash(&fn_def.name, num_params);
|
let hash_script = crate::calc_fn_hash(None, &fn_def.name, num_params);
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
let params_info = fn_def.params.iter().map(Into::into).collect();
|
let params_info = fn_def.params.iter().map(Into::into).collect();
|
||||||
self.functions.insert(
|
self.functions.insert(
|
||||||
@ -1021,11 +1021,12 @@ impl Module {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let name = name.as_ref();
|
let name = name.as_ref();
|
||||||
let hash_fn = calc_native_fn_hash(None, name, ¶m_types);
|
let hash_script = calc_fn_hash(None, name, param_types.len());
|
||||||
|
let hash_params = calc_fn_params_hash(param_types.iter().copied());
|
||||||
|
let hash_fn = combine_hashes(hash_script, hash_params);
|
||||||
|
|
||||||
if is_dynamic {
|
if is_dynamic {
|
||||||
self.dynamic_functions
|
self.dynamic_functions.mark(hash_script);
|
||||||
.mark(calc_fn_hash(name, param_types.len()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.functions.insert(
|
self.functions.insert(
|
||||||
@ -2126,7 +2127,7 @@ impl Module {
|
|||||||
// Index all variables
|
// Index all variables
|
||||||
if let Some(ref v) = module.variables {
|
if let Some(ref v) = module.variables {
|
||||||
for (var_name, value) in v {
|
for (var_name, value) in v {
|
||||||
let hash_var = crate::calc_qualified_var_hash(path.iter().copied(), var_name);
|
let hash_var = crate::calc_var_hash(path.iter().copied(), var_name);
|
||||||
variables.insert(hash_var, value.clone());
|
variables.insert(hash_var, value.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2160,7 +2161,7 @@ impl Module {
|
|||||||
functions.insert(hash_qualified_fn, f.func.clone());
|
functions.insert(hash_qualified_fn, f.func.clone());
|
||||||
} else if cfg!(not(feature = "no_function")) {
|
} else if cfg!(not(feature = "no_function")) {
|
||||||
let hash_qualified_script =
|
let hash_qualified_script =
|
||||||
crate::calc_qualified_fn_hash(path.iter().copied(), &f.name, f.num_params);
|
crate::calc_fn_hash(path.iter().copied(), &f.name, f.num_params);
|
||||||
functions.insert(hash_qualified_script, f.func.clone());
|
functions.insert(hash_qualified_script, f.func.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ impl<'a> OptimizerState<'a> {
|
|||||||
&mut self.caches,
|
&mut self.caches,
|
||||||
lib,
|
lib,
|
||||||
fn_name,
|
fn_name,
|
||||||
calc_fn_hash(fn_name, arg_values.len()),
|
calc_fn_hash(None, fn_name, arg_values.len()),
|
||||||
&mut arg_values.iter_mut().collect::<StaticVec<_>>(),
|
&mut arg_values.iter_mut().collect::<StaticVec<_>>(),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
@ -358,9 +358,9 @@ impl Expr {
|
|||||||
Self::Variable(x, .., pos) => {
|
Self::Variable(x, .., pos) => {
|
||||||
let ident = x.3.clone();
|
let ident = x.3.clone();
|
||||||
let getter = state.get_interned_getter(ident.as_str());
|
let getter = state.get_interned_getter(ident.as_str());
|
||||||
let hash_get = calc_fn_hash(&getter, 1);
|
let hash_get = calc_fn_hash(None, &getter, 1);
|
||||||
let setter = state.get_interned_setter(ident.as_str());
|
let setter = state.get_interned_setter(ident.as_str());
|
||||||
let hash_set = calc_fn_hash(&setter, 2);
|
let hash_set = calc_fn_hash(None, &setter, 2);
|
||||||
|
|
||||||
Self::Property(
|
Self::Property(
|
||||||
Box::new(((getter, hash_get), (setter, hash_set), ident)),
|
Box::new(((getter, hash_get), (setter, hash_set), ident)),
|
||||||
@ -576,7 +576,7 @@ impl Engine {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
let hash = if namespace.is_empty() {
|
let hash = if namespace.is_empty() {
|
||||||
calc_fn_hash(&id, 0)
|
calc_fn_hash(None, &id, 0)
|
||||||
} else {
|
} else {
|
||||||
let root = namespace.root();
|
let root = namespace.root();
|
||||||
let index = state.find_module(root);
|
let index = state.find_module(root);
|
||||||
@ -600,10 +600,10 @@ impl Engine {
|
|||||||
|
|
||||||
namespace.set_index(index);
|
namespace.set_index(index);
|
||||||
|
|
||||||
crate::calc_qualified_fn_hash(namespace.iter().map(Ident::as_str), &id, 0)
|
crate::calc_fn_hash(namespace.iter().map(Ident::as_str), &id, 0)
|
||||||
};
|
};
|
||||||
#[cfg(feature = "no_module")]
|
#[cfg(feature = "no_module")]
|
||||||
let hash = calc_fn_hash(&id, 0);
|
let hash = calc_fn_hash(None, &id, 0);
|
||||||
|
|
||||||
let hashes = if is_valid_function_name(&id) {
|
let hashes = if is_valid_function_name(&id) {
|
||||||
hash.into()
|
hash.into()
|
||||||
@ -645,7 +645,7 @@ impl Engine {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
let hash = if namespace.is_empty() {
|
let hash = if namespace.is_empty() {
|
||||||
calc_fn_hash(&id, args.len())
|
calc_fn_hash(None, &id, args.len())
|
||||||
} else {
|
} else {
|
||||||
let root = namespace.root();
|
let root = namespace.root();
|
||||||
let index = state.find_module(root);
|
let index = state.find_module(root);
|
||||||
@ -668,14 +668,10 @@ impl Engine {
|
|||||||
|
|
||||||
namespace.set_index(index);
|
namespace.set_index(index);
|
||||||
|
|
||||||
crate::calc_qualified_fn_hash(
|
crate::calc_fn_hash(namespace.iter().map(Ident::as_str), &id, args.len())
|
||||||
namespace.iter().map(Ident::as_str),
|
|
||||||
&id,
|
|
||||||
args.len(),
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
#[cfg(feature = "no_module")]
|
#[cfg(feature = "no_module")]
|
||||||
let hash = calc_fn_hash(&id, args.len());
|
let hash = calc_fn_hash(None, &id, args.len());
|
||||||
|
|
||||||
let hashes = if is_valid_function_name(&id) {
|
let hashes = if is_valid_function_name(&id) {
|
||||||
hash.into()
|
hash.into()
|
||||||
@ -1470,7 +1466,7 @@ impl Engine {
|
|||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let hash_script = calc_fn_hash(&func.name, func.params.len());
|
let hash_script = calc_fn_hash(None, &func.name, func.params.len());
|
||||||
lib.insert(hash_script, func.into());
|
lib.insert(hash_script, func.into());
|
||||||
|
|
||||||
expr
|
expr
|
||||||
@ -1835,7 +1831,7 @@ impl Engine {
|
|||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
if let Some((.., namespace, hash, name)) = namespaced_variable {
|
if let Some((.., namespace, hash, name)) = namespaced_variable {
|
||||||
if !namespace.is_empty() {
|
if !namespace.is_empty() {
|
||||||
*hash = crate::calc_qualified_var_hash(namespace.iter().map(Ident::as_str), name);
|
*hash = crate::calc_var_hash(namespace.iter().map(Ident::as_str), name);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
{
|
{
|
||||||
@ -1919,7 +1915,7 @@ impl Engine {
|
|||||||
|
|
||||||
Ok(FnCallExpr {
|
Ok(FnCallExpr {
|
||||||
name: state.get_interned_string("-"),
|
name: state.get_interned_string("-"),
|
||||||
hashes: FnCallHashes::from_native(calc_fn_hash("-", 1)),
|
hashes: FnCallHashes::from_native(calc_fn_hash(None, "-", 1)),
|
||||||
args,
|
args,
|
||||||
pos,
|
pos,
|
||||||
is_native_operator: true,
|
is_native_operator: true,
|
||||||
@ -1947,7 +1943,7 @@ impl Engine {
|
|||||||
|
|
||||||
Ok(FnCallExpr {
|
Ok(FnCallExpr {
|
||||||
name: state.get_interned_string("+"),
|
name: state.get_interned_string("+"),
|
||||||
hashes: FnCallHashes::from_native(calc_fn_hash("+", 1)),
|
hashes: FnCallHashes::from_native(calc_fn_hash(None, "+", 1)),
|
||||||
args,
|
args,
|
||||||
pos,
|
pos,
|
||||||
is_native_operator: true,
|
is_native_operator: true,
|
||||||
@ -1966,7 +1962,7 @@ impl Engine {
|
|||||||
|
|
||||||
Ok(FnCallExpr {
|
Ok(FnCallExpr {
|
||||||
name: state.get_interned_string("!"),
|
name: state.get_interned_string("!"),
|
||||||
hashes: FnCallHashes::from_native(calc_fn_hash("!", 1)),
|
hashes: FnCallHashes::from_native(calc_fn_hash(None, "!", 1)),
|
||||||
args,
|
args,
|
||||||
pos,
|
pos,
|
||||||
is_native_operator: true,
|
is_native_operator: true,
|
||||||
@ -2187,8 +2183,8 @@ impl Engine {
|
|||||||
// Recalculate hash
|
// Recalculate hash
|
||||||
func.hashes = FnCallHashes::from_all(
|
func.hashes = FnCallHashes::from_all(
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
calc_fn_hash(&func.name, func.args.len()),
|
calc_fn_hash(None, &func.name, func.args.len()),
|
||||||
calc_fn_hash(&func.name, func.args.len() + 1),
|
calc_fn_hash(None, &func.name, func.args.len() + 1),
|
||||||
);
|
);
|
||||||
|
|
||||||
let rhs = Expr::MethodCall(func, func_pos);
|
let rhs = Expr::MethodCall(func, func_pos);
|
||||||
@ -2233,8 +2229,8 @@ impl Engine {
|
|||||||
// Recalculate hash
|
// Recalculate hash
|
||||||
func.hashes = FnCallHashes::from_all(
|
func.hashes = FnCallHashes::from_all(
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
calc_fn_hash(&func.name, func.args.len()),
|
calc_fn_hash(None, &func.name, func.args.len()),
|
||||||
calc_fn_hash(&func.name, func.args.len() + 1),
|
calc_fn_hash(None, &func.name, func.args.len() + 1),
|
||||||
);
|
);
|
||||||
|
|
||||||
let new_lhs = BinaryExpr {
|
let new_lhs = BinaryExpr {
|
||||||
@ -2338,7 +2334,7 @@ impl Engine {
|
|||||||
settings.ensure_level_within_max_limit(state.max_expr_depth)?;
|
settings.ensure_level_within_max_limit(state.max_expr_depth)?;
|
||||||
|
|
||||||
let op = op_token.syntax();
|
let op = op_token.syntax();
|
||||||
let hash = calc_fn_hash(&op, 2);
|
let hash = calc_fn_hash(None, &op, 2);
|
||||||
|
|
||||||
let op_base = FnCallExpr {
|
let op_base = FnCallExpr {
|
||||||
name: state.get_interned_string(op.as_ref()),
|
name: state.get_interned_string(op.as_ref()),
|
||||||
@ -2412,7 +2408,7 @@ impl Engine {
|
|||||||
|
|
||||||
// Convert into a call to `contains`
|
// Convert into a call to `contains`
|
||||||
FnCallExpr {
|
FnCallExpr {
|
||||||
hashes: calc_fn_hash(OP_CONTAINS, 2).into(),
|
hashes: calc_fn_hash(None, OP_CONTAINS, 2).into(),
|
||||||
args,
|
args,
|
||||||
name: state.get_interned_string(OP_CONTAINS),
|
name: state.get_interned_string(OP_CONTAINS),
|
||||||
..op_base
|
..op_base
|
||||||
@ -2427,7 +2423,7 @@ impl Engine {
|
|||||||
.get(s.as_str())
|
.get(s.as_str())
|
||||||
.map_or(false, Option::is_some) =>
|
.map_or(false, Option::is_some) =>
|
||||||
{
|
{
|
||||||
let hash = calc_fn_hash(&s, 2);
|
let hash = calc_fn_hash(None, &s, 2);
|
||||||
let pos = args[0].start_position();
|
let pos = args[0].start_position();
|
||||||
|
|
||||||
FnCallExpr {
|
FnCallExpr {
|
||||||
@ -3345,7 +3341,7 @@ impl Engine {
|
|||||||
|
|
||||||
let func = func?;
|
let func = func?;
|
||||||
|
|
||||||
let hash = calc_fn_hash(&func.name, func.params.len());
|
let hash = calc_fn_hash(None, &func.name, func.params.len());
|
||||||
|
|
||||||
if !lib.is_empty() && lib.contains_key(&hash) {
|
if !lib.is_empty() && lib.contains_key(&hash) {
|
||||||
return Err(PERR::FnDuplicatedDefinition(
|
return Err(PERR::FnDuplicatedDefinition(
|
||||||
@ -3657,6 +3653,7 @@ impl Engine {
|
|||||||
let expr = FnCallExpr {
|
let expr = FnCallExpr {
|
||||||
name: state.get_interned_string(crate::engine::KEYWORD_FN_PTR_CURRY),
|
name: state.get_interned_string(crate::engine::KEYWORD_FN_PTR_CURRY),
|
||||||
hashes: FnCallHashes::from_native(calc_fn_hash(
|
hashes: FnCallHashes::from_native(calc_fn_hash(
|
||||||
|
None,
|
||||||
crate::engine::KEYWORD_FN_PTR_CURRY,
|
crate::engine::KEYWORD_FN_PTR_CURRY,
|
||||||
num_externals + 1,
|
num_externals + 1,
|
||||||
)),
|
)),
|
||||||
|
@ -66,7 +66,7 @@ impl Ord for FnMetadata<'_> {
|
|||||||
|
|
||||||
impl<'a> From<&'a FuncInfo> for FnMetadata<'a> {
|
impl<'a> From<&'a FuncInfo> for FnMetadata<'a> {
|
||||||
fn from(info: &'a FuncInfo) -> Self {
|
fn from(info: &'a FuncInfo) -> Self {
|
||||||
let base_hash = calc_fn_hash(&info.name, info.num_params);
|
let base_hash = calc_fn_hash(None, &info.name, info.num_params);
|
||||||
let (typ, full_hash) = if info.func.is_script() {
|
let (typ, full_hash) = if info.func.is_script() {
|
||||||
(FnType::Script, base_hash)
|
(FnType::Script, base_hash)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user