Skip to content

Commit 88f1405

Browse files
authored
Merge branch 'main' into patch-3
2 parents 932be63 + cf3fbfd commit 88f1405

File tree

31 files changed

+516
-240
lines changed

31 files changed

+516
-240
lines changed

CodeGeneration/Package.swift

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,8 @@ let package = Package(
1212
.executable(name: "generate-swift-syntax", targets: ["generate-swift-syntax"])
1313
],
1414
dependencies: [
15-
// This directory is a standalone package that uses swift-syntax from the
16-
// outer directory.
17-
// If you are making significant changs to `CodeGeneration` locally and want
18-
// to avoid breaking the build of `CodeGeneration` itself by generating new
19-
// files in the parent swift-syntax package, it is encouraged to change the
20-
// dependency to the following. That way `CodeGeneration` has its own
21-
// checkout of swift-syntax that is unaffected by the newly generated files.
22-
// Be sure to revert the change before committing your changes.
23-
//
24-
// .package(url: "https://github.com/apple/swift-syntax", branch: "main")
25-
.package(path: "..")
15+
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"),
16+
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2"),
2617
],
2718
targets: [
2819
.executableTarget(
@@ -63,14 +54,3 @@ let package = Package(
6354
),
6455
]
6556
)
66-
67-
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
68-
// Building standalone.
69-
package.dependencies += [
70-
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2")
71-
]
72-
} else {
73-
package.dependencies += [
74-
.package(path: "../../swift-argument-parser")
75-
]
76-
}

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ public let DECL_NODES: [Node] = [
461461
.keyword(.private),
462462
.keyword(.public),
463463
.keyword(.reasync),
464+
.keyword(._resultDependsOnSelf),
464465
.keyword(.required),
465466
.keyword(.static),
466467
.keyword(.unowned),

CodeGeneration/Sources/SyntaxSupport/ExperimentalFeatures.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public enum ExperimentalFeature: String, CaseIterable {
1717
case thenStatements
1818
case typedThrows
1919
case doExpressions
20+
case nonEscapableTypes
2021

2122
/// The name of the feature, which is used in the doc comment.
2223
public var featureName: String {
@@ -29,6 +30,8 @@ public enum ExperimentalFeature: String, CaseIterable {
2930
return "typed throws"
3031
case .doExpressions:
3132
return "'do' expressions"
33+
case .nonEscapableTypes:
34+
return "NonEscableTypes"
3235
}
3336
}
3437

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ public enum Keyword: CaseIterable {
239239
case renamed
240240
case `repeat`
241241
case required
242+
case _resultDependsOnSelf
242243
case `rethrows`
243244
case retroactive
244245
case `return`
@@ -610,6 +611,8 @@ public enum Keyword: CaseIterable {
610611
return KeywordSpec("repeat", isLexerClassified: true)
611612
case .required:
612613
return KeywordSpec("required")
614+
case ._resultDependsOnSelf:
615+
return KeywordSpec("_resultDependsOnSelf", experimentalFeature: .nonEscapableTypes)
613616
case .rethrows:
614617
return KeywordSpec("rethrows", isLexerClassified: true)
615618
case .retroactive:

Examples/Tests/MacroExamples/Implementation/ComplexMacros/DictionaryIndirectionMacroTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ final class DictionaryStorageMacroTests: XCTestCase {
3232
""",
3333
expandedSource: """
3434
struct Point {
35-
var x: Int = 1 {
35+
var x: Int {
3636
get {
3737
_storage["x", default: 1] as! Int
3838
}
3939
set {
4040
_storage["x"] = newValue
4141
}
4242
}
43-
var y: Int = 2 {
43+
var y: Int {
4444
get {
4545
_storage["y", default: 2] as! Int
4646
}

Examples/Tests/MacroExamples/Implementation/ComplexMacros/ObservableMacroTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ final class ObservableMacroTests: XCTestCase {
7777
}
7878
}
7979
80-
var isHappy: Bool = true {
80+
var isHappy: Bool {
8181
get {
8282
_registrar.beginAccess(\.isHappy)
8383
defer {

Release Notes/511.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Swift Syntax 511 Release Notes
22

33
## New APIs
4+
- FixIt now has a new computed propery named edits
5+
- Description: the edits represent the non-overlapping textual edits that need to be performed when the Fix-It is applied.
6+
- Issue: https://github.com/apple/sourcekit-lsp/issues/909
7+
- Pull Request: https://github.com/apple/swift-syntax/pull/2314
8+
9+
- SourceEdit
10+
- Description: SourceEdit has been moved from SwiftRefactor to SwiftSyntax
11+
- Issue: https://github.com/apple/sourcekit-lsp/issues/909
12+
- Pull Request: https://github.com/apple/swift-syntax/pull/2314
413

514
- `assertMacroExpansion` now have new parameters named `applyFixIts` and `fixedSource`
615
- Description: `applyFixIts` and `fixedSource` are used to assert so ensure that the source code after applying Fix-Its matches this string.
@@ -21,6 +30,11 @@
2130
- Issue: https://github.com/apple/swift-syntax/issues/2267
2231
- Pull request: https://github.com/apple/swift-syntax/pull/2272
2332

33+
- `MacroExpansion{Error|Warning|FixIt}Message` moved to the `SwiftSyntaxMacros` module
34+
- Description: Move the `MacroExpansion{Error|Warning|FixIt}Message` types from the `SwiftSyntaxMacroExpansion` module to `SwiftSyntaxMacros`. Deprecated typealiases in `SwiftSyntaxMacroExpansion` forward to `SwiftSyntaxMacros`.
35+
- Pull request: https://github.com/apple/swift-syntax/pull/2338
36+
- Notes: The expansion diagnostic messages were defined in `SwiftSyntaxMacroExpansion`, which is intended as an implementation detail of the plugin server and should not need to be imported by macros.
37+
2438
## API-Incompatible Changes
2539

2640
- Effect specifiers:

Sources/SwiftDiagnostics/FixIt.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,45 @@ public struct FixIt {
4646
self.changes = changes
4747
}
4848
}
49+
50+
extension FixIt {
51+
/// The edits represent the non-overlapping textual edits that need to be performed when the Fix-It is applied.
52+
public var edits: [SourceEdit] {
53+
var existingEdits = [SourceEdit]()
54+
for change in changes {
55+
let edit = change.edit
56+
let isOverlapping = existingEdits.contains { edit.range.overlaps($0.range) }
57+
if !isOverlapping {
58+
// The edit overlaps with the previous edit. We can't apply both
59+
// without conflicts. Apply the one that's listed first and drop the
60+
// later edit.
61+
existingEdits.append(edit)
62+
}
63+
}
64+
return existingEdits
65+
}
66+
}
67+
68+
private extension FixIt.Change {
69+
var edit: SourceEdit {
70+
switch self {
71+
case .replace(let oldNode, let newNode):
72+
return SourceEdit(
73+
range: oldNode.position..<oldNode.endPosition,
74+
replacement: newNode.description
75+
)
76+
77+
case .replaceLeadingTrivia(let token, let newTrivia):
78+
return SourceEdit(
79+
range: token.position..<token.positionAfterSkippingLeadingTrivia,
80+
replacement: newTrivia.description
81+
)
82+
83+
case .replaceTrailingTrivia(let token, let newTrivia):
84+
return SourceEdit(
85+
range: token.endPositionBeforeTrailingTrivia..<token.endPosition,
86+
replacement: newTrivia.description
87+
)
88+
}
89+
}
90+
}

Sources/SwiftParser/Declarations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension DeclarationModifier {
1818
case .__consuming, .__setter_access, ._const, ._local, .async,
1919
.borrowing, .class, .consuming, .convenience, .distributed, .dynamic,
2020
.final, .indirect, .infix, .isolated, .lazy, .mutating, .nonmutating,
21-
.optional, .override, .postfix, .prefix, .reasync, .required,
21+
.optional, .override, .postfix, .prefix, .reasync, ._resultDependsOnSelf, .required,
2222
.rethrows, .static, .weak:
2323
return false
2424
case .fileprivate, .internal, .nonisolated, .package, .open, .private,

Sources/SwiftParser/Modifiers.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ extension Parser {
8585
(.declarationModifier(._const), let handle)?,
8686
(.declarationModifier(._local), let handle)?,
8787
(.declarationModifier(.__setter_access), let handle)?,
88-
(.declarationModifier(.reasync), let handle)?:
88+
(.declarationModifier(.reasync), let handle)?,
89+
(.declarationModifier(._resultDependsOnSelf), let handle)? where experimentalFeatures.contains(.nonEscapableTypes):
8990
let (unexpectedBeforeKeyword, keyword) = self.eat(handle)
9091
elements.append(RawDeclModifierSyntax(unexpectedBeforeKeyword, name: keyword, detail: nil, arena: self.arena))
9192
case (.declarationModifier(.rethrows), _)?:
@@ -99,9 +100,9 @@ extension Parser {
99100
}
100101

101102
extension Parser {
102-
mutating func parseModifierDetail(_ keyword: Keyword) -> RawDeclModifierDetailSyntax {
103+
mutating func parseModifierDetail() -> RawDeclModifierDetailSyntax {
103104
let (unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
104-
let (unexpectedBeforeDetailToken, detailToken) = self.expect(.identifier, TokenSpec(keyword, remapping: .identifier), default: .identifier)
105+
let (unexpectedBeforeDetailToken, detailToken) = self.expect(.identifier, TokenSpec(.set, remapping: .identifier), default: .identifier)
105106
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
106107
return RawDeclModifierDetailSyntax(
107108
unexpectedBeforeLeftParen,
@@ -119,7 +120,7 @@ extension Parser {
119120

120121
let detail: RawDeclModifierDetailSyntax?
121122
if self.at(.leftParen) {
122-
detail = self.parseModifierDetail(.set)
123+
detail = self.parseModifierDetail()
123124
} else {
124125
detail = nil
125126
}
@@ -224,7 +225,18 @@ extension Parser {
224225

225226
let detail: RawDeclModifierDetailSyntax?
226227
if self.at(.leftParen) {
227-
detail = self.parseModifierDetail(.unsafe)
228+
let (unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
229+
let (unexpectedBeforeDetailToken, detailToken) = self.expect(TokenSpec(.unsafe, remapping: .identifier))
230+
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
231+
detail = RawDeclModifierDetailSyntax(
232+
unexpectedBeforeLeftParen,
233+
leftParen: leftParen,
234+
unexpectedBeforeDetailToken,
235+
detail: detailToken,
236+
unexpectedBeforeRightParen,
237+
rightParen: rightParen,
238+
arena: self.arena
239+
)
228240
} else {
229241
detail = nil
230242
}

Sources/SwiftParser/Patterns.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
@_spi(RawSyntax) import SwiftSyntax
13+
@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) import SwiftSyntax
1414

1515
extension Parser {
1616
/// Parse a pattern.

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ enum TokenPrecedence: Comparable {
230230
// Declaration Modifiers
231231
.__consuming, .final, .required, .optional, .lazy, .dynamic, .infix, .postfix, .prefix, .mutating, .nonmutating, .convenience, .override, .package, .open,
232232
.__setter_access, .indirect, .isolated, .nonisolated, .distributed, ._local,
233-
.inout, ._mutating, ._borrow, ._borrowing, .borrowing, ._consuming, .consuming, .consume,
233+
.inout, ._mutating, ._borrow, ._borrowing, .borrowing, ._consuming, .consuming, .consume, ._resultDependsOnSelf,
234234
// Accessors
235235
.get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress,
236236
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, ._modify,

Sources/SwiftParser/TokenSpecSet.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ enum DeclarationModifier: TokenSpecSet {
376376
case `static`
377377
case unowned
378378
case weak
379+
case _resultDependsOnSelf
379380

380381
init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
381382
switch PrepareForKeywordMatch(lexeme) {
@@ -414,6 +415,7 @@ enum DeclarationModifier: TokenSpecSet {
414415
case TokenSpec(.static): self = .static
415416
case TokenSpec(.unowned): self = .unowned
416417
case TokenSpec(.weak): self = .weak
418+
case TokenSpec(._resultDependsOnSelf) where experimentalFeatures.contains(.nonEscapableTypes): self = ._resultDependsOnSelf
417419
default: return nil
418420
}
419421
}
@@ -455,6 +457,7 @@ enum DeclarationModifier: TokenSpecSet {
455457
case .static: return .keyword(.static)
456458
case .unowned: return TokenSpec(.unowned, recoveryPrecedence: .declKeyword)
457459
case .weak: return TokenSpec(.weak, recoveryPrecedence: .declKeyword)
460+
case ._resultDependsOnSelf: return TokenSpec(._resultDependsOnSelf, recoveryPrecedence: .declKeyword)
458461
}
459462
}
460463
}

Sources/SwiftParser/generated/ExperimentalFeatures.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ extension Parser {
2525

2626
extension Parser.ExperimentalFeatures {
2727
/// Whether to enable the parsing of reference bindings.
28-
public static let referenceBindings = Self(rawValue: 1 << 0)
28+
public static let referenceBindings = Self (rawValue: 1 << 0)
2929

3030
/// Whether to enable the parsing of 'then' statements.
31-
public static let thenStatements = Self(rawValue: 1 << 1)
31+
public static let thenStatements = Self (rawValue: 1 << 1)
3232

3333
/// Whether to enable the parsing of typed throws.
34-
public static let typedThrows = Self(rawValue: 1 << 2)
34+
public static let typedThrows = Self (rawValue: 1 << 2)
3535

3636
/// Whether to enable the parsing of 'do' expressions.
37-
public static let doExpressions = Self(rawValue: 1 << 3)
37+
public static let doExpressions = Self (rawValue: 1 << 3)
38+
39+
/// Whether to enable the parsing of NonEscableTypes.
40+
public static let nonEscapableTypes = Self (rawValue: 1 << 4)
3841
}

Sources/SwiftParser/generated/Parser+TokenSpecSet.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,8 @@ extension DeclModifierSyntax {
714714
case `private`
715715
case `public`
716716
case reasync
717+
@_spi(ExperimentalLanguageFeatures)
718+
case _resultDependsOnSelf
717719
case required
718720
case `static`
719721
case unowned
@@ -783,6 +785,8 @@ extension DeclModifierSyntax {
783785
self = .public
784786
case TokenSpec(.reasync):
785787
self = .reasync
788+
case TokenSpec(._resultDependsOnSelf) where experimentalFeatures.contains(.nonEscapableTypes):
789+
self = ._resultDependsOnSelf
786790
case TokenSpec(.required):
787791
self = .required
788792
case TokenSpec(.static):
@@ -860,6 +864,8 @@ extension DeclModifierSyntax {
860864
return .keyword(.public)
861865
case .reasync:
862866
return .keyword(.reasync)
867+
case ._resultDependsOnSelf:
868+
return .keyword(._resultDependsOnSelf)
863869
case .required:
864870
return .keyword(.required)
865871
case .static:
@@ -939,6 +945,8 @@ extension DeclModifierSyntax {
939945
return .keyword(.public)
940946
case .reasync:
941947
return .keyword(.reasync)
948+
case ._resultDependsOnSelf:
949+
return .keyword(._resultDependsOnSelf)
942950
case .required:
943951
return .keyword(.required)
944952
case .static:

0 commit comments

Comments
 (0)