Skip to content

Commit 82cf0c5

Browse files
author
jturcotti
committed
improve diagnostics
1 parent ba59f86 commit 82cf0c5

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,20 @@ class PartitionAnalysis {
527527
}
528528
}
529529

530+
// track the AST exprs that have already had diagnostics emitted about
531+
llvm::DenseSet<Expr *> emittedExprs;
532+
533+
// check if a diagnostic has already been emitted about expr, only
534+
// returns true false for each expr
535+
bool hasBeenEmitted(Expr *expr) {
536+
if (auto castExpr = dyn_cast<ImplicitConversionExpr>(expr))
537+
return hasBeenEmitted(castExpr->getSubExpr());
538+
539+
if (emittedExprs.contains(expr)) return true;
540+
emittedExprs.insert(expr);
541+
return false;
542+
}
543+
530544
// once the fixpoint has been solved for, run one more pass over each basic
531545
// block, reporting any failures due to requiring consumed regions in the
532546
// fixpoint state
@@ -538,9 +552,12 @@ class PartitionAnalysis {
538552
SILInstruction *sourceInstr = partitionOp.getSourceInst();
539553
assert(sourceInstr && "PartitionOps used in PartitionAnalysis should "
540554
"always have been generated with a sourceInst");
555+
Expr *expr = sourceInstr->getLoc().getAsASTNode<Expr>();
556+
assert(expr && "PartitionOp's source location should correspond to"
557+
"an AST node");
558+
if (hasBeenEmitted(expr)) return;
541559
function->getASTContext().Diags.diagnose(
542-
sourceInstr->getLoc().getSourceLoc(),
543-
diag::send_non_sendable, consumedVal);
560+
expr->getLoc(), diag::send_non_sendable, consumedVal);
544561
});
545562
}
546563
}

0 commit comments

Comments
 (0)