-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JIT: Add support for SwiftIndirectResult
in Swift calling convention
#103570
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
07b417f
Add test for SwiftIndirectResult
jakobbotsch 889a2e5
Fix test
jakobbotsch 1e71cf2
unmanaged
jakobbotsch a68f138
Unsafe, pass indirect result correctly
jakobbotsch 1103717
Add to CMake files
jakobbotsch 3726cbf
Add support for SwiftIndirectResult
jakobbotsch 0db1d8f
Fix export name
jakobbotsch b00a2fa
Enable library evolution
jakobbotsch ceee815
Reverse pinvoke support
jakobbotsch b4dabd0
Use a separate local for Swift indirect result parameter
jakobbotsch 4f410da
Fix ret buf handling now that it is a struct in some cases
jakobbotsch e1bc2e8
Run jit-format
jakobbotsch 8dc1931
Disable new test on Mono
jakobbotsch deae39e
Clean up
jakobbotsch 974f37a
Enable library evolution in all Swift tests
jakobbotsch e05c282
Revert "Enable library evolution in all Swift tests"
jakobbotsch 3024b10
Move comment
jakobbotsch 18ab440
Merge branch 'main' of github.com:dotnet/runtime into swift-indirect-…
jakobbotsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/tests/Interop/Swift/SwiftIndirectResult/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
project(SwiftIndirectResult) | ||
include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake") | ||
|
||
set(SOURCE SwiftIndirectResult) | ||
|
||
if (NOT SWIFT_COMPILER_TARGET AND CLR_CMAKE_TARGET_OSX) | ||
set(SWIFT_PLATFORM "macosx") | ||
set(SWIFT_PLATFORM_SUFFIX "") | ||
set(SWIFT_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET}) | ||
set(SWIFT_COMPILER_TARGET "${CMAKE_OSX_ARCHITECTURES}-apple-${SWIFT_PLATFORM}${SWIFT_DEPLOYMENT_TARGET}${SWIFT_PLATFORM_SUFFIX}") | ||
endif() | ||
|
||
add_custom_target(${SOURCE} ALL | ||
COMMAND xcrun swiftc -target ${SWIFT_COMPILER_TARGET} -enable-library-evolution -emit-library ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}.swift -o ${CMAKE_CURRENT_BINARY_DIR}/lib${SOURCE}.dylib | ||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}.swift | ||
COMMENT "Generating ${SOURCE} library" | ||
) | ||
|
||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${SOURCE}.dylib | ||
DESTINATION bin | ||
) |
53 changes: 53 additions & 0 deletions
53
src/tests/Interop/Swift/SwiftIndirectResult/SwiftIndirectResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.InteropServices.Swift; | ||
using Xunit; | ||
|
||
public unsafe class SwiftIndirectResultTests | ||
{ | ||
private struct NonFrozenStruct | ||
{ | ||
public int A; | ||
public int B; | ||
public int C; | ||
} | ||
|
||
private const string SwiftLib = "libSwiftIndirectResult.dylib"; | ||
|
||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] | ||
[DllImport(SwiftLib, EntryPoint = "$s19SwiftIndirectResult21ReturnNonFrozenStruct1a1b1cAA0efG0Vs5Int32V_A2ItF")] | ||
public static extern void ReturnNonFrozenStruct(SwiftIndirectResult result, int a, int b, int c); | ||
|
||
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] | ||
[DllImport(SwiftLib, EntryPoint = "$s19SwiftIndirectResult26SumReturnedNonFrozenStruct1fs5Int32VAA0fgH0VyXE_tF")] | ||
public static extern int SumReturnedNonFrozenStruct(delegate* unmanaged[Swift]<SwiftIndirectResult, SwiftSelf, void> func, void* funcContext); | ||
|
||
[Fact] | ||
public static void TestReturnNonFrozenStruct() | ||
{ | ||
// In normal circumstances this instance would have unknown/dynamically determined size. | ||
NonFrozenStruct instance; | ||
ReturnNonFrozenStruct(new SwiftIndirectResult(&instance), 10, 20, 30); | ||
Assert.Equal(10, instance.A); | ||
Assert.Equal(20, instance.B); | ||
Assert.Equal(30, instance.C); | ||
} | ||
|
||
[UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] | ||
private static void ReversePInvokeReturnNonFrozenStruct(SwiftIndirectResult result, SwiftSelf self) | ||
{ | ||
// In normal circumstances this would require using dynamically sized memcpy and members to create the struct. | ||
*(NonFrozenStruct*)result.Value = new NonFrozenStruct { A = 10, B = 20, C = 30 }; | ||
} | ||
|
||
[Fact] | ||
public static void TestSumReturnedNonFrozenStruct() | ||
{ | ||
int result = SumReturnedNonFrozenStruct(&ReversePInvokeReturnNonFrozenStruct, null); | ||
Assert.Equal(60, result); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/tests/Interop/Swift/SwiftIndirectResult/SwiftIndirectResult.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<!-- Needed for CLRTestTargetUnsupported, CMakeProjectReference --> | ||
<RequiresProcessIsolation>true</RequiresProcessIsolation> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<!-- Swift interop is supported on Apple platforms only --> | ||
<CLRTestTargetUnsupported Condition="'$(TargetsOSX)' != 'true' and '$(TargetsAppleMobile)' != 'true'">true</CLRTestTargetUnsupported> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(TestLibraryProjectPath)" /> | ||
<CMakeProjectReference Include="CMakeLists.txt" /> | ||
</ItemGroup> | ||
</Project> |
18 changes: 18 additions & 0 deletions
18
src/tests/Interop/Swift/SwiftIndirectResult/SwiftIndirectResult.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
public struct NonFrozenStruct | ||
{ | ||
let a : Int32; | ||
let b : Int32; | ||
let c : Int32; | ||
} | ||
|
||
public func ReturnNonFrozenStruct(a: Int32, b: Int32, c: Int32) -> NonFrozenStruct { | ||
return NonFrozenStruct(a: a, b: b, c: c) | ||
} | ||
|
||
public func SumReturnedNonFrozenStruct(f: () -> NonFrozenStruct) -> Int32 { | ||
let s = f() | ||
return s.a + s.b + s.c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update this comment to mention the SwiftIndirectResult case, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the existing comment up to where we assign
spillStack
in theSwiftError*
case instead (there is already a comment on the newspillStack = true
I added)