10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- #if SWIFT_SYNTAX_BUILD_USING_CMAKE
14
- // The CMake bulid of swift-syntax does not build the _AtomicBool module because swift-syntax's CMake build is
15
- // Swift-only. Fake an `AtomicBool` type that is not actually atomic. This should be acceptable for the following
16
- // reasons:
17
- // - `AtomicBool` is only used for the `hasParent` assertion, so release compilers don't rely on it
18
- // - The compiler is single-threaded so it it is safe from race conditions on `AtomicBool`.
19
- fileprivate struct AtomicBool {
20
- var value : Bool
21
-
22
- init ( initialValue: Bool ) {
23
- self . value = initialValue
24
- }
25
- }
13
+ #if swift(>=6.0)
14
+ private import _SwiftSyntaxCShims
26
15
#else
27
- import _SwiftSyntaxCShims
16
+ @ _implementationOnly import _SwiftSyntaxCShims
28
17
#endif
29
18
30
19
/// A syntax arena owns the memory for all syntax nodes within it.
@@ -69,7 +58,7 @@ public class SyntaxArena {
69
58
///
70
59
/// - Important: This is only intended to be used for assertions to catch
71
60
/// retain cycles in syntax arenas.
72
- fileprivate var hasParent : AtomicBool
61
+ fileprivate let hasParent : UnsafeMutablePointer < AtomicBool >
73
62
#endif
74
63
75
64
/// Construct a new ``SyntaxArena`` in which syntax nodes can be allocated.
@@ -81,14 +70,17 @@ public class SyntaxArena {
81
70
self . allocator = BumpPtrAllocator ( initialSlabSize: slabSize)
82
71
self . childRefs = [ ]
83
72
#if DEBUG || SWIFTSYNTAX_ENABLE_ASSERTIONS
84
- self . hasParent = AtomicBool ( initialValue : false )
73
+ self . hasParent = swiftsyntax_atomic_bool_create ( false )
85
74
#endif
86
75
}
87
76
88
77
deinit {
89
78
for child in childRefs {
90
79
child. release ( )
91
80
}
81
+ #if DEBUG || SWIFTSYNTAX_ENABLE_ASSERTIONS
82
+ swiftsyntax_atomic_bool_destroy ( self . hasParent)
83
+ #endif
92
84
}
93
85
94
86
/// Allocates a buffer of `RawSyntax?` with the given count, then returns the
@@ -158,7 +150,7 @@ public class SyntaxArena {
158
150
159
151
#if DEBUG || SWIFTSYNTAX_ENABLE_ASSERTIONS
160
152
precondition (
161
- !self . hasParent. value ,
153
+ !swiftsyntax_atomic_bool_get ( self . hasParent) ,
162
154
" an arena can't have a new child once it's owned by other arenas "
163
155
)
164
156
#endif
@@ -300,14 +292,14 @@ struct SyntaxArenaRef: Hashable, @unchecked Sendable {
300
292
}
301
293
302
294
#if DEBUG || SWIFTSYNTAX_ENABLE_ASSERTIONS
303
- /// Accessor for ther underlying's `SyntaxArena.hasParent`
295
+ /// Accessor for the underlying's `SyntaxArena.hasParent`
304
296
var hasParent : Bool {
305
- value. hasParent. value
297
+ swiftsyntax_atomic_bool_get ( value. hasParent)
306
298
}
307
299
308
300
/// Sets the `SyntaxArena.hasParent` on the referenced arena.
309
301
func setHasParent( _ newValue: Bool ) {
310
- value. hasParent. value = newValue
302
+ swiftsyntax_atomic_bool_set ( value. hasParent, newValue)
311
303
}
312
304
#endif
313
305
0 commit comments