Skip to content

Commit 4399cba

Browse files
authored
Add a reserved argument to the test content record accessor signature. (#1017)
This PR adds a `reserved` argument to `__TestContentRecordAccessor` for our future use. Resolves rdar://146818672. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent b3d3fd7 commit 4399cba

File tree

7 files changed

+19
-12
lines changed

7 files changed

+19
-12
lines changed

Documentation/ABI/TestContent.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ testing library have the following layout:
4444
typealias Accessor = @convention(c) (
4545
_ outValue: UnsafeMutableRawPointer,
4646
_ type: UnsafeRawPointer,
47-
_ hint: UnsafeRawPointer?
47+
_ hint: UnsafeRawPointer?,
48+
_ reserved: UInt
4849
) -> CBool
4950

5051
typealias TestContentRecord = (
@@ -63,7 +64,8 @@ If needed, this type can be represented in C as a structure:
6364
typedef bool (* SWTAccessor)(
6465
void *outValue,
6566
const void *type,
66-
const void *_Nullable hint
67+
const void *_Nullable hint,
68+
uintptr_t reserved
6769
);
6870

6971
struct SWTTestContentRecord {
@@ -117,7 +119,7 @@ If `accessor` is `nil`, the test content record is ignored. The testing library
117119
may, in the future, define record kinds that do not provide an accessor function
118120
(that is, they represent pure compile-time information only.)
119121

120-
The third argument to this function, `type`, is a pointer to the type[^mightNotBeSwift]
122+
The second argument to this function, `type`, is a pointer to the type[^mightNotBeSwift]
121123
(not a bitcast Swift type) of the value expected to be written to `outValue`.
122124
This argument helps to prevent memory corruption if two copies of Swift Testing
123125
or a third-party library are inadvertently loaded into the same process. If the
@@ -134,12 +136,15 @@ accessor function must return `false` and must not modify `outValue`.
134136
[`std::type_info`](https://en.cppreference.com/w/cpp/types/type_info), and
135137
write a C++ class instance to `outValue` using [placement `new`](https://en.cppreference.com/w/cpp/language/new#Placement_new).
136138

137-
The fourth argument to this function, `hint`, is an optional input that can be
139+
The third argument to this function, `hint`, is an optional input that can be
138140
passed to help the accessor function determine if its corresponding test content
139141
record matches what the caller is looking for. If the caller passes `nil` as the
140142
`hint` argument, the accessor behaves as if it matched (that is, no additional
141143
filtering is performed.)
142144

145+
The fourth argument to this function, `reserved`, is reserved for future use.
146+
Accessor functions should assume it is `0` and must not access it.
147+
143148
The concrete Swift type of the value written to `outValue`, the type pointed to
144149
by `type`, and the value pointed to by `hint` depend on the kind of record:
145150

Sources/Testing/Discovery+Macro.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ protocol DiscoverableAsTestContent: _TestDiscovery.DiscoverableAsTestContent, ~C
2828
public typealias __TestContentRecordAccessor = @convention(c) (
2929
_ outValue: UnsafeMutableRawPointer,
3030
_ type: UnsafeRawPointer,
31-
_ hint: UnsafeRawPointer?
31+
_ hint: UnsafeRawPointer?,
32+
_ reserved: UInt
3233
) -> CBool
3334

3435
/// The content of a test content record.

Sources/TestingMacros/ConditionMacro.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ extension ExitTestConditionMacro {
484484
"""
485485
@available(*, deprecated, message: "This type is an implementation detail of the testing library. Do not use it directly.")
486486
enum \(enumName) {
487-
private nonisolated static let accessor: Testing.__TestContentRecordAccessor = { outValue, type, hint in
487+
private nonisolated static let accessor: Testing.__TestContentRecordAccessor = { outValue, type, hint, _ in
488488
Testing.ExitTest.__store(
489489
\(exitTestIDExpr),
490490
\(bodyThunkName),

Sources/TestingMacros/SuiteDeclarationMacro.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public struct SuiteDeclarationMacro: MemberMacro, PeerMacro, Sendable {
149149
result.append(
150150
"""
151151
@available(*, deprecated, message: "This property is an implementation detail of the testing library. Do not use it directly.")
152-
private nonisolated static let \(accessorName): Testing.__TestContentRecordAccessor = { outValue, type, _ in
152+
private nonisolated static let \(accessorName): Testing.__TestContentRecordAccessor = { outValue, type, _, _ in
153153
Testing.Test.__store(\(generatorName), into: outValue, asTypeAt: type)
154154
}
155155
"""

Sources/TestingMacros/TestDeclarationMacro.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public struct TestDeclarationMacro: PeerMacro, Sendable {
474474
result.append(
475475
"""
476476
@available(*, deprecated, message: "This property is an implementation detail of the testing library. Do not use it directly.")
477-
private \(staticKeyword(for: typeName)) nonisolated let \(accessorName): Testing.__TestContentRecordAccessor = { outValue, type, _ in
477+
private \(staticKeyword(for: typeName)) nonisolated let \(accessorName): Testing.__TestContentRecordAccessor = { outValue, type, _, _ in
478478
Testing.Test.__store(\(generatorName), into: outValue, asTypeAt: type)
479479
}
480480
"""

Sources/_TestDiscovery/TestContentRecord.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
private typealias _TestContentRecordAccessor = @convention(c) (
2525
_ outValue: UnsafeMutableRawPointer,
2626
_ type: UnsafeRawPointer,
27-
_ hint: UnsafeRawPointer?
27+
_ hint: UnsafeRawPointer?,
28+
_ reserved: UInt
2829
) -> CBool
2930

3031
/// The content of a test content record.
@@ -160,10 +161,10 @@ public struct TestContentRecord<T> where T: DiscoverableAsTestContent & ~Copyabl
160161
withUnsafeTemporaryAllocation(of: T.self, capacity: 1) { buffer in
161162
let initialized = if let hint {
162163
withUnsafePointer(to: hint) { hint in
163-
accessor(buffer.baseAddress!, type, hint)
164+
accessor(buffer.baseAddress!, type, hint, 0)
164165
}
165166
} else {
166-
accessor(buffer.baseAddress!, type, nil)
167+
accessor(buffer.baseAddress!, type, nil, 0)
167168
}
168169
guard initialized else {
169170
return nil

Tests/TestingTests/DiscoveryTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct DiscoveryTests {
9393
private static let record: __TestContentRecord = (
9494
0xABCD1234,
9595
0,
96-
{ outValue, type, hint in
96+
{ outValue, type, hint, _ in
9797
guard type.load(as: Any.Type.self) == MyTestContent.self else {
9898
return false
9999
}

0 commit comments

Comments
 (0)