This maintains proposals for changes and user-visible enhancements to the Swift Programming Language.
abertelrud/swift-corelibs-foundation 0
The Foundation Project, providing core utilities, internationalization, and OS independence
abertelrud/swift-integration-tests 0
Automated tests for validating the generated Swift snapshots behave correctly
A low-level build system, used by Xcode 9 and the Swift Package Manager
abertelrud/swift-package-manager 0
The Package Manager for the Swift Programming Language
abertelrud/swift-tools-support-core 0
Contains common infrastructural code for both SwiftPM and llbuild.
Pull request review commentapple/swift-evolution
func test(_ collection: RandomAccessCollection) { ``` ___ -This way, a protocol or protocol extension member (method/property/subscript/initializer) may be used on an existential value iff the following criteria hold:+This way, a protocol or protocol extension member (method/property/subscript/initializer) may be used on an existential value if and only if the following criteria hold: * The type of the invoked member (accessor — for storage declarations), as viewed in context of the *base type*, must **not** contain references to `Self` or `Self`-rooted associated types in [non-covariant](https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)) position.
While examining this section, I found the sentence structure here a bit hard to parse. I suggest we reverse the wording for easier understanding, which then also mirrors the outlined limitations above
This way, a protocol or protocol extension member (method/property/subscript/initializer) may be used on an existential value *unless*:
* The type of the invoked member (accessor — for storage declarations), as viewed in context of the *base type*, contains references to `Self` or `Self`-rooted associated types in [non-covariant](https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)) position.
Feel free to discard this suggestion if you think it's not necessary.
comment created time in an hour
Pull request review commentapple/swift-evolution
func test(_ collection: RandomAccessCollection) { ``` ___ -This way, a protocol or protocol extension member (method/property/subscript/initializer) may be used on an existential value iff the following criteria hold:+This way, a protocol or protocol extension member (method/property/subscript/initializer) may be used on an existential value if the following criteria hold:
Updated to use the spelled out version. From the context it seems intentional and not a typo.
comment created time in an hour
Pull request review commentapple/swift-syntax
+%{+ from gyb_syntax_support import *+ from gyb_syntax_support.kinds import lowercase_first_word+ from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS+ # -*- mode: Swift -*-+ # Ignore the following admonition it applies to the resulting .swift file only++ def syntax_buildable_child_type(syntax_kind, is_token=False, is_optional=False):+ if syntax_kind in SYNTAX_BASE_KINDS:+ buildable_type = syntax_kind + 'Buildable'+ elif not is_token:+ buildable_type = syntax_kind+ elif 'List' in syntax_kind:+ buildable_type = syntax_kind + 'Syntax'+ else:+ buildable_type = 'TokenSyntax'++ if is_optional:+ buildable_type += '?'++ return buildable_type+}%+//// Automatically Generated From DeclBuildables.swift.gyb.+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift.org open source project+//+// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors+//+//===----------------------------------------------------------------------===//++import SwiftSyntax++// MARK: Protocols++% for kind in SYNTAX_BASE_KINDS:+% if kind != 'SyntaxCollection':+% build_kind = 'Syntax' if kind == 'Syntax' else kind + 'Syntax'+% if kind == 'Syntax':+public protocol ${kind}ListBuildable {+% else:+public protocol ${kind}ListBuildable: SyntaxListBuildable {+% end+ func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}]
Would some documentation like this help?
/// Builds list of `${kind}`s
/// - Parameter format: The `Format` to use.
/// - Parameter leadingTrivia: Replaces the the last leading trivia if not nil.
comment created time in an hour
pull request commentapple/swift
[cmake] [unittests] include googletest headers to Xcode project header search paths
Hum, interesting ... this could potentially fix the problem people were having https://forums.swift.org/t/gtest-gtest-h-not-found-in-typeref-cpp-while-compiling-the-compiler/44399 ?
comment created time in an hour
push eventapple/swift
commit sha ddeb1929c47b4ac5f88473ce36471941ffbbb4b2
[DiagnosticQol][SR-14505] Use DeclDescriptive kind in missing return data flow diagnostics (#36952) * [Diagnostics] Use DeclDescriptiveKind on data flow diagnostics to improve diagnostic message * [tests] Add regression tests to SILOptimizer/return.swift * [tests] Adapt other tests to changes of SR-14505 * [Diagnostics] Adapt message for missing return diagnostics, remove article * [Diagnostics] Adapt message for missing return diagnostics to have a note with fix * [tests] Adjust tests in validation suit
commit sha 752948a9fe6b291aa86f2e9010c14997a7c6ed9d
Merge remote-tracking branch 'origin/main' into next
push time in an hour
push eventapple/swift-syntax
commit sha 87b17c3512b18dcbed6a49749dec669aebf22ebd
Fix typo
commit sha 2ce4a331f948aaff6febdc9c9f0a082b85dbebb8
Merge pull request #275 from kimdv/kimdv/fix-typo Fix typo
push time in an hour
push eventapple/swift
commit sha ddeb1929c47b4ac5f88473ce36471941ffbbb4b2
[DiagnosticQol][SR-14505] Use DeclDescriptive kind in missing return data flow diagnostics (#36952) * [Diagnostics] Use DeclDescriptiveKind on data flow diagnostics to improve diagnostic message * [tests] Add regression tests to SILOptimizer/return.swift * [tests] Adapt other tests to changes of SR-14505 * [Diagnostics] Adapt message for missing return diagnostics, remove article * [Diagnostics] Adapt message for missing return diagnostics to have a note with fix * [tests] Adjust tests in validation suit
push time in an hour
PR merged apple/swift
<!-- What's in this pull request? --> Separate closure and declaration on diagnoseMissingReturn data flow diagnostics and use better descriptive naming.
<!-- If this pull request resolves any bugs in the Swift bug tracker, provide a link: --> Resolves SR-14505.
<!-- Before merging this pull request, you must run the Swift continuous integration tests. For information about triggering CI builds via @swift-ci, see: https://github.com/apple/swift/blob/master/docs/ContinuousIntegration.md#swift-ci
Thank you for your contribution to Swift! -->
pr closed time in an hour
pull request commentapple/swift
[cmake] [unittests] include googletest headers to Xcode project header search paths
@varungandhi-apple check please, and thank you.
comment created time in an hour
PR opened apple/swift
add target include directories on AddSwiftUnittests.cmake module. currently generated Xcode project doesn't include googletest headers after https://reviews.llvm.org/D86616
pr created time in an hour
Pull request review commentapple/swift
[DNM] Lift the 'Self or associated type' restriction
bool ASTContext::isASCIIString(StringRef s) const { } return true; }++/// Classify usages of Self in the given type.+///+/// \param position The position we are currently at, in terms of variance.+static SelfReferenceInfo+findExistentialSelfReferences(GenericSignature existentialSig, Type type,+ SelfReferencePosition position) {+ // If there are no type parameters, we're done.+ if (!type->hasTypeParameter())+ return SelfReferenceInfo();++ // Tuples preserve variance.+ if (auto tuple = type->getAs<TupleType>()) {+ auto info = SelfReferenceInfo();+ for (auto &elt : tuple->getElements()) {+ info |= findExistentialSelfReferences(existentialSig, elt.getType(),+ position);+ }++ // A covariant Self result inside a tuple will not be bona fide.+ info.hasCovariantSelfResult = false;++ return info;+ }++ // Function preserve variance in the result type, and flip variance in+ // the parameter type.+ if (auto funcTy = type->getAs<AnyFunctionType>()) {+ auto inputInfo = SelfReferenceInfo();+ for (auto param : funcTy->getParams()) {+ // inout parameters are invariant.+ if (param.isInOut()) {+ inputInfo |=+ findExistentialSelfReferences(existentialSig, param.getPlainType(),+ SelfReferencePosition::Invariant);+ continue;+ }+ inputInfo |= findExistentialSelfReferences(+ existentialSig, param.getParameterType(), position.flipped());+ }++ // A covariant Self result inside a parameter will not be bona fide.+ inputInfo.hasCovariantSelfResult = false;++ auto resultInfo = findExistentialSelfReferences(+ existentialSig, funcTy->getResult(), position);+ if (resultInfo.selfRef == SelfReferencePosition::Covariant) {+ resultInfo.hasCovariantSelfResult = true;+ }+ return inputInfo |= resultInfo;+ }++ // Metatypes preserve variance.+ if (auto metaTy = type->getAs<MetatypeType>()) {+ return findExistentialSelfReferences(existentialSig,+ metaTy->getInstanceType(), position);+ }++ // Optionals preserve variance.+ if (auto optType = type->getOptionalObjectType()) {+ return findExistentialSelfReferences(existentialSig, optType, position);+ }++ // DynamicSelfType preserves variance.+ // FIXME: This shouldn't ever appear in protocol requirement+ // signatures.+ if (auto selfType = type->getAs<DynamicSelfType>()) {+ return findExistentialSelfReferences(existentialSig,+ selfType->getSelfType(), position);+ }++ // Bound generic types are invariant.+ if (auto boundGenericType = type->getAs<BoundGenericType>()) {
Special-case covariance is already implemented on the main
branch. This branch needs a rebase.
comment created time in 2 hours
pull request commentapple/swift
[SourceKit] Add locations for symbols in external modules
Artem ended up making it compile-able in older compilers, so should hopefully work this time 🤞
@swift-ci please build toolchain macOS platform
comment created time in 2 hours
Pull request review commentapple/swift-evolution
func test(_ collection: RandomAccessCollection) { ``` ___ -This way, a protocol or protocol extension member (method/property/subscript/initializer) may be used on an existential value iff the following criteria hold:+This way, a protocol or protocol extension member (method/property/subscript/initializer) may be used on an existential value if the following criteria hold:
"iff" was removed from public API documentation: apple/swift#27115
comment created time in 2 hours
Pull request review commentapple/swift-evolution
func test(_ collection: RandomAccessCollection) { ``` ___ -This way, a protocol or protocol extension member (method/property/subscript/initializer) may be used on an existential value iff the following criteria hold:+This way, a protocol or protocol extension member (method/property/subscript/initializer) may be used on an existential value if the following criteria hold:
TIL - I've never seen it shortened like that before (having studied math in another language). Would you agree that it'd be clearer, if it's spelled out fully?
comment created time in 3 hours
Pull request review commentapple/swift-syntax
+%{+ from gyb_syntax_support import *+ from gyb_syntax_support.kinds import lowercase_first_word+ from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS+ # -*- mode: Swift -*-+ # Ignore the following admonition it applies to the resulting .swift file only++ def syntax_buildable_child_type(type_name, syntax_kind, is_token, is_optional=False):+ if syntax_kind in SYNTAX_BASE_KINDS:+ buildable_type = syntax_kind + 'Buildable'+ elif not is_token:+ buildable_type = syntax_kind+ else:+ buildable_type = type_name++ if is_optional:+ buildable_type += '?'++ return buildable_type+}%+//// Automatically Generated From DeclBuildables.swift.gyb.+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift.org open source project+//+// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors+//+//===----------------------------------------------------------------------===//++import SwiftSyntax++// MARK: Protocols++% for kind in SYNTAX_BASE_KINDS:+% if kind != 'SyntaxCollection':+% build_kind = 'Syntax' if kind == 'Syntax' else kind + 'Syntax'+% if kind == 'Syntax':+public protocol ${kind}ListBuildable {+% else:+public protocol ${kind}ListBuildable: SyntaxListBuildable {+% end+ func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}]+}++% if kind == 'Syntax':+public protocol ${kind}Buildable: ${kind}ListBuildable {+% else:+public protocol ${kind}Buildable: SyntaxBuildable, ${kind}ListBuildable {+% end+ func build${kind}(format: Format, leadingTrivia: Trivia?) -> ${build_kind}+}++extension ${kind}Buildable {+% if kind != 'Syntax':+ func build${kind}(format: Format) -> ${build_kind} {+ build${kind}(format: format, leadingTrivia: nil)+ }+% end+ public func buildSyntax(format: Format) -> Syntax {+ buildSyntax(format: format, leadingTrivia: nil)+ }++ public func buildSyntax(format: Format, leadingTrivia: Trivia?) -> Syntax {+ Syntax(build${kind}(format: format, leadingTrivia: leadingTrivia))+ }++ public func build${kind}List(format: Format) -> [${build_kind}] {+ build${kind}List(format: format, leadingTrivia: nil)+ }++ public func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}] {+ [build${kind}(format: format, leadingTrivia: leadingTrivia)]+ }+}++% end+% end++// MARK: - Buildables++% for node in SYNTAX_NODES:+% if node.is_buildable():+public struct ${node.syntax_kind}: ${node.base_kind}Buildable {
Will do it another.
comment created time in 3 hours
pull request commentapple/swift-syntax
Let’s see what CI has to say about this.
https://github.com/apple/swift/pull/36726
@swift-ci Please test
comment created time in 3 hours
Pull request review commentapple/swift-syntax
+import XCTest+import SwiftSyntax+import SwiftSyntaxBuilder++final class EnumCaseElementTests: XCTestCase {+ func test_enumCaseElementInit() {+ let leadingTrivia = Trivia.garbageText("␣")+ let string = SyntaxFactory.makeStringSegment("Hello World")+ let segment = StringSegment(content: string)+ let segments = StringLiteralSegments([segment])++ let stringLiteralExpr: ExprBuildable = StringLiteralExpr(openDelimiter: nil,+ openQuote: SyntaxFactory.makeStringQuoteToken(),
Let’s put it in a follow-up PR before any more discussions about it come up, complicating this PR even further.
comment created time in 3 hours
Pull request review commentapple/swift-syntax
+import XCTest+import SwiftSyntax+import SwiftSyntaxBuilder++final class EnumCaseElementTests: XCTestCase {+ func test_enumCaseElementInit() {+ let leadingTrivia = Trivia.garbageText("␣")+ let string = SyntaxFactory.makeStringSegment("Hello World")+ let segment = StringSegment(content: string)+ let segments = StringLiteralSegments([segment])++ let stringLiteralExpr: ExprBuildable = StringLiteralExpr(openDelimiter: nil,+ openQuote: SyntaxFactory.makeStringQuoteToken(),
Should it be in this PR or another? What do you prefer?
comment created time in 3 hours
Pull request review commentapple/swift-syntax
+%{+ from gyb_syntax_support import *+ from gyb_syntax_support.kinds import lowercase_first_word+ from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS+ # -*- mode: Swift -*-+ # Ignore the following admonition it applies to the resulting .swift file only++ def syntax_buildable_child_type(type_name, syntax_kind, is_token, is_optional=False):+ if syntax_kind in SYNTAX_BASE_KINDS:+ buildable_type = syntax_kind + 'Buildable'+ elif not is_token:+ buildable_type = syntax_kind+ else:+ buildable_type = type_name++ if is_optional:+ buildable_type += '?'++ return buildable_type+}%+//// Automatically Generated From DeclBuildables.swift.gyb.+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift.org open source project+//+// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors+//+//===----------------------------------------------------------------------===//++import SwiftSyntax++// MARK: Protocols++% for kind in SYNTAX_BASE_KINDS:+% if kind != 'SyntaxCollection':+% build_kind = 'Syntax' if kind == 'Syntax' else kind + 'Syntax'+% if kind == 'Syntax':+public protocol ${kind}ListBuildable {+% else:+public protocol ${kind}ListBuildable: SyntaxListBuildable {+% end+ func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}]+}++% if kind == 'Syntax':+public protocol ${kind}Buildable: ${kind}ListBuildable {+% else:+public protocol ${kind}Buildable: SyntaxBuildable, ${kind}ListBuildable {+% end+ func build${kind}(format: Format, leadingTrivia: Trivia?) -> ${build_kind}+}++extension ${kind}Buildable {+% if kind != 'Syntax':+ func build${kind}(format: Format) -> ${build_kind} {+ build${kind}(format: format, leadingTrivia: nil)+ }+% end+ public func buildSyntax(format: Format) -> Syntax {+ buildSyntax(format: format, leadingTrivia: nil)+ }++ public func buildSyntax(format: Format, leadingTrivia: Trivia?) -> Syntax {+ Syntax(build${kind}(format: format, leadingTrivia: leadingTrivia))+ }++ public func build${kind}List(format: Format) -> [${build_kind}] {+ build${kind}List(format: format, leadingTrivia: nil)+ }++ public func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}] {+ [build${kind}(format: format, leadingTrivia: leadingTrivia)]+ }+}++% end+% end++// MARK: - Buildables++% for node in SYNTAX_NODES:+% if node.is_buildable():+public struct ${node.syntax_kind}: ${node.base_kind}Buildable {
Yeah, would be good to use the documentation we already have. It doesn’t have to be in this PR though if you’d rather want to get this merged as soon as possible and tackle it in a follow-up PR. However you like it.
comment created time in 3 hours
Pull request review commentapple/swift-syntax
+import XCTest+import SwiftSyntax+import SwiftSyntaxBuilder++final class EnumCaseElementTests: XCTestCase {+ func test_enumCaseElementInit() {+ let leadingTrivia = Trivia.garbageText("␣")+ let string = SyntaxFactory.makeStringSegment("Hello World")+ let segment = StringSegment(content: string)+ let segments = StringLiteralSegments([segment])++ let stringLiteralExpr: ExprBuildable = StringLiteralExpr(openDelimiter: nil,+ openQuote: SyntaxFactory.makeStringQuoteToken(),
I didn’t realize that. I think they should definitely be public, otherwise I can’t think of what they are good for.
comment created time in 3 hours
Pull request review commentapple/swift-syntax
+%{+ from gyb_syntax_support import *+ from gyb_syntax_support.kinds import lowercase_first_word+ from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS+ # -*- mode: Swift -*-+ # Ignore the following admonition it applies to the resulting .swift file only++ def syntax_buildable_child_type(syntax_kind, is_token=False, is_optional=False):+ if syntax_kind in SYNTAX_BASE_KINDS:+ buildable_type = syntax_kind + 'Buildable'+ elif not is_token:+ buildable_type = syntax_kind+ elif 'List' in syntax_kind:+ buildable_type = syntax_kind + 'Syntax'+ else:+ buildable_type = 'TokenSyntax'++ if is_optional:+ buildable_type += '?'++ return buildable_type+}%+//// Automatically Generated From DeclBuildables.swift.gyb.+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift.org open source project+//+// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors+//+//===----------------------------------------------------------------------===//++import SwiftSyntax++// MARK: Protocols++% for kind in SYNTAX_BASE_KINDS:+% if kind != 'SyntaxCollection':+% build_kind = 'Syntax' if kind == 'Syntax' else kind + 'Syntax'+% if kind == 'Syntax':+public protocol ${kind}ListBuildable {+% else:+public protocol ${kind}ListBuildable: SyntaxListBuildable {+% end+ func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}]+}++% if kind == 'Syntax':+public protocol ${kind}Buildable: ${kind}ListBuildable {+% else:+public protocol ${kind}Buildable: SyntaxBuildable, ${kind}ListBuildable {+% end+ func build${kind}(format: Format, leadingTrivia: Trivia?) -> ${build_kind}+}++extension ${kind}Buildable {+ public func buildSyntax(format: Format, leadingTrivia: Trivia?) -> Syntax {+ Syntax(build${kind}(format: format, leadingTrivia: leadingTrivia))+ }++ public func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}] {+ [build${kind}(format: format, leadingTrivia: leadingTrivia)]+ }+}++% end+% end++// MARK: - Buildables++% for node in SYNTAX_NODES:+% if node.is_buildable():+% return_type = 'Syntax'+% if node.base_kind != 'Syntax':+% return_type = node.base_kind + 'Syntax'+% end+public struct ${node.syntax_kind}: ${node.base_kind}Buildable {+% child_params = []+% for child in node.children:+% param_type = syntax_buildable_child_type(child.syntax_kind, child.is_token(), child.is_optional)+% child_params.append("%s: %s" % (child.swift_name, param_type))+% end+% for child_param in child_params:+ let ${child_param}+% end++ public init(+ ${',\n '.join(child_params)}+ ) {+% for child in node.children:+ self.${child.swift_name} = ${child.swift_name}+% end+ }+ + func build${node.syntax_kind}(format: Format, leadingTrivia: Trivia?) -> ${node.syntax_kind}Syntax {+% child_params = []+% for child in node.children:+% param_name = child.swift_name+% if child.is_token() and child.requires_leading_newline:+% param_name = param_name + '.withLeadingTrivia(.newlines(1) + format._makeIndent())'+% elif child.syntax_kind in SYNTAX_BASE_KINDS or not child.is_token():+% if child.is_optional:+% param_name = param_name + "?"+% end+% format = 'format'+% if child.is_indented:+% format += '._indented()'+% end +% param_name = param_name + ".build" + child.syntax_kind + "(format: " + format + ", leadingTrivia: nil)"+% end+% child_params.append("%s: %s" % (child.swift_name, param_name))+% end+ let ${node.swift_syntax_kind} = SyntaxFactory.make${node.syntax_kind}(+ ${',\n '.join(child_params)}+ )+ + if let leadingTrivia = leadingTrivia {+ return ${node.swift_syntax_kind}+ .withLeadingTrivia(leadingTrivia)+ }++ return ${node.swift_syntax_kind}+ }++ public func build${node.base_kind}(format: Format, leadingTrivia: Trivia?) -> ${return_type} {
👍
I think it’s OK. I wouldn't object to more (I think almost nobody every objects to more good comments) but there’s nothing pressing I can think of.
comment created time in 3 hours
Pull request review commentapple/swift-syntax
+%{+ from gyb_syntax_support import *+ from gyb_syntax_support.kinds import lowercase_first_word+ from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS+ # -*- mode: Swift -*-+ # Ignore the following admonition it applies to the resulting .swift file only++ def syntax_buildable_child_type(syntax_kind, is_token=False, is_optional=False):+ if syntax_kind in SYNTAX_BASE_KINDS:+ buildable_type = syntax_kind + 'Buildable'+ elif not is_token:+ buildable_type = syntax_kind+ elif 'List' in syntax_kind:+ buildable_type = syntax_kind + 'Syntax'+ else:+ buildable_type = 'TokenSyntax'++ if is_optional:+ buildable_type += '?'++ return buildable_type+}%+//// Automatically Generated From DeclBuildables.swift.gyb.+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift.org open source project+//+// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors+//+//===----------------------------------------------------------------------===//++import SwiftSyntax++// MARK: Protocols++% for kind in SYNTAX_BASE_KINDS:+% if kind != 'SyntaxCollection':+% build_kind = 'Syntax' if kind == 'Syntax' else kind + 'Syntax'+% if kind == 'Syntax':+public protocol ${kind}ListBuildable {+% else:+public protocol ${kind}ListBuildable: SyntaxListBuildable {+% end+ func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}]+}++% if kind == 'Syntax':+public protocol ${kind}Buildable: ${kind}ListBuildable {+% else:+public protocol ${kind}Buildable: SyntaxBuildable, ${kind}ListBuildable {+% end+ func build${kind}(format: Format, leadingTrivia: Trivia?) -> ${build_kind}+}++extension ${kind}Buildable {+ public func buildSyntax(format: Format, leadingTrivia: Trivia?) -> Syntax {+ Syntax(build${kind}(format: format, leadingTrivia: leadingTrivia))+ }++ public func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}] {+ [build${kind}(format: format, leadingTrivia: leadingTrivia)]+ }+}++% end+% end++// MARK: - Buildables++% for node in SYNTAX_NODES:+% if node.is_buildable():+% return_type = 'Syntax'+% if node.base_kind != 'Syntax':+% return_type = node.base_kind + 'Syntax'+% end
Yeah, looks good now that the variable definition is close to its use.
comment created time in 3 hours
Pull request review commentapple/swift-syntax
+%{+ from gyb_syntax_support import *+ from gyb_syntax_support.kinds import lowercase_first_word+ from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS+ # -*- mode: Swift -*-+ # Ignore the following admonition it applies to the resulting .swift file only++ def syntax_buildable_child_type(syntax_kind, is_token=False, is_optional=False):+ if syntax_kind in SYNTAX_BASE_KINDS:+ buildable_type = syntax_kind + 'Buildable'+ elif not is_token:+ buildable_type = syntax_kind+ elif 'List' in syntax_kind:+ buildable_type = syntax_kind + 'Syntax'+ else:+ buildable_type = 'TokenSyntax'++ if is_optional:+ buildable_type += '?'++ return buildable_type+}%+//// Automatically Generated From DeclBuildables.swift.gyb.+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift.org open source project+//+// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors+//+//===----------------------------------------------------------------------===//++import SwiftSyntax++// MARK: Protocols++% for kind in SYNTAX_BASE_KINDS:+% if kind != 'SyntaxCollection':+% build_kind = 'Syntax' if kind == 'Syntax' else kind + 'Syntax'+% if kind == 'Syntax':+public protocol ${kind}ListBuildable {+% else:+public protocol ${kind}ListBuildable: SyntaxListBuildable {+% end+ func build${kind}List(format: Format, leadingTrivia: Trivia?) -> [${build_kind}]
Ah, I see. Makes total sense. Could you add a comment describing the behaviour?
comment created time in 3 hours
push eventapple/swift-evolution
commit sha 80602141f65b3fc8a98283e1e8dc4fe1b51312bd
0311 minor fixes (#1335) Plain text print to actual call
push time in 3 hours
PR merged apple/swift-evolution
Plain text print to actual call
pr closed time in 3 hours
pull request commentapple/swift-evolution
Sure, might as well -- thank you.
comment created time in 3 hours