File tree Expand file tree Collapse file tree 5 files changed +15
-37
lines changed Expand file tree Collapse file tree 5 files changed +15
-37
lines changed Original file line number Diff line number Diff line change 1010//
1111//===----------------------------------------------------------------------===//
1212
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
3314
3415/// Provides API to get an atomically increasing counter value.
3516struct AtomicCounter {
3617 /// Get an atomically increasing counter value.
3718 static func next( ) -> UInt64 {
38- return AtomicCounter . cswiftsyntax_get_unique_counter ( )
19+ return cswiftsyntax_get_unique_counter ( )
3920 }
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- } ( )
4521}
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"
22
33uint64_t cswiftsyntax_get_unique_counter (void ) {
44 static _Atomic uint64_t counter = 0 ;
You can’t perform that action at this time.
0 commit comments