Skip to content

Add support for lifetime type specifiers #2433

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
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
9 changes: 9 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/Child.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public enum TokenChoice: Equatable {
case .token: return false
}
}

public var varOrCaseName: TokenSyntax {
switch self {
case .keyword(let keyword):
return keyword.spec.varOrCaseName
case .token(let token):
return token.spec.varOrCaseName
}
}
}

public enum ChildKind {
Expand Down
4 changes: 2 additions & 2 deletions CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ struct GrammarGenerator {
let optionality = child.isOptional ? "?" : ""
switch child.kind {
case .node(let kind):
return "``\(kind.syntaxType)``\(optionality)"
return "\(kind.doccLink)\(optionality)"
case .nodeChoices(let choices):
let choicesDescriptions = choices.map { grammar(for: $0) }
return "(\(choicesDescriptions.joined(separator: " | ")))\(optionality)"
case .collection(kind: let kind, _, _, _):
return "``\(kind.syntaxType)``\(optionality)"
return "\(kind.doccLink)\(optionality)"
case .token(let choices, _, _):
if choices.count == 1 {
return "\(grammar(for: choices.first!))\(optionality)"
Expand Down
21 changes: 15 additions & 6 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public enum Keyword: CaseIterable {
case _Class
case _compilerInitialized
case _const
case _consume
case _consuming
case _copy
case _documentation
case _dynamicReplacement
case _effects
Expand All @@ -119,6 +121,7 @@ public enum Keyword: CaseIterable {
case _local
case _modify
case _move
case _mutate
case _mutating
case _NativeClass
case _NativeRefCountedObject
Expand Down Expand Up @@ -328,6 +331,8 @@ public enum Keyword: CaseIterable {
return KeywordSpec("_backDeploy")
case ._borrow:
return KeywordSpec("_borrow")
case ._borrowing:
return KeywordSpec("_borrowing", experimentalFeature: .referenceBindings, or: .borrowingSwitch)
case ._BridgeObject:
return KeywordSpec("_BridgeObject")
case ._cdecl:
Expand All @@ -338,6 +343,12 @@ public enum Keyword: CaseIterable {
return KeywordSpec("_compilerInitialized")
case ._const:
return KeywordSpec("_const")
case ._consume:
return KeywordSpec("_consume", experimentalFeature: .nonescapableTypes)
case ._consuming:
return KeywordSpec("_consuming", experimentalFeature: .referenceBindings)
case ._copy:
return KeywordSpec("_copy", experimentalFeature: .nonescapableTypes)
case ._documentation:
return KeywordSpec("_documentation")
case ._dynamicReplacement:
Expand All @@ -358,6 +369,10 @@ public enum Keyword: CaseIterable {
return KeywordSpec("_modify")
case ._move:
return KeywordSpec("_move")
case ._mutate:
return KeywordSpec("_mutate", experimentalFeature: .nonescapableTypes)
case ._mutating:
return KeywordSpec("_mutating", experimentalFeature: .referenceBindings)
case ._NativeClass:
return KeywordSpec("_NativeClass")
case ._NativeRefCountedObject:
Expand Down Expand Up @@ -743,12 +758,6 @@ public enum Keyword: CaseIterable {
return KeywordSpec("wrt")
case .yield:
return KeywordSpec("yield")
case ._borrowing:
return KeywordSpec("_borrowing", experimentalFeature: .referenceBindings, or: .borrowingSwitch)
case ._consuming:
return KeywordSpec("_consuming", experimentalFeature: .referenceBindings)
case ._mutating:
return KeywordSpec("_mutating", experimentalFeature: .referenceBindings)
}
}
}
14 changes: 5 additions & 9 deletions CodeGeneration/Sources/SyntaxSupport/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ public class Node {
// This will repeat the syntax type before and after the dot, which is
// a little unfortunate, but it's the only way I found to get docc to
// generate a fully-qualified type + member.
return " - ``\($0.node.syntaxType)``.``\($0.node.syntaxType)/\(childName)``"
return " - \($0.node.doccLink).``\($0.node.syntaxType)/\(childName)``"
} else {
return " - ``\($0.node.syntaxType)``"
return " - \($0.node.doccLink)"
}
}
.joined(separator: "\n")
Expand All @@ -249,7 +249,7 @@ public class Node {
let list =
SYNTAX_NODES
.filter { $0.base == self.kind && !$0.isExperimental }
.map { "- ``\($0.kind.syntaxType)``" }
.map { "- \($0.kind.doccLink)" }
.joined(separator: "\n")

guard !list.isEmpty else {
Expand Down Expand Up @@ -392,9 +392,9 @@ public struct CollectionNode {
public var grammar: SwiftSyntax.Trivia {
let grammar: String
if let onlyElement = elementChoices.only {
grammar = "``\(onlyElement.syntaxType)`` `*`"
grammar = "\(onlyElement.doccLink) `*`"
} else {
grammar = "(\(elementChoices.map { "``\($0.syntaxType)``" }.joined(separator: " | "))) `*`"
grammar = "(\(elementChoices.map { "\($0.doccLink)" }.joined(separator: " | "))) `*`"
}

return .docCommentTrivia(
Expand All @@ -421,7 +421,3 @@ fileprivate extension Child {
}
}
}

fileprivate extension Node {

}
33 changes: 26 additions & 7 deletions CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public enum SyntaxNodeKind: String, CaseIterable {
case dictionaryExpr
case dictionaryType
case differentiabilityArgument
case differentiabilityArguments
case differentiabilityArgumentList
case differentiabilityArguments
case differentiabilityWithRespectToArgument
case differentiableAttributeArguments
case discardAssignmentExpr
Expand Down Expand Up @@ -182,6 +182,9 @@ public enum SyntaxNodeKind: String, CaseIterable {
case labeledSpecializeArgument
case labeledStmt
case layoutRequirement
case lifetimeSpecifierArgument
case lifetimeSpecifierArgumentList
case lifetimeTypeSpecifier
case macroDecl
case macroExpansionDecl
case macroExpansionExpr
Expand Down Expand Up @@ -244,14 +247,15 @@ public enum SyntaxNodeKind: String, CaseIterable {
case returnStmt
case sameTypeRequirement
case sequenceExpr
case simpleTypeSpecifier
case simpleStringLiteralExpr
case simpleStringLiteralSegmentList
case someOrAnyType
case sourceFile
case specializeAttributeArgumentList
case specializeAvailabilityArgument
case specializeTargetFunctionArgument
case stmt
case simpleStringLiteralExpr
case simpleStringLiteralSegmentList
case stringLiteralExpr
case stringLiteralSegmentList
case stringSegment
Expand Down Expand Up @@ -285,6 +289,9 @@ public enum SyntaxNodeKind: String, CaseIterable {
case typeEffectSpecifiers
case typeExpr
case typeInitializerClause
case typeSpecifier
case lifetimeSpecifierArguments
case typeSpecifierList
case unavailableFromAsyncAttributeArguments
case underscorePrivateAttributeArguments
case unexpectedNodes
Expand All @@ -299,10 +306,10 @@ public enum SyntaxNodeKind: String, CaseIterable {
case whereClause
case whileStmt
case wildcardPattern
case yieldStmt
case yieldedExpression
case yieldedExpressionsClause
case yieldedExpressionList
case yieldedExpressionsClause
case yieldStmt

// Nodes that have special handling throughout the codebase

Expand Down Expand Up @@ -348,6 +355,17 @@ public enum SyntaxNodeKind: String, CaseIterable {
}
}

/// If this node is non-experimental a docc link wrapped in two backticks.
///
/// For experimental nodes, the node's type name in code font.
public var doccLink: String {
if let node = SYNTAX_NODE_MAP[self], node.isExperimental {
return "`\(syntaxType)`"
} else {
return "``\(syntaxType)``"
}
}

/// For base nodes, the name of the corresponding protocol to which all the
/// concrete nodes that have this base kind, conform.
public var protocolType: TypeSyntax {
Expand Down Expand Up @@ -405,8 +423,8 @@ public enum SyntaxNodeKind: String, CaseIterable {
case .derivativeAttributeArguments: return "derivativeRegistrationAttributeArguments"
case .designatedType: return "designatedTypeElement"
case .differentiabilityArgument: return "differentiabilityParam"
case .differentiabilityArguments: return "differentiabilityParams"
case .differentiabilityArgumentList: return "differentiabilityParamList"
case .differentiabilityArguments: return "differentiabilityParams"
case .differentiabilityWithRespectToArgument: return "differentiabilityParamsClause"
case .documentationAttributeArgumentList: return "documentationAttributeArguments"
case .dynamicReplacementAttributeArguments: return "dynamicReplacementArguments"
Expand Down Expand Up @@ -440,6 +458,7 @@ public enum SyntaxNodeKind: String, CaseIterable {
case .precedenceGroupName: return "precedenceGroupNameElement"
case .repeatStmt: return "repeatWhileStmt"
case .someOrAnyType: return "constrainedSugarType"
case .simpleTypeSpecifier: return "typeSpecifier"
case .specializeAttributeArgumentList: return "specializeAttributeSpecList"
case .specializeAvailabilityArgument: return "availabilityEntry"
case .specializeTargetFunctionArgument: return "targetFunctionEntry"
Expand All @@ -451,8 +470,8 @@ public enum SyntaxNodeKind: String, CaseIterable {
case .typeAliasDecl: return "typealiasDecl"
case .unavailableFromAsyncAttributeArguments: return "unavailableFromAsyncArguments"
case .yieldedExpression: return "yieldExprListElement"
case .yieldedExpressionsClause: return "yieldList"
case .yieldedExpressionList: return "yieldExprList"
case .yieldedExpressionsClause: return "yieldList"
default: return nil
}
}
Expand Down
Loading