Skip to content

Commit 4538b1b

Browse files
committed
AST: Remove derivedSubs parameter from getOverrideSubstitutions()
We can apply a substitution map afterwards if needed.
1 parent 2686ce3 commit 4538b1b

File tree

8 files changed

+17
-33
lines changed

8 files changed

+17
-33
lines changed

include/swift/AST/SubstitutionMap.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,15 @@ class SubstitutionMap {
199199
/// written in terms of the generic signature of 'baseDecl'.
200200
static SubstitutionMap
201201
getOverrideSubstitutions(const ValueDecl *baseDecl,
202-
const ValueDecl *derivedDecl,
203-
Optional<SubstitutionMap> derivedSubs);
202+
const ValueDecl *derivedDecl);
204203

205204
/// Variant of the above for when we have the generic signatures but not
206205
/// the decls for 'derived' and 'base'.
207206
static SubstitutionMap
208207
getOverrideSubstitutions(const ClassDecl *baseClass,
209208
const ClassDecl *derivedClass,
210209
GenericSignature baseSig,
211-
GenericSignature derivedSig,
212-
Optional<SubstitutionMap> derivedSubs);
210+
GenericSignature derivedSig);
213211

214212
/// Combine two substitution maps as follows.
215213
///

lib/AST/ConcreteDeclRef.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ ConcreteDeclRef ConcreteDeclRef::getOverriddenDecl() const {
3636

3737
SubstitutionMap subs;
3838
if (baseSig) {
39-
Optional<SubstitutionMap> derivedSubMap;
39+
subs = SubstitutionMap::getOverrideSubstitutions(baseDecl, derivedDecl);
4040
if (derivedSig)
41-
derivedSubMap = getSubstitutions();
42-
subs = SubstitutionMap::getOverrideSubstitutions(baseDecl, derivedDecl,
43-
derivedSubMap);
41+
subs = subs.subst(getSubstitutions());
4442
}
4543
return ConcreteDeclRef(baseDecl, subs);
4644
}

lib/AST/SubstitutionMap.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,7 @@ SubstitutionMap::getProtocolSubstitutions(ProtocolDecl *protocol,
497497
SubstitutionMap
498498
SubstitutionMap::getOverrideSubstitutions(
499499
const ValueDecl *baseDecl,
500-
const ValueDecl *derivedDecl,
501-
Optional<SubstitutionMap> derivedSubs) {
500+
const ValueDecl *derivedDecl) {
502501
// For overrides within a protocol hierarchy, substitute the Self type.
503502
if (auto baseProto = baseDecl->getDeclContext()->getSelfProtocolDecl()) {
504503
auto baseSig = baseDecl->getInnermostDeclContext()
@@ -515,44 +514,33 @@ SubstitutionMap::getOverrideSubstitutions(
515514
->getGenericSignatureOfContext();
516515

517516
return getOverrideSubstitutions(baseClass, derivedClass,
518-
baseSig, derivedSig,
519-
derivedSubs);
517+
baseSig, derivedSig);
520518
}
521519

522520
SubstitutionMap
523521
SubstitutionMap::getOverrideSubstitutions(const ClassDecl *baseClass,
524522
const ClassDecl *derivedClass,
525523
GenericSignature baseSig,
526-
GenericSignature derivedSig,
527-
Optional<SubstitutionMap> derivedSubs) {
524+
GenericSignature derivedSig) {
528525
if (baseSig.isNull())
529526
return SubstitutionMap();
530527

531-
auto *M = baseClass->getParentModule();
532-
533528
unsigned baseDepth = 0;
534529
SubstitutionMap baseSubMap;
535530
if (auto baseClassSig = baseClass->getGenericSignature()) {
536531
baseDepth = baseClassSig.getGenericParams().back()->getDepth() + 1;
537532

538533
auto derivedClassTy = derivedClass->getDeclaredInterfaceType();
539-
if (derivedSubs)
540-
derivedClassTy = derivedClassTy.subst(*derivedSubs);
541-
auto baseClassTy = derivedClassTy->getSuperclassForDecl(baseClass);
542-
if (baseClassTy->is<ErrorType>())
543-
return SubstitutionMap();
544-
545-
baseSubMap = baseClassTy->getContextSubstitutionMap(M, baseClass);
534+
baseSubMap = derivedClassTy->getContextSubstitutionMap(
535+
baseClass->getParentModule(), baseClass);
546536
}
547537

548538
unsigned origDepth = 0;
549539
if (auto derivedClassSig = derivedClass->getGenericSignature())
550540
origDepth = derivedClassSig.getGenericParams().back()->getDepth() + 1;
551541

552542
SubstitutionMap origSubMap;
553-
if (derivedSubs)
554-
origSubMap = *derivedSubs;
555-
else if (derivedSig)
543+
if (derivedSig)
556544
origSubMap = derivedSig->getIdentitySubstitutionMap();
557545

558546
return combineSubstitutionMaps(baseSubMap, origSubMap,

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4989,7 +4989,7 @@ Type TypeBase::adjustSuperclassMemberDeclType(const ValueDecl *baseDecl,
49894989
const ValueDecl *derivedDecl,
49904990
Type memberType) {
49914991
auto subs = SubstitutionMap::getOverrideSubstitutions(
4992-
baseDecl, derivedDecl, /*derivedSubs=*/None);
4992+
baseDecl, derivedDecl);
49934993

49944994
if (auto *genericMemberType = memberType->getAs<GenericFunctionType>()) {
49954995
memberType = FunctionType::get(genericMemberType->getParams(),

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3665,8 +3665,8 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
36653665
// to reference the overridden declaration instead.
36663666
if (baseDecl != externalDecl) {
36673667
externalSubs = SubstitutionMap::getOverrideSubstitutions(baseDecl,
3668-
externalDecl,
3669-
externalSubs);
3668+
externalDecl)
3669+
.subst(externalSubs);
36703670
externalDecl = baseDecl;
36713671
}
36723672
}

lib/SILGen/SILGenPoly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4224,7 +4224,7 @@ SILGenFunction::emitVTableThunk(SILDeclRef base,
42244224
SILType::getPrimitiveObjectType(derivedFTy),
42254225
subs, args, derivedYields);
42264226
auto overrideSubs = SubstitutionMap::getOverrideSubstitutions(
4227-
base.getDecl(), derived.getDecl(), /*derivedSubs=*/subs);
4227+
base.getDecl(), derived.getDecl()).subst(subs);
42284228

42294229
YieldInfo derivedYieldInfo(SGM, derived, derivedFTy, subs);
42304230
YieldInfo baseYieldInfo(SGM, base, thunkTy, overrideSubs);

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,8 @@ synthesizeDesignatedInitOverride(AbstractFunctionDecl *fn, void *context) {
639639
SubstitutionMap subs;
640640
if (auto *genericEnv = fn->getGenericEnvironment())
641641
subs = genericEnv->getForwardingSubstitutionMap();
642-
subs = SubstitutionMap::getOverrideSubstitutions(superclassCtor, fn, subs);
642+
subs = SubstitutionMap::getOverrideSubstitutions(superclassCtor, fn)
643+
.subst(subs);
643644
ConcreteDeclRef ctorRef(superclassCtor, subs);
644645

645646
auto type = superclassCtor->getInitializerInterfaceType().subst(subs);

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,7 @@ static bool parameterTypesMatch(const ValueDecl *derivedDecl,
620620
if (baseParams->size() != derivedParams->size())
621621
return false;
622622

623-
auto subs = SubstitutionMap::getOverrideSubstitutions(baseDecl, derivedDecl,
624-
/*derivedSubs=*/None);
623+
auto subs = SubstitutionMap::getOverrideSubstitutions(baseDecl, derivedDecl);
625624

626625
for (auto i : indices(baseParams->getArray())) {
627626
auto *baseParam = baseParams->get(i);

0 commit comments

Comments
 (0)