@@ -434,18 +434,8 @@ computeDesignatedInitOverrideSignature(ASTContext &ctx,
434
434
ClassDecl *classDecl,
435
435
Type superclassTy,
436
436
ConstructorDecl *superclassCtor) {
437
- auto *superclassDecl = superclassTy->getClassOrBoundGenericClass ();
438
-
439
- auto classSig = classDecl->getGenericSignature ();
440
- auto superclassCtorSig = superclassCtor->getGenericSignature ();
441
- auto superclassSig = superclassDecl->getGenericSignature ();
442
-
443
- // These are our outputs.
444
- GenericSignature genericSig = classSig;
445
437
auto *genericParams = superclassCtor->getGenericParams ();
446
438
447
- SmallVector<GenericTypeParamType *, 1 > newParamTypes;
448
-
449
439
// If genericParams is non-null, the base class initializer has its own
450
440
// generic parameters. Otherwise, it is non-generic with a contextual
451
441
// 'where' clause.
@@ -454,8 +444,8 @@ computeDesignatedInitOverrideSignature(ASTContext &ctx,
454
444
// but change the depth of the generic parameters to be one greater
455
445
// than the depth of the subclass.
456
446
unsigned depth = 0 ;
457
- if (auto genericSig = classDecl->getGenericSignature ())
458
- depth = genericSig .getGenericParams ().back ()->getDepth () + 1 ;
447
+ if (auto classSig = classDecl->getGenericSignature ())
448
+ depth = classSig .getGenericParams ().back ()->getDepth () + 1 ;
459
449
460
450
SmallVector<GenericTypeParamDecl *, 4 > newParams;
461
451
for (auto *param : genericParams->getParams ()) {
@@ -474,71 +464,15 @@ computeDesignatedInitOverrideSignature(ASTContext &ctx,
474
464
SourceLoc (),
475
465
ArrayRef<RequirementRepr>(),
476
466
SourceLoc ());
477
-
478
- // Add the generic parameter types.
479
- for (auto *newParam : newParams) {
480
- newParamTypes.push_back (
481
- newParam->getDeclaredInterfaceType ()->castTo <GenericTypeParamType>());
482
- }
483
467
}
484
468
485
- auto baseSubMap = superclassTy->getContextSubstitutionMap (
486
- classDecl->getParentModule (), superclassDecl);
487
-
488
- // The depth at which the initializer's own generic parameters start, if any.
489
- unsigned superclassDepth = 0 ;
490
- if (superclassSig)
491
- superclassDepth = superclassSig.getGenericParams ().back ()->getDepth () + 1 ;
492
-
493
- // We're going to be substituting the requirements of the base class
494
- // initializer to form the requirements of the derived class initializer.
495
- auto substFn = [&](SubstitutableType *type) -> Type {
496
- auto *gp = cast<GenericTypeParamType>(type);
497
- // Generic parameters of the base class itself are mapped via the
498
- // substitution map of the superclass type.
499
- if (gp->getDepth () < superclassDepth)
500
- return Type (gp).subst (baseSubMap);
501
-
502
- // Generic parameters added by the base class initializer map to the new
503
- // generic parameters of the derived initializer.
504
- return genericParams->getParams ()[gp->getIndex ()]
505
- ->getDeclaredInterfaceType ();
506
- };
507
-
508
- auto lookupConformanceFn =
509
- [&](CanType depTy, Type substTy,
510
- ProtocolDecl *proto) -> ProtocolConformanceRef {
511
- if (depTy->getRootGenericParam ()->getDepth () < superclassDepth)
512
- if (auto conf = baseSubMap.lookupConformance (depTy, proto))
513
- return conf;
514
-
515
- return ProtocolConformanceRef (proto);
516
- };
517
-
518
- SmallVector<Requirement, 2 > requirements;
519
-
520
- // If the base initializer's generic signature is different
521
- // from that of the base class, the base class initializer either
522
- // has generic parameters or a 'where' clause.
523
- //
524
- // We need to "rebase" the requirements on top of the derived class's
525
- // generic signature.
526
- if (superclassSig.getPointer () != superclassCtorSig.getPointer () &&
527
- (classSig || newParamTypes.size () != 0 )) {
528
- for (auto reqt : superclassCtorSig.getRequirements ()) {
529
- if (auto substReqt = reqt.subst (substFn, lookupConformanceFn))
530
- requirements.push_back (*substReqt);
531
- }
532
-
533
- genericSig = buildGenericSignature (ctx, classSig,
534
- std::move (newParamTypes),
535
- std::move (requirements));
536
- }
469
+ auto *superclassDecl = superclassTy->getClassOrBoundGenericClass ();
470
+ auto superclassCtorSig = superclassCtor->getGenericSignature ();
537
471
538
- // Now form the substitution map that will be used to remap parameter
539
- // types.
540
472
auto subMap = SubstitutionMap::getOverrideSubstitutions (
541
473
superclassDecl, classDecl, superclassCtorSig, genericParams);
474
+ auto genericSig = ctx.getOverrideGenericSignature (
475
+ superclassDecl, classDecl, superclassCtorSig, genericParams);
542
476
543
477
return DesignatedInitOverrideInfo{genericSig, genericParams, subMap};
544
478
}
0 commit comments