From bb8d56683375160bdcc35d0ca7dcf06bb875bece Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 29 Sep 2025 11:56:14 -0700 Subject: [PATCH] Adopt `package` access modifier and get rid of gybbing --- CMakeLists.txt | 2 + Package.swift | 15 - Package@swift-6.0.swift | 15 - .../BitSet/BitSet._UnsafeHandle.swift | 18 +- .../CMakeLists.txt | 30 +- .../{Debugging.swift.gyb => Debugging.swift} | 13 +- ...criptions.swift.gyb => Descriptions.swift} | 28 +- ...xedWidthInteger+roundUpToPowerOfTwo.swift} | 13 +- ...eger rank.swift.gyb => Integer rank.swift} | 23 +- ....gyb => UInt+first and last set bit.swift} | 15 +- ...reversed.swift.gyb => UInt+reversed.swift} | 13 +- ...ixedWidthInteger+roundUpToPowerOfTwo.swift | 46 - .../autogenerated/Integer rank.swift | 304 ---- .../UInt+first and last set bit.swift | 54 - .../autogenerated/UInt+reversed.swift | 58 - ...rride.swift.gyb => LifetimeOverride.swift} | 17 +- ...b => RandomAccessCollection+Offsets.swift} | 17 +- ...ex.swift.gyb => _UnsafeBitSet+Index.swift} | 40 +- ...rd.swift.gyb => _UnsafeBitSet+_Word.swift} | 89 +- ...feBitSet.swift.gyb => _UnsafeBitSet.swift} | 117 +- .../autogenerated/_UnsafeBitSet+Index.swift | 184 --- .../autogenerated/_UnsafeBitSet+_Word.swift | 643 --------- .../autogenerated/_UnsafeBitSet.swift | 932 ------------ ...t.gyb => UnsafeBufferPointer+Extras.swift} | 17 +- ...> UnsafeMutableBufferPointer+Extras.swift} | 51 +- ...nsafeMutableRawBufferPointer+Extras.swift} | 11 +- ...yb => UnsafeRawBufferPointer+Extras.swift} | 12 +- .../autogenerated/Debugging.swift | 54 - .../autogenerated/Descriptions.swift | 140 -- .../autogenerated/LifetimeOverride.swift | 169 --- .../RandomAccessCollection+Offsets.swift | 58 - .../UnsafeBufferPointer+Extras.swift | 157 --- .../UnsafeMutableBufferPointer+Extras.swift | 580 -------- ...UnsafeMutableRawBufferPointer+Extras.swift | 45 - .../UnsafeRawBufferPointer+Extras.swift | 43 - Utils/README.md | 6 - Utils/generate-sources.sh | 62 - Utils/gyb | 3 - Utils/gyb.py | 1247 ----------------- Utils/gyb_utils.py | 34 - Xcode/Collections.xcconfig | 5 +- Xcode/Collections.xcodeproj/project.pbxproj | 206 +-- 42 files changed, 261 insertions(+), 5325 deletions(-) rename Sources/InternalCollectionsUtilities/{Debugging.swift.gyb => Debugging.swift} (73%) rename Sources/InternalCollectionsUtilities/{Descriptions.swift.gyb => Descriptions.swift} (61%) rename Sources/InternalCollectionsUtilities/IntegerTricks/{FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb => FixedWidthInteger+roundUpToPowerOfTwo.swift} (69%) rename Sources/InternalCollectionsUtilities/IntegerTricks/{Integer rank.swift.gyb => Integer rank.swift} (85%) rename Sources/InternalCollectionsUtilities/IntegerTricks/{UInt+first and last set bit.swift.gyb => UInt+first and last set bit.swift} (69%) rename Sources/InternalCollectionsUtilities/IntegerTricks/{UInt+reversed.swift.gyb => UInt+reversed.swift} (74%) delete mode 100644 Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/FixedWidthInteger+roundUpToPowerOfTwo.swift delete mode 100644 Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/Integer rank.swift delete mode 100644 Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/UInt+first and last set bit.swift delete mode 100644 Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/UInt+reversed.swift rename Sources/InternalCollectionsUtilities/{LifetimeOverride.swift.gyb => LifetimeOverride.swift} (88%) rename Sources/InternalCollectionsUtilities/{RandomAccessCollection+Offsets.swift.gyb => RandomAccessCollection+Offsets.swift} (62%) rename Sources/InternalCollectionsUtilities/UnsafeBitSet/{_UnsafeBitSet+Index.swift.gyb => _UnsafeBitSet+Index.swift} (62%) rename Sources/InternalCollectionsUtilities/UnsafeBitSet/{_UnsafeBitSet+_Word.swift.gyb => _UnsafeBitSet+_Word.swift} (73%) rename Sources/InternalCollectionsUtilities/UnsafeBitSet/{_UnsafeBitSet.swift.gyb => _UnsafeBitSet.swift} (75%) delete mode 100644 Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet+Index.swift delete mode 100644 Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet+_Word.swift delete mode 100644 Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet.swift rename Sources/InternalCollectionsUtilities/{UnsafeBufferPointer+Extras.swift.gyb => UnsafeBufferPointer+Extras.swift} (87%) rename Sources/InternalCollectionsUtilities/{UnsafeMutableBufferPointer+Extras.swift.gyb => UnsafeMutableBufferPointer+Extras.swift} (86%) rename Sources/InternalCollectionsUtilities/{UnsafeMutableRawBufferPointer+Extras.swift.gyb => UnsafeMutableRawBufferPointer+Extras.swift} (76%) rename Sources/InternalCollectionsUtilities/{UnsafeRawBufferPointer+Extras.swift.gyb => UnsafeRawBufferPointer+Extras.swift} (75%) delete mode 100644 Sources/InternalCollectionsUtilities/autogenerated/Debugging.swift delete mode 100644 Sources/InternalCollectionsUtilities/autogenerated/Descriptions.swift delete mode 100644 Sources/InternalCollectionsUtilities/autogenerated/LifetimeOverride.swift delete mode 100644 Sources/InternalCollectionsUtilities/autogenerated/RandomAccessCollection+Offsets.swift delete mode 100644 Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift delete mode 100644 Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift delete mode 100644 Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableRawBufferPointer+Extras.swift delete mode 100644 Sources/InternalCollectionsUtilities/autogenerated/UnsafeRawBufferPointer+Extras.swift delete mode 100755 Utils/generate-sources.sh delete mode 100755 Utils/gyb delete mode 100755 Utils/gyb.py delete mode 100644 Utils/gyb_utils.py diff --git a/CMakeLists.txt b/CMakeLists.txt index e9107233..ddd1bebb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,8 @@ foreach(def ${availability_defs}) add_compile_options("$<$:SHELL:-enable-experimental-feature \"AvailabilityMacro=${def}\">") endforeach() +add_compile_options("$<$:SHELL:-package-name swift-collections>") + add_subdirectory(Sources) # if(BUILD_TESTING) # add_subdirectory(Tests) diff --git a/Package.swift b/Package.swift index 1f0cbfc6..116633a1 100644 --- a/Package.swift +++ b/Package.swift @@ -209,21 +209,6 @@ let targets: [CustomTarget] = [ name: "InternalCollectionsUtilities", exclude: [ "CMakeLists.txt", - "Debugging.swift.gyb", - "Descriptions.swift.gyb", - "IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb", - "IntegerTricks/Integer rank.swift.gyb", - "IntegerTricks/UInt+first and last set bit.swift.gyb", - "IntegerTricks/UInt+reversed.swift.gyb", - "RandomAccessCollection+Offsets.swift.gyb", - "UnsafeBitSet/_UnsafeBitSet+Index.swift.gyb", - "UnsafeBitSet/_UnsafeBitSet+_Word.swift.gyb", - "UnsafeBitSet/_UnsafeBitSet.swift.gyb", - "UnsafeBufferPointer+Extras.swift.gyb", - "UnsafeMutableBufferPointer+Extras.swift.gyb", - "UnsafeRawBufferPointer+Extras.swift.gyb", - "UnsafeMutableRawBufferPointer+Extras.swift.gyb", - "LifetimeOverride.swift.gyb", ]), .target( diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift index 44eb7ae6..e04dc722 100644 --- a/Package@swift-6.0.swift +++ b/Package@swift-6.0.swift @@ -228,21 +228,6 @@ let targets: [CustomTarget] = [ name: "InternalCollectionsUtilities", exclude: [ "CMakeLists.txt", - "Debugging.swift.gyb", - "Descriptions.swift.gyb", - "IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb", - "IntegerTricks/Integer rank.swift.gyb", - "IntegerTricks/UInt+first and last set bit.swift.gyb", - "IntegerTricks/UInt+reversed.swift.gyb", - "RandomAccessCollection+Offsets.swift.gyb", - "UnsafeBitSet/_UnsafeBitSet+Index.swift.gyb", - "UnsafeBitSet/_UnsafeBitSet+_Word.swift.gyb", - "UnsafeBitSet/_UnsafeBitSet.swift.gyb", - "UnsafeBufferPointer+Extras.swift.gyb", - "UnsafeMutableBufferPointer+Extras.swift.gyb", - "UnsafeRawBufferPointer+Extras.swift.gyb", - "UnsafeMutableRawBufferPointer+Extras.swift.gyb", - "LifetimeOverride.swift.gyb", ]), .target( diff --git a/Sources/BitCollections/BitSet/BitSet._UnsafeHandle.swift b/Sources/BitCollections/BitSet/BitSet._UnsafeHandle.swift index cf6a1d3f..1c69f9eb 100644 --- a/Sources/BitCollections/BitSet/BitSet._UnsafeHandle.swift +++ b/Sources/BitCollections/BitSet/BitSet._UnsafeHandle.swift @@ -37,7 +37,7 @@ extension _UnsafeBitSet { extension _UnsafeBitSet { @inlinable - public mutating func combineSharedPrefix( + internal mutating func combineSharedPrefix( with other: Self, using function: (inout _Word, _Word) -> Void ) { @@ -51,7 +51,7 @@ extension _UnsafeBitSet { extension _UnsafeBitSet { @_effects(releasenone) - public mutating func formUnion(_ range: Range) { + internal mutating func formUnion(_ range: Range) { ensureMutable() let l = Index(range.lowerBound) let u = Index(range.upperBound) @@ -73,7 +73,7 @@ extension _UnsafeBitSet { } @_effects(releasenone) - public mutating func formIntersection(_ range: Range) { + internal mutating func formIntersection(_ range: Range) { ensureMutable() let l = Index(Swift.min(range.lowerBound, capacity)) let u = Index(Swift.min(range.upperBound, capacity)) @@ -98,7 +98,7 @@ extension _UnsafeBitSet { } @_effects(releasenone) - public mutating func formSymmetricDifference(_ range: Range) { + internal mutating func formSymmetricDifference(_ range: Range) { ensureMutable() let l = Index(range.lowerBound) let u = Index(range.upperBound) @@ -121,7 +121,7 @@ extension _UnsafeBitSet { } @_effects(releasenone) - public mutating func subtract(_ range: Range) { + internal mutating func subtract(_ range: Range) { ensureMutable() let l = Index(Swift.min(range.lowerBound, capacity)) let u = Index(Swift.min(range.upperBound, capacity)) @@ -141,7 +141,7 @@ extension _UnsafeBitSet { } @_effects(releasenone) - public func isDisjoint(with range: Range) -> Bool { + internal func isDisjoint(with range: Range) -> Bool { if self.isEmpty { return true } let lower = Index(Swift.min(range.lowerBound, capacity)) let upper = Index(Swift.min(range.upperBound, capacity)) @@ -167,7 +167,7 @@ extension _UnsafeBitSet { } @_effects(releasenone) - public func isSubset(of range: Range) -> Bool { + internal func isSubset(of range: Range) -> Bool { guard !range.isEmpty else { return isEmpty } guard !_words.isEmpty else { return true } let r = range.clamped(to: 0 ..< UInt(capacity)) @@ -193,7 +193,7 @@ extension _UnsafeBitSet { } @_effects(releasenone) - public func isSuperset(of range: Range) -> Bool { + internal func isSuperset(of range: Range) -> Bool { guard !range.isEmpty else { return true } let r = range.clamped(to: 0 ..< UInt(capacity)) guard r == range else { return false } @@ -218,7 +218,7 @@ extension _UnsafeBitSet { } @_effects(releasenone) - public func isEqualSet(to range: Range) -> Bool { + internal func isEqualSet(to range: Range) -> Bool { if range.isEmpty { return self.isEmpty } let r = range.clamped(to: 0 ..< UInt(capacity)) guard r == range else { return false } diff --git a/Sources/InternalCollectionsUtilities/CMakeLists.txt b/Sources/InternalCollectionsUtilities/CMakeLists.txt index b61f764d..c007ce1c 100644 --- a/Sources/InternalCollectionsUtilities/CMakeLists.txt +++ b/Sources/InternalCollectionsUtilities/CMakeLists.txt @@ -21,21 +21,21 @@ else() endif() target_sources(${module_name} PRIVATE - "autogenerated/Debugging.swift" - "autogenerated/Descriptions.swift" - "autogenerated/LifetimeOverride.swift" - "autogenerated/RandomAccessCollection+Offsets.swift" - "autogenerated/UnsafeBufferPointer+Extras.swift" - "autogenerated/UnsafeMutableBufferPointer+Extras.swift" - "autogenerated/UnsafeRawBufferPointer+Extras.swift" - "autogenerated/UnsafeMutableRawBufferPointer+Extras.swift" - "IntegerTricks/autogenerated/FixedWidthInteger+roundUpToPowerOfTwo.swift" - "IntegerTricks/autogenerated/Integer rank.swift" - "IntegerTricks/autogenerated/UInt+first and last set bit.swift" - "IntegerTricks/autogenerated/UInt+reversed.swift" - "UnsafeBitSet/autogenerated/_UnsafeBitSet+Index.swift" - "UnsafeBitSet/autogenerated/_UnsafeBitSet+_Word.swift" - "UnsafeBitSet/autogenerated/_UnsafeBitSet.swift" + "Debugging.swift" + "Descriptions.swift" + "LifetimeOverride.swift" + "RandomAccessCollection+Offsets.swift" + "UnsafeBufferPointer+Extras.swift" + "UnsafeMutableBufferPointer+Extras.swift" + "UnsafeRawBufferPointer+Extras.swift" + "UnsafeMutableRawBufferPointer+Extras.swift" + "IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift" + "IntegerTricks/Integer rank.swift" + "IntegerTricks/UInt+first and last set bit.swift" + "IntegerTricks/UInt+reversed.swift" + "UnsafeBitSet/_UnsafeBitSet+Index.swift" + "UnsafeBitSet/_UnsafeBitSet+_Word.swift" + "UnsafeBitSet/_UnsafeBitSet.swift" "_SortedCollection.swift" "_UniqueCollection.swift" ) diff --git a/Sources/InternalCollectionsUtilities/Debugging.swift.gyb b/Sources/InternalCollectionsUtilities/Debugging.swift similarity index 73% rename from Sources/InternalCollectionsUtilities/Debugging.swift.gyb rename to Sources/InternalCollectionsUtilities/Debugging.swift index 0771c41b..82e8c2ae 100644 --- a/Sources/InternalCollectionsUtilities/Debugging.swift.gyb +++ b/Sources/InternalCollectionsUtilities/Debugging.swift @@ -2,20 +2,13 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} /// True if consistency checking is enabled in the implementation of the /// Swift Collections package, false otherwise. /// @@ -23,12 +16,10 @@ ${visibility_boilerplate(modifier)} /// returns true -- for example, operations that are documented to take /// O(1) time might take O(*n*) time, or worse. @inlinable @inline(__always) -${modifier} var _isCollectionsInternalCheckingEnabled: Bool { +package var _isCollectionsInternalCheckingEnabled: Bool { #if COLLECTIONS_INTERNAL_CHECKS return true #else return false #endif } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/Descriptions.swift.gyb b/Sources/InternalCollectionsUtilities/Descriptions.swift similarity index 61% rename from Sources/InternalCollectionsUtilities/Descriptions.swift.gyb rename to Sources/InternalCollectionsUtilities/Descriptions.swift index eea428dd..7b151010 100644 --- a/Sources/InternalCollectionsUtilities/Descriptions.swift.gyb +++ b/Sources/InternalCollectionsUtilities/Descriptions.swift @@ -2,40 +2,32 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} - -${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } -${modifier} func _addressString(for pointer: UnsafeRawPointer) -> String { +@usableFromInline +package func _addressString(for pointer: UnsafeRawPointer) -> String { let address = UInt(bitPattern: pointer) return "0x\(String(address, radix: 16))" } -${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } -${modifier} func _addressString(for object: AnyObject) -> String { +@usableFromInline +package func _addressString(for object: AnyObject) -> String { _addressString(for: Unmanaged.passUnretained(object).toOpaque()) } -${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } -${modifier} func _addressString(for object: Unmanaged) -> String { +@usableFromInline +package func _addressString(for object: Unmanaged) -> String { _addressString(for: object.toOpaque()) } #if !$Embedded @inlinable -${modifier} func _arrayDescription( +package func _arrayDescription( for elements: C ) -> String { var result = "[" @@ -53,7 +45,7 @@ ${modifier} func _arrayDescription( } @inlinable -${modifier} func _dictionaryDescription( +package func _dictionaryDescription( for elements: C ) -> String where C.Element == (key: Key, value: Value) { guard !elements.isEmpty else { return "[:]" } @@ -73,5 +65,3 @@ ${modifier} func _dictionaryDescription( return result } #endif -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb b/Sources/InternalCollectionsUtilities/IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift similarity index 69% rename from Sources/InternalCollectionsUtilities/IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb rename to Sources/InternalCollectionsUtilities/IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift index 8c0e5e43..dc38cb86 100644 --- a/Sources/InternalCollectionsUtilities/IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb +++ b/Sources/InternalCollectionsUtilities/IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift @@ -2,29 +2,20 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension FixedWidthInteger { /// Round up `self` to the nearest power of two, assuming it's representable. /// Returns 0 if `self` isn't positive. @inlinable - ${modifier} func _roundUpToPowerOfTwo() -> Self { + package func _roundUpToPowerOfTwo() -> Self { guard self > 0 else { return 0 } let l = Self.bitWidth - (self &- 1).leadingZeroBitCount return 1 << l } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/IntegerTricks/Integer rank.swift.gyb b/Sources/InternalCollectionsUtilities/IntegerTricks/Integer rank.swift similarity index 85% rename from Sources/InternalCollectionsUtilities/IntegerTricks/Integer rank.swift.gyb rename to Sources/InternalCollectionsUtilities/IntegerTricks/Integer rank.swift index f0f77aaf..af950616 100644 --- a/Sources/InternalCollectionsUtilities/IntegerTricks/Integer rank.swift.gyb +++ b/Sources/InternalCollectionsUtilities/IntegerTricks/Integer rank.swift @@ -9,13 +9,6 @@ // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension FixedWidthInteger { @inlinable @inline(__always) internal var _nonzeroBitCount: Self { @@ -23,7 +16,7 @@ extension FixedWidthInteger { } @inlinable @inline(__always) - ${modifier} func _rank(ofBit bit: UInt) -> Int { + package func _rank(ofBit bit: UInt) -> Int { assert(bit < Self.bitWidth) let mask: Self = (1 &<< bit) &- 1 return (self & mask).nonzeroBitCount @@ -32,8 +25,8 @@ extension FixedWidthInteger { extension UInt { @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} func _bit(ranked n: Int) -> UInt? { + @usableFromInline + package func _bit(ranked n: Int) -> UInt? { // FIXME: Use bit deposit instruction when available (PDEP on Intel). assert(UInt.bitWidth == 64 || UInt.bitWidth == 32, "Unsupported UInt bitWidth") @@ -85,8 +78,8 @@ extension UInt32 { // Returns the position of the `n`th set bit in `self`, i.e., the bit with // rank `n`. @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} func _bit(ranked n: Int) -> UInt? { + @usableFromInline + package func _bit(ranked n: Int) -> UInt? { // FIXME: Use bit deposit instruction when available (PDEP on Intel). assert(n >= 0 && n < Self.bitWidth) var shift: Self = 0 @@ -125,8 +118,8 @@ extension UInt16 { // Returns the position of the `n`th set bit in `self`, i.e., the bit with // rank `n`. @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} func _bit(ranked n: Int) -> UInt? { + @usableFromInline + package func _bit(ranked n: Int) -> UInt? { // FIXME: Use bit deposit instruction when available (PDEP on Intel). assert(n >= 0 && n < Self.bitWidth) var shift: Self = 0 @@ -155,5 +148,3 @@ extension UInt16 { return UInt(truncatingIfNeeded: shift) } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/IntegerTricks/UInt+first and last set bit.swift.gyb b/Sources/InternalCollectionsUtilities/IntegerTricks/UInt+first and last set bit.swift similarity index 69% rename from Sources/InternalCollectionsUtilities/IntegerTricks/UInt+first and last set bit.swift.gyb rename to Sources/InternalCollectionsUtilities/IntegerTricks/UInt+first and last set bit.swift index 2f12f599..11a4cf2f 100644 --- a/Sources/InternalCollectionsUtilities/IntegerTricks/UInt+first and last set bit.swift.gyb +++ b/Sources/InternalCollectionsUtilities/IntegerTricks/UInt+first and last set bit.swift @@ -2,33 +2,24 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension UInt { @inlinable @inline(__always) - ${modifier} var _firstSetBit: UInt? { + package var _firstSetBit: UInt? { guard self != 0 else { return nil } let v = UInt.bitWidth &- 1 &- self.leadingZeroBitCount return UInt(truncatingIfNeeded: v) } @inlinable @inline(__always) - ${modifier} var _lastSetBit: UInt? { + package var _lastSetBit: UInt? { guard self != 0 else { return nil } return UInt(truncatingIfNeeded: self.trailingZeroBitCount) } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/IntegerTricks/UInt+reversed.swift.gyb b/Sources/InternalCollectionsUtilities/IntegerTricks/UInt+reversed.swift similarity index 74% rename from Sources/InternalCollectionsUtilities/IntegerTricks/UInt+reversed.swift.gyb rename to Sources/InternalCollectionsUtilities/IntegerTricks/UInt+reversed.swift index e4f18702..ed36cc7b 100644 --- a/Sources/InternalCollectionsUtilities/IntegerTricks/UInt+reversed.swift.gyb +++ b/Sources/InternalCollectionsUtilities/IntegerTricks/UInt+reversed.swift @@ -2,23 +2,16 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension UInt { @inlinable - ${modifier} var _reversed: UInt { + package var _reversed: UInt { // https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel var shift: UInt = UInt(UInt.bitWidth) var mask: UInt = ~0; @@ -32,5 +25,3 @@ extension UInt { return result } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/FixedWidthInteger+roundUpToPowerOfTwo.swift b/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/FixedWidthInteger+roundUpToPowerOfTwo.swift deleted file mode 100644 index 4f6fdb1e..00000000 --- a/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/FixedWidthInteger+roundUpToPowerOfTwo.swift +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension FixedWidthInteger { - /// Round up `self` to the nearest power of two, assuming it's representable. - /// Returns 0 if `self` isn't positive. - @inlinable - internal func _roundUpToPowerOfTwo() -> Self { - guard self > 0 else { return 0 } - let l = Self.bitWidth - (self &- 1).leadingZeroBitCount - return 1 << l - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension FixedWidthInteger { - /// Round up `self` to the nearest power of two, assuming it's representable. - /// Returns 0 if `self` isn't positive. - @inlinable - public func _roundUpToPowerOfTwo() -> Self { - guard self > 0 else { return 0 } - let l = Self.bitWidth - (self &- 1).leadingZeroBitCount - return 1 << l - } -} -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/Integer rank.swift b/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/Integer rank.swift deleted file mode 100644 index 1ef0f299..00000000 --- a/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/Integer rank.swift +++ /dev/null @@ -1,304 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension FixedWidthInteger { - @inlinable @inline(__always) - internal var _nonzeroBitCount: Self { - Self(truncatingIfNeeded: nonzeroBitCount) - } - - @inlinable @inline(__always) - internal func _rank(ofBit bit: UInt) -> Int { - assert(bit < Self.bitWidth) - let mask: Self = (1 &<< bit) &- 1 - return (self & mask).nonzeroBitCount - } -} - -extension UInt { - @_effects(releasenone) - @usableFromInline - internal func _bit(ranked n: Int) -> UInt? { - // FIXME: Use bit deposit instruction when available (PDEP on Intel). - assert(UInt.bitWidth == 64 || UInt.bitWidth == 32, - "Unsupported UInt bitWidth") - - var shift: Self = 0 - var n = Self(truncatingIfNeeded: n) - - if MemoryLayout.size == 8 { - let c32 = (self & 0xFFFFFFFF)._nonzeroBitCount - if n >= c32 { - shift &+= 32 - n &-= c32 - } - } else { - assert(MemoryLayout.size == 4, "Unknown platform") - } - - let c16 = ((self &>> shift) & 0xFFFF)._nonzeroBitCount - if n >= c16 { - shift &+= 16 - n &-= c16 - } - let c8 = ((self &>> shift) & 0xFF)._nonzeroBitCount - if n >= c8 { - shift &+= 8 - n &-= c8 - } - let c4 = ((self &>> shift) & 0xF)._nonzeroBitCount - if n >= c4 { - shift &+= 4 - n &-= c4 - } - let c2 = ((self &>> shift) & 0x3)._nonzeroBitCount - if n >= c2 { - shift &+= 2 - n &-= c2 - } - let c1 = (self &>> shift) & 0x1 - if n >= c1 { - shift &+= 1 - n &-= c1 - } - guard n == 0 && (self &>> shift) & 0x1 == 1 else { return nil } - return shift - } -} - -extension UInt32 { - // Returns the position of the `n`th set bit in `self`, i.e., the bit with - // rank `n`. - @_effects(releasenone) - @usableFromInline - internal func _bit(ranked n: Int) -> UInt? { - // FIXME: Use bit deposit instruction when available (PDEP on Intel). - assert(n >= 0 && n < Self.bitWidth) - var shift: Self = 0 - var n = Self(truncatingIfNeeded: n) - let c16 = (self & 0xFFFF)._nonzeroBitCount - if n >= c16 { - shift = 16 - n -= c16 - } - let c8 = ((self &>> shift) & 0xFF)._nonzeroBitCount - if n >= c8 { - shift &+= 8 - n -= c8 - } - let c4 = ((self &>> shift) & 0xF)._nonzeroBitCount - if n >= c4 { - shift &+= 4 - n -= c4 - } - let c2 = ((self &>> shift) & 0x3)._nonzeroBitCount - if n >= c2 { - shift &+= 2 - n -= c2 - } - let c1 = (self &>> shift) & 0x1 - if n >= c1 { - shift &+= 1 - n -= c1 - } - guard n == 0, (self &>> shift) & 0x1 == 1 else { return nil } - return UInt(truncatingIfNeeded: shift) - } -} - -extension UInt16 { - // Returns the position of the `n`th set bit in `self`, i.e., the bit with - // rank `n`. - @_effects(releasenone) - @usableFromInline - internal func _bit(ranked n: Int) -> UInt? { - // FIXME: Use bit deposit instruction when available (PDEP on Intel). - assert(n >= 0 && n < Self.bitWidth) - var shift: Self = 0 - var n = Self(truncatingIfNeeded: n) - let c8 = ((self &>> shift) & 0xFF)._nonzeroBitCount - if n >= c8 { - shift &+= 8 - n -= c8 - } - let c4 = ((self &>> shift) & 0xF)._nonzeroBitCount - if n >= c4 { - shift &+= 4 - n -= c4 - } - let c2 = ((self &>> shift) & 0x3)._nonzeroBitCount - if n >= c2 { - shift &+= 2 - n -= c2 - } - let c1 = (self &>> shift) & 0x1 - if n >= c1 { - shift &+= 1 - n -= c1 - } - guard n == 0, (self &>> shift) & 0x1 == 1 else { return nil } - return UInt(truncatingIfNeeded: shift) - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension FixedWidthInteger { - @inlinable @inline(__always) - internal var _nonzeroBitCount: Self { - Self(truncatingIfNeeded: nonzeroBitCount) - } - - @inlinable @inline(__always) - public func _rank(ofBit bit: UInt) -> Int { - assert(bit < Self.bitWidth) - let mask: Self = (1 &<< bit) &- 1 - return (self & mask).nonzeroBitCount - } -} - -extension UInt { - @_effects(releasenone) - //@usableFromInline - public func _bit(ranked n: Int) -> UInt? { - // FIXME: Use bit deposit instruction when available (PDEP on Intel). - assert(UInt.bitWidth == 64 || UInt.bitWidth == 32, - "Unsupported UInt bitWidth") - - var shift: Self = 0 - var n = Self(truncatingIfNeeded: n) - - if MemoryLayout.size == 8 { - let c32 = (self & 0xFFFFFFFF)._nonzeroBitCount - if n >= c32 { - shift &+= 32 - n &-= c32 - } - } else { - assert(MemoryLayout.size == 4, "Unknown platform") - } - - let c16 = ((self &>> shift) & 0xFFFF)._nonzeroBitCount - if n >= c16 { - shift &+= 16 - n &-= c16 - } - let c8 = ((self &>> shift) & 0xFF)._nonzeroBitCount - if n >= c8 { - shift &+= 8 - n &-= c8 - } - let c4 = ((self &>> shift) & 0xF)._nonzeroBitCount - if n >= c4 { - shift &+= 4 - n &-= c4 - } - let c2 = ((self &>> shift) & 0x3)._nonzeroBitCount - if n >= c2 { - shift &+= 2 - n &-= c2 - } - let c1 = (self &>> shift) & 0x1 - if n >= c1 { - shift &+= 1 - n &-= c1 - } - guard n == 0 && (self &>> shift) & 0x1 == 1 else { return nil } - return shift - } -} - -extension UInt32 { - // Returns the position of the `n`th set bit in `self`, i.e., the bit with - // rank `n`. - @_effects(releasenone) - //@usableFromInline - public func _bit(ranked n: Int) -> UInt? { - // FIXME: Use bit deposit instruction when available (PDEP on Intel). - assert(n >= 0 && n < Self.bitWidth) - var shift: Self = 0 - var n = Self(truncatingIfNeeded: n) - let c16 = (self & 0xFFFF)._nonzeroBitCount - if n >= c16 { - shift = 16 - n -= c16 - } - let c8 = ((self &>> shift) & 0xFF)._nonzeroBitCount - if n >= c8 { - shift &+= 8 - n -= c8 - } - let c4 = ((self &>> shift) & 0xF)._nonzeroBitCount - if n >= c4 { - shift &+= 4 - n -= c4 - } - let c2 = ((self &>> shift) & 0x3)._nonzeroBitCount - if n >= c2 { - shift &+= 2 - n -= c2 - } - let c1 = (self &>> shift) & 0x1 - if n >= c1 { - shift &+= 1 - n -= c1 - } - guard n == 0, (self &>> shift) & 0x1 == 1 else { return nil } - return UInt(truncatingIfNeeded: shift) - } -} - -extension UInt16 { - // Returns the position of the `n`th set bit in `self`, i.e., the bit with - // rank `n`. - @_effects(releasenone) - //@usableFromInline - public func _bit(ranked n: Int) -> UInt? { - // FIXME: Use bit deposit instruction when available (PDEP on Intel). - assert(n >= 0 && n < Self.bitWidth) - var shift: Self = 0 - var n = Self(truncatingIfNeeded: n) - let c8 = ((self &>> shift) & 0xFF)._nonzeroBitCount - if n >= c8 { - shift &+= 8 - n -= c8 - } - let c4 = ((self &>> shift) & 0xF)._nonzeroBitCount - if n >= c4 { - shift &+= 4 - n -= c4 - } - let c2 = ((self &>> shift) & 0x3)._nonzeroBitCount - if n >= c2 { - shift &+= 2 - n -= c2 - } - let c1 = (self &>> shift) & 0x1 - if n >= c1 { - shift &+= 1 - n -= c1 - } - guard n == 0, (self &>> shift) & 0x1 == 1 else { return nil } - return UInt(truncatingIfNeeded: shift) - } -} -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/UInt+first and last set bit.swift b/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/UInt+first and last set bit.swift deleted file mode 100644 index ae5ccb01..00000000 --- a/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/UInt+first and last set bit.swift +++ /dev/null @@ -1,54 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension UInt { - @inlinable @inline(__always) - internal var _firstSetBit: UInt? { - guard self != 0 else { return nil } - let v = UInt.bitWidth &- 1 &- self.leadingZeroBitCount - return UInt(truncatingIfNeeded: v) - } - - @inlinable @inline(__always) - internal var _lastSetBit: UInt? { - guard self != 0 else { return nil } - return UInt(truncatingIfNeeded: self.trailingZeroBitCount) - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension UInt { - @inlinable @inline(__always) - public var _firstSetBit: UInt? { - guard self != 0 else { return nil } - let v = UInt.bitWidth &- 1 &- self.leadingZeroBitCount - return UInt(truncatingIfNeeded: v) - } - - @inlinable @inline(__always) - public var _lastSetBit: UInt? { - guard self != 0 else { return nil } - return UInt(truncatingIfNeeded: self.trailingZeroBitCount) - } -} -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/UInt+reversed.swift b/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/UInt+reversed.swift deleted file mode 100644 index ac02ad29..00000000 --- a/Sources/InternalCollectionsUtilities/IntegerTricks/autogenerated/UInt+reversed.swift +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension UInt { - @inlinable - internal var _reversed: UInt { - // https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel - var shift: UInt = UInt(UInt.bitWidth) - var mask: UInt = ~0; - var result = self - while true { - shift &>>= 1 - guard shift > 0 else { break } - mask ^= mask &<< shift - result = ((result &>> shift) & mask) | ((result &<< shift) & ~mask) - } - return result - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension UInt { - @inlinable - public var _reversed: UInt { - // https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel - var shift: UInt = UInt(UInt.bitWidth) - var mask: UInt = ~0; - var result = self - while true { - shift &>>= 1 - guard shift > 0 else { break } - mask ^= mask &<< shift - result = ((result &>> shift) & mask) | ((result &<< shift) & ~mask) - } - return result - } -} -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/LifetimeOverride.swift.gyb b/Sources/InternalCollectionsUtilities/LifetimeOverride.swift similarity index 88% rename from Sources/InternalCollectionsUtilities/LifetimeOverride.swift.gyb rename to Sources/InternalCollectionsUtilities/LifetimeOverride.swift index fa8d6de6..beb8b140 100644 --- a/Sources/InternalCollectionsUtilities/LifetimeOverride.swift.gyb +++ b/Sources/InternalCollectionsUtilities/LifetimeOverride.swift @@ -10,14 +10,7 @@ // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - #if compiler(>=6.2) -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} /// Unsafely discard any lifetime dependency on the `dependent` argument. /// Return a value identical to `dependent` with an immortal lifetime. @unsafe @@ -25,7 +18,7 @@ ${visibility_boilerplate(modifier)} @_alwaysEmitIntoClient @_transparent @_lifetime(immortal) -${modifier} func _unsafeImmortalize( +package func _unsafeImmortalize( _ dependent: consuming T ) -> T { // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence @@ -41,7 +34,7 @@ ${modifier} func _unsafeImmortalize( @_alwaysEmitIntoClient @_transparent @_lifetime(borrow source) -${modifier} func _overrideLifetime< +package func _overrideLifetime< T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable >( _ dependent: consuming T, borrowing source: borrowing U @@ -59,7 +52,7 @@ ${modifier} func _overrideLifetime< @_alwaysEmitIntoClient @_transparent @_lifetime(copy source) -${modifier} func _overrideLifetime< +package func _overrideLifetime< T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable >( _ dependent: consuming T, copying source: borrowing U @@ -77,7 +70,7 @@ ${modifier} func _overrideLifetime< @_alwaysEmitIntoClient @_transparent @_lifetime(&source) -${modifier} func _overrideLifetime< +package func _overrideLifetime< T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable >( @@ -88,6 +81,4 @@ ${modifier} func _overrideLifetime< // should be expressed by a builtin that is hidden within the function body. dependent } -% end -${visibility_boilerplate("end")} #endif diff --git a/Sources/InternalCollectionsUtilities/RandomAccessCollection+Offsets.swift.gyb b/Sources/InternalCollectionsUtilities/RandomAccessCollection+Offsets.swift similarity index 62% rename from Sources/InternalCollectionsUtilities/RandomAccessCollection+Offsets.swift.gyb rename to Sources/InternalCollectionsUtilities/RandomAccessCollection+Offsets.swift index b9fef5be..9963643a 100644 --- a/Sources/InternalCollectionsUtilities/RandomAccessCollection+Offsets.swift.gyb +++ b/Sources/InternalCollectionsUtilities/RandomAccessCollection+Offsets.swift @@ -2,35 +2,26 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension RandomAccessCollection { @_alwaysEmitIntoClient @inline(__always) - ${modifier} func _index(at offset: Int) -> Index { + package func _index(at offset: Int) -> Index { index(startIndex, offsetBy: offset) } @_alwaysEmitIntoClient @inline(__always) - ${modifier} func _offset(of index: Index) -> Int { + package func _offset(of index: Index) -> Int { distance(from: startIndex, to: index) } @_alwaysEmitIntoClient @inline(__always) - ${modifier} subscript(_offset offset: Int) -> Element { + package subscript(_offset offset: Int) -> Element { self[_index(at: offset)] } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+Index.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+Index.swift similarity index 62% rename from Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+Index.swift.gyb rename to Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+Index.swift index f5770d6b..d0f1890f 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+Index.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+Index.swift @@ -2,41 +2,35 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension _UnsafeBitSet { - ${"@frozen" if modifier == "public" else "@frozen @usableFromInline"} - ${modifier} struct Index: Comparable, Hashable { + @frozen + @usableFromInline + package struct Index: Comparable, Hashable { @usableFromInline internal typealias _Word = _UnsafeBitSet._Word - ${"@usableFromInline" if modifier != "public" else ""} - ${modifier} var value: UInt + @usableFromInline + package var value: UInt @inlinable - ${modifier} init(_ value: UInt) { + package init(_ value: UInt) { self.value = value } @inlinable - ${modifier} init(_ value: Int) { + package init(_ value: Int) { self.value = UInt(value) } @inlinable - ${modifier} init(word: Int, bit: UInt) { + package init(word: Int, bit: UInt) { assert(word >= 0 && word <= Int.max / _Word.capacity) assert(bit < _Word.capacity) self.value = UInt(word &* _Word.capacity) &+ bit @@ -46,24 +40,24 @@ extension _UnsafeBitSet { extension _UnsafeBitSet.Index { @inlinable - ${modifier} var word: Int { + package var word: Int { // Note: We perform on UInts to get faster unsigned math (shifts). Int(truncatingIfNeeded: value / UInt(bitPattern: _Word.capacity)) } @inlinable - ${modifier} var bit: UInt { + package var bit: UInt { // Note: We perform on UInts to get faster unsigned math (masking). value % UInt(bitPattern: _Word.capacity) } @inlinable - ${modifier} var split: (word: Int, bit: UInt) { + package var split: (word: Int, bit: UInt) { (word, bit) } @inlinable - ${modifier} var endSplit: (word: Int, bit: UInt) { + package var endSplit: (word: Int, bit: UInt) { let w = word let b = bit if w > 0, b == 0 { return (w &- 1, UInt(_Word.capacity)) } @@ -71,17 +65,17 @@ extension _UnsafeBitSet.Index { } @inlinable - ${modifier} static func ==(left: Self, right: Self) -> Bool { + package static func ==(left: Self, right: Self) -> Bool { left.value == right.value } @inlinable - ${modifier} static func <(left: Self, right: Self) -> Bool { + package static func <(left: Self, right: Self) -> Bool { left.value < right.value } @inlinable - ${modifier} func hash(into hasher: inout Hasher) { + package func hash(into hasher: inout Hasher) { hasher.combine(value) } @@ -95,5 +89,3 @@ extension _UnsafeBitSet.Index { Self(value - 1) } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+_Word.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+_Word.swift similarity index 73% rename from Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+_Word.swift.gyb rename to Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+_Word.swift index bacd1199..f7bdfbe3 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+_Word.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet+_Word.swift @@ -2,43 +2,36 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension _UnsafeBitSet { - ${"@frozen" if modifier == "public" else "@frozen @usableFromInline"} - ${modifier} struct _Word { - ${"@usableFromInline" if modifier != "public" else ""} - ${modifier} var value: UInt + @frozen + @usableFromInline + package struct _Word { + @usableFromInline + package var value: UInt @inlinable @inline(__always) - ${modifier} init(_ value: UInt) { + package init(_ value: UInt) { self.value = value } @inlinable @inline(__always) - ${modifier} init(upTo bit: UInt) { + package init(upTo bit: UInt) { assert(bit <= _Word.capacity) self.init((1 << bit) &- 1) } @inlinable @inline(__always) - ${modifier} init(from start: UInt, to end: UInt) { + package init(from start: UInt, to end: UInt) { assert(start <= end && end <= _Word.capacity) self = Self(upTo: end).symmetricDifference(Self(upTo: start)) } @@ -46,8 +39,8 @@ extension _UnsafeBitSet { } extension _UnsafeBitSet._Word: CustomStringConvertible { - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} var description: String { + @usableFromInline + package var description: String { String(value, radix: 16) } } @@ -89,7 +82,7 @@ extension _UnsafeBitSet._Word { extension _UnsafeBitSet._Word { @inlinable @inline(__always) - ${modifier} static func wordCount(forBitCount count: UInt) -> Int { + package static func wordCount(forBitCount count: UInt) -> Int { // Note: We perform on UInts to get faster unsigned math (shifts). let width = UInt(bitPattern: Self.capacity) return Int(bitPattern: (count + width - 1) / width) @@ -99,51 +92,51 @@ extension _UnsafeBitSet._Word { extension _UnsafeBitSet._Word { @inlinable @inline(__always) - ${modifier} static var capacity: Int { + package static var capacity: Int { return UInt.bitWidth } @inlinable @inline(__always) - ${modifier} var count: Int { + package var count: Int { value.nonzeroBitCount } @inlinable @inline(__always) - ${modifier} var isEmpty: Bool { + package var isEmpty: Bool { value == 0 } @inlinable @inline(__always) - ${modifier} var isFull: Bool { + package var isFull: Bool { value == UInt.max } @inlinable @inline(__always) - ${modifier} func contains(_ bit: UInt) -> Bool { + package func contains(_ bit: UInt) -> Bool { assert(bit >= 0 && bit < UInt.bitWidth) return value & (1 &<< bit) != 0 } @inlinable @inline(__always) - ${modifier} var firstMember: UInt? { + package var firstMember: UInt? { value._lastSetBit } @inlinable @inline(__always) - ${modifier} var lastMember: UInt? { + package var lastMember: UInt? { value._firstSetBit } @inlinable @inline(__always) @discardableResult - ${modifier} mutating func insert(_ bit: UInt) -> Bool { + package mutating func insert(_ bit: UInt) -> Bool { assert(bit < UInt.bitWidth) let mask: UInt = 1 &<< bit let inserted = value & mask == 0 @@ -154,7 +147,7 @@ extension _UnsafeBitSet._Word { @inlinable @inline(__always) @discardableResult - ${modifier} mutating func remove(_ bit: UInt) -> Bool { + package mutating func remove(_ bit: UInt) -> Bool { assert(bit < UInt.bitWidth) let mask: UInt = 1 &<< bit let removed = (value & mask) != 0 @@ -164,7 +157,7 @@ extension _UnsafeBitSet._Word { @inlinable @inline(__always) - ${modifier} mutating func update(_ bit: UInt, to value: Bool) { + package mutating func update(_ bit: UInt, to value: Bool) { assert(bit < UInt.bitWidth) let mask: UInt = 1 &<< bit if value { @@ -213,12 +206,12 @@ extension _UnsafeBitSet._Word { extension _UnsafeBitSet._Word { @inlinable @inline(__always) - ${modifier} static var empty: Self { + package static var empty: Self { Self(0) } @inline(__always) - ${modifier} static var allBits: Self { + package static var allBits: Self { Self(UInt.max) } } @@ -229,14 +222,14 @@ extension _UnsafeBitSet._Word { // iterator, not the original word. extension _UnsafeBitSet._Word: Sequence, IteratorProtocol { @inlinable @inline(__always) - ${modifier} var underestimatedCount: Int { + package var underestimatedCount: Int { count } /// Return the index of the lowest set bit in this word, /// and also destructively clear it. @inlinable - ${modifier} mutating func next() -> UInt? { + package mutating func next() -> UInt? { guard value != 0 else { return nil } let bit = UInt(truncatingIfNeeded: value.trailingZeroBitCount) value &= value &- 1 // Clear lowest nonzero bit. @@ -246,66 +239,66 @@ extension _UnsafeBitSet._Word: Sequence, IteratorProtocol { extension _UnsafeBitSet._Word: Equatable { @inlinable - ${modifier} static func ==(left: Self, right: Self) -> Bool { + package static func ==(left: Self, right: Self) -> Bool { left.value == right.value } } extension _UnsafeBitSet._Word: Hashable { @inlinable - ${modifier} func hash(into hasher: inout Hasher) { + package func hash(into hasher: inout Hasher) { hasher.combine(value) } } extension _UnsafeBitSet._Word { @inlinable @inline(__always) - ${modifier} func complement() -> Self { + package func complement() -> Self { Self(~self.value) } @inlinable @inline(__always) - ${modifier} mutating func formComplement() { + package mutating func formComplement() { self.value = ~self.value } @inlinable @inline(__always) - ${modifier} func union(_ other: Self) -> Self { + package func union(_ other: Self) -> Self { Self(self.value | other.value) } @inlinable @inline(__always) - ${modifier} mutating func formUnion(_ other: Self) { + package mutating func formUnion(_ other: Self) { self.value |= other.value } @inlinable @inline(__always) - ${modifier} func intersection(_ other: Self) -> Self { + package func intersection(_ other: Self) -> Self { Self(self.value & other.value) } @inlinable @inline(__always) - ${modifier} mutating func formIntersection(_ other: Self) { + package mutating func formIntersection(_ other: Self) { self.value &= other.value } @inlinable @inline(__always) - ${modifier} func symmetricDifference(_ other: Self) -> Self { + package func symmetricDifference(_ other: Self) -> Self { Self(self.value ^ other.value) } @inlinable @inline(__always) - ${modifier} mutating func formSymmetricDifference(_ other: Self) { + package mutating func formSymmetricDifference(_ other: Self) { self.value ^= other.value } @inlinable @inline(__always) - ${modifier} func subtracting(_ other: Self) -> Self { + package func subtracting(_ other: Self) -> Self { Self(self.value & ~other.value) } @inlinable @inline(__always) - ${modifier} mutating func subtract(_ other: Self) { + package mutating func subtract(_ other: Self) { self.value &= ~other.value } } @@ -313,17 +306,15 @@ extension _UnsafeBitSet._Word { extension _UnsafeBitSet._Word { @inlinable @inline(__always) - ${modifier} func shiftedDown(by shift: UInt) -> Self { + package func shiftedDown(by shift: UInt) -> Self { assert(shift >= 0 && shift < Self.capacity) return Self(self.value &>> shift) } @inlinable @inline(__always) - ${modifier} func shiftedUp(by shift: UInt) -> Self { + package func shiftedUp(by shift: UInt) -> Self { assert(shift >= 0 && shift < Self.capacity) return Self(self.value &<< shift) } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift similarity index 75% rename from Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift.gyb rename to Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift index 108b3c62..5fc44ca9 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift @@ -2,27 +2,21 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} /// An unsafe-unowned bitset view over `UInt` storage, providing bit set /// primitives. -${"@frozen" if modifier == "public" else "@frozen @usableFromInline"} -${modifier} struct _UnsafeBitSet { +@frozen +@usableFromInline +package struct _UnsafeBitSet { /// An unsafe-unowned storage view. - ${"@usableFromInline" if modifier != "public" else ""} - ${modifier} let _words: UnsafeBufferPointer<_Word> + @usableFromInline + package let _words: UnsafeBufferPointer<_Word> #if DEBUG /// True when this handle does not support table mutations. @@ -33,7 +27,7 @@ ${modifier} struct _UnsafeBitSet { @inlinable @inline(__always) - ${modifier} func ensureMutable() { + package func ensureMutable() { #if DEBUG assert(_mutable) #endif @@ -41,14 +35,14 @@ ${modifier} struct _UnsafeBitSet { @inlinable @inline(__always) - ${modifier} var _mutableWords: UnsafeMutableBufferPointer<_Word> { + package var _mutableWords: UnsafeMutableBufferPointer<_Word> { ensureMutable() return UnsafeMutableBufferPointer(mutating: _words) } @inlinable @inline(__always) - ${modifier} init( + package init( words: UnsafeBufferPointer<_Word>, mutable: Bool ) { @@ -61,7 +55,7 @@ ${modifier} struct _UnsafeBitSet { @inlinable @inline(__always) - ${modifier} init( + package init( words: UnsafeMutableBufferPointer<_Word>, mutable: Bool ) { @@ -72,7 +66,7 @@ ${modifier} struct _UnsafeBitSet { extension _UnsafeBitSet { @inlinable @inline(__always) - ${modifier} var wordCount: Int { + package var wordCount: Int { _words.count } } @@ -80,7 +74,7 @@ extension _UnsafeBitSet { extension _UnsafeBitSet { @inlinable @inline(__always) - ${modifier} static func withTemporaryBitSet( + package static func withTemporaryBitSet( capacity: Int, run body: (inout _UnsafeBitSet) throws -> R ) rethrows -> R { @@ -90,7 +84,7 @@ extension _UnsafeBitSet { @inlinable @inline(__always) - ${modifier} static func withTemporaryBitSet( + package static func withTemporaryBitSet( wordCount: Int, run body: (inout Self) throws -> R ) rethrows -> R { @@ -130,12 +124,12 @@ extension _UnsafeBitSet { extension _UnsafeBitSet { @_effects(readnone) @inlinable @inline(__always) - ${modifier} static func wordCount(forCapacity capacity: UInt) -> Int { + package static func wordCount(forCapacity capacity: UInt) -> Int { _Word.wordCount(forBitCount: capacity) } @inlinable @inline(__always) - ${modifier} var capacity: UInt { + package var capacity: UInt { UInt(wordCount &* _Word.capacity) } @@ -146,17 +140,17 @@ extension _UnsafeBitSet { @_effects(releasenone) @inline(__always) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} func contains(_ element: UInt) -> Bool { + @usableFromInline + package func contains(_ element: UInt) -> Bool { let (word, bit) = Index(element).split guard word < wordCount else { return false } return _words[word].contains(bit) } @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } + @usableFromInline @discardableResult - ${modifier} mutating func insert(_ element: UInt) -> Bool { + package mutating func insert(_ element: UInt) -> Bool { ensureMutable() assert(isWithinBounds(element)) let index = Index(element) @@ -164,9 +158,9 @@ extension _UnsafeBitSet { } @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } + @usableFromInline @discardableResult - ${modifier} mutating func remove(_ element: UInt) -> Bool { + package mutating func remove(_ element: UInt) -> Bool { ensureMutable() let index = Index(element) if index.word >= _words.count { return false } @@ -174,8 +168,8 @@ extension _UnsafeBitSet { } @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} mutating func update(_ member: UInt, to newValue: Bool) -> Bool { + @usableFromInline + package mutating func update(_ member: UInt, to newValue: Bool) -> Bool { ensureMutable() let (w, b) = Index(member).split _mutableWords[w].update(b, to: newValue) @@ -183,8 +177,8 @@ extension _UnsafeBitSet { } @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} mutating func insertAll(upTo max: UInt) { + @usableFromInline + package mutating func insertAll(upTo max: UInt) { assert(max <= capacity) guard max > 0 else { return } let (w, b) = Index(max).split @@ -197,50 +191,51 @@ extension _UnsafeBitSet { } @_alwaysEmitIntoClient - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } + @usableFromInline @inline(__always) @discardableResult - ${modifier} mutating func insert(_ element: Int) -> Bool { + package mutating func insert(_ element: Int) -> Bool { precondition(element >= 0) return insert(UInt(bitPattern: element)) } @_alwaysEmitIntoClient - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } + @usableFromInline @inline(__always) @discardableResult - ${modifier} mutating func remove(_ element: Int) -> Bool { + package mutating func remove(_ element: Int) -> Bool { guard element >= 0 else { return false } return remove(UInt(bitPattern: element)) } @_alwaysEmitIntoClient - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } + @usableFromInline @inline(__always) - ${modifier} mutating func insertAll(upTo max: Int) { + package mutating func insertAll(upTo max: Int) { precondition(max >= 0) return insertAll(upTo: UInt(bitPattern: max)) } } extension _UnsafeBitSet: Sequence { - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} typealias Element = UInt + @usableFromInline + package typealias Element = UInt @inlinable @inline(__always) - ${modifier} var underestimatedCount: Int { + package var underestimatedCount: Int { count // FIXME: really? } @inlinable @inline(__always) - ${modifier} func makeIterator() -> Iterator { + package func makeIterator() -> Iterator { return Iterator(self) } - ${"@frozen" if modifier == "public" else "@usableFromInline @frozen"} - ${modifier} struct Iterator: IteratorProtocol { + @frozen + @usableFromInline + package struct Iterator: IteratorProtocol { @usableFromInline internal let _bitset: _UnsafeBitSet @@ -258,8 +253,8 @@ extension _UnsafeBitSet: Sequence { } @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} mutating func next() -> UInt? { + @usableFromInline + package mutating func next() -> UInt? { if let bit = _word.next() { return Index(word: _index, bit: bit).value } @@ -278,36 +273,36 @@ extension _UnsafeBitSet: Sequence { extension _UnsafeBitSet: BidirectionalCollection { @inlinable @inline(__always) - ${modifier} var count: Int { + package var count: Int { _words.reduce(0) { $0 + $1.count } } @inlinable @inline(__always) - ${modifier} var isEmpty: Bool { + package var isEmpty: Bool { _words.firstIndex(where: { !$0.isEmpty }) == nil } @inlinable - ${modifier} var startIndex: Index { + package var startIndex: Index { let word = _words.firstIndex { !$0.isEmpty } guard let word = word else { return endIndex } return Index(word: word, bit: _words[word].firstMember!) } @inlinable - ${modifier} var endIndex: Index { + package var endIndex: Index { Index(word: wordCount, bit: 0) } @inlinable - ${modifier} subscript(position: Index) -> UInt { + package subscript(position: Index) -> UInt { position.value } @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} func index(after index: Index) -> Index { + @usableFromInline + package func index(after index: Index) -> Index { precondition(index < endIndex, "Index out of bounds") var word = index.word var w = _words[word] @@ -323,8 +318,8 @@ extension _UnsafeBitSet: BidirectionalCollection { } @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} func index(before index: Index) -> Index { + @usableFromInline + package func index(before index: Index) -> Index { precondition(index <= endIndex, "Index out of bounds") var word = index.word var w: _Word @@ -343,8 +338,8 @@ extension _UnsafeBitSet: BidirectionalCollection { } @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} func distance(from start: Index, to end: Index) -> Int { + @usableFromInline + package func distance(from start: Index, to end: Index) -> Int { precondition(start <= endIndex && end <= endIndex, "Index out of bounds") let isNegative = end < start let (start, end) = (Swift.min(start, end), Swift.max(start, end)) @@ -375,8 +370,8 @@ extension _UnsafeBitSet: BidirectionalCollection { } @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} func index(_ i: Index, offsetBy distance: Int) -> Index { + @usableFromInline + package func index(_ i: Index, offsetBy distance: Int) -> Index { precondition(i <= endIndex, "Index out of bounds") precondition(i == endIndex || contains(i.value), "Invalid index") guard distance != 0 else { return i } @@ -416,8 +411,8 @@ extension _UnsafeBitSet: BidirectionalCollection { } @_effects(releasenone) - ${"@usableFromInline" if modifier != "public" else "//@usableFromInline" } - ${modifier} func index( + @usableFromInline + package func index( _ i: Index, offsetBy distance: Int, limitedBy limit: Index ) -> Index? { precondition(i <= endIndex && limit <= endIndex, "Index out of bounds") @@ -469,5 +464,3 @@ extension _UnsafeBitSet: BidirectionalCollection { return nil } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet+Index.swift b/Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet+Index.swift deleted file mode 100644 index f2d2b9d5..00000000 --- a/Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet+Index.swift +++ /dev/null @@ -1,184 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension _UnsafeBitSet { - @frozen @usableFromInline - internal struct Index: Comparable, Hashable { - @usableFromInline - internal typealias _Word = _UnsafeBitSet._Word - - @usableFromInline - internal var value: UInt - - @inlinable - internal init(_ value: UInt) { - self.value = value - } - - @inlinable - internal init(_ value: Int) { - self.value = UInt(value) - } - - @inlinable - internal init(word: Int, bit: UInt) { - assert(word >= 0 && word <= Int.max / _Word.capacity) - assert(bit < _Word.capacity) - self.value = UInt(word &* _Word.capacity) &+ bit - } - } -} - -extension _UnsafeBitSet.Index { - @inlinable - internal var word: Int { - // Note: We perform on UInts to get faster unsigned math (shifts). - Int(truncatingIfNeeded: value / UInt(bitPattern: _Word.capacity)) - } - - @inlinable - internal var bit: UInt { - // Note: We perform on UInts to get faster unsigned math (masking). - value % UInt(bitPattern: _Word.capacity) - } - - @inlinable - internal var split: (word: Int, bit: UInt) { - (word, bit) - } - - @inlinable - internal var endSplit: (word: Int, bit: UInt) { - let w = word - let b = bit - if w > 0, b == 0 { return (w &- 1, UInt(_Word.capacity)) } - return (w, b) - } - - @inlinable - internal static func ==(left: Self, right: Self) -> Bool { - left.value == right.value - } - - @inlinable - internal static func <(left: Self, right: Self) -> Bool { - left.value < right.value - } - - @inlinable - internal func hash(into hasher: inout Hasher) { - hasher.combine(value) - } - - @inlinable - internal func _successor() -> Self { - Self(value + 1) - } - - @inlinable - internal func _predecessor() -> Self { - Self(value - 1) - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension _UnsafeBitSet { - @frozen - public struct Index: Comparable, Hashable { - @usableFromInline - internal typealias _Word = _UnsafeBitSet._Word - - - public var value: UInt - - @inlinable - public init(_ value: UInt) { - self.value = value - } - - @inlinable - public init(_ value: Int) { - self.value = UInt(value) - } - - @inlinable - public init(word: Int, bit: UInt) { - assert(word >= 0 && word <= Int.max / _Word.capacity) - assert(bit < _Word.capacity) - self.value = UInt(word &* _Word.capacity) &+ bit - } - } -} - -extension _UnsafeBitSet.Index { - @inlinable - public var word: Int { - // Note: We perform on UInts to get faster unsigned math (shifts). - Int(truncatingIfNeeded: value / UInt(bitPattern: _Word.capacity)) - } - - @inlinable - public var bit: UInt { - // Note: We perform on UInts to get faster unsigned math (masking). - value % UInt(bitPattern: _Word.capacity) - } - - @inlinable - public var split: (word: Int, bit: UInt) { - (word, bit) - } - - @inlinable - public var endSplit: (word: Int, bit: UInt) { - let w = word - let b = bit - if w > 0, b == 0 { return (w &- 1, UInt(_Word.capacity)) } - return (w, b) - } - - @inlinable - public static func ==(left: Self, right: Self) -> Bool { - left.value == right.value - } - - @inlinable - public static func <(left: Self, right: Self) -> Bool { - left.value < right.value - } - - @inlinable - public func hash(into hasher: inout Hasher) { - hasher.combine(value) - } - - @inlinable - internal func _successor() -> Self { - Self(value + 1) - } - - @inlinable - internal func _predecessor() -> Self { - Self(value - 1) - } -} -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet+_Word.swift b/Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet+_Word.swift deleted file mode 100644 index 586e872e..00000000 --- a/Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet+_Word.swift +++ /dev/null @@ -1,643 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension _UnsafeBitSet { - @frozen @usableFromInline - internal struct _Word { - @usableFromInline - internal var value: UInt - - @inlinable - @inline(__always) - internal init(_ value: UInt) { - self.value = value - } - - @inlinable - @inline(__always) - internal init(upTo bit: UInt) { - assert(bit <= _Word.capacity) - self.init((1 << bit) &- 1) - } - - @inlinable - @inline(__always) - internal init(from start: UInt, to end: UInt) { - assert(start <= end && end <= _Word.capacity) - self = Self(upTo: end).symmetricDifference(Self(upTo: start)) - } - } -} - -extension _UnsafeBitSet._Word: CustomStringConvertible { - @usableFromInline - internal var description: String { - String(value, radix: 16) - } -} - -extension _UnsafeBitSet._Word { - /// Returns the `n`th member in `self`. - /// - /// - Parameter n: The offset of the element to retrieve. This value is - /// decremented by the number of items found in this `self` towards the - /// value we're looking for. (If the function returns non-nil, then `n` - /// is set to `0` on return.) - /// - Returns: If this word contains enough members to satisfy the request, - /// then this function returns the member found. Otherwise it returns nil. - @inline(never) - internal func nthElement(_ n: inout UInt) -> UInt? { - let c = UInt(bitPattern: count) - guard n < c else { - n &-= c - return nil - } - let m = Int(bitPattern: n) - n = 0 - return value._bit(ranked: m)! - } - - @inline(never) - internal func nthElementFromEnd(_ n: inout UInt) -> UInt? { - let c = UInt(bitPattern: count) - guard n < c else { - n &-= c - return nil - } - let m = Int(bitPattern: c &- 1 &- n) - n = 0 - return value._bit(ranked: m)! - } -} - -extension _UnsafeBitSet._Word { - @inlinable - @inline(__always) - internal static func wordCount(forBitCount count: UInt) -> Int { - // Note: We perform on UInts to get faster unsigned math (shifts). - let width = UInt(bitPattern: Self.capacity) - return Int(bitPattern: (count + width - 1) / width) - } -} - -extension _UnsafeBitSet._Word { - @inlinable - @inline(__always) - internal static var capacity: Int { - return UInt.bitWidth - } - - @inlinable - @inline(__always) - internal var count: Int { - value.nonzeroBitCount - } - - @inlinable - @inline(__always) - internal var isEmpty: Bool { - value == 0 - } - - @inlinable - @inline(__always) - internal var isFull: Bool { - value == UInt.max - } - - @inlinable - @inline(__always) - internal func contains(_ bit: UInt) -> Bool { - assert(bit >= 0 && bit < UInt.bitWidth) - return value & (1 &<< bit) != 0 - } - - @inlinable - @inline(__always) - internal var firstMember: UInt? { - value._lastSetBit - } - - @inlinable - @inline(__always) - internal var lastMember: UInt? { - value._firstSetBit - } - - @inlinable - @inline(__always) - @discardableResult - internal mutating func insert(_ bit: UInt) -> Bool { - assert(bit < UInt.bitWidth) - let mask: UInt = 1 &<< bit - let inserted = value & mask == 0 - value |= mask - return inserted - } - - @inlinable - @inline(__always) - @discardableResult - internal mutating func remove(_ bit: UInt) -> Bool { - assert(bit < UInt.bitWidth) - let mask: UInt = 1 &<< bit - let removed = (value & mask) != 0 - value &= ~mask - return removed - } - - @inlinable - @inline(__always) - internal mutating func update(_ bit: UInt, to value: Bool) { - assert(bit < UInt.bitWidth) - let mask: UInt = 1 &<< bit - if value { - self.value |= mask - } else { - self.value &= ~mask - } - } -} - -extension _UnsafeBitSet._Word { - @inlinable - @inline(__always) - internal mutating func insertAll(upTo bit: UInt) { - assert(bit >= 0 && bit < Self.capacity) - let mask: UInt = (1 as UInt &<< bit) &- 1 - value |= mask - } - - @inlinable - @inline(__always) - internal mutating func removeAll(upTo bit: UInt) { - assert(bit >= 0 && bit < Self.capacity) - let mask = UInt.max &<< bit - value &= mask - } - - @inlinable - @inline(__always) - internal mutating func removeAll(through bit: UInt) { - assert(bit >= 0 && bit < Self.capacity) - var mask = UInt.max &<< bit - mask &= mask &- 1 // Clear lowest nonzero bit. - value &= mask - } - - @inlinable - @inline(__always) - internal mutating func removeAll(from bit: UInt) { - assert(bit >= 0 && bit < Self.capacity) - let mask: UInt = (1 as UInt &<< bit) &- 1 - value &= mask - } -} - -extension _UnsafeBitSet._Word { - @inlinable - @inline(__always) - internal static var empty: Self { - Self(0) - } - - @inline(__always) - internal static var allBits: Self { - Self(UInt.max) - } -} - -// _Word implements Sequence by using a copy of itself as its Iterator. -// Iteration with `next()` destroys the word's value; however, this won't cause -// problems in normal use, because `next()` is usually called on a separate -// iterator, not the original word. -extension _UnsafeBitSet._Word: Sequence, IteratorProtocol { - @inlinable @inline(__always) - internal var underestimatedCount: Int { - count - } - - /// Return the index of the lowest set bit in this word, - /// and also destructively clear it. - @inlinable - internal mutating func next() -> UInt? { - guard value != 0 else { return nil } - let bit = UInt(truncatingIfNeeded: value.trailingZeroBitCount) - value &= value &- 1 // Clear lowest nonzero bit. - return bit - } -} - -extension _UnsafeBitSet._Word: Equatable { - @inlinable - internal static func ==(left: Self, right: Self) -> Bool { - left.value == right.value - } -} - -extension _UnsafeBitSet._Word: Hashable { - @inlinable - internal func hash(into hasher: inout Hasher) { - hasher.combine(value) - } -} - -extension _UnsafeBitSet._Word { - @inlinable @inline(__always) - internal func complement() -> Self { - Self(~self.value) - } - - @inlinable @inline(__always) - internal mutating func formComplement() { - self.value = ~self.value - } - - @inlinable @inline(__always) - internal func union(_ other: Self) -> Self { - Self(self.value | other.value) - } - - @inlinable @inline(__always) - internal mutating func formUnion(_ other: Self) { - self.value |= other.value - } - - @inlinable @inline(__always) - internal func intersection(_ other: Self) -> Self { - Self(self.value & other.value) - } - - @inlinable @inline(__always) - internal mutating func formIntersection(_ other: Self) { - self.value &= other.value - } - - @inlinable @inline(__always) - internal func symmetricDifference(_ other: Self) -> Self { - Self(self.value ^ other.value) - } - - @inlinable @inline(__always) - internal mutating func formSymmetricDifference(_ other: Self) { - self.value ^= other.value - } - - @inlinable @inline(__always) - internal func subtracting(_ other: Self) -> Self { - Self(self.value & ~other.value) - } - - @inlinable @inline(__always) - internal mutating func subtract(_ other: Self) { - self.value &= ~other.value - } -} - -extension _UnsafeBitSet._Word { - @inlinable - @inline(__always) - internal func shiftedDown(by shift: UInt) -> Self { - assert(shift >= 0 && shift < Self.capacity) - return Self(self.value &>> shift) - } - - @inlinable - @inline(__always) - internal func shiftedUp(by shift: UInt) -> Self { - assert(shift >= 0 && shift < Self.capacity) - return Self(self.value &<< shift) - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension _UnsafeBitSet { - @frozen - public struct _Word { - - public var value: UInt - - @inlinable - @inline(__always) - public init(_ value: UInt) { - self.value = value - } - - @inlinable - @inline(__always) - public init(upTo bit: UInt) { - assert(bit <= _Word.capacity) - self.init((1 << bit) &- 1) - } - - @inlinable - @inline(__always) - public init(from start: UInt, to end: UInt) { - assert(start <= end && end <= _Word.capacity) - self = Self(upTo: end).symmetricDifference(Self(upTo: start)) - } - } -} - -extension _UnsafeBitSet._Word: CustomStringConvertible { - //@usableFromInline - public var description: String { - String(value, radix: 16) - } -} - -extension _UnsafeBitSet._Word { - /// Returns the `n`th member in `self`. - /// - /// - Parameter n: The offset of the element to retrieve. This value is - /// decremented by the number of items found in this `self` towards the - /// value we're looking for. (If the function returns non-nil, then `n` - /// is set to `0` on return.) - /// - Returns: If this word contains enough members to satisfy the request, - /// then this function returns the member found. Otherwise it returns nil. - @inline(never) - internal func nthElement(_ n: inout UInt) -> UInt? { - let c = UInt(bitPattern: count) - guard n < c else { - n &-= c - return nil - } - let m = Int(bitPattern: n) - n = 0 - return value._bit(ranked: m)! - } - - @inline(never) - internal func nthElementFromEnd(_ n: inout UInt) -> UInt? { - let c = UInt(bitPattern: count) - guard n < c else { - n &-= c - return nil - } - let m = Int(bitPattern: c &- 1 &- n) - n = 0 - return value._bit(ranked: m)! - } -} - -extension _UnsafeBitSet._Word { - @inlinable - @inline(__always) - public static func wordCount(forBitCount count: UInt) -> Int { - // Note: We perform on UInts to get faster unsigned math (shifts). - let width = UInt(bitPattern: Self.capacity) - return Int(bitPattern: (count + width - 1) / width) - } -} - -extension _UnsafeBitSet._Word { - @inlinable - @inline(__always) - public static var capacity: Int { - return UInt.bitWidth - } - - @inlinable - @inline(__always) - public var count: Int { - value.nonzeroBitCount - } - - @inlinable - @inline(__always) - public var isEmpty: Bool { - value == 0 - } - - @inlinable - @inline(__always) - public var isFull: Bool { - value == UInt.max - } - - @inlinable - @inline(__always) - public func contains(_ bit: UInt) -> Bool { - assert(bit >= 0 && bit < UInt.bitWidth) - return value & (1 &<< bit) != 0 - } - - @inlinable - @inline(__always) - public var firstMember: UInt? { - value._lastSetBit - } - - @inlinable - @inline(__always) - public var lastMember: UInt? { - value._firstSetBit - } - - @inlinable - @inline(__always) - @discardableResult - public mutating func insert(_ bit: UInt) -> Bool { - assert(bit < UInt.bitWidth) - let mask: UInt = 1 &<< bit - let inserted = value & mask == 0 - value |= mask - return inserted - } - - @inlinable - @inline(__always) - @discardableResult - public mutating func remove(_ bit: UInt) -> Bool { - assert(bit < UInt.bitWidth) - let mask: UInt = 1 &<< bit - let removed = (value & mask) != 0 - value &= ~mask - return removed - } - - @inlinable - @inline(__always) - public mutating func update(_ bit: UInt, to value: Bool) { - assert(bit < UInt.bitWidth) - let mask: UInt = 1 &<< bit - if value { - self.value |= mask - } else { - self.value &= ~mask - } - } -} - -extension _UnsafeBitSet._Word { - @inlinable - @inline(__always) - internal mutating func insertAll(upTo bit: UInt) { - assert(bit >= 0 && bit < Self.capacity) - let mask: UInt = (1 as UInt &<< bit) &- 1 - value |= mask - } - - @inlinable - @inline(__always) - internal mutating func removeAll(upTo bit: UInt) { - assert(bit >= 0 && bit < Self.capacity) - let mask = UInt.max &<< bit - value &= mask - } - - @inlinable - @inline(__always) - internal mutating func removeAll(through bit: UInt) { - assert(bit >= 0 && bit < Self.capacity) - var mask = UInt.max &<< bit - mask &= mask &- 1 // Clear lowest nonzero bit. - value &= mask - } - - @inlinable - @inline(__always) - internal mutating func removeAll(from bit: UInt) { - assert(bit >= 0 && bit < Self.capacity) - let mask: UInt = (1 as UInt &<< bit) &- 1 - value &= mask - } -} - -extension _UnsafeBitSet._Word { - @inlinable - @inline(__always) - public static var empty: Self { - Self(0) - } - - @inline(__always) - public static var allBits: Self { - Self(UInt.max) - } -} - -// _Word implements Sequence by using a copy of itself as its Iterator. -// Iteration with `next()` destroys the word's value; however, this won't cause -// problems in normal use, because `next()` is usually called on a separate -// iterator, not the original word. -extension _UnsafeBitSet._Word: Sequence, IteratorProtocol { - @inlinable @inline(__always) - public var underestimatedCount: Int { - count - } - - /// Return the index of the lowest set bit in this word, - /// and also destructively clear it. - @inlinable - public mutating func next() -> UInt? { - guard value != 0 else { return nil } - let bit = UInt(truncatingIfNeeded: value.trailingZeroBitCount) - value &= value &- 1 // Clear lowest nonzero bit. - return bit - } -} - -extension _UnsafeBitSet._Word: Equatable { - @inlinable - public static func ==(left: Self, right: Self) -> Bool { - left.value == right.value - } -} - -extension _UnsafeBitSet._Word: Hashable { - @inlinable - public func hash(into hasher: inout Hasher) { - hasher.combine(value) - } -} - -extension _UnsafeBitSet._Word { - @inlinable @inline(__always) - public func complement() -> Self { - Self(~self.value) - } - - @inlinable @inline(__always) - public mutating func formComplement() { - self.value = ~self.value - } - - @inlinable @inline(__always) - public func union(_ other: Self) -> Self { - Self(self.value | other.value) - } - - @inlinable @inline(__always) - public mutating func formUnion(_ other: Self) { - self.value |= other.value - } - - @inlinable @inline(__always) - public func intersection(_ other: Self) -> Self { - Self(self.value & other.value) - } - - @inlinable @inline(__always) - public mutating func formIntersection(_ other: Self) { - self.value &= other.value - } - - @inlinable @inline(__always) - public func symmetricDifference(_ other: Self) -> Self { - Self(self.value ^ other.value) - } - - @inlinable @inline(__always) - public mutating func formSymmetricDifference(_ other: Self) { - self.value ^= other.value - } - - @inlinable @inline(__always) - public func subtracting(_ other: Self) -> Self { - Self(self.value & ~other.value) - } - - @inlinable @inline(__always) - public mutating func subtract(_ other: Self) { - self.value &= ~other.value - } -} - -extension _UnsafeBitSet._Word { - @inlinable - @inline(__always) - public func shiftedDown(by shift: UInt) -> Self { - assert(shift >= 0 && shift < Self.capacity) - return Self(self.value &>> shift) - } - - @inlinable - @inline(__always) - public func shiftedUp(by shift: UInt) -> Self { - assert(shift >= 0 && shift < Self.capacity) - return Self(self.value &<< shift) - } -} -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet.swift b/Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet.swift deleted file mode 100644 index 6da0c4ef..00000000 --- a/Sources/InternalCollectionsUtilities/UnsafeBitSet/autogenerated/_UnsafeBitSet.swift +++ /dev/null @@ -1,932 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -/// An unsafe-unowned bitset view over `UInt` storage, providing bit set -/// primitives. -@frozen @usableFromInline -internal struct _UnsafeBitSet { - /// An unsafe-unowned storage view. - @usableFromInline - internal let _words: UnsafeBufferPointer<_Word> - -#if DEBUG - /// True when this handle does not support table mutations. - /// (This is only checked in debug builds.) - @usableFromInline - internal let _mutable: Bool -#endif - - @inlinable - @inline(__always) - internal func ensureMutable() { -#if DEBUG - assert(_mutable) -#endif - } - - @inlinable - @inline(__always) - internal var _mutableWords: UnsafeMutableBufferPointer<_Word> { - ensureMutable() - return UnsafeMutableBufferPointer(mutating: _words) - } - - @inlinable - @inline(__always) - internal init( - words: UnsafeBufferPointer<_Word>, - mutable: Bool - ) { - assert(words.baseAddress != nil) - self._words = words -#if DEBUG - self._mutable = mutable -#endif - } - - @inlinable - @inline(__always) - internal init( - words: UnsafeMutableBufferPointer<_Word>, - mutable: Bool - ) { - self.init(words: UnsafeBufferPointer(words), mutable: mutable) - } -} - -extension _UnsafeBitSet { - @inlinable - @inline(__always) - internal var wordCount: Int { - _words.count - } -} - -extension _UnsafeBitSet { - @inlinable - @inline(__always) - internal static func withTemporaryBitSet( - capacity: Int, - run body: (inout _UnsafeBitSet) throws -> R - ) rethrows -> R { - let wordCount = _UnsafeBitSet.wordCount(forCapacity: UInt(capacity)) - return try withTemporaryBitSet(wordCount: wordCount, run: body) - } - - @inlinable - @inline(__always) - internal static func withTemporaryBitSet( - wordCount: Int, - run body: (inout Self) throws -> R - ) rethrows -> R { - var result: R? - try _withTemporaryBitSet(wordCount: wordCount) { bitset in - result = try body(&bitset) - } - return result! - } - - @inline(never) - @usableFromInline - internal static func _withTemporaryBitSet( - wordCount: Int, - run body: (inout Self) throws -> Void - ) rethrows { - try _withTemporaryUninitializedBitSet(wordCount: wordCount) { handle in - handle._mutableWords.initialize(repeating: .empty) - try body(&handle) - } - } - - internal static func _withTemporaryUninitializedBitSet( - wordCount: Int, - run body: (inout Self) throws -> Void - ) rethrows { - assert(wordCount >= 0) - return try withUnsafeTemporaryAllocation( - of: _Word.self, capacity: wordCount - ) { words in - var bitset = Self(words: words, mutable: true) - return try body(&bitset) - } - } -} - -extension _UnsafeBitSet { - @_effects(readnone) - @inlinable @inline(__always) - internal static func wordCount(forCapacity capacity: UInt) -> Int { - _Word.wordCount(forBitCount: capacity) - } - - @inlinable @inline(__always) - internal var capacity: UInt { - UInt(wordCount &* _Word.capacity) - } - - @inlinable @inline(__always) - internal func isWithinBounds(_ element: UInt) -> Bool { - element < capacity - } - - @_effects(releasenone) - @inline(__always) - @usableFromInline - internal func contains(_ element: UInt) -> Bool { - let (word, bit) = Index(element).split - guard word < wordCount else { return false } - return _words[word].contains(bit) - } - - @_effects(releasenone) - @usableFromInline - @discardableResult - internal mutating func insert(_ element: UInt) -> Bool { - ensureMutable() - assert(isWithinBounds(element)) - let index = Index(element) - return _mutableWords[index.word].insert(index.bit) - } - - @_effects(releasenone) - @usableFromInline - @discardableResult - internal mutating func remove(_ element: UInt) -> Bool { - ensureMutable() - let index = Index(element) - if index.word >= _words.count { return false } - return _mutableWords[index.word].remove(index.bit) - } - - @_effects(releasenone) - @usableFromInline - internal mutating func update(_ member: UInt, to newValue: Bool) -> Bool { - ensureMutable() - let (w, b) = Index(member).split - _mutableWords[w].update(b, to: newValue) - return w == _words.count &- 1 - } - - @_effects(releasenone) - @usableFromInline - internal mutating func insertAll(upTo max: UInt) { - assert(max <= capacity) - guard max > 0 else { return } - let (w, b) = Index(max).split - for i in 0 ..< w { - _mutableWords[i] = .allBits - } - if b > 0 { - _mutableWords[w].insertAll(upTo: b) - } - } - - @_alwaysEmitIntoClient - @usableFromInline - @inline(__always) - @discardableResult - internal mutating func insert(_ element: Int) -> Bool { - precondition(element >= 0) - return insert(UInt(bitPattern: element)) - } - - @_alwaysEmitIntoClient - @usableFromInline - @inline(__always) - @discardableResult - internal mutating func remove(_ element: Int) -> Bool { - guard element >= 0 else { return false } - return remove(UInt(bitPattern: element)) - } - - @_alwaysEmitIntoClient - @usableFromInline - @inline(__always) - internal mutating func insertAll(upTo max: Int) { - precondition(max >= 0) - return insertAll(upTo: UInt(bitPattern: max)) - } -} - -extension _UnsafeBitSet: Sequence { - @usableFromInline - internal typealias Element = UInt - - @inlinable - @inline(__always) - internal var underestimatedCount: Int { - count // FIXME: really? - } - - @inlinable - @inline(__always) - internal func makeIterator() -> Iterator { - return Iterator(self) - } - - @usableFromInline @frozen - internal struct Iterator: IteratorProtocol { - @usableFromInline - internal let _bitset: _UnsafeBitSet - - @usableFromInline - internal var _index: Int - - @usableFromInline - internal var _word: _Word - - @inlinable - internal init(_ bitset: _UnsafeBitSet) { - self._bitset = bitset - self._index = 0 - self._word = bitset.wordCount > 0 ? bitset._words[0] : .empty - } - - @_effects(releasenone) - @usableFromInline - internal mutating func next() -> UInt? { - if let bit = _word.next() { - return Index(word: _index, bit: bit).value - } - while (_index + 1) < _bitset.wordCount { - _index += 1 - _word = _bitset._words[_index] - if let bit = _word.next() { - return Index(word: _index, bit: bit).value - } - } - return nil - } - } -} - -extension _UnsafeBitSet: BidirectionalCollection { - @inlinable - @inline(__always) - internal var count: Int { - _words.reduce(0) { $0 + $1.count } - } - - @inlinable - @inline(__always) - internal var isEmpty: Bool { - _words.firstIndex(where: { !$0.isEmpty }) == nil - } - - @inlinable - internal var startIndex: Index { - let word = _words.firstIndex { !$0.isEmpty } - guard let word = word else { return endIndex } - return Index(word: word, bit: _words[word].firstMember!) - } - - @inlinable - internal var endIndex: Index { - Index(word: wordCount, bit: 0) - } - - @inlinable - internal subscript(position: Index) -> UInt { - position.value - } - - @_effects(releasenone) - @usableFromInline - internal func index(after index: Index) -> Index { - precondition(index < endIndex, "Index out of bounds") - var word = index.word - var w = _words[word] - w.removeAll(through: index.bit) - while w.isEmpty { - word += 1 - guard word < wordCount else { - return Index(word: wordCount, bit: 0) - } - w = _words[word] - } - return Index(word: word, bit: w.firstMember!) - } - - @_effects(releasenone) - @usableFromInline - internal func index(before index: Index) -> Index { - precondition(index <= endIndex, "Index out of bounds") - var word = index.word - var w: _Word - if index.bit > 0 { - w = _words[word] - w.removeAll(from: index.bit) - } else { - w = .empty - } - while w.isEmpty { - word -= 1 - precondition(word >= 0, "Can't advance below startIndex") - w = _words[word] - } - return Index(word: word, bit: w.lastMember!) - } - - @_effects(releasenone) - @usableFromInline - internal func distance(from start: Index, to end: Index) -> Int { - precondition(start <= endIndex && end <= endIndex, "Index out of bounds") - let isNegative = end < start - let (start, end) = (Swift.min(start, end), Swift.max(start, end)) - - let (w1, b1) = start.split - let (w2, b2) = end.split - - if w1 == w2 { - guard w1 < wordCount else { return 0 } - let mask = _Word(from: b1, to: b2) - let c = _words[w1].intersection(mask).count - return isNegative ? -c : c - } - - var c = 0 - var w = w1 - guard w < wordCount else { return 0 } - - c &+= _words[w].subtracting(_Word(upTo: b1)).count - w &+= 1 - while w < w2 { - c &+= _words[w].count - w &+= 1 - } - guard w < wordCount else { return isNegative ? -c : c } - c &+= _words[w].intersection(_Word(upTo: b2)).count - return isNegative ? -c : c - } - - @_effects(releasenone) - @usableFromInline - internal func index(_ i: Index, offsetBy distance: Int) -> Index { - precondition(i <= endIndex, "Index out of bounds") - precondition(i == endIndex || contains(i.value), "Invalid index") - guard distance != 0 else { return i } - var remaining = distance.magnitude - if distance > 0 { - var (w, b) = i.split - precondition(w < wordCount, "Index out of bounds") - if let v = _words[w].subtracting(_Word(upTo: b)).nthElement(&remaining) { - return Index(word: w, bit: v) - } - while true { - w &+= 1 - guard w < wordCount else { break } - if let v = _words[w].nthElement(&remaining) { - return Index(word: w, bit: v) - } - } - precondition(remaining == 0, "Index out of bounds") - return endIndex - } - - // distance < 0 - remaining -= 1 - var (w, b) = i.endSplit - if w < wordCount { - if let v = _words[w].intersection(_Word(upTo: b)).nthElementFromEnd(&remaining) { - return Index(word: w, bit: v) - } - } - while true { - precondition(w > 0, "Index out of bounds") - w &-= 1 - if let v = _words[w].nthElementFromEnd(&remaining) { - return Index(word: w, bit: v) - } - } - } - - @_effects(releasenone) - @usableFromInline - internal func index( - _ i: Index, offsetBy distance: Int, limitedBy limit: Index - ) -> Index? { - precondition(i <= endIndex && limit <= endIndex, "Index out of bounds") - precondition(i == endIndex || contains(i.value), "Invalid index") - guard distance != 0 else { return i } - var remaining = distance.magnitude - if distance > 0 { - guard i <= limit else { - return self.index(i, offsetBy: distance) - } - var (w, b) = i.split - if w < wordCount, - let v = _words[w].subtracting(_Word(upTo: b)).nthElement(&remaining) - { - let r = Index(word: w, bit: v) - return r <= limit ? r : nil - } - let maxWord = Swift.min(wordCount - 1, limit.word) - while w < maxWord { - w &+= 1 - if let v = _words[w].nthElement(&remaining) { - let r = Index(word: w, bit: v) - return r <= limit ? r : nil - } - } - return remaining == 0 && limit == endIndex ? endIndex : nil - } - - // distance < 0 - guard i >= limit else { - return self.index(i, offsetBy: distance) - } - remaining &-= 1 - var (w, b) = i.endSplit - if w < wordCount { - if let v = _words[w].intersection(_Word(upTo: b)).nthElementFromEnd(&remaining) { - let r = Index(word: w, bit: v) - return r >= limit ? r : nil - } - } - let minWord = limit.word - while w > minWord { - w &-= 1 - if let v = _words[w].nthElementFromEnd(&remaining) { - let r = Index(word: w, bit: v) - return r >= limit ? r : nil - } - } - return nil - } -} -#else // !COLLECTIONS_SINGLE_MODULE -/// An unsafe-unowned bitset view over `UInt` storage, providing bit set -/// primitives. -@frozen -public struct _UnsafeBitSet { - /// An unsafe-unowned storage view. - - public let _words: UnsafeBufferPointer<_Word> - -#if DEBUG - /// True when this handle does not support table mutations. - /// (This is only checked in debug builds.) - @usableFromInline - internal let _mutable: Bool -#endif - - @inlinable - @inline(__always) - public func ensureMutable() { -#if DEBUG - assert(_mutable) -#endif - } - - @inlinable - @inline(__always) - public var _mutableWords: UnsafeMutableBufferPointer<_Word> { - ensureMutable() - return UnsafeMutableBufferPointer(mutating: _words) - } - - @inlinable - @inline(__always) - public init( - words: UnsafeBufferPointer<_Word>, - mutable: Bool - ) { - assert(words.baseAddress != nil) - self._words = words -#if DEBUG - self._mutable = mutable -#endif - } - - @inlinable - @inline(__always) - public init( - words: UnsafeMutableBufferPointer<_Word>, - mutable: Bool - ) { - self.init(words: UnsafeBufferPointer(words), mutable: mutable) - } -} - -extension _UnsafeBitSet { - @inlinable - @inline(__always) - public var wordCount: Int { - _words.count - } -} - -extension _UnsafeBitSet { - @inlinable - @inline(__always) - public static func withTemporaryBitSet( - capacity: Int, - run body: (inout _UnsafeBitSet) throws -> R - ) rethrows -> R { - let wordCount = _UnsafeBitSet.wordCount(forCapacity: UInt(capacity)) - return try withTemporaryBitSet(wordCount: wordCount, run: body) - } - - @inlinable - @inline(__always) - public static func withTemporaryBitSet( - wordCount: Int, - run body: (inout Self) throws -> R - ) rethrows -> R { - var result: R? - try _withTemporaryBitSet(wordCount: wordCount) { bitset in - result = try body(&bitset) - } - return result! - } - - @inline(never) - @usableFromInline - internal static func _withTemporaryBitSet( - wordCount: Int, - run body: (inout Self) throws -> Void - ) rethrows { - try _withTemporaryUninitializedBitSet(wordCount: wordCount) { handle in - handle._mutableWords.initialize(repeating: .empty) - try body(&handle) - } - } - - internal static func _withTemporaryUninitializedBitSet( - wordCount: Int, - run body: (inout Self) throws -> Void - ) rethrows { - assert(wordCount >= 0) - return try withUnsafeTemporaryAllocation( - of: _Word.self, capacity: wordCount - ) { words in - var bitset = Self(words: words, mutable: true) - return try body(&bitset) - } - } -} - -extension _UnsafeBitSet { - @_effects(readnone) - @inlinable @inline(__always) - public static func wordCount(forCapacity capacity: UInt) -> Int { - _Word.wordCount(forBitCount: capacity) - } - - @inlinable @inline(__always) - public var capacity: UInt { - UInt(wordCount &* _Word.capacity) - } - - @inlinable @inline(__always) - internal func isWithinBounds(_ element: UInt) -> Bool { - element < capacity - } - - @_effects(releasenone) - @inline(__always) - //@usableFromInline - public func contains(_ element: UInt) -> Bool { - let (word, bit) = Index(element).split - guard word < wordCount else { return false } - return _words[word].contains(bit) - } - - @_effects(releasenone) - //@usableFromInline - @discardableResult - public mutating func insert(_ element: UInt) -> Bool { - ensureMutable() - assert(isWithinBounds(element)) - let index = Index(element) - return _mutableWords[index.word].insert(index.bit) - } - - @_effects(releasenone) - //@usableFromInline - @discardableResult - public mutating func remove(_ element: UInt) -> Bool { - ensureMutable() - let index = Index(element) - if index.word >= _words.count { return false } - return _mutableWords[index.word].remove(index.bit) - } - - @_effects(releasenone) - //@usableFromInline - public mutating func update(_ member: UInt, to newValue: Bool) -> Bool { - ensureMutable() - let (w, b) = Index(member).split - _mutableWords[w].update(b, to: newValue) - return w == _words.count &- 1 - } - - @_effects(releasenone) - //@usableFromInline - public mutating func insertAll(upTo max: UInt) { - assert(max <= capacity) - guard max > 0 else { return } - let (w, b) = Index(max).split - for i in 0 ..< w { - _mutableWords[i] = .allBits - } - if b > 0 { - _mutableWords[w].insertAll(upTo: b) - } - } - - @_alwaysEmitIntoClient - //@usableFromInline - @inline(__always) - @discardableResult - public mutating func insert(_ element: Int) -> Bool { - precondition(element >= 0) - return insert(UInt(bitPattern: element)) - } - - @_alwaysEmitIntoClient - //@usableFromInline - @inline(__always) - @discardableResult - public mutating func remove(_ element: Int) -> Bool { - guard element >= 0 else { return false } - return remove(UInt(bitPattern: element)) - } - - @_alwaysEmitIntoClient - //@usableFromInline - @inline(__always) - public mutating func insertAll(upTo max: Int) { - precondition(max >= 0) - return insertAll(upTo: UInt(bitPattern: max)) - } -} - -extension _UnsafeBitSet: Sequence { - //@usableFromInline - public typealias Element = UInt - - @inlinable - @inline(__always) - public var underestimatedCount: Int { - count // FIXME: really? - } - - @inlinable - @inline(__always) - public func makeIterator() -> Iterator { - return Iterator(self) - } - - @frozen - public struct Iterator: IteratorProtocol { - @usableFromInline - internal let _bitset: _UnsafeBitSet - - @usableFromInline - internal var _index: Int - - @usableFromInline - internal var _word: _Word - - @inlinable - internal init(_ bitset: _UnsafeBitSet) { - self._bitset = bitset - self._index = 0 - self._word = bitset.wordCount > 0 ? bitset._words[0] : .empty - } - - @_effects(releasenone) - //@usableFromInline - public mutating func next() -> UInt? { - if let bit = _word.next() { - return Index(word: _index, bit: bit).value - } - while (_index + 1) < _bitset.wordCount { - _index += 1 - _word = _bitset._words[_index] - if let bit = _word.next() { - return Index(word: _index, bit: bit).value - } - } - return nil - } - } -} - -extension _UnsafeBitSet: BidirectionalCollection { - @inlinable - @inline(__always) - public var count: Int { - _words.reduce(0) { $0 + $1.count } - } - - @inlinable - @inline(__always) - public var isEmpty: Bool { - _words.firstIndex(where: { !$0.isEmpty }) == nil - } - - @inlinable - public var startIndex: Index { - let word = _words.firstIndex { !$0.isEmpty } - guard let word = word else { return endIndex } - return Index(word: word, bit: _words[word].firstMember!) - } - - @inlinable - public var endIndex: Index { - Index(word: wordCount, bit: 0) - } - - @inlinable - public subscript(position: Index) -> UInt { - position.value - } - - @_effects(releasenone) - //@usableFromInline - public func index(after index: Index) -> Index { - precondition(index < endIndex, "Index out of bounds") - var word = index.word - var w = _words[word] - w.removeAll(through: index.bit) - while w.isEmpty { - word += 1 - guard word < wordCount else { - return Index(word: wordCount, bit: 0) - } - w = _words[word] - } - return Index(word: word, bit: w.firstMember!) - } - - @_effects(releasenone) - //@usableFromInline - public func index(before index: Index) -> Index { - precondition(index <= endIndex, "Index out of bounds") - var word = index.word - var w: _Word - if index.bit > 0 { - w = _words[word] - w.removeAll(from: index.bit) - } else { - w = .empty - } - while w.isEmpty { - word -= 1 - precondition(word >= 0, "Can't advance below startIndex") - w = _words[word] - } - return Index(word: word, bit: w.lastMember!) - } - - @_effects(releasenone) - //@usableFromInline - public func distance(from start: Index, to end: Index) -> Int { - precondition(start <= endIndex && end <= endIndex, "Index out of bounds") - let isNegative = end < start - let (start, end) = (Swift.min(start, end), Swift.max(start, end)) - - let (w1, b1) = start.split - let (w2, b2) = end.split - - if w1 == w2 { - guard w1 < wordCount else { return 0 } - let mask = _Word(from: b1, to: b2) - let c = _words[w1].intersection(mask).count - return isNegative ? -c : c - } - - var c = 0 - var w = w1 - guard w < wordCount else { return 0 } - - c &+= _words[w].subtracting(_Word(upTo: b1)).count - w &+= 1 - while w < w2 { - c &+= _words[w].count - w &+= 1 - } - guard w < wordCount else { return isNegative ? -c : c } - c &+= _words[w].intersection(_Word(upTo: b2)).count - return isNegative ? -c : c - } - - @_effects(releasenone) - //@usableFromInline - public func index(_ i: Index, offsetBy distance: Int) -> Index { - precondition(i <= endIndex, "Index out of bounds") - precondition(i == endIndex || contains(i.value), "Invalid index") - guard distance != 0 else { return i } - var remaining = distance.magnitude - if distance > 0 { - var (w, b) = i.split - precondition(w < wordCount, "Index out of bounds") - if let v = _words[w].subtracting(_Word(upTo: b)).nthElement(&remaining) { - return Index(word: w, bit: v) - } - while true { - w &+= 1 - guard w < wordCount else { break } - if let v = _words[w].nthElement(&remaining) { - return Index(word: w, bit: v) - } - } - precondition(remaining == 0, "Index out of bounds") - return endIndex - } - - // distance < 0 - remaining -= 1 - var (w, b) = i.endSplit - if w < wordCount { - if let v = _words[w].intersection(_Word(upTo: b)).nthElementFromEnd(&remaining) { - return Index(word: w, bit: v) - } - } - while true { - precondition(w > 0, "Index out of bounds") - w &-= 1 - if let v = _words[w].nthElementFromEnd(&remaining) { - return Index(word: w, bit: v) - } - } - } - - @_effects(releasenone) - //@usableFromInline - public func index( - _ i: Index, offsetBy distance: Int, limitedBy limit: Index - ) -> Index? { - precondition(i <= endIndex && limit <= endIndex, "Index out of bounds") - precondition(i == endIndex || contains(i.value), "Invalid index") - guard distance != 0 else { return i } - var remaining = distance.magnitude - if distance > 0 { - guard i <= limit else { - return self.index(i, offsetBy: distance) - } - var (w, b) = i.split - if w < wordCount, - let v = _words[w].subtracting(_Word(upTo: b)).nthElement(&remaining) - { - let r = Index(word: w, bit: v) - return r <= limit ? r : nil - } - let maxWord = Swift.min(wordCount - 1, limit.word) - while w < maxWord { - w &+= 1 - if let v = _words[w].nthElement(&remaining) { - let r = Index(word: w, bit: v) - return r <= limit ? r : nil - } - } - return remaining == 0 && limit == endIndex ? endIndex : nil - } - - // distance < 0 - guard i >= limit else { - return self.index(i, offsetBy: distance) - } - remaining &-= 1 - var (w, b) = i.endSplit - if w < wordCount { - if let v = _words[w].intersection(_Word(upTo: b)).nthElementFromEnd(&remaining) { - let r = Index(word: w, bit: v) - return r >= limit ? r : nil - } - } - let minWord = limit.word - while w > minWord { - w &-= 1 - if let v = _words[w].nthElementFromEnd(&remaining) { - let r = Index(word: w, bit: v) - return r >= limit ? r : nil - } - } - return nil - } -} -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift similarity index 87% rename from Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb rename to Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift index ff993060..5cc4116a 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift @@ -9,17 +9,10 @@ // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension UnsafeBufferPointer { @inlinable @inline(__always) - ${modifier} func _ptr(at index: Int) -> UnsafePointer { + package func _ptr(at index: Int) -> UnsafePointer { assert(index >= 0 && index < count) return baseAddress.unsafelyUnwrapped + index } @@ -29,7 +22,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { /// Returns a Boolean value indicating whether two `UnsafeBufferPointer` /// instances refer to the same region in memory. @inlinable @inline(__always) - ${modifier} func _isIdentical(to other: Self) -> Bool { + package func _isIdentical(to other: Self) -> Bool { (self.baseAddress == other.baseAddress) && (self.count == other.count) } } @@ -52,7 +45,7 @@ extension UnsafeBufferPointer where Element: ~Copyable { /// - Complexity: O(1) @_alwaysEmitIntoClient @inline(__always) - public func _extracting(first maxLength: Int) -> Self { + package func _extracting(first maxLength: Int) -> Self { precondition(maxLength >= 0, "Can't have a prefix of negative length") let newCount = Swift.min(maxLength, count) return Self(start: baseAddress, count: newCount) @@ -75,12 +68,10 @@ extension UnsafeBufferPointer where Element: ~Copyable { /// - Complexity: O(1) @_alwaysEmitIntoClient @inline(__always) - public func _extracting(last maxLength: Int) -> Self { + package func _extracting(last maxLength: Int) -> Self { precondition(maxLength >= 0, "Can't have a suffix of negative length") let newCount = Swift.min(maxLength, count) return extracting(Range(uncheckedBounds: (count - newCount, count))) } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift similarity index 86% rename from Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb rename to Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift index 2bed0319..a9eaadcb 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift @@ -9,19 +9,12 @@ // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension UnsafeMutableBufferPointer where Element: ~Copyable { /// Returns a Boolean value indicating whether two /// `UnsafeMutableBufferPointer` instances refer to the same region in /// memory. @inlinable @inline(__always) - ${modifier} func _isIdentical(to other: Self) -> Bool { + package func _isIdentical(to other: Self) -> Bool { (self.baseAddress == other.baseAddress) && (self.count == other.count) } } @@ -76,7 +69,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { extension UnsafeMutableBufferPointer where Element: ~Copyable { @inlinable - ${modifier} func _moveInitializePrefix( + package func _moveInitializePrefix( from source: UnsafeMutableBufferPointer ) -> Int { if source.isEmpty { return 0 } @@ -97,7 +90,7 @@ extension UnsafeMutableBufferPointer { /// /// - Returns: The index after the last item that was initialized in this buffer. @inlinable - ${modifier} func _initializePrefix( + package func _initializePrefix( copying source: UnsafeBufferPointer ) -> Int { if source.isEmpty { return 0 } @@ -108,7 +101,7 @@ extension UnsafeMutableBufferPointer { } @inlinable - ${modifier} func _initializePrefix( + package func _initializePrefix( copying source: UnsafeMutableBufferPointer ) -> Int { _initializePrefix(copying: UnsafeBufferPointer(source)) @@ -125,7 +118,7 @@ extension UnsafeMutableBufferPointer { /// - Returns: The index after the last item that was initialized in this buffer. @available(SwiftStdlib 5.0, *) @inlinable - ${modifier} func _initializePrefix(copying source: Span) -> Int { + package func _initializePrefix(copying source: Span) -> Int { source.withUnsafeBufferPointer { self._initializePrefix(copying: $0) } } #endif @@ -139,7 +132,7 @@ extension UnsafeMutableBufferPointer { /// /// The count of `buffer` must not be greater than `self.count`. @inlinable - ${modifier} mutating func _initializeAndDropPrefix(copying source: UnsafeBufferPointer) { + package mutating func _initializeAndDropPrefix(copying source: UnsafeBufferPointer) { let i = _initializePrefix(copying: source) self = self.extracting(i...) } @@ -155,7 +148,7 @@ extension UnsafeMutableBufferPointer { /// The count of `span` must not be greater than `self.count`. @available(SwiftStdlib 5.0, *) @inlinable - ${modifier} mutating func _initializeAndDropPrefix(copying span: Span) { + package mutating func _initializeAndDropPrefix(copying span: Span) { span.withUnsafeBufferPointer { buffer in self._initializeAndDropPrefix(copying: buffer) } @@ -165,7 +158,7 @@ extension UnsafeMutableBufferPointer { extension UnsafeMutableBufferPointer { @inlinable - ${modifier} func initialize(fromContentsOf source: Self) -> Index { + package func initialize(fromContentsOf source: Self) -> Index { guard source.count > 0 else { return 0 } precondition( source.count <= self.count, @@ -177,7 +170,7 @@ extension UnsafeMutableBufferPointer { } @inlinable - ${modifier} func initialize(fromContentsOf source: Slice) -> Index { + package func initialize(fromContentsOf source: Slice) -> Index { let sourceCount = source.count guard sourceCount > 0 else { return 0 } precondition( @@ -192,7 +185,7 @@ extension UnsafeMutableBufferPointer { extension Slice { @inlinable @inline(__always) - ${modifier} func initialize( + package func initialize( fromContentsOf source: UnsafeMutableBufferPointer ) -> Index where Base == UnsafeMutableBufferPointer @@ -203,7 +196,7 @@ extension Slice { } @inlinable @inline(__always) - ${modifier} func initialize( + package func initialize( fromContentsOf source: Slice> ) -> Index where Base == UnsafeMutableBufferPointer @@ -216,7 +209,7 @@ extension Slice { extension UnsafeMutableBufferPointer { @inlinable @inline(__always) - ${modifier} func initializeAll( + package func initializeAll( fromContentsOf source: C ) where C.Element == Element { let i = self.initialize(fromContentsOf: source) @@ -224,13 +217,13 @@ extension UnsafeMutableBufferPointer { } @inlinable @inline(__always) - ${modifier} func initializeAll(fromContentsOf source: Self) { + package func initializeAll(fromContentsOf source: Self) { let i = self.initialize(fromContentsOf: source) assert(i == self.endIndex) } @inlinable @inline(__always) - ${modifier} func initializeAll(fromContentsOf source: Slice) { + package func initializeAll(fromContentsOf source: Slice) { let i = self.initialize(fromContentsOf: source) assert(i == self.endIndex) } @@ -238,7 +231,7 @@ extension UnsafeMutableBufferPointer { extension UnsafeMutableBufferPointer where Element: ~Copyable { @inlinable @inline(__always) - ${modifier} func moveInitializeAll(fromContentsOf source: Self) { + package func moveInitializeAll(fromContentsOf source: Self) { let i = self.moveInitialize(fromContentsOf: source) assert(i == self.endIndex) } @@ -246,7 +239,7 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable { extension UnsafeMutableBufferPointer { @inlinable @inline(__always) - ${modifier} func moveInitializeAll(fromContentsOf source: Slice) { + package func moveInitializeAll(fromContentsOf source: Slice) { let i = self.moveInitialize(fromContentsOf: source) assert(i == self.endIndex) } @@ -254,7 +247,7 @@ extension UnsafeMutableBufferPointer { extension Slice { @inlinable @inline(__always) - ${modifier} func initializeAll( + package func initializeAll( fromContentsOf source: C ) where Base == UnsafeMutableBufferPointer { let i = self.initialize(fromContentsOf: source) @@ -262,7 +255,7 @@ extension Slice { } @inlinable @inline(__always) - ${modifier} func initializeAll( + package func initializeAll( fromContentsOf source: UnsafeMutableBufferPointer ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) @@ -270,7 +263,7 @@ extension Slice { } @inlinable @inline(__always) - ${modifier} func initializeAll( + package func initializeAll( fromContentsOf source: Slice> ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) @@ -278,7 +271,7 @@ extension Slice { } @inlinable @inline(__always) - ${modifier} func moveInitializeAll( + package func moveInitializeAll( fromContentsOf source: UnsafeMutableBufferPointer ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) @@ -286,12 +279,10 @@ extension Slice { } @inlinable @inline(__always) - ${modifier} func moveInitializeAll( + package func moveInitializeAll( fromContentsOf source: Slice> ) where Base == UnsafeMutableBufferPointer { let target = UnsafeMutableBufferPointer(rebasing: self) target.moveInitializeAll(fromContentsOf: source) } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableRawBufferPointer+Extras.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeMutableRawBufferPointer+Extras.swift similarity index 76% rename from Sources/InternalCollectionsUtilities/UnsafeMutableRawBufferPointer+Extras.swift.gyb rename to Sources/InternalCollectionsUtilities/UnsafeMutableRawBufferPointer+Extras.swift index 8b649fbb..060f164c 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableRawBufferPointer+Extras.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableRawBufferPointer+Extras.swift @@ -9,22 +9,13 @@ // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension UnsafeMutableRawBufferPointer { /// Returns a Boolean value indicating whether two /// `UnsafeMutableRawBufferPointer` instances refer to the same region in /// memory. @inlinable @inline(__always) - ${modifier} func _isIdentical(to other: Self) -> Bool { + package func _isIdentical(to other: Self) -> Bool { (self.baseAddress == other.baseAddress) && (self.count == other.count) } } -% end -${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/UnsafeRawBufferPointer+Extras.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeRawBufferPointer+Extras.swift similarity index 75% rename from Sources/InternalCollectionsUtilities/UnsafeRawBufferPointer+Extras.swift.gyb rename to Sources/InternalCollectionsUtilities/UnsafeRawBufferPointer+Extras.swift index dd3157f6..828e0f2a 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeRawBufferPointer+Extras.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeRawBufferPointer+Extras.swift @@ -9,21 +9,11 @@ // //===----------------------------------------------------------------------===// -%{ - from gyb_utils import * -}% -${autogenerated_warning()} - -% for modifier in visibility_levels: -${visibility_boilerplate(modifier)} extension UnsafeRawBufferPointer { /// Returns a Boolean value indicating whether two `UnsafeRawBufferPointer` /// instances refer to the same region in memory. @inlinable @inline(__always) - ${modifier} func _isIdentical(to other: Self) -> Bool { + package func _isIdentical(to other: Self) -> Bool { (self.baseAddress == other.baseAddress) && (self.count == other.count) } } -% end -${visibility_boilerplate("end")} - diff --git a/Sources/InternalCollectionsUtilities/autogenerated/Debugging.swift b/Sources/InternalCollectionsUtilities/autogenerated/Debugging.swift deleted file mode 100644 index 84e49530..00000000 --- a/Sources/InternalCollectionsUtilities/autogenerated/Debugging.swift +++ /dev/null @@ -1,54 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -/// True if consistency checking is enabled in the implementation of the -/// Swift Collections package, false otherwise. -/// -/// Documented performance promises are null and void when this property -/// returns true -- for example, operations that are documented to take -/// O(1) time might take O(*n*) time, or worse. -@inlinable @inline(__always) -internal var _isCollectionsInternalCheckingEnabled: Bool { -#if COLLECTIONS_INTERNAL_CHECKS - return true -#else - return false -#endif -} -#else // !COLLECTIONS_SINGLE_MODULE -/// True if consistency checking is enabled in the implementation of the -/// Swift Collections package, false otherwise. -/// -/// Documented performance promises are null and void when this property -/// returns true -- for example, operations that are documented to take -/// O(1) time might take O(*n*) time, or worse. -@inlinable @inline(__always) -public var _isCollectionsInternalCheckingEnabled: Bool { -#if COLLECTIONS_INTERNAL_CHECKS - return true -#else - return false -#endif -} -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/autogenerated/Descriptions.swift b/Sources/InternalCollectionsUtilities/autogenerated/Descriptions.swift deleted file mode 100644 index 6dc2ab7c..00000000 --- a/Sources/InternalCollectionsUtilities/autogenerated/Descriptions.swift +++ /dev/null @@ -1,140 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE - -@usableFromInline -internal func _addressString(for pointer: UnsafeRawPointer) -> String { - let address = UInt(bitPattern: pointer) - return "0x\(String(address, radix: 16))" -} - -@usableFromInline -internal func _addressString(for object: AnyObject) -> String { - _addressString(for: Unmanaged.passUnretained(object).toOpaque()) -} - -@usableFromInline -internal func _addressString(for object: Unmanaged) -> String { - _addressString(for: object.toOpaque()) -} - -#if !$Embedded -@inlinable -internal func _arrayDescription( - for elements: C -) -> String { - var result = "[" - var first = true - for item in elements { - if first { - first = false - } else { - result += ", " - } - debugPrint(item, terminator: "", to: &result) - } - result += "]" - return result -} - -@inlinable -internal func _dictionaryDescription( - for elements: C -) -> String where C.Element == (key: Key, value: Value) { - guard !elements.isEmpty else { return "[:]" } - var result = "[" - var first = true - for (key, value) in elements { - if first { - first = false - } else { - result += ", " - } - debugPrint(key, terminator: "", to: &result) - result += ": " - debugPrint(value, terminator: "", to: &result) - } - result += "]" - return result -} -#endif -#else // !COLLECTIONS_SINGLE_MODULE - -//@usableFromInline -public func _addressString(for pointer: UnsafeRawPointer) -> String { - let address = UInt(bitPattern: pointer) - return "0x\(String(address, radix: 16))" -} - -//@usableFromInline -public func _addressString(for object: AnyObject) -> String { - _addressString(for: Unmanaged.passUnretained(object).toOpaque()) -} - -//@usableFromInline -public func _addressString(for object: Unmanaged) -> String { - _addressString(for: object.toOpaque()) -} - -#if !$Embedded -@inlinable -public func _arrayDescription( - for elements: C -) -> String { - var result = "[" - var first = true - for item in elements { - if first { - first = false - } else { - result += ", " - } - debugPrint(item, terminator: "", to: &result) - } - result += "]" - return result -} - -@inlinable -public func _dictionaryDescription( - for elements: C -) -> String where C.Element == (key: Key, value: Value) { - guard !elements.isEmpty else { return "[:]" } - var result = "[" - var first = true - for (key, value) in elements { - if first { - first = false - } else { - result += ", " - } - debugPrint(key, terminator: "", to: &result) - result += ": " - debugPrint(value, terminator: "", to: &result) - } - result += "]" - return result -} -#endif -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/autogenerated/LifetimeOverride.swift b/Sources/InternalCollectionsUtilities/autogenerated/LifetimeOverride.swift deleted file mode 100644 index 7c16eeec..00000000 --- a/Sources/InternalCollectionsUtilities/autogenerated/LifetimeOverride.swift +++ /dev/null @@ -1,169 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - -#if compiler(>=6.2) - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -/// Unsafely discard any lifetime dependency on the `dependent` argument. -/// Return a value identical to `dependent` with an immortal lifetime. -@unsafe -@_unsafeNonescapableResult -@_alwaysEmitIntoClient -@_transparent -@_lifetime(immortal) -internal func _unsafeImmortalize( - _ dependent: consuming T -) -> T { - // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence - // should be expressed by a builtin that is hidden within the function body. - dependent -} - -/// Unsafely discard any lifetime dependency on the `dependent` argument. -/// Return a value identical to `dependent` with a lifetime dependency -/// on the caller's borrow scope of the `source` argument. -@unsafe -@_unsafeNonescapableResult -@_alwaysEmitIntoClient -@_transparent -@_lifetime(borrow source) -internal func _overrideLifetime< - T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable ->( - _ dependent: consuming T, borrowing source: borrowing U -) -> T { - // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence - // should be expressed by a builtin that is hidden within the function body. - dependent -} - -/// Unsafely discard any lifetime dependency on the `dependent` argument. -/// Return a value identical to `dependent` that inherits -/// all lifetime dependencies from the `source` argument. -@unsafe -@_unsafeNonescapableResult -@_alwaysEmitIntoClient -@_transparent -@_lifetime(copy source) -internal func _overrideLifetime< - T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable ->( - _ dependent: consuming T, copying source: borrowing U -) -> T { - // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence - // should be expressed by a builtin that is hidden within the function body. - dependent -} - -/// Unsafely discard any lifetime dependency on the `dependent` argument. -/// Return a value identical to `dependent` with a lifetime dependency -/// on the caller's exclusive borrow scope of the `source` argument. -@unsafe -@_unsafeNonescapableResult -@_alwaysEmitIntoClient -@_transparent -@_lifetime(&source) -internal func _overrideLifetime< - T: ~Copyable & ~Escapable, - U: ~Copyable & ~Escapable ->( - _ dependent: consuming T, - mutating source: inout U -) -> T { - // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence - // should be expressed by a builtin that is hidden within the function body. - dependent -} -#else // !COLLECTIONS_SINGLE_MODULE -/// Unsafely discard any lifetime dependency on the `dependent` argument. -/// Return a value identical to `dependent` with an immortal lifetime. -@unsafe -@_unsafeNonescapableResult -@_alwaysEmitIntoClient -@_transparent -@_lifetime(immortal) -public func _unsafeImmortalize( - _ dependent: consuming T -) -> T { - // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence - // should be expressed by a builtin that is hidden within the function body. - dependent -} - -/// Unsafely discard any lifetime dependency on the `dependent` argument. -/// Return a value identical to `dependent` with a lifetime dependency -/// on the caller's borrow scope of the `source` argument. -@unsafe -@_unsafeNonescapableResult -@_alwaysEmitIntoClient -@_transparent -@_lifetime(borrow source) -public func _overrideLifetime< - T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable ->( - _ dependent: consuming T, borrowing source: borrowing U -) -> T { - // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence - // should be expressed by a builtin that is hidden within the function body. - dependent -} - -/// Unsafely discard any lifetime dependency on the `dependent` argument. -/// Return a value identical to `dependent` that inherits -/// all lifetime dependencies from the `source` argument. -@unsafe -@_unsafeNonescapableResult -@_alwaysEmitIntoClient -@_transparent -@_lifetime(copy source) -public func _overrideLifetime< - T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable ->( - _ dependent: consuming T, copying source: borrowing U -) -> T { - // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence - // should be expressed by a builtin that is hidden within the function body. - dependent -} - -/// Unsafely discard any lifetime dependency on the `dependent` argument. -/// Return a value identical to `dependent` with a lifetime dependency -/// on the caller's exclusive borrow scope of the `source` argument. -@unsafe -@_unsafeNonescapableResult -@_alwaysEmitIntoClient -@_transparent -@_lifetime(&source) -public func _overrideLifetime< - T: ~Copyable & ~Escapable, - U: ~Copyable & ~Escapable ->( - _ dependent: consuming T, - mutating source: inout U -) -> T { - // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence - // should be expressed by a builtin that is hidden within the function body. - dependent -} -#endif // COLLECTIONS_SINGLE_MODULE -#endif diff --git a/Sources/InternalCollectionsUtilities/autogenerated/RandomAccessCollection+Offsets.swift b/Sources/InternalCollectionsUtilities/autogenerated/RandomAccessCollection+Offsets.swift deleted file mode 100644 index ebcc44ca..00000000 --- a/Sources/InternalCollectionsUtilities/autogenerated/RandomAccessCollection+Offsets.swift +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension RandomAccessCollection { - @_alwaysEmitIntoClient @inline(__always) - internal func _index(at offset: Int) -> Index { - index(startIndex, offsetBy: offset) - } - - @_alwaysEmitIntoClient @inline(__always) - internal func _offset(of index: Index) -> Int { - distance(from: startIndex, to: index) - } - - @_alwaysEmitIntoClient @inline(__always) - internal subscript(_offset offset: Int) -> Element { - self[_index(at: offset)] - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension RandomAccessCollection { - @_alwaysEmitIntoClient @inline(__always) - public func _index(at offset: Int) -> Index { - index(startIndex, offsetBy: offset) - } - - @_alwaysEmitIntoClient @inline(__always) - public func _offset(of index: Index) -> Int { - distance(from: startIndex, to: index) - } - - @_alwaysEmitIntoClient @inline(__always) - public subscript(_offset offset: Int) -> Element { - self[_index(at: offset)] - } -} -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift deleted file mode 100644 index 014ddf27..00000000 --- a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift +++ /dev/null @@ -1,157 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2021 - 2025 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension UnsafeBufferPointer { - @inlinable - @inline(__always) - internal func _ptr(at index: Int) -> UnsafePointer { - assert(index >= 0 && index < count) - return baseAddress.unsafelyUnwrapped + index - } -} - -extension UnsafeBufferPointer where Element: ~Copyable { - /// Returns a Boolean value indicating whether two `UnsafeBufferPointer` - /// instances refer to the same region in memory. - @inlinable @inline(__always) - internal func _isIdentical(to other: Self) -> Bool { - (self.baseAddress == other.baseAddress) && (self.count == other.count) - } -} - -extension UnsafeBufferPointer where Element: ~Copyable { - /// Returns a buffer pointer containing the initial elements of this buffer, - /// up to the specified maximum length. - /// - /// If the maximum length exceeds the length of this buffer pointer, - /// then the result contains all the elements. - /// - /// The returned buffer's first item is always at offset 0; unlike buffer - /// slices, extracted buffers do not share their indices with the - /// buffer from which they are extracted. - /// - /// - Parameter maxLength: The maximum number of elements to return. - /// `maxLength` must be greater than or equal to zero. - /// - Returns: A buffer pointer with at most `maxLength` elements. - /// - /// - Complexity: O(1) - @_alwaysEmitIntoClient - @inline(__always) - public func _extracting(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") - let newCount = Swift.min(maxLength, count) - return Self(start: baseAddress, count: newCount) - } - - /// Returns a buffer pointer containing the final elements of this buffer, - /// up to the given maximum length. - /// - /// If the maximum length exceeds the length of this buffer pointer, - /// the result contains all the elements. - /// - /// The returned buffer's first item is always at offset 0; unlike buffer - /// slices, extracted buffers do not share their indices with the - /// span from which they are extracted. - /// - /// - Parameter maxLength: The maximum number of elements to return. - /// `maxLength` must be greater than or equal to zero. - /// - Returns: A buffer pointer with at most `maxLength` elements. - /// - /// - Complexity: O(1) - @_alwaysEmitIntoClient - @inline(__always) - public func _extracting(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") - let newCount = Swift.min(maxLength, count) - return extracting(Range(uncheckedBounds: (count - newCount, count))) - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension UnsafeBufferPointer { - @inlinable - @inline(__always) - public func _ptr(at index: Int) -> UnsafePointer { - assert(index >= 0 && index < count) - return baseAddress.unsafelyUnwrapped + index - } -} - -extension UnsafeBufferPointer where Element: ~Copyable { - /// Returns a Boolean value indicating whether two `UnsafeBufferPointer` - /// instances refer to the same region in memory. - @inlinable @inline(__always) - public func _isIdentical(to other: Self) -> Bool { - (self.baseAddress == other.baseAddress) && (self.count == other.count) - } -} - -extension UnsafeBufferPointer where Element: ~Copyable { - /// Returns a buffer pointer containing the initial elements of this buffer, - /// up to the specified maximum length. - /// - /// If the maximum length exceeds the length of this buffer pointer, - /// then the result contains all the elements. - /// - /// The returned buffer's first item is always at offset 0; unlike buffer - /// slices, extracted buffers do not share their indices with the - /// buffer from which they are extracted. - /// - /// - Parameter maxLength: The maximum number of elements to return. - /// `maxLength` must be greater than or equal to zero. - /// - Returns: A buffer pointer with at most `maxLength` elements. - /// - /// - Complexity: O(1) - @_alwaysEmitIntoClient - @inline(__always) - public func _extracting(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") - let newCount = Swift.min(maxLength, count) - return Self(start: baseAddress, count: newCount) - } - - /// Returns a buffer pointer containing the final elements of this buffer, - /// up to the given maximum length. - /// - /// If the maximum length exceeds the length of this buffer pointer, - /// the result contains all the elements. - /// - /// The returned buffer's first item is always at offset 0; unlike buffer - /// slices, extracted buffers do not share their indices with the - /// span from which they are extracted. - /// - /// - Parameter maxLength: The maximum number of elements to return. - /// `maxLength` must be greater than or equal to zero. - /// - Returns: A buffer pointer with at most `maxLength` elements. - /// - /// - Complexity: O(1) - @_alwaysEmitIntoClient - @inline(__always) - public func _extracting(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") - let newCount = Swift.min(maxLength, count) - return extracting(Range(uncheckedBounds: (count - newCount, count))) - } -} -#endif // COLLECTIONS_SINGLE_MODULE - diff --git a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift deleted file mode 100644 index 7abcc67e..00000000 --- a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift +++ /dev/null @@ -1,580 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2025 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension UnsafeMutableBufferPointer where Element: ~Copyable { - /// Returns a Boolean value indicating whether two - /// `UnsafeMutableBufferPointer` instances refer to the same region in - /// memory. - @inlinable @inline(__always) - internal func _isIdentical(to other: Self) -> Bool { - (self.baseAddress == other.baseAddress) && (self.count == other.count) - } -} - -extension UnsafeMutableBufferPointer where Element: ~Copyable { - /// Returns a buffer pointer containing the initial elements of this buffer, - /// up to the specified maximum length. - /// - /// If the maximum length exceeds the length of this buffer pointer, - /// then the result contains all the elements. - /// - /// The returned buffer's first item is always at offset 0; unlike buffer - /// slices, extracted buffers do not share their indices with the - /// buffer from which they are extracted. - /// - /// - Parameter maxLength: The maximum number of elements to return. - /// `maxLength` must be greater than or equal to zero. - /// - Returns: A buffer pointer with at most `maxLength` elements. - /// - /// - Complexity: O(1) - @_alwaysEmitIntoClient - @inline(__always) - public func _extracting(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") - let newCount = Swift.min(maxLength, count) - return Self(start: baseAddress, count: newCount) - } - - /// Returns a buffer pointer containing the final elements of this buffer, - /// up to the given maximum length. - /// - /// If the maximum length exceeds the length of this buffer pointer, - /// the result contains all the elements. - /// - /// The returned buffer's first item is always at offset 0; unlike buffer - /// slices, extracted buffers do not share their indices with the - /// buffer from which they are extracted. - /// - /// - Parameter maxLength: The maximum number of elements to return. - /// `maxLength` must be greater than or equal to zero. - /// - Returns: A buffer pointer with at most `maxLength` elements. - /// - /// - Complexity: O(1) - @_alwaysEmitIntoClient - @inline(__always) - public func _extracting(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") - let newCount = Swift.min(maxLength, count) - return extracting(Range(uncheckedBounds: (count - newCount, count))) - } -} - -extension UnsafeMutableBufferPointer where Element: ~Copyable { - @inlinable - internal func _moveInitializePrefix( - from source: UnsafeMutableBufferPointer - ) -> Int { - if source.isEmpty { return 0 } - precondition(source.count <= self.count) - self.baseAddress.unsafelyUnwrapped.moveInitialize( - from: source.baseAddress.unsafelyUnwrapped, count: source.count) - return source.count - } -} - -extension UnsafeMutableBufferPointer { - /// Initialize slots at the start of this buffer by copying data from `source`. - /// - /// If `Element` is not bitwise copyable, then the memory region addressed by `self` must be - /// entirely uninitialized, while `source` must be fully initialized. - /// - /// The `source` buffer must fit entirely in `self`. - /// - /// - Returns: The index after the last item that was initialized in this buffer. - @inlinable - internal func _initializePrefix( - copying source: UnsafeBufferPointer - ) -> Int { - if source.isEmpty { return 0 } - precondition(source.count <= self.count) - self.baseAddress.unsafelyUnwrapped.initialize( - from: source.baseAddress.unsafelyUnwrapped, count: source.count) - return source.count - } - - @inlinable - internal func _initializePrefix( - copying source: UnsafeMutableBufferPointer - ) -> Int { - _initializePrefix(copying: UnsafeBufferPointer(source)) - } - -#if compiler(>=6.2) - /// Initialize slots at the start of this buffer by copying data from `source`. - /// - /// If `Element` is not bitwise copyable, then the memory region addressed by `self` must be - /// entirely uninitialized. - /// - /// The `source` span must fit entirely in `self`. - /// - /// - Returns: The index after the last item that was initialized in this buffer. - @available(SwiftStdlib 5.0, *) - @inlinable - internal func _initializePrefix(copying source: Span) -> Int { - source.withUnsafeBufferPointer { self._initializePrefix(copying: $0) } - } -#endif - - /// Initialize slots at the start of this buffer by copying data from `buffer`, then - /// shrink `self` to drop all initialized items from its front, leaving it addressing the - /// uninitialized remainder. - /// - /// If `Element` is not bitwise copyable, then the memory region addressed by `self` must be - /// entirely uninitialized, while `buffer` must be fully initialized. - /// - /// The count of `buffer` must not be greater than `self.count`. - @inlinable - internal mutating func _initializeAndDropPrefix(copying source: UnsafeBufferPointer) { - let i = _initializePrefix(copying: source) - self = self.extracting(i...) - } - -#if compiler(>=6.2) - /// Initialize slots at the start of this buffer by copying data from `span`, then - /// shrink `self` to drop all initialized items from its front, leaving it addressing the - /// uninitialized remainder. - /// - /// If `Element` is not bitwise copyable, then the memory region addressed by `self` must be - /// entirely uninitialized. - /// - /// The count of `span` must not be greater than `self.count`. - @available(SwiftStdlib 5.0, *) - @inlinable - internal mutating func _initializeAndDropPrefix(copying span: Span) { - span.withUnsafeBufferPointer { buffer in - self._initializeAndDropPrefix(copying: buffer) - } - } -#endif -} - -extension UnsafeMutableBufferPointer { - @inlinable - internal func initialize(fromContentsOf source: Self) -> Index { - guard source.count > 0 else { return 0 } - precondition( - source.count <= self.count, - "buffer cannot contain every element from source.") - baseAddress.unsafelyUnwrapped.initialize( - from: source.baseAddress.unsafelyUnwrapped, - count: source.count) - return source.count - } - - @inlinable - internal func initialize(fromContentsOf source: Slice) -> Index { - let sourceCount = source.count - guard sourceCount > 0 else { return 0 } - precondition( - sourceCount <= self.count, - "buffer cannot contain every element from source.") - baseAddress.unsafelyUnwrapped.initialize( - from: source.base.baseAddress.unsafelyUnwrapped + source.startIndex, - count: sourceCount) - return sourceCount - } -} - -extension Slice { - @inlinable @inline(__always) - internal func initialize( - fromContentsOf source: UnsafeMutableBufferPointer - ) -> Index - where Base == UnsafeMutableBufferPointer - { - let target = UnsafeMutableBufferPointer(rebasing: self) - let i = target.initialize(fromContentsOf: source) - return self.startIndex + i - } - - @inlinable @inline(__always) - internal func initialize( - fromContentsOf source: Slice> - ) -> Index - where Base == UnsafeMutableBufferPointer - { - let target = UnsafeMutableBufferPointer(rebasing: self) - let i = target.initialize(fromContentsOf: source) - return self.startIndex + i - } -} - -extension UnsafeMutableBufferPointer { - @inlinable @inline(__always) - internal func initializeAll( - fromContentsOf source: C - ) where C.Element == Element { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) - } - - @inlinable @inline(__always) - internal func initializeAll(fromContentsOf source: Self) { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) - } - - @inlinable @inline(__always) - internal func initializeAll(fromContentsOf source: Slice) { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) - } -} - -extension UnsafeMutableBufferPointer where Element: ~Copyable { - @inlinable @inline(__always) - internal func moveInitializeAll(fromContentsOf source: Self) { - let i = self.moveInitialize(fromContentsOf: source) - assert(i == self.endIndex) - } -} - -extension UnsafeMutableBufferPointer { - @inlinable @inline(__always) - internal func moveInitializeAll(fromContentsOf source: Slice) { - let i = self.moveInitialize(fromContentsOf: source) - assert(i == self.endIndex) - } -} - -extension Slice { - @inlinable @inline(__always) - internal func initializeAll( - fromContentsOf source: C - ) where Base == UnsafeMutableBufferPointer { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) - } - - @inlinable @inline(__always) - internal func initializeAll( - fromContentsOf source: UnsafeMutableBufferPointer - ) where Base == UnsafeMutableBufferPointer { - let target = UnsafeMutableBufferPointer(rebasing: self) - target.initializeAll(fromContentsOf: source) - } - - @inlinable @inline(__always) - internal func initializeAll( - fromContentsOf source: Slice> - ) where Base == UnsafeMutableBufferPointer { - let target = UnsafeMutableBufferPointer(rebasing: self) - target.initializeAll(fromContentsOf: source) - } - - @inlinable @inline(__always) - internal func moveInitializeAll( - fromContentsOf source: UnsafeMutableBufferPointer - ) where Base == UnsafeMutableBufferPointer { - let target = UnsafeMutableBufferPointer(rebasing: self) - target.moveInitializeAll(fromContentsOf: source) - } - - @inlinable @inline(__always) - internal func moveInitializeAll( - fromContentsOf source: Slice> - ) where Base == UnsafeMutableBufferPointer { - let target = UnsafeMutableBufferPointer(rebasing: self) - target.moveInitializeAll(fromContentsOf: source) - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension UnsafeMutableBufferPointer where Element: ~Copyable { - /// Returns a Boolean value indicating whether two - /// `UnsafeMutableBufferPointer` instances refer to the same region in - /// memory. - @inlinable @inline(__always) - public func _isIdentical(to other: Self) -> Bool { - (self.baseAddress == other.baseAddress) && (self.count == other.count) - } -} - -extension UnsafeMutableBufferPointer where Element: ~Copyable { - /// Returns a buffer pointer containing the initial elements of this buffer, - /// up to the specified maximum length. - /// - /// If the maximum length exceeds the length of this buffer pointer, - /// then the result contains all the elements. - /// - /// The returned buffer's first item is always at offset 0; unlike buffer - /// slices, extracted buffers do not share their indices with the - /// buffer from which they are extracted. - /// - /// - Parameter maxLength: The maximum number of elements to return. - /// `maxLength` must be greater than or equal to zero. - /// - Returns: A buffer pointer with at most `maxLength` elements. - /// - /// - Complexity: O(1) - @_alwaysEmitIntoClient - @inline(__always) - public func _extracting(first maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a prefix of negative length") - let newCount = Swift.min(maxLength, count) - return Self(start: baseAddress, count: newCount) - } - - /// Returns a buffer pointer containing the final elements of this buffer, - /// up to the given maximum length. - /// - /// If the maximum length exceeds the length of this buffer pointer, - /// the result contains all the elements. - /// - /// The returned buffer's first item is always at offset 0; unlike buffer - /// slices, extracted buffers do not share their indices with the - /// buffer from which they are extracted. - /// - /// - Parameter maxLength: The maximum number of elements to return. - /// `maxLength` must be greater than or equal to zero. - /// - Returns: A buffer pointer with at most `maxLength` elements. - /// - /// - Complexity: O(1) - @_alwaysEmitIntoClient - @inline(__always) - public func _extracting(last maxLength: Int) -> Self { - precondition(maxLength >= 0, "Can't have a suffix of negative length") - let newCount = Swift.min(maxLength, count) - return extracting(Range(uncheckedBounds: (count - newCount, count))) - } -} - -extension UnsafeMutableBufferPointer where Element: ~Copyable { - @inlinable - public func _moveInitializePrefix( - from source: UnsafeMutableBufferPointer - ) -> Int { - if source.isEmpty { return 0 } - precondition(source.count <= self.count) - self.baseAddress.unsafelyUnwrapped.moveInitialize( - from: source.baseAddress.unsafelyUnwrapped, count: source.count) - return source.count - } -} - -extension UnsafeMutableBufferPointer { - /// Initialize slots at the start of this buffer by copying data from `source`. - /// - /// If `Element` is not bitwise copyable, then the memory region addressed by `self` must be - /// entirely uninitialized, while `source` must be fully initialized. - /// - /// The `source` buffer must fit entirely in `self`. - /// - /// - Returns: The index after the last item that was initialized in this buffer. - @inlinable - public func _initializePrefix( - copying source: UnsafeBufferPointer - ) -> Int { - if source.isEmpty { return 0 } - precondition(source.count <= self.count) - self.baseAddress.unsafelyUnwrapped.initialize( - from: source.baseAddress.unsafelyUnwrapped, count: source.count) - return source.count - } - - @inlinable - public func _initializePrefix( - copying source: UnsafeMutableBufferPointer - ) -> Int { - _initializePrefix(copying: UnsafeBufferPointer(source)) - } - -#if compiler(>=6.2) - /// Initialize slots at the start of this buffer by copying data from `source`. - /// - /// If `Element` is not bitwise copyable, then the memory region addressed by `self` must be - /// entirely uninitialized. - /// - /// The `source` span must fit entirely in `self`. - /// - /// - Returns: The index after the last item that was initialized in this buffer. - @available(SwiftStdlib 5.0, *) - @inlinable - public func _initializePrefix(copying source: Span) -> Int { - source.withUnsafeBufferPointer { self._initializePrefix(copying: $0) } - } -#endif - - /// Initialize slots at the start of this buffer by copying data from `buffer`, then - /// shrink `self` to drop all initialized items from its front, leaving it addressing the - /// uninitialized remainder. - /// - /// If `Element` is not bitwise copyable, then the memory region addressed by `self` must be - /// entirely uninitialized, while `buffer` must be fully initialized. - /// - /// The count of `buffer` must not be greater than `self.count`. - @inlinable - public mutating func _initializeAndDropPrefix(copying source: UnsafeBufferPointer) { - let i = _initializePrefix(copying: source) - self = self.extracting(i...) - } - -#if compiler(>=6.2) - /// Initialize slots at the start of this buffer by copying data from `span`, then - /// shrink `self` to drop all initialized items from its front, leaving it addressing the - /// uninitialized remainder. - /// - /// If `Element` is not bitwise copyable, then the memory region addressed by `self` must be - /// entirely uninitialized. - /// - /// The count of `span` must not be greater than `self.count`. - @available(SwiftStdlib 5.0, *) - @inlinable - public mutating func _initializeAndDropPrefix(copying span: Span) { - span.withUnsafeBufferPointer { buffer in - self._initializeAndDropPrefix(copying: buffer) - } - } -#endif -} - -extension UnsafeMutableBufferPointer { - @inlinable - public func initialize(fromContentsOf source: Self) -> Index { - guard source.count > 0 else { return 0 } - precondition( - source.count <= self.count, - "buffer cannot contain every element from source.") - baseAddress.unsafelyUnwrapped.initialize( - from: source.baseAddress.unsafelyUnwrapped, - count: source.count) - return source.count - } - - @inlinable - public func initialize(fromContentsOf source: Slice) -> Index { - let sourceCount = source.count - guard sourceCount > 0 else { return 0 } - precondition( - sourceCount <= self.count, - "buffer cannot contain every element from source.") - baseAddress.unsafelyUnwrapped.initialize( - from: source.base.baseAddress.unsafelyUnwrapped + source.startIndex, - count: sourceCount) - return sourceCount - } -} - -extension Slice { - @inlinable @inline(__always) - public func initialize( - fromContentsOf source: UnsafeMutableBufferPointer - ) -> Index - where Base == UnsafeMutableBufferPointer - { - let target = UnsafeMutableBufferPointer(rebasing: self) - let i = target.initialize(fromContentsOf: source) - return self.startIndex + i - } - - @inlinable @inline(__always) - public func initialize( - fromContentsOf source: Slice> - ) -> Index - where Base == UnsafeMutableBufferPointer - { - let target = UnsafeMutableBufferPointer(rebasing: self) - let i = target.initialize(fromContentsOf: source) - return self.startIndex + i - } -} - -extension UnsafeMutableBufferPointer { - @inlinable @inline(__always) - public func initializeAll( - fromContentsOf source: C - ) where C.Element == Element { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) - } - - @inlinable @inline(__always) - public func initializeAll(fromContentsOf source: Self) { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) - } - - @inlinable @inline(__always) - public func initializeAll(fromContentsOf source: Slice) { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) - } -} - -extension UnsafeMutableBufferPointer where Element: ~Copyable { - @inlinable @inline(__always) - public func moveInitializeAll(fromContentsOf source: Self) { - let i = self.moveInitialize(fromContentsOf: source) - assert(i == self.endIndex) - } -} - -extension UnsafeMutableBufferPointer { - @inlinable @inline(__always) - public func moveInitializeAll(fromContentsOf source: Slice) { - let i = self.moveInitialize(fromContentsOf: source) - assert(i == self.endIndex) - } -} - -extension Slice { - @inlinable @inline(__always) - public func initializeAll( - fromContentsOf source: C - ) where Base == UnsafeMutableBufferPointer { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) - } - - @inlinable @inline(__always) - public func initializeAll( - fromContentsOf source: UnsafeMutableBufferPointer - ) where Base == UnsafeMutableBufferPointer { - let target = UnsafeMutableBufferPointer(rebasing: self) - target.initializeAll(fromContentsOf: source) - } - - @inlinable @inline(__always) - public func initializeAll( - fromContentsOf source: Slice> - ) where Base == UnsafeMutableBufferPointer { - let target = UnsafeMutableBufferPointer(rebasing: self) - target.initializeAll(fromContentsOf: source) - } - - @inlinable @inline(__always) - public func moveInitializeAll( - fromContentsOf source: UnsafeMutableBufferPointer - ) where Base == UnsafeMutableBufferPointer { - let target = UnsafeMutableBufferPointer(rebasing: self) - target.moveInitializeAll(fromContentsOf: source) - } - - @inlinable @inline(__always) - public func moveInitializeAll( - fromContentsOf source: Slice> - ) where Base == UnsafeMutableBufferPointer { - let target = UnsafeMutableBufferPointer(rebasing: self) - target.moveInitializeAll(fromContentsOf: source) - } -} -#endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableRawBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableRawBufferPointer+Extras.swift deleted file mode 100644 index b97bfe3b..00000000 --- a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableRawBufferPointer+Extras.swift +++ /dev/null @@ -1,45 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2025 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension UnsafeMutableRawBufferPointer { - /// Returns a Boolean value indicating whether two - /// `UnsafeMutableRawBufferPointer` instances refer to the same region in - /// memory. - @inlinable @inline(__always) - internal func _isIdentical(to other: Self) -> Bool { - (self.baseAddress == other.baseAddress) && (self.count == other.count) - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension UnsafeMutableRawBufferPointer { - /// Returns a Boolean value indicating whether two - /// `UnsafeMutableRawBufferPointer` instances refer to the same region in - /// memory. - @inlinable @inline(__always) - public func _isIdentical(to other: Self) -> Bool { - (self.baseAddress == other.baseAddress) && (self.count == other.count) - } -} -#endif // COLLECTIONS_SINGLE_MODULE - diff --git a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeRawBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeRawBufferPointer+Extras.swift deleted file mode 100644 index 7caa59d0..00000000 --- a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeRawBufferPointer+Extras.swift +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2025 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - - -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# - - - -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE -extension UnsafeRawBufferPointer { - /// Returns a Boolean value indicating whether two `UnsafeRawBufferPointer` - /// instances refer to the same region in memory. - @inlinable @inline(__always) - internal func _isIdentical(to other: Self) -> Bool { - (self.baseAddress == other.baseAddress) && (self.count == other.count) - } -} -#else // !COLLECTIONS_SINGLE_MODULE -extension UnsafeRawBufferPointer { - /// Returns a Boolean value indicating whether two `UnsafeRawBufferPointer` - /// instances refer to the same region in memory. - @inlinable @inline(__always) - public func _isIdentical(to other: Self) -> Bool { - (self.baseAddress == other.baseAddress) && (self.count == other.count) - } -} -#endif // COLLECTIONS_SINGLE_MODULE - diff --git a/Utils/README.md b/Utils/README.md index 58bce3bd..4c50ad4c 100644 --- a/Utils/README.md +++ b/Utils/README.md @@ -6,12 +6,6 @@ Beware! The contents of this directory are not source stable. They are provided - `generate-docs.sh`: A shell scripts that automates the generation of API documentation. -- `generate-sources.sh`: A shell script that invokes `gyb` to regenerate the contents of autogenerated/ directories. This needs to be run whenever a file with a `.swift.gyb` extension is updated. - -- `gyb`, `gyb.py`: Generate Your Boilerplate. A rudimentary source code generation utility. - -- `gyb_utils.py`: A Python module containing code generation utility definitions that are shared across multiple `.swift.gyb` files in this repository. - - `run-full-tests.sh`: A shell script that exercises many common configurations of this package in a semi-automated way. This is used before tagging a release to avoid accidentally shipping a package version that breaks some setups. - `shuffle-sources.sh`: A legacy utility that randomly reorders Swift source files in a given directory. This is used to avoid reoccurrances of issue #7. (This is hopefully only relevant with compilers that the package no longer supports.) diff --git a/Utils/generate-sources.sh b/Utils/generate-sources.sh deleted file mode 100755 index 1ed52f69..00000000 --- a/Utils/generate-sources.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/sh -#===----------------------------------------------------------------------===// -# -# This source file is part of the Swift.org open source project -# -# Copyright (c) 2020 - 2024 Apple Inc. and the Swift project authors -# Licensed under Apache License v2.0 with Runtime Library Exception -# -# See https://swift.org/LICENSE.txt for license information -# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -# -#===----------------------------------------------------------------------===// - -set -eu - -srcroot="$(dirname "$0")/.." -cd "$srcroot" - -gyb="./Utils/gyb" - -# Disable line directives in gyb output. We commit generated sources -# into the package repository, so we do not want absolute file names -# in them. -lineDirective='' - -# Uncomment the following line to enable #sourceLocation directives. -# This is useful for local development. -#lineDirective='#sourceLocation(file: "%(file)s", line: %(line)d)' - - -# Create a temporary directory; remove it on exit. -tmpdir="$(mktemp -d "${TMPDIR:-/tmp}/$(basename "$0").XXXXXXXX")" -trap "rm -rf \"$tmpdir\"" EXIT - -# Run gyb on each gyb file in the source tree and put results in -# subdirectories named 'autogenerated'. -find ./Sources ./Tests -name "*.gyb" | while read input; do - basename="$(basename "$input")" - targetdir="$(dirname "$input")/autogenerated" - output="$targetdir/"${basename%.gyb} - tmpfile="$tmpdir/${basename%.gyb}" - - # Make sure the output directory exists. - mkdir -p "$targetdir" - - # Run gyb, making sure to only update files when they change. - "$gyb" --line-directive "$lineDirective" -o "$tmpfile" "$input" - if [ -e "$output" ] && cmp -s "$tmpfile" "$output"; then - : Ignore unchanged file - else - echo "Updated $output" - cp "$tmpfile" "$output" - fi - echo "$output" >> "$tmpdir/generated-files.txt" -done - -# Remove autogenerated files without a corresponding gyb. -find . -path '*/autogenerated/*.swift' >> "$tmpdir/generated-files.txt" -sort "$tmpdir/generated-files.txt" | uniq -u | while read obsolete; do - echo "Removing $obsolete" - rm "$obsolete" -done diff --git a/Utils/gyb b/Utils/gyb deleted file mode 100755 index 8206bd8a..00000000 --- a/Utils/gyb +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env python3 -import gyb -gyb.main() diff --git a/Utils/gyb.py b/Utils/gyb.py deleted file mode 100755 index e3af0b7d..00000000 --- a/Utils/gyb.py +++ /dev/null @@ -1,1247 +0,0 @@ -#!/usr/bin/env python -# GYB: Generate Your Boilerplate (improved names welcome; at least -# this one's short). See -h output for instructions - -import os -import re -import sys -import textwrap -import tokenize -from bisect import bisect -from io import StringIO - - -def get_line_starts(s): - """Return a list containing the start index of each line in s. - - The list also contains a sentinel index for the end of the string, - so there will be one more element in the list than there are lines - in the string - """ - starts = [0] - - for line in s.split('\n'): - starts.append(starts[-1] + len(line) + 1) - - starts[-1] -= 1 - return starts - - -def strip_trailing_nl(s): - """If s ends with a newline, drop it; else return s intact""" - return s[:-1] if s.endswith('\n') else s - - -def split_lines(s): - """Split s into a list of lines, each of which has a trailing newline - - If the lines are later concatenated, the result is s, possibly - with a single appended newline. - """ - return [l + '\n' for l in s.split('\n')] - - -# text on a line up to the first '$$', '${', or '%%' -literalText = r'(?: [^$\n%] | \$(?![${]) | %(?!%) )*' - -# The part of an '%end' line that follows the '%' sign -linesClose = r'[\ \t]* end [\ \t]* (?: \# .* )? $' - -# Note: Where "# Absorb" appears below, the regexp attempts to eat up -# through the end of ${...} and %{...}% constructs. In reality we -# handle this with the Python tokenizer, which avoids mis-detections -# due to nesting, comments and strings. This extra absorption in the -# regexp facilitates testing the regexp on its own, by preventing the -# interior of some of these constructs from being treated as literal -# text. -tokenize_re = re.compile( - r''' -# %-lines and %{...}-blocks - # \n? # absorb one preceding newline - ^ - (?: - (?P - (?P<_indent> [\ \t]* % (?! [{%] ) [\ \t]* ) (?! [\ \t] | ''' + - linesClose + r''' ) .* - ( \n (?P=_indent) (?! ''' + linesClose + r''' ) .* ) * - ) - | (?P [\ \t]* % [ \t]* ''' + linesClose + r''' ) - | [\ \t]* (?P %\{ ) - (?: [^}]| \} (?!%) )* \}% # Absorb - ) - \n? # absorb one trailing newline - -# Substitutions -| (?P \$\{ ) - [^}]* \} # Absorb - -# %% and $$ are literal % and $ respectively -| (?P[$%]) (?P=symbol) - -# Literal text -| (?P ''' + literalText + r''' - (?: - # newline that doesn't precede space+% - (?: \n (?! [\ \t]* %[^%] ) ) - ''' + literalText + r''' - )* - \n? - ) -''', re.VERBOSE | re.MULTILINE) - -gyb_block_close = re.compile(r'\}%[ \t]*\n?') - - -def token_pos_to_index(token_pos, start, line_starts): - """Translate a tokenize (line, column) pair into an absolute - position in source text given the position where we started - tokenizing and a list that maps lines onto their starting - character indexes. - """ - relative_token_line_plus1, token_col = token_pos - - # line number where we started tokenizing - start_line_num = bisect(line_starts, start) - 1 - - # line number of the token in the whole text - abs_token_line = relative_token_line_plus1 - 1 + start_line_num - - # if found in the first line, adjust the end column to account - # for the extra text - if relative_token_line_plus1 == 1: - token_col += start - line_starts[start_line_num] - - # Sometimes tokenizer errors report a line beyond the last one - if abs_token_line >= len(line_starts): - return line_starts[-1] - - return line_starts[abs_token_line] + token_col - - -def tokenize_python_to_unmatched_close_curly(source_text, start, line_starts): - """Apply Python's tokenize to source_text starting at index start - while matching open and close curly braces. When an unmatched - close curly brace is found, return its index. If not found, - return len(source_text). If there's a tokenization error, return - the position of the error. - """ - stream = StringIO(source_text) - stream.seek(start) - nesting = 0 - - try: - for kind, text, token_start, token_end, line_text \ - in tokenize.generate_tokens(stream.readline): - - if text == '{': - nesting += 1 - elif text == '}': - nesting -= 1 - if nesting < 0: - return token_pos_to_index(token_start, start, line_starts) - - except tokenize.TokenError as error: - (message, error_pos) = error.args - return token_pos_to_index(error_pos, start, line_starts) - - return len(source_text) - - -def tokenize_template(template_text): - r"""Given the text of a template, returns an iterator over - (tokenType, token, match) tuples. - - **Note**: this is template syntax tokenization, not Python - tokenization. - - When a non-literal token is matched, a client may call - iter.send(pos) on the iterator to reset the position in - template_text at which scanning will resume. - - This function provides a base level of tokenization which is - then refined by ParseContext.token_generator. - - >>> from pprint import * - >>> pprint(list((kind, text) for kind, text, _ in tokenize_template( - ... '%for x in range(10):\n% print x\n%end\njuicebox'))) - [('gybLines', '%for x in range(10):\n% print x'), - ('gybLinesClose', '%end'), - ('literal', 'juicebox')] - - >>> pprint(list((kind, text) for kind, text, _ in tokenize_template( - ... '''Nothing - ... % if x: - ... % for i in range(3): - ... ${i} - ... % end - ... % else: - ... THIS SHOULD NOT APPEAR IN THE OUTPUT - ... '''))) - [('literal', 'Nothing\n'), - ('gybLines', '% if x:\n% for i in range(3):'), - ('substitutionOpen', '${'), - ('literal', '\n'), - ('gybLinesClose', '% end'), - ('gybLines', '% else:'), - ('literal', 'THIS SHOULD NOT APPEAR IN THE OUTPUT\n')] - - >>> for kind, text, _ in tokenize_template(''' - ... This is $some$ literal stuff containing a ${substitution} - ... followed by a %{...} block: - ... %{ - ... # Python code - ... }% - ... and here $${are} some %-lines: - ... % x = 1 - ... % y = 2 - ... % if z == 3: - ... % print '${hello}' - ... % end - ... % for x in zz: - ... % print x - ... % # different indentation - ... % twice - ... and some lines that literally start with a %% token - ... %% first line - ... %% second line - ... '''): - ... print((kind, text.strip().split('\n',1)[0])) - ('literal', 'This is $some$ literal stuff containing a') - ('substitutionOpen', '${') - ('literal', 'followed by a %{...} block:') - ('gybBlockOpen', '%{') - ('literal', 'and here ${are} some %-lines:') - ('gybLines', '% x = 1') - ('gybLinesClose', '% end') - ('gybLines', '% for x in zz:') - ('gybLines', '% # different indentation') - ('gybLines', '% twice') - ('literal', 'and some lines that literally start with a % token') - """ - pos = 0 - end = len(template_text) - - saved_literal = [] - literal_first_match = None - - while pos < end: - m = tokenize_re.match(template_text, pos, end) - - # pull out the one matched key (ignoring internal patterns starting - # with _) - ((kind, text), ) = ( - (kind, text) for (kind, text) in list(m.groupdict().items()) - if text is not None and kind[0] != '_') - - if kind in ('literal', 'symbol'): - if len(saved_literal) == 0: - literal_first_match = m - # literals and symbols get batched together - saved_literal.append(text) - pos = None - else: - # found a non-literal. First yield any literal we've accumulated - if saved_literal != []: - yield 'literal', ''.join(saved_literal), literal_first_match - saved_literal = [] - - # Then yield the thing we found. If we get a reply, it's - # the place to resume tokenizing - pos = yield kind, text, m - - # If we were not sent a new position by our client, resume - # tokenizing at the end of this match. - if pos is None: - pos = m.end(0) - else: - # Client is not yet ready to process next token - yield - - if saved_literal != []: - yield 'literal', ''.join(saved_literal), literal_first_match - - -def split_gyb_lines(source_lines): - r"""Return a list of lines at which to split the incoming source - - These positions represent the beginnings of python line groups that - will require a matching %end construct if they are to be closed. - - >>> src = split_lines('''\ - ... if x: - ... print x - ... if y: # trailing comment - ... print z - ... if z: # another comment\ - ... ''') - >>> s = split_gyb_lines(src) - >>> len(s) - 2 - >>> src[s[0]] - ' print z\n' - >>> s[1] - len(src) - 0 - - >>> src = split_lines('''\ - ... if x: - ... if y: print 1 - ... if z: - ... print 2 - ... pass\ - ... ''') - >>> s = split_gyb_lines(src) - >>> len(s) - 1 - >>> src[s[0]] - ' if y: print 1\n' - - >>> src = split_lines('''\ - ... if x: - ... if y: - ... print 1 - ... print 2 - ... ''') - >>> s = split_gyb_lines(src) - >>> len(s) - 2 - >>> src[s[0]] - ' if y:\n' - >>> src[s[1]] - ' print 1\n' - """ - last_token_text, last_token_kind = None, None - unmatched_indents = [] - - dedents = 0 - try: - for token_kind, token_text, token_start, \ - (token_end_line, token_end_col), line_text \ - in tokenize.generate_tokens(lambda i=iter(source_lines): - next(i)): - - if token_kind in (tokenize.COMMENT, tokenize.ENDMARKER): - continue - - if token_text == '\n' and last_token_text == ':': - unmatched_indents.append(token_end_line) - - # The tokenizer appends dedents at EOF; don't consider - # those as matching indentations. Instead just save them - # up... - if last_token_kind == tokenize.DEDENT: - dedents += 1 - # And count them later, when we see something real. - if token_kind != tokenize.DEDENT and dedents > 0: - unmatched_indents = unmatched_indents[:-dedents] - dedents = 0 - - last_token_text, last_token_kind = token_text, token_kind - - except tokenize.TokenError: - # Let the later compile() call report the error - return [] - - if last_token_text == ':': - unmatched_indents.append(len(source_lines)) - - return unmatched_indents - - -def code_starts_with_dedent_keyword(source_lines): - r"""Return True iff the incoming Python source_lines begin with "else", - "elif", "except", or "finally". - - Initial comments and whitespace are ignored. - - >>> code_starts_with_dedent_keyword(split_lines('if x in y: pass')) - False - >>> code_starts_with_dedent_keyword(split_lines('except ifSomethingElse:')) - True - >>> code_starts_with_dedent_keyword( - ... split_lines('\n# comment\nelse: # yes')) - True - """ - token_text = None - for token_kind, token_text, _, _, _ \ - in tokenize.generate_tokens(lambda i=iter(source_lines): next(i)): - - if token_kind != tokenize.COMMENT and token_text.strip() != '': - break - - return token_text in ('else', 'elif', 'except', 'finally') - - -class ParseContext(object): - - """State carried through a parse of a template""" - - filename = '' - template = '' - line_starts = [] - code_start_line = -1 - code_text = None - tokens = None # The rest of the tokens - close_lines = False - - def __init__(self, filename, template=None): - self.filename = os.path.abspath(filename) - if sys.platform == 'win32': - self.filename = self.filename.replace('\\', '/') - if template is None: - with open(filename) as f: - self.template = f.read() - else: - self.template = template - self.line_starts = get_line_starts(self.template) - self.tokens = self.token_generator(tokenize_template(self.template)) - self.next_token() - - def pos_to_line(self, pos): - return bisect(self.line_starts, pos) - 1 - - def token_generator(self, base_tokens): - r"""Given an iterator over (kind, text, match) triples (see - tokenize_template above), return a refined iterator over - token_kinds. - - Among other adjustments to the elements found by base_tokens, - this refined iterator tokenizes python code embedded in - template text to help determine its true extent. The - expression "base_tokens.send(pos)" is used to reset the index at - which base_tokens resumes scanning the underlying text. - - >>> ctx = ParseContext('dummy', ''' - ... %for x in y: - ... % print x - ... % end - ... literally - ... ''') - >>> while ctx.token_kind: - ... print((ctx.token_kind, ctx.code_text or ctx.token_text)) - ... ignored = ctx.next_token() - ('literal', '\n') - ('gybLinesOpen', 'for x in y:\n') - ('gybLines', ' print x\n') - ('gybLinesClose', '% end') - ('literal', 'literally\n') - - >>> ctx = ParseContext('dummy', - ... '''Nothing - ... % if x: - ... % for i in range(3): - ... ${i} - ... % end - ... % else: - ... THIS SHOULD NOT APPEAR IN THE OUTPUT - ... ''') - >>> while ctx.token_kind: - ... print((ctx.token_kind, ctx.code_text or ctx.token_text)) - ... ignored = ctx.next_token() - ('literal', 'Nothing\n') - ('gybLinesOpen', 'if x:\n') - ('gybLinesOpen', ' for i in range(3):\n') - ('substitutionOpen', 'i') - ('literal', '\n') - ('gybLinesClose', '% end') - ('gybLinesOpen', 'else:\n') - ('literal', 'THIS SHOULD NOT APPEAR IN THE OUTPUT\n') - - >>> ctx = ParseContext('dummy', - ... '''% for x in [1, 2, 3]: - ... % if x == 1: - ... literal1 - ... % elif x > 1: # add output line here to fix bug - ... % if x == 2: - ... literal2 - ... % end - ... % end - ... % end - ... ''') - >>> while ctx.token_kind: - ... print((ctx.token_kind, ctx.code_text or ctx.token_text)) - ... ignored = ctx.next_token() - ('gybLinesOpen', 'for x in [1, 2, 3]:\n') - ('gybLinesOpen', ' if x == 1:\n') - ('literal', 'literal1\n') - ('gybLinesOpen', 'elif x > 1: # add output line here to fix bug\n') - ('gybLinesOpen', ' if x == 2:\n') - ('literal', 'literal2\n') - ('gybLinesClose', '% end') - ('gybLinesClose', '% end') - ('gybLinesClose', '% end') - """ - for self.token_kind, self.token_text, self.token_match in base_tokens: - kind = self.token_kind - self.code_text = None - - # Do we need to close the current lines? - self.close_lines = kind == 'gybLinesClose' - - # %{...}% and ${...} constructs - if kind.endswith('Open'): - - # Tokenize text that follows as Python up to an unmatched '}' - code_start = self.token_match.end(kind) - self.code_start_line = self.pos_to_line(code_start) - - close_pos = tokenize_python_to_unmatched_close_curly( - self.template, code_start, self.line_starts) - self.code_text = self.template[code_start:close_pos] - yield kind - - if (kind == 'gybBlockOpen'): - # Absorb any '}% \n' - m2 = gyb_block_close.match(self.template, close_pos) - if not m2: - raise ValueError("Invalid block closure") - next_pos = m2.end(0) - else: - assert kind == 'substitutionOpen' - # skip past the closing '}' - next_pos = close_pos + 1 - - # Resume tokenizing after the end of the code. - base_tokens.send(next_pos) - - elif kind == 'gybLines': - - self.code_start_line = self.pos_to_line( - self.token_match.start('gybLines')) - indentation = self.token_match.group('_indent') - - # Strip off the leading indentation and %-sign - source_lines = re.split( - '^' + re.escape(indentation), - self.token_match.group('gybLines') + '\n', - flags=re.MULTILINE)[1:] - - if code_starts_with_dedent_keyword(source_lines): - self.close_lines = True - - last_split = 0 - for line in split_gyb_lines(source_lines): - self.token_kind = 'gybLinesOpen' - self.code_text = ''.join(source_lines[last_split:line]) - yield self.token_kind - last_split = line - self.code_start_line += line - last_split - self.close_lines = False - - self.code_text = ''.join(source_lines[last_split:]) - if self.code_text: - self.token_kind = 'gybLines' - yield self.token_kind - else: - yield self.token_kind - - def next_token(self): - """Move to the next token""" - for kind in self.tokens: - return self.token_kind - - self.token_kind = None - - -_default_line_directive = \ - '// ###sourceLocation(file: "%(file)s", line: %(line)d)' - - -class ExecutionContext(object): - - """State we pass around during execution of a template""" - - def __init__(self, line_directive=_default_line_directive, - **local_bindings): - self.local_bindings = local_bindings - self.line_directive = line_directive - self.local_bindings['__context__'] = self - self.result_text = [] - self.last_file_line = None - - def append_text(self, text, file, line): - # see if we need to inject a line marker - if self.line_directive: - if (file, line) != self.last_file_line: - # We can only insert the line directive at a line break - if len(self.result_text) == 0 \ - or self.result_text[-1].endswith('\n'): - substitutions = {'file': file, 'line': line + 1} - format_str = self.line_directive + '\n' - self.result_text.append(format_str % substitutions) - # But if the new text contains any line breaks, we can create - # one - elif '\n' in text: - i = text.find('\n') - self.result_text.append(text[:i + 1]) - # and try again - self.append_text(text[i + 1:], file, line + 1) - return - - self.result_text.append(text) - self.last_file_line = (file, line + text.count('\n')) - - -class ASTNode(object): - - """Abstract base class for template AST nodes""" - - def __init__(self): - raise NotImplementedError("ASTNode.__init__ is not implemented.") - - def execute(self, context): - raise NotImplementedError("ASTNode.execute is not implemented.") - - def __str__(self, indent=''): - raise NotImplementedError("ASTNode.__str__ is not implemented.") - - def format_children(self, indent): - if not self.children: - return ' []' - - return '\n'.join( - ['', indent + '['] + - [x.__str__(indent + 4 * ' ') for x in self.children] + - [indent + ']']) - - -class Block(ASTNode): - - """A sequence of other AST nodes, to be executed in order""" - - children = [] - - def __init__(self, context): - self.children = [] - - while context.token_kind and not context.close_lines: - if context.token_kind == 'literal': - node = Literal - else: - node = Code - self.children.append(node(context)) - - def execute(self, context): - for x in self.children: - x.execute(context) - - def __str__(self, indent=''): - return indent + 'Block:' + self.format_children(indent) - - -class Literal(ASTNode): - - """An AST node that generates literal text""" - - def __init__(self, context): - self.text = context.token_text - start_position = context.token_match.start(context.token_kind) - self.start_line_number = context.pos_to_line(start_position) - self.filename = context.filename - context.next_token() - - def execute(self, context): - context.append_text(self.text, self.filename, self.start_line_number) - - def __str__(self, indent=''): - return '\n'.join( - [indent + x for x in ['Literal:'] + - strip_trailing_nl(self.text).split('\n')]) - - -class Code(ASTNode): - - """An AST node that is evaluated as Python""" - - code = None - children = () - kind = None - - def __init__(self, context): - - source = '' - source_line_count = 0 - - def accumulate_code(): - s = source + (context.code_start_line - source_line_count) * '\n' \ - + textwrap.dedent(context.code_text) - line_count = context.code_start_line + \ - context.code_text.count('\n') - context.next_token() - return s, line_count - - eval_exec = 'exec' - if context.token_kind.startswith('substitution'): - eval_exec = 'eval' - source, source_line_count = accumulate_code() - source = '(' + source.strip() + ')' - - else: - while context.token_kind == 'gybLinesOpen': - source, source_line_count = accumulate_code() - source += ' __children__[%d].execute(__context__)\n' % len( - self.children) - source_line_count += 1 - - self.children += (Block(context),) - - if context.token_kind == 'gybLinesClose': - context.next_token() - - if context.token_kind == 'gybLines': - source, source_line_count = accumulate_code() - - # Only handle a substitution as part of this code block if - # we don't already have some %-lines. - elif context.token_kind == 'gybBlockOpen': - - # Opening ${...} and %{...}% constructs - source, source_line_count = accumulate_code() - - self.filename = context.filename - self.start_line_number = context.code_start_line - self.code = compile(source, context.filename, eval_exec) - self.source = source - - def execute(self, context): - # Save __children__ from the local bindings - save_children = context.local_bindings.get('__children__') - # Execute the code with our __children__ in scope - context.local_bindings['__children__'] = self.children - context.local_bindings['__file__'] = self.filename - result = eval(self.code, context.local_bindings) - - if context.local_bindings['__children__'] is not self.children: - raise ValueError("The code is not allowed to mutate __children__") - # Restore the bindings - context.local_bindings['__children__'] = save_children - - # If we got a result, the code was an expression, so append - # its value - if result is not None \ - or (isinstance(result, str) and result != ''): - from numbers import Number, Integral - result_string = None - if isinstance(result, Number) and not isinstance(result, Integral): - result_string = repr(result) - else: - result_string = str(result) - context.append_text( - result_string, self.filename, self.start_line_number) - - def __str__(self, indent=''): - source_lines = re.sub(r'^\n', '', strip_trailing_nl( - self.source), flags=re.MULTILINE).split('\n') - if len(source_lines) == 1: - s = indent + 'Code: {' + source_lines[0] + '}' - else: - s = indent + 'Code:\n' + indent + '{\n' + '\n'.join( - indent + 4 * ' ' + l for l in source_lines - ) + '\n' + indent + '}' - return s + self.format_children(indent) - - -def expand(filename, line_directive=_default_line_directive, **local_bindings): - r"""Return the contents of the given template file, executed with the given - local bindings. - - >>> from tempfile import NamedTemporaryFile - >>> # On Windows, the name of a NamedTemporaryFile cannot be used to open - >>> # the file for a second time if delete=True. Therefore, we have to - >>> # manually handle closing and deleting this file to allow us to open - >>> # the file by its name across all platforms. - >>> f = NamedTemporaryFile(delete=False) - >>> f.write( - ... r'''--- - ... % for i in range(int(x)): - ... a pox on ${i} for epoxy - ... % end - ... ${120 + - ... - ... 3} - ... abc - ... ${"w\nx\nX\ny"} - ... z - ... ''') - >>> f.flush() - >>> result = expand( - ... f.name, - ... line_directive='//#sourceLocation(file: "%(file)s", ' + \ - ... 'line: %(line)d)', - ... x=2 - ... ).replace( - ... '"%s"' % f.name.replace('\\', '/'), '"dummy.file"') - >>> print(result, end='') - //#sourceLocation(file: "dummy.file", line: 1) - --- - //#sourceLocation(file: "dummy.file", line: 3) - a pox on 0 for epoxy - //#sourceLocation(file: "dummy.file", line: 3) - a pox on 1 for epoxy - //#sourceLocation(file: "dummy.file", line: 5) - 123 - //#sourceLocation(file: "dummy.file", line: 8) - abc - w - x - X - y - //#sourceLocation(file: "dummy.file", line: 10) - z - >>> f.close() - >>> os.remove(f.name) - """ - with open(filename) as f: - t = parse_template(filename, f.read()) - d = os.getcwd() - os.chdir(os.path.dirname(os.path.abspath(filename))) - try: - return execute_template( - t, line_directive=line_directive, **local_bindings) - finally: - os.chdir(d) - - -def parse_template(filename, text=None): - r"""Return an AST corresponding to the given template file. - - If text is supplied, it is assumed to be the contents of the file, - as a string. - - >>> print(parse_template('dummy.file', text= - ... '''% for x in [1, 2, 3]: - ... % if x == 1: - ... literal1 - ... % elif x > 1: # add output line after this line to fix bug - ... % if x == 2: - ... literal2 - ... % end - ... % end - ... % end - ... ''')) - Block: - [ - Code: - { - for x in [1, 2, 3]: - __children__[0].execute(__context__) - } - [ - Block: - [ - Code: - { - if x == 1: - __children__[0].execute(__context__) - elif x > 1: # add output line after this line to fix bug - __children__[1].execute(__context__) - } - [ - Block: - [ - Literal: - literal1 - ] - Block: - [ - Code: - { - if x == 2: - __children__[0].execute(__context__) - } - [ - Block: - [ - Literal: - literal2 - ] - ] - ] - ] - ] - ] - ] - - >>> print(parse_template( - ... 'dummy.file', - ... text='%for x in range(10):\n% print(x)\n%end\njuicebox')) - Block: - [ - Code: - { - for x in range(10): - __children__[0].execute(__context__) - } - [ - Block: - [ - Code: {print(x)} [] - ] - ] - Literal: - juicebox - ] - - >>> print(parse_template('/dummy.file', text= - ... '''Nothing - ... % if x: - ... % for i in range(3): - ... ${i} - ... % end - ... % else: - ... THIS SHOULD NOT APPEAR IN THE OUTPUT - ... ''')) - Block: - [ - Literal: - Nothing - Code: - { - if x: - __children__[0].execute(__context__) - else: - __children__[1].execute(__context__) - } - [ - Block: - [ - Code: - { - for i in range(3): - __children__[0].execute(__context__) - } - [ - Block: - [ - Code: {(i)} [] - Literal: - - ] - ] - ] - Block: - [ - Literal: - THIS SHOULD NOT APPEAR IN THE OUTPUT - ] - ] - ] - - >>> print(parse_template('dummy.file', text='''% - ... %for x in y: - ... % print(y) - ... ''')) - Block: - [ - Code: - { - for x in y: - __children__[0].execute(__context__) - } - [ - Block: - [ - Code: {print(y)} [] - ] - ] - ] - - >>> print(parse_template('dummy.file', text='''% - ... %if x: - ... % print(y) - ... AAAA - ... %else: - ... BBBB - ... ''')) - Block: - [ - Code: - { - if x: - __children__[0].execute(__context__) - else: - __children__[1].execute(__context__) - } - [ - Block: - [ - Code: {print(y)} [] - Literal: - AAAA - ] - Block: - [ - Literal: - BBBB - ] - ] - ] - - >>> print(parse_template('dummy.file', text='''% - ... %if x: - ... % print(y) - ... AAAA - ... %# This is a comment - ... %else: - ... BBBB - ... ''')) - Block: - [ - Code: - { - if x: - __children__[0].execute(__context__) - # This is a comment - else: - __children__[1].execute(__context__) - } - [ - Block: - [ - Code: {print(y)} [] - Literal: - AAAA - ] - Block: - [ - Literal: - BBBB - ] - ] - ] - - >>> print(parse_template('dummy.file', text='''\ - ... %for x in y: - ... AAAA - ... %if x: - ... BBBB - ... %end - ... CCCC - ... ''')) - Block: - [ - Code: - { - for x in y: - __children__[0].execute(__context__) - } - [ - Block: - [ - Literal: - AAAA - Code: - { - if x: - __children__[0].execute(__context__) - } - [ - Block: - [ - Literal: - BBBB - ] - ] - Literal: - CCCC - ] - ] - ] - """ - return Block(ParseContext(filename, text)) - - -def execute_template( - ast, line_directive=_default_line_directive, **local_bindings): - r"""Return the text generated by executing the given template AST. - - Keyword arguments become local variable bindings in the execution context - - >>> root_directory = os.path.abspath('/') - >>> file_name = (root_directory + 'dummy.file').replace('\\', '/') - >>> ast = parse_template(file_name, text= - ... '''Nothing - ... % if x: - ... % for i in range(3): - ... ${i} - ... % end - ... % else: - ... THIS SHOULD NOT APPEAR IN THE OUTPUT - ... ''') - >>> out = execute_template(ast, - ... line_directive='//#sourceLocation(file: "%(file)s", line: %(line)d)', - ... x=1) - >>> out = out.replace(file_name, "DUMMY-FILE") - >>> print(out, end="") - //#sourceLocation(file: "DUMMY-FILE", line: 1) - Nothing - //#sourceLocation(file: "DUMMY-FILE", line: 4) - 0 - //#sourceLocation(file: "DUMMY-FILE", line: 4) - 1 - //#sourceLocation(file: "DUMMY-FILE", line: 4) - 2 - - >>> ast = parse_template(file_name, text= - ... '''Nothing - ... % a = [] - ... % for x in range(3): - ... % a.append(x) - ... % end - ... ${a} - ... ''') - >>> out = execute_template(ast, - ... line_directive='//#sourceLocation(file: "%(file)s", line: %(line)d)', - ... x=1) - >>> out = out.replace(file_name, "DUMMY-FILE") - >>> print(out, end="") - //#sourceLocation(file: "DUMMY-FILE", line: 1) - Nothing - //#sourceLocation(file: "DUMMY-FILE", line: 6) - [0, 1, 2] - - >>> ast = parse_template(file_name, text= - ... '''Nothing - ... % a = [] - ... % for x in range(3): - ... % a.append(x) - ... % end - ... ${a} - ... ''') - >>> out = execute_template(ast, - ... line_directive='#line %(line)d "%(file)s"', x=1) - >>> out = out.replace(file_name, "DUMMY-FILE") - >>> print(out, end="") - #line 1 "DUMMY-FILE" - Nothing - #line 6 "DUMMY-FILE" - [0, 1, 2] - """ - execution_context = ExecutionContext( - line_directive=line_directive, **local_bindings) - ast.execute(execution_context) - return ''.join(execution_context.result_text) - - -def main(): - import argparse - import sys - - parser = argparse.ArgumentParser( - formatter_class=argparse.RawDescriptionHelpFormatter, - description='Generate Your Boilerplate!', epilog=''' - A GYB template consists of the following elements: - - - Literal text which is inserted directly into the output - - - %% or $$ in literal text, which insert literal '%' and '$' - symbols respectively. - - - Substitutions of the form ${}. The Python - expression is converted to a string and the result is inserted - into the output. - - - Python code delimited by %{...}%. Typically used to inject - definitions (functions, classes, variable bindings) into the - evaluation context of the template. Common indentation is - stripped, so you can add as much indentation to the beginning - of this code as you like - - - Lines beginning with optional whitespace followed by a single - '%' and Python code. %-lines allow you to nest other - constructs inside them. To close a level of nesting, use the - "%end" construct. - - - Lines beginning with optional whitespace and followed by a - single '%' and the token "end", which close open constructs in - %-lines. - - Example template: - - - Hello - - %{ - x = 42 - def succ(a): - return a+1 - }% - - I can assure you that ${x} < ${succ(x)} - - % if int(y) > 7: - % for i in range(3): - y is greater than seven! - % end - % else: - y is less than or equal to seven - % end - - - The End. - - - When run with "gyb -Dy=9", the output is - - - Hello - - - I can assure you that 42 < 43 - - y is greater than seven! - y is greater than seven! - y is greater than seven! - - - The End. - -''' - ) - parser.add_argument( - '-D', action='append', dest='defines', metavar='NAME=VALUE', - default=[], - help='''Bindings to be set in the template's execution context''') - - parser.add_argument( - 'file', type=argparse.FileType(), - help='Path to GYB template file (defaults to stdin)', nargs='?', - default=sys.stdin) - parser.add_argument( - '-o', dest='target', type=argparse.FileType('w'), - help='Output file (defaults to stdout)', default=sys.stdout) - parser.add_argument( - '--test', action='store_true', - default=False, help='Run a self-test') - parser.add_argument( - '--verbose-test', action='store_true', - default=False, help='Run a verbose self-test') - parser.add_argument( - '--dump', action='store_true', - default=False, help='Dump the parsed template to stdout') - parser.add_argument( - '--line-directive', - default=_default_line_directive, - help=''' - Line directive format string, which will be - provided 2 substitutions, `%%(line)d` and `%%(file)s`. - - Example: `#sourceLocation(file: "%%(file)s", line: %%(line)d)` - - The default works automatically with the `line-directive` tool, - which see for more information. - ''') - - args = parser.parse_args(sys.argv[1:]) - - if args.test or args.verbose_test: - import doctest - selfmod = sys.modules[__name__] - if doctest.testmod(selfmod, verbose=args.verbose_test or None).failed: - sys.exit(1) - - bindings = dict(x.split('=', 1) for x in args.defines) - ast = parse_template(args.file.name, args.file.read()) - if args.dump: - print(ast) - # Allow the template to open files and import .py files relative to its own - # directory - os.chdir(os.path.dirname(os.path.abspath(args.file.name))) - sys.path = ['.'] + sys.path - - args.target.write(execute_template(ast, args.line_directive, **bindings)) - - -if __name__ == '__main__': - main() diff --git a/Utils/gyb_utils.py b/Utils/gyb_utils.py deleted file mode 100644 index e73fd8c7..00000000 --- a/Utils/gyb_utils.py +++ /dev/null @@ -1,34 +0,0 @@ -#===-----------------------------------------------------------------------===// -# -# This source file is part of the Swift.org open source project -# -# Copyright (c) 2023 - 2024 Apple Inc. and the Swift project authors -# Licensed under Apache License v2.0 with Runtime Library Exception -# -# See https://swift.org/LICENSE.txt for license information -# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -# -#===-----------------------------------------------------------------------===// - -def autogenerated_warning(): - return """ -// ############################################################################# -// # # -// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # -// # # -// ############################################################################# -""" - -visibility_levels = ["internal", "public"] -def visibility_boilerplate(part): - if part == "internal": - return """ -// In single module mode, we need these declarations to be internal, -// but in regular builds we want them to be public. Unfortunately -// the current best way to do this is to duplicate all definitions. -#if COLLECTIONS_SINGLE_MODULE""" - - if part == "public": - return "#else // !COLLECTIONS_SINGLE_MODULE" - if part == "end": - return "#endif // COLLECTIONS_SINGLE_MODULE" diff --git a/Xcode/Collections.xcconfig b/Xcode/Collections.xcconfig index 80ac6f17..debfe73c 100644 --- a/Xcode/Collections.xcconfig +++ b/Xcode/Collections.xcconfig @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2023 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2023 - 2025 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information @@ -15,6 +15,9 @@ PRODUCT_BUNDLE_IDENTIFIER = org.swift.Collections SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator watchos watchsimulator appletvos appletvsimulator ARCHS = $(ARCHS_STANDARD) +OTHER_SWIFT_FLAGS = $(inherited) \ + -package-name CollectionsInternal + MACOSX_DEPLOYMENT_TARGET = 12.0 IPHONEOS_DEPLOYMENT_TARGET = 15.0 WATCHOS_DEPLOYMENT_TARGET = 8.0 diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index 984ed02b..94a6ec41 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -17,9 +17,6 @@ 7D48BCF02E51597200D7F6F7 /* Assertions+Containers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCEF2E51597200D7F6F7 /* Assertions+Containers.swift */; }; 7D48BCF22E51599200D7F6F7 /* CheckContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCF12E51599200D7F6F7 /* CheckContainer.swift */; }; 7D48BCF42E5159A300D7F6F7 /* StaccatoContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCF32E5159A300D7F6F7 /* StaccatoContainer.swift */; }; - 7D48BCFE2E5182CE00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCFD2E5182CE00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift */; }; - 7D48BCFF2E5182CE00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCFC2E5182CE00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift */; }; - 7D48BD002E5182CE00D7F6F7 /* LifetimeOverride.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCFA2E5182CE00D7F6F7 /* LifetimeOverride.swift */; }; 7D6FEE0F2E877870007C1B86 /* RefTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE0E2E877870007C1B86 /* RefTests.swift */; }; 7D6FEE102E877870007C1B86 /* MutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE0D2E877870007C1B86 /* MutTests.swift */; }; 7D6FEE162E8778CF007C1B86 /* Mut.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D6FEE142E8778CF007C1B86 /* Mut.swift */; }; @@ -42,6 +39,21 @@ 7D9B859929E4F74400B291CD /* BitArray+LosslessStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859329E4F74400B291CD /* BitArray+LosslessStringConvertible.swift */; }; 7D9B859A29E4F74400B291CD /* BitArray+RandomBits.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859429E4F74400B291CD /* BitArray+RandomBits.swift */; }; 7D9B859B29E4F74400B291CD /* BitArray+ExpressibleByStringLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859529E4F74400B291CD /* BitArray+ExpressibleByStringLiteral.swift */; }; + 7DAD899E2E8B09C300DD5786 /* UInt+first and last set bit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899C2E8B09C300DD5786 /* UInt+first and last set bit.swift */; }; + 7DAD899F2E8B09C300DD5786 /* UInt+reversed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899D2E8B09C300DD5786 /* UInt+reversed.swift */; }; + 7DAD89A02E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899A2E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */; }; + 7DAD89A12E8B09C300DD5786 /* Integer rank.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD899B2E8B09C300DD5786 /* Integer rank.swift */; }; + 7DAD89A52E8B09D900DD5786 /* _UnsafeBitSet+_Word.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89A32E8B09D900DD5786 /* _UnsafeBitSet+_Word.swift */; }; + 7DAD89A62E8B09D900DD5786 /* _UnsafeBitSet+Index.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89A42E8B09D900DD5786 /* _UnsafeBitSet+Index.swift */; }; + 7DAD89A72E8B09D900DD5786 /* _UnsafeBitSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89A22E8B09D900DD5786 /* _UnsafeBitSet.swift */; }; + 7DAD89B02E8B09EC00DD5786 /* LifetimeOverride.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89AA2E8B09EC00DD5786 /* LifetimeOverride.swift */; }; + 7DAD89B12E8B09EC00DD5786 /* RandomAccessCollection+Offsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89AB2E8B09EC00DD5786 /* RandomAccessCollection+Offsets.swift */; }; + 7DAD89B22E8B09EC00DD5786 /* UnsafeMutableBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89AD2E8B09EC00DD5786 /* UnsafeMutableBufferPointer+Extras.swift */; }; + 7DAD89B32E8B09EC00DD5786 /* Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89A92E8B09EC00DD5786 /* Descriptions.swift */; }; + 7DAD89B42E8B09EC00DD5786 /* UnsafeBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89AC2E8B09EC00DD5786 /* UnsafeBufferPointer+Extras.swift */; }; + 7DAD89B52E8B09EC00DD5786 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89A82E8B09EC00DD5786 /* Debugging.swift */; }; + 7DAD89B62E8B09EC00DD5786 /* UnsafeMutableRawBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89AE2E8B09EC00DD5786 /* UnsafeMutableRawBufferPointer+Extras.swift */; }; + 7DAD89B72E8B09EC00DD5786 /* UnsafeRawBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DAD89AF2E8B09EC00DD5786 /* UnsafeRawBufferPointer+Extras.swift */; }; 7DE91B2F29CA6721004483EB /* Collections.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DE91B2629CA6721004483EB /* Collections.framework */; }; 7DE9200D29CA70F3004483EB /* OrderedDictionary+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91E7529CA70F3004483EB /* OrderedDictionary+Equatable.swift */; }; 7DE9200E29CA70F3004483EB /* OrderedDictionary+ExpressibleByDictionaryLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91E7629CA70F3004483EB /* OrderedDictionary+ExpressibleByDictionaryLiteral.swift */; }; @@ -381,30 +393,6 @@ 7DE9221C29CA8576004483EB /* RangeReplaceableCollectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE921F729CA8576004483EB /* RangeReplaceableCollectionTests.swift */; }; 7DE9221D29CA8576004483EB /* DequeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE921F829CA8576004483EB /* DequeTests.swift */; }; 7DE9221E29CA8576004483EB /* MutableCollectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE921F929CA8576004483EB /* MutableCollectionTests.swift */; }; - 7DEBDAF829CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD429CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift */; }; - 7DEBDAF929CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD529CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift */; }; - 7DEBDAFA29CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD629CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift */; }; - 7DEBDAFB29CBEE5300ADC226 /* Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD729CBEE5300ADC226 /* Descriptions.swift */; }; - 7DEBDAFC29CBEE5300ADC226 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD829CBEE5300ADC226 /* Debugging.swift */; }; - 7DEBDB0129CBEE5300ADC226 /* _UnsafeBitSet+Index.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDADF29CBEE5300ADC226 /* _UnsafeBitSet+Index.swift */; }; - 7DEBDB0229CBEE5300ADC226 /* _UnsafeBitSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE029CBEE5300ADC226 /* _UnsafeBitSet.swift */; }; - 7DEBDB0329CBEE5300ADC226 /* _UnsafeBitSet+_Word.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE129CBEE5300ADC226 /* _UnsafeBitSet+_Word.swift */; }; - 7DEBDB0829CBEE5300ADC226 /* UInt+reversed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE829CBEE5300ADC226 /* UInt+reversed.swift */; }; - 7DEBDB0929CBEE5300ADC226 /* Integer rank.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE929CBEE5300ADC226 /* Integer rank.swift */; }; - 7DEBDB0A29CBEE5300ADC226 /* UInt+first and last set bit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAEA29CBEE5300ADC226 /* UInt+first and last set bit.swift */; }; - 7DEBDB0B29CBEE5300ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAEB29CBEE5300ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */; }; - 7DEBDB0E29CBF68900ADC226 /* Integer rank.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE929CBEE5300ADC226 /* Integer rank.swift */; }; - 7DEBDB0F29CBF68900ADC226 /* UInt+reversed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE829CBEE5300ADC226 /* UInt+reversed.swift */; }; - 7DEBDB1029CBF68900ADC226 /* UInt+first and last set bit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAEA29CBEE5300ADC226 /* UInt+first and last set bit.swift */; }; - 7DEBDB1129CBF68900ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAEB29CBEE5300ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */; }; - 7DEBDB1629CBF69F00ADC226 /* _UnsafeBitSet+Index.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDADF29CBEE5300ADC226 /* _UnsafeBitSet+Index.swift */; }; - 7DEBDB1729CBF69F00ADC226 /* _UnsafeBitSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE029CBEE5300ADC226 /* _UnsafeBitSet.swift */; }; - 7DEBDB1829CBF69F00ADC226 /* _UnsafeBitSet+_Word.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE129CBEE5300ADC226 /* _UnsafeBitSet+_Word.swift */; }; - 7DEBDB1A29CBF6B200ADC226 /* Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD729CBEE5300ADC226 /* Descriptions.swift */; }; - 7DEBDB1B29CBF6B200ADC226 /* UnsafeBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD529CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift */; }; - 7DEBDB1C29CBF6B200ADC226 /* Debugging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD829CBEE5300ADC226 /* Debugging.swift */; }; - 7DEBDB1D29CBF6B200ADC226 /* RandomAccessCollection+Offsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD629CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift */; }; - 7DEBDB1E29CBF6B200ADC226 /* UnsafeMutableBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD429CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift */; }; 7DEBDB6E29CCE44A00ADC226 /* SortedCollectionAPIChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB3029CCE43600ADC226 /* SortedCollectionAPIChecker.swift */; }; 7DEBDB6F29CCE44A00ADC226 /* MinimalMutableRangeReplaceableRandomAccessCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB3F29CCE43600ADC226 /* MinimalMutableRangeReplaceableRandomAccessCollection.swift */; }; 7DEBDB7029CCE44A00ADC226 /* ResettableValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB4229CCE43600ADC226 /* ResettableValue.swift */; }; @@ -478,18 +466,8 @@ 7D48BCF12E51599200D7F6F7 /* CheckContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckContainer.swift; sourceTree = ""; }; 7D48BCF32E5159A300D7F6F7 /* StaccatoContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaccatoContainer.swift; sourceTree = ""; }; 7D48BCF52E51651900D7F6F7 /* Package@swift-6.0.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Package@swift-6.0.swift"; path = "../Package@swift-6.0.swift"; sourceTree = SOURCE_ROOT; }; - 7D48BCF62E5172CF00D7F6F7 /* LifetimeOverride.swift.gyb */ = {isa = PBXFileReference; lastKnownFileType = text; path = LifetimeOverride.swift.gyb; sourceTree = ""; }; - 7D48BCF82E5172CF00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift.gyb */ = {isa = PBXFileReference; lastKnownFileType = text; path = "UnsafeMutableRawBufferPointer+Extras.swift.gyb"; sourceTree = ""; }; - 7D48BCF92E5172CF00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift.gyb */ = {isa = PBXFileReference; lastKnownFileType = text; path = "UnsafeRawBufferPointer+Extras.swift.gyb"; sourceTree = ""; }; - 7D48BCFA2E5182CE00D7F6F7 /* LifetimeOverride.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LifetimeOverride.swift; sourceTree = ""; }; - 7D48BCFC2E5182CE00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeMutableRawBufferPointer+Extras.swift"; sourceTree = ""; }; - 7D48BCFD2E5182CE00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeRawBufferPointer+Extras.swift"; sourceTree = ""; }; 7D5A64D229CCE8CC00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D329CCEE9A00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; - 7D5A64D429CCEF1500CB2595 /* generate-sources.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "generate-sources.sh"; sourceTree = ""; }; - 7D5A64D529CCEF1500CB2595 /* gyb_utils.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = gyb_utils.py; sourceTree = ""; }; - 7D5A64D629CCEF1500CB2595 /* gyb */ = {isa = PBXFileReference; lastKnownFileType = text; path = gyb; sourceTree = ""; }; - 7D5A64D729CCEF1500CB2595 /* gyb.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = gyb.py; sourceTree = ""; }; 7D5A64D829CCF0FE00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D6FEE0D2E877870007C1B86 /* MutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MutTests.swift; sourceTree = ""; }; 7D6FEE0E2E877870007C1B86 /* RefTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefTests.swift; sourceTree = ""; }; @@ -516,6 +494,21 @@ 7D9B859429E4F74400B291CD /* BitArray+RandomBits.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BitArray+RandomBits.swift"; sourceTree = ""; }; 7D9B859529E4F74400B291CD /* BitArray+ExpressibleByStringLiteral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BitArray+ExpressibleByStringLiteral.swift"; sourceTree = ""; }; 7D9B859C29E4F77D00B291CD /* Collections.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Collections.xctestplan; sourceTree = ""; }; + 7DAD899A2E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FixedWidthInteger+roundUpToPowerOfTwo.swift"; sourceTree = ""; }; + 7DAD899B2E8B09C300DD5786 /* Integer rank.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Integer rank.swift"; sourceTree = ""; }; + 7DAD899C2E8B09C300DD5786 /* UInt+first and last set bit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt+first and last set bit.swift"; sourceTree = ""; }; + 7DAD899D2E8B09C300DD5786 /* UInt+reversed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt+reversed.swift"; sourceTree = ""; }; + 7DAD89A22E8B09D900DD5786 /* _UnsafeBitSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _UnsafeBitSet.swift; sourceTree = ""; }; + 7DAD89A32E8B09D900DD5786 /* _UnsafeBitSet+_Word.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "_UnsafeBitSet+_Word.swift"; sourceTree = ""; }; + 7DAD89A42E8B09D900DD5786 /* _UnsafeBitSet+Index.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "_UnsafeBitSet+Index.swift"; sourceTree = ""; }; + 7DAD89A82E8B09EC00DD5786 /* Debugging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Debugging.swift; sourceTree = ""; }; + 7DAD89A92E8B09EC00DD5786 /* Descriptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Descriptions.swift; sourceTree = ""; }; + 7DAD89AA2E8B09EC00DD5786 /* LifetimeOverride.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LifetimeOverride.swift; sourceTree = ""; }; + 7DAD89AB2E8B09EC00DD5786 /* RandomAccessCollection+Offsets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RandomAccessCollection+Offsets.swift"; sourceTree = ""; }; + 7DAD89AC2E8B09EC00DD5786 /* UnsafeBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeBufferPointer+Extras.swift"; sourceTree = ""; }; + 7DAD89AD2E8B09EC00DD5786 /* UnsafeMutableBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeMutableBufferPointer+Extras.swift"; sourceTree = ""; }; + 7DAD89AE2E8B09EC00DD5786 /* UnsafeMutableRawBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeMutableRawBufferPointer+Extras.swift"; sourceTree = ""; }; + 7DAD89AF2E8B09EC00DD5786 /* UnsafeRawBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeRawBufferPointer+Extras.swift"; sourceTree = ""; }; 7DE91B2629CA6721004483EB /* Collections.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Collections.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7DE91B2E29CA6721004483EB /* CollectionsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CollectionsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 7DE91E7229CA70F3004483EB /* OrderedCollections.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = OrderedCollections.docc; sourceTree = ""; }; @@ -880,30 +873,6 @@ 7DE921F729CA8576004483EB /* RangeReplaceableCollectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RangeReplaceableCollectionTests.swift; sourceTree = ""; }; 7DE921F829CA8576004483EB /* DequeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DequeTests.swift; sourceTree = ""; }; 7DE921F929CA8576004483EB /* MutableCollectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutableCollectionTests.swift; sourceTree = ""; }; - 7DEBDAD129CBEE5200ADC226 /* Descriptions.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Descriptions.swift.gyb; sourceTree = ""; }; - 7DEBDAD229CBEE5200ADC226 /* RandomAccessCollection+Offsets.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "RandomAccessCollection+Offsets.swift.gyb"; sourceTree = ""; }; - 7DEBDAD429CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UnsafeMutableBufferPointer+Extras.swift"; sourceTree = ""; }; - 7DEBDAD529CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UnsafeBufferPointer+Extras.swift"; sourceTree = ""; }; - 7DEBDAD629CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RandomAccessCollection+Offsets.swift"; sourceTree = ""; }; - 7DEBDAD729CBEE5300ADC226 /* Descriptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Descriptions.swift; sourceTree = ""; }; - 7DEBDAD829CBEE5300ADC226 /* Debugging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Debugging.swift; sourceTree = ""; }; - 7DEBDAD929CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "UnsafeBufferPointer+Extras.swift.gyb"; sourceTree = ""; }; - 7DEBDADB29CBEE5300ADC226 /* _UnsafeBitSet.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = _UnsafeBitSet.swift.gyb; sourceTree = ""; }; - 7DEBDADC29CBEE5300ADC226 /* _UnsafeBitSet+_Word.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "_UnsafeBitSet+_Word.swift.gyb"; sourceTree = ""; }; - 7DEBDADD29CBEE5300ADC226 /* _UnsafeBitSet+Index.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "_UnsafeBitSet+Index.swift.gyb"; sourceTree = ""; }; - 7DEBDADF29CBEE5300ADC226 /* _UnsafeBitSet+Index.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "_UnsafeBitSet+Index.swift"; sourceTree = ""; }; - 7DEBDAE029CBEE5300ADC226 /* _UnsafeBitSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _UnsafeBitSet.swift; sourceTree = ""; }; - 7DEBDAE129CBEE5300ADC226 /* _UnsafeBitSet+_Word.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "_UnsafeBitSet+_Word.swift"; sourceTree = ""; }; - 7DEBDAE329CBEE5300ADC226 /* UInt+reversed.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "UInt+reversed.swift.gyb"; sourceTree = ""; }; - 7DEBDAE429CBEE5300ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb"; sourceTree = ""; }; - 7DEBDAE529CBEE5300ADC226 /* UInt+first and last set bit.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "UInt+first and last set bit.swift.gyb"; sourceTree = ""; }; - 7DEBDAE629CBEE5300ADC226 /* Integer rank.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Integer rank.swift.gyb"; sourceTree = ""; }; - 7DEBDAE829CBEE5300ADC226 /* UInt+reversed.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UInt+reversed.swift"; sourceTree = ""; }; - 7DEBDAE929CBEE5300ADC226 /* Integer rank.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Integer rank.swift"; sourceTree = ""; }; - 7DEBDAEA29CBEE5300ADC226 /* UInt+first and last set bit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UInt+first and last set bit.swift"; sourceTree = ""; }; - 7DEBDAEB29CBEE5300ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FixedWidthInteger+roundUpToPowerOfTwo.swift"; sourceTree = ""; }; - 7DEBDAEC29CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "UnsafeMutableBufferPointer+Extras.swift.gyb"; sourceTree = ""; }; - 7DEBDAED29CBEE5300ADC226 /* Debugging.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Debugging.swift.gyb; sourceTree = ""; }; 7DEBDB2129CCE43600ADC226 /* Combinatorics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Combinatorics.swift; sourceTree = ""; }; 7DEBDB2229CCE43600ADC226 /* TestContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestContext.swift; sourceTree = ""; }; 7DEBDB2329CCE43600ADC226 /* Assertions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Assertions.swift; sourceTree = ""; }; @@ -1353,20 +1322,19 @@ 7DE91F2229CA70F3004483EB /* InternalCollectionsUtilities */ = { isa = PBXGroup; children = ( - 7DEBDAD329CBEE5300ADC226 /* autogenerated */, 7DEBDAE229CBEE5300ADC226 /* IntegerTricks */, 7DEBDADA29CBEE5300ADC226 /* UnsafeBitSet */, 7DE91F2E29CA70F3004483EB /* CMakeLists.txt */, 7DE91F3029CA70F3004483EB /* _SortedCollection.swift */, 7DE91F3829CA70F3004483EB /* _UniqueCollection.swift */, - 7DEBDAED29CBEE5300ADC226 /* Debugging.swift.gyb */, - 7DEBDAD129CBEE5200ADC226 /* Descriptions.swift.gyb */, - 7D48BCF62E5172CF00D7F6F7 /* LifetimeOverride.swift.gyb */, - 7DEBDAD229CBEE5200ADC226 /* RandomAccessCollection+Offsets.swift.gyb */, - 7DEBDAD929CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift.gyb */, - 7DEBDAEC29CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift.gyb */, - 7D48BCF82E5172CF00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift.gyb */, - 7D48BCF92E5172CF00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift.gyb */, + 7DAD89A82E8B09EC00DD5786 /* Debugging.swift */, + 7DAD89A92E8B09EC00DD5786 /* Descriptions.swift */, + 7DAD89AA2E8B09EC00DD5786 /* LifetimeOverride.swift */, + 7DAD89AB2E8B09EC00DD5786 /* RandomAccessCollection+Offsets.swift */, + 7DAD89AC2E8B09EC00DD5786 /* UnsafeBufferPointer+Extras.swift */, + 7DAD89AD2E8B09EC00DD5786 /* UnsafeMutableBufferPointer+Extras.swift */, + 7DAD89AE2E8B09EC00DD5786 /* UnsafeMutableRawBufferPointer+Extras.swift */, + 7DAD89AF2E8B09EC00DD5786 /* UnsafeRawBufferPointer+Extras.swift */, ); path = InternalCollectionsUtilities; sourceTree = ""; @@ -1609,10 +1577,6 @@ 7DE921AC29CA78B2004483EB /* Utils */ = { isa = PBXGroup; children = ( - 7D5A64D429CCEF1500CB2595 /* generate-sources.sh */, - 7D5A64D629CCEF1500CB2595 /* gyb */, - 7D5A64D529CCEF1500CB2595 /* gyb_utils.py */, - 7D5A64D729CCEF1500CB2595 /* gyb.py */, 7D5A64D329CCEE9A00CB2595 /* README.md */, 7DE921B629CA78B2004483EB /* generate-docs.sh */, 7DE921AD29CA78B2004483EB /* run-benchmarks.sh */, @@ -1752,65 +1716,27 @@ path = DequeTests; sourceTree = ""; }; - 7DEBDAD329CBEE5300ADC226 /* autogenerated */ = { - isa = PBXGroup; - children = ( - 7DEBDAD829CBEE5300ADC226 /* Debugging.swift */, - 7DEBDAD729CBEE5300ADC226 /* Descriptions.swift */, - 7D48BCFA2E5182CE00D7F6F7 /* LifetimeOverride.swift */, - 7DEBDAD629CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift */, - 7DEBDAD529CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift */, - 7DEBDAD429CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift */, - 7D48BCFC2E5182CE00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift */, - 7D48BCFD2E5182CE00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift */, - ); - path = autogenerated; - sourceTree = ""; - }; 7DEBDADA29CBEE5300ADC226 /* UnsafeBitSet */ = { isa = PBXGroup; children = ( - 7DEBDADE29CBEE5300ADC226 /* autogenerated */, - 7DEBDADB29CBEE5300ADC226 /* _UnsafeBitSet.swift.gyb */, - 7DEBDADC29CBEE5300ADC226 /* _UnsafeBitSet+_Word.swift.gyb */, - 7DEBDADD29CBEE5300ADC226 /* _UnsafeBitSet+Index.swift.gyb */, + 7DAD89A22E8B09D900DD5786 /* _UnsafeBitSet.swift */, + 7DAD89A32E8B09D900DD5786 /* _UnsafeBitSet+_Word.swift */, + 7DAD89A42E8B09D900DD5786 /* _UnsafeBitSet+Index.swift */, ); path = UnsafeBitSet; sourceTree = ""; }; - 7DEBDADE29CBEE5300ADC226 /* autogenerated */ = { - isa = PBXGroup; - children = ( - 7DEBDAE029CBEE5300ADC226 /* _UnsafeBitSet.swift */, - 7DEBDAE129CBEE5300ADC226 /* _UnsafeBitSet+_Word.swift */, - 7DEBDADF29CBEE5300ADC226 /* _UnsafeBitSet+Index.swift */, - ); - path = autogenerated; - sourceTree = ""; - }; 7DEBDAE229CBEE5300ADC226 /* IntegerTricks */ = { isa = PBXGroup; children = ( - 7DEBDAE729CBEE5300ADC226 /* autogenerated */, - 7DEBDAE429CBEE5300ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb */, - 7DEBDAE629CBEE5300ADC226 /* Integer rank.swift.gyb */, - 7DEBDAE529CBEE5300ADC226 /* UInt+first and last set bit.swift.gyb */, - 7DEBDAE329CBEE5300ADC226 /* UInt+reversed.swift.gyb */, + 7DAD899A2E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */, + 7DAD899B2E8B09C300DD5786 /* Integer rank.swift */, + 7DAD899C2E8B09C300DD5786 /* UInt+first and last set bit.swift */, + 7DAD899D2E8B09C300DD5786 /* UInt+reversed.swift */, ); path = IntegerTricks; sourceTree = ""; }; - 7DEBDAE729CBEE5300ADC226 /* autogenerated */ = { - isa = PBXGroup; - children = ( - 7DEBDAEB29CBEE5300ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */, - 7DEBDAE929CBEE5300ADC226 /* Integer rank.swift */, - 7DEBDAEA29CBEE5300ADC226 /* UInt+first and last set bit.swift */, - 7DEBDAE829CBEE5300ADC226 /* UInt+reversed.swift */, - ); - path = autogenerated; - sourceTree = ""; - }; 7DEBDB1F29CCE43600ADC226 /* _CollectionsTestSupport */ = { isa = PBXGroup; children = ( @@ -2120,7 +2046,6 @@ 7D9B859829E4F74400B291CD /* BitArray+Descriptions.swift in Sources */, 7DE9212329CA70F4004483EB /* TreeSet+SetAlgebra isEqualSet.swift in Sources */, 7DE9214629CA70F4004483EB /* _HashSlot.swift in Sources */, - 7DEBDB0129CBEE5300ADC226 /* _UnsafeBitSet+Index.swift in Sources */, 7DE9204129CA70F3004483EB /* _UnsafeBitset.swift in Sources */, 7DE9208F29CA70F4004483EB /* RopeElement.swift in Sources */, 7DE9207229CA70F4004483EB /* BigString+Managing Breaks.swift in Sources */, @@ -2154,11 +2079,9 @@ 7DEBDB9D29CCE73D00ADC226 /* Collections.swift in Sources */, 7DE9215C29CA70F4004483EB /* _Bitmap.swift in Sources */, 7DE9207029CA70F4004483EB /* BigString+Chunk+RopeElement.swift in Sources */, - 7DEBDB0B29CBEE5300ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */, 7DE9213729CA70F4004483EB /* TreeSet+Sequence.swift in Sources */, 7DE9217629CA70F4004483EB /* TreeDictionary+Initializers.swift in Sources */, 7DE9207E29CA70F4004483EB /* BigString+UTF16View.swift in Sources */, - 7DEBDAFA29CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift in Sources */, 7DE9216F29CA70F4004483EB /* TreeDictionary+CustomReflectable.swift in Sources */, 7DE920D729CA70F4004483EB /* BitSet+SetAlgebra isSuperset.swift in Sources */, 7DE920F429CA70F4004483EB /* BitArray+Hashable.swift in Sources */, @@ -2167,7 +2090,6 @@ 7DE9207529CA70F4004483EB /* BigString+Insert.swift in Sources */, 7DE9216129CA70F4004483EB /* _HashNode+Structural merge.swift in Sources */, 7DE9202F29CA70F3004483EB /* OrderedSet+ExpressibleByArrayLiteral.swift in Sources */, - 7DEBDAFC29CBEE5300ADC226 /* Debugging.swift in Sources */, 7DE9202B29CA70F3004483EB /* OrderedSet+Equatable.swift in Sources */, 7DE920EA29CA70F4004483EB /* BitArray.swift in Sources */, 7DE920CB29CA70F4004483EB /* BitSet+Random.swift in Sources */, @@ -2187,10 +2109,17 @@ 7DE9202529CA70F3004483EB /* OrderedSet+Hashable.swift in Sources */, 7DE9203A29CA70F3004483EB /* OrderedSet+Partial SetAlgebra+Basics.swift in Sources */, 7DE920B529CA70F4004483EB /* _SortedCollection.swift in Sources */, + 7DAD89B02E8B09EC00DD5786 /* LifetimeOverride.swift in Sources */, + 7DAD89B12E8B09EC00DD5786 /* RandomAccessCollection+Offsets.swift in Sources */, + 7DAD89B22E8B09EC00DD5786 /* UnsafeMutableBufferPointer+Extras.swift in Sources */, + 7DAD89B32E8B09EC00DD5786 /* Descriptions.swift in Sources */, + 7DAD89B42E8B09EC00DD5786 /* UnsafeBufferPointer+Extras.swift in Sources */, + 7DAD89B52E8B09EC00DD5786 /* Debugging.swift in Sources */, + 7DAD89B62E8B09EC00DD5786 /* UnsafeMutableRawBufferPointer+Extras.swift in Sources */, + 7DAD89B72E8B09EC00DD5786 /* UnsafeRawBufferPointer+Extras.swift in Sources */, 7DE9206929CA70F4004483EB /* BigString+Chunk+Indexing by UTF16.swift in Sources */, 7DE9202A29CA70F3004483EB /* OrderedSet+Partial SetAlgebra isSuperset.swift in Sources */, 7DE9207D29CA70F4004483EB /* BigSubstring+UTF16View.swift in Sources */, - 7DEBDAF829CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift in Sources */, 7DE9217229CA70F4004483EB /* TreeDictionary+Sendable.swift in Sources */, 7DE9207729CA70F4004483EB /* Range+BigString.swift in Sources */, 7DE9204B29CA70F3004483EB /* _DequeBuffer.swift in Sources */, @@ -2204,7 +2133,6 @@ 7DE920DB29CA70F4004483EB /* BitSet+Hashable.swift in Sources */, 7DE9208C29CA70F4004483EB /* _RopeItem.swift in Sources */, 7D9B859A29E4F74400B291CD /* BitArray+RandomBits.swift in Sources */, - 7DEBDB0929CBEE5300ADC226 /* Integer rank.swift in Sources */, 7DE920EC29CA70F4004483EB /* BitArray+Collection.swift in Sources */, 7DE9201729CA70F3004483EB /* OrderedDictionary+Codable.swift in Sources */, 7DE9208329CA70F4004483EB /* BigString+CustomDebugStringConvertible.swift in Sources */, @@ -2225,6 +2153,10 @@ 7DE9217729CA70F4004483EB /* TreeDictionary+Keys.swift in Sources */, 7DE920DA29CA70F4004483EB /* BitSet._UnsafeHandle.swift in Sources */, 7DE920D129CA70F4004483EB /* BitSet.Index.swift in Sources */, + 7DAD899E2E8B09C300DD5786 /* UInt+first and last set bit.swift in Sources */, + 7DAD899F2E8B09C300DD5786 /* UInt+reversed.swift in Sources */, + 7DAD89A02E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */, + 7DAD89A12E8B09C300DD5786 /* Integer rank.swift in Sources */, 7DE9207429CA70F4004483EB /* BigString+ReplaceSubrange.swift in Sources */, 7DE920DC29CA70F4004483EB /* BitSet+Invariants.swift in Sources */, 7DE9216729CA70F4004483EB /* TreeDictionary+Equatable.swift in Sources */, @@ -2270,7 +2202,6 @@ 7DE9201229CA70F3004483EB /* OrderedDictionary+Elements.SubSequence.swift in Sources */, 7DE9204429CA70F3004483EB /* _HashTable.swift in Sources */, 7DE9206529CA70F4004483EB /* BigString+Ingester.swift in Sources */, - 7DEBDAFB29CBEE5300ADC226 /* Descriptions.swift in Sources */, 7DE9209129CA70F4004483EB /* Rope+_UnsafeHandle.swift in Sources */, 7DE920D529CA70F4004483EB /* BitSet.swift in Sources */, 7DE9206B29CA70F4004483EB /* BigString+Chunk+Indexing by Characters.swift in Sources */, @@ -2281,13 +2212,9 @@ 7DE9213D29CA70F4004483EB /* TreeSet+SetAlgebra isSubset.swift in Sources */, 7DE9203029CA70F3004483EB /* OrderedSet+SubSequence.swift in Sources */, 7DE9215529CA70F4004483EB /* _RawHashNode+UnsafeHandle.swift in Sources */, - 7D48BCFE2E5182CE00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift in Sources */, - 7D48BCFF2E5182CE00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift in Sources */, - 7D48BD002E5182CE00D7F6F7 /* LifetimeOverride.swift in Sources */, 7DE9209429CA70F4004483EB /* Rope+_UnmanagedLeaf.swift in Sources */, 7DE9208429CA70F4004483EB /* BigString+Equatable.swift in Sources */, 7DE9203729CA70F3004483EB /* OrderedSet+Partial SetAlgebra union.swift in Sources */, - 7DEBDAF929CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift in Sources */, 7DE9215229CA70F4004483EB /* _HashNode+Builder.swift in Sources */, 7DE9212929CA70F4004483EB /* TreeSet+SetAlgebra formUnion.swift in Sources */, 7DE920C129CA70F4004483EB /* BitSet+SetAlgebra subtract.swift in Sources */, @@ -2300,6 +2227,9 @@ 7DE920D629CA70F4004483EB /* BitSet+Equatable.swift in Sources */, 7DE9217A29CA70F4004483EB /* Heap+Descriptions.swift in Sources */, 7DE9216429CA70F4004483EB /* _HashNode.swift in Sources */, + 7DAD89A52E8B09D900DD5786 /* _UnsafeBitSet+_Word.swift in Sources */, + 7DAD89A62E8B09D900DD5786 /* _UnsafeBitSet+Index.swift in Sources */, + 7DAD89A72E8B09D900DD5786 /* _UnsafeBitSet.swift in Sources */, 7DE9201E29CA70F3004483EB /* OrderedSet+Partial SetAlgebra symmetricDifference.swift in Sources */, 7DE9207A29CA70F4004483EB /* BigString+UTF8View.swift in Sources */, 7DE9201329CA70F3004483EB /* OrderedDictionary+CustomReflectable.swift in Sources */, @@ -2315,7 +2245,6 @@ 7DE9214129CA70F4004483EB /* _HashNode+Initializers.swift in Sources */, 7D9B859929E4F74400B291CD /* BitArray+LosslessStringConvertible.swift in Sources */, 7DE9202D29CA70F3004483EB /* OrderedSet.swift in Sources */, - 7DEBDB0329CBEE5300ADC226 /* _UnsafeBitSet+_Word.swift in Sources */, 7DE9216329CA70F4004483EB /* _HashLevel.swift in Sources */, 7D9B859729E4F74400B291CD /* BitArray+Shifts.swift in Sources */, 7DE9216C29CA70F4004483EB /* TreeDictionary+Descriptions.swift in Sources */, @@ -2331,7 +2260,6 @@ 7DE920E729CA70F4004483EB /* BitArray+CustomReflectable.swift in Sources */, 7DE9207B29CA70F4004483EB /* BigSubstring+UnicodeScalarView.swift in Sources */, 7DE9209D29CA70F4004483EB /* Rope+Insert.swift in Sources */, - 7DEBDB0229CBEE5300ADC226 /* _UnsafeBitSet.swift in Sources */, 7DE9214329CA70F4004483EB /* _HashNode+Subtree Removals.swift in Sources */, 7DE9207929CA70F4004483EB /* BigString+UnicodeScalarView.swift in Sources */, 7DE9205329CA70F3004483EB /* _DequeBufferHeader.swift in Sources */, @@ -2402,10 +2330,8 @@ 7DE920F329CA70F4004483EB /* BitArray+Copy.swift in Sources */, 7DE9214029CA70F4004483EB /* _Hash.swift in Sources */, 7DE9205629CA70F3004483EB /* Deque+Testing.swift in Sources */, - 7DEBDB0829CBEE5300ADC226 /* UInt+reversed.swift in Sources */, 7DE9209329CA70F4004483EB /* Rope+Invariants.swift in Sources */, 7DE920EE29CA70F4004483EB /* BitArray+ExpressibleByArrayLiteral.swift in Sources */, - 7DEBDB0A29CBEE5300ADC226 /* UInt+first and last set bit.swift in Sources */, 7DE9214C29CA70F4004483EB /* _HashNode+Primitive Insertions.swift in Sources */, 7DE920BE29CA70F4004483EB /* BitSet+SetAlgebra formIntersection.swift in Sources */, 7DE9217329CA70F4004483EB /* TreeDictionary+Merge.swift in Sources */, @@ -2425,28 +2351,22 @@ 7DEBDB9029CCE44A00ADC226 /* TestContext.swift in Sources */, 7D48BCF22E51599200D7F6F7 /* CheckContainer.swift in Sources */, 7DE9221429CA8576004483EB /* OrderedSet Diffing Tests.swift in Sources */, - 7DEBDB1D29CBF6B200ADC226 /* RandomAccessCollection+Offsets.swift in Sources */, 7DEBDB8529CCE44A00ADC226 /* AllOnesRandomNumberGenerator.swift in Sources */, 7DE921FD29CA8576004483EB /* CombinatoricsChecks.swift in Sources */, 7DEBDB8B29CCE44A00ADC226 /* _CollectionState.swift in Sources */, 7DE9220229CA8576004483EB /* TreeDictionary Tests.swift in Sources */, 7DEBDB8429CCE44A00ADC226 /* CheckSequence.swift in Sources */, 7DEBDB8029CCE44A00ADC226 /* MinimalRandomAccessCollection.swift in Sources */, - 7DEBDB0F29CBF68900ADC226 /* UInt+reversed.swift in Sources */, - 7DEBDB1E29CBF6B200ADC226 /* UnsafeMutableBufferPointer+Extras.swift in Sources */, 7DE9221C29CA8576004483EB /* RangeReplaceableCollectionTests.swift in Sources */, 7DE9220429CA8576004483EB /* TreeHashedCollections Fixtures.swift in Sources */, 7DEBDB7A29CCE44A00ADC226 /* SetAPIChecker.swift in Sources */, 7DE9221B29CA8576004483EB /* DequeInternals.swift in Sources */, 7DEBDB6E29CCE44A00ADC226 /* SortedCollectionAPIChecker.swift in Sources */, 7DE9220929CA8576004483EB /* BitArrayTests.swift in Sources */, - 7DEBDB1C29CBF6B200ADC226 /* Debugging.swift in Sources */, 7DE9221629CA8576004483EB /* OrderedSet.UnorderedView Tests.swift in Sources */, 7DEBDB7529CCE44A00ADC226 /* MinimalCollection.swift in Sources */, - 7DEBDB1029CBF68900ADC226 /* UInt+first and last set bit.swift in Sources */, 7DEBDB8C29CCE44A00ADC226 /* MinimalIterator.swift in Sources */, 7DEBDB8829CCE44A00ADC226 /* MinimalSequence.swift in Sources */, - 7DEBDB1129CBF68900ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */, 7DE921FE29CA8576004483EB /* Hash.swift in Sources */, 7DEBDB8929CCE44A00ADC226 /* Combinatorics.swift in Sources */, 7DE9221A29CA8576004483EB /* HeapNodeTests.swift in Sources */, @@ -2469,7 +2389,6 @@ 7DE9220329CA8576004483EB /* Colliders.swift in Sources */, 7DE9221729CA8576004483EB /* OrderedSetTests.swift in Sources */, 7DE9221D29CA8576004483EB /* DequeTests.swift in Sources */, - 7DEBDB1A29CBF6B200ADC226 /* Descriptions.swift in Sources */, 7DE921FA29CA8576004483EB /* UtilitiesTests.swift in Sources */, 7DE9220A29CA8576004483EB /* TestRope.swift in Sources */, 7DE9220529CA8576004483EB /* TreeDictionary.Values Tests.swift in Sources */, @@ -2483,7 +2402,6 @@ 7DE921FB29CA8576004483EB /* MinimalTypeConformances.swift in Sources */, 7DEBDB8129CCE44A00ADC226 /* CheckCollection.swift in Sources */, 7DEBDB7229CCE44A00ADC226 /* MinimalBidirectionalCollection.swift in Sources */, - 7DEBDB1B29CBF6B200ADC226 /* UnsafeBufferPointer+Extras.swift in Sources */, 7DEBDB8729CCE44A00ADC226 /* MinimalMutableRandomAccessCollection.swift in Sources */, 7DEBDB7829CCE44A00ADC226 /* Assertions.swift in Sources */, 7DE9220D29CA8576004483EB /* TestBigString.swift in Sources */, @@ -2494,12 +2412,9 @@ 7DE9220E29CA8576004483EB /* SampleStrings.swift in Sources */, 7D48BCEE2E5158A100D7F6F7 /* BoxTests.swift in Sources */, 7DEBDB9129CCE44A00ADC226 /* CollectionTestCase.swift in Sources */, - 7DEBDB1829CBF69F00ADC226 /* _UnsafeBitSet+_Word.swift in Sources */, 7DE921B929CA81DC004483EB /* _SortedCollection.swift in Sources */, - 7DEBDB1629CBF69F00ADC226 /* _UnsafeBitSet+Index.swift in Sources */, 7DEBDB7B29CCE44A00ADC226 /* IndexRangeCollection.swift in Sources */, 7DE9221929CA8576004483EB /* HeapTests.swift in Sources */, - 7DEBDB1729CBF69F00ADC226 /* _UnsafeBitSet.swift in Sources */, 7DEBDB7E29CCE44A00ADC226 /* CheckComparable.swift in Sources */, 7DEBDB7C29CCE44A00ADC226 /* MinimalDecoder.swift in Sources */, 7DE9220829CA8576004483EB /* BitSetTests.swift in Sources */, @@ -2510,7 +2425,6 @@ 7DEBDB9229CCE44A00ADC226 /* StringConvertibleValue.swift in Sources */, 7DEBDB6F29CCE44A00ADC226 /* MinimalMutableRangeReplaceableRandomAccessCollection.swift in Sources */, 7DE9220129CA8576004483EB /* TreeDictionary.Keys Tests.swift in Sources */, - 7DEBDB0E29CBF68900ADC226 /* Integer rank.swift in Sources */, 7DE9220729CA8576004483EB /* BitSet.Counted Tests.swift in Sources */, 7DE9220F29CA8576004483EB /* OrderedDictionary Tests.swift in Sources */, 7D48BCDF2E51558700D7F6F7 /* TestPrintable.swift in Sources */,