From 7d0898ed481e1855ec549924ab701bdc6f754b18 Mon Sep 17 00:00:00 2001 From: Tim Condon <0xTim@users.noreply.github.com> Date: Thu, 16 Nov 2023 02:04:47 +0000 Subject: [PATCH] Fix `AnySendableHashable` regression (#193) * Unbreak the API * Make it all inlineable --- Sources/ConsoleKit/Activity/ActivityBar.swift | 4 ++-- .../Utilities/AnySendableHashable.swift | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Sources/ConsoleKit/Activity/ActivityBar.swift b/Sources/ConsoleKit/Activity/ActivityBar.swift index 0c8cae5..be992a1 100644 --- a/Sources/ConsoleKit/Activity/ActivityBar.swift +++ b/Sources/ConsoleKit/Activity/ActivityBar.swift @@ -52,11 +52,11 @@ struct ActivityBarWidthKey: Hashable, Equatable { extension Console { public var activityBarWidth: Int { get { - self.userInfo[AnySendableHashable(ActivityBarWidthKey())] as? Int ?? 25 + self.userInfo[ActivityBarWidthKey()] as? Int ?? 25 } set { - self.userInfo[AnySendableHashable(ActivityBarWidthKey())] = newValue + self.userInfo[ActivityBarWidthKey()] = newValue } } } diff --git a/Sources/ConsoleKit/Utilities/AnySendableHashable.swift b/Sources/ConsoleKit/Utilities/AnySendableHashable.swift index dddf26b..79dc47d 100644 --- a/Sources/ConsoleKit/Utilities/AnySendableHashable.swift +++ b/Sources/ConsoleKit/Utilities/AnySendableHashable.swift @@ -1,19 +1,29 @@ /// A `Sendable` version of the standard library's `AnyHashable` type. public struct AnySendableHashable: @unchecked Sendable, Hashable, ExpressibleByStringLiteral { // Note: @unchecked Sendable since there's no way to express that `wrappedValue` is Sendable, even though we ensure that it is in the init. + @usableFromInline let wrappedValue: AnyHashable + @inlinable public init(_ wrappedValue: some Hashable & Sendable) { self.wrappedValue = AnyHashable(wrappedValue) } + @inlinable public init(stringLiteral value: String) { self.init(value) } } extension AnySendableHashable: CustomStringConvertible, CustomDebugStringConvertible, CustomReflectable { - public var description: String { self.wrappedValue.description } - public var debugDescription: String { self.wrappedValue.debugDescription } - public var customMirror: Mirror { self.wrappedValue.customMirror } + @inlinable public var description: String { self.wrappedValue.description } + @inlinable public var debugDescription: String { self.wrappedValue.debugDescription } + @inlinable public var customMirror: Mirror { self.wrappedValue.customMirror } +} + +extension Dictionary where Key == AnySendableHashable { + public subscript(key: some Hashable & Sendable) -> Value? { + @inlinable get { self[AnySendableHashable(key)] } + @inlinable set { self[AnySendableHashable(key)] = newValue } + } }