Skip to content

Commit

Permalink
Merge pull request #77843 from swiftlang/egorzhdan/cxxstdlib-hash-linux
Browse files Browse the repository at this point in the history
[cxx-interop] Workaround a deserialization error for CxxStdlib on Linux
  • Loading branch information
al45tair authored Nov 27, 2024
2 parents 46a21c4 + c577561 commit b13544e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions stdlib/public/Cxx/cxxshim/libcxxstdlibshim.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@

/// Used for std::string conformance to Swift.Hashable
typedef std::hash<std::string> __swift_interopHashOfString;
inline std::size_t __swift_interopComputeHashOfString(std::string str) {
return __swift_interopHashOfString()(str);
}

/// Used for std::u16string conformance to Swift.Hashable
typedef std::hash<std::u16string> __swift_interopHashOfU16String;
inline std::size_t __swift_interopComputeHashOfU16String(std::u16string str) {
return __swift_interopHashOfU16String()(str);
}

/// Used for std::u32string conformance to Swift.Hashable
typedef std::hash<std::u32string> __swift_interopHashOfU32String;
inline std::size_t __swift_interopComputeHashOfU32String(std::u32string str) {
return __swift_interopHashOfU32String()(str);
}

inline std::chrono::seconds __swift_interopMakeChronoSeconds(int64_t seconds) {
return std::chrono::seconds(seconds);
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/Cxx/std/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ extension std.string: Hashable {
@_alwaysEmitIntoClient
public func hash(into hasher: inout Hasher) {
// Call std::hash<std::string>::operator()
let cxxHash = __swift_interopHashOfString().callAsFunction(self)
let cxxHash = __swift_interopComputeHashOfString(self)
hasher.combine(cxxHash)
}
}
Expand All @@ -207,7 +207,7 @@ extension std.u16string: Hashable {
@_alwaysEmitIntoClient
public func hash(into hasher: inout Hasher) {
// Call std::hash<std::u16string>::operator()
let cxxHash = __swift_interopHashOfU16String().callAsFunction(self)
let cxxHash = __swift_interopComputeHashOfU16String(self)
hasher.combine(cxxHash)
}
}
Expand All @@ -216,7 +216,7 @@ extension std.u32string: Hashable {
@_alwaysEmitIntoClient
public func hash(into hasher: inout Hasher) {
// Call std::hash<std::u32string>::operator()
let cxxHash = __swift_interopHashOfU32String().callAsFunction(self)
let cxxHash = __swift_interopComputeHashOfU32String(self)
hasher.combine(cxxHash)
}
}
Expand Down

0 comments on commit b13544e

Please sign in to comment.