Skip to content

Commit 7f242e5

Browse files
committed
[Function builders] Clean up locators in the builder transform.
Now that statements can be locators, we can clean up several FIXMEs. Also, add an appropriate ContextualType locator noticed by Pavel.
1 parent c513cf1 commit 7f242e5

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,7 @@ class BuilderClosureVisitor
551551
return nullptr;
552552
}
553553

554-
// FIXME: Need a locator for the "if" statement.
555-
Type resultType = cs->addJoinConstraint(nullptr,
554+
Type resultType = cs->addJoinConstraint(cs->getConstraintLocator(ifStmt),
556555
{
557556
{ cs->getType(thenExpr), cs->getConstraintLocator(thenExpr) },
558557
{ cs->getType(elseExpr), cs->getConstraintLocator(elseExpr) }
@@ -709,8 +708,8 @@ class BuilderClosureVisitor
709708
}
710709

711710
// Form the type of the switch itself.
712-
// FIXME: Need a locator for the "switch" statement.
713-
Type resultType = cs->addJoinConstraint(nullptr, injectedCaseTerms);
711+
Type resultType = cs->addJoinConstraint(
712+
cs->getConstraintLocator(switchStmt), injectedCaseTerms);
714713
if (!resultType) {
715714
hadError = true;
716715
return nullptr;
@@ -810,7 +809,8 @@ class BuilderClosureVisitor
810809
}
811810
cs->addConstraint(
812811
ConstraintKind::Equal, cs->getType(arrayInitExpr), arrayType,
813-
cs->getConstraintLocator(arrayInitExpr));
812+
cs->getConstraintLocator(
813+
arrayInitExpr, LocatorPathElt::ContextualType()));
814814

815815
// Form a call to Array.append(_:) to add the result of executing each
816816
// iteration of the loop body to the array formed above.
@@ -1477,32 +1477,10 @@ Optional<BraceStmt *> TypeChecker::applyFunctionBuilderBodyTransform(
14771477
// Build a constraint system in which we can check the body of the function.
14781478
ConstraintSystem cs(func, options);
14791479

1480-
// Find an expression... any expression... to use for a locator.
1481-
// FIXME: This is a hack because we don't have the notion of locators that
1482-
// refer to statements.
1483-
Expr *fakeAnchor = nullptr;
1484-
{
1485-
class FindExprWalker : public ASTWalker {
1486-
Expr *&fakeAnchor;
1487-
1488-
public:
1489-
explicit FindExprWalker(Expr *&fakeAnchor) : fakeAnchor(fakeAnchor) { }
1490-
1491-
std::pair<bool, Expr *> walkToExprPre(Expr *E) {
1492-
if (!fakeAnchor)
1493-
fakeAnchor = E;
1494-
1495-
return { false, nullptr };
1496-
}
1497-
} walker(fakeAnchor);
1498-
1499-
func->getBody()->walk(walker);
1500-
}
1501-
15021480
if (auto result = cs.matchFunctionBuilder(
15031481
func, builderType, resultContextType, resultConstraintKind,
1504-
/*calleeLocator=*/cs.getConstraintLocator(fakeAnchor),
1505-
/*FIXME:*/cs.getConstraintLocator(fakeAnchor))) {
1482+
cs.getConstraintLocator(func->getBody()),
1483+
cs.getConstraintLocator(func->getBody()))) {
15061484
if (result->isFailure())
15071485
return nullptr;
15081486
}

0 commit comments

Comments
 (0)