@@ -1137,9 +1137,45 @@ ProtocolConformanceRef ModuleDecl::lookupConformance(Type type,
1137
1137
static ProtocolConformanceRef getBuiltinTupleTypeConformance (
1138
1138
Type type, const TupleType *tupleType, ProtocolDecl *protocol,
1139
1139
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
+
1140
1177
// Tuple type are Sendable when all of their element types are Sendable.
1141
1178
if (protocol->isSpecificProtocol (KnownProtocolKind::Sendable)) {
1142
- ASTContext &ctx = protocol->getASTContext ();
1143
1179
1144
1180
// Create the pieces for a generic tuple type (T1, T2, ... TN) and a
1145
1181
// generic signature <T1, T2, ..., TN>.
0 commit comments