You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplify the expansion of @Test by eliminating the isolated thunk.
This PR removes one of the thunks we emit when expanding `@Test`. For example,
given the following test function:
```swift
@test func foo() {}
```
We currently emit, approximately:
```swift
@available(*, deprecated, message: "This function is an implementation detail of the testing library. Do not use it directly.")
@sendable private func $s12TestingTests3foo4TestfMp_17Z152ec26a56a4f672fMu_() async throws -> Void {
@sendable func $s12TestingTests3foo4TestfMp_7__localfMu_(_:isolated (any _Concurrency.Actor)?=Testing.__defaultSynchronousIsolationContext) async throws {
_ = unsafe try await Testing.__requiringUnsafe(Testing.__requiringTry(Testing.__requiringAwait(foo())))
}
try await $s12TestingTests3foo4TestfMp_7__localfMu_()
}
@available(*, deprecated, message: "This property is an implementation detail of the testing library. Do not use it directly.")
@sendable private func $s12TestingTests3foo4TestfMp_25generator152ec26a56a4f672fMu_() async -> Testing.Test {
return .__function(
named: "foo()",
in: nil as Swift.Never.Type?,
xcTestCompatibleSelector: nil,
traits: [],sourceBounds: Testing.__SourceBounds(__uncheckedLowerBound: Testing.SourceLocation(__uncheckedFileID: "TestingTests/ZipTests.swift", filePath: "/Volumes/Dev/Source/swift-testing-public/Tests/TestingTests/ZipTests.swift", line: 30, column: 2), upperBound: (30, 20)),
parameters: [],
testFunction: $s12TestingTests3foo4TestfMp_17Z152ec26a56a4f672fMu_
)
}
@section("__DATA_CONST,__swift5_tests")
@used@available(*, deprecated, message: "This property is an implementation detail of the testing library. Do not use it directly.")
private nonisolated let $s12TestingTests3foo4TestfMp_33testContentRecord152ec26a56a4f672fMu_: Testing.__TestContentRecord = (
0x74657374, /* 'test' */
0,
{ outValue, type, _, _ in
Testing.Test.__store($s12TestingTests3foo4TestfMp_25generator152ec26a56a4f672fMu_, into: outValue, asTypeAt: type)
},
0,
0
)
```
Note that the first thunk function has a nested thunk function that serves only
to impose actor isolation on the actual test function. This change replaces that
thunk with `nonisolated(nonsending)` in appropriate locations throughout the
macro target and library target. After this change, we emit a simpler expansion:
```swift
@available(*, deprecated, message: "This function is an implementation detail of the testing library. Do not use it directly.")
@sendable private nonisolated(nonsending) func $s12TestingTests3foo4TestfMp_17Z152ec26a56a4f672fMu_() async throws -> Void {
_ = unsafe try await Testing.__requiringUnsafe(Testing.__requiringTry(Testing.__requiringAwait(foo())))
}
@available(*, deprecated, message: "This function is an implementation detail of the testing library. Do not use it directly.")
@sendable private nonisolated(nonsending) func $s12TestingTests3foo4TestfMp_25generator152ec26a56a4f672fMu_() async -> Testing.Test {
return .__function(
named: "foo()",
in: nil as Swift.Never.Type?,
xcTestCompatibleSelector: nil,
traits: [],sourceBounds: Testing.__SourceBounds(__uncheckedLowerBound: Testing.SourceLocation(__uncheckedFileID: "TestingTests/ZipTests.swift", filePath: "/Volumes/Dev/Source/swift-testing-public/Tests/TestingTests/ZipTests.swift", line: 30, column: 2), upperBound: (30, 20)),
parameters: [],
testFunction: $s12TestingTests3foo4TestfMp_17Z152ec26a56a4f672fMu_
)
}
@section("__DATA_CONST,__swift5_tests")
@used@available(*, deprecated, message: "This property is an implementation detail of the testing library. Do not use it directly.")
private nonisolated let $s12TestingTests3foo4TestfMp_33testContentRecord152ec26a56a4f672fMu_: Testing.__TestContentRecord = (
0x74657374, /* 'test' */
0,
{ outValue, type, _, _ in
Testing.Test.__store($s12TestingTests3foo4TestfMp_25generator152ec26a56a4f672fMu_, into: outValue, asTypeAt: type)
},
0,
0
)
```
0 commit comments