mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: ModuleDecl::lookupConformance() looks for conformances on Builtin.TheTupleType given a tuple type
This commit is contained in:
@@ -1139,9 +1139,45 @@ ProtocolConformanceRef ModuleDecl::lookupConformance(Type type,
|
||||
static ProtocolConformanceRef getBuiltinTupleTypeConformance(
|
||||
Type type, const TupleType *tupleType, ProtocolDecl *protocol,
|
||||
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.
|
||||
SmallVector<ProtocolConformance *, 2> conformances;
|
||||
if (tupleDecl->lookupConformance(protocol, conformances)) {
|
||||
// If we have multiple conformances, first try to filter out any that are
|
||||
// unavailable on the current deployment target.
|
||||
//
|
||||
// FIXME: Conformance lookup should really depend on source location for
|
||||
// this to be 100% correct.
|
||||
if (conformances.size() > 1) {
|
||||
SmallVector<ProtocolConformance *, 2> availableConformances;
|
||||
|
||||
for (auto *conformance : conformances) {
|
||||
if (conformance->getDeclContext()->isAlwaysAvailableConformanceContext())
|
||||
availableConformances.push_back(conformance);
|
||||
}
|
||||
|
||||
// Don't filter anything out if all conformances are unavailable.
|
||||
if (!availableConformances.empty())
|
||||
std::swap(availableConformances, conformances);
|
||||
}
|
||||
|
||||
auto *conformance = cast<NormalProtocolConformance>(conformances.front());
|
||||
auto subMap = type->getContextSubstitutionMap(module,
|
||||
conformance->getDeclContext());
|
||||
|
||||
// TODO: labels
|
||||
auto *specialized = ctx.getSpecializedConformance(type, conformance, subMap);
|
||||
return ProtocolConformanceRef(specialized);
|
||||
}
|
||||
|
||||
// Tuple type are Sendable when all of their element types are Sendable.
|
||||
if (protocol->isSpecificProtocol(KnownProtocolKind::Sendable)) {
|
||||
ASTContext &ctx = protocol->getASTContext();
|
||||
|
||||
// Create the pieces for a generic tuple type (T1, T2, ... TN) and a
|
||||
// generic signature <T1, T2, ..., TN>.
|
||||
|
||||
Reference in New Issue
Block a user