-
Notifications
You must be signed in to change notification settings - Fork 341
Make FFI Ractor compatible and allow type retrieval of attached functions+variables #1023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
All objects are shareable now when frozen. All objects can be created in a non-main Ractor. Typedefs are a global mutable state and are not accessable from Ractor other than the main Ractor. So all Function, Struct, etc. must be defined in the main Ractor and can then be used in other Ractors.
The callback is now routet to the Ractor, that created the FFI::Function . Within this Ractor a new ruby thread is created to execute the Proc, like before.
No need to share per thread data object accross ractors.
Ractor-local custom typedefs are used now, since global writable typedefs aren't compatible with Ractor isolation. Now the builtin typedefs are frozen and available for all Ractors. But all custom typedefs are only per Ractor. Actually the global typedefs already were useable in Ractors, if they are resolved in C code. This is because the C code doesn't check the Ractor boundaries.
since there's no need to modify it later on
It is incompatible to our usage of instance variables by the Struct class.
.. and test Ractor compatibility there.
0cd7d7e to
744354b
Compare
larskanis
added a commit
to larskanis/truffleruby
that referenced
this pull request
Apr 26, 2023
This is the corresponding change to revealed type information introduced in ffi/ffi#1023
…o be attached This allows to freeze the FFI::Function immediately, so that it is shareable by Ractor without the need to freeze the module explicit. To make it shareable the typedef hash used for variadic functions is duplicated and made frozen. This creates a small compatibility issue: Only typedefs defined above the variadic function can be used by that function. If a typedef is created after the definition of the variadic function, then this typedef can no longer be used as parameter to that variadic function. Also fix the retrieval of simple (non-struct) global variables per #attached_variables. Closes ffi#975
The term "return_type" is already used in Truffleruby and sounds better to me. On the other hand the term "result_type" was only used in C-ffi as FunctionInfo#result_type, which is an internal class only.
Shareable instance variables on modules are essential for most Ractor specs. They were introduced in ruby-3.1.
And remove support for older rubies.
larskanis
added a commit
to larskanis/truffleruby
that referenced
this pull request
Apr 27, 2023
This is the corresponding change to revealed type information introduced in ffi/ffi#1023
larskanis
added a commit
to larskanis/truffleruby
that referenced
this pull request
Apr 27, 2023
This is the corresponding change to revealed type information introduced in ffi/ffi#1023
Closed
…ary definitions Ractor usable Freeze objects which are immutable from the start are now freezed. This allows these objects to be used by Ractor without make_shareable. This partially reverts commit 4fc6a8c in such a way, that functions are stored in a module variable @ffi_functions. Enums are implemented per FFI::Library not per attached function. To make them shareable they would have to be copied and freezed per function. This would increase memory footprint for the sake of Ractor support. IMHO it's better to mark the module explicit as finished by .freeze to allow its use in a Ractor. This also enables querying the enum definitions from a Ractor. Using a Hash instead of per-function variables allow to use foo! and bar? methods as wished in ffi#971. Fixes ffi#971
For consistency and to ease proting to JRuby and Truffleruby.
larskanis
added a commit
to larskanis/truffleruby
that referenced
this pull request
May 8, 2023
This is the corresponding change to revealed type information introduced in ffi/ffi#1023
..until necessary native methods are added.
john-heinnickel
pushed a commit
to thermofisher-jch/truffleruby
that referenced
this pull request
Aug 16, 2023
This is the corresponding change to revealed type information introduced in ffi/ffi#1023
kojix2
added a commit
to kojix2/ruby-htslib
that referenced
this pull request
Dec 14, 2023
…les instead of class variables. See ffi/ffi#1023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds support for use of FFI in a Ractor. It follows the philosophy of FFI to make using unsafe code as safe as possible. That means in case of Ractor the isolation is preserved for all FFI ruby objects, but the invoked C code can still bypass the isolation.
In a Ractor it's possible to:
In a Ractor it's impossible to:
This PR also adds methods for retrieval of parameter and return types of attached functions and variables as requested in #975 and it solves #992 by storing
FFI::Functioninstances in@ffi_functions.See the commit messages for more details.
Fixes #975
Closes #992