Skip to content

Revert "Revert "Revert "Eliminate SWIFT_SYNTAX_ALWAYS_SINGLE_THREADED""" #1091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ if (NOT SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT)
$<$<COMPILE_LANGUAGE:Swift>:-disable-implicit-string-processing-module-import>)
endif()

# Force single-threaded-only syntax trees to eliminate the Darwin
# dependency in the compiler.
add_compile_definitions(
$<$<COMPILE_LANGUAGE:Swift>:SWIFT_SYNTAX_ALWAYS_SINGLE_THREADED>
)

add_subdirectory(Sources)

export(EXPORT SwiftSyntaxTargets
Expand Down
22 changes: 15 additions & 7 deletions Sources/SwiftSyntax/SyntaxText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
//
//===----------------------------------------------------------------------===//

#if !SWIFT_SYNTAX_ALWAYS_SINGLE_THREADED
#if canImport(Darwin)
@_implementationOnly import Darwin
#elseif canImport(Glibc)
@_implementationOnly import Glibc
#endif
#endif

/// Represent a string.
///
/// This type does not own the string data. The data reside in some other buffer
Expand Down Expand Up @@ -212,17 +220,17 @@ extension String {
}
}

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(Linux) || os(FreeBSD) || os(OpenBSD)
@_silgen_name("memcmp")
public func memcmp(_: UnsafeRawPointer?, _: UnsafeRawPointer?, _: Int) -> Int32
#endif

private func compareMemory(
_ s1: UnsafePointer<UInt8>, _ s2: UnsafePointer<UInt8>, _ count: Int
) -> Bool {
assert(count >= 0)
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(Linux) || os(FreeBSD) || os(OpenBSD)
return memcmp(s1, s2, count) == 0
#if SWIFT_SYNTAX_ALWAYS_SINGLE_THREADED
return UnsafeBufferPointer(start: s1, count: count)
.elementsEqual(UnsafeBufferPointer(start: s2, count: count))
#elseif canImport(Darwin)
return Darwin.memcmp(s1, s2, count) == 0
#elseif canImport(Glibc)
return Glibc.memcmp(s1, s2, count) == 0
#else
return UnsafeBufferPointer(start: s1, count: count)
.elementsEqual(UnsafeBufferPointer(start: s2, count: count))
Expand Down
1 change: 1 addition & 0 deletions Tests/SwiftParserTest/LinkageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class LinkageTest: XCTestCase {
.library("-lswiftCompatibility56", condition: .mayBeAbsent("Starting in Xcode 14 this library is not always autolinked")),
.library("-lswiftCompatibilityConcurrency"),
.library("-lswiftCore"),
.library("-lswiftDarwin", condition: .mayBeAbsent("Not present when building inside the compiler")),
.library("-lswiftSwiftOnoneSupport", condition: .when(configuration: .debug)),
.library("-lswift_Concurrency"),
.library("-lswift_StringProcessing", condition: .mayBeAbsent("Starting in Xcode 14 this library is not always autolinked")),
Expand Down