Skip to content

Commit b8a8703

Browse files
authored
Merge pull request #14118 from milseman/hash_hack_attack
[string] ARC hack around hashValue
2 parents 92a2f9c + 436475f commit b8a8703

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

stdlib/public/core/StringHashable.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,22 @@ extension _UnmanagedOpaqueString {
145145
}
146146

147147
extension _StringGuts {
148+
//
149+
// FIXME(TODO: JIRA): HACK HACK HACK: Work around for ARC :-(
150+
//
148151
@_versioned
152+
@effects(readonly)
149153
@inline(never) // Hide the CF dependency
154+
internal static func _computeHashValue(
155+
_unsafeBitPattern: _RawBitPattern
156+
) -> Int {
157+
return _StringGuts(rawBits: _unsafeBitPattern)._computeHashValue()
158+
}
159+
160+
@_versioned
161+
// TODO: After removing above hack: @inline(never) // Hide the CF dependency
150162
internal func _computeHashValue() -> Int {
163+
defer { _fixLifetime(self) }
151164
if _slowPath(_isOpaque) {
152165
return _asOpaque().computeHashValue()
153166
}
@@ -158,8 +171,9 @@ extension _StringGuts {
158171
}
159172

160173
@_versioned
161-
@inline(never) // Hide the CF dependency
174+
// TODO: After removing above hack: @inline(never) // Hide the CF dependency
162175
internal func _computeHashValue(_ range: Range<Int>) -> Int {
176+
defer { _fixLifetime(self) }
163177
if _slowPath(_isOpaque) {
164178
return _asOpaque()[range].computeHashValue()
165179
}
@@ -177,7 +191,9 @@ extension String : Hashable {
177191
/// your program. Do not save hash values to use during a future execution.
178192
@_inlineable // FIXME(sil-serialize-all)
179193
public var hashValue: Int {
180-
return _guts._computeHashValue()
194+
defer { _fixLifetime(self) }
195+
let gutsBits = _guts.rawBits
196+
return _StringGuts._computeHashValue(_unsafeBitPattern: gutsBits)
181197
}
182198
}
183199

0 commit comments

Comments
 (0)