Skip to content

Commit 926066a

Browse files
authored
Merge pull request #28498 from hamishknight/warranty-void
2 parents 27db9f9 + 7edbd93 commit 926066a

File tree

6 files changed

+53
-25
lines changed

6 files changed

+53
-25
lines changed

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,8 +1235,8 @@ namespace {
12351235
if (selected->choice.getKind() == OverloadChoiceKind::DeclViaDynamic) {
12361236
// Rewrite for implicit unwrapping if the solution requires it.
12371237
auto *dynamicLocator = cs.getConstraintLocator(
1238-
locator.withPathElement(ConstraintLocator::SubscriptMember)
1239-
.withPathElement(ConstraintLocator::DynamicLookupResult));
1238+
locator, {ConstraintLocator::SubscriptMember,
1239+
ConstraintLocator::DynamicLookupResult});
12401240

12411241
if (solution.getDisjunctionChoice(dynamicLocator)) {
12421242
auto *forceValue = new (cs.getASTContext())
@@ -6992,9 +6992,9 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, ConcreteDeclRef callee,
69926992

69936993
// We're constructing a value of nominal type. Look for the constructor or
69946994
// enum element to use.
6995-
auto ctorLocator = cs.getConstraintLocator(
6996-
locator.withPathElement(ConstraintLocator::ApplyFunction)
6997-
.withPathElement(ConstraintLocator::ConstructorMember));
6995+
auto *ctorLocator =
6996+
cs.getConstraintLocator(locator, {ConstraintLocator::ApplyFunction,
6997+
ConstraintLocator::ConstructorMember});
69986998
auto selected = solution.getOverloadChoiceIfAvailable(ctorLocator);
69996999
if (!selected) {
70007000
assert(ty->hasError() || ty->hasUnresolvedType());

lib/Sema/CSGen.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,6 @@ namespace {
18521852

18531853
// Introduce conversions from each element to the element type of the
18541854
// array.
1855-
ConstraintLocatorBuilder builder(locator);
18561855
unsigned index = 0;
18571856
for (auto element : expr->getElements()) {
18581857
CS.addConstraint(ConstraintKind::Conversion,

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,9 @@ class ArgumentFailureTracker : public MatchCallArgumentListener {
860860

861861
unsigned newArgIdx = Arguments.size();
862862
auto *argLoc = CS.getConstraintLocator(
863-
Locator
864-
.withPathElement(LocatorPathElt::ApplyArgToParam(
865-
newArgIdx, paramIdx, param.getParameterFlags()))
866-
.withPathElement(LocatorPathElt::SynthesizedArgument(newArgIdx)));
863+
Locator, {LocatorPathElt::ApplyArgToParam(newArgIdx, paramIdx,
864+
param.getParameterFlags()),
865+
LocatorPathElt::SynthesizedArgument(newArgIdx)});
867866

868867
auto *argType =
869868
CS.createTypeVariable(argLoc, TVO_CanBindToInOut | TVO_CanBindToLValue |
@@ -4523,12 +4522,10 @@ ConstraintSystem::simplifyConstructionConstraint(
45234522
/*canonicalVararg=*/false);
45244523
Type resultType = fnType->getResult();
45254524

4526-
if (matchTypes(resultType, desugarValueType,
4527-
ConstraintKind::Bind,
4528-
flags,
4529-
ConstraintLocatorBuilder(locator)
4530-
.withPathElement(ConstraintLocator::ApplyFunction))
4531-
.isFailure())
4525+
ConstraintLocatorBuilder builder(locator);
4526+
if (matchTypes(resultType, desugarValueType, ConstraintKind::Bind, flags,
4527+
builder.withPathElement(ConstraintLocator::ApplyFunction))
4528+
.isFailure())
45324529
return SolutionKind::Error;
45334530

45344531
return matchTypes(argType, valueType, ConstraintKind::Conversion,

lib/Sema/ConstraintLocator.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,10 @@ class ConstraintLocatorBuilder {
811811
: previous(locator), element(),
812812
summaryFlags(locator ? locator->getSummaryFlags() : 0) { }
813813

814-
/// Retrieve a new path with the given path element added to it.
815-
ConstraintLocatorBuilder withPathElement(LocatorPathElt newElt) {
814+
/// Retrieve a new path with the given path element added to it. Note that
815+
/// the produced locator stores a reference to this locator, and therefore
816+
/// must not outlive it.
817+
ConstraintLocatorBuilder withPathElement(LocatorPathElt newElt) & {
816818
unsigned newFlags = summaryFlags | newElt.getNewSummaryFlags();
817819
if (!element)
818820
return ConstraintLocatorBuilder(previous, newElt, newFlags);

lib/Sema/ConstraintSystem.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,25 @@ ConstraintLocator *ConstraintSystem::getConstraintLocator(
413413
return getConstraintLocator(anchor, path, builder.getSummaryFlags());
414414
}
415415

416+
ConstraintLocator *ConstraintSystem::getConstraintLocator(
417+
ConstraintLocator *locator,
418+
ArrayRef<ConstraintLocator::PathElement> newElts) {
419+
auto oldPath = locator->getPath();
420+
SmallVector<ConstraintLocator::PathElement, 4> newPath;
421+
newPath.append(oldPath.begin(), oldPath.end());
422+
newPath.append(newElts.begin(), newElts.end());
423+
return getConstraintLocator(locator->getAnchor(), newPath);
424+
}
425+
426+
ConstraintLocator *ConstraintSystem::getConstraintLocator(
427+
const ConstraintLocatorBuilder &builder,
428+
ArrayRef<ConstraintLocator::PathElement> newElts) {
429+
SmallVector<ConstraintLocator::PathElement, 4> newPath;
430+
auto *anchor = builder.getLocatorParts(newPath);
431+
newPath.append(newElts.begin(), newElts.end());
432+
return getConstraintLocator(anchor, newPath);
433+
}
434+
416435
ConstraintLocator *
417436
ConstraintSystem::getCalleeLocator(ConstraintLocator *locator,
418437
bool lookThroughApply) {
@@ -1218,11 +1237,11 @@ void ConstraintSystem::openGenericRequirements(
12181237
break;
12191238
}
12201239

1221-
addConstraint(
1222-
*openedReq,
1223-
locator.withPathElement(LocatorPathElt::OpenedGeneric(signature))
1224-
.withPathElement(
1225-
LocatorPathElt::TypeParameterRequirement(pos, kind)));
1240+
auto openedGenericLoc =
1241+
locator.withPathElement(LocatorPathElt::OpenedGeneric(signature));
1242+
addConstraint(*openedReq,
1243+
openedGenericLoc.withPathElement(
1244+
LocatorPathElt::TypeParameterRequirement(pos, kind)));
12261245
}
12271246
}
12281247

lib/Sema/ConstraintSystem.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,10 +2024,21 @@ class ConstraintSystem {
20242024
ConstraintLocator *
20252025
getConstraintLocator(ConstraintLocator *locator,
20262026
ConstraintLocator::PathElement pathElt) {
2027-
return getConstraintLocator(ConstraintLocatorBuilder(locator)
2028-
.withPathElement(pathElt));
2027+
ConstraintLocatorBuilder builder(locator);
2028+
return getConstraintLocator(builder.withPathElement(pathElt));
20292029
}
20302030

2031+
/// Extend the given constraint locator with an array of path elements.
2032+
ConstraintLocator *
2033+
getConstraintLocator(ConstraintLocator *locator,
2034+
ArrayRef<ConstraintLocator::PathElement> newElts);
2035+
2036+
/// Retrieve the locator described by a given builder extended by an array of
2037+
/// path elements.
2038+
ConstraintLocator *
2039+
getConstraintLocator(const ConstraintLocatorBuilder &builder,
2040+
ArrayRef<ConstraintLocator::PathElement> newElts);
2041+
20312042
/// Retrieve the constraint locator described by the given
20322043
/// builder.
20332044
ConstraintLocator *

0 commit comments

Comments
 (0)