@@ -241,6 +241,40 @@ static bool isProjectedFromAggregate(SILValue value) {
241
241
return visitor.isMerge ;
242
242
}
243
243
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
+
244
278
// ===----------------------------------------------------------------------===//
245
279
// MARK: Expr/Type Inference for Diagnostics
246
280
// ===----------------------------------------------------------------------===//
@@ -1893,7 +1927,7 @@ class PartitionAnalysis {
1893
1927
// / Once we have reached a fixpoint, this routine runs over all blocks again
1894
1928
// / reporting any failures by applying our ops to the converged dataflow
1895
1929
// / state.
1896
- void diagnose () {
1930
+ void emitDiagnostics () {
1897
1931
assert (solved && " diagnose should not be called before solve" );
1898
1932
1899
1933
LLVM_DEBUG (llvm::dbgs () << " Emitting diagnostics for function "
@@ -1933,9 +1967,7 @@ class PartitionAnalysis {
1933
1967
<< " Rep: "
1934
1968
<< *translator.getValueForId (transferredVal)
1935
1969
->getRepresentative ());
1936
- function->getASTContext ().Diags .diagnose (
1937
- partitionOp.getSourceLoc ().getSourceLoc (),
1938
- diag::arg_region_transferred);
1970
+ diagnose (partitionOp, diag::arg_region_transferred);
1939
1971
};
1940
1972
eval.nonTransferrableElements = translator.getNeverTransferredValues ();
1941
1973
eval.isActorDerivedCallback = [&](Element element) -> bool {
@@ -1970,14 +2002,10 @@ class PartitionAnalysis {
1970
2002
liveness.process (requireInsts);
1971
2003
1972
2004
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 ())
1981
2009
.highlight (transferOp->get ().getLoc ().getSourceRange ());
1982
2010
1983
2011
// Ok, we now have our requires... emit the errors.
@@ -1996,10 +2024,8 @@ class PartitionAnalysis {
1996
2024
if (!liveness.finalRequires .contains (require))
1997
2025
continue ;
1998
2026
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 ());
2003
2029
didEmitRequire = true ;
2004
2030
}
2005
2031
@@ -2022,7 +2048,7 @@ class PartitionAnalysis {
2022
2048
auto analysis = PartitionAnalysis (function);
2023
2049
analysis.solve ();
2024
2050
LLVM_DEBUG (llvm::dbgs () << " SOLVED: " ; analysis.print (llvm::dbgs ()););
2025
- analysis.diagnose ();
2051
+ analysis.emitDiagnostics ();
2026
2052
}
2027
2053
};
2028
2054
0 commit comments