@@ -1351,114 +1351,6 @@ Type ExtensionDecl::getExtendedType() const {
1351
1351
return ErrorType::get (ctx);
1352
1352
}
1353
1353
1354
- // / Clone the given generic parameters in the given list. We don't need any
1355
- // / of the requirements, because they will be inferred.
1356
- static GenericParamList *cloneGenericParams (ASTContext &ctx,
1357
- ExtensionDecl *ext,
1358
- GenericParamList *fromParams) {
1359
- // Clone generic parameters.
1360
- SmallVector<GenericTypeParamDecl *, 2 > toGenericParams;
1361
- for (auto fromGP : *fromParams) {
1362
- // Create the new generic parameter.
1363
- auto toGP = new (ctx) GenericTypeParamDecl (ext, fromGP->getName (),
1364
- SourceLoc (),
1365
- fromGP->getDepth (),
1366
- fromGP->getIndex ());
1367
- toGP->setImplicit (true );
1368
-
1369
- // Record new generic parameter.
1370
- toGenericParams.push_back (toGP);
1371
- }
1372
-
1373
- return GenericParamList::create (ctx, SourceLoc (), toGenericParams,
1374
- SourceLoc ());
1375
- }
1376
-
1377
- static GenericParamList *
1378
- createExtensionGenericParams (ASTContext &ctx,
1379
- ExtensionDecl *ext,
1380
- NominalTypeDecl *nominal) {
1381
- // Collect generic parameters from all outer contexts.
1382
- SmallVector<GenericParamList *, 2 > allGenericParams;
1383
- nominal->forEachGenericContext ([&](GenericParamList *gpList) {
1384
- allGenericParams.push_back (
1385
- cloneGenericParams (ctx, ext, gpList));
1386
- });
1387
-
1388
- GenericParamList *toParams = nullptr ;
1389
- for (auto *gpList : llvm::reverse (allGenericParams)) {
1390
- gpList->setOuterParameters (toParams);
1391
- toParams = gpList;
1392
- }
1393
-
1394
- return toParams;
1395
- }
1396
-
1397
- GenericParamList *
1398
- GenericParamListRequest::evaluate (Evaluator &evaluator, GenericContext *value) const {
1399
- if (auto *ext = dyn_cast<ExtensionDecl>(value)) {
1400
- // Create the generic parameter list for the extension by cloning the
1401
- // generic parameter lists of the nominal and any of its parent types.
1402
- auto &ctx = value->getASTContext ();
1403
- auto *nominal = ext->getExtendedNominal ();
1404
- if (!nominal) {
1405
- return nullptr ;
1406
- }
1407
- auto *genericParams = createExtensionGenericParams (ctx, ext, nominal);
1408
-
1409
- // Protocol extensions need an inheritance clause due to how name lookup
1410
- // is implemented.
1411
- if (auto *proto = ext->getExtendedProtocolDecl ()) {
1412
- auto protoType = proto->getDeclaredType ();
1413
- TypeLoc selfInherited[1 ] = { TypeLoc::withoutLoc (protoType) };
1414
- genericParams->getParams ().front ()->setInherited (
1415
- ctx.AllocateCopy (selfInherited));
1416
- }
1417
-
1418
- // Set the depth of every generic parameter.
1419
- unsigned depth = nominal->getGenericContextDepth ();
1420
- for (auto *outerParams = genericParams;
1421
- outerParams != nullptr ;
1422
- outerParams = outerParams->getOuterParameters ())
1423
- outerParams->setDepth (depth--);
1424
-
1425
- // If we have a trailing where clause, deal with it now.
1426
- // For now, trailing where clauses are only permitted on protocol extensions.
1427
- if (auto trailingWhereClause = ext->getTrailingWhereClause ()) {
1428
- if (genericParams) {
1429
- // Merge the trailing where clause into the generic parameter list.
1430
- // FIXME: Long-term, we'd like clients to deal with the trailing where
1431
- // clause explicitly, but for now it's far more direct to represent
1432
- // the trailing where clause as part of the requirements.
1433
- genericParams->addTrailingWhereClause (
1434
- ext->getASTContext (),
1435
- trailingWhereClause->getWhereLoc (),
1436
- trailingWhereClause->getRequirements ());
1437
- }
1438
-
1439
- // If there's no generic parameter list, the where clause is diagnosed
1440
- // in typeCheckDecl().
1441
- }
1442
- return genericParams;
1443
- } else if (auto *proto = dyn_cast<ProtocolDecl>(value)) {
1444
- // The generic parameter 'Self'.
1445
- auto &ctx = value->getASTContext ();
1446
- auto selfId = ctx.Id_Self ;
1447
- auto selfDecl = new (ctx) GenericTypeParamDecl (
1448
- proto, selfId, SourceLoc (), /* depth=*/ 0 , /* index=*/ 0 );
1449
- auto protoType = proto->getDeclaredType ();
1450
- TypeLoc selfInherited[1 ] = { TypeLoc::withoutLoc (protoType) };
1451
- selfDecl->setInherited (ctx.AllocateCopy (selfInherited));
1452
- selfDecl->setImplicit ();
1453
-
1454
- // The generic parameter list itself.
1455
- auto result = GenericParamList::create (ctx, SourceLoc (), selfDecl,
1456
- SourceLoc ());
1457
- return result;
1458
- }
1459
- return nullptr ;
1460
- }
1461
-
1462
1354
PatternBindingDecl::PatternBindingDecl (SourceLoc StaticLoc,
1463
1355
StaticSpellingKind StaticSpelling,
1464
1356
SourceLoc VarLoc,
0 commit comments