Skip to content

Commit d57f1aa

Browse files
authored
Merge pull request swiftlang#40919 from slavapestov/debug-generic-signatures
AST: -debug-generic-signatures protocol-qualifies DependentMemberTypes
2 parents 0a93cff + e497315 commit d57f1aa

File tree

64 files changed

+273
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+273
-269
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ struct PrintOptions {
200200
/// Print fully qualified extended types if ambiguous.
201201
bool FullyQualifiedExtendedTypesIfAmbiguous = false;
202202

203+
/// Whether to protocol-qualify DependentMemberTypes.
204+
bool ProtocolQualifiedDependentMemberTypes = false;
205+
203206
/// If true, printed module names will use the "exported" name, which may be
204207
/// different from the regular name.
205208
///

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6053,6 +6053,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
60536053
void visitDependentMemberType(DependentMemberType *T) {
60546054
visitParentType(T->getBase());
60556055
if (auto *const Assoc = T->getAssocType()) {
6056+
if (Options.ProtocolQualifiedDependentMemberTypes) {
6057+
Printer << "[";
6058+
Printer.printName(Assoc->getProtocol()->getName());
6059+
Printer << "]";
6060+
}
60566061
Printer.printTypeRef(T, Assoc, T->getName());
60576062
} else {
60586063
Printer.printName(T->getName());

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,14 +2629,16 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26292629
PD->dumpRef(llvm::errs());
26302630
llvm::errs() << "\n";
26312631
llvm::errs() << "Requirement signature: ";
2632-
requirementsSig->print(llvm::errs());
2632+
PrintOptions Opts;
2633+
Opts.ProtocolQualifiedDependentMemberTypes = true;
2634+
requirementsSig->print(llvm::errs(), Opts);
26332635
llvm::errs() << "\n";
26342636

26352637
llvm::errs() << "Canonical requirement signature: ";
26362638
auto canRequirementSig =
26372639
CanGenericSignature::getCanonical(requirementsSig.getGenericParams(),
26382640
requirementsSig.getRequirements());
2639-
canRequirementSig->print(llvm::errs());
2641+
canRequirementSig->print(llvm::errs(), Opts);
26402642
llvm::errs() << "\n";
26412643
}
26422644

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,12 @@ GenericSignatureRequest::evaluate(Evaluator &evaluator,
656656
llvm::errs() << "\n";
657657
PD->printContext(llvm::errs());
658658
llvm::errs() << "Generic signature: ";
659-
sig->print(llvm::errs());
659+
PrintOptions Opts;
660+
Opts.ProtocolQualifiedDependentMemberTypes = true;
661+
sig->print(llvm::errs(), Opts);
660662
llvm::errs() << "\n";
661663
llvm::errs() << "Canonical generic signature: ";
662-
sig.getCanonicalSignature()->print(llvm::errs());
664+
sig.getCanonicalSignature()->print(llvm::errs(), Opts);
663665
llvm::errs() << "\n";
664666
}
665667
return sig;
@@ -817,10 +819,12 @@ GenericSignatureRequest::evaluate(Evaluator &evaluator,
817819
GC->printContext(llvm::errs());
818820
}
819821
llvm::errs() << "Generic signature: ";
820-
sig->print(llvm::errs());
822+
PrintOptions Opts;
823+
Opts.ProtocolQualifiedDependentMemberTypes = true;
824+
sig->print(llvm::errs(), Opts);
821825
llvm::errs() << "\n";
822826
llvm::errs() << "Canonical generic signature: ";
823-
sig.getCanonicalSignature()->print(llvm::errs());
827+
sig.getCanonicalSignature()->print(llvm::errs(), Opts);
824828
llvm::errs() << "\n";
825829
}
826830

test/Frontend/debug-generic-signatures.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ protocol P1 {
1414
// CHECK: Generic signature: <Self where Self : P2>
1515
// CHECK-NEXT: Canonical generic signature: <τ_0_0 where τ_0_0 : P2>
1616
// CHECK-LABEL: main.(file).P2@
17-
// CHECK: Requirement signature: <Self where Self.A : P2, Self.B : P2, Self.A.A == Self.B.A>
18-
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.A : P2, τ_0_0.B : P2, τ_0_0.A.A == τ_0_0.B.A>
17+
// CHECK: Requirement signature: <Self where Self.[P2]A : P2, Self.[P2]B : P2, Self.[P2]A.[P2]A == Self.[P2]B.[P2]A>
18+
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.[P2]A : P2, τ_0_0.[P2]B : P2, τ_0_0.[P2]A.[P2]A == τ_0_0.[P2]B.[P2]A>
1919
protocol P2 {
2020
associatedtype A: P2
2121
associatedtype B: P2 where Self.A.A == Self.B.A
@@ -25,8 +25,8 @@ protocol P2 {
2525
// CHECK: Generic signature: <Self where Self : P3>
2626
// CHECK-NEXT: Canonical generic signature: <τ_0_0 where τ_0_0 : P3>
2727
// CHECK-LABEL: main.(file).P3@
28-
// CHECK: Requirement signature: <Self where Self.A : P3>
29-
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.A : P3>
28+
// CHECK: Requirement signature: <Self where Self.[P3]A : P3>
29+
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.[P3]A : P3>
3030
protocol P3 {
3131
associatedtype A: P3
3232
}

test/Generics/abstract_type_witnesses_in_protocols.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,47 @@ protocol Q {
1414
protocol R {}
1515

1616
// CHECK-LABEL: abstract_type_witnesses_in_protocols.(file).Q1@
17-
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.A == G<Self.A.T>, Self.B : P, Self.A.T == Self.B.T>
17+
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.[Q]A == G<Self.[Q]A.[P]T>, Self.[Q1]B : P, Self.[Q]A.[P]T == Self.[Q1]B.[P]T>
1818

1919
// GSB: Non-canonical requirement
2020
protocol Q1 : Q {
2121
associatedtype B : P where A == G<B.T>
2222
}
2323

2424
// CHECK-LABEL: abstract_type_witnesses_in_protocols.(file).Q1a@
25-
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.A == G<Self.A.T>, Self.B : P, Self.A.T : R, Self.A.T == Self.B.T>
25+
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.[Q]A == G<Self.[Q]A.[P]T>, Self.[Q1a]B : P, Self.[Q]A.[P]T : R, Self.[Q]A.[P]T == Self.[Q1a]B.[P]T>
2626

2727
// GSB: Missing requirement
2828
protocol Q1a : Q {
2929
associatedtype B : P where A.T : R, A == G<B.T>
3030
}
3131

3232
// CHECK-LABEL: abstract_type_witnesses_in_protocols.(file).Q1b@
33-
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.A == G<Self.A.T>, Self.B : P, Self.A.T : R, Self.A.T == Self.B.T>
33+
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.[Q]A == G<Self.[Q]A.[P]T>, Self.[Q1b]B : P, Self.[Q]A.[P]T : R, Self.[Q]A.[P]T == Self.[Q1b]B.[P]T>
3434

3535
// GSB: Non-canonical requirement
3636
protocol Q1b : Q {
3737
associatedtype B : P where B.T : R, A == G<B.T>
3838
}
3939

4040
// CHECK-LABEL: abstract_type_witnesses_in_protocols.(file).Q2@
41-
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.A == G<Self.A.T>, Self.B : P, Self.A.T == Self.B.T>
41+
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.[Q]A == G<Self.[Q]A.[P]T>, Self.[Q2]B : P, Self.[Q]A.[P]T == Self.[Q2]B.[P]T>
4242

4343
// GSB: Missing requirement
4444
protocol Q2 : Q {
4545
associatedtype B : P where A.T == B.T, A == G<B.T>
4646
}
4747

4848
// CHECK-LABEL: abstract_type_witnesses_in_protocols.(file).Q3@
49-
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.A == G<Self.A.T>, Self.B : P, Self.A.T == Self.B.T>
49+
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.[Q]A == G<Self.[Q]A.[P]T>, Self.[Q3]B : P, Self.[Q]A.[P]T == Self.[Q3]B.[P]T>
5050

5151
// GSB: Unsupported recursive requirement
5252
protocol Q3 : Q {
5353
associatedtype B : P where A == G<A.T>, A.T == B.T
5454
}
5555

5656
// CHECK-LABEL: abstract_type_witnesses_in_protocols.(file).Q4@
57-
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.A == G<Self.A.T>, Self.B : P, Self.A.T == Self.B.T>
57+
// CHECK-NEXT: Requirement signature: <Self where Self : Q, Self.[Q]A == G<Self.[Q]A.[P]T>, Self.[Q4]B : P, Self.[Q]A.[P]T == Self.[Q4]B.[P]T>
5858

5959
// GSB: Unsupported recursive requirement
6060
protocol Q4 : Q {

test/Generics/canonical_concrete_substitutions_in_protocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
struct G<T> {}
44

55
// CHECK-LABEL: canonical_concrete_substitutions_in_protocol.(file).P@
6-
// CHECK-NEXT: Requirement signature: <Self where Self.A == G<Self.B>, Self.B == Self.T.X, Self.T : Q>
6+
// CHECK-NEXT: Requirement signature: <Self where Self.[P]A == G<Self.[P]B>, Self.[P]B == Self.[P]T.[Q]X, Self.[P]T : Q>
77

88
protocol P {
99
associatedtype A where A == G<T.X>
@@ -20,4 +20,4 @@ protocol QQ : Q {}
2020
protocol R {
2121
associatedtype A
2222
associatedtype C: QQ where C.X == G<A>
23-
}
23+
}

test/Generics/concrete_conformances_in_protocol.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct S : P {
88
}
99

1010
// CHECK-LABEL: concrete_conformances_in_protocol.(file).R0@
11-
// CHECK-LABEL: Requirement signature: <Self where Self.A == S>
11+
// CHECK-LABEL: Requirement signature: <Self where Self.[R0]A == S>
1212

1313
protocol R0 {
1414
associatedtype A where A : P, A == S
@@ -19,15 +19,15 @@ protocol R0 {
1919
struct G<T> : P {}
2020

2121
// CHECK-LABEL: concrete_conformances_in_protocol.(file).R1@
22-
// CHECK-LABEL: Requirement signature: <Self where Self.B == G<Self.A>>
22+
// CHECK-LABEL: Requirement signature: <Self where Self.[R1]B == G<Self.[R1]A>>
2323

2424
protocol R1 {
2525
associatedtype A
2626
associatedtype B where B : P, B == G<A>
2727
}
2828

2929
// CHECK-LABEL: concrete_conformances_in_protocol.(file).R2@
30-
// CHECK-LABEL: Requirement signature: <Self where Self.A == G<Self.B>>
30+
// CHECK-LABEL: Requirement signature: <Self where Self.[R2]A == G<Self.[R2]B>>
3131

3232
protocol R2 {
3333
associatedtype A where A : P, A == G<B>
@@ -43,31 +43,31 @@ protocol PP {
4343
struct GG<T : P> : PP {}
4444

4545
// CHECK-LABEL: concrete_conformances_in_protocol.(file).RR3@
46-
// CHECK-LABEL: Requirement signature: <Self where Self.A : P, Self.B == GG<Self.A>>
46+
// CHECK-LABEL: Requirement signature: <Self where Self.[RR3]A : P, Self.[RR3]B == GG<Self.[RR3]A>>
4747

4848
protocol RR3 {
4949
associatedtype A : P
5050
associatedtype B where B : PP, B == GG<A>
5151
}
5252

5353
// CHECK-LABEL: concrete_conformances_in_protocol.(file).RR4@
54-
// CHECK-LABEL: Requirement signature: <Self where Self.A == GG<Self.B>, Self.B : P>
54+
// CHECK-LABEL: Requirement signature: <Self where Self.[RR4]A == GG<Self.[RR4]B>, Self.[RR4]B : P>
5555

5656
protocol RR4 {
5757
associatedtype A where A : PP, A == GG<B>
5858
associatedtype B : P
5959
}
6060

6161
// CHECK-LABEL: concrete_conformances_in_protocol.(file).RR5@
62-
// CHECK-LABEL: Requirement signature: <Self where Self.A : PP, Self.B == GG<Self.A.T>>
62+
// CHECK-LABEL: Requirement signature: <Self where Self.[RR5]A : PP, Self.[RR5]B == GG<Self.[RR5]A.[PP]T>>
6363

6464
protocol RR5 {
6565
associatedtype A : PP
6666
associatedtype B where B : PP, B == GG<A.T>
6767
}
6868

6969
// CHECK-LABEL: concrete_conformances_in_protocol.(file).RR6@
70-
// CHECK-LABEL: Requirement signature: <Self where Self.A == GG<Self.B.T>, Self.B : PP>
70+
// CHECK-LABEL: Requirement signature: <Self where Self.[RR6]A == GG<Self.[RR6]B.[PP]T>, Self.[RR6]B : PP>
7171

7272
protocol RR6 {
7373
associatedtype A where A : PP, A == GG<B.T>

test/Generics/conditional_requirement_inference_in_protocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
33

44
// CHECK-LABEL: conditional_requirement_inference_in_protocol.(file).Good@
5-
// CHECK-LABEL: Requirement signature: <Self where Self.T == Array<Self.U>, Self.U : Equatable>
5+
// CHECK-LABEL: Requirement signature: <Self where Self.[Good]T == Array<Self.[Good]U>, Self.[Good]U : Equatable>
66

77
protocol Good {
88
associatedtype T : Equatable // expected-warning {{redundant conformance constraint 'Self.T' : 'Equatable'}}
99
associatedtype U : Equatable where T == Array<U> // expected-note {{conformance constraint 'Self.T' : 'Equatable' implied here}}
1010
}
1111

1212
// CHECK-LABEL: conditional_requirement_inference_in_protocol.(file).Bad@
13-
// CHECK-LABEL: Requirement signature: <Self where Self.T == Array<Self.U>>
13+
// CHECK-LABEL: Requirement signature: <Self where Self.[Bad]T == Array<Self.[Bad]U>>
1414

1515
protocol Bad {
1616
associatedtype T : Equatable // expected-warning {{redundant conformance constraint 'Self.T' : 'Equatable'}}

test/Generics/confluent_example.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
// The GSB crashes with P1 and P2, and rejects P3.
44

55
// CHECK-LABEL: confluent_example.(file).P1@
6-
// CHECK-LABEL: Requirement signature: <Self where Self.A : P1, Self.A == Self.A.B, Self.B : P1, Self.B == Self.B.C, Self.C : P1>
6+
// CHECK-LABEL: Requirement signature: <Self where Self.[P1]A : P1, Self.[P1]A == Self.[P1]A.[P1]B, Self.[P1]B : P1, Self.[P1]B == Self.[P1]B.[P1]C, Self.[P1]C : P1>
77
protocol P1 {
88
associatedtype A : P1
99
associatedtype B : P1
1010
associatedtype C : P1 where A.B == A, B.C == B
1111
}
1212

1313
// CHECK-LABEL: confluent_example.(file).P2@
14-
// CHECK-LABEL: Requirement signature: <Self where Self.A : P2, Self.A == Self.A.B, Self.B : P2, Self.B == Self.B.C, Self.C : P2>
14+
// CHECK-LABEL: Requirement signature: <Self where Self.[P2]A : P2, Self.[P2]A == Self.[P2]A.[P2]B, Self.[P2]B : P2, Self.[P2]B == Self.[P2]B.[P2]C, Self.[P2]C : P2>
1515
protocol P2 {
1616
associatedtype A : P2
1717
associatedtype B : P2
1818
associatedtype C : P2 where A.B == A, B.C == B, A.C == A
1919
}
2020

2121
// CHECK-LABEL: confluent_example.(file).P3@
22-
// CHECK-LABEL: Requirement signature: <Self where Self.A : P3, Self.A == Self.A.B, Self.B : P3, Self.B == Self.B.C, Self.C : P3>
22+
// CHECK-LABEL: Requirement signature: <Self where Self.[P3]A : P3, Self.[P3]A == Self.[P3]A.[P3]B, Self.[P3]B : P3, Self.[P3]B == Self.[P3]B.[P3]C, Self.[P3]C : P3>
2323
protocol P3 {
2424
associatedtype A where A.B : P3
2525
associatedtype B where B.C : P3

0 commit comments

Comments
 (0)