File tree Expand file tree Collapse file tree 4 files changed +44
-19
lines changed Expand file tree Collapse file tree 4 files changed +44
-19
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ add_swift_host_library(swiftSema STATIC
2
2
BuilderTransform.cpp
3
3
CSApply.cpp
4
4
CSBindings.cpp
5
+ CSClosure.cpp
5
6
CSGen.cpp
6
7
CSRanking.cpp
7
8
CSSimplify.cpp
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -4418,24 +4418,10 @@ bool ConstraintSystem::generateConstraints(
4418
4418
llvm_unreachable (" BOOM" );
4419
4419
}
4420
4420
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);
4439
4425
return generateConstraintsFor (*this , expr, dc);
4440
4426
}
4441
4427
Original file line number Diff line number Diff line change @@ -3587,7 +3587,8 @@ class ConstraintSystem {
3587
3587
// / Generate constraints for the given (unchecked) expression.
3588
3588
// /
3589
3589
// / \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 );
3591
3592
3592
3593
// / Generate constraints for binding the given pattern to the
3593
3594
// / value of the given expression.
You can’t perform that action at this time.
0 commit comments