Skip to content

[5.10] Cherry-pick multiple PRs to release/5.10 #2346

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
merged 12 commits into from
Nov 29, 2023
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
21 changes: 0 additions & 21 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
]
}
4 changes: 4 additions & 0 deletions Release Notes/510.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
```
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDiagnostics/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,7 +26,7 @@ public struct MessageID: Hashable {
}
}

public enum DiagnosticSeverity {
public enum DiagnosticSeverity: Sendable {
case error
case warning
case note
Expand Down
9 changes: 8 additions & 1 deletion Sources/SwiftDiagnostics/Note.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
98 changes: 52 additions & 46 deletions Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/SwiftParser.docc/FilingBugReports.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 9 additions & 4 deletions Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)")
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSyntax/SyntaxChildren.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntax/SyntaxIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion Sources/SwiftSyntax/SyntaxText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<UInt8>(self.baseAddress! + count)
let otherEndBound = UnsafePointer<UInt8>(other.baseAddress! + other.count)
return (other.baseAddress! <= self.baseAddress!) && (selfEndBound <= otherEndBound)
}

/// Returns `true` if `other` is a substring of this ``SyntaxText``.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
)
Expand All @@ -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) {
Expand Down
16 changes: 14 additions & 2 deletions Sources/SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -54,14 +56,24 @@ 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(
of node: AttributeSyntax,
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.
Expand Down
47 changes: 47 additions & 0 deletions SwiftParserCLI/Package.swift
Original file line number Diff line number Diff line change
@@ -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")
]
}
Loading