Skip to content

Commit

Permalink
Introduce SwiftSelf<T> and SwiftIndirectResult structs (dotnet#10…
Browse files Browse the repository at this point in the history
…2717)

* Introduce SwiftSelf<T> and SwiftIndirectResult structs

---------

Co-authored-by: Matous Kozak <55735845+matouskozak@users.noreply.github.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
  • Loading branch information
3 people committed Jun 7, 2024
1 parent 17d88ed commit ab604e9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,41 @@ public SwiftSelf(void* value)
public void* Value { get; }
}

/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// <para>
/// This struct is used to pass the Swift frozen struct T to Swift functions in the context of interop with .NET.
/// </para>
/// <para>
/// Here's an example of how a SwiftSelf&lt;T&gt; context can be declared:
/// <code lang="csharp">
/// [UnmanagedCallConv(CallConvs = [typeof(CallConvSwift)])]
/// [LibraryImport("SwiftLibrary", EntryPoint = "export")]
/// public static extern void swiftFunction(SwiftSelf&lt;T&gt; self);
/// </code>
/// </para>
/// </remarks>
[Intrinsic]
public readonly unsafe struct SwiftSelf<T> where T: unmanaged
{
/// <summary>
/// Creates a new instance of the SwiftSelf struct with the specified value.
/// </summary>
/// <param name="value">The value representing the self context.</param>
public SwiftSelf(T value)
{
Value = value;
}

/// <summary>
/// Gets the value representing the Swift frozen struct.
/// </summary>
public T Value { get; }
}

/// <summary>
/// Represents the Swift error context, indicating that the argument is the error context.
/// </summary>
Expand Down Expand Up @@ -71,4 +106,40 @@ public SwiftError(void* value)
/// </summary>
public void* Value { get; }
}

/// <summary>
/// Represents the Swift return buffer context.
/// </summary>
/// <remarks>
/// <para>
/// 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.
/// </para>
/// <para>
/// Here's an example of how a SwiftIndirectResult can be declared:
/// <code lang="csharp">
/// [UnmanagedCallConv(CallConvs = [typeof(CallConvSwift)])]
/// [LibraryImport("SwiftLibrary", EntryPoint = "export")]
/// public static extern void swiftFunction(SwiftIndirectResult result);
/// </code>
/// </para>
/// </remarks>
[CLSCompliant(false)]
[Intrinsic]
public readonly unsafe struct SwiftIndirectResult
{
/// <summary>
/// Creates a new instance of the SwiftIndirectResult struct with the specified pointer value.
/// </summary>
/// <param name="value">The pointer value representing return buffer context.</param>
public SwiftIndirectResult(void* value)
{
Value = value;
}

/// <summary>
/// Gets the pointer of the return buffer register.
/// </summary>
public void* Value { get; }
}
}
13 changes: 13 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14232,6 +14232,19 @@ namespace System.Runtime.InteropServices.Swift
public unsafe SwiftSelf(void* value) { throw null; }
public unsafe void* Value { get { throw null; } }
}
public readonly partial struct SwiftSelf<T> 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
{
Expand Down

0 comments on commit ab604e9

Please sign in to comment.