Skip to content

[AnyHashable] Eliminate the _AnyHashableProtocol hack. #5132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@
//
//===----------------------------------------------------------------------===//

// FIXME(ABI)#35 (Concrete Same Type Requirements): This protocol exists to identify
// `AnyHashable` in conditional extensions. Replace this protocol
// with conditional extensions on `Set` and `Dictionary` "where Key ==
// AnyHashable".
public protocol _AnyHashableProtocol {
var base: Any { get }
}

extension AnyHashable : _AnyHashableProtocol {}

//===----------------------------------------------------------------------===//
// Convenience APIs for Set<AnyHashable>
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -49,8 +39,7 @@ extension Set {
}
}

// FIXME(ABI)#37 (Concrete Same Type Requirements): replace with `where Element == AnyHashable`.
extension Set where Element : _AnyHashableProtocol {
extension Set where Element == AnyHashable {
public mutating func insert<ConcreteElement : Hashable>(
_ newMember: ConcreteElement
) -> (inserted: Bool, memberAfterInsert: ConcreteElement) {
Expand All @@ -65,15 +54,15 @@ extension Set where Element : _AnyHashableProtocol {
public mutating func update<ConcreteElement : Hashable>(
with newMember: ConcreteElement
) -> ConcreteElement? {
return _concreteElement_update(with: AnyHashable(newMember) as! Element)
return _concreteElement_update(with: AnyHashable(newMember))
.map { $0.base as! ConcreteElement }
}

@discardableResult
public mutating func remove<ConcreteElement : Hashable>(
_ member: ConcreteElement
) -> ConcreteElement? {
return _concreteElement_remove(AnyHashable(member) as! Element)
return _concreteElement_remove(AnyHashable(member))
.map { $0.base as! ConcreteElement }
}
}
Expand Down Expand Up @@ -109,31 +98,30 @@ extension Dictionary {
}
}

// FIXME(ABI)#39 (Concrete Same Type Requirements): replace with `where Element == AnyHashable`.
extension Dictionary where Key : _AnyHashableProtocol {
extension Dictionary where Key == AnyHashable {
public subscript(_ key: _Hashable) -> Value? {
// FIXME(ABI)#40 (Generic subscripts): replace this API with a
// generic subscript.
get {
return self[_concreteKey: key._toAnyHashable() as! Key]
return self[_concreteKey: key._toAnyHashable()]
}
set {
self[_concreteKey: key._toAnyHashable() as! Key] = newValue
self[_concreteKey: key._toAnyHashable()] = newValue
}
}

@discardableResult
public mutating func updateValue<ConcreteKey : Hashable>(
_ value: Value, forKey key: ConcreteKey
) -> Value? {
return _concreteKey_updateValue(value, forKey: AnyHashable(key) as! Key)
return _concreteKey_updateValue(value, forKey: AnyHashable(key))
}

@discardableResult
public mutating func removeValue<ConcreteKey : Hashable>(
forKey key: ConcreteKey
) -> Value? {
return _concreteKey_removeValue(forKey: AnyHashable(key) as! Key)
return _concreteKey_removeValue(forKey: AnyHashable(key))
}
}