Skip to content

Commit 07b0c5c

Browse files
committed
ASTPrinter: Print shape requirements in a way that parses
1 parent 0f66cb6 commit 07b0c5c

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,22 +1787,26 @@ void PrintAST::printSingleDepthOfGenericSignature(
17871787
}
17881788

17891789
void PrintAST::printRequirement(const Requirement &req) {
1790-
printTransformedType(req.getFirstType());
17911790
switch (req.getKind()) {
17921791
case RequirementKind::SameShape:
1793-
Printer << ".shape == ";
1792+
Printer << "((";
1793+
printTransformedType(req.getFirstType());
1794+
Printer << ", ";
17941795
printTransformedType(req.getSecondType());
1795-
Printer << ".shape";
1796+
Printer << ")...) : Any";
17961797
return;
17971798
case RequirementKind::Layout:
1799+
printTransformedType(req.getFirstType());
17981800
Printer << " : ";
17991801
req.getLayoutConstraint()->print(Printer, Options);
18001802
return;
18011803
case RequirementKind::Conformance:
18021804
case RequirementKind::Superclass:
1805+
printTransformedType(req.getFirstType());
18031806
Printer << " : ";
18041807
break;
18051808
case RequirementKind::SameType:
1809+
printTransformedType(req.getFirstType());
18061810
Printer << " == ";
18071811
break;
18081812
}

test/Generics/pack-shape-requirements.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,42 @@ protocol P {
77
}
88

99
// CHECK-LABEL: inferSameShape(ts:us:)
10-
// CHECK-NEXT: Generic signature: <T..., U... where T.shape == U.shape>
10+
// CHECK-NEXT: Generic signature: <T..., U... where ((T, U)...) : Any>
1111
func inferSameShape<T..., U...>(ts t: T..., us u: U...) where ((T, U)...): Any {
1212
}
1313

1414
// CHECK-LABEL: desugarSameShape(ts:us:)
15-
// CHECK-NEXT: Generic signature: <T..., U... where T : P, T.shape == U.shape, U : P>
15+
// CHECK-NEXT: Generic signature: <T..., U... where T : P, ((T, U)...) : Any, U : P>
1616
func desugarSameShape<T..., U...>(ts t: T..., us u: U...) where T: P, U: P, ((T.A, U.A)...): Any {
1717
}
1818

1919
// CHECK-LABEL: multipleSameShape1(ts:us:vs:)
20-
// CHECK-NEXT: Generic signature: <T..., U..., V... where T.shape == U.shape, U.shape == V.shape>
20+
// CHECK-NEXT: Generic signature: <T..., U..., V... where ((T, U)...) : Any, ((U, V)...) : Any>
2121
func multipleSameShape1<T..., U..., V...>(ts t: T..., us u: U..., vs v: V...) where ((T, U, V)...): Any {
2222
}
2323

2424
// CHECK-LABEL: multipleSameShape2(ts:us:vs:)
25-
// CHECK-NEXT: Generic signature: <T..., U..., V... where T.shape == U.shape, U.shape == V.shape>
25+
// CHECK-NEXT: Generic signature: <T..., U..., V... where ((T, U)...) : Any, ((U, V)...) : Any>
2626
func multipleSameShape2<T..., U..., V...>(ts t: T..., us u: U..., vs v: V...) where ((V, T, U)...): Any {
2727
}
2828

2929
// CHECK-LABEL: multipleSameShape3(ts:us:vs:)
30-
// CHECK-NEXT: Generic signature: <T..., U..., V... where T.shape == U.shape, U.shape == V.shape>
30+
// CHECK-NEXT: Generic signature: <T..., U..., V... where ((T, U)...) : Any, ((U, V)...) : Any>
3131
func multipleSameShape3<T..., U..., V...>(ts t: T..., us u: U..., vs v: V...) where ((U, V, T)...): Any {
3232
}
3333

3434
// CHECK-LABEL: multipleSameShape4(ts:us:vs:)
35-
// CHECK-NEXT: Generic signature: <T..., U..., V... where T.shape == U.shape, U.shape == V.shape>
35+
// CHECK-NEXT: Generic signature: <T..., U..., V... where ((T, U)...) : Any, ((U, V)...) : Any>
3636
func multipleSameShape4<T..., U..., V...>(ts t: T..., us u: U..., vs v: V...) where ((U, T, V)...): Any {
3737
}
3838

3939
// CHECK-LABEL: multipleSameShape5(ts:us:vs:)
40-
// CHECK-NEXT: Generic signature: <T..., U..., V... where T.shape == U.shape, U.shape == V.shape>
40+
// CHECK-NEXT: Generic signature: <T..., U..., V... where ((T, U)...) : Any, ((U, V)...) : Any>
4141
func multipleSameShape5<T..., U..., V...>(ts t: T..., us u: U..., vs v: V...) where ((T, V, U)...): Any {
4242
}
4343

4444
// CHECK-LABEL: multipleSameShape6(ts:us:vs:)
45-
// CHECK-NEXT: Generic signature: <T..., U..., V... where T.shape == U.shape, U.shape == V.shape>
45+
// CHECK-NEXT: Generic signature: <T..., U..., V... where ((T, U)...) : Any, ((U, V)...) : Any>
4646
func multipleSameShape6<T..., U..., V...>(ts t: T..., us u: U..., vs v: V...) where ((V, U, T)...): Any {
4747
}
4848

@@ -55,15 +55,15 @@ struct Ts<T...> {
5555

5656
struct Vs<V...> {
5757
// CHECK-LABEL: Ts.Us.Vs.packEquality()
58-
// CHECK-NEXT: Generic signature: <T..., U..., V... where T == U, T.shape == V.shape>
58+
// CHECK-NEXT: Generic signature: <T..., U..., V... where T == U, ((T, V)...) : Any>
5959
func packEquality() where T == U, ((U, V)...): Any {
6060
}
6161
}
6262
}
6363
}
6464

6565
// CHECK-LABEL: expandedParameters(_:transform:)
66-
// CHECK-NEXT: Generic signature: <T..., Result... where T.shape == Result.shape>
66+
// CHECK-NEXT: Generic signature: <T..., Result... where ((T, Result)...) : Any>
6767
func expandedParameters<T..., Result...>(_ t: T..., transform: ((T) -> Result)...) -> (Result...) {
6868
fatalError()
6969
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-module-interface(%t/PackExpansionType.swiftinterface) %s -module-name PackExpansionType -enable-experimental-feature VariadicGenerics
3+
// RUN: %FileCheck %s < %t/PackExpansionType.swiftinterface
4+
5+
// CHECK: public func variadicFunction<T..., U...>(t: T..., u: U...) -> ((T, U)...) where ((T, U)...) : Any
6+
public func variadicFunction<T..., U...>(t: T..., u: U...) -> ((T, U)...) {}
7+
8+
// CHECK: public struct VariadicType<T...> {
9+
public struct VariadicType<T...> {
10+
// CHECK: public func variadicMethod<U...>(t: T..., u: U...) -> ((T, U)...) where ((T, U)...) : Any
11+
public func variadicMethod<U...>(t: T..., u: U...) -> ((T, U)...) {}
12+
}
13+
// CHECK: }

0 commit comments

Comments
 (0)