@@ -930,10 +930,8 @@ bool RequirementSource::shouldDiagnoseRedundancy(bool primary) const {
930
930
}
931
931
932
932
bool RequirementSource::isSelfDerivedSource (GenericSignatureBuilder &builder,
933
- Type type,
934
- bool &derivedViaConcrete) const {
935
- return getMinimalConformanceSource (builder, type, /* proto=*/ nullptr ,
936
- derivedViaConcrete)
933
+ Type type) const {
934
+ return getMinimalConformanceSource (builder, type, /* proto=*/ nullptr )
937
935
!= this ;
938
936
}
939
937
@@ -983,10 +981,7 @@ static bool isSelfDerivedProtocolRequirementInProtocol(
983
981
const RequirementSource *RequirementSource::getMinimalConformanceSource (
984
982
GenericSignatureBuilder &builder,
985
983
Type currentType,
986
- ProtocolDecl *proto,
987
- bool &derivedViaConcrete) const {
988
- derivedViaConcrete = false ;
989
-
984
+ ProtocolDecl *proto) const {
990
985
// If it's not a derived requirement, it's not self-derived.
991
986
if (!isDerivedRequirement ()) return this ;
992
987
@@ -1053,15 +1048,6 @@ const RequirementSource *RequirementSource::getMinimalConformanceSource(
1053
1048
ArchetypeResolutionKind::WellFormed);
1054
1049
assert (parentEquivClass && " Not a well-formed type?" );
1055
1050
1056
- if (requirementSignatureSelfProto) {
1057
- if (parentEquivClass->concreteType )
1058
- derivedViaConcrete = true ;
1059
- else if (parentEquivClass->superclass &&
1060
- builder.lookupConformance (parentEquivClass->superclass ,
1061
- source->getProtocolDecl ()))
1062
- derivedViaConcrete = true ;
1063
- }
1064
-
1065
1051
// The parent potential archetype must conform to the protocol in which
1066
1052
// this requirement resides. Add this constraint.
1067
1053
if (auto startOfPath =
@@ -1130,7 +1116,7 @@ const RequirementSource *RequirementSource::getMinimalConformanceSource(
1130
1116
redundantSubpath->first ,
1131
1117
redundantSubpath->second );
1132
1118
return shorterSource
1133
- ->getMinimalConformanceSource (builder, currentType, proto, derivedViaConcrete );
1119
+ ->getMinimalConformanceSource (builder, currentType, proto);
1134
1120
}
1135
1121
1136
1122
// It's self-derived but we don't have a redundant subpath to eliminate.
@@ -2824,13 +2810,10 @@ static void concretizeNestedTypeFromConcreteParent(
2824
2810
const RequirementSource *parentConcreteSource = nullptr ;
2825
2811
2826
2812
for (const auto &constraint : parentEquiv->conformsTo .find (proto)->second ) {
2827
- bool derivedViaConcrete = false ;
2828
-
2829
2813
auto *minimal = constraint.source ->getMinimalConformanceSource (
2830
- builder, constraint.getSubjectDependentType ({ }), proto,
2831
- derivedViaConcrete);
2814
+ builder, constraint.getSubjectDependentType ({ }), proto);
2832
2815
2833
- if (minimal == nullptr || derivedViaConcrete )
2816
+ if (minimal == nullptr )
2834
2817
continue ;
2835
2818
2836
2819
if (!isSuperclassConstrained) {
@@ -5679,13 +5662,10 @@ static void expandSameTypeConstraints(GenericSignatureBuilder &builder,
5679
5662
bool alreadyFound = false ;
5680
5663
const RequirementSource *conformsSource = nullptr ;
5681
5664
for (const auto &constraint : conforms.second ) {
5682
- bool derivedViaConcrete = false ;
5683
-
5684
5665
auto *minimal = constraint.source ->getMinimalConformanceSource (
5685
- builder, constraint.getSubjectDependentType ({ }), proto,
5686
- derivedViaConcrete);
5666
+ builder, constraint.getSubjectDependentType ({ }), proto);
5687
5667
5688
- if (minimal == nullptr || derivedViaConcrete )
5668
+ if (minimal == nullptr )
5689
5669
continue ;
5690
5670
5691
5671
if (minimal->getAffectedType ()->isEqual (dependentType)) {
@@ -5910,18 +5890,14 @@ void GenericSignatureBuilder::computeRedundantRequirements(
5910
5890
requirementSignatureSelfProto,
5911
5891
[&](const Constraint<ProtocolDecl *> &constraint) {
5912
5892
// FIXME: Remove this.
5913
- bool derivedViaConcrete;
5914
5893
auto minimalSource =
5915
5894
constraint.source ->getMinimalConformanceSource (
5916
5895
*this ,
5917
5896
constraint.getSubjectDependentType ({ }),
5918
- proto, derivedViaConcrete );
5897
+ proto);
5919
5898
if (minimalSource != constraint.source )
5920
5899
return true ;
5921
5900
5922
- if (derivedViaConcrete)
5923
- return true ;
5924
-
5925
5901
return false ;
5926
5902
});
5927
5903
@@ -6495,27 +6471,21 @@ void GenericSignatureBuilder::processDelayedRequirements() {
6495
6471
6496
6472
namespace {
6497
6473
// / Remove self-derived sources from the given vector of constraints.
6498
- // /
6499
- // / \returns true if any derived-via-concrete constraints were found.
6500
6474
template <typename T>
6501
- bool removeSelfDerived (GenericSignatureBuilder &builder,
6475
+ void removeSelfDerived (GenericSignatureBuilder &builder,
6502
6476
std::vector<Constraint<T>> &constraints,
6503
6477
ProtocolDecl *proto,
6504
- bool dropDerivedViaConcrete = true ,
6505
6478
bool allCanBeSelfDerived = false ) {
6506
6479
auto genericParams = builder.getGenericParams ();
6507
- bool anyDerivedViaConcrete = false ;
6508
- Optional<Constraint<T>> remainingConcrete;
6509
6480
SmallVector<Constraint<T>, 4 > minimalSources;
6510
6481
constraints.erase (
6511
6482
std::remove_if (constraints.begin (), constraints.end (),
6512
6483
[&](const Constraint<T> &constraint) {
6513
- bool derivedViaConcrete;
6514
6484
auto minimalSource =
6515
6485
constraint.source ->getMinimalConformanceSource (
6516
6486
builder,
6517
6487
constraint.getSubjectDependentType (genericParams),
6518
- proto, derivedViaConcrete );
6488
+ proto);
6519
6489
if (minimalSource != constraint.source ) {
6520
6490
// The minimal source is smaller than the original source, so the
6521
6491
// original source is self-derived.
@@ -6532,21 +6502,8 @@ namespace {
6532
6502
return true ;
6533
6503
}
6534
6504
6535
- if (!derivedViaConcrete)
6536
- return false ;
6537
-
6538
- anyDerivedViaConcrete = true ;
6539
-
6540
- if (!dropDerivedViaConcrete)
6541
- return false ;
6542
-
6543
- // Drop derived-via-concrete requirements.
6544
- if (!remainingConcrete)
6545
- remainingConcrete = constraint;
6546
-
6547
- ++NumSelfDerived;
6548
- return true ;
6549
- }),
6505
+ return false ;
6506
+ }),
6550
6507
constraints.end ());
6551
6508
6552
6509
// If we found any minimal sources, add them now, avoiding introducing any
@@ -6566,13 +6523,8 @@ namespace {
6566
6523
}
6567
6524
}
6568
6525
6569
- // If we only had concrete conformances, put one back.
6570
- if (constraints.empty () && remainingConcrete)
6571
- constraints.push_back (*remainingConcrete);
6572
-
6573
6526
assert ((!constraints.empty () || allCanBeSelfDerived) &&
6574
6527
" All constraints were self-derived!" );
6575
- return anyDerivedViaConcrete;
6576
6528
}
6577
6529
} // end anonymous namespace
6578
6530
@@ -7135,9 +7087,7 @@ static void computeDerivedSameTypeComponents(
7135
7087
// construction of self-derived sources really don't work, because we
7136
7088
// discover more information later, so we need a more on-line or
7137
7089
// iterative approach.
7138
- bool derivedViaConcrete;
7139
- if (concrete.source ->isSelfDerivedSource (builder, subjectType,
7140
- derivedViaConcrete))
7090
+ if (concrete.source ->isSelfDerivedSource (builder, subjectType))
7141
7091
continue ;
7142
7092
7143
7093
// If it has a better source than we'd seen before for this component,
@@ -7471,13 +7421,10 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
7471
7421
if (!equivClass->derivedSameTypeComponents .empty ())
7472
7422
return ;
7473
7423
7474
- bool anyDerivedViaConcrete = false ;
7475
7424
// Remove self-derived constraints.
7476
- if (removeSelfDerived (*this , equivClass->sameTypeConstraints ,
7477
- /* proto=*/ nullptr ,
7478
- /* dropDerivedViaConcrete=*/ false ,
7479
- /* allCanBeSelfDerived=*/ true ))
7480
- anyDerivedViaConcrete = true ;
7425
+ removeSelfDerived (*this , equivClass->sameTypeConstraints ,
7426
+ /* proto=*/ nullptr ,
7427
+ /* allCanBeSelfDerived=*/ true );
7481
7428
7482
7429
// Sort the constraints, so we get a deterministic ordering of diagnostics.
7483
7430
llvm::array_pod_sort (equivClass->sameTypeConstraints .begin (),
@@ -7555,16 +7502,6 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
7555
7502
IntercomponentEdge (firstComponentIdx, secondComponentIdx, constraint));
7556
7503
}
7557
7504
7558
- // If there were any derived-via-concrete constraints, drop them now before
7559
- // we emit other diagnostics.
7560
- if (anyDerivedViaConcrete) {
7561
- // Remove derived-via-concrete constraints.
7562
- (void )removeSelfDerived (*this , equivClass->sameTypeConstraints ,
7563
- /* proto=*/ nullptr ,
7564
- /* dropDerivedViaConcrete=*/ true ,
7565
- /* allCanBeSelfDerived=*/ true );
7566
- }
7567
-
7568
7505
// Walk through each of the components, checking the intracomponent edges.
7569
7506
// This will diagnose any explicitly-specified requirements within a
7570
7507
// component, all of which are redundant.
@@ -7762,7 +7699,6 @@ void GenericSignatureBuilder::checkConcreteTypeConstraints(
7762
7699
7763
7700
removeSelfDerived (*this , equivClass->concreteTypeConstraints ,
7764
7701
/* proto=*/ nullptr ,
7765
- /* dropDerivedViaConcrete=*/ true ,
7766
7702
/* allCanBeSelfDerived=*/ true );
7767
7703
7768
7704
// This can occur if the combination of a superclass requirement and
0 commit comments