Initial implementation of a new lowering from a Swift func to @_cdecl func#210
Merged
Merged
Conversation
…l` func
Start implementing a more complete and formal lowering from an arbitrary
Swift function to a `@_cdecl`-compatible thunk that calls that function.
This is set up in stages more akin to what you'd see in a compiler:
1. Resolve the syntax trees for the function into a more semantic
representation, for example resolving type names to nominal type
declarations. This includes a simplistic implementation of a symbol
table so we can resolve arbitrary type names.
2. Lower the semantic representation of each function parameter
(including self). How we do this varies based on type:
* Value types (struct / enum) are passed indirectly via
Unsafe(Mutable)RawPointer, using a mutable pointer when the
corresponding parameter is inout.
* Class / actor types are passed directly via UnsafeRawPointer.
* Swift types that map to primitive types (like Swift.Int32) in
passed directly, no translation required.
* Tuple types are recursively "exploded" into multiple parameters.
* Unsafe*BufferPointer types are "exploded" into a pointer and count.
* Typed unsafe pointers types are passed via their raw versions.
3. Lower returns similarly to parameters, using indirect mutable
parameters for the return when we can't return directly.
4. Render the lowered declaration into a FunctionDeclSyntax node,
which can be modified by the client.
At present, we aren't rendering the bodies of these thunks, which need
to effectively undo the transformations described in (3) and (4). For
example, reconstituting a tuple from disparate arguments,
appropriately re-typing and loading from indirectly-passed value
types, and so on. The description of the lowered signature is intended
to provide sufficient information for doing so, but will likely
require tweaking.
At present, this new code is not integrated in the main code path for
jextract-swift. Once it hits feature parity, we'll enable it.
Member
Author
|
I'm going to merge this and continue iterating. |
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
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.
Start implementing a more complete and formal lowering from an arbitrary Swift function to a
@_cdecl-compatible thunk that calls that function. This is set up in stages more akin to what you'd see in a compiler:At present, we aren't rendering the bodies of these thunks, which need to effectively undo the transformations described in (3) and (4). For example, reconstituting a tuple from disparate arguments, appropriately re-typing and loading from indirectly-passed value types, and so on. The description of the lowered signature is intended to provide sufficient information for doing so, but will likely require tweaking.
At present, this new code is not integrated in the main code path for jextract-swift. Once it hits feature parity, we'll enable it.