@@ -287,19 +287,28 @@ CalleeList CalleeCache::getCalleeList(FullApplySite FAS) const {
287287 return getCalleeListForCalleeKind (FAS.getCalleeOrigin ());
288288}
289289
290- // Return the list of functions that can be called via the given instruction.
291- CalleeList CalleeCache::getCalleeList (SILInstruction *I) const {
292- // We support only deallocation instructions at the moment.
293- assert ((isa<StrongReleaseInst>(I) || isa<ReleaseValueInst>(I)) &&
294- " A deallocation instruction expected" );
295- auto Ty = I->getOperand (0 )->getType ();
296- while (auto payloadTy = Ty.getOptionalObjectType ())
297- Ty = payloadTy;
298- auto Class = Ty.getClassOrBoundGenericClass ();
299- if (!Class || Class->hasClangNode ())
290+ // / Return the list of destructors of the class type \p type.
291+ // /
292+ // / If \p type is an optional, look through that optional.
293+ // / If \p exactType is true, then \p type is treated like a final class type.
294+ CalleeList CalleeCache::getDestructors (SILType type, bool isExactType) const {
295+ while (auto payloadTy = type.getOptionalObjectType ()) {
296+ type = payloadTy;
297+ }
298+ ClassDecl *classDecl = type.getClassOrBoundGenericClass ();
299+ if (!classDecl || classDecl->hasClangNode ())
300+ return CalleeList ();
301+
302+ if (isExactType || classDecl->isFinal ()) {
303+ // In case of a final class, just pick the deinit of the class.
304+ SILDeclRef destructor = SILDeclRef (classDecl->getDestructor ());
305+ if (SILFunction *destrImpl = M.lookUpFunction (destructor))
306+ return CalleeList (destrImpl);
300307 return CalleeList ();
301- SILDeclRef Destructor = SILDeclRef (Class->getDestructor ());
302- return getCalleeList (Destructor);
308+ }
309+ // If all that doesn't help get the list of deinits as we do for regular class
310+ // methods.
311+ return getCalleeList (SILDeclRef (classDecl->getDestructor ()));
303312}
304313
305314void BasicCalleeAnalysis::dump () const {
@@ -332,10 +341,11 @@ BridgedCalleeList CalleeAnalysis_getCallees(BridgedCalleeAnalysis calleeAnalysis
332341 return {cl.getOpaquePtr (), cl.getOpaqueKind (), cl.isIncomplete ()};
333342}
334343
335- BridgedCalleeList CalleeAnalysis_getInstCallees (BridgedCalleeAnalysis calleeAnalysis,
336- BridgedInstruction inst) {
344+ BridgedCalleeList CalleeAnalysis_getDestructors (BridgedCalleeAnalysis calleeAnalysis,
345+ BridgedType type,
346+ SwiftInt isExactType) {
337347 BasicCalleeAnalysis *bca = static_cast <BasicCalleeAnalysis *>(calleeAnalysis.bca );
338- CalleeList cl = bca->getCalleeList ( castToInst (inst) );
348+ CalleeList cl = bca->getDestructors ( castToSILType (type), isExactType != 0 );
339349 return {cl.getOpaquePtr (), cl.getOpaqueKind (), cl.isIncomplete ()};
340350}
341351
0 commit comments