Skip to content

Commit

Permalink
Delete dependsOn support
Browse files Browse the repository at this point in the history
  • Loading branch information
meg-gupta committed Oct 9, 2024
1 parent f4acb89 commit 8f28526
Show file tree
Hide file tree
Showing 30 changed files with 20 additions and 1,420 deletions.
6 changes: 0 additions & 6 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public enum Keyword: CaseIterable {
case `default`
case `defer`
case `deinit`
case dependsOn
case deprecated
case derivative
case didSet
Expand Down Expand Up @@ -257,7 +256,6 @@ public enum Keyword: CaseIterable {
case reverse
case right
case safe
case scoped
case `self`
case sending
case `Self`
Expand Down Expand Up @@ -476,8 +474,6 @@ public enum Keyword: CaseIterable {
return KeywordSpec("defer", isLexerClassified: true)
case .deinit:
return KeywordSpec("deinit", isLexerClassified: true)
case .dependsOn:
return KeywordSpec("dependsOn", experimentalFeature: .nonescapableTypes)
case .deprecated:
return KeywordSpec("deprecated")
case .derivative:
Expand Down Expand Up @@ -654,8 +650,6 @@ public enum Keyword: CaseIterable {
return KeywordSpec("right")
case .safe:
return KeywordSpec("safe")
case .scoped:
return KeywordSpec("scoped", experimentalFeature: .nonescapableTypes)
case .self:
return KeywordSpec("self", isLexerClassified: true)
case .Self:
Expand Down
4 changes: 0 additions & 4 deletions CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ public enum SyntaxNodeKind: String, CaseIterable, IdentifierConvertible, TypeCon
case labeledSpecializeArgument
case labeledStmt
case layoutRequirement
case lifetimeSpecifierArgument
case lifetimeSpecifierArgumentList
case lifetimeTypeSpecifier
case macroDecl
case macroExpansionDecl
case macroExpansionExpr
Expand Down Expand Up @@ -290,7 +287,6 @@ public enum SyntaxNodeKind: String, CaseIterable, IdentifierConvertible, TypeCon
case typeExpr
case typeInitializerClause
case typeSpecifier
case lifetimeSpecifierArguments
case typeSpecifierList
case unavailableFromAsyncAttributeArguments
case underscorePrivateAttributeArguments
Expand Down
77 changes: 1 addition & 76 deletions CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -500,81 +500,6 @@ public let TYPE_NODES: [Node] = [
]
),

Node(
kind: .lifetimeSpecifierArgument,
base: .syntax,
experimentalFeature: .nonescapableTypes,
nameForDiagnostics: nil,
documentation: """
A single argument that can be added to a lifetime specifier like `borrow`, `mutate`, `consume` or `copy`.
### Example
`data` in `func foo(data: Array<Item>) -> borrow(data) ComplexReferenceType`
""",
traits: [
"WithTrailingComma"
],
children: [
Child(
name: "parameter",
kind: .token(choices: [.token(.identifier), .keyword(.self), .token(.integerLiteral)]),
nameForDiagnostics: "parameter reference",
documentation: """
The parameter on which the lifetime of this type depends.
This can be an identifier referring to an external parameter name, an integer literal to refer to an unnamed
parameter or `self` if the type's lifetime depends on the object the method is called on.
"""
),
Child(
name: "trailingComma",
kind: .token(choices: [.token(.comma)]),
isOptional: true
),
]
),

Node(
kind: .lifetimeSpecifierArgumentList,
base: .syntaxCollection,
experimentalFeature: .nonescapableTypes,
nameForDiagnostics: nil,
elementChoices: [.lifetimeSpecifierArgument]
),

Node(
kind: .lifetimeTypeSpecifier,
base: .syntax,
experimentalFeature: .nonescapableTypes,
nameForDiagnostics: "lifetime specifier",
documentation: "A specifier that specifies function parameter on whose lifetime a type depends",
children: [
Child(
name: "dependsOnKeyword",
kind: .token(choices: [.keyword(.dependsOn)]),
documentation: "lifetime dependence specifier on the return type"
),
Child(
name: "leftParen",
kind: .token(choices: [.token(.leftParen)])
),
Child(
name: "scopedKeyword",
kind: .token(choices: [.keyword(.scoped)]),
documentation: "lifetime of return value is scoped to the lifetime of the original value",
isOptional: true
),
Child(
name: "arguments",
kind: .collection(kind: .lifetimeSpecifierArgumentList, collectionElementName: "Arguments")
),
Child(
name: "rightParen",
kind: .token(choices: [.token(.rightParen)])
),
]
),

Node(
kind: .simpleTypeSpecifier,
base: .syntax,
Expand Down Expand Up @@ -602,6 +527,6 @@ public let TYPE_NODES: [Node] = [
kind: .typeSpecifierList,
base: .syntaxCollection,
nameForDiagnostics: nil,
elementChoices: [.simpleTypeSpecifier, .lifetimeTypeSpecifier]
elementChoices: [.simpleTypeSpecifier]
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ class ValidateSyntaxNodes: XCTestCase {
node: .yieldedExpressionsClause,
message: "could conform to trait 'Parenthesized' but does not"
),
ValidationFailure(node: .lifetimeTypeSpecifier, message: "could conform to trait 'Parenthesized' but does not"),
]
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ nonisolated(unsafe) private var readabilityHandler: () -> Void = {
)
}

@_expose(wasm, "swift_wasm_macro_v1_pump")
@_expose(wasm,"swift_wasm_macro_v1_pump")
@_cdecl("swift_wasm_macro_v1_pump")
func wasmPump() {
readabilityHandler()
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/TokenPrecedence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ enum TokenPrecedence: Comparable {
.convenience, .override, .package, .open,
.__setter_access, .indirect, .isolated, .nonisolated, .distributed, ._local,
.inout, ._mutating, ._borrow, ._borrowing, .borrowing, ._consuming, .consuming, .consume,
.dependsOn, .scoped, .sending,
.sending,
// Accessors
.get, .set, .didSet, .willSet, .unsafeAddress, .addressWithOwner, .addressWithNativeOwner, .unsafeMutableAddress,
.mutableAddressWithOwner, .mutableAddressWithNativeOwner, ._read, .read, ._modify, .modify,
Expand Down
78 changes: 6 additions & 72 deletions Sources/SwiftParser/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -874,69 +874,11 @@ extension Parser.Lookahead {
}

extension Parser {
private mutating func parseLifetimeTypeSpecifier() -> RawTypeSpecifierListSyntax.Element {
let (unexpectedBeforeDependsOnKeyword, dependsOnKeyword) = self.expect(.keyword(.dependsOn))

guard let leftParen = self.consume(if: .leftParen) else {
// If there is no left paren, add an entirely missing detail. Otherwise, we start to consume the following type
// name as a token inside the detail, which leads to confusing recovery results.
let lifetimeSpecifierArgumentList = RawLifetimeSpecifierArgumentListSyntax(
elements: [
RawLifetimeSpecifierArgumentSyntax(parameter: missingToken(.identifier), trailingComma: nil, arena: arena)
],
arena: self.arena
)
let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax(
unexpectedBeforeDependsOnKeyword,
dependsOnKeyword: dependsOnKeyword,
leftParen: missingToken(.leftParen),
scopedKeyword: nil,
arguments: lifetimeSpecifierArgumentList,
rightParen: missingToken(.rightParen),
arena: self.arena
)
return .lifetimeTypeSpecifier(lifetimeSpecifier)
}

let scoped = self.consume(if: .keyword(.scoped))
var keepGoing: RawTokenSyntax?
var arguments: [RawLifetimeSpecifierArgumentSyntax] = []
var loopProgress = LoopProgressCondition()
repeat {
let (unexpectedBeforeParameter, parameter) = self.expect(
anyIn: LifetimeSpecifierArgumentSyntax.ParameterOptions.self,
default: .identifier
)
keepGoing = self.consume(if: .comma)
arguments.append(
RawLifetimeSpecifierArgumentSyntax(
unexpectedBeforeParameter,
parameter: parameter,
trailingComma: keepGoing,
arena: arena
)
)
} while keepGoing != nil && self.hasProgressed(&loopProgress)
let lifetimeSpecifierArgumentList = RawLifetimeSpecifierArgumentListSyntax(elements: arguments, arena: self.arena)
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
let lifetimeSpecifier = RawLifetimeTypeSpecifierSyntax(
unexpectedBeforeDependsOnKeyword,
dependsOnKeyword: dependsOnKeyword,
leftParen: leftParen,
scopedKeyword: scoped,
arguments: lifetimeSpecifierArgumentList,
unexpectedBeforeRightParen,
rightParen: rightParen,
arena: self.arena
)
return .lifetimeTypeSpecifier(lifetimeSpecifier)
}

private mutating func parseSimpleTypeSpecifier(
specifierHandle: TokenConsumptionHandle
) -> RawTypeSpecifierListSyntax.Element {
) -> RawSimpleTypeSpecifierSyntax {
let specifier = self.eat(specifierHandle)
return .simpleTypeSpecifier(RawSimpleTypeSpecifierSyntax(specifier: specifier, arena: arena))
return RawSimpleTypeSpecifierSyntax(specifier: specifier, arena: arena)
}

mutating func parseTypeAttributeList(
Expand All @@ -945,26 +887,18 @@ extension Parser {
specifiers: RawTypeSpecifierListSyntax,
attributes: RawAttributeListSyntax
)? {
var specifiers: [RawTypeSpecifierListSyntax.Element] = []
var specifiers: [RawSimpleTypeSpecifierSyntax] = []
SPECIFIER_PARSING: while canHaveParameterSpecifier {
if let (_, specifierHandle) = self.at(anyIn: SimpleTypeSpecifierSyntax.SpecifierOptions.self) {
specifiers.append(parseSimpleTypeSpecifier(specifierHandle: specifierHandle))
} else if self.at(.keyword(.dependsOn)) {
if self.experimentalFeatures.contains(.nonescapableTypes) {
specifiers.append(parseLifetimeTypeSpecifier())
} else {
break SPECIFIER_PARSING
}
} else {
break SPECIFIER_PARSING
}
}
specifiers += misplacedSpecifiers.map {
.simpleTypeSpecifier(
RawSimpleTypeSpecifierSyntax(
specifier: missingToken($0.tokenKind, text: $0.tokenText),
arena: arena
)
RawSimpleTypeSpecifierSyntax(
specifier: missingToken($0.tokenKind, text: $0.tokenText),
arena: arena
)
}

Expand Down
61 changes: 0 additions & 61 deletions Sources/SwiftParser/generated/Parser+TokenSpecSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2679,67 +2679,6 @@ extension LayoutRequirementSyntax {
}
}

extension LifetimeSpecifierArgumentSyntax {
@_spi(Diagnostics)
public enum ParameterOptions: TokenSpecSet {
case identifier
case `self`
case integerLiteral

init?(lexeme: Lexer.Lexeme, experimentalFeatures: Parser.ExperimentalFeatures) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(.identifier):
self = .identifier
case TokenSpec(.self):
self = .self
case TokenSpec(.integerLiteral):
self = .integerLiteral
default:
return nil
}
}

public init?(token: TokenSyntax) {
switch token {
case TokenSpec(.identifier):
self = .identifier
case TokenSpec(.self):
self = .self
case TokenSpec(.integerLiteral):
self = .integerLiteral
default:
return nil
}
}

var spec: TokenSpec {
switch self {
case .identifier:
return .identifier
case .self:
return .keyword(.self)
case .integerLiteral:
return .integerLiteral
}
}

/// Returns a token that satisfies the `TokenSpec` of this case.
///
/// If the token kind of this spec has variable text, e.g. for an identifier, this returns a token with empty text.
@_spi(Diagnostics)
public var tokenSyntax: TokenSyntax {
switch self {
case .identifier:
return .identifier("")
case .self:
return .keyword(.self)
case .integerLiteral:
return .integerLiteral("")
}
}
}
}

extension MemberTypeSyntax {
@_spi(Diagnostics)
public enum NameOptions: TokenSpecSet {
Expand Down
3 changes: 1 addition & 2 deletions Sources/SwiftParserDiagnostics/SyntaxExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ extension TypeSpecifierListSyntax {
var simpleSpecifiers: [TokenSyntax] {
return self.compactMap { specifier in
switch specifier {
case .simpleTypeSpecifier(let specifier): return specifier.specifier
case .lifetimeTypeSpecifier: return nil
case let specifier: return specifier.specifier
#if RESILIENT_LIBRARIES
@unknown default:
fatalError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ private func childNameForDiagnostics(_ keyPath: AnyKeyPath) -> String? {
return "size"
case \LayoutRequirementSyntax.alignment:
return "alignment"
case \LifetimeSpecifierArgumentSyntax.parameter:
return "parameter reference"
case \MacroDeclSyntax.attributes:
return "attributes"
case \MacroDeclSyntax.modifiers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ extension SyntaxKind {
return "labeled statement"
case .layoutRequirement:
return "layout requirement"
case .lifetimeTypeSpecifier:
return "lifetime specifier"
case .macroDecl:
return "macro"
case .macroExpansionDecl:
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftSyntax/SwiftSyntaxCompatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension AttributedTypeSyntax {
) {
let specifiers: TypeSpecifierListSyntax
if let specifier {
specifiers = [.simpleTypeSpecifier(SimpleTypeSpecifierSyntax(specifier: specifier))]
specifiers = [SimpleTypeSpecifierSyntax(specifier: specifier)]
} else {
specifiers = []
}
Expand Down Expand Up @@ -82,14 +82,14 @@ extension AttributedTypeSyntax {
@available(*, deprecated, message: "Access the specifiers list instead")
public var specifier: TokenSyntax? {
get {
if case .simpleTypeSpecifier(let simpleSpecifier) = specifiers.first {
if let simpleSpecifier = specifiers.first {
return simpleSpecifier.specifier
}
return nil
}
set {
if let newValue {
specifiers = [.simpleTypeSpecifier(SimpleTypeSpecifierSyntax(specifier: newValue))]
specifiers = [SimpleTypeSpecifierSyntax(specifier: newValue)]
} else {
specifiers = []
}
Expand Down
Loading

0 comments on commit 8f28526

Please sign in to comment.