Skip to content

Commit d44e5ef

Browse files
committed
Restore the Ability to Build with 5.6
We still support building with tools from Xcode 13, so we cannot adopt features after Swift 5.5. Recreate UMRP.alignedUp(toMultipleOf:) for this environment and conditionalize docc support in the build script on the newer language features being around.
1 parent 47dcde4 commit d44e5ef

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.6
1+
// swift-tools-version:5.5
22

33
import PackageDescription
44
import Foundation
@@ -142,9 +142,11 @@ let package = Package(
142142
]
143143
)
144144

145-
// If `SWIFTCI_USE_LOCAL_DEPS` is set, we are in a CI enviornment that might disallow
145+
#if swift(>=5.6)
146+
// If `SWIFTCI_USE_LOCAL_DEPS` is set, we are in a CI enviornment that might disallow
146147
// internet access, so we can't load swift-docc-plugin. Simply don't load it in these
147148
// environments because we don't build docc in CI at the moment.
148149
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
149150
package.dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"))
150151
}
152+
#endif

Sources/SwiftSyntax/BumpPtrAllocator.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public class BumpPtrAllocator {
119119
/// Check if the address is managed by this allocator.
120120
public func contains(address: UnsafeRawPointer) -> Bool {
121121
func test(_ slab: Slab) -> Bool {
122-
slab.baseAddress! <= address && address < slab.baseAddress! + slab.count
122+
UnsafeRawPointer(slab.baseAddress!) <= address && address < UnsafeRawPointer(slab.baseAddress!) + slab.count
123123
}
124124
return slabs.contains(where: test(_:)) || customSizeSlabs.contains(where: test(_:))
125125
}
@@ -145,3 +145,24 @@ public class BumpPtrAllocator {
145145
_totalBytesAllocated
146146
}
147147
}
148+
149+
// MARK: Compatibilty Shims
150+
151+
#if swift(<5.7)
152+
extension UnsafeMutableRawPointer {
153+
/// Obtain the next pointer whose bit pattern is a multiple of alignment.
154+
///
155+
/// - Parameter alignment: The alignment of the returned pointer, in bytes.
156+
/// Alignment must be a whole power of 2.
157+
/// - Returns: A pointer aligned to `alignment`.
158+
fileprivate func alignedUp(toMultipleOf alignment: Int) -> Self {
159+
let mask = UInt(alignment) &- 1
160+
assert(
161+
alignment > 0 && UInt(alignment) & mask == 0,
162+
"alignment must be a whole power of 2."
163+
)
164+
let bits = (UInt(bitPattern: self) &+ mask) & ~mask
165+
return .init(bitPattern: bits)!
166+
}
167+
}
168+
#endif

0 commit comments

Comments
 (0)