Skip to content

Commit d518259

Browse files
authored
Merge pull request swiftlang#242 from rintaro/revert-pr238
Revert "Add Double and Int Convenience Properties (swiftlang#239)"
2 parents fd78485 + bac8d8c commit d518259

20 files changed

+44
-316
lines changed

Changelog.md

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Note: This is in reverse chronological order, so newer entries are added to the
44

55
## Swift 5.3
66

7-
* Introduced `integerValue` and `floatingValue` properties to `IntegerLiteralExprSyntax` and `FloatLiteralExprSyntax`, respectively. Converted their `digits` and `floatingDigits` setters, respectively, into throwing functions.
8-
97
* Introduced `FunctionCallExprSyntax.additionalTrailingClosures` property with type `MultipleTrailingClosureElementListSyntax?` for supporting [SE-0279 Multiple Trailing Closures](https://github.com/apple/swift-evolution/blob/master/proposals/0279-multiple-trailing-closures.md).
108

119
* Introduced `syntaxNodeType` property for all types conforming to `SyntaxProtocol`, which returns the underlying syntax node type. It is primarily intended as a debugging aid during development.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ swift/utils/build-script --swiftsyntax --swiftpm --llbuild -t --skip-test-cmark
181181
```
182182
This command will build SwiftSyntax and all its dependencies, tell the build script to run tests, but skip all tests but the SwiftSyntax tests.
183183

184-
Note that it is not currently supported to build SwiftSyntax while building the Swift compiler using Xcode.
184+
Note that it is not currently supported to SwiftSyntax while building the Swift compiler using Xcode.
185185

186186
### CI Testing
187187

Sources/SwiftSyntax/SyntaxBuilders.swift.gyb

-4
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ extension ${node.name} {
8585
/// incrementally build the structure of the node.
8686
/// - Returns: A `${node.name}` with all the fields populated in the builder
8787
/// closure.
88-
% if node.must_uphold_invariant:
89-
public init?(_ build: (inout ${Builder}) -> Void) {
90-
% else:
9188
public init(_ build: (inout ${Builder}) -> Void) {
92-
% end
9389
var builder = ${Builder}()
9490
build(&builder)
9591
let data = builder.buildData()

Sources/SwiftSyntax/SyntaxConvenienceMethods.swift

-80
This file was deleted.

Sources/SwiftSyntax/SyntaxFactory.swift.gyb

+1-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ public enum SyntaxFactory {
5757
% param_type = param_type + "?"
5858
% child_params.append("%s: %s" % (child.swift_name, param_type))
5959
% child_params = ', '.join(child_params)
60-
% if node.must_uphold_invariant:
61-
public static func make${node.syntax_kind}(${child_params}) -> ${node.name}? {
62-
% else:
6360
public static func make${node.syntax_kind}(${child_params}) -> ${node.name} {
64-
% end
6561
let layout: [RawSyntax?] = [
6662
% for child in node.children:
6763
% if child.is_optional:
@@ -86,7 +82,7 @@ public enum SyntaxFactory {
8682
}
8783
% end
8884

89-
% if not node.is_base() and not node.must_uphold_invariant:
85+
% if not node.is_base():
9086
public static func makeBlank${node.syntax_kind}() -> ${node.name} {
9187
let data = SyntaxData.forRoot(RawSyntax.create(kind: .${node.swift_syntax_kind},
9288
layout: [

Sources/SwiftSyntax/SyntaxNodes.swift.gyb.template

-42
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,14 @@ public struct ${node.name}: ${base_type}Protocol, SyntaxHashable {
7070
public init?(_ syntax: Syntax) {
7171
guard syntax.raw.kind == .${node.swift_syntax_kind} else { return nil }
7272
self._syntaxNode = syntax
73-
% if node.must_uphold_invariant:
74-
if !isValid {
75-
fatalError("Instance of ${node.name} is invalid.")
76-
}
77-
% end
7873
}
7974

8075
/// Creates a `${node.name}` node from the given `SyntaxData`. This assumes
8176
/// that the `SyntaxData` is of the correct kind. If it is not, the behaviour
8277
/// is undefined.
83-
% if node.must_uphold_invariant:
84-
/// This initializer returns nil if the invariant is not satisfied.
85-
internal init?(_ data: SyntaxData) {
86-
% else:
8778
internal init(_ data: SyntaxData) {
88-
% end
8979
assert(data.raw.kind == .${node.swift_syntax_kind})
9080
self._syntaxNode = Syntax(data)
91-
% if node.must_uphold_invariant:
92-
if !isValid {
93-
return nil
94-
}
95-
% end
9681
}
9782

9883
public var syntaxNodeType: SyntaxProtocol.Type {
@@ -122,33 +107,10 @@ public struct ${node.name}: ${base_type}Protocol, SyntaxHashable {
122107
% end
123108
return ${child.type_name}(childData!)
124109
}
125-
% if not node.must_uphold_invariant:
126110
set(value) {
127111
self = with${child.name}(value)
128112
}
129-
% end
130-
}
131-
% if node.must_uphold_invariant:
132-
133-
public enum ${child.name}Error: Error, CustomStringConvertible {
134-
case invalid(${child.swift_name}: ${ret_type})
135-
136-
public var description: String {
137-
switch self {
138-
case .invalid(let ${child.swift_name}):
139-
return "attempted to use setter with invalid ${child.name} \"\(${child.swift_name})\""
140-
}
141-
}
142113
}
143-
144-
mutating public func set${child.name}(_ ${child.swift_name}: ${ret_type}) throws {
145-
if let childSyntax = with${child.name}(${child.swift_name}) {
146-
self = childSyntax
147-
} else {
148-
throw ${child.name}Error.invalid(${child.swift_name}: ${child.swift_name})
149-
}
150-
}
151-
% end
152114
%
153115
% # ===============
154116
% # Adding children
@@ -187,11 +149,7 @@ public struct ${node.name}: ${base_type}Protocol, SyntaxHashable {
187149
/// - param newChild: The new `${child.swift_name}` to replace the node's
188150
/// current `${child.swift_name}`, if present.
189151
public func with${child.name}(
190-
% if node.must_uphold_invariant:
191-
_ newChild: ${child.type_name}?) -> ${node.name}? {
192-
% else:
193152
_ newChild: ${child.type_name}?) -> ${node.name} {
194-
% end
195153
% if child.is_optional:
196154
let raw = newChild?.raw
197155
% else:

Sources/SwiftSyntax/SyntaxRewriter.swift.gyb

-5
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,7 @@ open class SyntaxRewriter {
9191
if let newNode = visitAny(node._syntaxNode) { return newNode }
9292
return Syntax(visit(node))
9393
% else:
94-
% if node.must_uphold_invariant:
95-
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
96-
let node = ${node.name}(data)!
97-
% else:
9894
let node = ${node.name}(data)
99-
% end
10095
// Accessing _syntaxNode directly is faster than calling Syntax(node)
10196
visitPre(node._syntaxNode)
10297
defer { visitPost(node._syntaxNode) }

Sources/SwiftSyntax/SyntaxVisitor.swift.gyb

-5
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ open class SyntaxVisitor {
8686
}
8787
visitPost(node)
8888
% else:
89-
% if node.must_uphold_invariant:
90-
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
91-
let node = ${node.name}(data)!
92-
% else:
9389
let node = ${node.name}(data)
94-
% end
9590
let needsChildren = (visit(node) == .visitChildren)
9691
// Avoid calling into visitChildren if possible.
9792
if needsChildren && node.raw.numberOfChildren > 0 {

Sources/SwiftSyntax/gyb_generated/SyntaxBuilders.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ extension FloatLiteralExprSyntax {
10771077
/// incrementally build the structure of the node.
10781078
/// - Returns: A `FloatLiteralExprSyntax` with all the fields populated in the builder
10791079
/// closure.
1080-
public init?(_ build: (inout FloatLiteralExprSyntaxBuilder) -> Void) {
1080+
public init(_ build: (inout FloatLiteralExprSyntaxBuilder) -> Void) {
10811081
var builder = FloatLiteralExprSyntaxBuilder()
10821082
build(&builder)
10831083
let data = builder.buildData()
@@ -1444,7 +1444,7 @@ extension IntegerLiteralExprSyntax {
14441444
/// incrementally build the structure of the node.
14451445
/// - Returns: A `IntegerLiteralExprSyntax` with all the fields populated in the builder
14461446
/// closure.
1447-
public init?(_ build: (inout IntegerLiteralExprSyntaxBuilder) -> Void) {
1447+
public init(_ build: (inout IntegerLiteralExprSyntaxBuilder) -> Void) {
14481448
var builder = IntegerLiteralExprSyntaxBuilder()
14491449
build(&builder)
14501450
let data = builder.buildData()

Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift

+16-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ public enum SyntaxFactory {
619619
], length: .zero, presence: .present))
620620
return ArrowExprSyntax(data)
621621
}
622-
public static func makeFloatLiteralExpr(floatingDigits: TokenSyntax) -> FloatLiteralExprSyntax? {
622+
public static func makeFloatLiteralExpr(floatingDigits: TokenSyntax) -> FloatLiteralExprSyntax {
623623
let layout: [RawSyntax?] = [
624624
floatingDigits.raw,
625625
]
@@ -629,6 +629,13 @@ public enum SyntaxFactory {
629629
return FloatLiteralExprSyntax(data)
630630
}
631631

632+
public static func makeBlankFloatLiteralExpr() -> FloatLiteralExprSyntax {
633+
let data = SyntaxData.forRoot(RawSyntax.create(kind: .floatLiteralExpr,
634+
layout: [
635+
RawSyntax.missingToken(TokenKind.floatingLiteral("")),
636+
], length: .zero, presence: .present))
637+
return FloatLiteralExprSyntax(data)
638+
}
632639
public static func makeTupleExpr(leftParen: TokenSyntax, elementList: TupleExprElementListSyntax, rightParen: TokenSyntax) -> TupleExprSyntax {
633640
let layout: [RawSyntax?] = [
634641
leftParen.raw,
@@ -757,7 +764,7 @@ public enum SyntaxFactory {
757764
], length: .zero, presence: .present))
758765
return DictionaryElementSyntax(data)
759766
}
760-
public static func makeIntegerLiteralExpr(digits: TokenSyntax) -> IntegerLiteralExprSyntax? {
767+
public static func makeIntegerLiteralExpr(digits: TokenSyntax) -> IntegerLiteralExprSyntax {
761768
let layout: [RawSyntax?] = [
762769
digits.raw,
763770
]
@@ -767,6 +774,13 @@ public enum SyntaxFactory {
767774
return IntegerLiteralExprSyntax(data)
768775
}
769776

777+
public static func makeBlankIntegerLiteralExpr() -> IntegerLiteralExprSyntax {
778+
let data = SyntaxData.forRoot(RawSyntax.create(kind: .integerLiteralExpr,
779+
layout: [
780+
RawSyntax.missingToken(TokenKind.integerLiteral("")),
781+
], length: .zero, presence: .present))
782+
return IntegerLiteralExprSyntax(data)
783+
}
770784
public static func makeBooleanLiteralExpr(booleanLiteral: TokenSyntax) -> BooleanLiteralExprSyntax {
771785
let layout: [RawSyntax?] = [
772786
booleanLiteral.raw,

Sources/SwiftSyntax/gyb_generated/SyntaxRewriter.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -2135,8 +2135,7 @@ open class SyntaxRewriter {
21352135

21362136
/// Implementation detail of visit(_:). Do not call directly.
21372137
private func visitImplFloatLiteralExprSyntax(_ data: SyntaxData) -> Syntax {
2138-
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
2139-
let node = FloatLiteralExprSyntax(data)!
2138+
let node = FloatLiteralExprSyntax(data)
21402139
// Accessing _syntaxNode directly is faster than calling Syntax(node)
21412140
visitPre(node._syntaxNode)
21422141
defer { visitPost(node._syntaxNode) }
@@ -2206,8 +2205,7 @@ open class SyntaxRewriter {
22062205

22072206
/// Implementation detail of visit(_:). Do not call directly.
22082207
private func visitImplIntegerLiteralExprSyntax(_ data: SyntaxData) -> Syntax {
2209-
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
2210-
let node = IntegerLiteralExprSyntax(data)!
2208+
let node = IntegerLiteralExprSyntax(data)
22112209
// Accessing _syntaxNode directly is faster than calling Syntax(node)
22122210
visitPre(node._syntaxNode)
22132211
defer { visitPost(node._syntaxNode) }

Sources/SwiftSyntax/gyb_generated/SyntaxVisitor.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -2878,8 +2878,7 @@ open class SyntaxVisitor {
28782878

28792879
/// Implementation detail of doVisit(_:_:). Do not call directly.
28802880
private func visitImplFloatLiteralExprSyntax(_ data: SyntaxData) {
2881-
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
2882-
let node = FloatLiteralExprSyntax(data)!
2881+
let node = FloatLiteralExprSyntax(data)
28832882
let needsChildren = (visit(node) == .visitChildren)
28842883
// Avoid calling into visitChildren if possible.
28852884
if needsChildren && node.raw.numberOfChildren > 0 {
@@ -2956,8 +2955,7 @@ open class SyntaxVisitor {
29562955

29572956
/// Implementation detail of doVisit(_:_:). Do not call directly.
29582957
private func visitImplIntegerLiteralExprSyntax(_ data: SyntaxData) {
2959-
// We know that the SyntaxData is valid since we are walking a valid syntax tree and haven't modified the syntax data. Thus the initializer below will never return nil.
2960-
let node = IntegerLiteralExprSyntax(data)!
2958+
let node = IntegerLiteralExprSyntax(data)
29612959
let needsChildren = (visit(node) == .visitChildren)
29622960
// Avoid calling into visitChildren if possible.
29632961
if needsChildren && node.raw.numberOfChildren > 0 {

0 commit comments

Comments
 (0)