From 6369fa5c65cd7f99243d150dde84db39c82f2cce Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 27 Mar 2022 21:53:50 +0800 Subject: [PATCH] Minor refactor. --- README.md | 1 + src/api/call_fn.rs | 6 ++---- src/api/eval.rs | 4 ++-- src/eval/eval_state.rs | 2 +- src/optimizer.rs | 8 ++++---- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a9c52df4..23a28ba1 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ Protected against attacks * [Sand-boxed](https://rhai.rs/book/safety/sandbox.html) - the scripting engine, if declared immutable, cannot mutate the containing environment unless [explicitly permitted](https://rhai.rs/book/patterns/control.html). * Rugged - protected against malicious attacks (such as [stack-overflow](https://rhai.rs/book/safety/max-call-stack.html), [over-sized data](https://rhai.rs/book/safety/max-string-size.html), and [runaway scripts](https://rhai.rs/book/safety/max-operations.html) etc.) that may come from untrusted third-party user-land scripts. * Track script evaluation [progress](https://rhai.rs/book/safety/progress.html) and manually terminate a script run. +* Passes Miri. For those who actually want their own language diff --git a/src/api/call_fn.rs b/src/api/call_fn.rs index 80a0d193..cfad57f9 100644 --- a/src/api/call_fn.rs +++ b/src/api/call_fn.rs @@ -178,7 +178,7 @@ impl Engine { #[cfg(not(feature = "no_closure"))] crate::func::call::ensure_no_data_race(name, &mut args, false)?; - let result = self.call_script_fn( + self.call_script_fn( scope, global, state, @@ -189,8 +189,6 @@ impl Engine { rewind_scope, Position::NONE, 0, - ); - - result + ) } } diff --git a/src/api/eval.rs b/src/api/eval.rs index dc4a4336..20d4655b 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -227,9 +227,9 @@ impl Engine { ast.as_ref(), ]; let lib = if lib.first().map(|m: &&Module| m.is_empty()).unwrap_or(true) { - &lib[0..0] + &[] } else { - &lib + &lib[..] }; self.eval_global_statements(scope, global, &mut state, statements, lib, level) } diff --git a/src/eval/eval_state.rs b/src/eval/eval_state.rs index 5f8a7c3a..b826ffd9 100644 --- a/src/eval/eval_state.rs +++ b/src/eval/eval_state.rs @@ -40,7 +40,7 @@ impl EvalState<'_> { always_search_scope: false, scope_level: 0, fn_resolution_caches: StaticVec::new_const(), - dummy: PhantomData::default(), + dummy: Default::default(), } } /// Get the number of function resolution cache(s) in the stack. diff --git a/src/optimizer.rs b/src/optimizer.rs index a9952ce0..5e19726e 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -9,8 +9,8 @@ use crate::func::hashing::get_hasher; use crate::tokenizer::{Span, Token}; use crate::types::dynamic::AccessMode; use crate::{ - calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnPtr, Position, Scope, - StaticVec, AST, INT, INT_BITS, + calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnPtr, Identifier, + Position, Scope, StaticVec, AST, INT, INT_BITS, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -46,7 +46,7 @@ struct OptimizerState<'a> { /// Has the [`AST`] been changed during this pass? changed: bool, /// Collection of constants to use for eager function evaluations. - variables: StaticVec<(String, AccessMode, Option)>, + variables: StaticVec<(Identifier, AccessMode, Option)>, /// Activate constants propagation? propagate_constants: bool, /// An [`Engine`] instance for eager function evaluation. @@ -100,7 +100,7 @@ impl<'a> OptimizerState<'a> { #[inline(always)] pub fn push_var( &mut self, - name: impl Into, + name: impl Into, access: AccessMode, value: Option, ) {