@@ -197,21 +197,18 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
197
197
// have to look through other elements that are generated from an argument
198
198
// conversion such as GenericArgument for an optional-to-optional conversion,
199
199
// and OptionalPayload for a value-to-optional conversion.
200
- auto applyArgEltIter =
201
- std::find_if (path.rbegin (), path.rend (), [](LocatorPathElt elt) {
202
- return elt.is <LocatorPathElt::ApplyArgToParam>();
203
- });
204
-
205
- if (applyArgEltIter == path.rend ())
200
+ auto iter = path.rbegin ();
201
+ auto applyArgElt = locator->findLast <LocatorPathElt::ApplyArgToParam>(iter);
202
+ if (!applyArgElt)
206
203
return None;
207
204
208
- assert ( std::find_if (applyArgEltIter + 1 , path. rend (), [](LocatorPathElt elt) {
209
- return elt. getKind () == ConstraintLocator ::ApplyArgToParam;
210
- }) == path. rend () && " Multiple ApplyArgToParam components?" );
205
+ auto nextIter = iter + 1 ;
206
+ assert (!locator-> findLast <LocatorPathElt ::ApplyArgToParam>(nextIter) &&
207
+ " Multiple ApplyArgToParam components?" );
211
208
212
209
// Form a new locator that ends at the apply-arg-to-param element, and
213
210
// simplify it to get the full argument expression.
214
- auto argPath = path.drop_back (applyArgEltIter - path.rbegin ());
211
+ auto argPath = path.drop_back (iter - path.rbegin ());
215
212
auto *argLocator = cs.getConstraintLocator (
216
213
anchor, argPath, ConstraintLocator::getSummaryFlagsForPath (argPath));
217
214
@@ -271,9 +268,8 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
271
268
fnInterfaceType = resolveInterfaceType (rawFnType);
272
269
}
273
270
274
- auto applyArgElt = applyArgEltIter->castTo <LocatorPathElt::ApplyArgToParam>();
275
- auto argIdx = applyArgElt.getArgIdx ();
276
- auto paramIdx = applyArgElt.getParamIdx ();
271
+ auto argIdx = applyArgElt->getArgIdx ();
272
+ auto paramIdx = applyArgElt->getParamIdx ();
277
273
278
274
return FunctionArgApplyInfo (argExpr, argIdx, getType (argExpr), paramIdx,
279
275
fnInterfaceType, fnType, callee);
@@ -409,12 +405,8 @@ GenericSignature *RequirementFailure::getSignature(ConstraintLocator *locator) {
409
405
if (isConditional ())
410
406
return Conformance->getGenericSignature ();
411
407
412
- auto path = locator->getPath ();
413
- for (auto iter = path.rbegin (); iter != path.rend (); ++iter) {
414
- const auto &elt = *iter;
415
- if (auto genericElt = elt.getAs <LocatorPathElt::OpenedGeneric>())
416
- return genericElt->getSignature ();
417
- }
408
+ if (auto genericElt = locator->findLast <LocatorPathElt::OpenedGeneric>())
409
+ return genericElt->getSignature ();
418
410
419
411
llvm_unreachable (" Type requirement failure should always have signature" );
420
412
}
@@ -3563,12 +3555,8 @@ bool KeyPathSubscriptIndexHashableFailure::diagnoseAsError() {
3563
3555
auto loc = anchor->getLoc ();
3564
3556
if (locator->isKeyPathSubscriptComponent ()) {
3565
3557
auto *KPE = cast<KeyPathExpr>(anchor);
3566
- for (auto &elt : locator->getPath ()) {
3567
- if (auto kpElt = elt.getAs <LocatorPathElt::KeyPathComponent>()) {
3568
- loc = KPE->getComponents ()[kpElt->getIndex ()].getLoc ();
3569
- break ;
3570
- }
3571
- }
3558
+ if (auto kpElt = locator->findFirst <LocatorPathElt::KeyPathComponent>())
3559
+ loc = KPE->getComponents ()[kpElt->getIndex ()].getLoc ();
3572
3560
}
3573
3561
3574
3562
emitDiagnostic (loc, diag::expr_keypath_subscript_index_not_hashable,
@@ -3581,14 +3569,9 @@ SourceLoc InvalidMemberRefInKeyPath::getLoc() const {
3581
3569
3582
3570
if (auto *KPE = dyn_cast<KeyPathExpr>(anchor)) {
3583
3571
auto *locator = getLocator ();
3584
- auto componentIter =
3585
- llvm::find_if (locator->getPath (), [](const LocatorPathElt &elt) {
3586
- return elt.isKeyPathComponent ();
3587
- });
3588
-
3589
- assert (componentIter != locator->getPath ().end ());
3590
- auto component = componentIter->castTo <LocatorPathElt::KeyPathComponent>();
3591
- return KPE->getComponents ()[component.getIndex ()].getLoc ();
3572
+ auto component = locator->findFirst <LocatorPathElt::KeyPathComponent>();
3573
+ assert (component);
3574
+ return KPE->getComponents ()[component->getIndex ()].getLoc ();
3592
3575
}
3593
3576
3594
3577
return anchor->getLoc ();
0 commit comments