Skip to content

Commit

Permalink
update bindings, add StaticGlobal and StaticSymbol, add tests for jul…
Browse files Browse the repository at this point in the history
…ia_module macro
  • Loading branch information
Taaitaaiger committed Apr 21, 2023
1 parent dee9f26 commit 6faa2d8
Show file tree
Hide file tree
Showing 65 changed files with 2,735 additions and 616 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ matplotlibrc
releasenotes.md
ARCHITECTURE.md
playground
libjulia_module_test.so
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

- `ForeignType` requires `Send + Sync`, whether a `ForeignType` is large or contains pointers to managed data is now expressed with the associated constants `LARGE` and `HAS_POINTERS`, the super type is returned by the trait method `ForeignType::super_type`. Foreign types can be reinitialized with `reinit_foreign_type`, which is available since Julia 1.9.

- `OpaqueType` has been added, which is similar to `ForeignType` except that it can contain no references to Julia data.
- `OpaqueType` has been added, which is similar to `ForeignType` except that it can contain no references to Julia data.

- A managed type for `Binding` has been added, this is available since Julia 1.10.

- The `Jlrs` Julia module is no longer included with jlrs, but published as a separate package.

- The jlrs-derive crate is now part of jlrs-macros. Two additional macros are available: `julia_version` can be used as an alternative to writing big cfgs to handle differences between Julia versions, and `julia_module` to generate the data that `Jlrs.Wrap` uses to make the exported functions, methods, types, constant and globals available in a Julia module.

- Several traits have been added to implement the `julia_module` macro: `CCallArg`, `CCallReturn`, and `ConstructType`, the first two provide a mapping from a Rust type to the types Julia should use in generated Julia functions, the latter is used to construct the `DataType` at runtime. The managed type `TypedValue` has been added to make more types constructible, and `RustResult` to enable writing fallible `ccall`able functions. Similarly, `RankedArray` and `TypedRankedArray` have been added.
- Several traits have been added to implement the `julia_module` macro: `CCallArg`, `CCallReturn`, and `ConstructType`, the first two provide a mapping from a Rust type to the types Julia should use in generated Julia functions, the latter is used to construct the `DataType` at runtime. The managed type `TypedValue` has been added to make more types constructible, and `RustResult` to enable writing fallible `ccall`able functions. Similarly, `RankedArray` and `TypedRankedArray` have been added. A `CCallRef` type has been added to work with Julia `Ref`s that have been used as arguments of `ccall`ed functions.

- The `no-link` feature has been added to skip linking Julia.

- `Dims::n_dimensions` has been renamed to `Dims::rank`.
Expand All @@ -32,6 +32,10 @@

- `LeakedValue` has been removed in favor of making managed data generally leakable by erasing the `'scope` lifetime with `Managed::leak` or `Ref::leak`.

- `CCall` now has `invoke` methods to avoid having to manually create a stack frame.

- Global Julia data can be cached in a static container by using `StaticGlobal` and `StaticSymbol`.


#### v0.17

Expand Down Expand Up @@ -85,13 +89,13 @@

- `Ref` wraps a `NonNull` pointer to Julia data, like wrappers do. Undefinedness is expressed through `Option`.

- Uses of `ValidLayout` have been mostly replaced with `ValidField`. `ValidField` is not implemented for mutable structs because they're not stored inline when used as a field of some other type.
- Uses of `ValidLayout` have been mostly replaced with `ValidField`. `ValidField` is not implemented for mutable structs because they're not stored inline when used as a field of some other type.

- `CCall::throw_exception` has been added and can be used to throw an exception from a `ccall`ed function.

- Add `Affinity` so tasks can be explicitly scheduled on the main runtime thread.

- `Global` has been renamed to `Unrooted`.
- `Global` has been renamed to `Unrooted`.


#### v0.16
Expand Down
9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@

[workspace]
members = [
"examples",
"jl_sys",
"jlrs",
"jlrs_macros",
# "playground"
]
members = ["examples", "jl_sys", "jlrs", "jlrs_macros"]
exclude = ["julia_module_test"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl PersistentTask for AccumulatorTask {
// The data is tracked first to ensure it's not
// already borrowed from Rust.
unsafe {
let mut tracked = state.array.track_mut()?;
let mut tracked = state.array.track_exclusive()?;
let mut data = tracked.bits_data_mut()?;
data[state.offset] = input;
};
Expand Down
2 changes: 1 addition & 1 deletion examples/ccall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub unsafe extern "C" fn add(a: i32, b: i32) -> i32 {
// `Array{Float64}`.
#[no_mangle]
pub unsafe extern "C" fn incr_array(mut arr: TypedArray<f64>) {
let Ok(mut arr) = arr.track_mut() else {
let Ok(mut arr) = arr.track_exclusive() else {
return;
};

Expand Down
8 changes: 4 additions & 4 deletions examples/ccall_with_threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ unsafe impl Send for UvHandle {}
/// task = @async begin
/// condition = Base.AsyncCondition()
/// output = AtomicUInt32(0)
///
///
/// GC.@preserve output begin
/// joinhandle = ccall(("multithreaded", :libccall_with_threads), Ptr{Cvoid},
/// (Any, Ptr{Cvoid}), output, condition.handle)
/// wait(condition)
/// ccall(("drop_handle", :libccall_with_threads), Cvoid, (Ptr{Cvoid},), joinhandle)
///
///
/// @atomic output.v
/// end
/// end
///
///
/// task2 = @async begin
/// @assert fetch(task) == 127 \"Wrong result\"
/// end
///
///
/// wait(task)
/// wait(task2)
/// end
Expand Down
1 change: 1 addition & 0 deletions jl_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ fn generate_bindings(julia_dir: &str) {
.allowlist_function("jlrs_lock")
.allowlist_function("jlrs_unlock")
.allowlist_function("jlrs_array_data_owner_offset")
.allowlist_function("jlrs_gc_queue_multiroot")
.allowlist_function("jl_setjmp")
.allowlist_function("jl_excstack_state")
.allowlist_function("jl_enter_handler")
Expand Down
12 changes: 6 additions & 6 deletions jl_sys/generate_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ function print_help() {
echo "When the beta flag is set, the following is expected:"
echo ""
echo -e "\033[1m Version Default path${spacing}Override\033[0m"
echo " Linux 64-bit 1.9 $HOME/julia-1.9.0-beta4 JULIA_1_9_DIR"
echo " Linux 32-bit 1.9 $HOME/julia-1.9.0-beta4-32 JULIA_1_9_DIR_32"
echo " Windows 64-bit 1.9 $HOME/julia-1.9.0-beta4-win JULIA_1_9_DIR_WIN"
echo " Linux 64-bit 1.9 $HOME/julia-1.9.0-rc1 JULIA_1_9_DIR"
echo " Linux 32-bit 1.9 $HOME/julia-1.9.0-rc1-32 JULIA_1_9_DIR_32"
echo " Windows 64-bit 1.9 $HOME/julia-1.9.0-rc1-win JULIA_1_9_DIR_WIN"
echo ""
echo ""
echo "All dependencies must have been installed before running this script. The"
Expand Down Expand Up @@ -130,23 +130,23 @@ fi

if [ "${BETA}" = "y" -o "${ALL}" = "y" ]; then
if [ -z "$JULIA_1_9_DIR" ]; then
JULIA_1_9_DIR=${HOME}/julia-1.9.0-beta4
JULIA_1_9_DIR=${HOME}/julia-1.9.0-rc1
fi
if [ ! -d "$JULIA_1_9_DIR" ]; then
echo "Error: $JULIA_1_9_DIR does not exist" >&2
exit 1
fi

if [ -z "$JULIA_1_9_DIR_32" ]; then
JULIA_1_9_DIR_32=${HOME}/julia-1.9.0-beta4-32
JULIA_1_9_DIR_32=${HOME}/julia-1.9.0-rc1-32
fi
if [ ! -d "$JULIA_1_9_DIR_32" ]; then
echo "Error: $JULIA_1_9_DIR_32 does not exist" >&2
exit 1
fi

if [ -z "$JULIA_1_9_DIR_WIN" ]; then
JULIA_1_9_DIR_WIN=${HOME}/julia-1.9.0-beta4-win
JULIA_1_9_DIR_WIN=${HOME}/julia-1.9.0-rc1-win
fi
if [ ! -d "$JULIA_1_9_DIR_WIN" ]; then
echo "Error: $JULIA_1_9_DIR_WIN does not exist" >&2
Expand Down
7 changes: 7 additions & 0 deletions jl_sys/src/bindings_1_6_i686_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _mallocarray_t {
Expand Down
7 changes: 7 additions & 0 deletions jl_sys/src/bindings_1_6_x86_64_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _mallocarray_t {
Expand Down
7 changes: 7 additions & 0 deletions jl_sys/src/bindings_1_6_x86_64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _mallocarray_t {
Expand Down
7 changes: 7 additions & 0 deletions jl_sys/src/bindings_1_7_i686_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
extern "C" {
pub fn jlrs_lock(v: *mut jl_value_t);
}
Expand Down
7 changes: 7 additions & 0 deletions jl_sys/src/bindings_1_7_x86_64_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
extern "C" {
pub fn jlrs_lock(v: *mut jl_value_t);
}
Expand Down
7 changes: 7 additions & 0 deletions jl_sys/src/bindings_1_7_x86_64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
extern "C" {
pub fn jlrs_lock(v: *mut jl_value_t);
}
Expand Down
7 changes: 7 additions & 0 deletions jl_sys/src/bindings_1_8_i686_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
extern "C" {
pub fn jlrs_lock(v: *mut jl_value_t);
}
Expand Down
7 changes: 7 additions & 0 deletions jl_sys/src/bindings_1_8_x86_64_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2611,6 +2611,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
extern "C" {
pub fn jlrs_lock(v: *mut jl_value_t);
}
Expand Down
7 changes: 7 additions & 0 deletions jl_sys/src/bindings_1_8_x86_64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
extern "C" {
pub fn jlrs_lock(v: *mut jl_value_t);
}
Expand Down
12 changes: 10 additions & 2 deletions jl_sys/src/bindings_1_9_i686_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* generated from julia version 1.9.0-beta4 */
/* generated from julia version 1.9.0-rc1 */
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct __BindgenBitfieldUnit<Storage> {
Expand Down Expand Up @@ -667,6 +667,7 @@ pub struct _jl_method_instance_t {
pub callbacks: *mut jl_array_t,
pub cache: ::std::sync::atomic::AtomicPtr<_jl_code_instance_t>,
pub inInference: u8,
pub cache_with_orig: u8,
pub precompiled: u8,
}
#[repr(C)]
Expand Down Expand Up @@ -697,7 +698,7 @@ pub struct _jl_code_instance_t {
pub ipo_purity_bits: u32,
pub purity_bits: ::std::sync::atomic::AtomicU32,
pub argescapes: *mut jl_value_t,
pub isspecsig: u8,
pub specsigflags: ::std::sync::atomic::AtomicU8,
pub precompile: ::std::sync::atomic::AtomicU8,
pub relocatability: u8,
pub invoke: ::atomic::Atomic<jl_callptr_t>,
Expand Down Expand Up @@ -2425,6 +2426,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
extern "C" {
pub fn jlrs_lock(v: *mut jl_value_t);
}
Expand Down
12 changes: 10 additions & 2 deletions jl_sys/src/bindings_1_9_x86_64_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* generated from julia version 1.9.0-beta4 */
/* generated from julia version 1.9.0-rc1 */
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct __BindgenBitfieldUnit<Storage> {
Expand Down Expand Up @@ -675,6 +675,7 @@ pub struct _jl_method_instance_t {
pub callbacks: *mut jl_array_t,
pub cache: ::std::sync::atomic::AtomicPtr<_jl_code_instance_t>,
pub inInference: u8,
pub cache_with_orig: u8,
pub precompiled: u8,
}
#[repr(C)]
Expand Down Expand Up @@ -705,7 +706,7 @@ pub struct _jl_code_instance_t {
pub ipo_purity_bits: u32,
pub purity_bits: ::std::sync::atomic::AtomicU32,
pub argescapes: *mut jl_value_t,
pub isspecsig: u8,
pub specsigflags: ::std::sync::atomic::AtomicU8,
pub precompile: ::std::sync::atomic::AtomicU8,
pub relocatability: u8,
pub invoke: ::atomic::Atomic<jl_callptr_t>,
Expand Down Expand Up @@ -2695,6 +2696,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
extern "C" {
pub fn jlrs_lock(v: *mut jl_value_t);
}
Expand Down
12 changes: 10 additions & 2 deletions jl_sys/src/bindings_1_9_x86_64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* generated from julia version 1.9.0-beta4 */
/* generated from julia version 1.9.0-rc1 */
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct __BindgenBitfieldUnit<Storage> {
Expand Down Expand Up @@ -667,6 +667,7 @@ pub struct _jl_method_instance_t {
pub callbacks: *mut jl_array_t,
pub cache: ::std::sync::atomic::AtomicPtr<_jl_code_instance_t>,
pub inInference: u8,
pub cache_with_orig: u8,
pub precompiled: u8,
}
#[repr(C)]
Expand Down Expand Up @@ -697,7 +698,7 @@ pub struct _jl_code_instance_t {
pub ipo_purity_bits: u32,
pub purity_bits: ::std::sync::atomic::AtomicU32,
pub argescapes: *mut jl_value_t,
pub isspecsig: u8,
pub specsigflags: ::std::sync::atomic::AtomicU8,
pub precompile: ::std::sync::atomic::AtomicU8,
pub relocatability: u8,
pub invoke: ::atomic::Atomic<jl_callptr_t>,
Expand Down Expand Up @@ -2425,6 +2426,13 @@ extern "C" {
extern "C" {
pub fn jlrs_array_data_owner_offset(n_dims: u16) -> uint_t;
}
extern "C" {
pub fn jlrs_gc_queue_multiroot(
parent: *mut jl_value_t,
dt: *mut jl_datatype_t,
ptr: *const ::std::os::raw::c_void,
);
}
extern "C" {
pub fn jlrs_lock(v: *mut jl_value_t);
}
Expand Down
Loading

0 comments on commit 6faa2d8

Please sign in to comment.