From 352a76ed2a1b39bb42664a6051db2b30efd51289 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Wed, 3 Dec 2025 11:57:41 -0500 Subject: [PATCH 1/5] Remove `GUID.Wrapper` from the WinSDK overlay. Now that the `Equatable` and `Hashable` conformances for `GUID` have landed in the 6.3 toolchain, we can remove our wrapper workaround type. For the short term, we emit retroactive conformances to these protocols when using the 6.2 toolchain, but I'll remove those in short order. --- .../AttachableImageFormat+CLSID.swift | 24 +++++++-------- .../Support/Additions/GUIDAdditions.swift | 30 ++----------------- 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/Sources/Overlays/_Testing_WinSDK/Attachments/AttachableImageFormat+CLSID.swift b/Sources/Overlays/_Testing_WinSDK/Attachments/AttachableImageFormat+CLSID.swift index dfe04c885..f652e4a33 100644 --- a/Sources/Overlays/_Testing_WinSDK/Attachments/AttachableImageFormat+CLSID.swift +++ b/Sources/Overlays/_Testing_WinSDK/Attachments/AttachableImageFormat+CLSID.swift @@ -16,7 +16,7 @@ public import WinSDK /// } extension AttachableImageFormat { private static let _encoderPathExtensionsByCLSID = Result { - var result = [CLSID.Wrapper: [String]]() + var result = [CLSID: [String]]() // Create an imaging factory. let factory = try IWICImagingFactory.create() @@ -69,7 +69,7 @@ extension AttachableImageFormat { continue } let extensions = _pathExtensions(for: info) - result[CLSID.Wrapper(clsid)] = extensions + result[clsid] = extensions } return result @@ -136,7 +136,7 @@ extension AttachableImageFormat { 0 == _wcsicmp(pathExtension, encoderExt) } } - }.map { $0.key.rawValue } + }.map { $0.key } } /// Get the `CLSID` value of the WIC image encoder corresponding to the same @@ -172,13 +172,13 @@ extension AttachableImageFormat { static func appendPathExtension(for clsid: CLSID, to preferredName: String) -> String { // If there's already a CLSID associated with the filename, and it matches // the one passed to us, no changes are needed. - if let existingCLSID = computeEncoderCLSID(forPreferredName: preferredName), CLSID.Wrapper(clsid) == CLSID.Wrapper(existingCLSID) { + if let existingCLSID = computeEncoderCLSID(forPreferredName: preferredName), clsid == existingCLSID { return preferredName } // Find the preferred path extension for the encoder with the given CLSID. let encoderPathExtensionsByCLSID = (try? _encoderPathExtensionsByCLSID.get()) ?? [:] - if let ext = encoderPathExtensionsByCLSID[CLSID.Wrapper(clsid)]?.first { + if let ext = encoderPathExtensionsByCLSID[clsid]?.first { return "\(preferredName).\(ext)" } @@ -221,12 +221,12 @@ extension AttachableImageFormat { /// @Available(Swift, introduced: 6.3) /// } public init(encoderCLSID: CLSID, encodingQuality: Float = 1.0) { - let encoderCLSID = CLSID.Wrapper(encoderCLSID) - let kind: Kind = if encoderCLSID == CLSID.Wrapper(CLSID_WICPngEncoder) { + let kind: Kind = switch encoderCLSID { + case CLSID_WICPngEncoder: .png - } else if encoderCLSID == CLSID.Wrapper(CLSID_WICJpegEncoder) { + case CLSID_WICJpegEncoder: .jpeg - } else { + default: .systemValue(encoderCLSID) } self.init(kind: kind, encodingQuality: encodingQuality) @@ -281,7 +281,7 @@ extension AttachableImageFormat.Kind: CustomStringConvertible, CustomDebugString case .jpeg: CLSID_WICJpegEncoder case let .systemValue(clsid): - (clsid as! CLSID.Wrapper).rawValue + clsid as! CLSID } } @@ -308,7 +308,7 @@ extension AttachableImageFormat.Kind: CustomStringConvertible, CustomDebugString package var description: String { let clsid = encoderCLSID let encoderPathExtensionsByCLSID = (try? AttachableImageFormat._encoderPathExtensionsByCLSID.get()) ?? [:] - if let ext = encoderPathExtensionsByCLSID[CLSID.Wrapper(clsid)]?.first { + if let ext = encoderPathExtensionsByCLSID[clsid]?.first { return "\(ext.uppercased()) format" } return Self._description(of: clsid) @@ -318,7 +318,7 @@ extension AttachableImageFormat.Kind: CustomStringConvertible, CustomDebugString let clsid = encoderCLSID let clsidDescription = Self._description(of: clsid) let encoderPathExtensionsByCLSID = (try? AttachableImageFormat._encoderPathExtensionsByCLSID.get()) ?? [:] - if let ext = encoderPathExtensionsByCLSID[CLSID.Wrapper(clsid)]?.first { + if let ext = encoderPathExtensionsByCLSID[clsid]?.first { return "\(ext.uppercased()) format (\(clsidDescription))" } return clsidDescription diff --git a/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift b/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift index 06985ed4c..f499895b2 100644 --- a/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift +++ b/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift @@ -8,31 +8,10 @@ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors // -#if os(Windows) +#if compiler(<6.3) && os(Windows) internal import WinSDK -extension GUID { - /// A type that wraps `GUID` instances and conforms to various Swift - /// protocols. - /// - /// - Bug: This type will become obsolete once we can use the `Equatable` and - /// `Hashable` conformances added to the WinSDK module in Swift 6.3. -#if compiler(>=6.3.1) && DEBUG - @available(*, deprecated, message: "GUID.Wrapper is no longer needed and can be removed.") -#endif - struct Wrapper: Sendable, RawRepresentable { - var rawValue: GUID - } -} - -// MARK: - - -extension GUID.Wrapper: Equatable, Hashable, CustomStringConvertible { - init(_ rawValue: GUID) { - self.init(rawValue: rawValue) - } - -#if compiler(<6.3.1) +extension GUID: @retroactive Equatable, Hashable { private var _uint128Value: UInt128 { withUnsafeBytes(of: rawValue) { buffer in buffer.baseAddress!.loadUnaligned(as: UInt128.self) @@ -46,10 +25,5 @@ extension GUID.Wrapper: Equatable, Hashable, CustomStringConvertible { func hash(into hasher: inout Hasher) { hasher.combine(_uint128Value) } - - var description: String { - String(describing: rawValue) - } -#endif } #endif From 76de40df3863eeb93081004a9e86842e467f4892 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Wed, 3 Dec 2025 12:24:59 -0500 Subject: [PATCH 2/5] Hide the conformances --- .../_Testing_WinSDK/Support/Additions/GUIDAdditions.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift b/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift index f499895b2..2cb3c62c0 100644 --- a/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift +++ b/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift @@ -11,7 +11,11 @@ #if compiler(<6.3) && os(Windows) internal import WinSDK -extension GUID: @retroactive Equatable, Hashable { +/// A protocol that obscures the `Equatable` and `Hashable` protocols so we +/// don't need to publicly declare that `GUID` conforms to them. +protocol GUIDProtocol: Equatable, Hashable {} + +extension GUID: GUIDProtocol { private var _uint128Value: UInt128 { withUnsafeBytes(of: rawValue) { buffer in buffer.baseAddress!.loadUnaligned(as: UInt128.self) From 4484f186e009dbab52d241358daf67b36d31d988 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Wed, 3 Dec 2025 12:37:56 -0500 Subject: [PATCH 3/5] Revert "Hide the conformances" This reverts commit 76de40df3863eeb93081004a9e86842e467f4892. --- .../_Testing_WinSDK/Support/Additions/GUIDAdditions.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift b/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift index 2cb3c62c0..f499895b2 100644 --- a/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift +++ b/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift @@ -11,11 +11,7 @@ #if compiler(<6.3) && os(Windows) internal import WinSDK -/// A protocol that obscures the `Equatable` and `Hashable` protocols so we -/// don't need to publicly declare that `GUID` conforms to them. -protocol GUIDProtocol: Equatable, Hashable {} - -extension GUID: GUIDProtocol { +extension GUID: @retroactive Equatable, Hashable { private var _uint128Value: UInt128 { withUnsafeBytes(of: rawValue) { buffer in buffer.baseAddress!.loadUnaligned(as: UInt128.self) From cd8936326e55c0759266c54665235c532034392f Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Wed, 3 Dec 2025 12:38:45 -0500 Subject: [PATCH 4/5] Okay just make the conformances public --- .../Support/Additions/GUIDAdditions.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift b/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift index f499895b2..82d4ec89d 100644 --- a/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift +++ b/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift @@ -9,20 +9,20 @@ // #if compiler(<6.3) && os(Windows) -internal import WinSDK +public import WinSDK -extension GUID: @retroactive Equatable, Hashable { +extension GUID: @retroactive Equatable, @retroactive Hashable { private var _uint128Value: UInt128 { - withUnsafeBytes(of: rawValue) { buffer in + withUnsafeBytes(of: self) { buffer in buffer.baseAddress!.loadUnaligned(as: UInt128.self) } } - static func ==(lhs: Self, rhs: Self) -> Bool { + public static func ==(lhs: Self, rhs: Self) -> Bool { lhs._uint128Value == rhs._uint128Value } - func hash(into hasher: inout Hasher) { + public func hash(into hasher: inout Hasher) { hasher.combine(_uint128Value) } } From 95883de0a019eba315882e4a43bd5923d9c89aab Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Wed, 3 Dec 2025 12:42:39 -0500 Subject: [PATCH 5/5] C++ interop workaround same as in the main Swift repo --- .../_Testing_WinSDK/Support/Additions/GUIDAdditions.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift b/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift index 82d4ec89d..95796785a 100644 --- a/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift +++ b/Sources/Overlays/_Testing_WinSDK/Support/Additions/GUIDAdditions.swift @@ -18,7 +18,9 @@ extension GUID: @retroactive Equatable, @retroactive Hashable { } } - public static func ==(lhs: Self, rhs: Self) -> Bool { + // SEE: https://github.com/swiftlang/swift/pull/85196 + @_implements(Equatable, ==(_:_:)) + public static func __equals(lhs: Self, rhs: Self) -> Bool { lhs._uint128Value == rhs._uint128Value }