Skip to content

Commit 1166e22

Browse files
committed
[region-isolation] Clean up diagnostics to use helper functions.
Just makes things a little cleaner than invoking the methods on ASTContext directly.
1 parent 918f207 commit 1166e22

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,40 @@ static bool isProjectedFromAggregate(SILValue value) {
241241
return visitor.isMerge;
242242
}
243243

244+
//===----------------------------------------------------------------------===//
245+
// MARK: Diagnostics
246+
//===----------------------------------------------------------------------===//
247+
248+
template <typename... T, typename... U>
249+
static InFlightDiagnostic diagnose(ASTContext &context, SourceLoc loc,
250+
Diag<T...> diag, U &&...args) {
251+
return context.Diags.diagnose(loc, diag, std::forward<U>(args)...);
252+
}
253+
254+
template <typename... T, typename... U>
255+
static InFlightDiagnostic diagnose(const PartitionOp &op, Diag<T...> diag,
256+
U &&...args) {
257+
return ::diagnose(op.getSourceInst()->getFunction()->getASTContext(),
258+
op.getSourceLoc().getSourceLoc(), diag,
259+
std::forward<U>(args)...);
260+
}
261+
262+
template <typename... T, typename... U>
263+
static InFlightDiagnostic diagnose(const Operand *op, Diag<T...> diag,
264+
U &&...args) {
265+
return ::diagnose(op->getUser()->getFunction()->getASTContext(),
266+
op->getUser()->getLoc().getSourceLoc(), diag,
267+
std::forward<U>(args)...);
268+
}
269+
270+
template <typename... T, typename... U>
271+
static InFlightDiagnostic diagnose(const SILInstruction *inst, Diag<T...> diag,
272+
U &&...args) {
273+
return ::diagnose(inst->getFunction()->getASTContext(),
274+
inst->getLoc().getSourceLoc(), diag,
275+
std::forward<U>(args)...);
276+
}
277+
244278
//===----------------------------------------------------------------------===//
245279
// MARK: Expr/Type Inference for Diagnostics
246280
//===----------------------------------------------------------------------===//
@@ -1893,7 +1927,7 @@ class PartitionAnalysis {
18931927
/// Once we have reached a fixpoint, this routine runs over all blocks again
18941928
/// reporting any failures by applying our ops to the converged dataflow
18951929
/// state.
1896-
void diagnose() {
1930+
void emitDiagnostics() {
18971931
assert(solved && "diagnose should not be called before solve");
18981932

18991933
LLVM_DEBUG(llvm::dbgs() << "Emitting diagnostics for function "
@@ -1933,9 +1967,7 @@ class PartitionAnalysis {
19331967
<< " Rep: "
19341968
<< *translator.getValueForId(transferredVal)
19351969
->getRepresentative());
1936-
function->getASTContext().Diags.diagnose(
1937-
partitionOp.getSourceLoc().getSourceLoc(),
1938-
diag::arg_region_transferred);
1970+
diagnose(partitionOp, diag::arg_region_transferred);
19391971
};
19401972
eval.nonTransferrableElements = translator.getNeverTransferredValues();
19411973
eval.isActorDerivedCallback = [&](Element element) -> bool {
@@ -1970,14 +2002,10 @@ class PartitionAnalysis {
19702002
liveness.process(requireInsts);
19712003

19722004
InferredCallerArgumentTypeInfo argTypeInfo(transferOp);
1973-
auto loc = transferOp->getUser()->getLoc();
1974-
1975-
function->getASTContext()
1976-
.Diags
1977-
.diagnose(loc.getSourceLoc(), diag::call_site_transfer_yields_race,
1978-
argTypeInfo.inferredType,
1979-
argTypeInfo.isolationCrossing.getCallerIsolation(),
1980-
argTypeInfo.isolationCrossing.getCalleeIsolation())
2005+
diagnose(transferOp, diag::call_site_transfer_yields_race,
2006+
argTypeInfo.inferredType,
2007+
argTypeInfo.isolationCrossing.getCallerIsolation(),
2008+
argTypeInfo.isolationCrossing.getCalleeIsolation())
19812009
.highlight(transferOp->get().getLoc().getSourceRange());
19822010

19832011
// Ok, we now have our requires... emit the errors.
@@ -1996,10 +2024,8 @@ class PartitionAnalysis {
19962024
if (!liveness.finalRequires.contains(require))
19972025
continue;
19982026

1999-
auto loc = require->getLoc();
2000-
function->getASTContext()
2001-
.Diags.diagnose(loc.getSourceLoc(), diag::possible_racy_access_site)
2002-
.highlight(loc.getSourceRange());
2027+
diagnose(require, diag::possible_racy_access_site)
2028+
.highlight(require->getLoc().getSourceRange());
20032029
didEmitRequire = true;
20042030
}
20052031

@@ -2022,7 +2048,7 @@ class PartitionAnalysis {
20222048
auto analysis = PartitionAnalysis(function);
20232049
analysis.solve();
20242050
LLVM_DEBUG(llvm::dbgs() << "SOLVED: "; analysis.print(llvm::dbgs()););
2025-
analysis.diagnose();
2051+
analysis.emitDiagnostics();
20262052
}
20272053
};
20282054

0 commit comments

Comments
 (0)