Skip to content

Commit 5285907

Browse files
authored
Merge pull request #2281 from apple/resultDependsOn
Add initial support for _resultDependsOnSelf
2 parents b73118c + e79e22b commit 5285907

File tree

14 files changed

+58
-5
lines changed

14 files changed

+58
-5
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: 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:

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: 2 additions & 1 deletion
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), _)?:

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: 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
}

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:

Sources/SwiftSyntax/generated/Keyword.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ public enum Keyword: UInt8, Hashable {
181181
case renamed
182182
case `repeat`
183183
case required
184+
@_spi(ExperimentalLanguageFeatures)
185+
case _resultDependsOnSelf
184186
case `rethrows`
185187
case retroactive
186188
case `return`
@@ -722,6 +724,8 @@ public enum Keyword: UInt8, Hashable {
722724
self = ._compilerInitialized
723725
case "_originallyDefinedIn":
724726
self = ._originallyDefinedIn
727+
case "_resultDependsOnSelf":
728+
self = ._resultDependsOnSelf
725729
case "unsafeMutableAddress":
726730
self = .unsafeMutableAddress
727731
default:
@@ -942,6 +946,7 @@ public enum Keyword: UInt8, Hashable {
942946
"renamed",
943947
"repeat",
944948
"required",
949+
"_resultDependsOnSelf",
945950
"rethrows",
946951
"retroactive",
947952
"return",

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
804804
.keyword("private"),
805805
.keyword("public"),
806806
.keyword("reasync"),
807+
.keyword("_resultDependsOnSelf"),
807808
.keyword("required"),
808809
.keyword("static"),
809810
.keyword("unowned"),

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesD.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public struct DeclModifierDetailSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyn
169169

170170
/// ### Children
171171
///
172-
/// - `name`: (`__consuming` | `__setter_access` | `_const` | `_local` | `actor` | `async` | `borrowing` | `class` | `consuming` | `convenience` | `distributed` | `dynamic` | `fileprivate` | `final` | `indirect` | `infix` | `internal` | `isolated` | `lazy` | `mutating` | `nonisolated` | `nonmutating` | `open` | `optional` | `override` | `package` | `postfix` | `prefix` | `private` | `public` | `reasync` | `required` | `static` | `unowned` | `weak`)
172+
/// - `name`: (`__consuming` | `__setter_access` | `_const` | `_local` | `actor` | `async` | `borrowing` | `class` | `consuming` | `convenience` | `distributed` | `dynamic` | `fileprivate` | `final` | `indirect` | `infix` | `internal` | `isolated` | `lazy` | `mutating` | `nonisolated` | `nonmutating` | `open` | `optional` | `override` | `package` | `postfix` | `prefix` | `private` | `public` | `reasync` | `_resultDependsOnSelf` | `required` | `static` | `unowned` | `weak`)
173173
/// - `detail`: ``DeclModifierDetailSyntax``?
174174
///
175175
/// ### Contained in
@@ -270,6 +270,7 @@ public struct DeclModifierSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNod
270270
/// - `private`
271271
/// - `public`
272272
/// - `reasync`
273+
/// - `_resultDependsOnSelf`
273274
/// - `required`
274275
/// - `static`
275276
/// - `unowned`

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,4 +3095,28 @@ final class DeclarationTests: ParserTestCase {
30953095
substructure: AccessorBlockSyntax(accessors: .getter([CodeBlockItemSyntax("return 1")]))
30963096
)
30973097
}
3098+
3099+
func testResultDependsOnSelf() {
3100+
assertParse(
3101+
"""
3102+
class MethodModifiers {
3103+
_resultDependsOnSelf func getDependentResult() -> Builtin.NativeObject {
3104+
return Builtin.unsafeCastToNativeObject(self)
3105+
}
3106+
}
3107+
""",
3108+
experimentalFeatures: .nonEscapableTypes
3109+
)
3110+
3111+
assertParse(
3112+
"""
3113+
class MethodModifiers {
3114+
_resultDependsOnSelf func _resultDependsOnSelf() -> Builtin.NativeObject {
3115+
return Builtin.unsafeCastToNativeObject(self)
3116+
}
3117+
}
3118+
""",
3119+
experimentalFeatures: .nonEscapableTypes
3120+
)
3121+
}
30983122
}

0 commit comments

Comments
 (0)