Skip to content

Commit 24fbd54

Browse files
authored
Merge pull request #69200 from slavapestov/more-assoc-conformance-cleanups
More associated conformance cleanups
2 parents ef5492d + 273baf5 commit 24fbd54

File tree

1 file changed

+10
-59
lines changed

1 file changed

+10
-59
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4763,21 +4763,6 @@ swift::checkTypeWitness(Type type, AssociatedTypeDecl *assocType,
47634763
KnownProtocolKind::Sendable))
47644764
.isInvalid())
47654765
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-
}
47814766
}
47824767

47834768
if (sig->requiresClass(depTy) &&
@@ -5196,10 +5181,8 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
51965181
return false;
51975182
});
51985183

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) {
52035186
auto conformance = Conformance->getAssociatedConformance(depTy, proto);
52045187
if (conformance.isConcrete()) {
52055188
auto *concrete = conformance.getConcrete();
@@ -5208,8 +5191,9 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
52085191
conformance, where,
52095192
depTy, replacementTy);
52105193
}
5211-
}
5212-
}
5194+
5195+
return false;
5196+
});
52135197
}
52145198

52155199
#pragma mark Protocol conformance checking
@@ -7070,51 +7054,18 @@ ValueWitnessRequest::evaluate(Evaluator &eval,
70707054
return known->second;
70717055
}
70727056

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-
71047057
ProtocolConformanceRef
71057058
AssociatedConformanceRequest::evaluate(Evaluator &eval,
71067059
NormalProtocolConformance *conformance,
71077060
CanType origTy, ProtocolDecl *reqProto,
71087061
unsigned index) const {
71097062
auto *module = conformance->getDeclContext()->getParentModule();
7110-
Type substTy;
71117063

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);
71187069

71197070
// Looking up a conformance for a contextual type and mapping the
71207071
// conformance context produces a more accurate result than looking

0 commit comments

Comments
 (0)