Skip to content

Commit e8c4418

Browse files
committed
GSB: We only care about 'derived from concrete' requirements when building requirement signatures
Once we can rebuild requirement signatures after dropping redundant requirements, we won't need this at all.
1 parent 977d3a7 commit e8c4418

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,12 +1096,14 @@ const RequirementSource *RequirementSource::getMinimalConformanceSource(
10961096
ArchetypeResolutionKind::WellFormed);
10971097
assert(parentEquivClass && "Not a well-formed type?");
10981098

1099-
if (parentEquivClass->concreteType)
1100-
derivedViaConcrete = true;
1101-
else if (parentEquivClass->superclass &&
1102-
builder.lookupConformance(parentEquivClass->superclass,
1103-
source->getProtocolDecl()))
1104-
derivedViaConcrete = true;
1099+
if (requirementSignatureSelfProto) {
1100+
if (parentEquivClass->concreteType)
1101+
derivedViaConcrete = true;
1102+
else if (parentEquivClass->superclass &&
1103+
builder.lookupConformance(parentEquivClass->superclass,
1104+
source->getProtocolDecl()))
1105+
derivedViaConcrete = true;
1106+
}
11051107

11061108
// The parent potential archetype must conform to the protocol in which
11071109
// this requirement resides. Add this constraint.
@@ -7200,6 +7202,9 @@ void GenericSignatureBuilder::diagnoseRedundantRequirements() const {
72007202

72017203
for (auto otherReq : found->second) {
72027204
auto *otherSource = otherReq.getSource();
7205+
if (otherSource->isInferredRequirement())
7206+
continue;
7207+
72037208
auto otherLoc = otherSource->getLoc();
72047209
if (otherLoc.isInvalid())
72057210
continue;
@@ -7237,6 +7242,9 @@ void GenericSignatureBuilder::diagnoseRedundantRequirements() const {
72377242

72387243
for (auto otherReq : found->second) {
72397244
auto *otherSource = otherReq.getSource();
7245+
if (otherSource->isInferredRequirement())
7246+
continue;
7247+
72407248
auto otherLoc = otherSource->getLoc();
72417249
if (otherLoc.isInvalid())
72427250
continue;
@@ -7276,6 +7284,9 @@ void GenericSignatureBuilder::diagnoseRedundantRequirements() const {
72767284

72777285
for (auto otherReq : found->second) {
72787286
auto *otherSource = otherReq.getSource();
7287+
if (otherSource->isInferredRequirement())
7288+
continue;
7289+
72797290
auto otherLoc = otherSource->getLoc();
72807291
if (otherLoc.isInvalid())
72817292
continue;

test/Generics/rdar75656022.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ struct OriginalExampleWithWarning<A, B> where A : P2, B : P2, A.T == B.T {
4949
where C : P1,
5050
D : P1, // expected-warning {{redundant conformance constraint 'D' : 'P1'}}
5151
C.T : P1, // expected-warning {{redundant conformance constraint 'C.T' : 'P1'}}
52-
A == S1<C, C.T.T, S2<C.T>>,
52+
A == S1<C, C.T.T, S2<C.T>>, // expected-note {{conformance constraint 'D' : 'P1' implied here}}
53+
// expected-note@-1 {{conformance constraint 'C.T' : 'P1' implied here}}
5354
C.T == D,
5455
E == D.T { }
5556
}
@@ -71,6 +72,7 @@ struct WithoutBogusGenericParametersWithWarning<A, B> where A : P2, B : P2, A.T
7172
where C : P1,
7273
C.T : P1, // expected-warning {{redundant conformance constraint 'C.T' : 'P1'}}
7374
A == S1<C, C.T.T, S2<C.T>> {}
75+
// expected-note@-1 {{conformance constraint 'C.T' : 'P1' implied here}}
7476
}
7577

7678
// Same as above but without unnecessary generic parameters

0 commit comments

Comments
 (0)