600.0.1
Compared to 600.0.0 this release fixes a compilation issue when building swift-syntax in C++ interop mode (#2861).
It also contains the following changes from 600.0.0.
New APIs
-
FixIt now has a new computed property named
edits- Description: the
editsrepresent the non-overlapping textualeditsthat need to be performed when the Fix-It is applied. - Issue: swiftlang/sourcekit-lsp#909
- Pull Request: #2314
- Description: the
-
SourceEdit- Description:
SourceEdithas been moved from SwiftRefactor to SwiftSyntax - Issue: swiftlang/sourcekit-lsp#909
- Pull Request: #2314
- Description:
-
assertMacroExpansionnow have new parameters namedapplyFixItsandfixedSource -
DeclSyntaxEnum,StmtSyntaxEnum,ExprSyntaxEnum,TypeSyntaxEnum, andPatternSyntaxEnum- Description: Enum to exhaustively switch over all different syntax nodes of each base type.
- Pull Request: #2351
-
WithOptionalCodeBlock- Description: A trait for syntax nodes that have an optional code block, such as
FunctionDeclSyntaxandInitializerDeclSyntax. - Pull Request: #2359
- Description: A trait for syntax nodes that have an optional code block, such as
-
CodeBlockSyntax- Description:
CodeBlockSyntaxis nowSyntaxParseable, so it can be used with string interpolations. - Pull Request: #2361
- Description:
-
ThrowsClause- Description: The
throwsSpecifierfor the effects nodes (AccessorEffectSpecifiers,FunctionEffectSpecifiers,TypeEffectSpecifiers,EffectSpecifiers) has been replaced withthrowsClause, which captures both the throws specifier and the (optional) thrown error type, as introduced by SE-0413. - Pull Request: #2379
- Description: The
-
String.isValidSwiftIdentifier(for:)- Description:
SwiftParseradds an extension onStringto check if it can be used as an identifier in a given context. - Pull Request: #2434
- Description:
-
MacroDeclSyntax.expand- the
expand(argumentList:definition:replacements:)method gains a new parameter 'genericReplacements:' that is defaulted to an empty array. - The method's signature is now
expand(argumentList:definition:replacements:genericReplacements:) - Pull Request: #2450
- the
-
SyntaxProtocol.asMacroLexicalContext()andallMacroLexicalContexts(enclosingSyntax:)- Description: Produce the lexical context for a given syntax node (if it has one), or the entire stack of lexical contexts enclosing a syntax node, for use in macro expansion.
- Pull request: #1554
-
TriviaPiece.isComment- Description:
TriviaPiecenow has a computed propertyisCommentthat returnstrueif the trivia piece is a comment. - Pull Request: #2469
- Description:
-
New
assertMacroExpansionAPI with option to specify macro specifications withmacroSpecsargument -
BasicFormat.inferIndentation(of:)- Description: Uses heuristics to infer the indentation width used in a syntax tree.
- Pull Request: #2514
-
IncrementalEditstores replacement text- Description:
IncrementalEditused to store the range that was replaced and the length of the replacement but not the replacement bytes by itself.IncrementalEditnow has areplacementproperty that contains the replacement bytes. - Pull Request: #2527
- Description:
-
Type specifiers
- Description:
AttributedTypeSyntaxcan now contain multiple specifiers and these types are used to model the list of specifiers. Additionally, type specifiers can now contain arguments, likeborrow(data). To facilitate this, the following new types were introduces:LifetimeSpecifierArgumentListSyntax,LifetimeSpecifierArgumentSyntax,LifetimeSpecifierArgumentsSyntax,LifetimeTypeSpecifierSyntax,SimpleTypeSpecifierSyntax,TypeSpecifierListSyntax - Pull request: #2433
- Description:
-
DeclGroupSyntax.introducer- Description: The
DeclGroupSyntaxtrait has an extraintroducerproperty, ie. the keyword that introduces the declaration. - Issue: https://github.com/swiftlang/sourcekit-lsp/issues/2535
- Pull Request: #2539
- Description: The
-
ExprSyntax.interpretedAsVersionTuple- Description: With the change to parse
#if canImport(MyModule, _version: 1.2.3)as a function call instead of a dedicated syntax node,1.2.3natively gets parsed as a member access3to the1.2float literal. This property allows the reinterpretation of such an expression as a version tuple. - Pull request: #2025
- Description: With the change to parse
-
SyntaxProtocol.node(at:)- Description: Given a
SyntaxIdentifier, returns theSyntaxnode with that identifier - Pull request: #2594
- Description: Given a
-
SyntaxIdentifier.IndexInTree- Description: Uniquely identifies a syntax node within a tree. This is similar to
SyntaxIdentifierbut does not store the root ID of the tree. It can thus be transferred across trees that are structurally equivalent, for example two copies of the same tree that live in different processes. The only public functions on this type aretoOpaqueandinit(fromOpaque:), which allow serialization of theIndexInTree. - Pull request: #2594
- Description: Uniquely identifies a syntax node within a tree. This is similar to
-
SyntaxIdentifierconformance toComparable:- Description: A
SyntaxIdentifiercompares less than anotherSyntaxIdentifierif the node at that identifier occurs first during a depth-first traversal of the tree. - Pull request: #2594
- Description: A
-
SyntaxIdentifier.indexInTreeandSyntaxIdentifier.fromIndexInTree- Description:
SyntaxIdentifier.indexInTreeallows the retrieval of aSyntaxIdentifierthat identifies the syntax node independent of the syntax tree.SyntaxIdentifier.fromIndexInTreeallows the creation for aSyntaxIdentifierfrom a tree-agnosticSyntaxIdentifier.IndexInTreeand the tree's root node. - Pull request: #2594
- Description:
-
SwiftSyntaxMacrosGenericTestSupport- Description: A version of the
SwiftSyntaxMacrosTestSupportmodule that doesn't depend onFoundationorXCTestand can thus be used to write macro tests usingswift-testing. Since swift-syntax can't depend on swift-testing (which would incur a circular dependency since swift-testing depends on swift-syntax), users need to manually specify a failure handler like the following, that fails the swift-testing test:Issue.record("\($0.message)", fileID: $0.location.fileID, filePath: $0.location.filePath, line: $0.location.line, column: $0.location.column) - Pull request: #2647
- Description: A version of the
-
TokenSyntax.identifier- Description: Adds an
identifierproperty toTokenSyntaxwhich returns a canonicalized representation of an identifier that strips away backticks. - Pull request: #2576
- Description: Adds an
Deprecations
-
Child Choice Node Casts
- Description:
is,as, andcastmethods for types not contained in the choice node are marked as deprecated. The deprecated methods will emit a warning, indicating that the cast will always fail. - Issue: #2092
- Pull Request: #2184
- Migration steps: Remove the
is,asorcastmethods because they will always fail.
- Description:
-
IncrementalParseTransition:- Description: The initializer
IncrementalParseTransition.init(previousTree:edits:lookaheadRanges:reusedNodeCallback:)is marked as deprecated. UseIncrementalParseTransition.init(previousIncrementalParseResult:edits:reusedNodeCallback:)instead. - Issue: #2267
- Pull request: #2272
- Migration steps: Call
IncrementalParseTransition.init(previousIncrementalParseResult:edits:reusedNodeCallback:)instead.
- Description: The initializer
-
MacroExpansion{Error|Warning|FixIt}Messagemoved to theSwiftSyntaxMacrosmodule- Description: Move the
MacroExpansion{Error|Warning|FixIt}Messagetypes from theSwiftSyntaxMacroExpansionmodule toSwiftSyntaxMacros. Deprecated typealiases inSwiftSyntaxMacroExpansionforward toSwiftSyntaxMacros. - Pull request: #2338
- Notes: The expansion diagnostic messages were defined in
SwiftSyntaxMacroExpansion, which is intended as an implementation detail of the plugin server and should not need to be imported by macros.
- Description: Move the
-
EditorPlaceholderDeclSyntaxandEditorPlaceholderExprSyntax:- Description:
EditorPlaceholderDeclSyntaxandEditorPlaceholderExprSyntaxare now deprecated and placeholders are instead parsed as identifiers within aMissingDeclSyntaxorDeclReferenceExprSyntax. - Pull request: #2237
- Description:
-
AttributedTypeSyntax.specifierhas renamed tospecifiersand changed to be a collection- Description: Types can have multiple specifiers now and the syntax tree has been modified to reflect that.
- Pull request: #2433
-
CanImportExprSyntaxandCanImportVersionInfoSyntax- Description: Instead of parsing
canImportinside#ifdirectives as a special expression node, parse it as a functionc call expression. This is in-line with how theswift(>=6.0)andcompiler(>=6.0)directives are parsed. - Pull request: #2025
- Description: Instead of parsing
API-Incompatible Changes
-
MacroDefinitionused for expanding macros:- Description: The
MacroDefinition/expansionenum case used to have two values ((MacroExpansionExprSyntax, replacements: [Replacement])), has now gained another value in order to support generic argument replacements in macro expansions:(MacroExpansionExprSyntax, replacements: [Replacement], genericReplacements: [GenericArgumentReplacement]) - Pull request: #2450
- Migration steps: Code which exhaustively checked over the enum should be changed to
case .expansion(let node, let replacements, let genericReplacements):. Creating the.extensiongained a compatibility shim, retaining the previous syntax source compatible (return .expansion(node, replacements: [])).
- Description: The
-
Effect specifiers:
- Description: The
unexpectedAfterThrowsSpecifiernode of the various effect specifiers has been removed. - Pull request: #2219
- Migration steps: Check
unexpectedBetweenThrowsSpecifierAndThrownErrorandunexpectedAfterThrownErrorinstead.
- Description: The
-
SyntaxKindremoved conformance toCaseIterable- Description:
SyntaxKindno longer conforms toCaseIterablesince there is no good use case to iterate over all syntax kinds. - Pull request: #2292
- Migration steps: Exhaustively check all the syntax nodes that your program supports. There should be no use case to iterate over all cases in
SyntaxKind.
- Description:
-
IntegerLiteralExprSyntax.Radixremoved conformance toCaseIterable- Description:
IntegerLiteralExprSyntax.Radixno longer conforms toCaseIterablesince there is no good use case to iterate over all radix kinds. - Pull request: #2292
- Migration steps: There should be no use case to iterate over all cases in
IntegerLiteralExprSyntax.Radix.
- Description:
-
Parser.parseIncrementally(source:parseTransition:)andParser.parseIncrementally(source:maximumNestingLevel:parseTransition:):- Description: The default versions of
Parser.parseIncrementallyreturn aIncrementalParseResultinstead of a tuple. Access to the struct should be compatible with the tuple in almost all cases unless the tuple is stored into a variable and then destructed or passed to a function that expects a tuple. - Issue: #2267
- Pull request: #2272
- Migration steps: If necessary, change type annotations from the tuple to the
IncrementalParseResulttype.
- Description: The default versions of
-
SyntaxClassificationgained a new case:argumentLabel- The new classification case covers the first names of parameters in function-like declarations and the label of arguments in function-like calls.
- Pull request: #2375
- Migration steps: In exhaustive switches over
SyntaxClassification, cover the new case.
-
SyntaxEnumandSyntaxKindgained new cases:throwsClause- The new cases cover the newly introduced
ThrowsClauseSyntax - Pull request: #2379
- Migration steps: In exhaustive switches over
SyntaxEnumandSyntaxKind, cover the new case.
- The new cases cover the newly introduced
-
MacroExpansionContextnow requires a propertylexicalContext:- Description: The new property provides the lexical context in which the macro is expanded, and has several paired API changes. Types that conform to
MacroExpansionContextwill need to implement this property. Additionally, theHostToPluginMessagecasesexpandFreestandingMacroandexpandAttachedMacronow include an optionallexicalContext. Finally, theSyntaxProtocol.expand(macros:in:indentationWidth:)syntactic expansion operation has been deprecated in favor of a new versionexpand(macros:contextGenerator:indentationWidth:)that takes a function produces a new macro expansion context for each expansion. - Pull request: #1554
- Migration steps: Add the new property
lexicalContextto anyMacroExpansionContext-conforming types. If implementing the host-to-plugin message protocol, add support forlexicalContext. For macro expansion operations going throughSyntaxProtocol.expand, provide a context generator that creates a fresh context including the lexical context.
- Description: The new property provides the lexical context in which the macro is expanded, and has several paired API changes. Types that conform to
-
TriviaPiece.isBackslashinSwiftParserDiagnosticsremoved- Description:
TriviaPiece.isBackslashwas not intended to be public API. - Pull request: #2531
- Migration steps: Use
if case .backslash = triviaPieceinstead
- Description:
-
All symbols in
SwiftCompilerPluginMessageHandlingare now SPI- Description: This module is only intended to be used from some internal components. Any other modules should not use them directly.
- Pull request: #2489
- Migration steps: Stop using this module.