Skip to content

Commit e0c65b2

Browse files
authored
Merge pull request #2346 from ahoppen/ahoppen/5.10/cherry-picks
[5.10] Cherry-pick multiple PRs to `release/5.10` 🚥 #2339
2 parents 7f41827 + 58a574e commit e0c65b2

File tree

33 files changed

+256
-89
lines changed

33 files changed

+256
-89
lines changed

Package.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,6 @@ let package = Package(
269269
dependencies: ["_SwiftSyntaxTestSupport", "SwiftRefactor"]
270270
),
271271

272-
// MARK: - Executable targets
273-
274-
.executableTarget(
275-
name: "swift-parser-cli",
276-
dependencies: [
277-
"_InstructionCounter", "SwiftBasicFormat", "SwiftDiagnostics", "SwiftOperators", "SwiftParser", "SwiftParserDiagnostics", "SwiftSyntax",
278-
.product(name: "ArgumentParser", package: "swift-argument-parser"),
279-
]
280-
),
281-
282272
// MARK: - Deprecated targets
283273

284274
// MARK: PerformanceTest
@@ -307,14 +297,3 @@ package.targets.append(
307297
}
308298
)
309299
)
310-
311-
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
312-
// Building standalone.
313-
package.dependencies += [
314-
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2")
315-
]
316-
} else {
317-
package.dependencies += [
318-
.package(path: "../swift-argument-parser")
319-
]
320-
}

Release Notes/510.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242

4343
## API-Incompatible Changes
4444

45+
- `NoteMessage.fixItID` renamed to `noteID`
46+
- 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`.
47+
- Issue: https://github.com/apple/swift-syntax/issues/2261
48+
- Pull Request: https://github.com/apple/swift-syntax/pull/2264
4549

4650
## Template
4751

Sources/SwiftBasicFormat/SwiftBasicFormat.docc/FilingBugReports.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Guide to provide steps for filing actionable bug reports for `BasicFormat` failu
66

77
Reducing a failure requires the `swift-parser-cli` utility that you can build by checking out `swift-syntax` and running
88
```
9-
swift build --product swift-parser-cli
9+
swift build --package-path SwiftParserCLI
1010
```
11-
or building the `swift-parser-cli` target in Xcode.
11+
or openning `SwiftParserCLI` package and building the `swift-parser-cli` target in Xcode.
1212

1313
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`
1414
```

Sources/SwiftDiagnostics/Message.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/// Two diagnostics with the same ID don’t need to necessarily have the exact
1717
/// same wording. Eg. it’s possible that the message contains more context when
1818
/// available.
19-
public struct MessageID: Hashable {
19+
public struct MessageID: Hashable, Sendable {
2020
private let domain: String
2121
private let id: String
2222

@@ -26,7 +26,7 @@ public struct MessageID: Hashable {
2626
}
2727
}
2828

29-
public enum DiagnosticSeverity {
29+
public enum DiagnosticSeverity: Sendable {
3030
case error
3131
case warning
3232
case note

Sources/SwiftDiagnostics/Note.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ public protocol NoteMessage {
2020
var message: String { get }
2121

2222
/// See ``MessageID``.
23-
var fixItID: MessageID { get }
23+
var noteID: MessageID { get }
24+
}
25+
26+
extension NoteMessage {
27+
@available(*, deprecated, message: "Use noteID instead.", renamed: "noteID")
28+
public var fixItID: MessageID {
29+
return noteID
30+
}
2431
}
2532

2633
/// A note that points to another node that's relevant for a Diagnostic.

Sources/SwiftParser/Lexer/UnicodeScalarExtensions.swift

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,58 @@ extension Unicode.Scalar {
1919
// N1518: Recommendations for extended identifier characters for C and C++
2020
// Proposed Annex X.1: Ranges of characters allowed
2121
let c = self.value
22-
return c == 0x00A8 || c == 0x00AA || c == 0x00AD || c == 0x00AF
23-
|| (c >= 0x00B2 && c <= 0x00B5) || (c >= 0x00B7 && c <= 0x00BA)
24-
|| (c >= 0x00BC && c <= 0x00BE) || (c >= 0x00C0 && c <= 0x00D6)
25-
|| (c >= 0x00D8 && c <= 0x00F6) || (c >= 0x00F8 && c <= 0x00FF)
26-
27-
|| (c >= 0x0100 && c <= 0x167F)
28-
|| (c >= 0x1681 && c <= 0x180D)
29-
|| (c >= 0x180F && c <= 0x1FFF)
30-
31-
|| (c >= 0x200B && c <= 0x200D)
32-
|| (c >= 0x202A && c <= 0x202E)
33-
|| (c >= 0x203F && c <= 0x2040)
34-
|| c == 0x2054
35-
|| (c >= 0x2060 && c <= 0x206F)
36-
37-
|| (c >= 0x2070 && c <= 0x218F)
38-
|| (c >= 0x2460 && c <= 0x24FF)
39-
|| (c >= 0x2776 && c <= 0x2793)
40-
|| (c >= 0x2C00 && c <= 0x2DFF)
41-
|| (c >= 0x2E80 && c <= 0x2FFF)
42-
43-
|| (c >= 0x3004 && c <= 0x3007)
44-
|| (c >= 0x3021 && c <= 0x302F)
45-
|| (c >= 0x3031 && c <= 0x303F)
46-
47-
|| (c >= 0x3040 && c <= 0xD7FF)
48-
49-
|| (c >= 0xF900 && c <= 0xFD3D)
50-
|| (c >= 0xFD40 && c <= 0xFDCF)
51-
|| (c >= 0xFDF0 && c <= 0xFE44)
52-
|| (c >= 0xFE47 && c <= 0xFFF8)
53-
54-
|| (c >= 0x10000 && c <= 0x1FFFD)
55-
|| (c >= 0x20000 && c <= 0x2FFFD)
56-
|| (c >= 0x30000 && c <= 0x3FFFD)
57-
|| (c >= 0x40000 && c <= 0x4FFFD)
58-
|| (c >= 0x50000 && c <= 0x5FFFD)
59-
|| (c >= 0x60000 && c <= 0x6FFFD)
60-
|| (c >= 0x70000 && c <= 0x7FFFD)
61-
|| (c >= 0x80000 && c <= 0x8FFFD)
62-
|| (c >= 0x90000 && c <= 0x9FFFD)
63-
|| (c >= 0xA0000 && c <= 0xAFFFD)
64-
|| (c >= 0xB0000 && c <= 0xBFFFD)
65-
|| (c >= 0xC0000 && c <= 0xCFFFD)
66-
|| (c >= 0xD0000 && c <= 0xDFFFD)
67-
|| (c >= 0xE0000 && c <= 0xEFFFD)
22+
return (c == 0x00A8) as Bool
23+
|| (c == 0x00AA) as Bool
24+
|| (c == 0x00AD) as Bool
25+
|| (c == 0x00AF) as Bool
26+
|| (c >= 0x00B2 && c <= 0x00B5) as Bool
27+
|| (c >= 0x00B7 && c <= 0x00BA) as Bool
28+
|| (c >= 0x00BC && c <= 0x00BE) as Bool
29+
|| (c >= 0x00C0 && c <= 0x00D6) as Bool
30+
|| (c >= 0x00D8 && c <= 0x00F6) as Bool
31+
|| (c >= 0x00F8 && c <= 0x00FF) as Bool
32+
33+
|| (c >= 0x0100 && c <= 0x167F) as Bool
34+
|| (c >= 0x1681 && c <= 0x180D) as Bool
35+
|| (c >= 0x180F && c <= 0x1FFF) as Bool
36+
37+
|| (c >= 0x200B && c <= 0x200D) as Bool
38+
|| (c >= 0x202A && c <= 0x202E) as Bool
39+
|| (c >= 0x203F && c <= 0x2040) as Bool
40+
|| (c == 0x2054) as Bool
41+
|| (c >= 0x2060 && c <= 0x206F) as Bool
42+
43+
|| (c >= 0x2070 && c <= 0x218F) as Bool
44+
|| (c >= 0x2460 && c <= 0x24FF) as Bool
45+
|| (c >= 0x2776 && c <= 0x2793) as Bool
46+
|| (c >= 0x2C00 && c <= 0x2DFF) as Bool
47+
|| (c >= 0x2E80 && c <= 0x2FFF) as Bool
48+
49+
|| (c >= 0x3004 && c <= 0x3007) as Bool
50+
|| (c >= 0x3021 && c <= 0x302F) as Bool
51+
|| (c >= 0x3031 && c <= 0x303F) as Bool
52+
53+
|| (c >= 0x3040 && c <= 0xD7FF) as Bool
54+
55+
|| (c >= 0xF900 && c <= 0xFD3D) as Bool
56+
|| (c >= 0xFD40 && c <= 0xFDCF) as Bool
57+
|| (c >= 0xFDF0 && c <= 0xFE44) as Bool
58+
|| (c >= 0xFE47 && c <= 0xFFF8) as Bool
59+
60+
|| (c >= 0x10000 && c <= 0x1FFFD) as Bool
61+
|| (c >= 0x20000 && c <= 0x2FFFD) as Bool
62+
|| (c >= 0x30000 && c <= 0x3FFFD) as Bool
63+
|| (c >= 0x40000 && c <= 0x4FFFD) as Bool
64+
|| (c >= 0x50000 && c <= 0x5FFFD) as Bool
65+
|| (c >= 0x60000 && c <= 0x6FFFD) as Bool
66+
|| (c >= 0x70000 && c <= 0x7FFFD) as Bool
67+
|| (c >= 0x80000 && c <= 0x8FFFD) as Bool
68+
|| (c >= 0x90000 && c <= 0x9FFFD) as Bool
69+
|| (c >= 0xA0000 && c <= 0xAFFFD) as Bool
70+
|| (c >= 0xB0000 && c <= 0xBFFFD) as Bool
71+
|| (c >= 0xC0000 && c <= 0xCFFFD) as Bool
72+
|| (c >= 0xD0000 && c <= 0xDFFFD) as Bool
73+
|| (c >= 0xE0000 && c <= 0xEFFFD) as Bool
6874
}
6975

7076
var isValidIdentifierStartCodePoint: Bool {

Sources/SwiftParser/SwiftParser.docc/FilingBugReports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Guide to provide steps for filing actionable bug reports for parser failures.
44

5-
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.
5+
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.
66

77
## Round-Trip Failure or Parser Crash
88

Sources/SwiftParserDiagnostics/ParserDiagnosticMessages.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,21 @@ public extension ParserError {
3636
}
3737

3838
public protocol ParserNote: NoteMessage {
39-
var fixItID: MessageID { get }
39+
var noteID: MessageID { get }
4040
}
4141

4242
public extension ParserNote {
43+
@available(*, deprecated, message: "Use noteID instead.", renamed: "noteID")
4344
static var fixItID: MessageID {
45+
return Self.noteID
46+
}
47+
48+
static var noteID: MessageID {
4449
return MessageID(domain: diagnosticDomain, id: "\(self)")
4550
}
4651

47-
var fixItID: MessageID {
48-
return Self.fixItID
52+
var noteID: MessageID {
53+
return Self.noteID
4954
}
5055
}
5156

@@ -573,7 +578,7 @@ public struct StaticParserNote: NoteMessage {
573578
self.messageID = messageID
574579
}
575580

576-
public var fixItID: MessageID {
581+
public var noteID: MessageID {
577582
MessageID(domain: diagnosticDomain, id: "\(type(of: self)).\(messageID)")
578583
}
579584
}

Sources/SwiftSyntax/SyntaxChildren.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/// The data for an index in a syntax children collection that is not the end
1616
/// index. See ``SyntaxChildrenIndex`` for the representation of the end index.
17-
struct SyntaxChildrenIndexData: Hashable, Comparable {
17+
struct SyntaxChildrenIndexData: Hashable, Comparable, Sendable {
1818
/// The UTF-8 offset of the item at this index in the source file
1919
/// See `AbsoluteSyntaxPosition.offset`
2020
let offset: UInt32
@@ -50,7 +50,7 @@ struct SyntaxChildrenIndexData: Hashable, Comparable {
5050
}
5151

5252
/// An index in a syntax children collection.
53-
public struct SyntaxChildrenIndex: Hashable, Comparable, ExpressibleByNilLiteral {
53+
public struct SyntaxChildrenIndex: Hashable, Comparable, ExpressibleByNilLiteral, Sendable {
5454
/// Construct the `endIndex` of a ``SyntaxChildren`` collection.
5555
public init(nilLiteral: ()) {
5656
self.data = nil

Sources/SwiftSyntax/SyntaxIdentifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/// Represents a unique value for a node within its own tree.
1414
@_spi(RawSyntax)
15-
public struct SyntaxIndexInTree: Comparable, Hashable {
15+
public struct SyntaxIndexInTree: Comparable, Hashable, Sendable {
1616
let indexInTree: UInt32
1717

1818
static var zero: SyntaxIndexInTree = SyntaxIndexInTree(indexInTree: 0)

Sources/SwiftSyntax/SyntaxText.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ public struct SyntaxText {
100100
guard !self.isEmpty && !other.isEmpty else {
101101
return self.isEmpty && other.isEmpty
102102
}
103-
return (other.baseAddress! <= self.baseAddress! && self.baseAddress! + count <= other.baseAddress! + other.count)
103+
let selfEndBound = UnsafePointer<UInt8>(self.baseAddress! + count)
104+
let otherEndBound = UnsafePointer<UInt8>(other.baseAddress! + other.count)
105+
return (other.baseAddress! <= self.baseAddress!) && (selfEndBound <= otherEndBound)
104106
}
105107

106108
/// Returns `true` if `other` is a substring of this ``SyntaxText``.

Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ extension LabeledExprSyntax {
346346
public init(label: String? = nil, expression: some ExprSyntaxProtocol) {
347347
self.init(
348348
label: label.map { .identifier($0) },
349-
colon: label == nil ? nil : .colonToken(),
349+
colon: label == nil ? nil : .colonToken(trailingTrivia: .space),
350350
expression: expression
351351
)
352352
}

Sources/SwiftSyntaxBuilder/SyntaxParsable+ExpressibleByStringInterpolation.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ extension SyntaxParseable {
4848
{
4949
let diagnostics = ParseDiagnosticsGenerator.diagnostics(for: self)
5050
let formattedDiagnostics = DiagnosticsFormatter().annotatedSource(tree: self, diags: diagnostics)
51-
Logger(subsystem: "SwiftSyntax", category: "ParseError").fault(
51+
Logger(subsystem: "org.swift.swift-syntax", category: "ParseError").fault(
5252
"""
5353
Parsing a `\(Self.self)` node from string interpolation produced the following parsing errors.
5454
Set a breakpoint in `SyntaxParseable.logStringInterpolationParsingError()` to debug the failure.
55+
56+
To explicitly support parsing of invalid source code, import SwiftParser and invoke the parser as follows
57+
var parser = Parser(source)
58+
\(Self.self).parse(from: &parser)
5559
\(formattedDiagnostics, privacy: .private)
5660
"""
5761
)
@@ -61,7 +65,7 @@ extension SyntaxParseable {
6165

6266
/// Initialize the syntax node from a string interpolation.
6367
///
64-
/// - Important: This asssumes that the string interpolation produces a valid
68+
/// - Important: This assumes that the string interpolation produces a valid
6569
/// syntax tree. If the syntax tree is not valid, a fault will
6670
/// be logged using OSLog on Darwin platforms.
6771
public init(stringInterpolation: SyntaxStringInterpolation) {

Sources/SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public protocol MemberMacro: AttachedMacro {
2323
///
2424
/// - Returns: the set of member declarations introduced by this macro, which
2525
/// are nested inside the `attachedTo` declaration.
26-
@available(*, deprecated, message: "Use expansion(of:providingMembersOf:conformingTo:in:")
26+
///
27+
/// - Warning: This is the legacy `expansion` function of `MemberMacro` that is provided for backwards-compatiblity.
28+
/// Use ``expansion(of:providingMembersOf:conformingTo:in:)-1sxoe`` instead.
2729
static func expansion(
2830
of node: AttributeSyntax,
2931
providingMembersOf declaration: some DeclGroupSyntax,
@@ -54,14 +56,24 @@ public protocol MemberMacro: AttachedMacro {
5456
) throws -> [DeclSyntax]
5557
}
5658

59+
private struct UnimplementedExpansionMethodError: Error, CustomStringConvertible {
60+
var description: String {
61+
"""
62+
Types conforming to `MemberMacro` must implement either \
63+
expansion(of:providingMembersOf:in:) or \
64+
expansion(of:providingMembersOf:conformingTo:in:)
65+
"""
66+
}
67+
}
68+
5769
public extension MemberMacro {
5870
/// Default implementation supplies no conformances.
5971
static func expansion(
6072
of node: AttributeSyntax,
6173
providingMembersOf declaration: some DeclGroupSyntax,
6274
in context: some MacroExpansionContext
6375
) throws -> [DeclSyntax] {
64-
return try expansion(of: node, providingMembersOf: declaration, conformingTo: [], in: context)
76+
throw UnimplementedExpansionMethodError()
6577
}
6678

6779
/// Default implementation that ignores the unhandled conformances.

SwiftParserCLI/Package.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// swift-tools-version:5.7
2+
3+
import Foundation
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SwiftParserCLI",
8+
platforms: [
9+
.macOS(.v10_15)
10+
],
11+
products: [
12+
.executable(name: "swift-parser-cli", targets: ["swift-parser-cli"])
13+
],
14+
dependencies: [
15+
.package(path: "..")
16+
],
17+
targets: [
18+
.target(
19+
name: "InstructionCounter"
20+
),
21+
22+
.executableTarget(
23+
name: "swift-parser-cli",
24+
dependencies: [
25+
"InstructionCounter",
26+
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
27+
.product(name: "SwiftDiagnostics", package: "swift-syntax"),
28+
.product(name: "SwiftOperators", package: "swift-syntax"),
29+
.product(name: "SwiftParser", package: "swift-syntax"),
30+
.product(name: "SwiftParserDiagnostics", package: "swift-syntax"),
31+
.product(name: "SwiftSyntax", package: "swift-syntax"),
32+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
33+
]
34+
),
35+
]
36+
)
37+
38+
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
39+
// Building standalone.
40+
package.dependencies += [
41+
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2")
42+
]
43+
} else {
44+
package.dependencies += [
45+
.package(path: "../../swift-argument-parser")
46+
]
47+
}

0 commit comments

Comments
 (0)