Skip to content

Commit da3ebda

Browse files
committed
Merge branch 'main' into jgrynspan/162-redesign-value-capture
2 parents 894fa8b + 87f4168 commit da3ebda

23 files changed

+230
-334
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ jobs:
2424
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
2525
with:
2626
license_header_check_project_name: "Swift"
27-
docs_check_container_image: "swift:6.2-noble"
27+
docs_check_enabled: false
2828
format_check_enabled: false
2929
api_breakage_check_enabled: false

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ extension Array where Element == PackageDescription.SwiftSetting {
391391
.define("SWT_NO_DYNAMIC_LINKING", .whenEmbedded(or: .when(platforms: [.wasi]))),
392392
.define("SWT_NO_PIPES", .whenEmbedded(or: .when(platforms: [.wasi]))),
393393
.define("SWT_NO_FOUNDATION_FILE_COORDINATION", .whenEmbedded(or: .whenApple(false))),
394+
.define("SWT_NO_IMAGE_ATTACHMENTS", .whenEmbedded(or: .when(platforms: [.linux, .custom("freebsd"), .openbsd, .wasi, .android]))),
394395

395396
.define("SWT_NO_LEGACY_TEST_DISCOVERY", .whenEmbedded()),
396397
.define("SWT_NO_LIBDISPATCH", .whenEmbedded()),

Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private import ImageIO
3939
/// @Available(Swift, introduced: 6.3)
4040
/// }
4141
@available(_uttypesAPI, *)
42-
public protocol AttachableAsCGImage: SendableMetatype {
42+
public protocol AttachableAsCGImage: _AttachableAsImage, SendableMetatype {
4343
/// An instance of `CGImage` representing this image.
4444
///
4545
/// - Throws: Any error that prevents the creation of an image.
@@ -68,22 +68,6 @@ public protocol AttachableAsCGImage: SendableMetatype {
6868
/// This property is not part of the public interface of the testing
6969
/// library. It may be removed in a future update.
7070
var _attachmentScaleFactor: CGFloat { get }
71-
72-
/// Make a copy of this instance to pass to an attachment.
73-
///
74-
/// - Returns: A copy of `self`, or `self` if no copy is needed.
75-
///
76-
/// The testing library uses this function to take ownership of image
77-
/// resources that test authors pass to it. If possible, make a copy of or add
78-
/// a reference to `self`. If this type does not support making copies, return
79-
/// `self` verbatim.
80-
///
81-
/// The default implementation of this function when `Self` conforms to
82-
/// `Sendable` simply returns `self`.
83-
///
84-
/// This function is not part of the public interface of the testing library.
85-
/// It may be removed in a future update.
86-
func _copyAttachableValue() -> Self
8771
}
8872

8973
@available(_uttypesAPI, *)
@@ -95,6 +79,8 @@ extension AttachableAsCGImage {
9579
public var _attachmentScaleFactor: CGFloat {
9680
1.0
9781
}
82+
83+
public func _deinitializeAttachableValue() {}
9884
}
9985

10086
@available(_uttypesAPI, *)

Sources/Overlays/_Testing_CoreGraphics/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ if(APPLE)
1111
Attachments/_AttachableImageWrapper+AttachableWrapper.swift
1212
Attachments/AttachableAsCGImage.swift
1313
Attachments/AttachableImageFormat+UTType.swift
14-
Attachments/Attachment+AttachableAsCGImage.swift
1514
Attachments/CGImage+AttachableAsCGImage.swift
1615
ReexportTesting.swift)
1716

Sources/Overlays/_Testing_WinSDK/Attachments/AttachableAsIWICBitmapSource.swift

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public protocol _AttachableByAddressAsIWICBitmapSource {
113113
/// you have an image in another format that needs to be attached to a test,
114114
/// first convert it to an instance of one of the types above.
115115
@_spi(Experimental)
116-
public protocol AttachableAsIWICBitmapSource: SendableMetatype {
116+
public protocol AttachableAsIWICBitmapSource: _AttachableAsImage, SendableMetatype {
117117
/// Create a WIC bitmap source representing an instance of this type.
118118
///
119119
/// - Returns: A pointer to a new WIC bitmap source representing this image.
@@ -145,39 +145,6 @@ public protocol AttachableAsIWICBitmapSource: SendableMetatype {
145145
func _copyAttachableIWICBitmapSource(
146146
using factory: UnsafeMutablePointer<IWICImagingFactory>
147147
) throws -> UnsafeMutablePointer<IWICBitmapSource>
148-
149-
/// Make a copy of this instance.
150-
///
151-
/// - Returns: A copy of `self`, or `self` if this type does not support a
152-
/// copying operation.
153-
///
154-
/// The testing library uses this function to take ownership of image
155-
/// resources that test authors pass to it. If possible, make a copy of or add
156-
/// a reference to `self`. If this type does not support making copies, return
157-
/// `self` verbatim.
158-
///
159-
/// The default implementation of this function when `Self` conforms to
160-
/// `Sendable` simply returns `self`.
161-
///
162-
/// This function is not part of the public interface of the testing library.
163-
/// It may be removed in a future update.
164-
func _copyAttachableValue() -> Self
165-
166-
/// Manually deinitialize any resources associated with this image.
167-
///
168-
/// The implementation of this function cleans up any resources (such as
169-
/// handles or COM objects) associated with this image. The testing library
170-
/// automatically invokes this function as needed.
171-
///
172-
/// This function is not responsible for releasing the image returned from
173-
/// `_copyAttachableIWICBitmapSource(using:)`.
174-
///
175-
/// The default implementation of this function when `Self` conforms to
176-
/// `Sendable` does nothing.
177-
///
178-
/// This function is not part of the public interface of the testing library.
179-
/// It may be removed in a future update.
180-
func _deinitializeAttachableValue()
181148
}
182149

183150
extension AttachableAsIWICBitmapSource {
@@ -187,12 +154,4 @@ extension AttachableAsIWICBitmapSource {
187154
try copyAttachableIWICBitmapSource()
188155
}
189156
}
190-
191-
extension AttachableAsIWICBitmapSource where Self: Sendable {
192-
public func _copyAttachableValue() -> Self {
193-
self
194-
}
195-
196-
public func _deinitializeAttachableValue() {}
197-
}
198157
#endif

Sources/Overlays/_Testing_WinSDK/Attachments/Attachment+AttachableAsIWICBitmapSource.swift

Lines changed: 0 additions & 107 deletions
This file was deleted.

Sources/Overlays/_Testing_WinSDK/Attachments/UnsafeMutablePointer+AttachableAsIWICBitmapSource.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private import Testing
1313
public import WinSDK
1414

1515
@_spi(Experimental)
16-
extension UnsafeMutablePointer: AttachableAsIWICBitmapSource where Pointee: _AttachableByAddressAsIWICBitmapSource {
16+
extension UnsafeMutablePointer: _AttachableAsImage, AttachableAsIWICBitmapSource where Pointee: _AttachableByAddressAsIWICBitmapSource {
1717
public func copyAttachableIWICBitmapSource() throws -> UnsafeMutablePointer<IWICBitmapSource> {
1818
let factory = try IWICImagingFactory.create()
1919
defer {
@@ -30,7 +30,7 @@ extension UnsafeMutablePointer: AttachableAsIWICBitmapSource where Pointee: _Att
3030
Pointee._copyAttachableValue(at: self)
3131
}
3232

33-
public consuming func _deinitializeAttachableValue() {
33+
public func _deinitializeAttachableValue() {
3434
Pointee._deinitializeAttachableValue(at: self)
3535
}
3636
}

Sources/Overlays/_Testing_WinSDK/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
1111
Attachments/_AttachableImageWrapper+AttachableWrapper.swift
1212
Attachments/AttachableAsIWICBitmapSource.swift
1313
Attachments/AttachableImageFormat+CLSID.swift
14-
Attachments/Attachment+AttachableAsIWICBitmapSource.swift
1514
Attachments/HBITMAP+AttachableAsIWICBitmapSource.swift
1615
Attachments/HICON+AttachableAsIWICBitmapSource.swift
1716
Attachments/IWICBitmapSource+AttachableAsIWICBitmapSource.swift

Sources/Testing/Attachments/Images/AttachableImageFormat.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
/// @Metadata {
3232
/// @Available(Swift, introduced: 6.3)
3333
/// }
34+
#if SWT_NO_IMAGE_ATTACHMENTS
35+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
36+
#endif
3437
@available(_uttypesAPI, *)
3538
public struct AttachableImageFormat: Sendable {
3639
/// An enumeration describing the various kinds of image format that can be
@@ -77,6 +80,9 @@ public struct AttachableImageFormat: Sendable {
7780

7881
// MARK: -
7982

83+
#if SWT_NO_IMAGE_ATTACHMENTS
84+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
85+
#endif
8086
@available(_uttypesAPI, *)
8187
extension AttachableImageFormat {
8288
/// The PNG image format.
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_TARGET_OS_APPLE && canImport(CoreGraphics)
12-
public import Testing
13-
11+
#if SWT_NO_IMAGE_ATTACHMENTS
12+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
13+
#endif
1414
@available(_uttypesAPI, *)
1515
extension Attachment {
1616
/// Initialize an instance of this type that encloses the given image.
@@ -52,12 +52,8 @@ extension Attachment {
5252
named preferredName: String? = nil,
5353
as imageFormat: AttachableImageFormat? = nil,
5454
sourceLocation: SourceLocation = #_sourceLocation
55-
) where T: AttachableAsCGImage, AttachableValue == _AttachableImageWrapper<T> {
56-
let imageWrapper = _AttachableImageWrapper(
57-
image: image._copyAttachableValue(),
58-
imageFormat: imageFormat,
59-
deinitializingWith: { _ in }
60-
)
55+
) where AttachableValue: _AttachableImageWrapper<T> & AttachableWrapper {
56+
let imageWrapper = AttachableValue(image: image, imageFormat: imageFormat)
6157
self.init(imageWrapper, named: preferredName, sourceLocation: sourceLocation)
6258
}
6359

@@ -99,7 +95,7 @@ extension Attachment {
9995
named preferredName: String? = nil,
10096
as imageFormat: AttachableImageFormat? = nil,
10197
sourceLocation: SourceLocation = #_sourceLocation
102-
) where T: AttachableAsCGImage, AttachableValue == _AttachableImageWrapper<T> {
98+
) where AttachableValue: _AttachableImageWrapper<T> & AttachableWrapper {
10399
let attachment = Self(image, named: preferredName, as: imageFormat, sourceLocation: sourceLocation)
104100
Self.record(attachment, sourceLocation: sourceLocation)
105101
}
@@ -108,12 +104,14 @@ extension Attachment {
108104
// MARK: -
109105

110106
@_spi(Experimental) // STOP: not part of ST-0014
107+
#if SWT_NO_IMAGE_ATTACHMENTS
108+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
109+
#endif
111110
@available(_uttypesAPI, *)
112-
extension Attachment where AttachableValue: AttachableWrapper, AttachableValue.Wrapped: AttachableAsCGImage {
111+
extension Attachment where AttachableValue: AttachableWrapper, AttachableValue.Wrapped: _AttachableAsImage {
113112
/// The image format to use when encoding the represented image.
114113
@_disfavoredOverload public var imageFormat: AttachableImageFormat? {
115114
// FIXME: no way to express `where AttachableValue == _AttachableImageWrapper<???>` on a property (see rdar://47559973)
116115
(attachableValue as? _AttachableImageWrapper<AttachableValue.Wrapped>)?.imageFormat
117116
}
118117
}
119-
#endif

0 commit comments

Comments
 (0)