Skip to content

Commit 7e20199

Browse files
committed
Update the reflection printer to not omit parens from single argument
function types. This exposes something which I think is a bug in the reflection encoding, I'll chat with Slava about it.
1 parent 226a675 commit 7e20199

File tree

2 files changed

+38
-59
lines changed

2 files changed

+38
-59
lines changed

stdlib/public/runtime/Casting.cpp

+11-33
Original file line numberDiff line numberDiff line change
@@ -161,41 +161,19 @@ static void _buildFunctionTypeName(const FunctionTypeMetadata *func,
161161
bool qualified,
162162
std::string &result) {
163163

164-
if (func->getNumArguments() == 1) {
165-
auto firstArgument = func->getArguments()[0].getPointer();
166-
bool isInout = func->getArguments()[0].getFlag();
167-
168-
// This could be a single input tuple, with one or more arguments inside,
169-
// but guaranteed to not have inout types.
170-
if (auto tupleMetadata = dyn_cast<TupleTypeMetadata>(firstArgument)) {
171-
_buildNameForMetadata(tupleMetadata,
172-
TypeSyntaxLevel::TypeSimple,
173-
qualified,
174-
result);
175-
} else {
176-
if (isInout)
177-
result += "inout ";
178-
179-
_buildNameForMetadata(firstArgument,
180-
TypeSyntaxLevel::TypeSimple,
181-
qualified,
182-
result);
164+
result += "(";
165+
for (size_t i = 0; i < func->getNumArguments(); ++i) {
166+
auto arg = func->getArguments()[i].getPointer();
167+
bool isInout = func->getArguments()[i].getFlag();
168+
if (isInout)
169+
result += "inout ";
170+
_buildNameForMetadata(arg, TypeSyntaxLevel::TypeSimple,
171+
qualified, result);
172+
if (i < func->getNumArguments() - 1) {
173+
result += ", ";
183174
}
184-
} else {
185-
result += "(";
186-
for (size_t i = 0; i < func->getNumArguments(); ++i) {
187-
auto arg = func->getArguments()[i].getPointer();
188-
bool isInout = func->getArguments()[i].getFlag();
189-
if (isInout)
190-
result += "inout ";
191-
_buildNameForMetadata(arg, TypeSyntaxLevel::TypeSimple,
192-
qualified, result);
193-
if (i < func->getNumArguments() - 1) {
194-
result += ", ";
195-
}
196-
}
197-
result += ")";
198175
}
176+
result += ")";
199177

200178
if (func->throws()) {
201179
result += " throws";

test/1_stdlib/TypeName.swift

+27-26
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ typealias F = () -> ()
5050
typealias F2 = () -> () -> ()
5151
typealias F3 = (() -> ()) -> ()
5252

53-
printTypeName(F.self) // CHECK-NEXT: () -> ()
54-
printTypeName(F2.self) // CHECK-NEXT: () -> () -> ()
55-
printTypeName(F3.self) // CHECK-NEXT: (() -> ()) -> ()
53+
printTypeName(F.self) // CHECK-NEXT: (()) -> ()
54+
printTypeName(F2.self) // CHECK-NEXT: (()) -> (()) -> ()
55+
printTypeName(F3.self) // CHECK-NEXT: (((()) -> ())) -> ()
56+
5657

5758
#if _runtime(_ObjC)
5859
typealias B = @convention(block) () -> ()
@@ -66,11 +67,11 @@ print("@convention(block) () -> ()")
6667
print("() -> @convention(block) () -> ()")
6768
print("(@convention(block) () -> ()) -> ()")
6869
#endif
69-
// CHECK-NEXT: @convention(block) () -> ()
70-
// CHECK-NEXT: () -> @convention(block) () -> ()
71-
// CHECK-NEXT: (@convention(block) () -> ()) -> ()
70+
// CHECK-NEXT: @convention(block) (()) -> ()
71+
// CHECK-NEXT: (()) -> @convention(block) (()) -> ()
72+
// CHECK-NEXT: ((@convention(block) (()) -> ())) -> ()
7273

73-
printTypeName(F.Type.self) // CHECK-NEXT: (() -> ()).Type
74+
printTypeName(F.Type.self) // CHECK-NEXT: ((()) -> ()).Type
7475
printTypeName(C.Type.self) // CHECK-NEXT: [[THIS]].C.Type
7576
printTypeName(C.Type.Type.self) // CHECK-NEXT: [[THIS]].C.Type.Type
7677
printTypeName(Any.Type.self) // CHECK-NEXT: protocol<>.Type
@@ -81,24 +82,24 @@ printTypeName((AnyObject?).self) // CHECK-NEXT: {{^}}Swift.Optional<Swift.AnyObj
8182

8283
printTypeName(Void.self) // CHECK-NEXT: ()
8384
typealias Tup = (Any, F, C)
84-
printTypeName(Tup.self) // CHECK-NEXT: (protocol<>, () -> (), [[THIS]].C)
85+
printTypeName(Tup.self) // CHECK-NEXT: (protocol<>, (()) -> (), [[THIS]].C)
8586

86-
typealias IF = inout Int -> ()
87-
typealias IF2 = inout Int -> inout Int -> ()
88-
typealias IF3 = (inout Int -> ()) -> ()
89-
typealias IF3a = (inout (Int -> ())) -> ()
90-
typealias IF3b = inout (Int -> ()) -> ()
87+
typealias IF = (inout Int) -> ()
88+
typealias IF2 = (inout Int) -> (inout Int) -> ()
89+
typealias IF3 = ((inout Int) -> ()) -> ()
90+
typealias IF3a = (inout ((Int) -> ())) -> ()
91+
typealias IF3b = (inout ((Int) -> ())) -> ()
9192
typealias IF3c = ((inout Int) -> ()) -> ()
92-
typealias IF4 = inout (() -> ()) -> ()
93+
typealias IF4 = (inout (() -> ())) -> ()
9394
typealias IF5 = (inout Int, Any) -> ()
9495

95-
printTypeName(IF.self) // CHECK-NEXT: inout Swift.Int -> ()
96-
printTypeName(IF2.self) // CHECK-NEXT: inout Swift.Int -> inout Swift.Int -> ()
97-
printTypeName(IF3.self) // CHECK-NEXT: inout (Swift.Int -> ()) -> ()
98-
printTypeName(IF3a.self) // CHECK-NEXT: inout (Swift.Int -> ()) -> ()
99-
printTypeName(IF3b.self) // CHECK-NEXT: inout (Swift.Int -> ()) -> ()
100-
printTypeName(IF3c.self) // CHECK-NEXT: (inout Swift.Int -> ()) -> ()
101-
printTypeName(IF4.self) // CHECK-NEXT: inout (() -> ()) -> ()
96+
printTypeName(IF.self) // CHECK-NEXT: (inout Swift.Int) -> ()
97+
printTypeName(IF2.self) // CHECK-NEXT: (inout Swift.Int) -> (inout Swift.Int) -> ()
98+
printTypeName(IF3.self) // CHECK-NEXT: (((inout Swift.Int) -> ())) -> ()
99+
printTypeName(IF3a.self) // CHECK-NEXT: (inout ((Swift.Int) -> ())) -> ()
100+
printTypeName(IF3b.self) // CHECK-NEXT: (inout ((Swift.Int) -> ())) -> ()
101+
printTypeName(IF3c.self) // CHECK-NEXT: (((inout Swift.Int) -> ())) -> ()
102+
printTypeName(IF4.self) // CHECK-NEXT: (inout ((()) -> ())) -> ()
102103
printTypeName(IF5.self) // CHECK-NEXT: (inout Swift.Int, protocol<>) -> ()
103104

104105
func curry1() {
@@ -125,12 +126,12 @@ func curry3Throws() throws -> () throws -> () {
125126
return curry1Throws
126127
}
127128

128-
printTypeName(curry1.dynamicType) // CHECK-NEXT: () -> ()
129+
printTypeName(curry1.dynamicType) // CHECK-NEXT: (()) -> ()
129130

130-
printTypeName(curry2.dynamicType) // CHECK-NEXT: () -> () -> ()
131+
printTypeName(curry2.dynamicType) // CHECK-NEXT: (()) -> (()) -> ()
131132

132-
printTypeName(curry2Throws.dynamicType) // CHECK-NEXT: () throws -> () -> ()
133+
printTypeName(curry2Throws.dynamicType) // CHECK-NEXT: (()) throws -> (()) -> ()
133134

134-
printTypeName(curry3.dynamicType) // CHECK-NEXT: () -> () throws -> ()
135+
printTypeName(curry3.dynamicType) // CHECK-NEXT: (()) -> (()) throws -> ()
135136

136-
printTypeName(curry3Throws.dynamicType) // CHECK-NEXT: () throws -> () throws -> ()
137+
printTypeName(curry3Throws.dynamicType) // CHECK-NEXT: (()) throws -> (()) throws -> ()

0 commit comments

Comments
 (0)