Skip to content

Commit 60e2fcb

Browse files
committed
AST: ModuleDecl::lookupConformance() looks for conformances on Builtin.TheTupleType given a tuple type
1 parent 70b553b commit 60e2fcb

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

lib/AST/Module.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,9 +1139,45 @@ ProtocolConformanceRef ModuleDecl::lookupConformance(Type type,
11391139
static ProtocolConformanceRef getBuiltinTupleTypeConformance(
11401140
Type type, const TupleType *tupleType, ProtocolDecl *protocol,
11411141
ModuleDecl *module) {
1142+
ASTContext &ctx = protocol->getASTContext();
1143+
1144+
// This is the new code path.
1145+
//
1146+
// FIXME: Remove the Sendable stuff below.
1147+
auto *tupleDecl = ctx.getBuiltinTupleDecl();
1148+
1149+
// Find the (unspecialized) conformance.
1150+
SmallVector<ProtocolConformance *, 2> conformances;
1151+
if (tupleDecl->lookupConformance(protocol, conformances)) {
1152+
// If we have multiple conformances, first try to filter out any that are
1153+
// unavailable on the current deployment target.
1154+
//
1155+
// FIXME: Conformance lookup should really depend on source location for
1156+
// this to be 100% correct.
1157+
if (conformances.size() > 1) {
1158+
SmallVector<ProtocolConformance *, 2> availableConformances;
1159+
1160+
for (auto *conformance : conformances) {
1161+
if (conformance->getDeclContext()->isAlwaysAvailableConformanceContext())
1162+
availableConformances.push_back(conformance);
1163+
}
1164+
1165+
// Don't filter anything out if all conformances are unavailable.
1166+
if (!availableConformances.empty())
1167+
std::swap(availableConformances, conformances);
1168+
}
1169+
1170+
auto *conformance = cast<NormalProtocolConformance>(conformances.front());
1171+
auto subMap = type->getContextSubstitutionMap(module,
1172+
conformance->getDeclContext());
1173+
1174+
// TODO: labels
1175+
auto *specialized = ctx.getSpecializedConformance(type, conformance, subMap);
1176+
return ProtocolConformanceRef(specialized);
1177+
}
1178+
11421179
// Tuple type are Sendable when all of their element types are Sendable.
11431180
if (protocol->isSpecificProtocol(KnownProtocolKind::Sendable)) {
1144-
ASTContext &ctx = protocol->getASTContext();
11451181

11461182
// Create the pieces for a generic tuple type (T1, T2, ... TN) and a
11471183
// generic signature <T1, T2, ..., TN>.

0 commit comments

Comments
 (0)