Skip to content

v1.12.0

Compare
Choose a tag to compare
@schungx schungx released this 31 Dec 04:03
· 619 commits to main since this release
4c2630b

Bug fixes

  • Integer numbers that are too large to deserialize into INT now fall back to Decimal or FLOAT instead of silently truncating.
  • Parsing deeply-nested closures (e.g. ||{||{||{||{||{||{||{...}}}}}}}) no longer panics but will be confined to the nesting limit.
  • Closures containing a single expression are now allowed in Engine::eval_expression etc.
  • Strings interpolation now works under Engine::new_raw without any standard package.
  • Fn now throws an error if the name is a reserved keyword as it cannot possibly map to such a function. This also disallows creating function pointers to custom operators which are defined as disabled keywords (a mouthful), but such custom operators are designed primarily to be used as operators.

Breaking API changes

  • The callback for initializing a debugger instance has changed to Fn(&Engine, Debugger) -> Debugger. This allows more control over the initial setup of the debugger.
  • The internal macro reify! is no longer available publicly.

Deprecated API's

  • Module::with_capacity is deprecated.
  • The internal method Engine::eval_statements_raw is deprecated.
  • Array overloaded methods that take function names (as string) are deprecated in favor of using the Fn("...") call.

Speed improvements

  • The function registration mechanism is revamped to take advantage of constant generics, among others, to omit checking code where possible. This yields a 10-20% speed improvements on certain real-life, function-call-heavy workloads.
  • Functions taking function pointers as parameters, usually called with closures, now run faster because a link to the anonymous function (generated by the closure) is stored together with the function pointer itself. This allows short-circuiting the function lookup step.

Net features

First class functions (sort of)

  • A function pointer created via a closure definition now links to the particular anonymous function itself.
  • This avoids a potentially expensive function lookup when the function pointer is called, speeding up closures.
  • Closures now also encapsulate their defining environment, so function pointers can now be freely exported from modules!

!in

  • A new operator !in is added which maps to !(... in ...).

Engine::call_fn_with_options

  • Engine::call_fn_raw is deprecated in favor of Engine::call_fn_with_options which allows setting options for the function call.
  • The options are for future-proofing the API.
  • In this version, it gains the ability to set the value of the custom state (accessible via NativeCallContext::tag) for a function evaluation, overriding Engine::set_default_tag.

Compact a script for compression

  • Engine::compact_script is added which takes a valid script (it still returns parsing errors) and returns a compacted version of the script with all insignificant whitespaces and all comments removed.
  • A compact script compresses better than one with liberal whitespaces and comments.
  • Unlike some uglifiers or minifiers, Engine::compact_script does not optimize the script in any way, nor does it rename variables.

Enhanced array API

  • Array methods that take a function pointer, usually a closure (e.g. map, filter, index_of, reduce etc.), can now bind the array element to this when calling a closure.
  • This vastly improves performance when working with arrays of large types (e.g. object maps) by avoiding unnecessary cloning.
  • find and find_map are added for arrays.
  • for_each is also added for arrays, allowing a closure to mutate array elements (bound to this) in turn.

Enhancements

  • Optimizations have been done to key data structures to minimize size and creation time, which involves turning rarely-used fields into Option<Box<T>>. This resulted in some speed improvements.
  • CallableFunction is exported under internals.
  • The TypeBuilder type and CustomType trait are no longer marked as volatile.
  • FuncArgs is also implemented for arrays.
  • Engine::set_XXX API can now be chained.
  • EvalContext::scope_mut now returns &mut Scope instead of &mut &mut Scope.
  • Line-style doc-comments are now merged into a single string to avoid creating many strings. Block-style doc-comments continue to be independent strings.
  • Block-style doc-comments are now "un-indented" for better formatting.
  • Doc-comments on plugin modules are now captured in the module's doc field.
  • Expression nesting levels is refined such that it grows less excessively for common patterns.
  • The traits Index and IndexMut are added to FnPtr.
  • FnPtr::iter_curry and FnPtr::iter_curry_mut are added.
  • Dynamic::deep_scan is added to recursively scan for Dynamic values.
  • >> and << operators on integers no longer throw errors when the number of bits to shift is out of bounds. Shifting by a negative number of bits simply reverses the shift direction.