@@ -92,34 +92,6 @@ static Expr *inferArgumentExprFromApplyExpr(ApplyExpr *sourceApply,
92
92
return foundExpr;
93
93
}
94
94
95
- static std::optional<Identifier> inferNameFromValue (SILValue value) {
96
- auto *fn = value->getFunction ();
97
- if (!fn)
98
- return {};
99
- VariableNameInferrer::Options options;
100
- options |= VariableNameInferrer::Flag::InferSelfThroughAllAccessors;
101
- SmallString<64 > resultingName;
102
- VariableNameInferrer inferrer (fn, options, resultingName);
103
- if (!inferrer.inferByWalkingUsesToDefsReturningRoot (value))
104
- return {};
105
- return fn->getASTContext ().getIdentifier (resultingName);
106
- }
107
-
108
- static std::optional<std::pair<Identifier, SILValue>>
109
- inferNameAndRootFromValue (SILValue value) {
110
- auto *fn = value->getFunction ();
111
- if (!fn)
112
- return {};
113
- VariableNameInferrer::Options options;
114
- options |= VariableNameInferrer::Flag::InferSelfThroughAllAccessors;
115
- SmallString<64 > resultingName;
116
- VariableNameInferrer inferrer (fn, options, resultingName);
117
- SILValue rootValue = inferrer.inferByWalkingUsesToDefsReturningRoot (value);
118
- if (!rootValue)
119
- return {};
120
- return {{fn->getASTContext ().getIdentifier (resultingName), rootValue}};
121
- }
122
-
123
95
// ===----------------------------------------------------------------------===//
124
96
// MARK: Diagnostics
125
97
// ===----------------------------------------------------------------------===//
@@ -693,7 +665,8 @@ bool UseAfterTransferDiagnosticInferrer::initForIsolatedPartialApply(
693
665
emittedDiagnostic = true ;
694
666
695
667
auto &state = transferringOpToStateMap.get (transferOp);
696
- if (auto rootValueAndName = inferNameAndRootFromValue (transferOp->get ())) {
668
+ if (auto rootValueAndName =
669
+ VariableNameInferrer::inferNameAndRoot (transferOp->get ())) {
697
670
diagnosticEmitter.emitNamedIsolationCrossingDueToCapture (
698
671
RegularLocation (std::get<0 >(p).getLoc ()), rootValueAndName->first ,
699
672
state.isolationInfo , std::get<2 >(p));
@@ -815,7 +788,7 @@ void UseAfterTransferDiagnosticInferrer::infer() {
815
788
816
789
// First try to do the named diagnostic if we can find a name.
817
790
if (auto rootValueAndName =
818
- inferNameAndRootFromValue (transferOp->get ())) {
791
+ VariableNameInferrer::inferNameAndRoot (transferOp->get ())) {
819
792
return diagnosticEmitter.emitNamedUseOfStronglyTransferredValue (
820
793
baseLoc, rootValueAndName->first );
821
794
}
@@ -841,7 +814,8 @@ void UseAfterTransferDiagnosticInferrer::infer() {
841
814
if (auto *sourceApply = loc.getAsASTNode <ApplyExpr>()) {
842
815
// Before we do anything further, see if we can find a name and emit a name
843
816
// error.
844
- if (auto rootValueAndName = inferNameAndRootFromValue (transferOp->get ())) {
817
+ if (auto rootValueAndName =
818
+ VariableNameInferrer::inferNameAndRoot (transferOp->get ())) {
845
819
auto &state = transferringOpToStateMap.get (transferOp);
846
820
return diagnosticEmitter.emitNamedIsolationCrossingError (
847
821
baseLoc, rootValueAndName->first , state.isolationInfo ,
@@ -1178,7 +1152,7 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
1178
1152
1179
1153
// See if we can infer a name from the value.
1180
1154
SmallString<64 > resultingName;
1181
- if (auto varName = inferNameFromValue (op->get ())) {
1155
+ if (auto varName = VariableNameInferrer::inferName (op->get ())) {
1182
1156
diagnosticEmitter.emitNamedFunctionArgumentApplyStronglyTransferred (
1183
1157
loc, *varName);
1184
1158
return true ;
@@ -1218,7 +1192,7 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
1218
1192
1219
1193
// See if we can infer a name from the value.
1220
1194
SmallString<64 > resultingName;
1221
- if (auto name = inferNameFromValue (op->get ())) {
1195
+ if (auto name = VariableNameInferrer::inferName (op->get ())) {
1222
1196
diagnosticEmitter.emitNamedIsolation (loc, *name, *isolation);
1223
1197
return true ;
1224
1198
}
@@ -1266,7 +1240,7 @@ bool TransferNonTransferrableDiagnosticInferrer::run() {
1266
1240
" All result info must be the same... if that changes... update "
1267
1241
" this code!" );
1268
1242
SmallString<64 > resultingName;
1269
- if (auto name = inferNameFromValue (op->get ())) {
1243
+ if (auto name = VariableNameInferrer::inferName (op->get ())) {
1270
1244
diagnosticEmitter.emitNamedTransferringReturn (loc, *name);
1271
1245
return true ;
1272
1246
}
0 commit comments