@@ -936,10 +936,8 @@ bool RequirementSource::shouldDiagnoseRedundancy(bool primary) const {
936
936
}
937
937
938
938
bool RequirementSource::isSelfDerivedSource (GenericSignatureBuilder &builder,
939
- Type type,
940
- bool &derivedViaConcrete) const {
941
- return getMinimalConformanceSource (builder, type, /* proto=*/ nullptr ,
942
- derivedViaConcrete)
939
+ Type type) const {
940
+ return getMinimalConformanceSource (builder, type, /* proto=*/ nullptr )
943
941
!= this ;
944
942
}
945
943
@@ -989,10 +987,7 @@ static bool isSelfDerivedProtocolRequirementInProtocol(
989
987
const RequirementSource *RequirementSource::getMinimalConformanceSource (
990
988
GenericSignatureBuilder &builder,
991
989
Type currentType,
992
- ProtocolDecl *proto,
993
- bool &derivedViaConcrete) const {
994
- derivedViaConcrete = false ;
995
-
990
+ ProtocolDecl *proto) const {
996
991
// If it's not a derived requirement, it's not self-derived.
997
992
if (!isDerivedRequirement ()) return this ;
998
993
@@ -1059,15 +1054,6 @@ const RequirementSource *RequirementSource::getMinimalConformanceSource(
1059
1054
ArchetypeResolutionKind::WellFormed);
1060
1055
assert (parentEquivClass && " Not a well-formed type?" );
1061
1056
1062
- if (requirementSignatureSelfProto) {
1063
- if (parentEquivClass->concreteType )
1064
- derivedViaConcrete = true ;
1065
- else if (parentEquivClass->superclass &&
1066
- builder.lookupConformance (parentEquivClass->superclass ,
1067
- source->getProtocolDecl ()))
1068
- derivedViaConcrete = true ;
1069
- }
1070
-
1071
1057
// The parent potential archetype must conform to the protocol in which
1072
1058
// this requirement resides. Add this constraint.
1073
1059
if (auto startOfPath =
@@ -1136,7 +1122,7 @@ const RequirementSource *RequirementSource::getMinimalConformanceSource(
1136
1122
redundantSubpath->first ,
1137
1123
redundantSubpath->second );
1138
1124
return shorterSource
1139
- ->getMinimalConformanceSource (builder, currentType, proto, derivedViaConcrete );
1125
+ ->getMinimalConformanceSource (builder, currentType, proto);
1140
1126
}
1141
1127
1142
1128
// It's self-derived but we don't have a redundant subpath to eliminate.
@@ -5797,13 +5783,10 @@ static void expandSameTypeConstraints(GenericSignatureBuilder &builder,
5797
5783
bool alreadyFound = false ;
5798
5784
const RequirementSource *conformsSource = nullptr ;
5799
5785
for (const auto &constraint : conforms.second ) {
5800
- bool derivedViaConcrete = false ;
5801
-
5802
5786
auto *minimal = constraint.source ->getMinimalConformanceSource (
5803
- builder, constraint.getSubjectDependentType ({ }), proto,
5804
- derivedViaConcrete);
5787
+ builder, constraint.getSubjectDependentType ({ }), proto);
5805
5788
5806
- if (minimal == nullptr || derivedViaConcrete )
5789
+ if (minimal == nullptr )
5807
5790
continue ;
5808
5791
5809
5792
if (minimal->getAffectedType ()->isEqual (dependentType)) {
@@ -6028,18 +6011,14 @@ void GenericSignatureBuilder::computeRedundantRequirements(
6028
6011
requirementSignatureSelfProto,
6029
6012
[&](const Constraint<ProtocolDecl *> &constraint) {
6030
6013
// FIXME: Remove this.
6031
- bool derivedViaConcrete;
6032
6014
auto minimalSource =
6033
6015
constraint.source ->getMinimalConformanceSource (
6034
6016
*this ,
6035
6017
constraint.getSubjectDependentType ({ }),
6036
- proto, derivedViaConcrete );
6018
+ proto);
6037
6019
if (minimalSource != constraint.source )
6038
6020
return true ;
6039
6021
6040
- if (derivedViaConcrete)
6041
- return true ;
6042
-
6043
6022
return false ;
6044
6023
});
6045
6024
@@ -6613,27 +6592,21 @@ void GenericSignatureBuilder::processDelayedRequirements() {
6613
6592
6614
6593
namespace {
6615
6594
// / Remove self-derived sources from the given vector of constraints.
6616
- // /
6617
- // / \returns true if any derived-via-concrete constraints were found.
6618
6595
template <typename T>
6619
- bool removeSelfDerived (GenericSignatureBuilder &builder,
6596
+ void removeSelfDerived (GenericSignatureBuilder &builder,
6620
6597
std::vector<Constraint<T>> &constraints,
6621
6598
ProtocolDecl *proto,
6622
- bool dropDerivedViaConcrete = true ,
6623
6599
bool allCanBeSelfDerived = false ) {
6624
6600
auto genericParams = builder.getGenericParams ();
6625
- bool anyDerivedViaConcrete = false ;
6626
- Optional<Constraint<T>> remainingConcrete;
6627
6601
SmallVector<Constraint<T>, 4 > minimalSources;
6628
6602
constraints.erase (
6629
6603
std::remove_if (constraints.begin (), constraints.end (),
6630
6604
[&](const Constraint<T> &constraint) {
6631
- bool derivedViaConcrete;
6632
6605
auto minimalSource =
6633
6606
constraint.source ->getMinimalConformanceSource (
6634
6607
builder,
6635
6608
constraint.getSubjectDependentType (genericParams),
6636
- proto, derivedViaConcrete );
6609
+ proto);
6637
6610
if (minimalSource != constraint.source ) {
6638
6611
// The minimal source is smaller than the original source, so the
6639
6612
// original source is self-derived.
@@ -6650,21 +6623,8 @@ namespace {
6650
6623
return true ;
6651
6624
}
6652
6625
6653
- if (!derivedViaConcrete)
6654
- return false ;
6655
-
6656
- anyDerivedViaConcrete = true ;
6657
-
6658
- if (!dropDerivedViaConcrete)
6659
- return false ;
6660
-
6661
- // Drop derived-via-concrete requirements.
6662
- if (!remainingConcrete)
6663
- remainingConcrete = constraint;
6664
-
6665
- ++NumSelfDerived;
6666
- return true ;
6667
- }),
6626
+ return false ;
6627
+ }),
6668
6628
constraints.end ());
6669
6629
6670
6630
// If we found any minimal sources, add them now, avoiding introducing any
@@ -6684,13 +6644,8 @@ namespace {
6684
6644
}
6685
6645
}
6686
6646
6687
- // If we only had concrete conformances, put one back.
6688
- if (constraints.empty () && remainingConcrete)
6689
- constraints.push_back (*remainingConcrete);
6690
-
6691
6647
assert ((!constraints.empty () || allCanBeSelfDerived) &&
6692
6648
" All constraints were self-derived!" );
6693
- return anyDerivedViaConcrete;
6694
6649
}
6695
6650
} // end anonymous namespace
6696
6651
@@ -7253,9 +7208,7 @@ static void computeDerivedSameTypeComponents(
7253
7208
// construction of self-derived sources really don't work, because we
7254
7209
// discover more information later, so we need a more on-line or
7255
7210
// iterative approach.
7256
- bool derivedViaConcrete;
7257
- if (concrete.source ->isSelfDerivedSource (builder, subjectType,
7258
- derivedViaConcrete))
7211
+ if (concrete.source ->isSelfDerivedSource (builder, subjectType))
7259
7212
continue ;
7260
7213
7261
7214
// If it has a better source than we'd seen before for this component,
@@ -7589,13 +7542,10 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
7589
7542
if (!equivClass->derivedSameTypeComponents .empty ())
7590
7543
return ;
7591
7544
7592
- bool anyDerivedViaConcrete = false ;
7593
7545
// Remove self-derived constraints.
7594
- if (removeSelfDerived (*this , equivClass->sameTypeConstraints ,
7595
- /* proto=*/ nullptr ,
7596
- /* dropDerivedViaConcrete=*/ false ,
7597
- /* allCanBeSelfDerived=*/ true ))
7598
- anyDerivedViaConcrete = true ;
7546
+ removeSelfDerived (*this , equivClass->sameTypeConstraints ,
7547
+ /* proto=*/ nullptr ,
7548
+ /* allCanBeSelfDerived=*/ true );
7599
7549
7600
7550
// Sort the constraints, so we get a deterministic ordering of diagnostics.
7601
7551
llvm::array_pod_sort (equivClass->sameTypeConstraints .begin (),
@@ -7673,16 +7623,6 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
7673
7623
IntercomponentEdge (firstComponentIdx, secondComponentIdx, constraint));
7674
7624
}
7675
7625
7676
- // If there were any derived-via-concrete constraints, drop them now before
7677
- // we emit other diagnostics.
7678
- if (anyDerivedViaConcrete) {
7679
- // Remove derived-via-concrete constraints.
7680
- (void )removeSelfDerived (*this , equivClass->sameTypeConstraints ,
7681
- /* proto=*/ nullptr ,
7682
- /* dropDerivedViaConcrete=*/ true ,
7683
- /* allCanBeSelfDerived=*/ true );
7684
- }
7685
-
7686
7626
// Walk through each of the components, checking the intracomponent edges.
7687
7627
// This will diagnose any explicitly-specified requirements within a
7688
7628
// component, all of which are redundant.
@@ -7880,7 +7820,6 @@ void GenericSignatureBuilder::checkConcreteTypeConstraints(
7880
7820
7881
7821
removeSelfDerived (*this , equivClass->concreteTypeConstraints ,
7882
7822
/* proto=*/ nullptr ,
7883
- /* dropDerivedViaConcrete=*/ true ,
7884
7823
/* allCanBeSelfDerived=*/ true );
7885
7824
7886
7825
// This can occur if the combination of a superclass requirement and
0 commit comments