@@ -54,8 +54,7 @@ void CalleeCache::sortAndUniqueCallees() {
54
54
55
55
CalleeCache::CalleesAndCanCallUnknown &
56
56
CalleeCache::getOrCreateCalleesForMethod (SILDeclRef Decl) {
57
- auto *AFD = cast<AbstractFunctionDecl>(Decl.getDecl ());
58
- auto Found = TheCache.find (AFD);
57
+ auto Found = TheCache.find (Decl);
59
58
if (Found != TheCache.end ())
60
59
return Found->second ;
61
60
@@ -66,7 +65,7 @@ CalleeCache::getOrCreateCalleesForMethod(SILDeclRef Decl) {
66
65
67
66
bool Inserted;
68
67
CacheType::iterator It;
69
- std::tie (It, Inserted) = TheCache.insert (std::make_pair (AFD , Entry));
68
+ std::tie (It, Inserted) = TheCache.insert (std::make_pair (Decl , Entry));
70
69
assert (Inserted && " Expected new entry to be inserted!" );
71
70
72
71
return It->second ;
@@ -82,26 +81,38 @@ void CalleeCache::computeClassMethodCalleesForClass(ClassDecl *CD) {
82
81
if (!AFD)
83
82
continue ;
84
83
85
- auto Method = SILDeclRef (AFD);
86
- auto *CalledFn = M.lookUpFunctionInVTable (CD, Method);
87
- if (!CalledFn)
88
- continue ;
84
+ if (auto *ConstrDecl = dyn_cast<ConstructorDecl>(AFD)) {
85
+ computeClassMethodCallees (CD, SILDeclRef (AFD,
86
+ SILDeclRef::Kind::Initializer));
87
+ if (ConstrDecl->isRequired ()) {
88
+ computeClassMethodCallees (CD, SILDeclRef (AFD,
89
+ SILDeclRef::Kind::Allocator));
90
+ }
91
+ } else {
92
+ computeClassMethodCallees (CD, SILDeclRef (AFD));
93
+ }
94
+ }
95
+ }
89
96
90
- bool canCallUnknown = !calleesAreStaticallyKnowable (M, Method);
97
+ void CalleeCache::computeClassMethodCallees (ClassDecl *CD, SILDeclRef Method) {
98
+ auto *CalledFn = M.lookUpFunctionInVTable (CD, Method);
99
+ if (!CalledFn)
100
+ return ;
91
101
92
- // Update the callees for this method and all the methods it
93
- // overrides by adding this function to their lists.
94
- do {
95
- auto &TheCallees = getOrCreateCalleesForMethod (Method);
96
- assert (TheCallees.getPointer () && " Unexpected null callees!" );
102
+ bool canCallUnknown = !calleesAreStaticallyKnowable (M, Method);
97
103
98
- TheCallees.getPointer ()->push_back (CalledFn);
99
- if (canCallUnknown)
100
- TheCallees.setInt (true );
104
+ // Update the callees for this method and all the methods it
105
+ // overrides by adding this function to their lists.
106
+ do {
107
+ auto &TheCallees = getOrCreateCalleesForMethod (Method);
108
+ assert (TheCallees.getPointer () && " Unexpected null callees!" );
101
109
102
- Method = Method.getNextOverriddenVTableEntry ();
103
- } while (Method);
104
- }
110
+ TheCallees.getPointer ()->push_back (CalledFn);
111
+ if (canCallUnknown)
112
+ TheCallees.setInt (true );
113
+
114
+ Method = Method.getNextOverriddenVTableEntry ();
115
+ } while (Method);
105
116
}
106
117
107
118
void CalleeCache::computeWitnessMethodCalleesForWitnessTable (
@@ -154,7 +165,7 @@ CalleeCache::getSingleCalleeForWitnessMethod(WitnessMethodInst *WMI) const {
154
165
155
166
// Look up the precomputed callees for an abstract function and
156
167
// return it as a CalleeList.
157
- CalleeList CalleeCache::getCalleeList (AbstractFunctionDecl * Decl) const {
168
+ CalleeList CalleeCache::getCalleeList (SILDeclRef Decl) const {
158
169
auto Found = TheCache.find (Decl);
159
170
if (Found == TheCache.end ())
160
171
return CalleeList ();
@@ -172,15 +183,13 @@ CalleeList CalleeCache::getCalleeList(WitnessMethodInst *WMI) const {
172
183
173
184
// Otherwise see if we previously computed the callees based on
174
185
// witness tables.
175
- auto *Decl = cast<AbstractFunctionDecl>(WMI->getMember ().getDecl ());
176
- return getCalleeList (Decl);
186
+ return getCalleeList (WMI->getMember ());
177
187
}
178
188
179
189
// Return a callee list for a given class method.
180
190
CalleeList CalleeCache::getCalleeList (ClassMethodInst *CMI) const {
181
191
// Look for precomputed callees based on vtables.
182
- auto *Decl = cast<AbstractFunctionDecl>(CMI->getMember ().getDecl ());
183
- return getCalleeList (Decl);
192
+ return getCalleeList (CMI->getMember ());
184
193
}
185
194
186
195
// Return the list of functions that can be called via the given callee.
@@ -232,6 +241,6 @@ CalleeList CalleeCache::getCalleeList(SILInstruction *I) const {
232
241
auto Class = Ty.getSwiftRValueType ().getClassOrBoundGenericClass ();
233
242
if (!Class || Class->hasClangNode () || !Class->hasDestructor ())
234
243
return CalleeList ();
235
- auto Destructor = Class->getDestructor ();
244
+ SILDeclRef Destructor = SILDeclRef ( Class->getDestructor () );
236
245
return getCalleeList (Destructor);
237
246
}
0 commit comments