Commit Graph

47 Commits

Author SHA1 Message Date
Pavel Yaskevich
ff4aca308d [ConstraintSystem/Closures] Ignore all unsupported declarations during constraint generation
Everything besides `PatternBindingDecl` is handled at solution application time.
2021-10-08 10:08:03 -07:00
Pavel Yaskevich
c68a74a0c6 [ConstraintSystem/Closures] Allow return without result expression 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
dea609f78c [ConstraintSystem/Closures] Add support for do-catch statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
1324d1fe3f [ConstraintSystem/Closures] Add support for switch statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
0247652239 [ConstraintSystem/Closures] Add support for case statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
b1d6d3a92e [ConstraintSystem/Closures] Add support for for-in statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
8929d7e75e [ConstraintSystem/Closures] Add support for throw statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
305437c475 [ConstraintSystem/Closures] Add support for #assert statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
32b257bb0e [ConstraintSystem/Closures] Add support for continue statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
f6398d6687 [ConstraintSystem/Closures] Add support for break statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
880d862faf [ConstraintSystem/Closures] Add support for defer statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
00e98ff0ce [ConstraintSystem/Closures] Add support for fallthrough statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
9d89ae0773 [ConstraintSystem] Let closure body element simplification take advantage of contextual information 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
55bae6150d [Constraint] Allow closure body elements to carry contextual information 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
d74cb79ea3 [ConstraintSystem/Closures] Add support for repeat .. while statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
34538ef037 [ConstraintSystem/Closures] Add support for do statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
f999fa24e8 [ConstraintSystem/Closures] Add support for while statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
391b0c6f31 [ConstraintSystem/Closures] Add support for guard statement 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
cedb345878 [CSClosure] Further simplify conjunction creation for ASTNode elements 2021-10-08 10:08:02 -07:00
Pavel Yaskevich
a37b546b5e [CSClosure] Mark empty brace statements as non-viable elements
Such statements do not require any inference so could be safely
omitted from conjunctions.
2021-10-08 10:08:01 -07:00
Pavel Yaskevich
d81490516a [CSClosure] NFC: Simplify creation of non-isolated conjunctions for a set of ASTNodes 2021-10-08 10:08:01 -07:00
Pavel Yaskevich
a2d4ae3ba8 [ConstraintSystem/Closures] Add support for if statement 2021-10-08 10:08:01 -07:00
Pavel Yaskevich
2b7602e134 [CSClosure] Implement constraint generation for closure body elements 2021-10-08 10:08:01 -07:00
Pavel Yaskevich
91eecdb6d0 [CSClosure] Initial support for multi-statement closures
Implement constraint generation for brace statements and
refactor closure contraint generation to accept multi-statement
closures.
2021-10-08 10:08:01 -07:00
Pavel Yaskevich
73dffb3125 [ConstraintSystem] Don't require a type variable per closure body element
Since each of the body elements is already going to have a type associated
with it there is no need to create yet another type variable.
2021-10-08 10:08:01 -07:00
Pavel Yaskevich
eb8eabfba7 [ConstraintSystem] Add a skeleton of ClosureBodyElement constraint 2021-10-08 10:08:00 -07:00
Pavel Yaskevich
18128eeeec [CSClosure] Use rewritten expression when applying solution to a brace statement
It went un-noticed because currently only single-statement closures
using this logic and their bodies are modeled as a single return statement.
2021-08-11 13:44:59 -07:00
Pavel Yaskevich
3e73f88512 [ConstraintSystem] NFC: Use stored result type while generating constraints for closures
Instead of passing/storing result type to constraint generator,
let's retrieve it from the constraint system when needed.
2021-07-14 16:28:26 -07:00
Holly Borla
31f7b1ac75 [ConstraintSystem] Change the type of an unapplied function reference
when it has property wrapper parameters.

The property wrapper type will be replaced with either the wrapped-value
or projected-value type, depending on the argument label/parameter name,
and CSApply will build a thunk to construct the property wrapper and call
the function.
2021-02-25 18:35:13 -08:00
maustinstar
3913c31688 [SR-11711] Single-expression returns for #if declarations within closures 2020-11-03 12:48:05 -05:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Pavel Yaskevich
461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Pavel Yaskevich
f94be56468 [Sema] Decouple ConstraintSystem and TypeChecker headers 2020-10-06 13:18:49 -07:00
Hamish Knight
a7a8d9fd26 [AST] Remove NewBodyKind default
A bunch of callers were accidentally misusing it.
2020-09-04 13:24:34 -07:00
Rintaro Ishizaki
8425e1cf4f [AST] Rename TypeCheckedAtOnce to TypeCheckedWithSignature
To clarify the meaning
2020-07-24 10:48:51 -07:00
Rintaro Ishizaki
b1eec26653 [AST] Add a enum for type checking state of ClosureExpr's body 2020-07-24 10:46:03 -07:00
Doug Gregor
a4239370c8 [Constraint solver] Wire up "parents" of closure return statements. 2020-06-05 14:02:46 -07:00
Doug Gregor
a115ad9f5c [AST] Record "separately checked" in ClosureExpr.
Reverse the polarity of the "checked in context" bit for ClosureExpr
to "separately checked", which simplifies the AST walker logic (to
"should we walk separately type-checked closure bodies?") and
eliminates single-expression closures as a separate case to consider.
2020-06-05 00:05:11 -07:00
Doug Gregor
1d36224e74 [ClosureExpr] Remove hasAppliedFunctionBuilder.
There are no longer any clients of the "has applied function builder" bit
in ClosureExpr, so remove it.
2020-06-04 23:16:51 -07:00
Doug Gregor
836bc57fe5 [AST Walker] Stop visiting the bodies of closures as expressions.
Single-expression closures have always been traversed differently
from multi-statement closures. The former were traversed as if the
expression was their only child, skipping the BraceStmt and implicit
return, while the later was traversed as a normal BraceStmt.
Unify on the latter treatment, so that traversal

There are a few places where we unintentionally relied on this
expression-as-child behavior. Clean those up to work with arbitrary
closures, which is an overall simplification in the logic.
2020-06-04 23:06:32 -07:00
Doug Gregor
f55e7643fa [Constaint system] Add a predicate for when to check closures in enclosing expr
Introduce a new predicate, shouldTypeCheckInEnclosingExpression(), to
determine when the body of a closure should be checked as part of the
enclosing expression rather than separately, and use it in the various
places where "hasSingleExpressionBody()" was used for that purpose.
2020-06-03 22:48:58 -07:00
Doug Gregor
690d6c446b [AST] Record whether a closure was type-checked in its enclosing expression
Rather than using various "applied function builder" and "is single
expression body" checks to determine whether a closure was
type-checked in its enclosing expression, record in the closure
expression whether it actually *was* type-checked as part of its
enclosing expression.
2020-06-03 22:26:20 -07:00
Doug Gregor
761ee54006 [Constraint system] Use a visitor for solution application to closures.
Introduce a statement visitor that applies a particular solution to
the body of a closure. This matches the mechanism used by function
builders (and is similar to how we handle expressions in general),
simplifying the logic for handling
conversion-to-void-returning-closures and
conversion-from-Never-returning-bodies. It is a stepping stone for
type inference of multi-statement closures.
2020-05-31 00:03:56 -07:00
Doug Gregor
af048d6953 [Constraint system] Move solution application for closures to CSClosure.
Slim down CSApply.cpp by moving the logic for applying a solution to a
closure into CSClosure.cpp. Also, eliminate duplicated logic for applying
function builders to the body of a closure or function. This should
not change semantics at all.
2020-05-30 22:44:30 -07:00
Doug Gregor
b9b8f08f54 [Constraint system] Switch closure constraint generation to a visitor.
In preparation for implementing support for multiple-statement closure
inference, switch closure constraint generation over to a statement
visitor. Only the subset of statements that correspond to
single-expression closures is currently handled; there is no way to
enable this for multiple-statement closures yet.
2020-05-29 22:00:37 -07:00
Doug Gregor
451e3cc480 [Constraint system] Move closure type checking to a separate file. 2020-05-29 21:05:02 -07:00