Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Swift Function Call ABI #3

Open
nvzqz opened this issue Sep 27, 2019 · 1 comment
Open

Swift Function Call ABI #3

nvzqz opened this issue Sep 27, 2019 · 1 comment

Comments

@nvzqz
Copy link
Owner

nvzqz commented Sep 27, 2019

For the long-term success of this project, it should allow for exposing functions in Rust that can be called in Swift via the Swift function ABI as well as calling functions declared in Swift directly from Rust without an intermediate C or Objective-C layer. LLVM currently supports the Swift calling convention, also known as swiftcc. In order to expose Swift functions and call them directly in an FFI-safe manner, the Rust compiler needs to be taught Swift's function call ABI.

rust-lang/rust#64582 implements the basic function ABI in rustc via LLVM. This would allow for:

extern "Swift" {
    fn foo();
}

extern "Swift" fn bar() {
    // ...
}

type F = extern "Swift" fn();
@Dante-Broggi
Copy link
Contributor

One thing of note is that there is a definite difference between "the Swift calling convention" and swiftcc, as mentioned in this llvm thread, in particular swiftcc uses the llvm / backend support for struct aggregates, while "the Swift calling convention", pre-expands or indirects all structs before llvm.

A particular example is that these functions are ABI equivalent according to "the Swift calling convention" as stated here in the aforementioned thread.

struct A { i32, float };
struct B { float, i32 };

define @foo (A, i32) -> @foo(i32, float, i32);

// and

define @foo (i32, B) -> @foo(i32, float, i32);

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants