Skip to content
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

Switch SwiftSelf<T> position requirement to last #108547

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2226,9 +2226,9 @@ void Compiler::impPopArgsForSwiftCall(GenTreeCall* call, CORINFO_SIG_INFO* sig,
BADCODE("Duplicate SwiftSelf parameter");
}

if (argIndex != 0)
if (argIndex != (sig->numArgs - 1))
{
BADCODE("SwiftSelf<T> must be the first argument in the signature");
BADCODE("SwiftSelf<T> must be the last argument in the signature");
}

selfType = info.compCompHnd->getTypeInstantiationArgument(argClass, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3714,9 +3714,9 @@ mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions,
break;
} else if (param_klass == swift_error || param_klass == swift_error_ptr) {
swift_error_args++;
} else if (param_gklass && (param_gklass->container_class == swift_self_t) && i > 0) {
} else if (param_gklass && (param_gklass->container_class == swift_self_t) && (i != method->signature->param_count - 1)) {
swift_error_args = swift_self_args = 0;
mono_error_set_generic_error (emitted_error, "System", "InvalidProgramException", "SwiftSelf<T> must be the first argument in the signature.");
mono_error_set_generic_error (emitted_error, "System", "InvalidProgramException", "SwiftSelf<T> must be the last argument in the signature.");
break;
} else if (param_gklass && (param_gklass->container_class == swift_self_t) && m_type_is_byref (method->signature->params [i])) {
swift_error_args = swift_self_args = 0;
Expand Down
26 changes: 24 additions & 2 deletions src/tests/Interop/Swift/SwiftSelfContext/SwiftSelfContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public struct FrozenNonEnregisteredStruct
}

[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })]
[DllImport(SwiftLib, EntryPoint = "$s16SwiftSelfContext24FrozenEnregisteredStructV3Sums5Int64VyF")]
[DllImport(SwiftLib, EntryPoint = "$s16SwiftSelfContext24FrozenEnregisteredStructV3sums5Int64VyF")]
public static extern long SumFrozenEnregisteredStruct(SwiftSelf<FrozenEnregisteredStruct> self);

[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })]
[DllImport(SwiftLib, EntryPoint = "$s16SwiftSelfContext27FrozenNonEnregisteredStructV3Sums5Int64VyF")]
[DllImport(SwiftLib, EntryPoint = "$s16SwiftSelfContext27FrozenNonEnregisteredStructV3sums5Int64VyF")]
public static extern long SumFrozenNonEnregisteredStruct(SwiftSelf<FrozenNonEnregisteredStruct> self);

[Fact]
Expand All @@ -81,4 +81,26 @@ public unsafe static void TestSelfIsFrozenNonEnregisteredStruct()
long sum = SumFrozenNonEnregisteredStruct(new SwiftSelf<FrozenNonEnregisteredStruct>(new FrozenNonEnregisteredStruct { A = 10, B = 20, C = 30, D = 40, E = 50 }));
Assert.Equal(150, sum);
}

[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })]
[DllImport(SwiftLib, EntryPoint = "$s16SwiftSelfContext24FrozenEnregisteredStructV16sumWithExtraArgs1c1dS2f_SftF")]
public static extern float SumFrozenEnregisteredStructWithExtraArgs(float c, float d, SwiftSelf<FrozenEnregisteredStruct> self);

[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })]
[DllImport(SwiftLib, EntryPoint = "$s16SwiftSelfContext27FrozenNonEnregisteredStructV16sumWithExtraArgs1f1gS2f_SftF")]
public static extern float SumFrozenNonEnregisteredStructWithExtraArgs(float f, float g, SwiftSelf<FrozenNonEnregisteredStruct> self);

[Fact]
public unsafe static void TestSelfIsFrozenEnregisteredStructWithExtraArgs()
{
float sum = SumFrozenEnregisteredStructWithExtraArgs(3f, 4f, new SwiftSelf<FrozenEnregisteredStruct>(new FrozenEnregisteredStruct { A = 10, B = 20 }));
Assert.Equal(37f, sum);
}

[Fact]
public unsafe static void TestSelfIsFrozenNonEnregisteredStructWithExtraArgs()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this is the test which fails on the CI. So far I have determined that the error also occurs when we use non-generic SwifSelf instead. The error seems to be only occurring on the runtime x64 macos runtime_tests pipeline.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #108855 about this and disabled this test against that issue

{
float sum = SumFrozenNonEnregisteredStructWithExtraArgs(3f, 4f, new SwiftSelf<FrozenNonEnregisteredStruct>(new FrozenNonEnregisteredStruct { A = 10, B = 20, C = 30, D = 40, E = 50 }));
Assert.Equal(157f, sum);
}
}
14 changes: 11 additions & 3 deletions src/tests/Interop/Swift/SwiftSelfContext/SwiftSelfContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ public struct FrozenEnregisteredStruct
let a : Int64;
let b : Int64;

public func Sum() -> Int64 {
public func sum() -> Int64 {
return a + b
}

public func sumWithExtraArgs(c: Float, d: Float) -> Float {
return Float(a + b) + c + d
}
}

@frozen
Expand All @@ -39,7 +43,11 @@ public struct FrozenNonEnregisteredStruct {
let d : Int64;
let e : Int64;

public func Sum() -> Int64 {
public func sum() -> Int64 {
return a + b + c + d + e
}
}

public func sumWithExtraArgs(f: Float, g: Float) -> Float {
return Float(a + b + c + d + e) + f + g
}
}
Loading