Skip to content

Commit 53fc177

Browse files
authored
Merge pull request #37945 from eeckstein/fix-cow-check-availability
stdlib: fix availability for internal COW checks.
2 parents 29176fc + 0831240 commit 53fc177

25 files changed

+2777
-3141
lines changed

stdlib/public/core/Builtin.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,18 @@ internal func _class_getInstancePositiveExtentSize(_ theClass: AnyClass) -> Int
346346
}
347347

348348
#if INTERNAL_CHECKS_ENABLED
349-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
349+
// "9999" means: enable if linked with a built library, but not when linked with
350+
// the OS libraries.
351+
// Note: this must not be changed to a "real" OS version.
352+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
350353
@usableFromInline
351354
@_silgen_name("_swift_isImmutableCOWBuffer")
352355
internal func _swift_isImmutableCOWBuffer(_ object: AnyObject) -> Bool
353356

354-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
357+
// "9999" means: enable if linked with a built library, but not when linked with
358+
// the OS libraries.
359+
// Note: this must not be changed to a "real" OS version.
360+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
355361
@usableFromInline
356362
@_silgen_name("_swift_setImmutableCOWBuffer")
357363
internal func _swift_setImmutableCOWBuffer(_ object: AnyObject, _ immutable: Bool) -> Bool

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
import SwiftShims
1414

1515
#if INTERNAL_CHECKS_ENABLED
16-
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
16+
// "9999" means: enable if linked with a built library, but not when linked with
17+
// the OS libraries.
18+
// Note: this must not be changed to a "real" OS version.
19+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
1720
@_silgen_name("swift_COWChecksEnabled")
1821
public func _COWChecksEnabled() -> Bool
1922
#endif
@@ -460,15 +463,21 @@ internal struct _ContiguousArrayBuffer<Element>: _ArrayBufferProtocol {
460463
@_alwaysEmitIntoClient
461464
internal var isImmutable: Bool {
462465
get {
463-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
466+
// "9999" means: enable if linked with a built library, but not when
467+
// linked with the OS libraries.
468+
// Note: this must not be changed to a "real" OS version.
469+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
464470
if (_COWChecksEnabled()) {
465471
return capacity == 0 || _swift_isImmutableCOWBuffer(_storage)
466472
}
467473
}
468474
return true
469475
}
470476
nonmutating set {
471-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
477+
// "9999" means: enable if linked with a built library, but not when
478+
// linked with the OS libraries.
479+
// Note: this must not be changed to a "real" OS version.
480+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
472481
if (_COWChecksEnabled()) {
473482
// Make sure to not modify the empty array singleton (which has a
474483
// capacity of 0).
@@ -489,7 +498,10 @@ internal struct _ContiguousArrayBuffer<Element>: _ArrayBufferProtocol {
489498

490499
@_alwaysEmitIntoClient
491500
internal var isMutable: Bool {
492-
if #available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *) {
501+
// "9999" means: enable if linked with a built library, but not when
502+
// linked with the OS libraries.
503+
// Note: this must not be changed to a "real" OS version.
504+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
493505
if (_COWChecksEnabled()) {
494506
return !_swift_isImmutableCOWBuffer(_storage)
495507
}

test/lit.cfg

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,13 @@ config.substitutions.append(('%raw-FileCheck', shell_quote(config.filecheck)))
21862186
config.substitutions.append(('%import-libdispatch', getattr(config, 'import_libdispatch', '')))
21872187
config.substitutions.append(('%import-static-libdispatch', getattr(config, 'import_libdispatch_static', '')))
21882188

2189+
# Disabe COW sanity checks in the swift runtime by default.
2190+
# (But it's required to set this environment variable to something)
2191+
config.environment['SWIFT_DEBUG_ENABLE_COW_CHECKS'] = 'false'
2192+
2193+
# Add this to the command which runs an executable to enable COW checks in the swift runtime.
2194+
config.substitutions.append(('%enable-cow-checking', TARGET_ENV_PREFIX + 'SWIFT_DEBUG_ENABLE_COW_CHECKS=true;'))
2195+
21892196
if config.lldb_build_root != "":
21902197
lldb_python_path = get_lldb_python_path(config.lldb_build_root)
21912198
lldb_python_interpreter = get_lldb_python_interpreter(config.lldb_build_root)
@@ -2210,9 +2217,6 @@ config.environment[TARGET_ENV_PREFIX + 'SWIFT_DETERMINISTIC_HASHING'] = '1'
22102217
# Enable malloc scribble during tests by default.
22112218
config.environment[TARGET_ENV_PREFIX + 'SWIFT_DEBUG_ENABLE_MALLOC_SCRIBBLE'] = 'YES'
22122219

2213-
# Enable COW sanity checks in the swift runtime by default.
2214-
config.environment['SWIFT_DEBUG_ENABLE_COW_CHECKS'] = 'true'
2215-
22162220
# Run lsb_release on the target to be tested and return the results.
22172221
def linux_get_lsb_release():
22182222
lsb_release_path = '/usr/bin/lsb_release'

0 commit comments

Comments
 (0)