File tree 5 files changed +15
-37
lines changed
5 files changed +15
-37
lines changed Original file line number Diff line number Diff line change 10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- // This is using the C function from '_CSwiftSyntax/src/atomic-counter.c' by
14
- // dynamically loading it using `dlsym`. The reason this mechanism is used
15
- // instead of importing a header is so that we preserve the property that
16
- // SwiftSyntax is a self-contained Swift module.
17
- // (also see '_CSwiftSyntax/include/README.md')
18
-
19
- #if os(Linux)
20
- import Glibc
21
- #else
22
- import Darwin. C
23
- #endif
24
-
25
- #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
26
- fileprivate let RTLD_DEFAULT = UnsafeMutableRawPointer ( bitPattern: - 2 )
27
- #elseif os(Linux)
28
- fileprivate let RTLD_DEFAULT = UnsafeMutableRawPointer ( bitPattern: 0 )
29
- #endif
30
-
31
- fileprivate typealias get_unique_counter_ty = ( @convention ( c) ( ) -> UInt64 )
32
- fileprivate let get_unique_counter_str = " cswiftsyntax_get_unique_counter "
13
+ @_implementationOnly import _CSwiftSyntax
33
14
34
15
/// Provides API to get an atomically increasing counter value.
35
16
struct AtomicCounter {
36
17
/// Get an atomically increasing counter value.
37
18
static func next( ) -> UInt64 {
38
- return AtomicCounter . cswiftsyntax_get_unique_counter ( )
19
+ return cswiftsyntax_get_unique_counter ( )
39
20
}
40
-
41
- static fileprivate let cswiftsyntax_get_unique_counter : get_unique_counter_ty = { ( ) -> get_unique_counter_ty in
42
- let ptr = dlsym ( RTLD_DEFAULT, get_unique_counter_str) !
43
- return unsafeBitCast ( ptr, to: get_unique_counter_ty. self)
44
- } ( )
45
21
}
Original file line number Diff line number Diff line change
1
+ This module is an implementation detail of SwiftSyntax and does not export
2
+ any public API. As such, any uses of it inside SwiftSyntax should import it
3
+ with the ` @_implementationOnly ` attribute (available since Swift 5.1).
4
+
5
+ This preserves the property that SwiftSyntax is a self-contained Swift
6
+ module, meaning that when distributing it, we do not also have to bundle
7
+ these private headers or use any dynamic symbol loading tricks that require
8
+ additional linker flags to be passed on some platforms (see
9
+ [ SR-11293] ( https://bugs.swift.org/browse/SR-11293 ) , for example).
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ #include <stdint.h>
2
+
3
+ uint64_t cswiftsyntax_get_unique_counter (void );
Original file line number Diff line number Diff line change 1
- #include <stdint.h>
1
+ #include "atomic-counter.h"
2
2
3
3
uint64_t cswiftsyntax_get_unique_counter (void ) {
4
4
static _Atomic uint64_t counter = 0 ;
You can’t perform that action at this time.
0 commit comments