Skip to content

Add initial support for _resultDependsOnSelf #2281

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 1 commit into from
Nov 9, 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
1 change: 1 addition & 0 deletions CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ public let DECL_NODES: [Node] = [
.keyword(.private),
.keyword(.public),
.keyword(.reasync),
.keyword(._resultDependsOnSelf),
.keyword(.required),
.keyword(.static),
.keyword(.unowned),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ExperimentalFeature: String, CaseIterable {
case thenStatements
case typedThrows
case doExpressions
case nonEscapableTypes

/// The name of the feature, which is used in the doc comment.
public var featureName: String {
Expand All @@ -29,6 +30,8 @@ public enum ExperimentalFeature: String, CaseIterable {
return "typed throws"
case .doExpressions:
return "'do' expressions"
case .nonEscapableTypes:
return "NonEscableTypes"
}
}

Expand Down
3 changes: 3 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public enum Keyword: CaseIterable {
case renamed
case `repeat`
case required
case _resultDependsOnSelf
case `rethrows`
case retroactive
case `return`
Expand Down Expand Up @@ -610,6 +611,8 @@ public enum Keyword: CaseIterable {
return KeywordSpec("repeat", isLexerClassified: true)
case .required:
return KeywordSpec("required")
case ._resultDependsOnSelf:
return KeywordSpec("_resultDependsOnSelf", experimentalFeature: .nonEscapableTypes)
case .rethrows:
return KeywordSpec("rethrows", isLexerClassified: true)
case .retroactive:
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension DeclarationModifier {
case .__consuming, .__setter_access, ._const, ._local, .async,
.borrowing, .class, .consuming, .convenience, .distributed, .dynamic,
.final, .indirect, .infix, .isolated, .lazy, .mutating, .nonmutating,
.optional, .override, .postfix, .prefix, .reasync, .required,
.optional, .override, .postfix, .prefix, .reasync, ._resultDependsOnSelf, .required,
.rethrows, .static, .weak:
return false
case .fileprivate, .internal, .nonisolated, .package, .open, .private,
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftParser/Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ extension Parser {
(.declarationModifier(._const), let handle)?,
(.declarationModifier(._local), let handle)?,
(.declarationModifier(.__setter_access), let handle)?,
(.declarationModifier(.reasync), let handle)?:
(.declarationModifier(.reasync), let handle)?,
(.declarationModifier(._resultDependsOnSelf), let handle)? where experimentalFeatures.contains(.nonEscapableTypes):
let (unexpectedBeforeKeyword, keyword) = self.eat(handle)
elements.append(RawDeclModifierSyntax(unexpectedBeforeKeyword, name: keyword, detail: nil, arena: self.arena))
case (.declarationModifier(.rethrows), _)?:
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/Patterns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

@_spi(RawSyntax) import SwiftSyntax
@_spi(RawSyntax) @_spi(ExperimentalLanguageFeatures) import SwiftSyntax
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @_spi(ExperimentalLanguageFeatures) is no longer necessary since you removed support for _resultDependsOn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let it be because I am going to be using it in the follow on PR.


extension Parser {
/// Parse a pattern.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/TokenPrecedence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ enum TokenPrecedence: Comparable {
// Declaration Modifiers
.__consuming, .final, .required, .optional, .lazy, .dynamic, .infix, .postfix, .prefix, .mutating, .nonmutating, .convenience, .override, .package, .open,
.__setter_access, .indirect, .isolated, .nonisolated, .distributed, ._local,
.inout, ._mutating, ._borrow, ._borrowing, .borrowing, ._consuming, .consuming, .consume,
.inout, ._mutating, ._borrow, ._borrowing, .borrowing, ._consuming, .consuming, .consume, ._resultDependsOnSelf,
// Accessors
.get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress,
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, ._modify,
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftParser/TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ enum DeclarationModifier: TokenSpecSet {
case `static`
case unowned
case weak
case _resultDependsOnSelf

init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
switch PrepareForKeywordMatch(lexeme) {
Expand Down Expand Up @@ -414,6 +415,7 @@ enum DeclarationModifier: TokenSpecSet {
case TokenSpec(.static): self = .static
case TokenSpec(.unowned): self = .unowned
case TokenSpec(.weak): self = .weak
case TokenSpec(._resultDependsOnSelf) where experimentalFeatures.contains(.nonEscapableTypes): self = ._resultDependsOnSelf
default: return nil
}
}
Expand Down Expand Up @@ -455,6 +457,7 @@ enum DeclarationModifier: TokenSpecSet {
case .static: return .keyword(.static)
case .unowned: return TokenSpec(.unowned, recoveryPrecedence: .declKeyword)
case .weak: return TokenSpec(.weak, recoveryPrecedence: .declKeyword)
case ._resultDependsOnSelf: return TokenSpec(._resultDependsOnSelf, recoveryPrecedence: .declKeyword)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftParser/generated/ExperimentalFeatures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ extension Parser.ExperimentalFeatures {

/// Whether to enable the parsing of 'do' expressions.
public static let doExpressions = Self (rawValue: 1 << 3)

/// Whether to enable the parsing of NonEscableTypes.
public static let nonEscapableTypes = Self (rawValue: 1 << 4)
}
8 changes: 8 additions & 0 deletions Sources/SwiftParser/generated/Parser+TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ extension DeclModifierSyntax {
case `private`
case `public`
case reasync
@_spi(ExperimentalLanguageFeatures)
case _resultDependsOnSelf
case required
case `static`
case unowned
Expand Down Expand Up @@ -783,6 +785,8 @@ extension DeclModifierSyntax {
self = .public
case TokenSpec(.reasync):
self = .reasync
case TokenSpec(._resultDependsOnSelf) where experimentalFeatures.contains(.nonEscapableTypes):
self = ._resultDependsOnSelf
case TokenSpec(.required):
self = .required
case TokenSpec(.static):
Expand Down Expand Up @@ -860,6 +864,8 @@ extension DeclModifierSyntax {
return .keyword(.public)
case .reasync:
return .keyword(.reasync)
case ._resultDependsOnSelf:
return .keyword(._resultDependsOnSelf)
case .required:
return .keyword(.required)
case .static:
Expand Down Expand Up @@ -939,6 +945,8 @@ extension DeclModifierSyntax {
return .keyword(.public)
case .reasync:
return .keyword(.reasync)
case ._resultDependsOnSelf:
return .keyword(._resultDependsOnSelf)
case .required:
return .keyword(.required)
case .static:
Expand Down
5 changes: 5 additions & 0 deletions Sources/SwiftSyntax/generated/Keyword.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public enum Keyword: UInt8, Hashable {
case renamed
case `repeat`
case required
@_spi(ExperimentalLanguageFeatures)
case _resultDependsOnSelf
case `rethrows`
case retroactive
case `return`
Expand Down Expand Up @@ -722,6 +724,8 @@ public enum Keyword: UInt8, Hashable {
self = ._compilerInitialized
case "_originallyDefinedIn":
self = ._originallyDefinedIn
case "_resultDependsOnSelf":
self = ._resultDependsOnSelf
case "unsafeMutableAddress":
self = .unsafeMutableAddress
default:
Expand Down Expand Up @@ -942,6 +946,7 @@ public enum Keyword: UInt8, Hashable {
"renamed",
"repeat",
"required",
"_resultDependsOnSelf",
"rethrows",
"retroactive",
"return",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
.keyword("private"),
.keyword("public"),
.keyword("reasync"),
.keyword("_resultDependsOnSelf"),
.keyword("required"),
.keyword("static"),
.keyword("unowned"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public struct DeclModifierDetailSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyn

/// ### Children
///
/// - `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`)
/// - `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`)
/// - `detail`: ``DeclModifierDetailSyntax``?
///
/// ### Contained in
Expand Down Expand Up @@ -270,6 +270,7 @@ public struct DeclModifierSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNod
/// - `private`
/// - `public`
/// - `reasync`
/// - `_resultDependsOnSelf`
/// - `required`
/// - `static`
/// - `unowned`
Expand Down
24 changes: 24 additions & 0 deletions Tests/SwiftParserTest/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3095,4 +3095,28 @@ final class DeclarationTests: ParserTestCase {
substructure: AccessorBlockSyntax(accessors: .getter([CodeBlockItemSyntax("return 1")]))
)
}

func testResultDependsOnSelf() {
assertParse(
"""
class MethodModifiers {
_resultDependsOnSelf func getDependentResult() -> Builtin.NativeObject {
return Builtin.unsafeCastToNativeObject(self)
}
}
""",
experimentalFeatures: .nonEscapableTypes
)

assertParse(
"""
class MethodModifiers {
_resultDependsOnSelf func _resultDependsOnSelf() -> Builtin.NativeObject {
return Builtin.unsafeCastToNativeObject(self)
}
}
""",
experimentalFeatures: .nonEscapableTypes
)
}
}