Skip to content

Commit a820410

Browse files
authored
Merge pull request #1091 from apple/revert-1068-revert-1066-revert-392944016fcfc16ea07fe8658c2c5d23cffa6433
Revert "Revert "Revert "Eliminate SWIFT_SYNTAX_ALWAYS_SINGLE_THREADED"""
2 parents b0b5f8d + b326356 commit a820410

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ if (NOT SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT)
4242
$<$<COMPILE_LANGUAGE:Swift>:-disable-implicit-string-processing-module-import>)
4343
endif()
4444

45+
# Force single-threaded-only syntax trees to eliminate the Darwin
46+
# dependency in the compiler.
47+
add_compile_definitions(
48+
$<$<COMPILE_LANGUAGE:Swift>:SWIFT_SYNTAX_ALWAYS_SINGLE_THREADED>
49+
)
50+
4551
add_subdirectory(Sources)
4652

4753
export(EXPORT SwiftSyntaxTargets

Sources/SwiftSyntax/SyntaxText.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if !SWIFT_SYNTAX_ALWAYS_SINGLE_THREADED
14+
#if canImport(Darwin)
15+
@_implementationOnly import Darwin
16+
#elseif canImport(Glibc)
17+
@_implementationOnly import Glibc
18+
#endif
19+
#endif
20+
1321
/// Represent a string.
1422
///
1523
/// This type does not own the string data. The data reside in some other buffer
@@ -212,17 +220,17 @@ extension String {
212220
}
213221
}
214222

215-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(Linux) || os(FreeBSD) || os(OpenBSD)
216-
@_silgen_name("memcmp")
217-
public func memcmp(_: UnsafeRawPointer?, _: UnsafeRawPointer?, _: Int) -> Int32
218-
#endif
219-
220223
private func compareMemory(
221224
_ s1: UnsafePointer<UInt8>, _ s2: UnsafePointer<UInt8>, _ count: Int
222225
) -> Bool {
223226
assert(count >= 0)
224-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(Linux) || os(FreeBSD) || os(OpenBSD)
225-
return memcmp(s1, s2, count) == 0
227+
#if SWIFT_SYNTAX_ALWAYS_SINGLE_THREADED
228+
return UnsafeBufferPointer(start: s1, count: count)
229+
.elementsEqual(UnsafeBufferPointer(start: s2, count: count))
230+
#elseif canImport(Darwin)
231+
return Darwin.memcmp(s1, s2, count) == 0
232+
#elseif canImport(Glibc)
233+
return Glibc.memcmp(s1, s2, count) == 0
226234
#else
227235
return UnsafeBufferPointer(start: s1, count: count)
228236
.elementsEqual(UnsafeBufferPointer(start: s2, count: count))

Tests/SwiftParserTest/LinkageTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ final class LinkageTest: XCTestCase {
3232
.library("-lswiftCompatibility56", condition: .mayBeAbsent("Starting in Xcode 14 this library is not always autolinked")),
3333
.library("-lswiftCompatibilityConcurrency"),
3434
.library("-lswiftCore"),
35+
.library("-lswiftDarwin", condition: .mayBeAbsent("Not present when building inside the compiler")),
3536
.library("-lswiftSwiftOnoneSupport", condition: .when(configuration: .debug)),
3637
.library("-lswift_Concurrency"),
3738
.library("-lswift_StringProcessing", condition: .mayBeAbsent("Starting in Xcode 14 this library is not always autolinked")),

0 commit comments

Comments
 (0)