Skip to content

Commit 66d62ff

Browse files
committed
stdlib: fix a back-deployment issue for array COW checks with a stdlib assert-build
And rename COWSanityChecks -> COWChecks. rdar://problem/68181747
1 parent 27aad53 commit 66d62ff

File tree

4 files changed

+29
-31
lines changed

4 files changed

+29
-31
lines changed

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,8 @@ import SwiftShims
1414

1515
#if INTERNAL_CHECKS_ENABLED
1616
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
17-
@_silgen_name("swift_COWSanityChecksEnabled")
18-
public func _COWSanityChecksEnabled() -> Bool
19-
20-
@_alwaysEmitIntoClient
21-
internal func doCOWSanityChecks() -> Bool {
22-
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
23-
return _COWSanityChecksEnabled()
24-
}
25-
return false
26-
}
17+
@_silgen_name("swift_COWChecksEnabled")
18+
public func _COWChecksEnabled() -> Bool
2719
#endif
2820

2921
/// Class used whose sole instance is used as storage for empty
@@ -468,34 +460,40 @@ internal struct _ContiguousArrayBuffer<Element>: _ArrayBufferProtocol {
468460
@_alwaysEmitIntoClient
469461
internal var isImmutable: Bool {
470462
get {
471-
if doCOWSanityChecks() {
472-
return capacity == 0 || _swift_isImmutableCOWBuffer(_storage)
463+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
464+
if (_COWChecksEnabled()) {
465+
return capacity == 0 || _swift_isImmutableCOWBuffer(_storage)
466+
}
473467
}
474468
return true
475469
}
476470
nonmutating set {
477-
if doCOWSanityChecks() {
478-
if newValue {
479-
if capacity > 0 {
480-
let wasImmutable = _swift_setImmutableCOWBuffer(_storage, true)
481-
_internalInvariant(!wasImmutable,
482-
"re-setting immutable array buffer to immutable")
471+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
472+
if (_COWChecksEnabled()) {
473+
if newValue {
474+
if capacity > 0 {
475+
let wasImmutable = _swift_setImmutableCOWBuffer(_storage, true)
476+
_internalInvariant(!wasImmutable,
477+
"re-setting immutable array buffer to immutable")
478+
}
479+
} else {
480+
_internalInvariant(capacity > 0,
481+
"setting empty array buffer to mutable")
482+
let wasImmutable = _swift_setImmutableCOWBuffer(_storage, false)
483+
_internalInvariant(wasImmutable,
484+
"re-setting mutable array buffer to mutable")
483485
}
484-
} else {
485-
_internalInvariant(capacity > 0,
486-
"setting empty array buffer to mutable")
487-
let wasImmutable = _swift_setImmutableCOWBuffer(_storage, false)
488-
_internalInvariant(wasImmutable,
489-
"re-setting mutable array buffer to mutable")
490486
}
491487
}
492488
}
493489
}
494490

495491
@_alwaysEmitIntoClient
496492
internal var isMutable: Bool {
497-
if doCOWSanityChecks() {
498-
return !_swift_isImmutableCOWBuffer(_storage)
493+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
494+
if (_COWChecksEnabled()) {
495+
return !_swift_isImmutableCOWBuffer(_storage)
496+
}
499497
}
500498
return true
501499
}

stdlib/public/runtime/EnvironmentVariables.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void swift::runtime::environment::initialize(void *context) {
190190
#endif
191191

192192
SWIFT_RUNTIME_EXPORT
193-
bool swift_COWSanityChecksEnabled() {
194-
return runtime::environment::SWIFT_DEBUG_ENABLE_COW_SANITY_CHECKS();
193+
bool swift_COWChecksEnabled() {
194+
return runtime::environment::SWIFT_DEBUG_ENABLE_COW_CHECKS();
195195
}
196196

stdlib/public/runtime/EnvironmentVariables.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ VARIABLE(SWIFT_ENABLE_MANGLED_NAME_VERIFICATION, bool, false,
4444
VARIABLE(SWIFT_DEBUG_ENABLE_MALLOC_SCRIBBLE, bool, false,
4545
"Scribble on runtime allocations such as metadata allocations.")
4646

47-
VARIABLE(SWIFT_DEBUG_ENABLE_COW_SANITY_CHECKS, bool, false,
48-
"Enable sanity checks for copy-on-write operations.")
47+
VARIABLE(SWIFT_DEBUG_ENABLE_COW_CHECKS, bool, false,
48+
"Enable internal checks for copy-on-write operations.")
4949

5050
#undef VARIABLE

test/lit.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ config.environment[TARGET_ENV_PREFIX + 'SWIFT_DETERMINISTIC_HASHING'] = '1'
19931993
config.environment[TARGET_ENV_PREFIX + 'SWIFT_DEBUG_ENABLE_MALLOC_SCRIBBLE'] = 'YES'
19941994

19951995
# Enable COW sanity checks in the swift runtime by default.
1996-
config.environment['SWIFT_DEBUG_ENABLE_COW_SANITY_CHECKS'] = 'true'
1996+
config.environment['SWIFT_DEBUG_ENABLE_COW_CHECKS'] = 'true'
19971997

19981998
# Run lsb_release on the target to be tested and return the results.
19991999
def linux_get_lsb_release():

0 commit comments

Comments
 (0)