Skip to content

Commit e154573

Browse files
authored
Merge pull request swiftlang#2433 from ahoppen/ahoppen/allow-multiple-type-specifiers
Add support for lifetime type specifiers
2 parents 9c34b1f + 3df63e8 commit e154573

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3414
-363
lines changed

CodeGeneration/Sources/SyntaxSupport/Child.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public enum TokenChoice: Equatable {
2424
case .token: return false
2525
}
2626
}
27+
28+
public var varOrCaseName: TokenSyntax {
29+
switch self {
30+
case .keyword(let keyword):
31+
return keyword.spec.varOrCaseName
32+
case .token(let token):
33+
return token.spec.varOrCaseName
34+
}
35+
}
2736
}
2837

2938
public enum ChildKind {

CodeGeneration/Sources/SyntaxSupport/GrammarGenerator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ struct GrammarGenerator {
3737
let optionality = child.isOptional ? "?" : ""
3838
switch child.kind {
3939
case .node(let kind):
40-
return "``\(kind.syntaxType)``\(optionality)"
40+
return "\(kind.doccLink)\(optionality)"
4141
case .nodeChoices(let choices):
4242
let choicesDescriptions = choices.map { grammar(for: $0) }
4343
return "(\(choicesDescriptions.joined(separator: " | ")))\(optionality)"
4444
case .collection(kind: let kind, _, _, _):
45-
return "``\(kind.syntaxType)``\(optionality)"
45+
return "\(kind.doccLink)\(optionality)"
4646
case .token(let choices, _, _):
4747
if choices.count == 1 {
4848
return "\(grammar(for: choices.first!))\(optionality)"

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ public enum Keyword: CaseIterable {
108108
case _Class
109109
case _compilerInitialized
110110
case _const
111+
case _consume
111112
case _consuming
113+
case _copy
112114
case _documentation
113115
case _dynamicReplacement
114116
case _effects
@@ -119,6 +121,7 @@ public enum Keyword: CaseIterable {
119121
case _local
120122
case _modify
121123
case _move
124+
case _mutate
122125
case _mutating
123126
case _NativeClass
124127
case _NativeRefCountedObject
@@ -328,6 +331,8 @@ public enum Keyword: CaseIterable {
328331
return KeywordSpec("_backDeploy")
329332
case ._borrow:
330333
return KeywordSpec("_borrow")
334+
case ._borrowing:
335+
return KeywordSpec("_borrowing", experimentalFeature: .referenceBindings, or: .borrowingSwitch)
331336
case ._BridgeObject:
332337
return KeywordSpec("_BridgeObject")
333338
case ._cdecl:
@@ -338,6 +343,12 @@ public enum Keyword: CaseIterable {
338343
return KeywordSpec("_compilerInitialized")
339344
case ._const:
340345
return KeywordSpec("_const")
346+
case ._consume:
347+
return KeywordSpec("_consume", experimentalFeature: .nonescapableTypes)
348+
case ._consuming:
349+
return KeywordSpec("_consuming", experimentalFeature: .referenceBindings)
350+
case ._copy:
351+
return KeywordSpec("_copy", experimentalFeature: .nonescapableTypes)
341352
case ._documentation:
342353
return KeywordSpec("_documentation")
343354
case ._dynamicReplacement:
@@ -358,6 +369,10 @@ public enum Keyword: CaseIterable {
358369
return KeywordSpec("_modify")
359370
case ._move:
360371
return KeywordSpec("_move")
372+
case ._mutate:
373+
return KeywordSpec("_mutate", experimentalFeature: .nonescapableTypes)
374+
case ._mutating:
375+
return KeywordSpec("_mutating", experimentalFeature: .referenceBindings)
361376
case ._NativeClass:
362377
return KeywordSpec("_NativeClass")
363378
case ._NativeRefCountedObject:
@@ -743,12 +758,6 @@ public enum Keyword: CaseIterable {
743758
return KeywordSpec("wrt")
744759
case .yield:
745760
return KeywordSpec("yield")
746-
case ._borrowing:
747-
return KeywordSpec("_borrowing", experimentalFeature: .referenceBindings, or: .borrowingSwitch)
748-
case ._consuming:
749-
return KeywordSpec("_consuming", experimentalFeature: .referenceBindings)
750-
case ._mutating:
751-
return KeywordSpec("_mutating", experimentalFeature: .referenceBindings)
752761
}
753762
}
754763
}

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ public class Node {
224224
// This will repeat the syntax type before and after the dot, which is
225225
// a little unfortunate, but it's the only way I found to get docc to
226226
// generate a fully-qualified type + member.
227-
return " - ``\($0.node.syntaxType)``.``\($0.node.syntaxType)/\(childName)``"
227+
return " - \($0.node.doccLink).``\($0.node.syntaxType)/\(childName)``"
228228
} else {
229-
return " - ``\($0.node.syntaxType)``"
229+
return " - \($0.node.doccLink)"
230230
}
231231
}
232232
.joined(separator: "\n")
@@ -249,7 +249,7 @@ public class Node {
249249
let list =
250250
SYNTAX_NODES
251251
.filter { $0.base == self.kind && !$0.isExperimental }
252-
.map { "- ``\($0.kind.syntaxType)``" }
252+
.map { "- \($0.kind.doccLink)" }
253253
.joined(separator: "\n")
254254

255255
guard !list.isEmpty else {
@@ -392,9 +392,9 @@ public struct CollectionNode {
392392
public var grammar: SwiftSyntax.Trivia {
393393
let grammar: String
394394
if let onlyElement = elementChoices.only {
395-
grammar = "``\(onlyElement.syntaxType)`` `*`"
395+
grammar = "\(onlyElement.doccLink) `*`"
396396
} else {
397-
grammar = "(\(elementChoices.map { "``\($0.syntaxType)``" }.joined(separator: " | "))) `*`"
397+
grammar = "(\(elementChoices.map { "\($0.doccLink)" }.joined(separator: " | "))) `*`"
398398
}
399399

400400
return .docCommentTrivia(
@@ -421,7 +421,3 @@ fileprivate extension Child {
421421
}
422422
}
423423
}
424-
425-
fileprivate extension Node {
426-
427-
}

CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public enum SyntaxNodeKind: String, CaseIterable {
9999
case dictionaryExpr
100100
case dictionaryType
101101
case differentiabilityArgument
102-
case differentiabilityArguments
103102
case differentiabilityArgumentList
103+
case differentiabilityArguments
104104
case differentiabilityWithRespectToArgument
105105
case differentiableAttributeArguments
106106
case discardAssignmentExpr
@@ -182,6 +182,9 @@ public enum SyntaxNodeKind: String, CaseIterable {
182182
case labeledSpecializeArgument
183183
case labeledStmt
184184
case layoutRequirement
185+
case lifetimeSpecifierArgument
186+
case lifetimeSpecifierArgumentList
187+
case lifetimeTypeSpecifier
185188
case macroDecl
186189
case macroExpansionDecl
187190
case macroExpansionExpr
@@ -244,14 +247,15 @@ public enum SyntaxNodeKind: String, CaseIterable {
244247
case returnStmt
245248
case sameTypeRequirement
246249
case sequenceExpr
250+
case simpleTypeSpecifier
251+
case simpleStringLiteralExpr
252+
case simpleStringLiteralSegmentList
247253
case someOrAnyType
248254
case sourceFile
249255
case specializeAttributeArgumentList
250256
case specializeAvailabilityArgument
251257
case specializeTargetFunctionArgument
252258
case stmt
253-
case simpleStringLiteralExpr
254-
case simpleStringLiteralSegmentList
255259
case stringLiteralExpr
256260
case stringLiteralSegmentList
257261
case stringSegment
@@ -285,6 +289,9 @@ public enum SyntaxNodeKind: String, CaseIterable {
285289
case typeEffectSpecifiers
286290
case typeExpr
287291
case typeInitializerClause
292+
case typeSpecifier
293+
case lifetimeSpecifierArguments
294+
case typeSpecifierList
288295
case unavailableFromAsyncAttributeArguments
289296
case underscorePrivateAttributeArguments
290297
case unexpectedNodes
@@ -299,10 +306,10 @@ public enum SyntaxNodeKind: String, CaseIterable {
299306
case whereClause
300307
case whileStmt
301308
case wildcardPattern
302-
case yieldStmt
303309
case yieldedExpression
304-
case yieldedExpressionsClause
305310
case yieldedExpressionList
311+
case yieldedExpressionsClause
312+
case yieldStmt
306313

307314
// Nodes that have special handling throughout the codebase
308315

@@ -348,6 +355,17 @@ public enum SyntaxNodeKind: String, CaseIterable {
348355
}
349356
}
350357

358+
/// If this node is non-experimental a docc link wrapped in two backticks.
359+
///
360+
/// For experimental nodes, the node's type name in code font.
361+
public var doccLink: String {
362+
if let node = SYNTAX_NODE_MAP[self], node.isExperimental {
363+
return "`\(syntaxType)`"
364+
} else {
365+
return "``\(syntaxType)``"
366+
}
367+
}
368+
351369
/// For base nodes, the name of the corresponding protocol to which all the
352370
/// concrete nodes that have this base kind, conform.
353371
public var protocolType: TypeSyntax {
@@ -405,8 +423,8 @@ public enum SyntaxNodeKind: String, CaseIterable {
405423
case .derivativeAttributeArguments: return "derivativeRegistrationAttributeArguments"
406424
case .designatedType: return "designatedTypeElement"
407425
case .differentiabilityArgument: return "differentiabilityParam"
408-
case .differentiabilityArguments: return "differentiabilityParams"
409426
case .differentiabilityArgumentList: return "differentiabilityParamList"
427+
case .differentiabilityArguments: return "differentiabilityParams"
410428
case .differentiabilityWithRespectToArgument: return "differentiabilityParamsClause"
411429
case .documentationAttributeArgumentList: return "documentationAttributeArguments"
412430
case .dynamicReplacementAttributeArguments: return "dynamicReplacementArguments"
@@ -440,6 +458,7 @@ public enum SyntaxNodeKind: String, CaseIterable {
440458
case .precedenceGroupName: return "precedenceGroupNameElement"
441459
case .repeatStmt: return "repeatWhileStmt"
442460
case .someOrAnyType: return "constrainedSugarType"
461+
case .simpleTypeSpecifier: return "typeSpecifier"
443462
case .specializeAttributeArgumentList: return "specializeAttributeSpecList"
444463
case .specializeAvailabilityArgument: return "availabilityEntry"
445464
case .specializeTargetFunctionArgument: return "targetFunctionEntry"
@@ -451,8 +470,8 @@ public enum SyntaxNodeKind: String, CaseIterable {
451470
case .typeAliasDecl: return "typealiasDecl"
452471
case .unavailableFromAsyncAttributeArguments: return "unavailableFromAsyncArguments"
453472
case .yieldedExpression: return "yieldExprListElement"
454-
case .yieldedExpressionsClause: return "yieldList"
455473
case .yieldedExpressionList: return "yieldExprList"
474+
case .yieldedExpressionsClause: return "yieldList"
456475
default: return nil
457476
}
458477
}

0 commit comments

Comments
 (0)