Commit Graph

214 Commits

Author SHA1 Message Date
Holly Borla
87bb7755c2 Merge pull request #30101 from hborla/dynamic-replacement-type-erasure
[Sema] Implement type erasure for dynamic replacement.
2020-02-28 09:37:33 -08:00
Holly Borla
3cdc30ffeb [Sema] Support type erasure for dynamic replacement in function
builders.
2020-02-27 09:01:16 -08:00
Doug Gregor
8482516412 [Constraint system] Properly deal with "as" patterns.
Teach pattern matching involving "as" patterns to work properly in
function builders. The code almost handled this, but prematurely
prechecking expressions in patterns broke it.
2020-02-25 16:29:07 -08:00
Doug Gregor
141f3e7f07 [Constraint system] Expand SolutionApplicationTarget to StmtConditions.
Handle StmtCondition as part of SolutionApplicationTarget, so we can
generate constraints from it and rewrite directly as part of a solution,
rather than open-coding the operation in the function builder transform.
2020-02-25 13:47:26 -08:00
Doug Gregor
4830c48960 [Constraint system] Support if let / if case in function builders.
Use the generalized constraint generation and binding for patterns to
introduce support for if-let and if-case in function builders, handling
arbitrary patterns.

Part of function builder generalization, rdar://problem/50426203.
2020-02-25 09:44:06 -08:00
Doug Gregor
3f2f79a699 [Constraint system] Fold pattern variable binding into constraint gen.
Rather than re-walk the pattern to create type bindings for the variables
that show up in the pattern, assign types to each of the variables as part
of constraint generation for the pattern. Only do this in contexts
where we will need the types, e.g., function builders.
2020-02-25 08:51:56 -08:00
Hamish Knight
1a9764e6d7 [CS] Remove SubExpressionDiagnostics option 2020-02-19 07:43:59 -08:00
Doug Gregor
5e28c7c886 [Constraint System] Move bindVariablesInPattern into the constraint system.
This general notion of wiring up the types of variables that occur
within a pattern to the types in the produced pattern type is useful
outside of function builders, too.
2020-02-13 10:51:26 -08:00
Doug Gregor
08315b102d Merge pull request #29786 from DougGregor/function-builders-let-decls
Allow initialized let/var declarations in function builders.
2020-02-12 20:50:28 -08:00
Doug Gregor
d4cd5e0ebc Merge pull request #29801 from DougGregor/constraint-solver-rewrite-target
[Constraint system] Factor out application to a SolutionApplicationTarget
2020-02-12 20:24:41 -08:00
Doug Gregor
2347829324 [Constraint System] Allow initialized let/var declarations in function builders.
Introduce support for initialized let/var declarations within function
builder closures, e.g.,

    let (a, b) = c()

We generate constraints for the declarations as elsewhere, but the types of
the declared variables (a and b in this case) are bound to the type of the
pattern by one-way constraints, to describe the flow of type information
through the closure.

Implements rdar://problem/57330696.
2020-02-12 17:51:48 -08:00
Doug Gregor
7f9029071d [Constraint system] Adopt rewriteTarget for function builder transform.
When applying a function builder to a closure to produce the final,
type-checked closure, use the new rewriteTarget() so it’s performed on
a per-target basis. Use this to eliminate some duplicating in the handling
of return types.
2020-02-12 17:51:47 -08:00
Doug Gregor
151fc79264 Merge pull request #29770 from DougGregor/builder-transform-node-types
[Constraint solver] Fix handling of node types for function builder application
2020-02-11 17:21:16 -08:00
Doug Gregor
4c98b31031 [Constraint solver] Apply solution to the system before builder transform.
This makes sure we can find information in the constraint system during
application. Fixes rdar://problem/59239224
2020-02-11 15:14:44 -08:00
Robert Widmann
d2360d2e8c [Gardening] dyn_cast -> isa 2020-02-07 16:09:31 -08:00
Holly Borla
778f8941ee [MiscDiagnostics] Walk into the body of a non single-statement closure
if the closure had a function builder transform applied.

This way, function builder closures can have syntactic restrictions
diagnosed the same way as other expressions.
2020-02-04 16:29:02 -08:00
Doug Gregor
3981a68a76 Merge pull request #29626 from DougGregor/function-builders-single-expr-closures-return
[Constraint solver] Fix function builders with single-expression closures
2020-02-03 23:10:51 -08:00
Doug Gregor
f8eee50310 [Constraint solver] Fix function builders with single-expression closures
Fix a few related issues involving the interaction with
single-expression closures:

* A single-expression closure can have a "return" in it; in such
cases, disable the function-builder transform.
* Have the function builder constraint generator look through the
"return" statement in a single-expression closure the same way as
solution application does

Fixes rdar://problem/59045763, where we rejected some well-formed code
involving a single-expression closure with a "return" keyword.
2020-02-03 17:52:44 -08:00
Pavel Yaskevich
7453d53e48 [TypeChecker/BuilderTransform] Switch to use hasLValueType instead of is<LValueType> to cover all cases where load is expected 2020-02-03 12:40:28 -08:00
Pavel Yaskevich
6d671020b9 [TypeChecker/BuilderTransform] Make sure implicit load expression updates types in AST
Can't use `ConstraintSystem::addImplicitLoadExpr` because that would
only cache types in constraint system and wouldn't propagate them to AST,
since that happens in `ExprRewritter::finalize` during regular solution
application. `TypeChecker::addImplicitLoadExpr` should be used directly
in cases like that.

Resolves: rdar://problem/58972627
2020-02-03 11:45:55 -08:00
Doug Gregor
eb2862ec1e [Constraint system] Collapse applySolutionImpl() into applySolution().
Now that we have a unified notion of a SolutionApplicationTarget, use it
to collapse 3 applySolution-ish functions into one.
2020-01-30 22:01:12 -08:00
Doug Gregor
cc44f22f43 [Function builder] Eliminate unnecessary dependency on UnderlyingTypeForOpaqueReturnType. 2020-01-27 15:01:09 -08:00
Doug Gregor
23615ba55d [Function builders] Add support for "if #available".
Availability checks in if statements don't need any actual semantic
checking, so enable them within function builders.
2020-01-23 22:00:41 -08:00
Doug Gregor
7217cfa4a5 [Constraint system] Move statement condition constraint generation.
Move constraint generation for statement conditions onto the
constraint system; it doesn't really have any reason to be located
within the function builder transform.
2020-01-23 21:51:53 -08:00
Doug Gregor
6238923e15 [Function builders] Support multiple Boolean conditions in 'if' statements
Generalize support for function builders to allow 'if' statements that
include multiple Boolean conditions, e.g., "if a, b, c, { ... }".
2020-01-23 17:04:17 -08:00
Doug Gregor
70300ada57 [Function builders] Perform syntactic use checks within function builders. 2020-01-22 22:22:36 -08:00
Doug Gregor
2b70025772 [Builder transform] Give generated pattern bindings proper source locations.
ASTScopes completely skip implicit pattern bindings, so don't mark
generated ones as implicit. Instead, give them suitable source
location information.

Fixes rdar://problem/58710568.
2020-01-21 10:12:48 -08:00
Doug Gregor
8283a67648 Revert "Revert "Reimplement function builders as statement transformations."" 2020-01-21 10:07:20 -08:00
Doug Gregor
86c13d3c74 Revert "Reimplement function builders as statement transformations." 2020-01-17 15:52:49 -08:00
Doug Gregor
bfa6d7316d [Function builders] Fake Expr-based locators for now.
The right solution is to extend the notion of the "anchor" of a locator
to also cover statements (and TypeReprs, and Patterns, and more), so
this is a stop-gap.
2020-01-16 13:19:21 -08:00
Doug Gregor
cf96e6559a [Function builders] Minor fixes for lvalue-ness, interface types 2020-01-16 13:19:21 -08:00
Doug Gregor
a49f0091cb [Constraint application] Skip error expressions when applying builders.
If we encountered an error, just skip it; there's nothing more to do.
2020-01-16 13:19:21 -08:00
Doug Gregor
f959ace180 [Function builders] Minor fixes for "load" expr generation 2020-01-16 13:18:33 -08:00
Doug Gregor
c8acc0fc43 [Function builders] Minor fixes for builder transform refactoring.
A couple of trivial fixes as part of the builder transform refactoring:
* When recording captured expressions, record the source entity appropriately
* Make sure to check (and skip) #if declarations in application
* Check and diagnostic #warning/#error as part of application (not generation)
* Simplify the body result type for return coercion during application
* When checking for applicability of a function builder, don't do any
  constraint generation.
2020-01-16 13:18:33 -08:00
Doug Gregor
3a51d5b9b2 [WIP] Reimplement function builders as statement transformations. 2020-01-16 13:18:33 -08:00
Doug Gregor
71350bdb7b Generalize some mentions of closures in function builder application 2020-01-16 13:18:33 -08:00
Doug Gregor
9e6f6d8d3b Rename FunctionBuilderClosurePreCheck -> FunctionBuilderBodyPreCheck 2020-01-16 13:18:33 -08:00
Pavel Yaskevich
af82e6f11b [TypeChecker] Use special locator while matching function builder body to closure result type 2020-01-14 00:09:33 -08:00
Pavel Yaskevich
9dc2dfde98 [ConstraintSystem] Allow single-statement closures be used with function builders
While resolving closure use contextual locator information to
determine whether given contextual type comes from a "function builder"
parameter and if so, use special `applyFunctionBuilder` to open
closure body instead of regular constraint generation.
2020-01-14 00:09:32 -08:00
Doug Gregor
5b320992ea [Constraint solver] Use a constraint system to apply all function builders.
When type checking the body of a function declaration that has a function
builder on it (e.g., `@ViewBuilder var body: some View { ... }`), create a
constraint system that is responsible for constraint generation and
application, sending function declarations through the same code paths
used by closures.
2020-01-09 14:38:45 -08:00
Doug Gregor
ac24491dae [Constraint system] Generalize function builder application APIs.
Teach the constraint system to handle matching a function builder to a
function as well as a closure.
2020-01-08 16:19:44 -08:00
Doug Gregor
fffe1291fa [Constraint system] Generalize record of transformed function builders. 2020-01-06 11:39:11 -08:00
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Doug Gregor
6022b3838f [Function builders] Handle #warning and #error
Fixes rdar://problem/53209000.
2019-12-05 23:24:41 -08:00
Robert Widmann
301e042121 Add PreCheckFunctionBuilderRequest
Drop a cache out of the type checker.
2019-11-10 14:18:54 -08:00
Robert Widmann
535150c7c6 Move preCheckExpression to ConstraintSystem 2019-11-10 13:48:03 -08:00
Robert Widmann
7bad9aacc3 Drop the TypeChecker out of ConstraintSystem 2019-11-10 13:26:47 -08:00
Doug Gregor
37c89f1c41 [Function builders] allowOneWay->oneWay and clean up some logic 2019-11-06 08:39:47 -08:00
Hamish Knight
424112fa26 applyFunctionBuilderBodyTransform can be static 2019-10-30 07:56:33 -07:00