@@ -4763,21 +4763,6 @@ swift::checkTypeWitness(Type type, AssociatedTypeDecl *assocType,
4763
4763
KnownProtocolKind::Sendable))
4764
4764
.isInvalid ())
4765
4765
return CheckTypeWitnessResult::forConformance (reqProto);
4766
-
4767
- // FIXME: Why is conformsToProtocol() not enough? The stdlib doesn't
4768
- // build unless we fail here while inferring an associated type
4769
- // somewhere.
4770
- if (contextType->isSpecialized ()) {
4771
- auto *decl = contextType->getAnyNominal ();
4772
- auto subMap = contextType->getContextSubstitutionMap (
4773
- module ,
4774
- decl,
4775
- decl->getGenericEnvironmentOfContext ());
4776
- for (auto replacement : subMap.getReplacementTypes ()) {
4777
- if (replacement->hasError ())
4778
- return CheckTypeWitnessResult::forConformance (reqProto);
4779
- }
4780
- }
4781
4766
}
4782
4767
4783
4768
if (sig->requiresClass (depTy) &&
@@ -5196,10 +5181,8 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
5196
5181
return false ;
5197
5182
});
5198
5183
5199
- for (auto req : proto->getRequirementSignature ().getRequirements ()) {
5200
- if (req.getKind () == RequirementKind::Conformance) {
5201
- auto depTy = req.getFirstType ();
5202
- auto *proto = req.getProtocolDecl ();
5184
+ Conformance->forEachAssociatedConformance (
5185
+ [&](Type depTy, ProtocolDecl *proto, unsigned index) {
5203
5186
auto conformance = Conformance->getAssociatedConformance (depTy, proto);
5204
5187
if (conformance.isConcrete ()) {
5205
5188
auto *concrete = conformance.getConcrete ();
@@ -5208,8 +5191,9 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
5208
5191
conformance, where,
5209
5192
depTy, replacementTy);
5210
5193
}
5211
- }
5212
- }
5194
+
5195
+ return false ;
5196
+ });
5213
5197
}
5214
5198
5215
5199
#pragma mark Protocol conformance checking
@@ -7070,51 +7054,18 @@ ValueWitnessRequest::evaluate(Evaluator &eval,
7070
7054
return known->second ;
7071
7055
}
7072
7056
7073
- // / A stripped-down version of Type::subst that only works on the protocol
7074
- // / Self type wrapped in zero or more DependentMemberTypes.
7075
- static Type
7076
- recursivelySubstituteBaseType (ModuleDecl *module ,
7077
- NormalProtocolConformance *conformance,
7078
- DependentMemberType *depMemTy) {
7079
- Type origBase = depMemTy->getBase ();
7080
-
7081
- // Recursive case.
7082
- if (auto *depBase = origBase->getAs <DependentMemberType>()) {
7083
- Type substBase = recursivelySubstituteBaseType (
7084
- module , conformance, depBase);
7085
- return depMemTy->substBaseType (module , substBase);
7086
- }
7087
-
7088
- // Base case. The associated type's protocol should be either the
7089
- // conformance protocol or an inherited protocol.
7090
- auto *reqProto = depMemTy->getAssocType ()->getProtocol ();
7091
- assert (origBase->isEqual (reqProto->getSelfInterfaceType ()));
7092
-
7093
- ProtocolConformance *reqConformance = conformance;
7094
-
7095
- // If we have an inherited protocol just look up the conformance.
7096
- if (reqProto != conformance->getProtocol ()) {
7097
- reqConformance = module ->lookupConformance (conformance->getType (), reqProto)
7098
- .getConcrete ();
7099
- }
7100
-
7101
- return reqConformance->getTypeWitness (depMemTy->getAssocType ());
7102
- }
7103
-
7104
7057
ProtocolConformanceRef
7105
7058
AssociatedConformanceRequest::evaluate (Evaluator &eval,
7106
7059
NormalProtocolConformance *conformance,
7107
7060
CanType origTy, ProtocolDecl *reqProto,
7108
7061
unsigned index) const {
7109
7062
auto *module = conformance->getDeclContext ()->getParentModule ();
7110
- Type substTy;
7111
7063
7112
- if (origTy->isEqual (conformance->getProtocol ()->getSelfInterfaceType ())) {
7113
- substTy = conformance->getType ();
7114
- } else {
7115
- auto *depMemTy = origTy->castTo <DependentMemberType>();
7116
- substTy = recursivelySubstituteBaseType (module , conformance, depMemTy);
7117
- }
7064
+ auto subMap = SubstitutionMap::getProtocolSubstitutions (
7065
+ conformance->getProtocol (),
7066
+ conformance->getType (),
7067
+ ProtocolConformanceRef (conformance));
7068
+ auto substTy = origTy.subst (subMap);
7118
7069
7119
7070
// Looking up a conformance for a contextual type and mapping the
7120
7071
// conformance context produces a more accurate result than looking
0 commit comments