From d8fb6c752c2ae0f0758136a2cdfafe29d577ee57 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 2 Feb 2024 08:51:47 +0800 Subject: [PATCH 1/5] Bump codegen version to satisfy semver. --- codegen/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 96b3d7ce8..cb4d1342a 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rhai_codegen" -version = "1.17.0" +version = "2.0.0" edition = "2018" resolver = "2" authors = ["jhwgh1968", "Stephen Chung"] From c6f50cc73b7aa0fd1ce2ad8a4e55f33a19f441bf Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 2 Feb 2024 08:52:52 +0800 Subject: [PATCH 2/5] Bump version. --- CHANGELOG.md | 6 ++++++ Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fe366a56..c108b3a4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Rhai Release Notes ================== +Version 1.17.1 +============== + +This is a bug-fix release that bumps `rhai_codegen` version to `2.0.0` to satisfy semver rules. + + Version 1.17.0 ============== diff --git a/Cargo.toml b/Cargo.toml index 2c651d67a..4eba5b050 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [".", "codegen"] [package] name = "rhai" -version = "1.17.0" +version = "1.17.1" rust-version = "1.66.0" edition = "2018" resolver = "2" From 81833e07961cf9610d5306ec03215737207586f1 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 1 Feb 2024 14:42:01 +0800 Subject: [PATCH 3/5] Export ThinVec. --- src/ast/ast.rs | 5 ++-- src/ast/expr.rs | 3 +-- src/eval/debugger.rs | 5 ++-- src/eval/global_state.rs | 12 ++++----- src/lib.rs | 58 ++++++++++++++++++---------------------- src/module/mod.rs | 2 +- src/parser.rs | 3 +-- src/serde/metadata.rs | 3 +-- src/types/fn_ptr.rs | 3 +-- src/types/scope.rs | 3 +-- 10 files changed, 43 insertions(+), 54 deletions(-) diff --git a/src/ast/ast.rs b/src/ast/ast.rs index 23c5736eb..e59b51bee 100644 --- a/src/ast/ast.rs +++ b/src/ast/ast.rs @@ -1,7 +1,7 @@ //! Module defining the AST (abstract syntax tree). use super::{ASTFlags, Expr, FnAccess, Stmt}; -use crate::{Dynamic, FnNamespace, ImmutableString, Position}; +use crate::{Dynamic, FnNamespace, ImmutableString, Position, ThinVec}; #[cfg(feature = "no_std")] use std::prelude::v1::*; use std::{ @@ -11,7 +11,6 @@ use std::{ ops::{Add, AddAssign}, ptr, }; -use thin_vec::ThinVec; /// Compiled AST (abstract syntax tree) of a Rhai script. /// @@ -989,7 +988,7 @@ pub struct EncapsulatedEnviron { pub lib: crate::SharedModule, /// Imported [modules][crate::Module]. #[cfg(not(feature = "no_module"))] - pub imports: thin_vec::ThinVec<(ImmutableString, crate::SharedModule)>, + pub imports: crate::ThinVec<(ImmutableString, crate::SharedModule)>, /// Globally-defined constants. #[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_function"))] diff --git a/src/ast/expr.rs b/src/ast/expr.rs index 9964f0c83..f26ee60d1 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -6,7 +6,7 @@ use crate::tokenizer::Token; use crate::types::dynamic::Union; use crate::{ calc_fn_hash, Dynamic, FnArgsVec, FnPtr, Identifier, ImmutableString, Position, SmartString, - StaticVec, INT, + StaticVec, ThinVec, INT, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -19,7 +19,6 @@ use std::{ mem, num::{NonZeroU8, NonZeroUsize}, }; -use thin_vec::ThinVec; /// _(internals)_ A binary expression. /// Exported under the `internals` feature only. diff --git a/src/eval/debugger.rs b/src/eval/debugger.rs index f6c6e7ba4..409a3f773 100644 --- a/src/eval/debugger.rs +++ b/src/eval/debugger.rs @@ -3,11 +3,12 @@ use super::{Caches, EvalContext, GlobalRuntimeState}; use crate::ast::{ASTNode, Expr, Stmt}; -use crate::{Dynamic, Engine, EvalAltResult, ImmutableString, Position, RhaiResultOf, Scope}; +use crate::{ + Dynamic, Engine, EvalAltResult, ImmutableString, Position, RhaiResultOf, Scope, ThinVec, +}; #[cfg(feature = "no_std")] use std::prelude::v1::*; use std::{fmt, iter::repeat, mem}; -use thin_vec::ThinVec; /// Callback function to initialize the debugger. #[cfg(not(feature = "sync"))] diff --git a/src/eval/global_state.rs b/src/eval/global_state.rs index 3990d84cb..eb66b85c1 100644 --- a/src/eval/global_state.rs +++ b/src/eval/global_state.rs @@ -25,14 +25,14 @@ pub type SharedGlobalConstants = pub struct GlobalRuntimeState { /// Names of imported [modules][crate::Module]. #[cfg(not(feature = "no_module"))] - imports: thin_vec::ThinVec, + imports: crate::ThinVec, /// Stack of imported [modules][crate::Module]. #[cfg(not(feature = "no_module"))] - modules: thin_vec::ThinVec, + modules: crate::ThinVec, /// The current stack of loaded [modules][crate::Module] containing script-defined functions. #[cfg(not(feature = "no_function"))] - pub lib: thin_vec::ThinVec, + pub lib: crate::ThinVec, /// Source of the current context. /// /// No source if the string is empty. @@ -82,11 +82,11 @@ impl GlobalRuntimeState { pub fn new(engine: &Engine) -> Self { Self { #[cfg(not(feature = "no_module"))] - imports: thin_vec::ThinVec::new(), + imports: crate::ThinVec::new(), #[cfg(not(feature = "no_module"))] - modules: thin_vec::ThinVec::new(), + modules: crate::ThinVec::new(), #[cfg(not(feature = "no_function"))] - lib: thin_vec::ThinVec::new(), + lib: crate::ThinVec::new(), source: None, num_operations: 0, #[cfg(not(feature = "no_module"))] diff --git a/src/lib.rs b/src/lib.rs index 0d8e70ffa..ede7c8a8b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -385,37 +385,7 @@ pub use api::definitions::Definitions; /// Number of items to keep inline for [`StaticVec`]. const STATIC_VEC_INLINE_SIZE: usize = 3; -/// Alias to [`smallvec::SmallVec<[T; 3]>`](https://crates.io/crates/smallvec), which is a -/// specialized [`Vec`] backed by a small, inline, fixed-size array when there are ≤ 3 items stored. -/// -/// # History -/// -/// And Saint Attila raised the `SmallVec` up on high, saying, "O Lord, bless this Thy `SmallVec` -/// that, with it, Thou mayest blow Thine allocation costs to tiny bits in Thy mercy." -/// -/// And the Lord did grin, and the people did feast upon the lambs and sloths and carp and anchovies -/// and orangutans and breakfast cereals and fruit bats and large chu... -/// -/// And the Lord spake, saying, "First shalt thou depend on the [`smallvec`](https://crates.io/crates/smallvec) crate. -/// Then, shalt thou keep three inline. No more. No less. Three shalt be the number thou shalt keep inline, -/// and the number to keep inline shalt be three. Four shalt thou not keep inline, nor either keep inline -/// thou two, excepting that thou then proceed to three. Five is right out. Once the number three, -/// being the third number, be reached, then, lobbest thou thy `SmallVec` towards thy heap, who, -/// being slow and cache-naughty in My sight, shall snuff it." -/// -/// # Why Three -/// -/// `StaticVec` is used frequently to keep small lists of items in inline (non-heap) storage in -/// order to improve cache friendliness and reduce indirections. -/// -/// The number 3, other than being the holy number, is carefully chosen for a balance between -/// storage space and reduce allocations. That is because most function calls (and most functions, -/// for that matter) contain fewer than 4 arguments, the exception being closures that capture a -/// large number of external variables. -/// -/// In addition, most script blocks either contain many statements, or just one or two lines; -/// most scripts load fewer than 4 external modules; most module paths contain fewer than 4 levels -/// (e.g. `std::collections::map::HashMap` is 4 levels and it is just about as long as they get). +/// Alias to [`smallvec::SmallVec<[T; 3]>`](https://crates.io/crates/smallvec). #[cfg(not(feature = "internals"))] type StaticVec = smallvec::SmallVec<[T; STATIC_VEC_INLINE_SIZE]>; @@ -454,11 +424,34 @@ type StaticVec = smallvec::SmallVec<[T; STATIC_VEC_INLINE_SIZE]>; #[cfg(feature = "internals")] pub type StaticVec = smallvec::SmallVec<[T; STATIC_VEC_INLINE_SIZE]>; +/// A smaller [`Vec`] alternative. +#[cfg(not(feature = "internals"))] +type ThinVec = thin_vec::ThinVec; + +/// _(internals)_ A smaller [`Vec`] alternative. Exported under the `internals` feature only. +/// +/// The standard [`Vec`] type uses three machine words (i.e. 24 bytes on 64-bit). +/// +/// [`ThinVec`](https://crates.io/crates/thin-vec) only uses one machine word, storing other +/// information inline together with the data. +/// +/// This is primarily used in places where a few bytes affect the size of the type +/// -- e.g. in `enum`'s. +#[cfg(feature = "internals")] +pub type ThinVec = thin_vec::ThinVec; + /// Number of items to keep inline for [`FnArgsVec`]. #[cfg(not(feature = "no_closure"))] const FN_ARGS_VEC_INLINE_SIZE: usize = 5; /// Inline arguments storage for function calls. +#[cfg(not(feature = "no_closure"))] +#[cfg(not(feature = "internals"))] +type FnArgsVec = smallvec::SmallVec<[T; FN_ARGS_VEC_INLINE_SIZE]>; + +/// _(internals)_ Inline arguments storage for function calls. +/// +/// Not available under `no_closure`. /// /// # Notes /// @@ -471,7 +464,8 @@ const FN_ARGS_VEC_INLINE_SIZE: usize = 5; /// /// Under `no_closure`, this type aliases to [`StaticVec`][crate::StaticVec] instead. #[cfg(not(feature = "no_closure"))] -type FnArgsVec = smallvec::SmallVec<[T; FN_ARGS_VEC_INLINE_SIZE]>; +#[cfg(feature = "internals")] +pub type FnArgsVec = smallvec::SmallVec<[T; FN_ARGS_VEC_INLINE_SIZE]>; /// Inline arguments storage for function calls. /// This type aliases to [`StaticVec`][crate::StaticVec]. diff --git a/src/module/mod.rs b/src/module/mod.rs index 6d9d31a3d..4b95184ff 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -2237,7 +2237,7 @@ impl Module { let mut module = Self::new(); // Extra modules left become sub-modules - let mut imports = thin_vec::ThinVec::new(); + let mut imports = crate::ThinVec::new(); if result.is_ok() { global diff --git a/src/parser.rs b/src/parser.rs index b571a13e3..c58b9ba9e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -20,7 +20,7 @@ use crate::types::{ use crate::{ calc_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, ExclusiveRange, FnArgsVec, ImmutableString, InclusiveRange, LexError, OptimizationLevel, ParseError, Position, Scope, - Shared, SmartString, StaticVec, VarDefInfo, AST, PERR, + Shared, SmartString, StaticVec, ThinVec, VarDefInfo, AST, PERR, }; use bitflags::bitflags; #[cfg(feature = "no_std")] @@ -31,7 +31,6 @@ use std::{ hash::{Hash, Hasher}, num::{NonZeroU8, NonZeroUsize}, }; -use thin_vec::ThinVec; pub type ParseResult = Result; diff --git a/src/serde/metadata.rs b/src/serde/metadata.rs index 23d079657..a34903a68 100644 --- a/src/serde/metadata.rs +++ b/src/serde/metadata.rs @@ -5,12 +5,11 @@ use crate::api::formatting::format_param_type_for_display; use crate::func::RhaiFunc; use crate::module::{calc_native_fn_hash, FuncMetadata, ModuleFlags}; use crate::types::custom_types::CustomTypeInfo; -use crate::{calc_fn_hash, Engine, FnAccess, SmartString, AST}; +use crate::{calc_fn_hash, Engine, FnAccess, SmartString, ThinVec, AST}; use serde::{Deserialize, Serialize}; #[cfg(feature = "no_std")] use std::prelude::v1::*; use std::{borrow::Cow, cmp::Ordering, collections::BTreeMap}; -use thin_vec::ThinVec; #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/src/types/fn_ptr.rs b/src/types/fn_ptr.rs index 679ee6817..dd70b68c7 100644 --- a/src/types/fn_ptr.rs +++ b/src/types/fn_ptr.rs @@ -6,7 +6,7 @@ use crate::tokenizer::{is_reserved_keyword_or_symbol, is_valid_function_name, To use crate::types::dynamic::Variant; use crate::{ Dynamic, Engine, FnArgsVec, FuncArgs, ImmutableString, NativeCallContext, Position, RhaiError, - RhaiResult, RhaiResultOf, Shared, StaticVec, AST, ERR, PERR, + RhaiResult, RhaiResultOf, Shared, StaticVec, ThinVec, AST, ERR, PERR, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -16,7 +16,6 @@ use std::{ fmt, mem, ops::{Index, IndexMut}, }; -use thin_vec::ThinVec; /// A general function pointer, which may carry additional (i.e. curried) argument values /// to be passed onto a function during a call. diff --git a/src/types/scope.rs b/src/types/scope.rs index e8622eaa8..ec1d95d29 100644 --- a/src/types/scope.rs +++ b/src/types/scope.rs @@ -1,7 +1,7 @@ //! Module that defines the [`Scope`] type representing a function call-stack scope. use super::dynamic::{AccessMode, Variant}; -use crate::{Dynamic, Identifier, ImmutableString, StaticVec}; +use crate::{Dynamic, Identifier, ImmutableString, StaticVec, ThinVec}; #[cfg(feature = "no_std")] use std::prelude::v1::*; use std::{ @@ -9,7 +9,6 @@ use std::{ iter::{Extend, FromIterator}, marker::PhantomData, }; -use thin_vec::ThinVec; /// Minimum number of entries in the [`Scope`] to avoid reallocations. pub const MIN_SCOPE_ENTRIES: usize = 8; From cb1ec1c595512e78b27b52372a24c5e21afffbf7 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 2 Feb 2024 09:00:50 +0800 Subject: [PATCH 4/5] Bump rhai_codegen version. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4eba5b050..5f3b1040f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ num-traits = { version = "0.2.0", default-features = false } once_cell = { version = "1.7.0", default-features = false, features = ["race"] } bitflags = { version = "2.0.0", default-features = false } smartstring = { version = "1.0.0", default-features = false } -rhai_codegen = { version = "1.17.0", path = "codegen" } +rhai_codegen = { version = "2.0.0", path = "codegen" } no-std-compat = { git = "https://gitlab.com/jD91mZM2/no-std-compat", version = "0.4.1", default-features = false, features = ["alloc"], optional = true } libm = { version = "0.2.0", default-features = false, optional = true } From 375e312f2d5a1ef0bed4dddf4877b9f1b6f319a5 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 2 Feb 2024 09:02:28 +0800 Subject: [PATCH 5/5] Add fix branch to CI. --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0cb327a51..ab476b317 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,6 +5,7 @@ on: branches: - main - master + - fix pull_request: {} env: