Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/SILOptimizer/Mandatory/DiagnoseInvalidEscapingCaptures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//
//===----------------------------------------------------------------------===//

#define DEBUG_TYPE "sil-diagnose-invalid-escaping-captures"

#include "swift/AST/ASTContext.h"
#include "swift/AST/DiagnosticsSIL.h"
#include "swift/AST/Expr.h"
Expand Down Expand Up @@ -199,6 +201,8 @@ bool isUseOfSelfInInitializer(Operand *oper) {
}

static bool checkForEscapingPartialApplyUses(PartialApplyInst *PAI) {
LLVM_DEBUG(llvm::dbgs() << "Checking for escaping partial apply uses.\n");

// Avoid exponential path exploration.
SmallVector<Operand *, 8> uses;
llvm::SmallDenseSet<Operand *, 8> visited;
Expand All @@ -215,10 +219,16 @@ static bool checkForEscapingPartialApplyUses(PartialApplyInst *PAI) {
bool foundEscapingUse = false;
while (!uses.empty()) {
Operand *oper = uses.pop_back_val();
foundEscapingUse |= checkNoEscapePartialApplyUse(oper, [&](SILValue V) {
LLVM_DEBUG(llvm::dbgs() << "Visiting user: " << *oper->getUser());
bool localFoundEscapingUse = checkNoEscapePartialApplyUse(oper, [&](SILValue V) {
for (Operand *use : V->getUses())
uselistInsert(use);
});
LLVM_DEBUG(
if (localFoundEscapingUse)
llvm::dbgs() << " Escapes!\n";
);
foundEscapingUse |= localFoundEscapingUse;
}

// If there aren't any, we're fine.
Expand Down Expand Up @@ -350,6 +360,8 @@ static void checkPartialApply(ASTContext &Context, DeclContext *DC,
if (isPartialApplyOfReabstractionThunk(PAI))
return;

LLVM_DEBUG(llvm::dbgs() << "Checking Partial Apply: " << *PAI);

ApplySite apply(PAI);

// Collect any non-escaping captures.
Expand Down Expand Up @@ -584,6 +596,8 @@ class DiagnoseInvalidEscapingCaptures : public SILFunctionTransform {
if (F->wasDeserializedCanonical())
return;

LLVM_DEBUG(llvm::dbgs() << "*** Diagnosing escaping captures in function: "
<< F->getName() << '\n');
checkEscapingCaptures(F);
}
};
Expand Down