Commit 4f6f7b5
committed
Initial implementation of a new lowering from a Swift func to
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.@_cdecl func1 parent 9c96f65 commit 4f6f7b5
File tree
17 files changed
+1641
-22
lines changed- Sources/JExtractSwift
- JavaConstants
- SwiftTypes
- Tests/JExtractSwiftTests
- Asserts
17 files changed
+1641
-22
lines changedLines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
38 | 53 | | |
39 | 54 | | |
40 | 55 | | |
| |||
68 | 83 | | |
69 | 84 | | |
70 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
71 | 91 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
0 commit comments