diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Swift/SwiftTypes.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Swift/SwiftTypes.cs index 13803374073b8..a8c4a18c30d72 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Swift/SwiftTypes.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Swift/SwiftTypes.cs @@ -38,6 +38,41 @@ public SwiftSelf(void* value) public void* Value { get; } } + /// + /// Represents the Swift 'self' context when the argument is Swift frozen struct T, which is either enregistered into multiple registers, + /// or passed by reference in the 'self' register. + /// + /// + /// + /// This struct is used to pass the Swift frozen struct T to Swift functions in the context of interop with .NET. + /// + /// + /// Here's an example of how a SwiftSelf<T> context can be declared: + /// + /// [UnmanagedCallConv(CallConvs = [typeof(CallConvSwift)])] + /// [LibraryImport("SwiftLibrary", EntryPoint = "export")] + /// public static extern void swiftFunction(SwiftSelf<T> self); + /// + /// + /// + [Intrinsic] + public readonly unsafe struct SwiftSelf where T: unmanaged + { + /// + /// Creates a new instance of the SwiftSelf struct with the specified value. + /// + /// The value representing the self context. + public SwiftSelf(T value) + { + Value = value; + } + + /// + /// Gets the value representing the Swift frozen struct. + /// + public T Value { get; } + } + /// /// Represents the Swift error context, indicating that the argument is the error context. /// @@ -71,4 +106,40 @@ public SwiftError(void* value) /// public void* Value { get; } } + + /// + /// Represents the Swift return buffer context. + /// + /// + /// + /// This struct is used to access the return buffer when interoping with Swift functions that return non-frozen structs. + /// It provides a pointer to the memory location where the result should be stored. + /// + /// + /// Here's an example of how a SwiftIndirectResult can be declared: + /// + /// [UnmanagedCallConv(CallConvs = [typeof(CallConvSwift)])] + /// [LibraryImport("SwiftLibrary", EntryPoint = "export")] + /// public static extern void swiftFunction(SwiftIndirectResult result); + /// + /// + /// + [CLSCompliant(false)] + [Intrinsic] + public readonly unsafe struct SwiftIndirectResult + { + /// + /// Creates a new instance of the SwiftIndirectResult struct with the specified pointer value. + /// + /// The pointer value representing return buffer context. + public SwiftIndirectResult(void* value) + { + Value = value; + } + + /// + /// Gets the pointer of the return buffer register. + /// + public void* Value { get; } + } } diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 37bd783042bdb..708692fa959ae 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -13904,6 +13904,19 @@ public readonly partial struct SwiftSelf public unsafe SwiftSelf(void* value) { throw null; } public unsafe void* Value { get { throw null; } } } + public readonly partial struct SwiftSelf where T: unmanaged + { + private readonly T _dummyPrimitive; + public unsafe SwiftSelf(T value) { throw null; } + public unsafe T Value { get { throw null; } } + } + [System.CLSCompliantAttribute(false)] + public readonly partial struct SwiftIndirectResult + { + private readonly int _dummyPrimitive; + public unsafe SwiftIndirectResult(void* value) { throw null; } + public unsafe void* Value { get { throw null; } } + } } namespace System.Runtime.Remoting {