Skip to content

Commit 0663896

Browse files
committed
AST: ModuleDecl::lookupConformance() looks for conformances on Builtin.TheTupleType given a tuple type
1 parent 8f37ca4 commit 0663896

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

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

0 commit comments

Comments
 (0)