Skip to content

Commit

Permalink
Fix AnySendableHashable regression (#193)
Browse files Browse the repository at this point in the history
* Unbreak the API

* Make it all inlineable
  • Loading branch information
0xTim authored Nov 16, 2023
1 parent f4ef965 commit 7d0898e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Sources/ConsoleKit/Activity/ActivityBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
16 changes: 13 additions & 3 deletions Sources/ConsoleKit/Utilities/AnySendableHashable.swift
Original file line number Diff line number Diff line change
@@ -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 }
}
}

0 comments on commit 7d0898e

Please sign in to comment.