Skip to content

Commit 23c2780

Browse files
committed
Add initial support for resultDependsOn and resultDependsOnSelf
Add them under a new NonEscapableTypes expermental feature
1 parent f6868a7 commit 23c2780

File tree

16 files changed

+106
-7
lines changed

16 files changed

+106
-7
lines changed

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ public enum Keyword: CaseIterable {
239239
case renamed
240240
case `repeat`
241241
case required
242+
case resultDependsOn
243+
case resultDependsOnSelf
242244
case `rethrows`
243245
case retroactive
244246
case `return`
@@ -610,6 +612,10 @@ public enum Keyword: CaseIterable {
610612
return KeywordSpec("repeat", isLexerClassified: true)
611613
case .required:
612614
return KeywordSpec("required")
615+
case .resultDependsOn:
616+
return KeywordSpec("resultDependsOn", experimentalFeature: .nonEscapableTypes)
617+
case .resultDependsOnSelf:
618+
return KeywordSpec("resultDependsOnSelf", experimentalFeature: .nonEscapableTypes)
613619
case .rethrows:
614620
return KeywordSpec("rethrows", isLexerClassified: true)
615621
case .retroactive:

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public let TYPE_NODES: [Node] = [
5252
.keyword(._const),
5353
.keyword(.borrowing),
5454
.keyword(.consuming),
55+
.keyword(.resultDependsOn),
5556
]),
5657
isOptional: true
5758
),

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, .nonisolated,
21-
.nonmutating, .optional, .override, .postfix, .prefix, .reasync,
21+
.nonmutating, .optional, .override, .postfix, .prefix, .reasync, .resultDependsOnSelf,
2222
.required, .rethrows, .static, .weak:
2323
return false
2424
case .fileprivate, .internal, .package, .open, .private,

Sources/SwiftParser/Modifiers.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ extension Parser {
8484
(.declarationModifier(._const), let handle)?,
8585
(.declarationModifier(._local), let handle)?,
8686
(.declarationModifier(.__setter_access), let handle)?,
87-
(.declarationModifier(.reasync), let handle)?:
87+
(.declarationModifier(.reasync), let handle)?,
88+
(.declarationModifier(.resultDependsOnSelf), let handle)? where experimentalFeatures.contains(.nonEscapableTypes):
8889
let (unexpectedBeforeKeyword, keyword) = self.eat(handle)
8990
elements.append(RawDeclModifierSyntax(unexpectedBeforeKeyword, name: keyword, detail: nil, arena: self.arena))
9091
case (.declarationModifier(.rethrows), _)?:

Sources/SwiftParser/Patterns.swift

Lines changed: 2 additions & 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.
@@ -354,6 +354,7 @@ extension Parser.Lookahead {
354354
&& !self.at(.keyword(.__owned))
355355
&& !self.at(.keyword(.borrowing))
356356
&& !self.at(.keyword(.consuming))
357+
&& (!experimentalFeatures.contains(.nonEscapableTypes) || !self.at(.keyword(.resultDependsOn)))
357358
{
358359
return true
359360
}

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, .resultDependsOn,
234234
// Accessors
235235
.get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress,
236236
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, ._modify,

Sources/SwiftParser/TokenSpecSet.swift

Lines changed: 7 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
}
@@ -679,6 +682,7 @@ public enum TypeSpecifier: TokenSpecSet {
679682
case shared
680683
case borrowing
681684
case consuming
685+
case resultDependsOn
682686

683687
init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
684688
switch PrepareForKeywordMatch(lexeme) {
@@ -687,6 +691,7 @@ public enum TypeSpecifier: TokenSpecSet {
687691
case TokenSpec(.__shared): self = .shared
688692
case TokenSpec(.consuming): self = .consuming
689693
case TokenSpec(.borrowing): self = .borrowing
694+
case TokenSpec(.resultDependsOn) where experimentalFeatures.contains(.nonEscapableTypes): self = .resultDependsOn
690695
default: return nil
691696
}
692697
}
@@ -699,6 +704,7 @@ public enum TypeSpecifier: TokenSpecSet {
699704
case TokenSpec(.__shared): self = .shared
700705
case TokenSpec(.consuming): self = .shared
701706
case TokenSpec(.borrowing): self = .shared
707+
case TokenSpec(.resultDependsOn): self = .resultDependsOn
702708
default: return nil
703709
}
704710
}
@@ -710,6 +716,7 @@ public enum TypeSpecifier: TokenSpecSet {
710716
case .shared: return .keyword(.__shared)
711717
case .borrowing: return .keyword(.borrowing)
712718
case .consuming: return .keyword(.consuming)
719+
case .resultDependsOn: return .keyword(.resultDependsOn)
713720
}
714721
}
715722
}

Sources/SwiftParser/generated/ExperimentalFeatures.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ extension Parser.ExperimentalFeatures {
3535

3636
/// Whether to enable the parsing of 'do' expressions.
3737
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
}

0 commit comments

Comments
 (0)