Skip to content

Commit 451e3cc

Browse files
committed
[Constraint system] Move closure type checking to a separate file.
1 parent 618b753 commit 451e3cc

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

lib/Sema/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ add_swift_host_library(swiftSema STATIC
22
BuilderTransform.cpp
33
CSApply.cpp
44
CSBindings.cpp
5+
CSClosure.cpp
56
CSGen.cpp
67
CSRanking.cpp
78
CSSimplify.cpp

lib/Sema/CSClosure.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- CSClosure.cpp - Closures -----------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file implements constraint generation and solution application for
14+
// closures. It provides part of the implementation of the ConstraintSystem
15+
// class.
16+
//
17+
//===----------------------------------------------------------------------===//
18+
19+
#include "ConstraintSystem.h"
20+
using namespace swift;
21+
using namespace swift::constraints;
22+
23+
bool ConstraintSystem::generateConstraints(
24+
ClosureExpr *closure, Type resultType) {
25+
assert(closure->hasSingleExpressionBody());
26+
auto closureBody = generateConstraints(
27+
closure->getSingleExpressionBody(), closure, /*isInputExpression=*/false);
28+
if (!closureBody)
29+
return true;
30+
31+
bool hasReturn = hasExplicitResult(closure);
32+
addConstraint(
33+
ConstraintKind::Conversion, getType(closureBody),
34+
resultType,
35+
getConstraintLocator(closure, LocatorPathElt::ClosureBody(hasReturn)));
36+
return false;
37+
}

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,24 +4418,10 @@ bool ConstraintSystem::generateConstraints(
44184418
llvm_unreachable("BOOM");
44194419
}
44204420

4421-
bool ConstraintSystem::generateConstraints(
4422-
ClosureExpr *closure, Type resultType) {
4423-
assert(closure->hasSingleExpressionBody());
4424-
auto closureBody = generateConstraintsFor(
4425-
*this, closure->getSingleExpressionBody(), closure);
4426-
if (!closureBody)
4427-
return true;
4428-
4429-
bool hasReturn = hasExplicitResult(closure);
4430-
addConstraint(
4431-
ConstraintKind::Conversion, getType(closureBody),
4432-
resultType,
4433-
getConstraintLocator(closure, LocatorPathElt::ClosureBody(hasReturn)));
4434-
return false;
4435-
}
4436-
4437-
Expr *ConstraintSystem::generateConstraints(Expr *expr, DeclContext *dc) {
4438-
InputExprs.insert(expr);
4421+
Expr *ConstraintSystem::generateConstraints(
4422+
Expr *expr, DeclContext *dc, bool isInputExpression) {
4423+
if (isInputExpression)
4424+
InputExprs.insert(expr);
44394425
return generateConstraintsFor(*this, expr, dc);
44404426
}
44414427

lib/Sema/ConstraintSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3587,7 +3587,8 @@ class ConstraintSystem {
35873587
/// Generate constraints for the given (unchecked) expression.
35883588
///
35893589
/// \returns a possibly-sanitized expression, or null if an error occurred.
3590-
Expr *generateConstraints(Expr *E, DeclContext *dc);
3590+
Expr *generateConstraints(Expr *E, DeclContext *dc,
3591+
bool isInputExpression = true);
35913592

35923593
/// Generate constraints for binding the given pattern to the
35933594
/// value of the given expression.

0 commit comments

Comments
 (0)