Skip to content

Commit cf503b9

Browse files
authored
Merge pull request #38397 from xedin/avoid-passing-closure-result-directly
[ConstraintSystem] NFC: Use stored result type while generating const…
2 parents b14f2b9 + 3e73f88 commit cf503b9

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

include/swift/Sema/ConstraintSystem.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -4096,10 +4096,9 @@ class ConstraintSystem {
40964096
/// Generate constraints for the body of the given closure.
40974097
///
40984098
/// \param closure the closure expression
4099-
/// \param resultType the closure's result type
41004099
///
41014100
/// \returns \c true if constraint generation failed, \c false otherwise
4102-
bool generateConstraints(ClosureExpr *closure, Type resultType);
4101+
bool generateConstraints(ClosureExpr *closure);
41034102

41044103
/// Generate constraints for the given (unchecked) expression.
41054104
///

lib/Sema/CSClosure.cpp

+8-12
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ class ClosureConstraintGenerator
3333

3434
ConstraintSystem &cs;
3535
ClosureExpr *closure;
36-
Type closureResultType;
3736

3837
public:
3938
/// Whether an error was encountered while generating constraints.
4039
bool hadError = false;
4140

42-
ClosureConstraintGenerator(ConstraintSystem &cs, ClosureExpr *closure,
43-
Type closureResultType)
44-
: cs(cs), closure(closure), closureResultType(closureResultType) { }
41+
ClosureConstraintGenerator(ConstraintSystem &cs, ClosureExpr *closure)
42+
: cs(cs), closure(closure) {}
4543

4644
private:
4745
void visitDecl(Decl *decl) {
@@ -95,11 +93,10 @@ class ClosureConstraintGenerator
9593

9694
// FIXME: Locator should point at the return statement?
9795
bool hasReturn = hasExplicitResult(closure);
98-
cs.addConstraint(
99-
ConstraintKind::Conversion, cs.getType(expr),
100-
closureResultType,
101-
cs.getConstraintLocator(
102-
closure, LocatorPathElt::ClosureBody(hasReturn)));
96+
cs.addConstraint(ConstraintKind::Conversion, cs.getType(expr),
97+
cs.getClosureType(closure)->getResult(),
98+
cs.getConstraintLocator(
99+
closure, LocatorPathElt::ClosureBody(hasReturn)));
103100
}
104101

105102
#define UNSUPPORTED_STMT(STMT) void visit##STMT##Stmt(STMT##Stmt *) { \
@@ -127,9 +124,8 @@ class ClosureConstraintGenerator
127124

128125
}
129126

130-
bool ConstraintSystem::generateConstraints(
131-
ClosureExpr *closure, Type resultType) {
132-
ClosureConstraintGenerator generator(*this, closure, resultType);
127+
bool ConstraintSystem::generateConstraints(ClosureExpr *closure) {
128+
ClosureConstraintGenerator generator(*this, closure);
133129
generator.visit(closure->getBody());
134130
return generator.hadError;
135131
}

lib/Sema/CSSimplify.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8950,7 +8950,7 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
89508950
// generate constraints for it now.
89518951
auto &ctx = getASTContext();
89528952
if (shouldTypeCheckInEnclosingExpression(closure)) {
8953-
if (generateConstraints(closure, closureType->getResult()))
8953+
if (generateConstraints(closure))
89548954
return false;
89558955
} else if (!hasExplicitResult(closure)) {
89568956
// If this closure has an empty body and no explicit result type

0 commit comments

Comments
 (0)