Skip to content

Commit 55e8f9f

Browse files
author
jturcotti
committed
improve debug output, finalize explicit constructor refactor, and begin improving diagnostic messages
1 parent 5f42a14 commit 55e8f9f

File tree

3 files changed

+150
-123
lines changed

3 files changed

+150
-123
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,22 @@ class PartitionOp {
7979
// generated during compilation from a SILBasicBlock
8080
SILInstruction *sourceInst;
8181

82+
// Record an AST expression corresponding to this PartitionOp, currently
83+
// populated only for Consume expressions to indicate the value being consumed
84+
Expr *sourceExpr;
85+
8286
// TODO: can the following declarations be merged?
8387
PartitionOp(PartitionOpKind OpKind, Element arg1,
84-
SILInstruction *sourceInst = nullptr)
85-
: OpKind(OpKind), OpArgs({arg1}), sourceInst(sourceInst) {}
88+
SILInstruction *sourceInst = nullptr,
89+
Expr* sourceExpr = nullptr)
90+
: OpKind(OpKind), OpArgs({arg1}),
91+
sourceInst(sourceInst), sourceExpr(sourceExpr) {}
8692

8793
PartitionOp(PartitionOpKind OpKind, Element arg1, Element arg2,
88-
SILInstruction *sourceInst = nullptr)
89-
: OpKind(OpKind), OpArgs({arg1, arg2}), sourceInst(sourceInst) {}
94+
SILInstruction *sourceInst = nullptr,
95+
Expr* sourceExpr = nullptr)
96+
: OpKind(OpKind), OpArgs({arg1, arg2}),
97+
sourceInst(sourceInst), sourceExpr(sourceExpr) {}
9098

9199
friend class Partition;
92100

@@ -102,8 +110,10 @@ class PartitionOp {
102110
}
103111

104112
static PartitionOp Consume(Element tgt,
105-
SILInstruction *sourceInst = nullptr) {
106-
return PartitionOp(PartitionOpKind::Consume, tgt, sourceInst);
113+
SILInstruction *sourceInst = nullptr,
114+
Expr *sourceExpr = nullptr) {
115+
return PartitionOp(PartitionOpKind::Consume, tgt,
116+
sourceInst, sourceExpr);
107117
}
108118

109119
static PartitionOp Merge(Element tgt1, Element tgt2,
@@ -116,7 +126,9 @@ class PartitionOp {
116126
return PartitionOp(PartitionOpKind::Require, tgt, sourceInst);
117127
}
118128

119-
bool operator==(const PartitionOp &other) const = default;
129+
bool operator==(const PartitionOp &other) const {
130+
return OpKind == other.OpKind && sourceInst == other.sourceInst;
131+
};
120132
// implemented for insertion into std::map
121133
bool operator<(const PartitionOp &other) const {
122134
if (OpKind != other.OpKind)

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -592,19 +592,26 @@ class PartitionOpTranslator {
592592

593593
//translate each SIL instruction to a PartitionOp, if necessary
594594
std::vector<PartitionOp> partitionOps;
595+
int lastTranslationIndex = -1;
595596
for (SILInstruction &instruction : *basicBlock) {
596597
auto ops = translateSILInstruction(&instruction);
597598
for (PartitionOp &op : ops) {
598599
partitionOps.push_back(op);
599600

600601
LLVM_DEBUG(
601-
llvm::dbgs() << " ┌─┬─╼";
602-
instruction.dump();
603-
llvm::dbgs() << " │ └─╼ ";
604-
instruction.getLoc().getSourceLoc().printLineAndColumn(llvm::dbgs(), function->getASTContext().SourceMgr);
605-
llvm::dbgs() << " │ translation #" << translationIndex;
606-
llvm::dbgs() << "\n └─────╼ ";
602+
if (translationIndex != lastTranslationIndex) {
603+
llvm::dbgs() << " ┌─┬─╼";
604+
instruction.dump();
605+
llvm::dbgs() << " │ └─╼ ";
606+
instruction.getLoc().getSourceLoc().printLineAndColumn(
607+
llvm::dbgs(), function->getASTContext().SourceMgr);
608+
llvm::dbgs() << " │ translation #" << translationIndex;
609+
llvm::dbgs() << "\n └─────╼ ";
610+
} else {
611+
llvm::dbgs() << " └╼ ";
612+
}
607613
op.dump();
614+
lastTranslationIndex = translationIndex;
608615
);
609616
}
610617
}
@@ -617,7 +624,7 @@ class PartitionOpTranslator {
617624
// SILBasicBlock for the region-based Sendable checking fixpoint analysis.
618625
// In particular, it records flags such as whether the block has been
619626
// reached by the analysis, whether the prior round indicated that this block
620-
// needs to be updated; it recorsd aux data such as the underlying basic block
627+
// needs to be updated; it records aux data such as the underlying basic block
621628
// and associated PartitionOpTranslator; and most importantly of all it includes
622629
// region partitions at entry and exit to this block - these are the stateful
623630
// component of the fixpoint analysis.
@@ -1218,8 +1225,13 @@ class PartitionAnalysis {
12181225
/*handleFailure=*/
12191226
[&](const PartitionOp& partitionOp, TrackableValueID consumedVal) {
12201227
auto expr = getExprForPartitionOp(partitionOp);
1228+
1229+
// ensure that multiple consumptions at the same AST node are only
1230+
// entered once into the race tracer
12211231
if (hasBeenEmitted(expr)) return;
1232+
12221233
raceTracer.traceUseOfConsumedValue(partitionOp, consumedVal);
1234+
12231235
/*
12241236
* This handles diagnosing accesses to consumed values at the site
12251237
* of access instead of the site of consumption, as this is less
@@ -1229,6 +1241,7 @@ class PartitionAnalysis {
12291241
expr->getLoc(), diag::consumed_value_used);
12301242
*/
12311243
},
1244+
12321245
/*handleConsumeNonConsumable=*/
12331246
[&](const PartitionOp& partitionOp, TrackableValueID consumedVal) {
12341247
auto expr = getExprForPartitionOp(partitionOp);
@@ -1247,11 +1260,13 @@ class PartitionAnalysis {
12471260
expr->getLoc(), diag::consumption_yields_race,
12481261
numDisplayed, numDisplayed != 1, numHidden > 0, numHidden);
12491262
},
1263+
12501264
/*diagnoseRequire=*/
12511265
[&](const PartitionOp& requireOp) {
12521266
auto expr = getExprForPartitionOp(requireOp);
12531267
function->getASTContext().Diags.diagnose(
1254-
expr->getLoc(), diag::possible_racy_access_site);
1268+
expr->getLoc(), diag::possible_racy_access_site)
1269+
.highlight(expr->getSourceRange());
12551270
});
12561271
}
12571272

0 commit comments

Comments
 (0)