Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum ExperimentalFeature: String, CaseIterable {
case oldOwnershipOperatorSpellings
case defaultIsolationPerFile
case moduleSelector
case defaultGenerics

/// The name of the feature as it is written in the compiler's `Features.def` file.
public var featureName: String {
Expand All @@ -47,6 +48,8 @@ public enum ExperimentalFeature: String, CaseIterable {
return "DefaultIsolationPerFile"
case .moduleSelector:
return "ModuleSelector"
case .defaultGenerics:
return "DefaultGenerics"
}
}

Expand All @@ -73,6 +76,8 @@ public enum ExperimentalFeature: String, CaseIterable {
return "set default actor isolation for a file"
case .moduleSelector:
return "Module selector syntax (`ModName::identifier`)"
case .defaultGenerics:
return "default generics"
}
}

Expand Down
7 changes: 7 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public let GENERIC_NODES: [Node] = [
nameForDiagnostics: "inherited type",
isOptional: true
),
Child(
name: "initializer",
kind: .node(kind: .typeInitializerClause),
experimentalFeature: .defaultGenerics,
nameForDiagnostics: "default type",
isOptional: true,
),
Child(
name: "trailingComma",
kind: .token(choices: [.token(.comma)]),
Expand Down
24 changes: 24 additions & 0 deletions Release Notes/603.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Swift Syntax 603 Release Notes

## New APIs

- `GenericParameterSyntax` now has a new `initializer` property.
- Description: Generic parameters can now optionally be passed a default type. The `initializer` is a `TypeInitializerSyntax` that captures both the `=` and the parsed `TypeSyntax`.
- Pull Request: https://github.com/swiftlang/swift-syntax/pull/3152

## API Behavior Changes

## Deprecations

## API-Incompatible Changes

## Template

- *Affected API or two word description*
- Description: *A 1-2 sentence description of the new/modified API*
- Issue: *If an issue exists for this change, a link to the issue*
- Pull Request: *Link to the pull request(s) that introduces this change*
- Migration steps: Steps that adopters of swift-syntax should take to move to the new API (required for deprecations and API-incompatible changes).
- Notes: *In case of deprecations or API-incompatible changes, the reason why this change was made and the suggested alternative*

*Insert entries in chronological order, with newer entries at the bottom*
19 changes: 19 additions & 0 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,24 @@ extension Parser {
unexpectedBeforeInherited = nil
inherited = nil
}

// Parse the default type, if any. We only have defaults of regular
// type parameters, not parameter packs or value generics yet.
let defaultType: RawTypeInitializerClauseSyntax?
if self.experimentalFeatures.contains(.defaultGenerics),
specifier == nil,
let equal = self.consume(if: .equal)
{
let type = self.parseType()
defaultType = RawTypeInitializerClauseSyntax(
equal: equal,
value: type,
arena: self.arena
)
} else {
defaultType = nil
}

keepGoing = self.consume(if: .comma)
elements.append(
RawGenericParameterSyntax(
Expand All @@ -686,6 +704,7 @@ extension Parser {
colon: colon,
unexpectedBeforeInherited,
inheritedType: inherited,
initializer: defaultType,
trailingComma: keepGoing,
arena: self.arena
)
Expand Down
5 changes: 5 additions & 0 deletions Sources/SwiftParser/generated/ExperimentalFeatures.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions Sources/SwiftSyntax/generated/raw/RawSyntaxNodesGHI.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading