@@ -102,16 +102,14 @@ using AssociativityCacheType =
102
102
struct OverrideSignatureKey {
103
103
GenericSignature baseMethodSig;
104
104
GenericSignature derivedMethodSig;
105
- Type superclassTy, subclassTy ;
105
+ Decl *subclassDecl ;
106
106
107
107
OverrideSignatureKey (GenericSignature baseMethodSignature,
108
108
GenericSignature derivedMethodSignature,
109
- Type superclassType,
110
- Type subclassType)
109
+ Decl *subclassDecl)
111
110
: baseMethodSig(baseMethodSignature),
112
111
derivedMethodSig (derivedMethodSignature),
113
- superclassTy(superclassType),
114
- subclassTy(subclassType) {}
112
+ subclassDecl(subclassDecl) {}
115
113
};
116
114
117
115
namespace llvm {
@@ -123,31 +121,27 @@ template <> struct DenseMapInfo<OverrideSignatureKey> {
123
121
const OverrideSignatureKey rhs) {
124
122
return lhs.baseMethodSig .getPointer () == rhs.baseMethodSig .getPointer () &&
125
123
lhs.derivedMethodSig .getPointer () == rhs.derivedMethodSig .getPointer () &&
126
- lhs.superclassTy .getPointer () == rhs.superclassTy .getPointer () &&
127
- lhs.subclassTy .getPointer () == rhs.subclassTy .getPointer ();
124
+ lhs.subclassDecl == rhs.subclassDecl ;
128
125
}
129
126
130
127
static inline OverrideSignatureKey getEmptyKey () {
131
128
return OverrideSignatureKey (DenseMapInfo<GenericSignature>::getEmptyKey (),
132
129
DenseMapInfo<GenericSignature>::getEmptyKey (),
133
- DenseMapInfo<Type>::getEmptyKey (),
134
- DenseMapInfo<Type>::getEmptyKey ());
130
+ DenseMapInfo<Decl *>::getEmptyKey ());
135
131
}
136
132
137
133
static inline OverrideSignatureKey getTombstoneKey () {
138
134
return OverrideSignatureKey (
139
135
DenseMapInfo<GenericSignature>::getTombstoneKey (),
140
136
DenseMapInfo<GenericSignature>::getTombstoneKey (),
141
- DenseMapInfo<Type>::getTombstoneKey (),
142
- DenseMapInfo<Type>::getTombstoneKey ());
137
+ DenseMapInfo<Decl *>::getTombstoneKey ());
143
138
}
144
139
145
140
static unsigned getHashValue (const OverrideSignatureKey &Val) {
146
141
return hash_combine (
147
142
DenseMapInfo<GenericSignature>::getHashValue (Val.baseMethodSig ),
148
143
DenseMapInfo<GenericSignature>::getHashValue (Val.derivedMethodSig ),
149
- DenseMapInfo<Type>::getHashValue (Val.superclassTy ),
150
- DenseMapInfo<Type>::getHashValue (Val.subclassTy ));
144
+ DenseMapInfo<Decl *>::getHashValue (Val.subclassDecl ));
151
145
}
152
146
};
153
147
} // namespace llvm
@@ -4471,40 +4465,39 @@ CanGenericSignature ASTContext::getOpenedArchetypeSignature(CanType existential,
4471
4465
GenericSignature
4472
4466
ASTContext::getOverrideGenericSignature (const ValueDecl *base,
4473
4467
const ValueDecl *derived) {
4474
- auto baseGenericCtx = base-> getAsGenericContext ( );
4475
- auto derivedGenericCtx = derived-> getAsGenericContext ( );
4468
+ assert (isa<AbstractFunctionDecl>(base) || isa<SubscriptDecl>(base) );
4469
+ assert (isa<AbstractFunctionDecl>(derived) || isa<SubscriptDecl>(derived) );
4476
4470
4477
- if (!baseGenericCtx || !derivedGenericCtx)
4478
- return nullptr ;
4471
+ auto baseClass = base-> getDeclContext ()-> getSelfClassDecl ();
4472
+ auto derivedClass = derived-> getDeclContext ()-> getSelfClassDecl () ;
4479
4473
4480
- if (base == derived)
4481
- return derivedGenericCtx-> getGenericSignature ( );
4474
+ assert (baseClass != nullptr );
4475
+ assert (derivedClass != nullptr );
4482
4476
4483
- auto baseClass = base->getDeclContext ()->getSelfClassDecl ();
4484
- if (!baseClass)
4485
- return nullptr ;
4477
+ auto baseGenericSig = base->getAsGenericContext ()->getGenericSignature ();
4478
+ auto derivedGenericSig = derived->getAsGenericContext ()->getGenericSignature ();
4486
4479
4487
- auto derivedClass = derived->getDeclContext ()->getSelfClassDecl ();
4488
- if (!derivedClass)
4489
- return nullptr ;
4480
+ if (base == derived)
4481
+ return derivedGenericSig;
4490
4482
4491
4483
if (derivedClass->getSuperclass ().isNull ())
4492
4484
return nullptr ;
4493
4485
4494
- if (baseGenericCtx->getGenericSignature ().isNull () ||
4495
- derivedGenericCtx->getGenericSignature ().isNull ())
4486
+ if (derivedGenericSig.isNull ())
4496
4487
return nullptr ;
4497
4488
4489
+ if (baseGenericSig.isNull ())
4490
+ return derivedGenericSig;
4491
+
4498
4492
auto baseClassSig = baseClass->getGenericSignature ();
4499
4493
auto subMap = derivedClass->getSuperclass ()->getContextSubstitutionMap (
4500
4494
derivedClass->getModuleContext (), baseClass);
4501
4495
4502
4496
unsigned derivedDepth = 0 ;
4503
4497
4504
- auto key = OverrideSignatureKey (baseGenericCtx->getGenericSignature (),
4505
- derivedGenericCtx->getGenericSignature (),
4506
- derivedClass->getSuperclass (),
4507
- derivedClass->getDeclaredInterfaceType ());
4498
+ auto key = OverrideSignatureKey (baseGenericSig,
4499
+ derivedGenericSig,
4500
+ derivedClass);
4508
4501
4509
4502
if (getImpl ().overrideSigCache .find (key) !=
4510
4503
getImpl ().overrideSigCache .end ()) {
@@ -4515,7 +4508,7 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
4515
4508
derivedDepth = derivedSig->getGenericParams ().back ()->getDepth () + 1 ;
4516
4509
4517
4510
SmallVector<GenericTypeParamType *, 2 > addedGenericParams;
4518
- if (auto *gpList = derivedGenericCtx ->getGenericParams ()) {
4511
+ if (auto *gpList = derived-> getAsGenericContext () ->getGenericParams ()) {
4519
4512
for (auto gp : *gpList) {
4520
4513
addedGenericParams.push_back (
4521
4514
gp->getDeclaredInterfaceType ()->castTo <GenericTypeParamType>());
@@ -4549,7 +4542,7 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
4549
4542
};
4550
4543
4551
4544
SmallVector<Requirement, 2 > addedRequirements;
4552
- for (auto reqt : baseGenericCtx-> getGenericSignature () ->getRequirements ()) {
4545
+ for (auto reqt : baseGenericSig ->getRequirements ()) {
4553
4546
if (auto substReqt = reqt.subst (substFn, lookupConformanceFn)) {
4554
4547
addedRequirements.push_back (*substReqt);
4555
4548
}
0 commit comments