AST: Remove old tuple conformance logic from getBuiltinTupleTypeConformance()

This commit is contained in:
Slava Pestov
2023-08-09 16:34:07 -04:00
parent 10359ea839
commit 9f51ea1de6

View File

@@ -1713,9 +1713,6 @@ static ProtocolConformanceRef getBuiltinTupleTypeConformance(
ModuleDecl *module) {
ASTContext &ctx = protocol->getASTContext();
// This is the new code path.
//
// FIXME: Remove the Sendable stuff below.
auto *tupleDecl = ctx.getBuiltinTupleDecl();
// Find the (unspecialized) conformance.
@@ -1748,62 +1745,6 @@ static ProtocolConformanceRef getBuiltinTupleTypeConformance(
return ProtocolConformanceRef(specialized);
}
/// For some known protocols (KPs) like Sendable and Copyable, a tuple type
/// conforms to the protocol KP when all of their element types conform to KP.
if (protocol->isSpecificProtocol(KnownProtocolKind::Sendable) ||
protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
// Create the pieces for a generic tuple type (T1, T2, ... TN) and a
// generic signature <T1, T2, ..., TN>.
SmallVector<GenericTypeParamType *, 4> genericParams;
SmallVector<Type, 4> typeSubstitutions;
SmallVector<TupleTypeElt, 4> genericElements;
SmallVector<Requirement, 4> conditionalRequirements;
for (const auto &elt : tupleType->getElements()) {
auto genericParam = GenericTypeParamType::get(/*isParameterPack*/ false, 0,
genericParams.size(), ctx);
genericParams.push_back(genericParam);
typeSubstitutions.push_back(elt.getType());
genericElements.push_back(elt.getWithType(genericParam));
conditionalRequirements.push_back(
Requirement(RequirementKind::Conformance, genericParam,
protocol->getDeclaredType()));
}
// If there were no generic parameters, just form the builtin conformance.
if (genericParams.empty()) {
return ProtocolConformanceRef(
ctx.getBuiltinConformance(type, protocol, GenericSignature(), { },
BuiltinConformanceKind::Synthesized));
}
// Form a generic conformance of (T1, T2, ..., TN): KP with signature
// <T1, T2, ..., TN> and conditional requirements T1: KP,
// T2: P, ..., TN: KP.
auto genericTupleType = TupleType::get(genericElements, ctx);
auto genericSig = GenericSignature::get(
genericParams, conditionalRequirements);
auto genericConformance = ctx.getBuiltinConformance(
genericTupleType, protocol, genericSig, conditionalRequirements,
BuiltinConformanceKind::Synthesized);
// Compute the substitution map from the generic parameters of the
// generic conformance to actual types that were in the tuple type.
// Form a specialized conformance from that.
auto subMap = SubstitutionMap::get(
genericSig, [&](SubstitutableType *type) {
if (auto gp = dyn_cast<GenericTypeParamType>(type)) {
if (gp->getDepth() == 0)
return typeSubstitutions[gp->getIndex()];
}
return Type(type);
},
LookUpConformanceInModule(module));
return ProtocolConformanceRef(
ctx.getSpecializedConformance(type, genericConformance, subMap));
}
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
}