@@ -169,15 +169,6 @@ struct TermArgSources {
169
169
170
170
} // namespace
171
171
172
- // / Used for generating informative diagnostics.
173
- static Expr *getExprForPartitionOp (const PartitionOp &op) {
174
- SILInstruction *sourceInstr = op.getSourceInst (/* assertNonNull=*/ true );
175
- Expr *expr = sourceInstr->getLoc ().getAsASTNode <Expr>();
176
- assert (expr && " PartitionOp's source location should correspond to"
177
- " an AST node" );
178
- return expr;
179
- }
180
-
181
172
static bool isProjectedFromAggregate (SILValue value) {
182
173
assert (value->getType ().isAddress ());
183
174
UseDefChainVisitor visitor;
@@ -1611,9 +1602,9 @@ class TransferRequireAccumulator {
1611
1602
assert (false && " no transfers besides callsites implemented yet" );
1612
1603
1613
1604
// Default to a more generic diagnostic if we can't find the callsite.
1614
- auto expr = getExprForPartitionOp ( transferOp);
1605
+ auto loc = transferOp. getSourceLoc ( );
1615
1606
auto diag = fn->getASTContext ().Diags .diagnose (
1616
- expr-> getLoc (), diag::transfer_yields_race, numDisplayed,
1607
+ loc. getSourceLoc (), diag::transfer_yields_race, numDisplayed,
1617
1608
numDisplayed != 1 , numHidden > 0 , numHidden);
1618
1609
if (auto sourceExpr = transferOp.getSourceExpr ())
1619
1610
diag.highlight (sourceExpr->getSourceRange ());
@@ -1626,10 +1617,10 @@ class TransferRequireAccumulator {
1626
1617
// transfer...
1627
1618
if (numRequiresToProcess-- == 0 )
1628
1619
break ;
1629
- auto expr = getExprForPartitionOp ( requireOp);
1620
+ auto loc = requireOp. getSourceLoc ( );
1630
1621
fn->getASTContext ()
1631
- .Diags .diagnose (expr-> getLoc (), diag::possible_racy_access_site)
1632
- .highlight (expr-> getSourceRange ());
1622
+ .Diags .diagnose (loc. getSourceLoc (), diag::possible_racy_access_site)
1623
+ .highlight (loc. getSourceRange ());
1633
1624
}
1634
1625
}
1635
1626
}
@@ -2065,18 +2056,15 @@ class PartitionAnalysis {
2065
2056
translator.sortUniqueNeverTransferredValues ();
2066
2057
}
2067
2058
2068
- // / Track the AST exprs that have already had diagnostics emitted about.
2069
- llvm::DenseSet<Expr *> emittedExprs;
2070
-
2071
- // / Check if a diagnostic has already been emitted for \p expr.
2072
- bool hasBeenEmitted (Expr *expr) {
2073
- if (auto castExpr = dyn_cast<ImplicitConversionExpr>(expr))
2074
- return hasBeenEmitted (castExpr->getSubExpr ());
2059
+ // / Track the transfer insts that have already had diagnostics emitted about.
2060
+ llvm::DenseSet<SILInstruction *> emittedTransferInsts;
2075
2061
2076
- if (emittedExprs.contains (expr))
2077
- return true ;
2078
- emittedExprs.insert (expr);
2079
- return false ;
2062
+ // / Returns true if a diagnostic has already been emitted for the transferred
2063
+ // / instruction \p transferredInst.
2064
+ // /
2065
+ // / If we return false, we insert \p transferredInst into emittedTransferInst.
2066
+ bool hasBeenEmitted (SILInstruction *transferredInst) {
2067
+ return !emittedTransferInsts.insert (transferredInst).second ;
2080
2068
}
2081
2069
2082
2070
// / Once we have reached a fixpoint, this routine runs over all blocks again
@@ -2098,24 +2086,22 @@ class PartitionAnalysis {
2098
2086
Partition workingPartition = blockState.getEntryPartition ();
2099
2087
PartitionOpEvaluator eval (workingPartition);
2100
2088
eval.failureCallback = /* handleFailure=*/
2101
- [&](const PartitionOp &partitionOp, TrackableValueID transferredVal,
2102
- SILInstruction *transferringInst) {
2103
- auto expr = getExprForPartitionOp (partitionOp);
2089
+ [&](const PartitionOp &partitionOp, TrackableValueID transferredVal,
2090
+ SILInstruction *transferringInst) {
2091
+ // Ensure that multiple transfers at the same AST node are only
2092
+ // entered once into the race tracer
2093
+ if (hasBeenEmitted (partitionOp.getSourceInst (true )))
2094
+ return ;
2104
2095
2105
- // Ensure that multiple transfers at the same AST node are only
2106
- // entered once into the race tracer
2107
- if (hasBeenEmitted (expr))
2108
- return ;
2109
-
2110
- LLVM_DEBUG (llvm::dbgs ()
2111
- << " Emitting Use After Transfer Error!\n "
2112
- << " ID: %%" << transferredVal << " \n "
2113
- << " Rep: "
2114
- << *translator.getValueForId (transferredVal)
2096
+ LLVM_DEBUG (llvm::dbgs ()
2097
+ << " Emitting Use After Transfer Error!\n "
2098
+ << " ID: %%" << transferredVal << " \n "
2099
+ << " Rep: "
2100
+ << *translator.getValueForId (transferredVal)
2115
2101
->getRepresentative ());
2116
2102
2117
2103
raceTracer.traceUseOfTransferredValue (partitionOp, transferredVal);
2118
- };
2104
+ };
2119
2105
eval.transferredNonTransferrableCallback =
2120
2106
[&](const PartitionOp &partitionOp, TrackableValueID transferredVal) {
2121
2107
LLVM_DEBUG (llvm::dbgs ()
@@ -2124,9 +2110,9 @@ class PartitionAnalysis {
2124
2110
<< " Rep: "
2125
2111
<< *translator.getValueForId (transferredVal)
2126
2112
->getRepresentative ());
2127
- auto expr = getExprForPartitionOp (partitionOp);
2128
2113
function->getASTContext ().Diags .diagnose (
2129
- expr->getLoc (), diag::arg_region_transferred);
2114
+ partitionOp.getSourceLoc ().getSourceLoc (),
2115
+ diag::arg_region_transferred);
2130
2116
};
2131
2117
eval.nonTransferrableElements = translator.getNeverTransferredValues ();
2132
2118
eval.isActorDerivedCallback = [&](Element element) -> bool {
0 commit comments