-
Notifications
You must be signed in to change notification settings - Fork 46
Model Swift's type metadata and value witness table for memory layout information #42
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
Model Swift's type metadata and value witness table for memory layout information #42
Conversation
… information Extend the Java SwiftKit with the ability to query the memory layout of an arbitrary Swift type given its Swift type metadata pointer (e.g., `Any.Type` in the Swift world). Use this to show the size, stride, and alignment of `Int?` from the Java side, which produces: Memory layout for Swift.Int?: size = 9 stride = 16 alignment = 8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, might be worth adding a test in java already, even tho most fail on CI they should already be working fine on macOS 😊
* the size of a pointer (aka C's ptrdiff_t). | ||
*/ | ||
public static ValueLayout SWIFT_INT = (ValueLayout.ADDRESS.byteSize() == 4) ? | ||
ValueLayout.JAVA_INT : ValueLayout.JAVA_LONG; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice, instead of guessing by platform. Lgtm
…ft type Given Swift type metadata, inspect the metadata to produce a memory layout for the Swift type that covers its size/alignment and can be used to refer to memory containing a Swift value of that type.
Tacked on the real API I wanted, which produces a memory layout for a given Swift type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, that’ll get us quite far already 🎉
Use this new API to give a name to the memory layout we create for a Swift type.
We're still working on the Java part of the CI; verified it locally. |
Extend the Java SwiftKit with the ability to query the memory layout of an arbitrary Swift type given its Swift type metadata pointer (e.g.,
Any.Type
in the Swift world). Use this to show the size, stride, and alignment ofInt?
from the Java side, determine the name of a Swift type from its metadata, and produce ajava.lang.foreign.MemoryLayout
for any Swift type. Here's some example output for the Swift typeInt?
(mangled name:SiSg
):