Skip to content

Commit fe0fc8b

Browse files
committed
Avoid confusing Swift 5.7 with _pointerBitWidth conditionals
#if conditional parsing is evidently broken in 5.7, and it gets confused unless things are arranged just right. Things seem to work as long as the `compiler(>=5.9)` conditional is put on its own `#if` construct on the topmost level — so let’s do that for now.
1 parent 48fad5a commit fe0fc8b

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

Sources/Atomics/Primitives/Primitives.native.swift.gyb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
}%
1616
${autogenerated_warning()}
1717

18-
#if ATOMICS_NATIVE_BUILTINS
18+
// FIXME: The conditionals below have been carefully constructed to
19+
// avoid confusing Swift 5.7; they can be sanitized once we drop support
20+
// for that version.
21+
#if compiler(>=5.9)
22+
#if !ATOMICS_NATIVE_BUILTINS
23+
#error("swift-atomics requires native builtins on Swift 5.9")
24+
#endif
1925
import Builtin
2026

2127
@_alwaysEmitIntoClient
@@ -39,7 +45,7 @@ internal func _atomicMemoryFence(
3945
% for (swiftType, builtinType, alignment) in nativePrimitives:
4046

4147
% if builtinType == "Int128":
42-
#if compiler(>=5.9) && _pointerBitWidth(_64)
48+
#if _pointerBitWidth(_64)
4349
% end
4450
@usableFromInline
4551
@frozen
@@ -267,14 +273,18 @@ extension UnsafeMutablePointer where Pointee == ${swiftType} {
267273
% end
268274
% end
269275

270-
#if compiler(>=5.9) && _pointerBitWidth(_64)
276+
#if _pointerBitWidth(_64)
271277
@usableFromInline internal typealias _AtomicIntStorage = _AtomicInt64Storage
272278
@usableFromInline internal typealias _AtomicDoubleWordStorage = _AtomicInt128Storage
273-
#elseif compiler(>=5.9) && _pointerBitWidth(_32)
279+
#elseif _pointerBitWidth(_32)
274280
@usableFromInline internal typealias _AtomicIntStorage = _AtomicInt32Storage
275281
@usableFromInline internal typealias _AtomicDoubleWordStorage = _AtomicInt64Storage
276282
#else
277283
#error("Unexpected pointer bit width")
278284
#endif
279285

280-
#endif // ATOMICS_NATIVE_BUILTINS
286+
#else // compiler(>=5.9)
287+
#if ATOMICS_NATIVE_BUILTINS
288+
#error("swift-atomics requires C shims on Swift versions below 5.9")
289+
#endif
290+
#endif // compiler(>=5.9)

Sources/Atomics/Primitives/autogenerated/Primitives.native.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
// #############################################################################
1919

2020

21-
#if ATOMICS_NATIVE_BUILTINS
21+
// FIXME: The conditionals below have been carefully constructed to
22+
// avoid confusing Swift 5.7; they can be sanitized once we drop support
23+
// for that version.
24+
#if compiler(>=5.9)
25+
#if !ATOMICS_NATIVE_BUILTINS
26+
#error("swift-atomics requires native builtins on Swift 5.9")
27+
#endif
2228
import Builtin
2329

2430
@_alwaysEmitIntoClient
@@ -2110,7 +2116,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage {
21102116
}
21112117
}
21122118

2113-
#if compiler(>=5.9) && _pointerBitWidth(_64)
2119+
#if _pointerBitWidth(_64)
21142120
@usableFromInline
21152121
@frozen
21162122
@_alignment(16)
@@ -2438,14 +2444,18 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt128Storage {
24382444
}
24392445
#endif
24402446

2441-
#if compiler(>=5.9) && _pointerBitWidth(_64)
2447+
#if _pointerBitWidth(_64)
24422448
@usableFromInline internal typealias _AtomicIntStorage = _AtomicInt64Storage
24432449
@usableFromInline internal typealias _AtomicDoubleWordStorage = _AtomicInt128Storage
2444-
#elseif compiler(>=5.9) && _pointerBitWidth(_32)
2450+
#elseif _pointerBitWidth(_32)
24452451
@usableFromInline internal typealias _AtomicIntStorage = _AtomicInt32Storage
24462452
@usableFromInline internal typealias _AtomicDoubleWordStorage = _AtomicInt64Storage
24472453
#else
24482454
#error("Unexpected pointer bit width")
24492455
#endif
24502456

2451-
#endif // ATOMICS_NATIVE_BUILTINS
2457+
#else // compiler(>=5.9)
2458+
#if ATOMICS_NATIVE_BUILTINS
2459+
#error("swift-atomics requires C shims on Swift versions below 5.9")
2460+
#endif
2461+
#endif // compiler(>=5.9)

Sources/Atomics/Types/DoubleWord.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if ATOMICS_NATIVE_BUILTINS
13+
// FIXME: The conditionals below have been carefully constructed to
14+
// avoid confusing Swift 5.7; they can be sanitized once we drop support
15+
// for that version.
16+
#if compiler(>=5.9)
17+
#if !ATOMICS_NATIVE_BUILTINS
18+
#error("swift-atomics requires native builtins on Swift 5.9")
19+
#endif
20+
1421
import Builtin
1522

16-
#if compiler(>=5.9) && _pointerBitWidth(_32)
23+
#if _pointerBitWidth(_32)
1724
@frozen
1825
@_alignment(8)
1926
public struct DoubleWord {
@@ -29,7 +36,7 @@ public struct DoubleWord {
2936
self.second = second
3037
}
3138
}
32-
#elseif compiler(>=5.9) && _pointerBitWidth(_64)
39+
#elseif _pointerBitWidth(_64)
3340
@frozen
3441
@_alignment(16)
3542
public struct DoubleWord {
@@ -63,10 +70,14 @@ extension DoubleWord {
6370
}
6471
}
6572

66-
#else // !ATOMICS_NATIVE_BUILTINS
73+
#else // compiler(>=5.9)
74+
75+
#if ATOMICS_NATIVE_BUILTINS
76+
#error("swift-atomics requires C shims on Swift versions below 5.9")
77+
#endif
6778
import _AtomicsShims
6879
public typealias DoubleWord = _AtomicsShims.DoubleWord
69-
#endif
80+
#endif // compiler(>=5.9)
7081

7182
extension DoubleWord {
7283
/// Initialize a new `DoubleWord` value given its high- and

0 commit comments

Comments
 (0)