Skip to content

[swift interop] Cannot call instance methods with at least one parameter when using SwiftSelf<T>  #107946

@jkurdek

Description

@jkurdek

Our current interop implementation only allows SwiftSelf (representing the self parameter in Swift instance methods) to be specified as the first parameter in function signatures. This design choice leads to issues when interfacing with Swift instance methods that accept additional parameters.

Let's consider following example

@frozen public struct SampleStruct
{
    public var x1: Int
    public var x2: Int

    public func addWithExtraArgs(x3: Float, x4: Float) -> Float {
        return Float(x1 + x2) + x3 + x4
    }
}

addWithExtraArgs results in the following LLVM-IR:

define protected swiftcc float @"output.SampleStruct.addWithExtraArgs(x3: Swift.Float, x4: Swift.Float) -> Swift.Float"(float %0, float %1, i64 %2, i64 %3) ...

SampleStruct is expected to be lowered into two i64 which are passed as last parameters.
This would correspond to following csharp signature:

static extern void AddWithExtraArgs(float a, float b, SwiftSelf<SampleStruct> struct)

We should either allow SwiftSelf<T> argument to be specified as the last parameter or we should reorder the parameters in runtime.

\cc: @kotlarmilos, @jakobbotsch, @amanasifkhalid, @matouskozak

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions