|
32 | 32 | #include "swift/AST/ModuleLoader.h"
|
33 | 33 | #include "swift/AST/NameLookup.h"
|
34 | 34 | #include "swift/AST/NameLookupRequests.h"
|
| 35 | +#include "swift/AST/PackConformance.h" |
35 | 36 | #include "swift/AST/ParseRequests.h"
|
36 | 37 | #include "swift/AST/PrettyStackTrace.h"
|
37 | 38 | #include "swift/AST/PrintOptions.h"
|
@@ -1259,6 +1260,33 @@ static ProtocolConformanceRef getBuiltinBuiltinTypeConformance(
|
1259 | 1260 | return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
|
1260 | 1261 | }
|
1261 | 1262 |
|
| 1263 | +static ProtocolConformanceRef getPackTypeConformance( |
| 1264 | + PackType *type, ProtocolDecl *protocol, ModuleDecl *mod) { |
| 1265 | + SmallVector<ProtocolConformanceRef, 2> patternConformances; |
| 1266 | + |
| 1267 | + for (auto packElement : type->getElementTypes()) { |
| 1268 | + if (auto *packExpansion = packElement->getAs<PackExpansionType>()) { |
| 1269 | + auto patternType = packExpansion->getPatternType(); |
| 1270 | + |
| 1271 | + auto patternConformance = |
| 1272 | + (patternType->isTypeParameter() |
| 1273 | + ? ProtocolConformanceRef(protocol) |
| 1274 | + : mod->lookupConformance(patternType, protocol)); |
| 1275 | + patternConformances.push_back(patternConformance); |
| 1276 | + continue; |
| 1277 | + } |
| 1278 | + |
| 1279 | + auto patternConformance = |
| 1280 | + (packElement->isTypeParameter() |
| 1281 | + ? ProtocolConformanceRef(protocol) |
| 1282 | + : mod->lookupConformance(packElement, protocol)); |
| 1283 | + patternConformances.push_back(patternConformance); |
| 1284 | + } |
| 1285 | + |
| 1286 | + return ProtocolConformanceRef( |
| 1287 | + PackConformance::get(type, protocol, patternConformances)); |
| 1288 | +} |
| 1289 | + |
1262 | 1290 | ProtocolConformanceRef
|
1263 | 1291 | LookupConformanceInModuleRequest::evaluate(
|
1264 | 1292 | Evaluator &evaluator, LookupConformanceDescriptor desc) const {
|
@@ -1322,6 +1350,11 @@ LookupConformanceInModuleRequest::evaluate(
|
1322 | 1350 | if (type->is<UnresolvedType>() || type->is<PlaceholderType>())
|
1323 | 1351 | return ProtocolConformanceRef(protocol);
|
1324 | 1352 |
|
| 1353 | + // Pack types can conform to protocols. |
| 1354 | + if (auto packType = type->getAs<PackType>()) { |
| 1355 | + return getPackTypeConformance(packType, protocol, mod); |
| 1356 | + } |
| 1357 | + |
1325 | 1358 | // Tuple types can conform to protocols.
|
1326 | 1359 | if (auto tupleType = type->getAs<TupleType>()) {
|
1327 | 1360 | return getBuiltinTupleTypeConformance(type, tupleType, protocol, mod);
|
|
0 commit comments