-
Notifications
You must be signed in to change notification settings - Fork 162
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
Add proposal for value types marked as @frozen #306
Add proposal for value types marked as @frozen #306
Conversation
For value types annotated as @Frozen, Swift calling convention directly handles them if they fit within 4 registers
@@ -106,6 +106,18 @@ Rejected Option 5 would have provided a better ".NET" shape than our selected al | |||
|
|||
In the SwiftAsync calling convention, there is also an Async Context register, similar to the Self and Error registers. Like the error register, the async context must be passed by a pointer value. As a result, similar options apply here, with the same constraints. Additionally, we don't already have an existing `CallConvAsync` calling convention modifier, so going the calling convention route like proposed for the self register is not practical. As a result, we will likely need to use a special type like `SwiftAsyncContext` to represent the async context register, similar to the proposals for the error register and the self register. | |||
|
|||
##### Value types marked as @frozen |
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.
I think this is covered in https://github.com/dotnet/designs/blob/3768dc57e7d90f2b21e17464bffcb590b157a810/proposed/swift-interop.md#structsenums paragraph already.
Can we use the plan described in that paragraph? (Handle non-frozen structs in projection layer, and assume that all structs are frozen in the low-level calling convention.)
If we want to have both frozen and opaque structs in the signature (and not represent opaque structs as
This ensures that we don't need to look at type attributes as part of the signature parsing, which we would prefer not to do. This also ensures that we can detect that a return of a Swift function is an opaque struct (and we can ensure we give it the same behavior as Clang gives a |
Would |
You're right, I don't think we would have enough information with just a If we were to do it as a return type, the JIT would have to know how to find the value witness table, which we don't want to plumb down that deep. If we were to do it as a parameter, then we wouldn't have a way to know if it was supposed to be a return value or not. In that case, I'd go back to my original suggestion and Jan's suggestion of "all structs in a signature are |
It sounds like we are just using I simply trying to clarify precisely why |
Yep. |
Agreed. Since we can't determine the buffer size without the value witness table, we will handle non-frozen structs in projection layer. |
Description
In Swift, when value types are annotated with
@frozen
, the calling convention directly handles them if they can fit within 4 registers. If the runtime supports passing 4-word structs by value and allows designating the self register, the 4-word struct returns, and an exception register, then binding tools should be able to handle most cases without requiring wrappers.