Skip to content

Commit 40dfda5

Browse files
committed
Disable runtime cow verification for mutableSpan property
1 parent c246b49 commit 40dfda5

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

stdlib/public/core/Array.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,17 @@ extension Array {
355355
}
356356
}
357357

358+
#if INTERNAL_CHECKS_ENABLED && COW_CHECKS_ENABLED
359+
@inlinable
360+
@_semantics("array.make_mutable")
361+
@_effects(notEscaping self.**)
362+
internal mutating func _makeMutableAndUniqueUnchecked() {
363+
if _slowPath(!_buffer.beginCOWMutationUnchecked()) {
364+
_buffer = _buffer._consumeAndCreateNew()
365+
}
366+
}
367+
#endif
368+
358369
/// Marks the end of an Array mutation.
359370
///
360371
/// After a call to `_endMutation` the buffer must not be mutated until a call
@@ -1735,7 +1746,11 @@ extension Array {
17351746
@lifetime(&self)
17361747
@_alwaysEmitIntoClient
17371748
mutating get {
1749+
#if INTERNAL_CHECKS_ENABLED && COW_CHECKS_ENABLED
1750+
_makeMutableAndUniqueUnchecked()
1751+
#else
17381752
_makeMutableAndUnique()
1753+
#endif
17391754
// LifetimeDependence analysis inserts call to Builtin.endCOWMutation.
17401755
let pointer = unsafe _buffer.firstElementAddress
17411756
let count = _buffer.mutableCount

stdlib/public/core/ArrayBuffer.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,22 @@ extension _ArrayBuffer {
135135
#endif
136136
return isUnique
137137
}
138-
138+
139+
#if INTERNAL_CHECKS_ENABLED && COW_CHECKS_ENABLED
140+
@_alwaysEmitIntoClient
141+
internal mutating func beginCOWMutationUnchecked() -> Bool {
142+
let isUnique: Bool
143+
if !_isClassOrObjCExistential(Element.self) {
144+
isUnique = _storage.beginCOWMutationUnflaggedNative()
145+
} else if !_storage.beginCOWMutationNative() {
146+
return false
147+
} else {
148+
isUnique = _isNative
149+
}
150+
return isUnique
151+
}
152+
#endif
153+
139154
/// Puts the buffer in an immutable state.
140155
///
141156
/// - Precondition: The buffer must be mutable or the empty array singleton.

stdlib/public/core/ArraySlice.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,10 +1305,12 @@ extension ArraySlice {
13051305
@lifetime(&self)
13061306
@_alwaysEmitIntoClient
13071307
mutating get {
1308+
#if INTERNAL_CHECKS_ENABLED && COW_CHECKS_ENABLED
1309+
_makeMutableAndUniqueUnchecked()
1310+
#else
13081311
_makeMutableAndUnique()
1309-
// NOTE: We don't have the ability to schedule a call to
1310-
// ContiguousArrayBuffer.endCOWMutation().
1311-
// rdar://146785284 (lifetime analysis for end of mutation)
1312+
#endif
1313+
// LifetimeDependence analysis inserts call to Builtin.endCOWMutation.
13121314
let (pointer, count) = unsafe (_buffer.firstElementAddress, _buffer.count)
13131315
let span = unsafe MutableSpan(_unsafeStart: pointer, count: count)
13141316
return unsafe _overrideLifetime(span, mutating: &self)

stdlib/public/core/ContiguousArray.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,10 +1247,12 @@ extension ContiguousArray {
12471247
@lifetime(&self)
12481248
@_alwaysEmitIntoClient
12491249
mutating get {
1250+
#if INTERNAL_CHECKS_ENABLED && COW_CHECKS_ENABLED
1251+
_makeMutableAndUniqueUnchecked()
1252+
#else
12501253
_makeMutableAndUnique()
1251-
// NOTE: We don't have the ability to schedule a call to
1252-
// ContiguousArrayBuffer.endCOWMutation().
1253-
// rdar://146785284 (lifetime analysis for end of mutation)
1254+
#endif
1255+
// LifetimeDependence analysis inserts call to Builtin.endCOWMutation.
12541256
let pointer = unsafe _buffer.firstElementAddress
12551257
let count = _buffer.mutableCount
12561258
let span = unsafe MutableSpan(_unsafeStart: pointer, count: count)

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ internal struct _ContiguousArrayBuffer<Element>: _ArrayBufferProtocol {
808808
/// - Warning: It's a requirement to call `beginCOWMutation` before the buffer
809809
/// is mutated.
810810
@_alwaysEmitIntoClient
811-
internal mutating func beginCOWMutation() -> Bool {
811+
internal mutating func beginCOWMutation(checked: Bool = true) -> Bool {
812812
if Bool(Builtin.beginCOWMutation(&_storage)) {
813813
#if INTERNAL_CHECKS_ENABLED && COW_CHECKS_ENABLED
814814
isImmutable = false
@@ -818,6 +818,16 @@ internal struct _ContiguousArrayBuffer<Element>: _ArrayBufferProtocol {
818818
return false;
819819
}
820820

821+
#if INTERNAL_CHECKS_ENABLED && COW_CHECKS_ENABLED
822+
@_alwaysEmitIntoClient
823+
internal mutating func beginCOWMutationUnchecked() -> Bool {
824+
if Bool(Builtin.beginCOWMutation(&_storage)) {
825+
return true
826+
}
827+
return false;
828+
}
829+
#endif
830+
821831
/// Puts the buffer in an immutable state.
822832
///
823833
/// - Precondition: The buffer must be mutable or the empty array singleton.

0 commit comments

Comments
 (0)