Skip to content

Commit 3f0e702

Browse files
authored
Merge pull request #13567 from DougGregor/assoc-type-infer-conditional-defaults
2 parents 1e8445f + 5494a1f commit 3f0e702

File tree

7 files changed

+366
-68
lines changed

7 files changed

+366
-68
lines changed

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,13 @@ RequirementCheckResult TypeChecker::checkGenericArguments(
13071307
secondType = req.getSecondType();
13081308
}
13091309

1310+
// Don't do further checking on error types.
1311+
if (firstType->hasError() || (secondType && secondType->hasError())) {
1312+
// Another requirement will fail later; just continue.
1313+
valid = false;
1314+
continue;
1315+
}
1316+
13101317
bool requirementFailure = false;
13111318
if (listener && !listener->shouldCheck(kind, firstType, secondType))
13121319
continue;

lib/Sema/TypeCheckProtocol.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ struct InferredTypeWitnessesSolution {
139139
#ifndef NDEBUG
140140
LLVM_ATTRIBUTE_USED
141141
#endif
142-
void dump();
142+
void dump() const;
143143
};
144144

145145
class RequirementEnvironment;
@@ -707,6 +707,12 @@ class AssociatedTypeInference {
707707
const llvm::SetVector<AssociatedTypeDecl *> &allUnresolved,
708708
ValueDecl *req);
709709

710+
/// Infer associated type witnesses for the given associated type.
711+
InferredAssociatedTypesByWitnesses inferTypeWitnessesViaAssociatedType(
712+
ConformanceChecker &checker,
713+
const llvm::SetVector<AssociatedTypeDecl *> &allUnresolved,
714+
AssociatedTypeDecl *assocType);
715+
710716
/// Infer associated type witnesses for all relevant value requirements.
711717
///
712718
/// \param assocTypes The set of associated types we're interested in.
@@ -728,12 +734,30 @@ class AssociatedTypeInference {
728734
/// known to the compiler.
729735
Type computeDerivedTypeWitness(AssociatedTypeDecl *assocType);
730736

737+
/// Compute a type witness without using a specific potential witness,
738+
/// e.g., using a fixed type (from a refined protocol), default type
739+
/// on an associated type, or deriving the type.
740+
///
741+
/// \param allowDerived Whether to allow "derived" type witnesses.
742+
Type computeAbstractTypeWitness(AssociatedTypeDecl *assocType,
743+
bool allowDerived);
744+
731745
/// Substitute the current type witnesses into the given interface type.
732746
Type substCurrentTypeWitnesses(Type type);
733747

748+
/// Retrieve substitution options with a tentative type witness
749+
/// operation that queries the current set of type witnesses.
750+
SubstOptions getSubstOptionsWithCurrentTypeWitnesses();
751+
734752
/// Check whether the current set of type witnesses meets the
735753
/// requirements of the protocol.
736-
bool checkCurrentTypeWitnesses();
754+
bool checkCurrentTypeWitnesses(
755+
const SmallVectorImpl<std::pair<ValueDecl *, ValueDecl *>>
756+
&valueWitnesses);
757+
758+
/// Check the current type witnesses against the
759+
/// requirements of the given constrained extension.
760+
bool checkConstrainedExtension(ExtensionDecl *ext);
737761

738762
/// Top-level operation to find solutions for the given unresolved
739763
/// associated types.

0 commit comments

Comments
 (0)