[ANN] jlrs 0.24 and JlrsCore 0.8: StaticArrays support, safety updates, and more!

jlrs is a crate for the Rust programming language for interop between Rust and Julia, version 0.24 brings several changes and new features. The tutorial has been updated to this new version.

Version support

Julia versions 1.10 up to and including 1.13 are supported. The MSRV is 1.97. The JlrsCore package has been updated to version 0.8, jlrs v0.24 is not compatible with earlier versions of JlrsCore.

jlrs-launcher has received several bugfixes and is now at version 0.1.2. It can be updated or installed with the command cargo install jlrs-launcher.

Scope safety changes

Julia’s exceptions and Rust’s panics don’t mix. It’s unsound to Rust-unwind through a Julia-try, and it’s unsound for a Julia exception to jump over any pending Rust-drops and Rust-catch_unwinds. While it’s still recommended to keep the panic setting set to abort, all methods that create local scopes now document whether they are exception-safe or panic-safe.

Since only unsafe methods can call functions without a try/catch statement and any Rust code can panic, panic-safe scopes are safe to create and exception-safe scopes unsafe.

Value-based typechecking

The method typecheck_val has been added to the Typecheck trait, which can be implemented if the typecheck can be performed without accessing the data’s type.

StaticArrays support

When the static-arrays feature is enabled, bindings for SVector, SMatrix, SArray, MVector, MMatrix and MArray are provided. These types can be used when embedding Julia and as argument and return types in exported functions. The for-loop in julia_module supports looping over constants to help avoid repetition if a function is exported for multiple sizes.

When a package like StaticArrays is used by a generated module, this package must be passed to the @initjlrs macro: @initjlrs [StaticArrays].

Generated module documentation with source links to Rust

A library can now be compiled with the jl-docs feature, in this case the full path to the Rust source file is encoded in the exported documentation. When Documenter is used, the source links will link to the original definition in jl_module. If this feature is disabled, no source links are generated.

Static caching for constructed types with parameters

jlrs normally caches constructed types with parameters in a global HashMap, which is significantly slower than the single static variable that is used to cache a type without parameters. When the static-cache feature is enabled, the static-generics crate is used to effectively cache constructed types in static variables.

GitHub
jlrs-launcher
Docs
Tutorial

1 Like