Model Swift's type metadata and value witness table for memory layout information#42
Merged
DougGregor merged 4 commits intoOct 5, 2024
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
ktoso
approved these changes
Oct 5, 2024
Collaborator
ktoso
left a comment
There was a problem hiding this comment.
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; |
Collaborator
There was a problem hiding this comment.
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.
Member
Author
|
Tacked on the real API I wanted, which produces a memory layout for a given Swift type |
ktoso
approved these changes
Oct 5, 2024
Collaborator
ktoso
left a comment
There was a problem hiding this comment.
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.
Member
Author
|
We're still working on the Java part of the CI; verified it locally. |
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.
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.Typein 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.MemoryLayoutfor any Swift type. Here's some example output for the Swift typeInt?(mangled name:SiSg):