Skip to content
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

Specify how function pointers will handle context registers #309

Merged
4 changes: 2 additions & 2 deletions proposed/swift-interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ We have selected the following option for supporting the Self register in the ca

1. Use specially-typed argument with a type, `SwiftSelf`, to represent which parameter should go into the self register.

We will provide a `SwiftSelf` type to specify "this argument goes in the self register". Specifying the type twice in a signature would generate an `InvalidProgramException`. This would allow the `self` argument to be specified anywhere in the argument list. Alternatively, many sections of the Swift ABI documentation, as well as the Clang docs refer to this parameter as the "context" argument instead of the "self" argument, so an alternative name could be `SwiftContext`.
We will provide a `SwiftSelf` type to specify "this argument goes in the self register". Specifying the type twice in a signature would generate an `InvalidProgramException`. This would allow the `self` argument to be specified anywhere in the argument list. Alternatively, many sections of the Swift ABI documentation, as well as the Clang docs refer to this parameter as the "context" argument instead of the "self" argument, so an alternative name could be `SwiftContext`. The `UnmanagedCallersOnly` leverages the existing proposal and treats delegates annotated with `UnmanagedCallersOnly` as Swift-like functions capable of handling context registers. In the prolog of the delegate, the self register value will be loaded into the `SwiftSelf` argument.
kotlarmilos marked this conversation as resolved.
Show resolved Hide resolved

For reference, explicitly declaring a function with the Swift or SwiftAsync calling conventions in Clang requires the "context" argument, the value that goes in the "self" register, as the last parameter or the penultimate parameter followed by the error parameter.

Expand All @@ -80,7 +80,7 @@ We have selected an approach for handling the error register in the Swift callin

1. Use a special type named something like `SwiftError*` to indicate the error parameter

This approach expresses that the to-be-called Swift function uses the Error Register in the signature and they both require signature manipulation in the JIT/AOT compilers. Like with `SwiftSelf`, we would throw an `InvalidProgramException` for a signature with multiple `SwiftError` parameters. We use a pointer-to-`SwiftError` type to indicate that the error register is a by-ref/out parameter. We don't use managed pointers as our modern JITs can reason about unmanaged pointers well enough that we do not end up losing any performance taking this route. The `UnmanagedCallersOnly` implementation will require a decent amount of JIT work to emulate a local variable for the register value, but we have prior art in the Clang implementation of the Swift error register that we can fall back on.
This approach expresses that the to-be-called Swift function uses the Error Register in the signature and they both require signature manipulation in the JIT/AOT compilers. Like with `SwiftSelf`, we would throw an `InvalidProgramException` for a signature with multiple `SwiftError` parameters. We use a pointer-to-`SwiftError` type to indicate that the error register is a by-ref/out parameter. We don't use managed pointers as our modern JITs can reason about unmanaged pointers well enough that we do not end up losing any performance taking this route. The `UnmanagedCallersOnly` implementation will require a decent amount of JIT work to emulate a local variable for the register value, but we have prior art in the Clang implementation of the Swift error register that we can fall back on. Delegates annotated with `UnmanagedCallersOnly` will store the `SwiftError*` value in the error register in their epilog.
kotlarmilos marked this conversation as resolved.
Show resolved Hide resolved

Additionally, we have selected this design as this provides consistency with the self register and async context register handling, discussed below.

Expand Down
Loading