Add Swift function call ABI#155815
Conversation
|
r? @jieyouxu rustbot has assigned @jieyouxu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
Adds an unstable `extern "Swift"` ABI behind the `abi_swift` feature gate, mapping to LLVM's `swiftcc` calling convention. Cranelift and GCC backends fall back to the platform default since they have no equivalent.
|
|
||
| /// Swift calling convention, exposed via LLVM's `swiftcc`. Cross-platform | ||
| /// and not tied to a specific target architecture. | ||
| Swift, |
There was a problem hiding this comment.
Do I understand it correctly that the Swift ABI isn't stable yet outside of Apple platforms?
There was a problem hiding this comment.
Yes, I think that's right. How do you think that should affect this PR? Should we only allow this on Apple targets?
There was a problem hiding this comment.
Yeah, I think it makes sense to only allow on Apple targets for now.
There was a problem hiding this comment.
But on Apple platforms it is stable? We're not chasing a moving target here, are we?
There was a problem hiding this comment.
Yes, it's stable on Apple platforms since 2019 and Swift 5:
https://www.swift.org/blog/abi-stability-and-more/
There's a lot of good details in this article:
https://faultlore.com/blah/swift-abi/#resilient-type-layout
There's also Embedded Swift, which has an unstable ABI regardless of platform:
https://docs.swift.org/embedded/documentation/embedded/abi/
| CanonAbi::Custom => default_call_conv, | ||
|
|
||
| // Cranelift has no Swift calling convention; fall back to the platform default. | ||
| CanonAbi::Swift => default_call_conv, |
There was a problem hiding this comment.
Please emit an error instead. Silently changing the calling convention is a miscompilations.
| // convention for declaring foreign functions. | ||
| CanonAbi::Custom => return None, | ||
| // gcc/gccjit does not have anything for Swift's calling convention. | ||
| CanonAbi::Swift => return None, |
There was a problem hiding this comment.
Same here
|
When will arguments be marked as |
So this is a bit experimental. I plan on looking into all the things (though in my free time, and thus slowly) needed to call into Swift from Rust, but I don't have a plan today. If you want a more concrete plan before merging this, I'd like hear some more detail (in the sense of, maybe a bullet list) of things that need to be done. |
|
To be clear, I'm not going to block this PR on figuring out By the way I noticed that a question of mine in the previous attempt hadn't been answered yet: #64582 (comment) https://github.com/swiftlang/swift/blob/main/docs/ABI/CallingConventionSummary.rst seems to suggest like the answer to my question is no it doesn't need a separate |
|
For something like adding a new ABI, it'd definitely need a RFC accepted prior to stabilization. There are mechanisms to support "land something unstably to gather impl experience to feed RFC design / explore edge cases", in this case I would expect to take the form of a lang experiment. That is, if there is a lang champion happy to champion this. Asked in #t-lang > Swift call ABI. |
|
To spell it out explicitly, the primary reason this is interesting is because there's a bunch of platform APIs that are only exposed over the Swift ABI, such as Existing solutions need users to write |
There was a problem hiding this comment.
Also, can you please expand on the motivations (in PR description or elsewhere) for adding a new Swift fn call ABI (unstable or not)? There was an earlier PR which this PR revives yes, but we would definitely like to know if the motivations and circumstances have changed since then.
E.g. Mads shared one such motivation in comment above, I'd be curious if you had the same motivations or additional/different ones.
It would also help a lot if the PR description could also be updated to include details like #155815 (comment).
@rustbot author
|
Reminder, once the PR becomes ready for a review, use |
Adds an unstable
extern "Swift"ABI behind theabi_swiftfeature gate, mapping to LLVM'sswiftcccalling convention. Cranelift and GCC backends fall back to the platform default since they have no equivalent.Reimplements #64582 on top of current main. The main objection to it seemed to be that it needed an RFC, but there was pushback (which seems sensible to me) that an RFC could be deferred until stabilization.
I think this needs a tracking issue? Would be happy to write one up if/when there is a consensus that this will be merged.