From 9f5783f1a482d6a4d97e1d2fa9d9afb8a0bff43a Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 31 Dec 2022 12:17:36 +0800 Subject: [PATCH 01/15] Bump version. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7cedfea8..90dba115 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [".", "codegen"] [package] name = "rhai" -version = "1.12.0" +version = "1.13.0" rust-version = "1.61.0" edition = "2018" resolver = "2" From ae02668d0859e3cb87312c4abe80ffd3fe392f1e Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 3 Jan 2023 14:00:18 +0800 Subject: [PATCH 02/15] Mark pure. --- CHANGELOG.md | 9 +++++++++ src/packages/array_basic.rs | 38 +++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 135fc201..0ba1bc4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Rhai Release Notes ================== +Version 1.13.0 +============== + +Bug fixes +--------- + +* `map` and `filter` for arrays are marked `pure`. Warnings are added to the documentation of pure array methods that take `this` closures. + + Version 1.12.0 ============== diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index 08c61b9e..7dabd569 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -651,6 +651,8 @@ pub mod array_functions { /// /// Array element (mutable) is bound to `this`. /// + /// This method is marked _pure_; the `mapper` function should not mutate array elements. + /// /// # Function Parameters /// /// * `element`: copy of array element @@ -669,7 +671,7 @@ pub mod array_functions { /// /// print(y); // prints "[0, 2, 6, 12, 20]" /// ``` - #[rhai_fn(return_raw)] + #[rhai_fn(return_raw, pure)] pub fn map(ctx: NativeCallContext, array: &mut Array, map: FnPtr) -> RhaiResultOf { if array.is_empty() { return Ok(Array::new()); @@ -692,6 +694,8 @@ pub mod array_functions { /// /// Array element (mutable) is bound to `this`. /// + /// This method is marked _pure_; the `filter` function should not mutate array elements. + /// /// # Function Parameters /// /// * `element`: copy of array element @@ -710,7 +714,7 @@ pub mod array_functions { /// /// print(y); // prints "[12, 20]" /// ``` - #[rhai_fn(return_raw)] + #[rhai_fn(return_raw, pure)] pub fn filter(ctx: NativeCallContext, array: &mut Array, filter: FnPtr) -> RhaiResultOf { if array.is_empty() { return Ok(Array::new()); @@ -882,6 +886,8 @@ pub mod array_functions { /// /// Array element (mutable) is bound to `this`. /// + /// This method is marked _pure_; the `filter` function should not mutate array elements. + /// /// # Function Parameters /// /// * `element`: copy of array element @@ -922,6 +928,8 @@ pub mod array_functions { /// /// Array element (mutable) is bound to `this`. /// + /// This method is marked _pure_; the `filter` function should not mutate array elements. + /// /// # Function Parameters /// /// * `element`: copy of array element @@ -1011,6 +1019,8 @@ pub mod array_functions { /// /// Array element (mutable) is bound to `this`. /// + /// This method is marked _pure_; the `filter` function should not mutate array elements. + /// /// # Function Parameters /// /// * `element`: copy of array element @@ -1055,6 +1065,8 @@ pub mod array_functions { /// /// Array element (mutable) is bound to `this`. /// + /// This method is marked _pure_; the `mapper` function should not mutate array elements. + /// /// # Function Parameters /// /// * `element`: copy of array element @@ -1087,6 +1099,8 @@ pub mod array_functions { /// /// Array element (mutable) is bound to `this`. /// + /// This method is marked _pure_; the `mapper` function should not mutate array elements. + /// /// # Function Parameters /// /// * `element`: copy of array element @@ -1143,6 +1157,8 @@ pub mod array_functions { /// /// Array element (mutable) is bound to `this`. /// + /// This method is marked _pure_; the `filter` function should not mutate array elements. + /// /// # Function Parameters /// /// * `element`: copy of array element @@ -1185,6 +1201,8 @@ pub mod array_functions { /// /// Array element (mutable) is bound to `this`. /// + /// This method is marked _pure_; the `filter` function should not mutate array elements. + /// /// # Function Parameters /// /// * `element`: copy of array element @@ -1281,9 +1299,11 @@ pub mod array_functions { /// # Function Parameters /// /// * `result`: accumulated result, initially `()` - /// * `element`: copy of array element + /// * `element`: copy of array element, or bound to `this` if omitted /// * `index` _(optional)_: current index in the array /// + /// This method is marked _pure_; the `reducer` function should not mutate array elements. + /// /// # Example /// /// ```rhai @@ -1306,9 +1326,11 @@ pub mod array_functions { /// # Function Parameters /// /// * `result`: accumulated result, starting with the value of `initial` - /// * `element`: copy of array element + /// * `element`: copy of array element, or bound to `this` if omitted /// * `index` _(optional)_: current index in the array /// + /// This method is marked _pure_; the `reducer` function should not mutate array elements. + /// /// # Example /// /// ```rhai @@ -1347,9 +1369,11 @@ pub mod array_functions { /// # Function Parameters /// /// * `result`: accumulated result, initially `()` - /// * `element`: copy of array element + /// * `element`: copy of array element, or bound to `this` if omitted /// * `index` _(optional)_: current index in the array /// + /// This method is marked _pure_; the `reducer` function should not mutate array elements. + /// /// # Example /// /// ```rhai @@ -1373,9 +1397,11 @@ pub mod array_functions { /// # Function Parameters /// /// * `result`: accumulated result, starting with the value of `initial` - /// * `element`: copy of array element + /// * `element`: copy of array element, or bound to `this` if omitted /// * `index` _(optional)_: current index in the array /// + /// This method is marked _pure_; the `reducer` function should not mutate array elements. + /// /// # Example /// /// ```rhai From 541951ec3f2689e362f0c965dea8fa6f73f95d55 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 6 Jan 2023 15:43:53 +0800 Subject: [PATCH 03/15] Remove macro_use in types. --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b6be66eb..a6facbc3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,8 +100,6 @@ use std::prelude::v1::*; mod reify; #[macro_use] mod restore; -#[macro_use] -mod types; mod api; mod ast; @@ -117,6 +115,7 @@ mod parser; pub mod serde; mod tests; mod tokenizer; +mod types; /// Error encountered when parsing a script. type PERR = ParseErrorType; From dd2a0a64aa33219701eb46191cdc79d207b45a58 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 8 Jan 2023 21:15:16 +0800 Subject: [PATCH 04/15] Remove Token::NONE. --- src/tokenizer.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 1f309386..16381ccf 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -276,8 +276,6 @@ pub enum Token { /// End of the input stream. /// Used as a placeholder for the end of input. EOF, - /// Placeholder to indicate the lack of a token. - NONE, } impl fmt::Display for Token { @@ -303,7 +301,6 @@ impl fmt::Display for Token { Comment(s) => f.write_str(s), EOF => f.write_str("{EOF}"), - NONE => f.write_str("{NONE}"), token => f.write_str(token.literal_syntax()), } @@ -332,7 +329,7 @@ impl Token { Custom(..) => false, LexError(..) | Comment(..) => false, - EOF | NONE => false, + EOF => false, _ => true, } From 6d64a75bd2088046e903536493995241d49c0d55 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 11 Jan 2023 09:34:54 +0800 Subject: [PATCH 05/15] Avoid creating new Scope. --- src/eval/chaining.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/eval/chaining.rs b/src/eval/chaining.rs index a31a4867..b7f12554 100644 --- a/src/eval/chaining.rs +++ b/src/eval/chaining.rs @@ -389,6 +389,11 @@ impl Engine { )?, } + #[cfg(feature = "debugging")] + let scope2 = &mut Scope::new(); + #[cfg(not(feature = "debugging"))] + let scope2 = (); + match lhs { // id.??? or id[???] Expr::Variable(.., var_pos) => { @@ -399,7 +404,7 @@ impl Engine { let target = &mut self.search_namespace(global, caches, scope, this_ptr, lhs)?; self.eval_dot_index_chain_raw( - global, caches, None, lhs, expr, target, rhs, idx_values, new_val, + global, caches, scope2, None, lhs, expr, target, rhs, idx_values, new_val, ) } // {expr}.??? = ??? or {expr}[???] = ??? @@ -412,7 +417,8 @@ impl Engine { let obj_ptr = &mut value.into(); self.eval_dot_index_chain_raw( - global, caches, this_ptr, lhs_expr, expr, obj_ptr, rhs, idx_values, new_val, + global, caches, scope2, this_ptr, lhs_expr, expr, obj_ptr, rhs, idx_values, + new_val, ) } } @@ -523,6 +529,8 @@ impl Engine { &self, global: &mut GlobalRuntimeState, caches: &mut Caches, + #[cfg(feature = "debugging")] scope: &mut Scope, + #[cfg(not(feature = "debugging"))] scope: (), this_ptr: Option<&mut Dynamic>, root: &Expr, parent: &Expr, @@ -537,9 +545,6 @@ impl Engine { #[cfg(feature = "debugging")] let mut this_ptr = this_ptr; - #[cfg(feature = "debugging")] - let scope = &mut Scope::new(); - match ChainType::from(parent) { #[cfg(not(feature = "no_index"))] ChainType::Indexing => { @@ -570,8 +575,8 @@ impl Engine { let obj_ptr = &mut obj; match self.eval_dot_index_chain_raw( - global, caches, this_ptr, root, rhs, obj_ptr, &x.rhs, idx_values, - new_val, + global, caches, scope, this_ptr, root, rhs, obj_ptr, &x.rhs, + idx_values, new_val, ) { Ok((result, true)) if is_obj_temp_val => { (Some(obj.take_or_clone()), (result, true)) @@ -880,8 +885,8 @@ impl Engine { }; self.eval_dot_index_chain_raw( - global, caches, _this_ptr, root, rhs, val_target, &x.rhs, idx_values, - new_val, + global, caches, scope, _this_ptr, root, rhs, val_target, &x.rhs, + idx_values, new_val, ) } // xxx.sub_lhs[expr] | xxx.sub_lhs.expr @@ -926,8 +931,8 @@ impl Engine { let val = &mut (&mut val).into(); let (result, may_be_changed) = self.eval_dot_index_chain_raw( - global, caches, _this_ptr, root, rhs, val, &x.rhs, idx_values, - new_val, + global, caches, scope, _this_ptr, root, rhs, val, &x.rhs, + idx_values, new_val, )?; // Feed the value back via a setter just in case it has been updated @@ -994,8 +999,8 @@ impl Engine { let val = &mut val.into(); self.eval_dot_index_chain_raw( - global, caches, _this_ptr, root, rhs, val, &x.rhs, idx_values, - new_val, + global, caches, scope, _this_ptr, root, rhs, val, &x.rhs, + idx_values, new_val, ) } // xxx.module::fn_name(...) - syntax error From ea3efe654cc9a41a3d206836d8f256e2ec175723 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 11 Jan 2023 11:42:46 +0800 Subject: [PATCH 06/15] Avoid unnecessarily creating Scope. --- src/api/compile.rs | 10 +++++++--- src/api/eval.rs | 4 ++-- src/api/formatting.rs | 5 ++--- src/api/json.rs | 5 ++--- src/api/optimize.rs | 2 +- src/api/run.rs | 2 +- src/eval/expr.rs | 2 +- src/func/call.rs | 2 +- src/optimizer.rs | 16 +++++++++------- src/parser.rs | 24 ++++++++++++++---------- 10 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/api/compile.rs b/src/api/compile.rs index 2b949efc..e222e403 100644 --- a/src/api/compile.rs +++ b/src/api/compile.rs @@ -202,7 +202,11 @@ impl Engine { scope: &Scope, scripts: impl AsRef<[S]>, ) -> ParseResult { - self.compile_with_scope_and_optimization_level(scope, scripts, self.optimization_level) + self.compile_with_scope_and_optimization_level( + Some(scope), + scripts, + self.optimization_level, + ) } /// Join a list of strings and compile into an [`AST`] using own scope at a specific optimization level. /// @@ -214,7 +218,7 @@ impl Engine { #[inline] pub(crate) fn compile_with_scope_and_optimization_level>( &self, - scope: &Scope, + scope: Option<&Scope>, scripts: impl AsRef<[S]>, optimization_level: OptimizationLevel, ) -> ParseResult { @@ -291,7 +295,7 @@ impl Engine { let scripts = [script]; let (stream, t) = self.lex_raw(&scripts, self.token_mapper.as_deref()); let interned_strings = &mut *locked_write(&self.interned_strings); - let state = &mut ParseState::new(scope, interned_strings, t); + let state = &mut ParseState::new(Some(scope), interned_strings, t); self.parse_global_expr(stream.peekable(), state, |_| {}, self.optimization_level) } } diff --git a/src/api/eval.rs b/src/api/eval.rs index d08915c4..c9fa2503 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -69,7 +69,7 @@ impl Engine { script: &str, ) -> RhaiResultOf { let ast = self.compile_with_scope_and_optimization_level( - scope, + Some(scope), [script], self.optimization_level, )?; @@ -123,7 +123,7 @@ impl Engine { let (stream, tc) = self.lex_raw(&scripts, self.token_mapper.as_deref()); - let state = &mut ParseState::new(scope, interned_strings, tc); + let state = &mut ParseState::new(Some(scope), interned_strings, tc); // No need to optimize a lone expression self.parse_global_expr( diff --git a/src/api/formatting.rs b/src/api/formatting.rs index d5f24576..9a342d10 100644 --- a/src/api/formatting.rs +++ b/src/api/formatting.rs @@ -4,7 +4,7 @@ use crate::parser::{ParseResult, ParseState}; use crate::types::StringsInterner; use crate::{ Engine, ExclusiveRange, FnPtr, ImmutableString, InclusiveRange, OptimizationLevel, Position, - RhaiError, Scope, SmartString, ERR, + RhaiError, SmartString, ERR, }; use std::any::type_name; #[cfg(feature = "no_std")] @@ -282,9 +282,8 @@ impl Engine { let (mut stream, tc) = self.lex_raw(&scripts, self.token_mapper.as_deref()); tc.borrow_mut().compressed = Some(String::new()); stream.state.last_token = Some(SmartString::new_const()); - let scope = Scope::new(); let mut interner = StringsInterner::new(); - let mut state = ParseState::new(&scope, &mut interner, tc); + let mut state = ParseState::new(None, &mut interner, tc); let mut _ast = self.parse( stream.peekable(), &mut state, diff --git a/src/api/json.rs b/src/api/json.rs index b62c1fb9..24ad805d 100644 --- a/src/api/json.rs +++ b/src/api/json.rs @@ -4,7 +4,7 @@ use crate::func::native::locked_write; use crate::parser::{ParseSettingFlags, ParseState}; use crate::tokenizer::Token; -use crate::{Engine, LexError, Map, OptimizationLevel, RhaiResultOf, Scope}; +use crate::{Engine, LexError, Map, OptimizationLevel, RhaiResultOf}; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -115,9 +115,8 @@ impl Engine { ); let ast = { - let scope = Scope::new(); let interned_strings = &mut *locked_write(&self.interned_strings); - let state = &mut ParseState::new(&scope, interned_strings, tokenizer_control); + let state = &mut ParseState::new(None, interned_strings, tokenizer_control); self.parse_global_expr( stream.peekable(), diff --git a/src/api/optimize.rs b/src/api/optimize.rs index 6ac76b22..92adec95 100644 --- a/src/api/optimize.rs +++ b/src/api/optimize.rs @@ -52,7 +52,7 @@ impl Engine { let mut ast = ast; let mut _new_ast = self.optimize_into_ast( - scope, + Some(scope), ast.take_statements(), #[cfg(not(feature = "no_function"))] ast.shared_lib() diff --git a/src/api/run.rs b/src/api/run.rs index e0f0b49c..77ca5360 100644 --- a/src/api/run.rs +++ b/src/api/run.rs @@ -60,7 +60,7 @@ impl Engine { let ast = { let (stream, tc) = self.lex_raw(&scripts, self.token_mapper.as_deref()); let interned_strings = &mut *locked_write(&self.interned_strings); - let state = &mut ParseState::new(scope, interned_strings, tc); + let state = &mut ParseState::new(Some(scope), interned_strings, tc); self.parse(stream.peekable(), state, self.optimization_level)? }; self.run_ast_with_scope(scope, &ast) diff --git a/src/eval/expr.rs b/src/eval/expr.rs index d99f7d41..75d9c0a5 100644 --- a/src/eval/expr.rs +++ b/src/eval/expr.rs @@ -298,7 +298,7 @@ impl Engine { let source = global.source(); let context = &(self, FUNC_TO_STRING, source, &*global, pos).into(); let display = print_with_func(FUNC_TO_STRING, context, item); - write!(concat, "{}", display).unwrap(); + write!(concat, "{display}").unwrap(); } #[cfg(not(feature = "unchecked"))] diff --git a/src/func/call.rs b/src/func/call.rs index f1f169c2..2532face 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -1518,7 +1518,7 @@ impl Engine { // Compile the script text // No optimizations because we only run it once let ast = self.compile_with_scope_and_optimization_level( - &Scope::new(), + None, [script], #[cfg(not(feature = "no_optimize"))] OptimizationLevel::None, diff --git a/src/optimizer.rs b/src/optimizer.rs index 15d11d2c..ea9c1fd7 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -1288,7 +1288,7 @@ impl Engine { fn optimize_top_level( &self, statements: StmtBlockContainer, - scope: &Scope, + scope: Option<&Scope>, lib: &[crate::SharedModule], optimization_level: OptimizationLevel, ) -> StmtBlockContainer { @@ -1309,11 +1309,13 @@ impl Engine { } // Add constants and variables from the scope - for (name, constant, value) in scope.iter() { - if constant { - state.push_var(name, AccessMode::ReadOnly, Some(value)); - } else { - state.push_var(name, AccessMode::ReadWrite, None); + if let Some(scope) = scope { + for (name, constant, value) in scope.iter() { + if constant { + state.push_var(name, AccessMode::ReadOnly, Some(value)); + } else { + state.push_var(name, AccessMode::ReadWrite, None); + } } } @@ -1323,7 +1325,7 @@ impl Engine { /// Optimize a collection of statements and functions into an [`AST`]. pub(crate) fn optimize_into_ast( &self, - scope: &Scope, + scope: Option<&Scope>, statements: StmtBlockContainer, #[cfg(not(feature = "no_function"))] functions: StaticVec< crate::Shared, diff --git a/src/parser.rs b/src/parser.rs index 6d58af31..60454e37 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -55,7 +55,7 @@ pub struct ParseState<'e, 's> { /// Strings interner. pub interned_strings: &'s mut StringsInterner, /// External [scope][Scope] with constants. - pub scope: &'e Scope<'e>, + pub external_constants: Option<&'e Scope<'e>>, /// Global runtime state. pub global: Option>, /// Encapsulates a local stack with variable names to simulate an actual runtime scope. @@ -87,7 +87,7 @@ impl fmt::Debug for ParseState<'_, '_> { f.field("tokenizer_control", &self.tokenizer_control) .field("interned_strings", &self.interned_strings) - .field("scope", &self.scope) + .field("external_constants_scope", &self.external_constants) .field("global", &self.global) .field("stack", &self.stack) .field("block_stack_len", &self.block_stack_len); @@ -109,7 +109,7 @@ impl<'e, 's> ParseState<'e, 's> { #[inline] #[must_use] pub fn new( - scope: &'e Scope, + external_constants: Option<&'e Scope>, interned_strings: &'s mut StringsInterner, tokenizer_control: TokenizerControl, ) -> Self { @@ -121,7 +121,7 @@ impl<'e, 's> ParseState<'e, 's> { #[cfg(not(feature = "no_closure"))] allow_capture: true, interned_strings, - scope, + external_constants, global: None, stack: None, block_stack_len: 0, @@ -1416,7 +1416,7 @@ impl Engine { // Build new parse state let new_interner = &mut StringsInterner::new(); let new_state = &mut ParseState::new( - state.scope, + state.external_constants, new_interner, state.tokenizer_control.clone(), ); @@ -1476,7 +1476,9 @@ impl Engine { && index.is_none() && !settings.has_flag(ParseSettingFlags::CLOSURE_SCOPE) && settings.has_option(LangOptions::STRICT_VAR) - && !state.scope.contains(name) + && !state + .external_constants + .map_or(false, |scope| scope.contains(name)) { // If the parent scope is not inside another capturing closure // then we can conclude that the captured variable doesn't exist. @@ -1624,7 +1626,9 @@ impl Engine { && !is_func && index.is_none() && settings.has_option(LangOptions::STRICT_VAR) - && !state.scope.contains(&s) + && !state + .external_constants + .map_or(false, |scope| scope.contains(&s)) { return Err( PERR::VariableUndefined(s.to_string()).into_err(settings.pos) @@ -3298,7 +3302,7 @@ impl Engine { (Token::Fn, pos) => { // Build new parse state let new_state = &mut ParseState::new( - state.scope, + state.external_constants, state.interned_strings, state.tokenizer_control.clone(), ); @@ -3848,7 +3852,7 @@ impl Engine { #[cfg(not(feature = "no_optimize"))] return Ok(self.optimize_into_ast( - state.scope, + state.external_constants, statements, #[cfg(not(feature = "no_function"))] functions.into_iter().map(|(.., v)| v).collect(), @@ -3934,7 +3938,7 @@ impl Engine { #[cfg(not(feature = "no_optimize"))] return Ok(self.optimize_into_ast( - state.scope, + state.external_constants, statements, #[cfg(not(feature = "no_function"))] _lib, From c7355395c9681bdd88db6b44ca99dbed1ef40c10 Mon Sep 17 00:00:00 2001 From: Mathieu Lala Date: Sat, 14 Jan 2023 13:58:51 +0100 Subject: [PATCH 07/15] feat: add a feature powerset check --- .github/workflows/build.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7dabfb37..e11278fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -88,6 +88,18 @@ jobs: command: test args: ${{matrix.flags}} + feature_powerset: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + - uses: taiki-e/install-action@v2 + with: + tool: cargo-hack@0.5.25 + - run: cargo hack check --feature-powerset --depth 2 --no-dev-deps --exclude-features "stdweb wasm-bindgen f32_float" + # no-std builds are a bit more extensive to test no_std_build: name: NoStdBuild From 733bb07d2dd3eb0712a0dd0ea3b8fabcaeea57d2 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 25 Jan 2023 07:37:44 +0800 Subject: [PATCH 08/15] Fix bug in chain parsing. --- CHANGELOG.md | 1 + src/parser.rs | 6 ++++-- tests/arrays.rs | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ba1bc4f..df828457 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Version 1.13.0 Bug fixes --------- +* Complex indexing/dotting chains now parse correctly, for example: `a[b][c[d]].e` * `map` and `filter` for arrays are marked `pure`. Warnings are added to the documentation of pure array methods that take `this` closures. diff --git a/src/parser.rs b/src/parser.rs index 60454e37..1230dbfc 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2102,8 +2102,10 @@ impl Engine { op_pos: Position, ) -> ParseResult { match (lhs, rhs) { - // lhs[idx_expr].rhs - (Expr::Index(mut x, options, pos), rhs) => { + // lhs[...][...].rhs + (Expr::Index(mut x, options, pos), rhs) + if !parent_options.contains(ASTFlags::BREAK) => + { let options = options | parent_options; x.rhs = Self::make_dot_expr(state, x.rhs, rhs, options, op_flags, op_pos)?; Ok(Expr::Index(x, ASTFlags::NONE, pos)) diff --git a/tests/arrays.rs b/tests/arrays.rs index e0d5226e..fe8b7b81 100644 --- a/tests/arrays.rs +++ b/tests/arrays.rs @@ -133,6 +133,20 @@ fn test_arrays() -> Result<(), Box> { ); } + #[cfg(not(feature = "no_object"))] + assert_eq!( + engine.eval::( + " + let x = #{ foo: 42 }; + let n = 0; + let a = [[x]]; + let i = [n]; + a[n][i[n]].foo + " + )?, + 42 + ); + assert_eq!( engine .eval::( From f4949a2beb805cc5531836de3a6768eea4e00c4f Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 27 Jan 2023 22:31:14 +0800 Subject: [PATCH 09/15] Always search scope after scope is modified. --- src/eval/debugger.rs | 11 +++++++++-- src/eval/expr.rs | 11 ++++++++++- src/eval/stmt.rs | 9 ++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/eval/debugger.rs b/src/eval/debugger.rs index 1bc1a5a5..652134a3 100644 --- a/src/eval/debugger.rs +++ b/src/eval/debugger.rs @@ -505,14 +505,21 @@ impl Engine { event: DebuggerEvent, ) -> Result, Box> { if let Some(ref x) = self.debugger_interface { + let orig_scope_len = scope.len(); + let src = global.source_raw().cloned(); let src = src.as_ref().map(|s| s.as_str()); let context = EvalContext::new(self, global, caches, scope, this_ptr); let (.., ref on_debugger) = **x; - let command = on_debugger(context, event, node, src, node.position())?; + let command = on_debugger(context, event, node, src, node.position()); - match command { + if orig_scope_len != scope.len() { + // The scope is changed, always search from now on + global.always_search_scope = true; + } + + match command? { DebuggerCommand::Continue => { global.debugger_mut().status = DebuggerStatus::CONTINUE; Ok(None) diff --git a/src/eval/expr.rs b/src/eval/expr.rs index 75d9c0a5..925a8132 100644 --- a/src/eval/expr.rs +++ b/src/eval/expr.rs @@ -174,9 +174,18 @@ impl Engine { // Check the variable resolver, if any if let Some(ref resolve_var) = self.resolve_var { + let orig_scope_len = scope.len(); + let context = EvalContext::new(self, global, caches, scope, this_ptr); let var_name = expr.get_variable_name(true).expect("`Expr::Variable`"); - match resolve_var(var_name, index, context) { + let resolved_var = resolve_var(var_name, index, context); + + if orig_scope_len != scope.len() { + // The scope is changed, always search from now on + global.always_search_scope = true; + } + + match resolved_var { Ok(Some(mut result)) => { result.set_access_mode(AccessMode::ReadOnly); return Ok(result.into()); diff --git a/src/eval/stmt.rs b/src/eval/stmt.rs index db2523ff..f9111ce6 100644 --- a/src/eval/stmt.rs +++ b/src/eval/stmt.rs @@ -728,10 +728,17 @@ impl Engine { nesting_level: global.scope_level, will_shadow, }; + let orig_scope_len = scope.len(); let context = EvalContext::new(self, global, caches, scope, this_ptr.as_deref_mut()); + let filter_result = filter(true, info, context); - if !filter(true, info, context)? { + if orig_scope_len != scope.len() { + // The scope is changed, always search from now on + global.always_search_scope = true; + } + + if !filter_result? { return Err(ERR::ErrorForbiddenVariable(var_name.to_string(), *pos).into()); } } From 2c631daa07b01fb057c0b2350aefef14b95ec2c3 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 28 Jan 2023 12:40:42 +0800 Subject: [PATCH 10/15] Add test for auto global constants for global namespace. --- tests/functions.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/functions.rs b/tests/functions.rs index 8e4a7f36..af9b9ba0 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -143,6 +143,21 @@ fn test_functions_global_module() -> Result<(), Box> { 123 ); + // Other globals + let mut module = Module::new(); + module.set_var("ANSWER", 123 as INT); + engine.register_global_module(module.into()); + + assert_eq!( + engine.eval::( + " + fn foo() { global::ANSWER } + foo() + " + )?, + 123 + ); + Ok(()) } From 62696853b426553592d2ee703312f65d93b9cf60 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 29 Jan 2023 15:23:33 +0800 Subject: [PATCH 11/15] Fix bug with parsing improper module separator. --- CHANGELOG.md | 1 + src/parser.rs | 82 +++++++++++++++++++++++++++++++++++------------- tests/modules.rs | 7 +++++ 3 files changed, 69 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df828457..ce0981c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Bug fixes * Complex indexing/dotting chains now parse correctly, for example: `a[b][c[d]].e` * `map` and `filter` for arrays are marked `pure`. Warnings are added to the documentation of pure array methods that take `this` closures. +* Syntax such as `foo.bar::baz` no longer panics, but returns a proper parse error. Version 1.12.0 diff --git a/src/parser.rs b/src/parser.rs index 1230dbfc..3088825e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -65,12 +65,15 @@ pub struct ParseState<'e, 's> { /// Tracks a list of external variables (variables that are not explicitly declared in the scope). #[cfg(not(feature = "no_closure"))] pub external_vars: Option>>, - /// An indicator that disables variable capturing into externals one single time - /// up until the nearest consumed Identifier token. - /// If set to false the next call to [`access_var`][ParseState::access_var] will not capture the variable. - /// All consequent calls to [`access_var`][ParseState::access_var] will not be affected. + /// An indicator that, when set to `false`, disables variable capturing into externals one + /// single time up until the nearest consumed Identifier token. + /// If set to false the next call to [`access_var`][ParseState::access_var] will not capture the + /// variable. All consequent calls to [`access_var`][ParseState::access_var] will not be affected. #[cfg(not(feature = "no_closure"))] pub allow_capture: bool, + /// If set to `false`, no namespace-qualified identifiers are parsed. + #[cfg(not(feature = "no_module"))] + pub allow_namespace: bool, /// Encapsulates a local stack with imported [module][crate::Module] names. #[cfg(not(feature = "no_module"))] pub imports: Option>>, @@ -98,7 +101,8 @@ impl fmt::Debug for ParseState<'_, '_> { #[cfg(not(feature = "no_module"))] f.field("imports", &self.imports) - .field("global_imports", &self.global_imports); + .field("global_imports", &self.global_imports) + .field("allow_namespace", &self.allow_namespace); f.finish() } @@ -120,6 +124,8 @@ impl<'e, 's> ParseState<'e, 's> { external_vars: None, #[cfg(not(feature = "no_closure"))] allow_capture: true, + #[cfg(not(feature = "no_module"))] + allow_namespace: true, interned_strings, external_constants, global: None, @@ -456,8 +462,8 @@ fn ensure_not_statement_expr( /// Make sure that the next expression is not a mis-typed assignment (i.e. `a = b` instead of `a == b`). fn ensure_not_assignment(input: &mut TokenStream) -> ParseResult<()> { match input.peek().expect(NEVER_ENDS) { - (Token::Equals, pos) => Err(LexError::ImproperSymbol( - "=".into(), + (token @ Token::Equals, pos) => Err(LexError::ImproperSymbol( + token.literal_syntax().into(), "Possibly a typo of '=='?".into(), ) .into_err(*pos)), @@ -1593,9 +1599,9 @@ impl Engine { token => unreachable!("Token::Identifier expected but gets {:?}", token), }; - match input.peek().expect(NEVER_ENDS).0 { + match input.peek().expect(NEVER_ENDS) { // Function call - Token::LeftParen | Token::Bang | Token::Unit => { + (Token::LeftParen | Token::Bang | Token::Unit, _) => { #[cfg(not(feature = "no_closure"))] { // Once the identifier consumed we must enable next variables capturing @@ -1609,7 +1615,15 @@ impl Engine { } // Namespace qualification #[cfg(not(feature = "no_module"))] - Token::DoubleColon => { + (token @ Token::DoubleColon, pos) => { + if !state.allow_namespace { + return Err(LexError::ImproperSymbol( + token.literal_syntax().into(), + String::new(), + ) + .into_err(*pos)); + } + #[cfg(not(feature = "no_closure"))] { // Once the identifier consumed we must enable next variables capturing @@ -1751,6 +1765,10 @@ impl Engine { let (.., ns, _, name) = *x; settings.pos = pos; + + #[cfg(not(feature = "no_module"))] + auto_restore! { let orig_allow_namespace = state.allow_namespace; state.allow_namespace = true } + self.parse_fn_call(input, state, lib, settings, name, no_args, true, ns)? } // Function call @@ -1758,8 +1776,21 @@ impl Engine { let (.., ns, _, name) = *x; let no_args = t == Token::Unit; settings.pos = pos; + + #[cfg(not(feature = "no_module"))] + auto_restore! { let orig_allow_namespace = state.allow_namespace; state.allow_namespace = true } + self.parse_fn_call(input, state, lib, settings, name, no_args, false, ns)? } + // Disallowed module separator + #[cfg(not(feature = "no_module"))] + (_, token @ Token::DoubleColon) if !state.allow_namespace => { + return Err(LexError::ImproperSymbol( + token.literal_syntax().into(), + String::new(), + ) + .into_err(tail_pos)) + } // module access #[cfg(not(feature = "no_module"))] (Expr::Variable(x, .., pos), Token::DoubleColon) => { @@ -1769,15 +1800,16 @@ impl Engine { namespace.push(var_name_def); - Expr::Variable( - (None, namespace, 0, state.get_interned_string(id2)).into(), - None, - pos2, - ) + let var_name = state.get_interned_string(id2); + + Expr::Variable((None, namespace, 0, var_name).into(), None, pos2) } // Indexing #[cfg(not(feature = "no_index"))] (expr, token @ (Token::LeftBracket | Token::QuestionBracket)) => { + #[cfg(not(feature = "no_module"))] + auto_restore! { let orig_allow_namespace = state.allow_namespace; state.allow_namespace = true } + let opt = match token { Token::LeftBracket => ASTFlags::NONE, Token::QuestionBracket => ASTFlags::NEGATED, @@ -1805,7 +1837,13 @@ impl Engine { (.., pos) => return Err(PERR::PropertyExpected.into_err(*pos)), } - let rhs = self.parse_primary(input, state, lib, settings.level_up()?, true)?; + let rhs = { + #[cfg(not(feature = "no_module"))] + auto_restore! { let orig_allow_namespace = state.allow_namespace; state.allow_namespace = false } + + self.parse_primary(input, state, lib, settings.level_up()?, true)? + }; + let op_flags = match op { Token::Period => ASTFlags::NONE, Token::Elvis => ASTFlags::NEGATED, @@ -2081,11 +2119,13 @@ impl Engine { } } // ??? && ??? = rhs, ??? || ??? = rhs, xxx ?? xxx = rhs - Expr::And(..) | Expr::Or(..) | Expr::Coalesce(..) => Err(LexError::ImproperSymbol( - "=".into(), - "Possibly a typo of '=='?".into(), - ) - .into_err(op_pos)), + Expr::And(..) | Expr::Or(..) | Expr::Coalesce(..) if !op_info.is_op_assignment() => { + Err(LexError::ImproperSymbol( + Token::Equals.literal_syntax().into(), + "Possibly a typo of '=='?".into(), + ) + .into_err(op_pos)) + } // expr = rhs _ => Err(PERR::AssignmentToInvalidLHS(String::new()).into_err(lhs.position())), } diff --git a/tests/modules.rs b/tests/modules.rs index babc862a..2c74e935 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -14,6 +14,13 @@ fn test_module() { assert_eq!(module.get_var_value::("answer").unwrap(), 42); } +#[test] +fn test_module_syntax() { + let engine = Engine::new(); + assert!(engine.compile("abc.def::xyz").is_err()); + assert!(engine.compile("abc.def::xyz()").is_err()); +} + #[test] fn test_module_sub_module() -> Result<(), Box> { let mut module = Module::new(); From 9f966f64734162817b1d046857f87d334a13028a Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 29 Jan 2023 16:01:34 +0800 Subject: [PATCH 12/15] Fix test output. --- codegen/ui_tests/rhai_fn_duplicate_attr.stderr | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/codegen/ui_tests/rhai_fn_duplicate_attr.stderr b/codegen/ui_tests/rhai_fn_duplicate_attr.stderr index c8101565..57ce356d 100644 --- a/codegen/ui_tests/rhai_fn_duplicate_attr.stderr +++ b/codegen/ui_tests/rhai_fn_duplicate_attr.stderr @@ -4,14 +4,14 @@ error: duplicated attribute 'rhai_fn' 6 | #[rhai_fn(pure)] | ^ -error[E0433]: failed to resolve: use of undeclared crate or module `test_module` - --> ui_tests/rhai_fn_duplicate_attr.rs:13:8 - | -13 | if test_module::test_fn(n) { - | ^^^^^^^^^^^ use of undeclared crate or module `test_module` - error[E0425]: cannot find value `n` in this scope --> ui_tests/rhai_fn_duplicate_attr.rs:13:29 | 13 | if test_module::test_fn(n) { | ^ not found in this scope + +error[E0433]: failed to resolve: use of undeclared crate or module `test_module` + --> ui_tests/rhai_fn_duplicate_attr.rs:13:8 + | +13 | if test_module::test_fn(n) { + | ^^^^^^^^^^^ use of undeclared crate or module `test_module` From 6400b33b1b60a4d0ac60e72b6f5adaff91d42561 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 30 Jan 2023 12:31:33 +0800 Subject: [PATCH 13/15] Use bitflag options for chains parsing. --- src/func/call.rs | 4 +- src/parser.rs | 101 +++++++++++++++++++++-------------------------- 2 files changed, 48 insertions(+), 57 deletions(-) diff --git a/src/func/call.rs b/src/func/call.rs index 2532face..837d6fb7 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -11,7 +11,7 @@ use crate::eval::{Caches, FnResolutionCacheEntry, GlobalRuntimeState}; use crate::tokenizer::{is_valid_function_name, Token}; use crate::{ calc_fn_hash, calc_fn_hash_full, Dynamic, Engine, FnArgsVec, FnPtr, ImmutableString, - OptimizationLevel, Position, RhaiError, RhaiResult, RhaiResultOf, Scope, Shared, ERR, + OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, Shared, ERR, }; #[cfg(feature = "no_std")] use hashbrown::hash_map::Entry; @@ -1053,7 +1053,7 @@ impl Engine { let mut arg_values = curry .into_iter() .map(Ok) - .chain(a_expr.iter().map(|expr| -> Result<_, RhaiError> { + .chain(a_expr.iter().map(|expr| -> Result<_, crate::RhaiError> { let this_ptr = this_ptr.as_deref_mut(); self.get_arg_value(global, caches, scope, this_ptr, expr) .map(|(v, ..)| v) diff --git a/src/parser.rs b/src/parser.rs index 3088825e..590d97f3 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -67,13 +67,12 @@ pub struct ParseState<'e, 's> { pub external_vars: Option>>, /// An indicator that, when set to `false`, disables variable capturing into externals one /// single time up until the nearest consumed Identifier token. - /// If set to false the next call to [`access_var`][ParseState::access_var] will not capture the - /// variable. All consequent calls to [`access_var`][ParseState::access_var] will not be affected. - #[cfg(not(feature = "no_closure"))] + /// + /// If set to `false` the next call to [`access_var`][ParseState::access_var] will not capture + /// the variable. + /// + /// All consequent calls to [`access_var`][ParseState::access_var] will not be affected. pub allow_capture: bool, - /// If set to `false`, no namespace-qualified identifiers are parsed. - #[cfg(not(feature = "no_module"))] - pub allow_namespace: bool, /// Encapsulates a local stack with imported [module][crate::Module] names. #[cfg(not(feature = "no_module"))] pub imports: Option>>, @@ -101,8 +100,7 @@ impl fmt::Debug for ParseState<'_, '_> { #[cfg(not(feature = "no_module"))] f.field("imports", &self.imports) - .field("global_imports", &self.global_imports) - .field("allow_namespace", &self.allow_namespace); + .field("global_imports", &self.global_imports); f.finish() } @@ -122,10 +120,7 @@ impl<'e, 's> ParseState<'e, 's> { expr_filter: |_| true, #[cfg(not(feature = "no_closure"))] external_vars: None, - #[cfg(not(feature = "no_closure"))] allow_capture: true, - #[cfg(not(feature = "no_module"))] - allow_namespace: true, interned_strings, external_constants, global: None, @@ -302,11 +297,8 @@ bitflags! { /// Is the construct being parsed located at global level? const GLOBAL_LEVEL = 0b0000_0001; /// Is the construct being parsed located inside a function definition? - #[cfg(not(feature = "no_function"))] const FN_SCOPE = 0b0000_0010; /// Is the construct being parsed located inside a closure definition? - #[cfg(not(feature = "no_function"))] - #[cfg(not(feature = "no_closure"))] const CLOSURE_SCOPE = 0b0000_0100; /// Is the construct being parsed located inside a breakable loop? const BREAKABLE = 0b0000_1000; @@ -318,6 +310,16 @@ bitflags! { } } +bitflags! { + /// Bit-flags containing all status for parsing property/indexing/namespace chains. + struct ChainingFlags: u8 { + /// Is the construct being parsed a property? + const PROPERTY = 0b0000_0001; + /// Disallow namespaces? + const DISALLOW_NAMESPACES = 0b0000_0010; + } +} + /// A type that encapsulates all the settings for a particular parsing function. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub struct ParseSettings { @@ -1314,7 +1316,7 @@ impl Engine { state: &mut ParseState, lib: &mut FnLib, settings: ParseSettings, - is_property: bool, + options: ChainingFlags, ) -> ParseResult { let (token, token_pos) = input.peek().expect(NEVER_ENDS); @@ -1450,15 +1452,13 @@ impl Engine { #[cfg(feature = "no_closure")] let options = self.options | (settings.options & LangOptions::STRICT_VAR); - // Brand new flags, turn on function scope + // Brand new flags, turn on function scope and closure scope let flags = ParseSettingFlags::FN_SCOPE + | ParseSettingFlags::CLOSURE_SCOPE | (settings.flags & (ParseSettingFlags::DISALLOW_UNQUOTED_MAP_PROPERTIES | ParseSettingFlags::DISALLOW_STATEMENTS_IN_BLOCKS)); - #[cfg(not(feature = "no_closure"))] - let flags = flags | ParseSettingFlags::CLOSURE_SCOPE; // turn on closure scope - let new_settings = ParseSettings { flags, options, @@ -1602,11 +1602,9 @@ impl Engine { match input.peek().expect(NEVER_ENDS) { // Function call (Token::LeftParen | Token::Bang | Token::Unit, _) => { - #[cfg(not(feature = "no_closure"))] - { - // Once the identifier consumed we must enable next variables capturing - state.allow_capture = true; - } + // Once the identifier consumed we must enable next variables capturing + state.allow_capture = true; + Expr::Variable( (None, ns, 0, state.get_interned_string(*s)).into(), None, @@ -1616,7 +1614,7 @@ impl Engine { // Namespace qualification #[cfg(not(feature = "no_module"))] (token @ Token::DoubleColon, pos) => { - if !state.allow_namespace { + if options.contains(ChainingFlags::DISALLOW_NAMESPACES) { return Err(LexError::ImproperSymbol( token.literal_syntax().into(), String::new(), @@ -1624,11 +1622,9 @@ impl Engine { .into_err(*pos)); } - #[cfg(not(feature = "no_closure"))] - { - // Once the identifier consumed we must enable next variables capturing - state.allow_capture = true; - } + // Once the identifier consumed we must enable next variables capturing + state.allow_capture = true; + let name = state.get_interned_string(*s); Expr::Variable((None, ns, 0, name).into(), None, settings.pos) } @@ -1636,7 +1632,7 @@ impl Engine { _ => { let (index, is_func) = state.access_var(&s, lib, settings.pos); - if !is_property + if !options.contains(ChainingFlags::PROPERTY) && !is_func && index.is_none() && settings.has_option(LangOptions::STRICT_VAR) @@ -1708,7 +1704,14 @@ impl Engine { return Ok(root_expr); } - self.parse_postfix(input, state, lib, settings, root_expr) + self.parse_postfix( + input, + state, + lib, + settings, + root_expr, + ChainingFlags::empty(), + ) } /// Tail processing of all possible postfix operators of a primary expression. @@ -1719,6 +1722,7 @@ impl Engine { lib: &mut FnLib, settings: ParseSettings, mut lhs: Expr, + options: ChainingFlags, ) -> ParseResult { let mut settings = settings; @@ -1766,9 +1770,6 @@ impl Engine { let (.., ns, _, name) = *x; settings.pos = pos; - #[cfg(not(feature = "no_module"))] - auto_restore! { let orig_allow_namespace = state.allow_namespace; state.allow_namespace = true } - self.parse_fn_call(input, state, lib, settings, name, no_args, true, ns)? } // Function call @@ -1777,14 +1778,13 @@ impl Engine { let no_args = t == Token::Unit; settings.pos = pos; - #[cfg(not(feature = "no_module"))] - auto_restore! { let orig_allow_namespace = state.allow_namespace; state.allow_namespace = true } - self.parse_fn_call(input, state, lib, settings, name, no_args, false, ns)? } // Disallowed module separator #[cfg(not(feature = "no_module"))] - (_, token @ Token::DoubleColon) if !state.allow_namespace => { + (_, token @ Token::DoubleColon) + if options.contains(ChainingFlags::DISALLOW_NAMESPACES) => + { return Err(LexError::ImproperSymbol( token.literal_syntax().into(), String::new(), @@ -1807,9 +1807,6 @@ impl Engine { // Indexing #[cfg(not(feature = "no_index"))] (expr, token @ (Token::LeftBracket | Token::QuestionBracket)) => { - #[cfg(not(feature = "no_module"))] - auto_restore! { let orig_allow_namespace = state.allow_namespace; state.allow_namespace = true } - let opt = match token { Token::LeftBracket => ASTFlags::NONE, Token::QuestionBracket => ASTFlags::NEGATED, @@ -1824,11 +1821,8 @@ impl Engine { // Expression after dot must start with an identifier match input.peek().expect(NEVER_ENDS) { (Token::Identifier(..), ..) => { - #[cfg(not(feature = "no_closure"))] - { - // Prevents capturing of the object properties as vars: xxx. - state.allow_capture = false; - } + // Prevents capturing of the object properties as vars: xxx. + state.allow_capture = false; } (Token::Reserved(s), ..) if is_keyword_function(s).1 => (), (Token::Reserved(s), pos) => { @@ -1837,18 +1831,15 @@ impl Engine { (.., pos) => return Err(PERR::PropertyExpected.into_err(*pos)), } - let rhs = { - #[cfg(not(feature = "no_module"))] - auto_restore! { let orig_allow_namespace = state.allow_namespace; state.allow_namespace = false } - - self.parse_primary(input, state, lib, settings.level_up()?, true)? - }; - let op_flags = match op { Token::Period => ASTFlags::NONE, Token::Elvis => ASTFlags::NEGATED, _ => unreachable!("`.` or `?.`"), }; + let options = ChainingFlags::PROPERTY | ChainingFlags::DISALLOW_NAMESPACES; + let rhs = + self.parse_primary(input, state, lib, settings.level_up()?, options)?; + Self::make_dot_expr(state, expr, rhs, ASTFlags::NONE, op_flags, tail_pos)? } // Unknown postfix operator @@ -2020,7 +2011,7 @@ impl Engine { // Token::EOF => Err(PERR::UnexpectedEOF.into_err(settings.pos)), // All other tokens - _ => self.parse_primary(input, state, lib, settings, false), + _ => self.parse_primary(input, state, lib, settings, ChainingFlags::empty()), } } From 933ffbc3fc4f8cd0a8533841fd84409bc3049eca Mon Sep 17 00:00:00 2001 From: Mathieu Lala Date: Sun, 5 Feb 2023 13:16:55 +0100 Subject: [PATCH 14/15] feat: for a manual job for --- .github/workflows/build.yml | 12 ------------ .github/workflows/ci.yaml | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e11278fb..7dabfb37 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -88,18 +88,6 @@ jobs: command: test args: ${{matrix.flags}} - feature_powerset: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@v1 - with: - toolchain: stable - - uses: taiki-e/install-action@v2 - with: - tool: cargo-hack@0.5.25 - - run: cargo hack check --feature-powerset --depth 2 --no-dev-deps --exclude-features "stdweb wasm-bindgen f32_float" - # no-std builds are a bit more extensive to test no_std_build: name: NoStdBuild diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..3e8e342a --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,25 @@ +name: Manual CI + +on: + workflow_dispatch: + inputs: + depth: + description: "Specify a max number of simultaneous feature flags" + required: true + type: string + default: "2" + +jobs: + feature_powerset: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@v1 + with: + toolchain: stable + - uses: taiki-e/install-action@v2 + with: + tool: cargo-hack@0.5.25 + - run: cargo hack check --feature-powerset --depth ${{ inputs.depth }} --no-dev-deps --exclude-features $FEATURE_EXCLUDE + env: + FEATURE_EXCLUDE: "no_std stdweb wasm-bindgen f32_float only_i32 unicode-xid-ident bin-features" From da2d3adaef9715ae2280c3bb6a98531e58ea0427 Mon Sep 17 00:00:00 2001 From: Mathieu Lala Date: Sun, 5 Feb 2023 13:22:44 +0100 Subject: [PATCH 15/15] fix: exclude feature --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3e8e342a..6b751bc8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,6 +20,6 @@ jobs: - uses: taiki-e/install-action@v2 with: tool: cargo-hack@0.5.25 - - run: cargo hack check --feature-powerset --depth ${{ inputs.depth }} --no-dev-deps --exclude-features $FEATURE_EXCLUDE + - run: cargo hack check --feature-powerset --depth ${{ inputs.depth }} --no-dev-deps --exclude-features "$FEATURE_EXCLUDE" env: FEATURE_EXCLUDE: "no_std stdweb wasm-bindgen f32_float only_i32 unicode-xid-ident bin-features"