31
31
#include " swift/AST/TypeRepr.h"
32
32
#include " swift/Basic/Debug.h"
33
33
#include " swift/Basic/LLVM.h"
34
+ #include " llvm/ADT/DenseSet.h"
34
35
#include " llvm/ADT/FoldingSet.h"
35
36
#include " llvm/ADT/ilist.h"
36
37
#include " llvm/ADT/PointerUnion.h"
@@ -654,11 +655,44 @@ class GenericSignatureBuilder {
654
655
bool isRedundantExplicitRequirement (const ExplicitRequirement &req) const ;
655
656
656
657
private:
657
- void computeRedundantRequirements (const ProtocolDecl *requirementSignatureSelfProto);
658
+ using GetKindAndRHS = llvm::function_ref<std::pair<RequirementKind, RequirementRHS>()>;
659
+ void getBaseRequirements (
660
+ GetKindAndRHS getKindAndRHS,
661
+ const RequirementSource *source,
662
+ const ProtocolDecl *requirementSignatureSelfProto,
663
+ SmallVectorImpl<ExplicitRequirement> &result);
664
+
665
+ // / Determine if an explicit requirement can be derived from the
666
+ // / requirement given by \p otherSource and \p otherRHS, using the
667
+ // / knowledge of any existing redundant requirements discovered so far.
668
+ Optional<ExplicitRequirement>
669
+ isValidRequirementDerivationPath (
670
+ llvm::SmallDenseSet<ExplicitRequirement, 4 > &visited,
671
+ RequirementKind otherKind,
672
+ const RequirementSource *otherSource,
673
+ RequirementRHS otherRHS,
674
+ const ProtocolDecl *requirementSignatureSelfProto);
675
+
676
+ // / Determine if the explicit requirement \p req can be derived from any
677
+ // / of the constraints in \p constraints, using the knowledge of any
678
+ // / existing redundant requirements discovered so far.
679
+ // /
680
+ // / Use \p filter to screen out less-specific and conflicting constraints
681
+ // / if the requirement is a superclass, concrete type or layout requirement.
682
+ template <typename T, typename Filter>
683
+ void checkIfRequirementCanBeDerived (
684
+ const ExplicitRequirement &req,
685
+ const std::vector<Constraint<T>> &constraints,
686
+ const ProtocolDecl *requirementSignatureSelfProto,
687
+ Filter filter);
688
+
689
+ void computeRedundantRequirements (
690
+ const ProtocolDecl *requirementSignatureSelfProto);
658
691
659
692
void diagnoseRedundantRequirements () const ;
660
693
661
- void diagnoseConflictingConcreteTypeRequirements () const ;
694
+ void diagnoseConflictingConcreteTypeRequirements (
695
+ const ProtocolDecl *requirementSignatureSelfProto);
662
696
663
697
// / Describes the relationship between a given constraint and
664
698
// / the canonical constraint of the equivalence class.
@@ -707,23 +741,6 @@ class GenericSignatureBuilder {
707
741
TypeArrayView<GenericTypeParamType> genericParams,
708
742
EquivalenceClass *equivClass);
709
743
710
- // / Check the superclass constraints within the equivalence
711
- // / class of the given potential archetype.
712
- void checkSuperclassConstraints (
713
- TypeArrayView<GenericTypeParamType> genericParams,
714
- EquivalenceClass *equivClass);
715
-
716
- // / Check conformance constraints within the equivalence class of the
717
- // / given potential archetype.
718
- void checkConformanceConstraints (
719
- TypeArrayView<GenericTypeParamType> genericParams,
720
- EquivalenceClass *equivClass);
721
-
722
- // / Check layout constraints within the equivalence class of the given
723
- // / potential archetype.
724
- void checkLayoutConstraints (TypeArrayView<GenericTypeParamType> genericParams,
725
- EquivalenceClass *equivClass);
726
-
727
744
// / Check same-type constraints within the equivalence class of the
728
745
// / given potential archetype.
729
746
void checkSameTypeConstraints (
@@ -1242,8 +1259,7 @@ class GenericSignatureBuilder::RequirementSource final
1242
1259
// / requirement redundant, because without said original requirement, the
1243
1260
// / derived requirement ceases to hold.
1244
1261
bool isSelfDerivedSource (GenericSignatureBuilder &builder,
1245
- Type type,
1246
- bool &derivedViaConcrete) const ;
1262
+ Type type) const ;
1247
1263
1248
1264
// / For a requirement source that describes the requirement \c type:proto,
1249
1265
// / retrieve the minimal subpath of this requirement source that will
@@ -1255,8 +1271,7 @@ class GenericSignatureBuilder::RequirementSource final
1255
1271
const RequirementSource *getMinimalConformanceSource (
1256
1272
GenericSignatureBuilder &builder,
1257
1273
Type type,
1258
- ProtocolDecl *proto,
1259
- bool &derivedViaConcrete) const ;
1274
+ ProtocolDecl *proto) const ;
1260
1275
1261
1276
// / Retrieve a source location that corresponds to the requirement.
1262
1277
SourceLoc getLoc () const ;
0 commit comments