Remove hashing hack.

This commit is contained in:
Stephen Chung
2023-02-11 11:56:20 +08:00
parent 75718a5a8b
commit e177a5648a
4 changed files with 26 additions and 72 deletions

View File

@@ -2,7 +2,6 @@
use super::{ASTFlags, ASTNode, Ident, Namespace, Stmt, StmtBlock};
use crate::engine::{KEYWORD_FN_PTR, OP_EXCLUSIVE_RANGE, OP_INCLUSIVE_RANGE};
use crate::func::hashing::ALT_ZERO_HASH;
use crate::tokenizer::Token;
use crate::types::dynamic::Union;
use crate::{
@@ -17,7 +16,7 @@ use std::{
fmt::Write,
hash::Hash,
iter::once,
num::{NonZeroU64, NonZeroU8, NonZeroUsize},
num::{NonZeroU8, NonZeroUsize},
};
/// _(internals)_ A binary expression.
@@ -103,9 +102,9 @@ impl CustomExpr {
pub struct FnCallHashes {
/// Pre-calculated hash for a script-defined function ([`None`] if native functions only).
#[cfg(not(feature = "no_function"))]
script: Option<NonZeroU64>,
script: Option<u64>,
/// Pre-calculated hash for a native Rust function with no parameter types.
native: NonZeroU64,
native: u64,
}
impl fmt::Debug for FnCallHashes {
@@ -128,8 +127,6 @@ impl fmt::Debug for FnCallHashes {
impl From<u64> for FnCallHashes {
#[inline]
fn from(hash: u64) -> Self {
let hash = NonZeroU64::new(if hash == 0 { ALT_ZERO_HASH } else { hash }).unwrap();
Self {
#[cfg(not(feature = "no_function"))]
script: Some(hash),
@@ -146,7 +143,7 @@ impl FnCallHashes {
Self {
#[cfg(not(feature = "no_function"))]
script: None,
native: NonZeroU64::new(if hash == 0 { ALT_ZERO_HASH } else { hash }).unwrap(),
native: hash,
}
}
/// Create a [`FnCallHashes`] with both native Rust and script function hashes.
@@ -155,8 +152,8 @@ impl FnCallHashes {
pub fn from_all(#[cfg(not(feature = "no_function"))] script: u64, native: u64) -> Self {
Self {
#[cfg(not(feature = "no_function"))]
script: NonZeroU64::new(if script == 0 { ALT_ZERO_HASH } else { script }),
native: NonZeroU64::new(if native == 0 { ALT_ZERO_HASH } else { native }).unwrap(),
script: Some(script),
native,
}
}
/// Is this [`FnCallHashes`] native-only?
@@ -174,7 +171,7 @@ impl FnCallHashes {
#[inline(always)]
#[must_use]
pub const fn native(&self) -> u64 {
self.native.get()
self.native
}
/// Get the script hash.
///
@@ -188,7 +185,7 @@ impl FnCallHashes {
#[must_use]
pub fn script(&self) -> u64 {
assert!(self.script.is_some());
self.script.as_ref().unwrap().get()
self.script.unwrap()
}
}