Skip to content

Commit f859dd1

Browse files
committed
[Foundation] URL: Fix availability of the new hash(into:) implementation
1 parent b711ed9 commit f859dd1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

stdlib/public/Darwin/Foundation/URL.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,36 @@ public struct URL : ReferenceConvertible, Equatable {
626626
return _url.hash
627627
}
628628

629+
@_alwaysEmitIntoClient // Introduced in 5.1
629630
public func hash(into hasher: inout Hasher) {
631+
// We expect this function to eventually satisfy the corresponding
632+
// requirement when URL starts conforming to Hashable. However, in the
633+
// meantime, it is useful to provide it so that user code can simply
634+
// declare the conformance if desired, without implementing anything.
635+
//
636+
// We want this definition to be available to all clients, even those
637+
// that get deployed with the 5.0 Foundation overlay where URL did not
638+
// provide this method. The `@_alwaysEmitIntoClient` attribute above
639+
// forces this function to get compiled into any user code that uses it.
640+
if #available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) {
641+
// When we're on recent enough ABI, we forward the call to the
642+
// resilient implementation provided below. The availability check
643+
// above guarantees that the entry point will exist in the library
644+
// we link with.
645+
_hash(into: &hasher)
646+
} else {
647+
// This is the hash encoding that gets used with the 5.0 ABI. It has
648+
// to match the version of == implemented by 5.0, so it shouldn't
649+
// ever be changed.
650+
hasher.combine(_bridgeToObjectiveC())
651+
}
652+
}
653+
654+
@usableFromInline
655+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
656+
internal func _hash(into hasher: inout Hasher) {
657+
// This code is beyond a resilience boundary. It has to be kept in
658+
// sync with the definition of == implemented below.
630659
hasher.combine(_url)
631660
}
632661

0 commit comments

Comments
 (0)