@@ -101,14 +101,14 @@ using AssociativityCacheType =
101
101
struct OverrideSignatureKey {
102
102
GenericSignature baseMethodSig;
103
103
GenericSignature derivedMethodSig;
104
- Decl *subclassDecl ;
104
+ NominalTypeDecl *derivedNominal ;
105
105
106
106
OverrideSignatureKey (GenericSignature baseMethodSignature,
107
107
GenericSignature derivedMethodSignature,
108
- Decl *subclassDecl )
108
+ NominalTypeDecl *derivedNominal )
109
109
: baseMethodSig(baseMethodSignature),
110
110
derivedMethodSig (derivedMethodSignature),
111
- subclassDecl(subclassDecl ) {}
111
+ derivedNominal(derivedNominal ) {}
112
112
};
113
113
114
114
namespace llvm {
@@ -120,27 +120,27 @@ template <> struct DenseMapInfo<OverrideSignatureKey> {
120
120
const OverrideSignatureKey rhs) {
121
121
return lhs.baseMethodSig .getPointer () == rhs.baseMethodSig .getPointer () &&
122
122
lhs.derivedMethodSig .getPointer () == rhs.derivedMethodSig .getPointer () &&
123
- lhs.subclassDecl == rhs.subclassDecl ;
123
+ lhs.derivedNominal == rhs.derivedNominal ;
124
124
}
125
125
126
126
static inline OverrideSignatureKey getEmptyKey () {
127
127
return OverrideSignatureKey (DenseMapInfo<GenericSignature>::getEmptyKey (),
128
128
DenseMapInfo<GenericSignature>::getEmptyKey (),
129
- DenseMapInfo<Decl *>::getEmptyKey ());
129
+ DenseMapInfo<NominalTypeDecl *>::getEmptyKey ());
130
130
}
131
131
132
132
static inline OverrideSignatureKey getTombstoneKey () {
133
133
return OverrideSignatureKey (
134
134
DenseMapInfo<GenericSignature>::getTombstoneKey (),
135
135
DenseMapInfo<GenericSignature>::getTombstoneKey (),
136
- DenseMapInfo<Decl *>::getTombstoneKey ());
136
+ DenseMapInfo<NominalTypeDecl *>::getTombstoneKey ());
137
137
}
138
138
139
139
static unsigned getHashValue (const OverrideSignatureKey &Val) {
140
140
return hash_combine (
141
141
DenseMapInfo<GenericSignature>::getHashValue (Val.baseMethodSig ),
142
142
DenseMapInfo<GenericSignature>::getHashValue (Val.derivedMethodSig ),
143
- DenseMapInfo<Decl *>::getHashValue (Val.subclassDecl ));
143
+ DenseMapInfo<NominalTypeDecl *>::getHashValue (Val.derivedNominal ));
144
144
}
145
145
};
146
146
} // namespace llvm
@@ -5214,11 +5214,11 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
5214
5214
assert (isa<AbstractFunctionDecl>(base) || isa<SubscriptDecl>(base));
5215
5215
assert (isa<AbstractFunctionDecl>(derived) || isa<SubscriptDecl>(derived));
5216
5216
5217
- const auto baseClass = base->getDeclContext ()->getSelfClassDecl ();
5218
- const auto derivedClass = derived->getDeclContext ()->getSelfClassDecl ();
5217
+ const auto baseNominal = base->getDeclContext ()->getSelfNominalTypeDecl ();
5218
+ const auto derivedNominal = derived->getDeclContext ()->getSelfNominalTypeDecl ();
5219
5219
5220
- assert (baseClass != nullptr );
5221
- assert (derivedClass != nullptr );
5220
+ assert (baseNominal != nullptr );
5221
+ assert (derivedNominal != nullptr );
5222
5222
5223
5223
const auto baseGenericSig =
5224
5224
base->getAsGenericContext ()->getGenericSignature ();
@@ -5228,10 +5228,6 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
5228
5228
if (base == derived)
5229
5229
return derivedGenericSig;
5230
5230
5231
- const auto derivedSuperclass = derivedClass->getSuperclass ();
5232
- if (derivedSuperclass.isNull ())
5233
- return nullptr ;
5234
-
5235
5231
if (derivedGenericSig.isNull ())
5236
5232
return nullptr ;
5237
5233
@@ -5240,21 +5236,14 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
5240
5236
5241
5237
auto key = OverrideSignatureKey (baseGenericSig,
5242
5238
derivedGenericSig,
5243
- derivedClass );
5239
+ derivedNominal );
5244
5240
5245
5241
if (getImpl ().overrideSigCache .find (key) !=
5246
5242
getImpl ().overrideSigCache .end ()) {
5247
5243
return getImpl ().overrideSigCache .lookup (key);
5248
5244
}
5249
5245
5250
- const auto derivedClassSig = derivedClass->getGenericSignature ();
5251
-
5252
- unsigned derivedDepth = 0 ;
5253
- unsigned baseDepth = 0 ;
5254
- if (derivedClassSig)
5255
- derivedDepth = derivedClassSig.getGenericParams ().back ()->getDepth () + 1 ;
5256
- if (const auto baseClassSig = baseClass->getGenericSignature ())
5257
- baseDepth = baseClassSig.getGenericParams ().back ()->getDepth () + 1 ;
5246
+ const auto derivedNominalSig = derivedNominal->getGenericSignature ();
5258
5247
5259
5248
SmallVector<GenericTypeParamType *, 2 > addedGenericParams;
5260
5249
if (const auto *gpList = derived->getAsGenericContext ()->getGenericParams ()) {
@@ -5264,38 +5253,59 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
5264
5253
}
5265
5254
}
5266
5255
5267
- const auto subMap = derivedSuperclass->getContextSubstitutionMap (
5268
- derivedClass->getModuleContext (), baseClass);
5256
+ SmallVector<Requirement, 2 > addedRequirements;
5269
5257
5270
- auto substFn = [&](SubstitutableType *type) -> Type {
5271
- auto *gp = cast<GenericTypeParamType>(type );
5258
+ if (isa<ProtocolDecl>(baseNominal)) {
5259
+ assert (isa<ProtocolDecl>(derivedNominal) );
5272
5260
5273
- if (gp-> getDepth () < baseDepth ) {
5274
- return Type (gp). subst (subMap );
5261
+ for ( auto reqt : baseGenericSig. getRequirements () ) {
5262
+ addedRequirements. push_back (reqt );
5275
5263
}
5264
+ } else {
5265
+ const auto derivedSuperclass = cast<ClassDecl>(derivedNominal)
5266
+ ->getSuperclass ();
5267
+ if (derivedSuperclass.isNull ())
5268
+ return nullptr ;
5276
5269
5277
- return CanGenericTypeParamType::get (
5278
- gp->isTypeSequence (), gp->getDepth () - baseDepth + derivedDepth,
5279
- gp->getIndex (), *this );
5280
- };
5270
+ unsigned derivedDepth = 0 ;
5271
+ unsigned baseDepth = 0 ;
5272
+ if (derivedNominalSig)
5273
+ derivedDepth = derivedNominalSig.getGenericParams ().back ()->getDepth () + 1 ;
5274
+ if (const auto baseNominalSig = baseNominal->getGenericSignature ())
5275
+ baseDepth = baseNominalSig.getGenericParams ().back ()->getDepth () + 1 ;
5281
5276
5282
- auto lookupConformanceFn =
5283
- [&](CanType depTy, Type substTy,
5284
- ProtocolDecl *proto) -> ProtocolConformanceRef {
5285
- if (auto conf = subMap.lookupConformance (depTy, proto))
5286
- return conf;
5277
+ const auto subMap = derivedSuperclass->getContextSubstitutionMap (
5278
+ derivedNominal->getModuleContext (), baseNominal);
5287
5279
5288
- return ProtocolConformanceRef (proto);
5289
- } ;
5280
+ auto substFn = [&](SubstitutableType *type) -> Type {
5281
+ auto *gp = cast<GenericTypeParamType>(type) ;
5290
5282
5291
- SmallVector<Requirement, 2 > addedRequirements;
5292
- for (auto reqt : baseGenericSig.getRequirements ()) {
5293
- if (auto substReqt = reqt.subst (substFn, lookupConformanceFn)) {
5294
- addedRequirements.push_back (*substReqt);
5283
+ if (gp->getDepth () < baseDepth) {
5284
+ return Type (gp).subst (subMap);
5285
+ }
5286
+
5287
+ return CanGenericTypeParamType::get (
5288
+ gp->isTypeSequence (), gp->getDepth () - baseDepth + derivedDepth,
5289
+ gp->getIndex (), *this );
5290
+ };
5291
+
5292
+ auto lookupConformanceFn =
5293
+ [&](CanType depTy, Type substTy,
5294
+ ProtocolDecl *proto) -> ProtocolConformanceRef {
5295
+ if (auto conf = subMap.lookupConformance (depTy, proto))
5296
+ return conf;
5297
+
5298
+ return ProtocolConformanceRef (proto);
5299
+ };
5300
+
5301
+ for (auto reqt : baseGenericSig.getRequirements ()) {
5302
+ if (auto substReqt = reqt.subst (substFn, lookupConformanceFn)) {
5303
+ addedRequirements.push_back (*substReqt);
5304
+ }
5295
5305
}
5296
5306
}
5297
5307
5298
- auto genericSig = buildGenericSignature (*this , derivedClassSig ,
5308
+ auto genericSig = buildGenericSignature (*this , derivedNominalSig ,
5299
5309
std::move (addedGenericParams),
5300
5310
std::move (addedRequirements));
5301
5311
getImpl ().overrideSigCache .insert (std::make_pair (key, genericSig));
0 commit comments