Skip to content

Commit ec428d2

Browse files
committed
Don't add retroactive conformances to GUID
1 parent fd84e29 commit ec428d2

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

Sources/Overlays/_Testing_WinSDK/Attachments/AttachableImageFormat+CLSID.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public import WinSDK
1313

1414
extension AttachableImageFormat {
1515
private static let _encoderPathExtensionsByCLSID = Result {
16-
var result = [GUID: [String]]()
16+
var result = [CLSID.Wrapper: [String]]()
1717

1818
// Create an imaging factory.
1919
let factory = try IWICImagingFactory.create()
@@ -66,7 +66,7 @@ extension AttachableImageFormat {
6666
continue
6767
}
6868
let extensions = _pathExtensions(for: info)
69-
result[clsid] = extensions
69+
result[CLSID.Wrapper(clsid)] = extensions
7070
}
7171

7272
return result
@@ -133,7 +133,7 @@ extension AttachableImageFormat {
133133
0 == _wcsicmp(pathExtension, encoderExt)
134134
}
135135
}
136-
}.map { $0.key }
136+
}.map { $0.key.rawValue }
137137
}
138138

139139
/// Get the `CLSID` value of the WIC image encoder corresponding to the same
@@ -169,13 +169,13 @@ extension AttachableImageFormat {
169169
static func appendPathExtension(for clsid: CLSID, to preferredName: String) -> String {
170170
// If there's already a CLSID associated with the filename, and it matches
171171
// the one passed to us, no changes are needed.
172-
if let existingCLSID = computeEncoderCLSID(forPreferredName: preferredName), clsid == existingCLSID {
172+
if let existingCLSID = computeEncoderCLSID(forPreferredName: preferredName), CLSID.Wrapper(clsid) == CLSID.Wrapper(existingCLSID) {
173173
return preferredName
174174
}
175175

176176
// Find the preferred path extension for the encoder with the given CLSID.
177177
let encoderPathExtensionsByCLSID = (try? _encoderPathExtensionsByCLSID.get()) ?? [:]
178-
if let ext = encoderPathExtensionsByCLSID[clsid]?.first {
178+
if let ext = encoderPathExtensionsByCLSID[CLSID.Wrapper(clsid)]?.first {
179179
return "\(preferredName).\(ext)"
180180
}
181181

@@ -202,7 +202,7 @@ extension AttachableImageFormat {
202202
case .jpeg:
203203
CLSID_WICJpegEncoder
204204
case let .systemValue(clsid):
205-
clsid as! GUID
205+
(clsid as! CLSID.Wrapper).rawValue
206206
}
207207
}
208208

@@ -231,11 +231,12 @@ extension AttachableImageFormat {
231231
@_spi(_)
232232
#endif
233233
public init(encoderCLSID: CLSID, encodingQuality: Float = 1.0) {
234-
if encoderCLSID == CLSID_WICPngEncoder {
234+
switch CLSID.Wrapper(encoderCLSID) {
235+
case CLSID.Wrapper(CLSID_WICPngEncoder):
235236
self = .png
236-
} else if encoderCLSID == CLSID_WICJpegEncoder {
237+
case CLSID.Wrapper(CLSID_WICJpegEncoder):
237238
self = .jpeg
238-
} else {
239+
case let encoderCLSID:
239240
self.init(kind: .systemValue(encoderCLSID), encodingQuality: encodingQuality)
240241
}
241242
}

Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,42 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if os(Windows) && compiler(<6.4)
12-
public import WinSDK
11+
#if os(Windows)
12+
internal import WinSDK
1313

14-
// Retroactively add conformance to `Equatable` and `Hashable` until
15-
// https://github.com/swiftlang/swift/pull/84792 is merged into the WinSDK Swift
16-
// overlay.
14+
extension GUID {
15+
/// A type that wraps `GUID` instances and conforms to various Swift
16+
/// protocols.
17+
///
18+
/// - Bug: This type will become obsolete once we can use the `Equatable` and
19+
/// `Hashable` conformances added to the WinSDK module in Swift 6.3.
20+
#if compiler(>=6.3.1) && DEBUG
21+
@available(*, deprecated, message: "GUID.Wrapper is no longer needed and can be removed.")
22+
#endif
23+
struct Wrapper: Sendable, RawRepresentable {
24+
var rawValue: GUID
25+
}
26+
}
1727

18-
@_spi(_)
19-
extension GUID: @retroactive Equatable, @retroactive Hashable {
20-
/// This GUID as an integer.
28+
extension GUID.Wrapper: Equatable, Hashable {
29+
init(_ rawValue: GUID) {
30+
self.init(rawValue: rawValue)
31+
}
32+
33+
#if compiler(<6.3.1)
2134
private var _uint128Value: UInt128 {
22-
withUnsafeBytes(of: self) { buffer in
35+
withUnsafeBytes(of: rawValue) { buffer in
2336
buffer.baseAddress!.loadUnaligned(as: UInt128.self)
2437
}
2538
}
2639

27-
public static func ==(lhs: Self, rhs: Self) -> Bool {
40+
static func ==(lhs: Self, rhs: Self) -> Bool {
2841
lhs._uint128Value == rhs._uint128Value
2942
}
3043

31-
public func hash(into hasher: inout Hasher) {
44+
func hash(into hasher: inout Hasher) {
3245
hasher.combine(_uint128Value)
3346
}
47+
#endif
3448
}
3549
#endif

0 commit comments

Comments
 (0)