1515//
1616// ===----------------------------------------------------------------------===//
1717
18+ #define DEBUG_TYPE " sil-diagnose-invalid-escaping-captures"
19+
1820#include " swift/AST/ASTContext.h"
1921#include " swift/AST/DiagnosticsSIL.h"
2022#include " swift/AST/Expr.h"
@@ -199,6 +201,8 @@ bool isUseOfSelfInInitializer(Operand *oper) {
199201}
200202
201203static bool checkForEscapingPartialApplyUses (PartialApplyInst *PAI) {
204+ LLVM_DEBUG (llvm::dbgs () << " Checking for escaping partial apply uses.\n " );
205+
202206 // Avoid exponential path exploration.
203207 SmallVector<Operand *, 8 > uses;
204208 llvm::SmallDenseSet<Operand *, 8 > visited;
@@ -215,10 +219,16 @@ static bool checkForEscapingPartialApplyUses(PartialApplyInst *PAI) {
215219 bool foundEscapingUse = false ;
216220 while (!uses.empty ()) {
217221 Operand *oper = uses.pop_back_val ();
218- foundEscapingUse |= checkNoEscapePartialApplyUse (oper, [&](SILValue V) {
222+ LLVM_DEBUG (llvm::dbgs () << " Visiting user: " << *oper->getUser ());
223+ bool localFoundEscapingUse = checkNoEscapePartialApplyUse (oper, [&](SILValue V) {
219224 for (Operand *use : V->getUses ())
220225 uselistInsert (use);
221226 });
227+ LLVM_DEBUG (
228+ if (localFoundEscapingUse)
229+ llvm::dbgs () << " Escapes!\n " ;
230+ );
231+ foundEscapingUse |= localFoundEscapingUse;
222232 }
223233
224234 // If there aren't any, we're fine.
@@ -350,6 +360,8 @@ static void checkPartialApply(ASTContext &Context, DeclContext *DC,
350360 if (isPartialApplyOfReabstractionThunk (PAI))
351361 return ;
352362
363+ LLVM_DEBUG (llvm::dbgs () << " Checking Partial Apply: " << *PAI);
364+
353365 ApplySite apply (PAI);
354366
355367 // Collect any non-escaping captures.
@@ -584,6 +596,8 @@ class DiagnoseInvalidEscapingCaptures : public SILFunctionTransform {
584596 if (F->wasDeserializedCanonical ())
585597 return ;
586598
599+ LLVM_DEBUG (llvm::dbgs () << " *** Diagnosing escaping captures in function: "
600+ << F->getName () << ' \n ' );
587601 checkEscapingCaptures (F);
588602 }
589603};
0 commit comments