Skip to content

Commit 2dfb7dc

Browse files
committed
Sema: Use getOverrideGenericSignature() in computeDesignatedInitOverrideSignature()
1 parent cb05ea6 commit 2dfb7dc

File tree

1 file changed

+6
-72
lines changed

1 file changed

+6
-72
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -434,18 +434,8 @@ computeDesignatedInitOverrideSignature(ASTContext &ctx,
434434
ClassDecl *classDecl,
435435
Type superclassTy,
436436
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;
445437
auto *genericParams = superclassCtor->getGenericParams();
446438

447-
SmallVector<GenericTypeParamType *, 1> newParamTypes;
448-
449439
// If genericParams is non-null, the base class initializer has its own
450440
// generic parameters. Otherwise, it is non-generic with a contextual
451441
// 'where' clause.
@@ -454,8 +444,8 @@ computeDesignatedInitOverrideSignature(ASTContext &ctx,
454444
// but change the depth of the generic parameters to be one greater
455445
// than the depth of the subclass.
456446
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;
459449

460450
SmallVector<GenericTypeParamDecl *, 4> newParams;
461451
for (auto *param : genericParams->getParams()) {
@@ -474,71 +464,15 @@ computeDesignatedInitOverrideSignature(ASTContext &ctx,
474464
SourceLoc(),
475465
ArrayRef<RequirementRepr>(),
476466
SourceLoc());
477-
478-
// Add the generic parameter types.
479-
for (auto *newParam : newParams) {
480-
newParamTypes.push_back(
481-
newParam->getDeclaredInterfaceType()->castTo<GenericTypeParamType>());
482-
}
483467
}
484468

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();
537471

538-
// Now form the substitution map that will be used to remap parameter
539-
// types.
540472
auto subMap = SubstitutionMap::getOverrideSubstitutions(
541473
superclassDecl, classDecl, superclassCtorSig, genericParams);
474+
auto genericSig = ctx.getOverrideGenericSignature(
475+
superclassDecl, classDecl, superclassCtorSig, genericParams);
542476

543477
return DesignatedInitOverrideInfo{genericSig, genericParams, subMap};
544478
}

0 commit comments

Comments
 (0)