diff --git a/Package.swift b/Package.swift index f6d3efe5c16..86d810ba5b7 100644 --- a/Package.swift +++ b/Package.swift @@ -269,16 +269,6 @@ let package = Package( dependencies: ["_SwiftSyntaxTestSupport", "SwiftRefactor"] ), - // MARK: - Executable targets - - .executableTarget( - name: "swift-parser-cli", - dependencies: [ - "_InstructionCounter", "SwiftBasicFormat", "SwiftDiagnostics", "SwiftOperators", "SwiftParser", "SwiftParserDiagnostics", "SwiftSyntax", - .product(name: "ArgumentParser", package: "swift-argument-parser"), - ] - ), - // MARK: - Deprecated targets // MARK: PerformanceTest @@ -307,14 +297,3 @@ package.targets.append( } ) ) - -if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil { - // Building standalone. - package.dependencies += [ - .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2") - ] -} else { - package.dependencies += [ - .package(path: "../swift-argument-parser") - ] -} diff --git a/Release Notes/510.md b/Release Notes/510.md index 9adf09c29ce..8ae0439576b 100644 --- a/Release Notes/510.md +++ b/Release Notes/510.md @@ -42,6 +42,10 @@ ## API-Incompatible Changes +- `NoteMessage.fixItID` renamed to `noteID` + - Description: This was an error that it was named `fixItID` and should have been named `noteID` instead. Accesses to `fixItID` are deprecated and forward to `noteID`. Any types that conform `NoteMessage` it will need to be updated to provide a `noteID` instead of a `fixItID`. + - Issue: https://github.com/apple/swift-syntax/issues/2261 + - Pull Request: https://github.com/apple/swift-syntax/pull/2264 ## Template diff --git a/Sources/SwiftBasicFormat/SwiftBasicFormat.docc/FilingBugReports.md b/Sources/SwiftBasicFormat/SwiftBasicFormat.docc/FilingBugReports.md index e28c69a6d3a..3c6179ab246 100644 --- a/Sources/SwiftBasicFormat/SwiftBasicFormat.docc/FilingBugReports.md +++ b/Sources/SwiftBasicFormat/SwiftBasicFormat.docc/FilingBugReports.md @@ -6,9 +6,9 @@ Guide to provide steps for filing actionable bug reports for `BasicFormat` failu Reducing a failure requires the `swift-parser-cli` utility that you can build by checking out `swift-syntax` and running ``` -swift build --product swift-parser-cli +swift build --package-path SwiftParserCLI ``` -or building the `swift-parser-cli` target in Xcode. +or openning `SwiftParserCLI` package and building the `swift-parser-cli` target in Xcode. 1. After you have built `swift-parse-cli`, you can format a single source file using BasicFormat by running the following command. If you are only experiencing the issue while formatting a single node, e.g. while creating an `AccessorDeclSyntax` inside a macro, you can additionally pass the type of the node as `--node-type AccessorDeclSyntax` ``` diff --git a/Sources/SwiftDiagnostics/Message.swift b/Sources/SwiftDiagnostics/Message.swift index 6ee0decf630..2bb6a905ced 100644 --- a/Sources/SwiftDiagnostics/Message.swift +++ b/Sources/SwiftDiagnostics/Message.swift @@ -16,7 +16,7 @@ /// Two diagnostics with the same ID don’t need to necessarily have the exact /// same wording. Eg. it’s possible that the message contains more context when /// available. -public struct MessageID: Hashable { +public struct MessageID: Hashable, Sendable { private let domain: String private let id: String @@ -26,7 +26,7 @@ public struct MessageID: Hashable { } } -public enum DiagnosticSeverity { +public enum DiagnosticSeverity: Sendable { case error case warning case note diff --git a/Sources/SwiftDiagnostics/Note.swift b/Sources/SwiftDiagnostics/Note.swift index fecbe1a056a..5a868da2ae5 100644 --- a/Sources/SwiftDiagnostics/Note.swift +++ b/Sources/SwiftDiagnostics/Note.swift @@ -20,7 +20,14 @@ public protocol NoteMessage { var message: String { get } /// See ``MessageID``. - var fixItID: MessageID { get } + var noteID: MessageID { get } +} + +extension NoteMessage { + @available(*, deprecated, message: "Use noteID instead.", renamed: "noteID") + public var fixItID: MessageID { + return noteID + } } /// A note that points to another node that's relevant for a Diagnostic. diff --git a/Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift b/Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift index 52774807220..03e86252c75 100644 --- a/Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift +++ b/Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift @@ -19,52 +19,58 @@ extension Unicode.Scalar { // N1518: Recommendations for extended identifier characters for C and C++ // Proposed Annex X.1: Ranges of characters allowed let c = self.value - return c == 0x00A8 || c == 0x00AA || c == 0x00AD || c == 0x00AF - || (c >= 0x00B2 && c <= 0x00B5) || (c >= 0x00B7 && c <= 0x00BA) - || (c >= 0x00BC && c <= 0x00BE) || (c >= 0x00C0 && c <= 0x00D6) - || (c >= 0x00D8 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FF) - - || (c >= 0x0100 && c <= 0x167F) - || (c >= 0x1681 && c <= 0x180D) - || (c >= 0x180F && c <= 0x1FFF) - - || (c >= 0x200B && c <= 0x200D) - || (c >= 0x202A && c <= 0x202E) - || (c >= 0x203F && c <= 0x2040) - || c == 0x2054 - || (c >= 0x2060 && c <= 0x206F) - - || (c >= 0x2070 && c <= 0x218F) - || (c >= 0x2460 && c <= 0x24FF) - || (c >= 0x2776 && c <= 0x2793) - || (c >= 0x2C00 && c <= 0x2DFF) - || (c >= 0x2E80 && c <= 0x2FFF) - - || (c >= 0x3004 && c <= 0x3007) - || (c >= 0x3021 && c <= 0x302F) - || (c >= 0x3031 && c <= 0x303F) - - || (c >= 0x3040 && c <= 0xD7FF) - - || (c >= 0xF900 && c <= 0xFD3D) - || (c >= 0xFD40 && c <= 0xFDCF) - || (c >= 0xFDF0 && c <= 0xFE44) - || (c >= 0xFE47 && c <= 0xFFF8) - - || (c >= 0x10000 && c <= 0x1FFFD) - || (c >= 0x20000 && c <= 0x2FFFD) - || (c >= 0x30000 && c <= 0x3FFFD) - || (c >= 0x40000 && c <= 0x4FFFD) - || (c >= 0x50000 && c <= 0x5FFFD) - || (c >= 0x60000 && c <= 0x6FFFD) - || (c >= 0x70000 && c <= 0x7FFFD) - || (c >= 0x80000 && c <= 0x8FFFD) - || (c >= 0x90000 && c <= 0x9FFFD) - || (c >= 0xA0000 && c <= 0xAFFFD) - || (c >= 0xB0000 && c <= 0xBFFFD) - || (c >= 0xC0000 && c <= 0xCFFFD) - || (c >= 0xD0000 && c <= 0xDFFFD) - || (c >= 0xE0000 && c <= 0xEFFFD) + return (c == 0x00A8) as Bool + || (c == 0x00AA) as Bool + || (c == 0x00AD) as Bool + || (c == 0x00AF) as Bool + || (c >= 0x00B2 && c <= 0x00B5) as Bool + || (c >= 0x00B7 && c <= 0x00BA) as Bool + || (c >= 0x00BC && c <= 0x00BE) as Bool + || (c >= 0x00C0 && c <= 0x00D6) as Bool + || (c >= 0x00D8 && c <= 0x00F6) as Bool + || (c >= 0x00F8 && c <= 0x00FF) as Bool + + || (c >= 0x0100 && c <= 0x167F) as Bool + || (c >= 0x1681 && c <= 0x180D) as Bool + || (c >= 0x180F && c <= 0x1FFF) as Bool + + || (c >= 0x200B && c <= 0x200D) as Bool + || (c >= 0x202A && c <= 0x202E) as Bool + || (c >= 0x203F && c <= 0x2040) as Bool + || (c == 0x2054) as Bool + || (c >= 0x2060 && c <= 0x206F) as Bool + + || (c >= 0x2070 && c <= 0x218F) as Bool + || (c >= 0x2460 && c <= 0x24FF) as Bool + || (c >= 0x2776 && c <= 0x2793) as Bool + || (c >= 0x2C00 && c <= 0x2DFF) as Bool + || (c >= 0x2E80 && c <= 0x2FFF) as Bool + + || (c >= 0x3004 && c <= 0x3007) as Bool + || (c >= 0x3021 && c <= 0x302F) as Bool + || (c >= 0x3031 && c <= 0x303F) as Bool + + || (c >= 0x3040 && c <= 0xD7FF) as Bool + + || (c >= 0xF900 && c <= 0xFD3D) as Bool + || (c >= 0xFD40 && c <= 0xFDCF) as Bool + || (c >= 0xFDF0 && c <= 0xFE44) as Bool + || (c >= 0xFE47 && c <= 0xFFF8) as Bool + + || (c >= 0x10000 && c <= 0x1FFFD) as Bool + || (c >= 0x20000 && c <= 0x2FFFD) as Bool + || (c >= 0x30000 && c <= 0x3FFFD) as Bool + || (c >= 0x40000 && c <= 0x4FFFD) as Bool + || (c >= 0x50000 && c <= 0x5FFFD) as Bool + || (c >= 0x60000 && c <= 0x6FFFD) as Bool + || (c >= 0x70000 && c <= 0x7FFFD) as Bool + || (c >= 0x80000 && c <= 0x8FFFD) as Bool + || (c >= 0x90000 && c <= 0x9FFFD) as Bool + || (c >= 0xA0000 && c <= 0xAFFFD) as Bool + || (c >= 0xB0000 && c <= 0xBFFFD) as Bool + || (c >= 0xC0000 && c <= 0xCFFFD) as Bool + || (c >= 0xD0000 && c <= 0xDFFFD) as Bool + || (c >= 0xE0000 && c <= 0xEFFFD) as Bool } var isValidIdentifierStartCodePoint: Bool { diff --git a/Sources/SwiftParser/SwiftParser.docc/FilingBugReports.md b/Sources/SwiftParser/SwiftParser.docc/FilingBugReports.md index 794e966c103..915afc1ab19 100644 --- a/Sources/SwiftParser/SwiftParser.docc/FilingBugReports.md +++ b/Sources/SwiftParser/SwiftParser.docc/FilingBugReports.md @@ -2,7 +2,7 @@ Guide to provide steps for filing actionable bug reports for parser failures. -Reducing a test case requires the `swift-parser-cli` utility that you can build by checking out `swift-syntax` and running `swift build --product swift-parser-cli` or building the `swift-parser-cli` target in Xcode. +Reducing a test case requires the `swift-parser-cli` utility that you can build by checking out `swift-syntax` and running `swift build --package-path SwiftParserCLI` or openning the `SwiftParserCLI` package and building the `swift-parser-cli` target in Xcode. ## Round-Trip Failure or Parser Crash diff --git a/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift b/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift index 8d210bd5be6..6b755497154 100644 --- a/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift +++ b/Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift @@ -36,16 +36,21 @@ public extension ParserError { } public protocol ParserNote: NoteMessage { - var fixItID: MessageID { get } + var noteID: MessageID { get } } public extension ParserNote { + @available(*, deprecated, message: "Use noteID instead.", renamed: "noteID") static var fixItID: MessageID { + return Self.noteID + } + + static var noteID: MessageID { return MessageID(domain: diagnosticDomain, id: "\(self)") } - var fixItID: MessageID { - return Self.fixItID + var noteID: MessageID { + return Self.noteID } } @@ -573,7 +578,7 @@ public struct StaticParserNote: NoteMessage { self.messageID = messageID } - public var fixItID: MessageID { + public var noteID: MessageID { MessageID(domain: diagnosticDomain, id: "\(type(of: self)).\(messageID)") } } diff --git a/Sources/SwiftSyntax/SyntaxChildren.swift b/Sources/SwiftSyntax/SyntaxChildren.swift index ffe67a40bdf..893ccb56fe0 100644 --- a/Sources/SwiftSyntax/SyntaxChildren.swift +++ b/Sources/SwiftSyntax/SyntaxChildren.swift @@ -14,7 +14,7 @@ /// The data for an index in a syntax children collection that is not the end /// index. See ``SyntaxChildrenIndex`` for the representation of the end index. -struct SyntaxChildrenIndexData: Hashable, Comparable { +struct SyntaxChildrenIndexData: Hashable, Comparable, Sendable { /// The UTF-8 offset of the item at this index in the source file /// See `AbsoluteSyntaxPosition.offset` let offset: UInt32 @@ -50,7 +50,7 @@ struct SyntaxChildrenIndexData: Hashable, Comparable { } /// An index in a syntax children collection. -public struct SyntaxChildrenIndex: Hashable, Comparable, ExpressibleByNilLiteral { +public struct SyntaxChildrenIndex: Hashable, Comparable, ExpressibleByNilLiteral, Sendable { /// Construct the `endIndex` of a ``SyntaxChildren`` collection. public init(nilLiteral: ()) { self.data = nil diff --git a/Sources/SwiftSyntax/SyntaxIdentifier.swift b/Sources/SwiftSyntax/SyntaxIdentifier.swift index 6886c6bfe3f..8f3c297cf16 100644 --- a/Sources/SwiftSyntax/SyntaxIdentifier.swift +++ b/Sources/SwiftSyntax/SyntaxIdentifier.swift @@ -12,7 +12,7 @@ /// Represents a unique value for a node within its own tree. @_spi(RawSyntax) -public struct SyntaxIndexInTree: Comparable, Hashable { +public struct SyntaxIndexInTree: Comparable, Hashable, Sendable { let indexInTree: UInt32 static var zero: SyntaxIndexInTree = SyntaxIndexInTree(indexInTree: 0) diff --git a/Sources/SwiftSyntax/SyntaxText.swift b/Sources/SwiftSyntax/SyntaxText.swift index 310bcb22836..c5068a76aa4 100644 --- a/Sources/SwiftSyntax/SyntaxText.swift +++ b/Sources/SwiftSyntax/SyntaxText.swift @@ -100,7 +100,9 @@ public struct SyntaxText { guard !self.isEmpty && !other.isEmpty else { return self.isEmpty && other.isEmpty } - return (other.baseAddress! <= self.baseAddress! && self.baseAddress! + count <= other.baseAddress! + other.count) + let selfEndBound = UnsafePointer(self.baseAddress! + count) + let otherEndBound = UnsafePointer(other.baseAddress! + other.count) + return (other.baseAddress! <= self.baseAddress!) && (selfEndBound <= otherEndBound) } /// Returns `true` if `other` is a substring of this ``SyntaxText``. diff --git a/Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift b/Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift index 6c4c3a302b9..7b2d8b77964 100644 --- a/Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift +++ b/Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift @@ -346,7 +346,7 @@ extension LabeledExprSyntax { public init(label: String? = nil, expression: some ExprSyntaxProtocol) { self.init( label: label.map { .identifier($0) }, - colon: label == nil ? nil : .colonToken(), + colon: label == nil ? nil : .colonToken(trailingTrivia: .space), expression: expression ) } diff --git a/Sources/SwiftSyntaxBuilder/SyntaxParsable+ExpressibleByStringInterpolation.swift b/Sources/SwiftSyntaxBuilder/SyntaxParsable+ExpressibleByStringInterpolation.swift index 741d26bb0ba..9b124cd5217 100644 --- a/Sources/SwiftSyntaxBuilder/SyntaxParsable+ExpressibleByStringInterpolation.swift +++ b/Sources/SwiftSyntaxBuilder/SyntaxParsable+ExpressibleByStringInterpolation.swift @@ -48,10 +48,14 @@ extension SyntaxParseable { { let diagnostics = ParseDiagnosticsGenerator.diagnostics(for: self) let formattedDiagnostics = DiagnosticsFormatter().annotatedSource(tree: self, diags: diagnostics) - Logger(subsystem: "SwiftSyntax", category: "ParseError").fault( + Logger(subsystem: "org.swift.swift-syntax", category: "ParseError").fault( """ Parsing a `\(Self.self)` node from string interpolation produced the following parsing errors. Set a breakpoint in `SyntaxParseable.logStringInterpolationParsingError()` to debug the failure. + + To explicitly support parsing of invalid source code, import SwiftParser and invoke the parser as follows + var parser = Parser(source) + \(Self.self).parse(from: &parser) \(formattedDiagnostics, privacy: .private) """ ) @@ -61,7 +65,7 @@ extension SyntaxParseable { /// Initialize the syntax node from a string interpolation. /// - /// - Important: This asssumes that the string interpolation produces a valid + /// - Important: This assumes that the string interpolation produces a valid /// syntax tree. If the syntax tree is not valid, a fault will /// be logged using OSLog on Darwin platforms. public init(stringInterpolation: SyntaxStringInterpolation) { diff --git a/Sources/SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift b/Sources/SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift index e5673bacc35..9a345ec6159 100644 --- a/Sources/SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift +++ b/Sources/SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift @@ -23,7 +23,9 @@ public protocol MemberMacro: AttachedMacro { /// /// - Returns: the set of member declarations introduced by this macro, which /// are nested inside the `attachedTo` declaration. - @available(*, deprecated, message: "Use expansion(of:providingMembersOf:conformingTo:in:") + /// + /// - Warning: This is the legacy `expansion` function of `MemberMacro` that is provided for backwards-compatiblity. + /// Use ``expansion(of:providingMembersOf:conformingTo:in:)-1sxoe`` instead. static func expansion( of node: AttributeSyntax, providingMembersOf declaration: some DeclGroupSyntax, @@ -54,6 +56,16 @@ public protocol MemberMacro: AttachedMacro { ) throws -> [DeclSyntax] } +private struct UnimplementedExpansionMethodError: Error, CustomStringConvertible { + var description: String { + """ + Types conforming to `MemberMacro` must implement either \ + expansion(of:providingMembersOf:in:) or \ + expansion(of:providingMembersOf:conformingTo:in:) + """ + } +} + public extension MemberMacro { /// Default implementation supplies no conformances. static func expansion( @@ -61,7 +73,7 @@ public extension MemberMacro { providingMembersOf declaration: some DeclGroupSyntax, in context: some MacroExpansionContext ) throws -> [DeclSyntax] { - return try expansion(of: node, providingMembersOf: declaration, conformingTo: [], in: context) + throw UnimplementedExpansionMethodError() } /// Default implementation that ignores the unhandled conformances. diff --git a/SwiftParserCLI/Package.swift b/SwiftParserCLI/Package.swift new file mode 100644 index 00000000000..c59ec321d32 --- /dev/null +++ b/SwiftParserCLI/Package.swift @@ -0,0 +1,47 @@ +// swift-tools-version:5.7 + +import Foundation +import PackageDescription + +let package = Package( + name: "SwiftParserCLI", + platforms: [ + .macOS(.v10_15) + ], + products: [ + .executable(name: "swift-parser-cli", targets: ["swift-parser-cli"]) + ], + dependencies: [ + .package(path: "..") + ], + targets: [ + .target( + name: "InstructionCounter" + ), + + .executableTarget( + name: "swift-parser-cli", + dependencies: [ + "InstructionCounter", + .product(name: "SwiftBasicFormat", package: "swift-syntax"), + .product(name: "SwiftDiagnostics", package: "swift-syntax"), + .product(name: "SwiftOperators", package: "swift-syntax"), + .product(name: "SwiftParser", package: "swift-syntax"), + .product(name: "SwiftParserDiagnostics", package: "swift-syntax"), + .product(name: "SwiftSyntax", package: "swift-syntax"), + .product(name: "ArgumentParser", package: "swift-argument-parser"), + ] + ), + ] +) + +if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil { + // Building standalone. + package.dependencies += [ + .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2") + ] +} else { + package.dependencies += [ + .package(path: "../../swift-argument-parser") + ] +} diff --git a/SwiftParserCLI/README.md b/SwiftParserCLI/README.md new file mode 100644 index 00000000000..f42dbdd7a12 --- /dev/null +++ b/SwiftParserCLI/README.md @@ -0,0 +1,14 @@ +# SwiftParserCLI + +This directory contains the source files of the `swift-parser-cli` program. + +You can build `swift-parser-cli` by checking out `swift-syntax` and running +``` +swift build --package-path SwiftParserCLI +``` +or entering this directory and running +``` +swift build +``` + +You can also open the `SwiftParserCLI` package and building the `swift-parser-cli` target in Xcode. diff --git a/SwiftParserCLI/Sources/InstructionCounter/include/InstructionsExecuted.h b/SwiftParserCLI/Sources/InstructionCounter/include/InstructionsExecuted.h new file mode 100644 index 00000000000..af9d9a4157b --- /dev/null +++ b/SwiftParserCLI/Sources/InstructionCounter/include/InstructionsExecuted.h @@ -0,0 +1,17 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#include + +/// On macOS returns the number of instructions the process has executed since +/// it was launched, on all other platforms returns 0. +uint64_t getInstructionsExecuted(); diff --git a/SwiftParserCLI/Sources/InstructionCounter/src/InstructionsExecuted.c b/SwiftParserCLI/Sources/InstructionCounter/src/InstructionsExecuted.c new file mode 100644 index 00000000000..4df6fa632f2 --- /dev/null +++ b/SwiftParserCLI/Sources/InstructionCounter/src/InstructionsExecuted.c @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#if __APPLE__ +#include +#if TARGET_OS_MAC && !TARGET_OS_IPHONE +#define TARGET_IS_MACOS 1 +#endif +#endif + +#include "InstructionsExecuted.h" + +#ifdef TARGET_IS_MACOS +#include +#include +#include + +uint64_t getInstructionsExecuted() { + struct rusage_info_v4 ru; + if (proc_pid_rusage(getpid(), RUSAGE_INFO_V4, (rusage_info_t *)&ru) == 0) { + return ru.ri_instructions; + } + return 0; +} +#else +uint64_t getInstructionsExecuted() { + return 0; +} +#endif diff --git a/Sources/swift-parser-cli/BasicFormat.swift b/SwiftParserCLI/Sources/swift-parser-cli/BasicFormat.swift similarity index 100% rename from Sources/swift-parser-cli/BasicFormat.swift rename to SwiftParserCLI/Sources/swift-parser-cli/BasicFormat.swift diff --git a/Sources/swift-parser-cli/Commands/PerformanceTest.swift b/SwiftParserCLI/Sources/swift-parser-cli/Commands/PerformanceTest.swift similarity index 99% rename from Sources/swift-parser-cli/Commands/PerformanceTest.swift rename to SwiftParserCLI/Sources/swift-parser-cli/Commands/PerformanceTest.swift index 300b175cbd0..4b8d545ee28 100644 --- a/Sources/swift-parser-cli/Commands/PerformanceTest.swift +++ b/SwiftParserCLI/Sources/swift-parser-cli/Commands/PerformanceTest.swift @@ -12,9 +12,9 @@ import ArgumentParser import Foundation +import InstructionCounter import SwiftParser import SwiftSyntax -import _InstructionCounter struct PerformanceTest: ParsableCommand { static var configuration = CommandConfiguration( diff --git a/Sources/swift-parser-cli/Commands/PrintDiags.swift b/SwiftParserCLI/Sources/swift-parser-cli/Commands/PrintDiags.swift similarity index 100% rename from Sources/swift-parser-cli/Commands/PrintDiags.swift rename to SwiftParserCLI/Sources/swift-parser-cli/Commands/PrintDiags.swift diff --git a/Sources/swift-parser-cli/Commands/PrintTree.swift b/SwiftParserCLI/Sources/swift-parser-cli/Commands/PrintTree.swift similarity index 100% rename from Sources/swift-parser-cli/Commands/PrintTree.swift rename to SwiftParserCLI/Sources/swift-parser-cli/Commands/PrintTree.swift diff --git a/Sources/swift-parser-cli/Commands/Reduce.swift b/SwiftParserCLI/Sources/swift-parser-cli/Commands/Reduce.swift similarity index 100% rename from Sources/swift-parser-cli/Commands/Reduce.swift rename to SwiftParserCLI/Sources/swift-parser-cli/Commands/Reduce.swift diff --git a/Sources/swift-parser-cli/Commands/VerifyRoundTrip.swift b/SwiftParserCLI/Sources/swift-parser-cli/Commands/VerifyRoundTrip.swift similarity index 100% rename from Sources/swift-parser-cli/Commands/VerifyRoundTrip.swift rename to SwiftParserCLI/Sources/swift-parser-cli/Commands/VerifyRoundTrip.swift diff --git a/Sources/swift-parser-cli/ParseCommand.swift b/SwiftParserCLI/Sources/swift-parser-cli/ParseCommand.swift similarity index 100% rename from Sources/swift-parser-cli/ParseCommand.swift rename to SwiftParserCLI/Sources/swift-parser-cli/ParseCommand.swift diff --git a/Sources/swift-parser-cli/SyntaxUtils.swift b/SwiftParserCLI/Sources/swift-parser-cli/SyntaxUtils.swift similarity index 100% rename from Sources/swift-parser-cli/SyntaxUtils.swift rename to SwiftParserCLI/Sources/swift-parser-cli/SyntaxUtils.swift diff --git a/Sources/swift-parser-cli/TerminalUtils.swift b/SwiftParserCLI/Sources/swift-parser-cli/TerminalUtils.swift similarity index 100% rename from Sources/swift-parser-cli/TerminalUtils.swift rename to SwiftParserCLI/Sources/swift-parser-cli/TerminalUtils.swift diff --git a/Sources/swift-parser-cli/Utils.swift b/SwiftParserCLI/Sources/swift-parser-cli/Utils.swift similarity index 100% rename from Sources/swift-parser-cli/Utils.swift rename to SwiftParserCLI/Sources/swift-parser-cli/Utils.swift diff --git a/Sources/swift-parser-cli/swift-parser-cli.swift b/SwiftParserCLI/Sources/swift-parser-cli/swift-parser-cli.swift similarity index 97% rename from Sources/swift-parser-cli/swift-parser-cli.swift rename to SwiftParserCLI/Sources/swift-parser-cli/swift-parser-cli.swift index d2b51ead174..21f02d924c0 100644 --- a/Sources/swift-parser-cli/swift-parser-cli.swift +++ b/SwiftParserCLI/Sources/swift-parser-cli/swift-parser-cli.swift @@ -12,12 +12,12 @@ import ArgumentParser import Foundation +import InstructionCounter import SwiftDiagnostics import SwiftOperators import SwiftParser import SwiftParserDiagnostics import SwiftSyntax -import _InstructionCounter #if os(Windows) import WinSDK diff --git a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Build.swift b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Build.swift index 171a6274dc9..ae884a7c02d 100644 --- a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Build.swift +++ b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/commands/Build.swift @@ -26,6 +26,7 @@ struct Build: ParsableCommand, BuildCommand { func run() throws { try buildTarget(packageDir: Paths.packageDir, targetName: "SwiftSyntax-all") try buildTarget(packageDir: Paths.examplesDir, targetName: "Examples-all") + try buildTarget(packageDir: Paths.swiftParserCliDir, targetName: "swift-parser-cli") try buildEditorExtension() } diff --git a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/Paths.swift b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/Paths.swift index 48a42e5e42f..693314275d4 100644 --- a/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/Paths.swift +++ b/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/Paths.swift @@ -32,6 +32,11 @@ enum Paths { .appendingPathComponent("Examples") } + static var swiftParserCliDir: URL { + packageDir + .appendingPathComponent("SwiftParserCLI") + } + static var codeGenerationDir: URL { packageDir .appendingPathComponent("CodeGeneration") diff --git a/Tests/SwiftSyntaxBuilderTest/Assertions.swift b/Tests/SwiftSyntaxBuilderTest/Assertions.swift index da1af7c6eb8..5e9d2afc4a5 100644 --- a/Tests/SwiftSyntaxBuilderTest/Assertions.swift +++ b/Tests/SwiftSyntaxBuilderTest/Assertions.swift @@ -19,10 +19,14 @@ func assertBuildResult( _ buildable: T, _ expectedResult: String, trimTrailingWhitespace: Bool = true, + format: Bool = true, file: StaticString = #file, line: UInt = #line ) { - var buildableDescription = buildable.formatted().description + var buildableDescription = + format + ? buildable.formatted().description + : buildable.description var expectedResult = expectedResult if trimTrailingWhitespace { buildableDescription = buildableDescription.trimmingTrailingWhitespace() diff --git a/Tests/SwiftSyntaxBuilderTest/LabeledExprSyntaxTests.swift b/Tests/SwiftSyntaxBuilderTest/LabeledExprSyntaxTests.swift new file mode 100644 index 00000000000..64075f57c07 --- /dev/null +++ b/Tests/SwiftSyntaxBuilderTest/LabeledExprSyntaxTests.swift @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SwiftSyntax +import SwiftSyntaxBuilder +import XCTest + +final class LabeledExprSyntaxTests: XCTestCase { + func testLabeledExprSyntax() { + let syntax = LabeledExprSyntax(label: "arg", expression: NilLiteralExprSyntax()) + assertBuildResult(syntax, "arg: nil", format: false) + } +}