@@ -55,6 +55,16 @@ using Region = PartitionPrimitives::Region;
55
55
56
56
} // namespace
57
57
58
+ // This option is used so we can test typed errors. Typed errors are a fallback
59
+ // case which are emitted when we are unable to infer the name of a value. We in
60
+ // most cases do succeed inferring, so it makes sense to add an asserts only
61
+ // option that can be used by the compiler to test that we emit these correctly.
62
+ static llvm::cl::opt<bool > ForceTypedErrors (
63
+ " sil-regionbasedisolation-force-use-of-typed-errors" ,
64
+ llvm::cl::desc (" Force the usage of typed instead of named errors to make "
65
+ " it easier to test typed errors" ),
66
+ llvm::cl::Hidden);
67
+
58
68
// ===----------------------------------------------------------------------===//
59
69
// MARK: Utilities
60
70
// ===----------------------------------------------------------------------===//
@@ -154,6 +164,23 @@ static Expr *inferArgumentExprFromApplyExpr(ApplyExpr *sourceApply,
154
164
return foundExpr;
155
165
}
156
166
167
+ // / Attempt to infer a name for \p value. Returns none if we fail or if we are
168
+ // / asked to force typed errors since we are testing.
169
+ static std::optional<Identifier> inferNameHelper (SILValue value) {
170
+ if (ForceTypedErrors)
171
+ return {};
172
+ return VariableNameInferrer::inferName (value);
173
+ }
174
+
175
+ // / Attempt to infer a name and root for \p value. Returns none if we fail or if
176
+ // / we are asked to force typed errors since we are testing.
177
+ static std::optional<std::pair<Identifier, SILValue>>
178
+ inferNameAndRootHelper (SILValue value) {
179
+ if (ForceTypedErrors)
180
+ return {};
181
+ return VariableNameInferrer::inferNameAndRoot (value);
182
+ }
183
+
157
184
// ===----------------------------------------------------------------------===//
158
185
// MARK: Diagnostics
159
186
// ===----------------------------------------------------------------------===//
@@ -894,8 +921,7 @@ bool UseAfterTransferDiagnosticInferrer::initForIsolatedPartialApply(
894
921
emittedDiagnostic = true ;
895
922
896
923
auto &state = transferringOpToStateMap.get (transferOp);
897
- if (auto rootValueAndName =
898
- VariableNameInferrer::inferNameAndRoot (transferOp->get ())) {
924
+ if (auto rootValueAndName = inferNameAndRootHelper (transferOp->get ())) {
899
925
diagnosticEmitter.emitNamedIsolationCrossingDueToCapture (
900
926
RegularLocation (std::get<0 >(p).getLoc ()), rootValueAndName->first ,
901
927
state.isolationInfo .getIsolationInfo (), std::get<2 >(p));
@@ -1066,8 +1092,7 @@ void UseAfterTransferDiagnosticInferrer::infer() {
1066
1092
.hasOption (SILParameterInfo::Sending)) {
1067
1093
1068
1094
// First try to do the named diagnostic if we can find a name.
1069
- if (auto rootValueAndName =
1070
- VariableNameInferrer::inferNameAndRoot (transferOp->get ())) {
1095
+ if (auto rootValueAndName = inferNameAndRootHelper (transferOp->get ())) {
1071
1096
return diagnosticEmitter.emitNamedUseOfStronglyTransferredValue (
1072
1097
baseLoc, rootValueAndName->first );
1073
1098
}
@@ -1093,8 +1118,7 @@ void UseAfterTransferDiagnosticInferrer::infer() {
1093
1118
if (auto *sourceApply = loc.getAsASTNode <ApplyExpr>()) {
1094
1119
// Before we do anything further, see if we can find a name and emit a name
1095
1120
// error.
1096
- if (auto rootValueAndName =
1097
- VariableNameInferrer::inferNameAndRoot (transferOp->get ())) {
1121
+ if (auto rootValueAndName = inferNameAndRootHelper (transferOp->get ())) {
1098
1122
auto &state = transferringOpToStateMap.get (transferOp);
1099
1123
return diagnosticEmitter.emitNamedIsolationCrossingError (
1100
1124
baseLoc, rootValueAndName->first ,
@@ -1579,7 +1603,7 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
1579
1603
1580
1604
// See if we can infer a name from the value.
1581
1605
SmallString<64 > resultingName;
1582
- if (auto varName = VariableNameInferrer::inferName (op->get ())) {
1606
+ if (auto varName = inferNameHelper (op->get ())) {
1583
1607
diagnosticEmitter.emitNamedFunctionArgumentApplyStronglyTransferred (
1584
1608
loc, *varName);
1585
1609
return true ;
@@ -1619,7 +1643,7 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
1619
1643
1620
1644
// See if we can infer a name from the value.
1621
1645
SmallString<64 > resultingName;
1622
- if (auto name = VariableNameInferrer::inferName (op->get ())) {
1646
+ if (auto name = inferNameHelper (op->get ())) {
1623
1647
diagnosticEmitter.emitNamedIsolation (loc, *name, *isolation);
1624
1648
return true ;
1625
1649
}
@@ -1667,7 +1691,7 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
1667
1691
" All result info must be the same... if that changes... update "
1668
1692
" this code!" );
1669
1693
SmallString<64 > resultingName;
1670
- if (auto name = VariableNameInferrer::inferName (op->get ())) {
1694
+ if (auto name = inferNameHelper (op->get ())) {
1671
1695
diagnosticEmitter.emitNamedTransferringReturn (loc, *name);
1672
1696
return true ;
1673
1697
}
@@ -1807,7 +1831,7 @@ class InOutSendingNotDisconnectedDiagnosticEmitter {
1807
1831
void InOutSendingNotDisconnectedDiagnosticEmitter::emit () {
1808
1832
// We should always be able to find a name for an inout sending param. If we
1809
1833
// do not, emit an unknown pattern error.
1810
- auto varName = VariableNameInferrer::inferName (info.inoutSendingParam );
1834
+ auto varName = inferNameHelper (info.inoutSendingParam );
1811
1835
if (!varName) {
1812
1836
return emitUnknownPatternError ();
1813
1837
}
0 commit comments