Commit Graph

214 Commits

Author SHA1 Message Date
Hamish Knight
db2a9a470b Merge pull request #60803 from hamishknight/part-and-partial 2022-08-31 14:57:53 +01:00
Holly Borla
ca08b56fd3 Merge pull request #60844 from hborla/generic-result-builder
[ConstraintSystem] Before applying the result builder transform to a function body, map the result builder type into context.
2022-08-30 08:06:58 -07:00
Holly Borla
8ba51888c6 [ConstraintSystem] Before applying the result builder transform to a
function body, map the result builder type into context.

This was already done for inferred result builder attributes; now,
the constraint system will map the builder type into context for all
result builder attributes applied to computed properties/functions.
2022-08-29 22:13:13 -07:00
Hamish Knight
cebcbb0767 [CS] Improve diagnostics when buildPartialBlock is unavailable
If `buildBlock` is also unavailable, or the
builder itself is unavailable, continue to solve
using `buildPartialBlock` to get better
diagnostics.

This behavior technically differs from what is
specified in SE-0348, but only affects the invalid
case where no builder methods are available to use.

In particular, this improves diagnostics for
RegexComponentBuilder when the deployment target
is too low. Previously we would try to solve using
`buildBlock` (as `buildPartialBlock` is unavailable),
but RegexComponentBuilder only defines `buildBlock`
for the empty body case, leading to unhelpful
diagnostics that ultimately preferred not to use
the result builder at all.

rdar://97533700
2022-08-26 19:45:03 +01:00
Hamish Knight
dd1da22b16 [CS] Separate availability checking from SupportedOps cache
Previously we would cache the result of the first
query, with any further query of
`ResultBuilder::supports` ignoring the
`checkAvailability` parameter. Separate out the
availability checking such that we compute the
information up front, and adjust the result
depending on `checkAvailability`.
2022-08-26 19:45:02 +01:00
Suyash Srijan
390d8cc44b [IDE] Add result builder code completion for buildPartialBlock (#60669) 2022-08-20 15:36:15 +01:00
Pavel Yaskevich
93417d9f94 Merge pull request #60495 from amritpan/refactor-solver-state-indents
[ConstraintSystem] NFC: Refactor solver state depth to its own function fo…
2022-08-11 00:30:09 -07:00
Ben Barham
a59fa46813 Merge pull request #60426 from bnbarham/include-smallvec
[Basic] Include SmallVector.h for Clang <= 5
2022-08-10 15:54:48 -07:00
Amritpan Kaur
fd41a39294 [ConstraintSystem] Refactor solver state depth to its own function for easier indent editing in future. 2022-08-10 13:29:02 -07:00
Pavel Yaskevich
2ebc7a266c Merge pull request #60449 from xedin/dont-erase-result-during-transform
[ResultBuilder] AST transform: don't try type erasure of result expressions
2022-08-09 11:30:06 -07:00
Pavel Yaskevich
422dbe493a [ResultBuilder] AST transform: don't try type erasure of result expressions
Constraint generation is going to erase when appropriate and rewrite the target,
no need to do that explicitly during result builder transform.
2022-08-08 13:43:28 -07:00
Pavel Yaskevich
b39302a585 Merge pull request #60203 from xedin/rdar-96997534
[CSGen] Allow `_` pattern to be a hole
2022-08-08 10:14:18 -07:00
Ben Barham
6de34f37e5 [NFC] Revert SmallVector<T> -> SmallVector<T, N> fixes
With the change to include `SmallVector.h` directly in `LLVM.h` rather
than forward declaring in the only case it matters (ie. Clang <= 5),
these fixes are no longer needed. Since defaulted version is preferred
when there's no better choice (which is presumably the case if that's
how they were originally added), use it instead. Some uses were instead
changed to add `llvm::` so remove that too.
2022-08-05 21:25:55 -07:00
Pavel Yaskevich
f43aad2222 [BuilderTransform] Use correct locator for case subject expressions
Instead of `CTP_Initialization` transform should use `CTP_CaseStmt`
to identify the root correctly.
2022-08-03 15:50:33 -07:00
Meghana Gupta
d58560e65c Fix source to use template <typename T, unsigned N> class SmallVector
The SmallVector version with default template does not compile with older compiler versions
2022-08-03 12:00:57 -07:00
Alex Hoppen
a368f024bb [TypeChecker] Use the brace statement as the start location of a buildLimitedAvailability call
Otherwise, the call to buildLimitedAvailability has a bigger source range than the brace statement that surrounds it, causing a verification failure.
2022-08-02 11:59:03 -07:00
Pavel Yaskevich
186bf0ab3b [BuilderTransform] Cache previously applied transforms
Since result builder is just an AST transformation, the result
of a successful transform could be cache and reused with a different
`$__builderSelf` type.
2022-08-02 11:59:03 -07:00
Pavel Yaskevich
04952fdc0a [TypeChecker] Implement result builder transform via AST modification
The transform changes closure body into a multi-statement closure
with all of the implicit result builder calls and type-checks it
like a regular closure.

There are a couple of result builder specific changes mentioned below,
otherwise the logic to generate constraints and apply solutions is
unchanged:

- Placeholder variable: A variable declaration that doesn't have a
  type deduced and infers it from its first use. If such a variable
  has an initializer, it would be type-checked during solution application.

- TypeJoinExpr - an implicit expression that refers to a "join" variable
  and a set of expressions that should all produce the same type that
  becomes a type of a "join" variable.
2022-08-02 11:59:03 -07:00
Pavel Yaskevich
8850dcfea4 [BuilderTransform] Move some of the common logic into a base class
The base class is intended to facilitate logic sharing between
existing one-way constraint based transform and the new AST one.
2022-08-02 11:03:26 -07:00
Pavel Yaskevich
22daa865b5 [ConstraintSystem] Make for-in solution application target standalone
Previously for-in target was actually an expression target, which means
certain type-checking behavior. These changes make it a standalone target
with custom behavior which would allow solver to introduce implicit
`makeIterator` and `next` calls and move some logic from SILGen.
2022-05-30 23:17:41 -07:00
Pavel Yaskevich
9773a3c1d5 Merge pull request #42395 from xedin/result-builder-type
[BuilderTransform] Extract all builder related operations into `ResultBuilder` type
2022-04-25 10:25:15 -07:00
Josh Soref
4c77c59269 Spelling sema (#42474)
* spelling: accessibility

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: accessories

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: adjustments

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: all

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: ambiguous

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: arguments

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: assignment

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: associated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: assumes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: auxiliary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: availability

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: available

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: belongs

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: checking

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: clazz

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: compatibility

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: completely

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: completion

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: complicated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conformance

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: constrained

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: constraint

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: contextual

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: conversion

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: convertible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: couldn't

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declaration

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: defaultable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: depending

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: describe

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnostic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnostics

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existential

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: expects

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicitly

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: expression

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: first

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: font

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: forward

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: given

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: global

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: guarantee

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: happened

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: hierarchy

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: identical

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: immediately

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: implicit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: indicates

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: inferred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initializer

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: integrity

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interpolation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: introducing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: involved

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: just

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: like

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: likewise

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: mismatch

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: missing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: more

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: necessarily

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: noescape

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: nonetheless

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurrences

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: operators

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: optional

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: otherwise

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: outside

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overload

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: overridden

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: override

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameter

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameters

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: penalize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: platforms

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: precedence

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preemptively

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preliminary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: preserve

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: propagate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: propagated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: qualifier

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: question

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: really

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: received

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: references

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replaceable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replacement

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: representable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: representative

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: requirement

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: requires

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: resolved

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: retrieve

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rewriting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: satisfied

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: semantics

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: signature

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: similar

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: simplest

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: simplification

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: solver

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: struct

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: structurally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: success

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: sure

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: symmetric

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: syntactically

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: target

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: themselves

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: these

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: this

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transform

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transparent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: tread

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: truncation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: type

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unconstructable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: universally

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unknown

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unwrapped

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: versioned

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: visible

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: where

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-20 15:12:46 -07:00
Pavel Yaskevich
6bc6ded6cf [BuilderTransform] Move buildVarRef to ResultBuilder type 2022-04-15 14:26:55 -07:00
Pavel Yaskevich
f54172e222 [BuilderTransform] Handle ReturnStmt via CONTROL_FLOW_STMT macro 2022-04-15 14:26:55 -07:00
Pavel Yaskevich
54d6bc9bc3 [BuilderTransform] Move buildVar to ResultBuilder type 2022-04-15 14:26:55 -07:00
Pavel Yaskevich
e087489f30 [BuilderTransform] Move buildCall to ResultBuilder type 2022-04-15 14:26:44 -07:00
Pavel Yaskevich
95d9362506 [BuilderTransform] Extract support checks and builder info into ResultBuilder type 2022-04-15 14:26:36 -07:00
Pavel Yaskevich
018cd080c7 Merge pull request #42329 from xedin/builder-var
[BuilderTransform] Replace use of `TypeExpr` with a special $builderSelf variable
2022-04-15 09:36:05 -07:00
Pavel Yaskevich
fb4720d355 [BuilderTransform] Replace use of TypeExpr with a special $builderSelf variable
For all of the `build*` calls, let's use a special variable declaration
`$builderSelf` which refers to a type of the builder used. This allows
us to remove hacks related to use of `TypeExpr`. Reference to `$builderSelf`
is replaced with `TypeExpr` during solution application when the builder
type is completely resolved.
2022-04-14 21:16:48 -07:00
Alex Hoppen
b034c48b1d [CodeCompletion] Record fixes while solving result builders for code completion
We record fixes while solving normal expressions for code completion and we should do the same when solving result builders if we are reporting the solutions to completion callbacks.
2022-04-08 11:16:08 +02:00
swift-ci
882edde92f Merge pull request #41966 from rxwei/se-0348-if-approved
[ResultBuilders] Enable SE-0348 `buildPartialBlock` by default.
2022-04-04 21:21:19 -07:00
Doug Gregor
4db1f7d4e7 Map case variable types out of context.
Otherwise, we end up recording contextual types here.
2022-03-28 11:06:50 -07:00
Richard Wei
335b766b25 [ResultBuilders] Enable SE-0348 buildPartialBlock by default.
Enables SE-0348 `buildPartialBlock` feature by default. The frontend flag is kept for compatibility with existing clients, but is now ineffective.

Also includes some improved error messages for invalid result builder call sites.
2022-03-22 16:26:50 -07:00
Alex Hoppen
a8cec01c6f [CodeCompletion] Exit early in applyResultBuilderBodyTransform after reporing solutions to code completion 2022-03-18 08:11:34 +01:00
Alex Hoppen
f538d33e5f [CodeCompletion][Sema] Migrate CallArgurment position completion to the solver-based implementation
This hooks up call argument position completion to the typeCheckForCodeCompletion API to generate completions from all the solutions the constraint solver produces (even those requiring fixes), rather than relying on a single solution being applied to the AST (if any).

Co-authored-by: Nathan Hawes <nathan.john.hawes@gmail.com>
2022-03-17 15:15:54 +01:00
Alex Hoppen
135c266115 [CodeCompletion] Call sawSolution when type checking a result builder 2022-03-16 23:17:11 +01:00
Richard Wei
b1f020bf38 [ResultBuilders] buildPartialBlock support
This PR implements support for `buildPartialBlock` as proposed in https://forums.swift.org/t/pitch-buildpartialblock-for-result-builders/55561. This is similar to the existing support for `buildBlock(combining:into:)` except that it also checks for availability when deciding whether to fall back to plain old `buildBlock`.

> In the result builder transform, the compiler will look for static members `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)` in the builder type. If the following conditions are met:
> - Both methods `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)` exist.
> - The availability of the enclosing declaration is greater than or equal to the availability of `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)`.

When there's no available `buildPartialBlock` to call and there's no `buildBlock`, emit a diagnostic:
```console
result builder 'Builder' does not implement any 'buildBlock' or a combination of 'buildPartialBlock(first:)' and 'buildPartialBlock(accumulated:next:)' with sufficient availability for this call site
```
2022-03-04 00:24:35 -08:00
Richard Wei
59ad670c0c Merge pull request #40799 from rxwei/pairwise-buildblock
[ResultBuilders] `buildBlock(combining:into:)` for pairwise combination.
2022-01-19 17:11:38 -08:00
Richard Wei
b6e679f22c [ResultBuilders] buildBlock(combining:into:) for pairwise combination.
Allow a user-defined `buildBlock(combining:into:)` to combine subexpressions in a block pairwise top to bottom. To use `buildBlock(_combining:into:)`, the user also needs to provide a unary `buildBlock(_:)` as a base case. The feature is being gated under frontend flag `-enable-experimental-pairwise-build-block`.

This will enable use cases in `RegexBuilder` in experimental declarative string processing, where we need to concatenate tuples and conditionally skip captureless regexes.  For example:

```swift
let regex = Regex {
  "a" // Regex<Substring>
  OneOrMore("b").capture() // Regex<(Substring, Substring)>
  "c" // Regex<Substring>
  Optionally("d".capture()) // Regex<(Substring, Substring?)>
} // Regex<Tuple3<Substring, Substring, Substring?>>
let result = "abc".firstMatch(of: regex)
// MatchResult<(Substring, Substring, Substring?)>
```

In this example, patterns `"a"` and `"c"` have no captures, so we need to skip them. However with the existing result builder `buildBlock()` feature that builds a block wholesale from all subexpressions, we had to generate `2^arity` overloads accounting for any occurrences of captureless regexes. There are also other complexities such as having to drop-first from the tuple to obtain the capture type. Though these features could in theory be supported via variadic generics, we feel that allowing result builders to pairwise combine subexpressions in a block is a much simpler and potentially more useful approach.

With `buildBlock(_combining:into:)`, the regex builders can be defined as the following, assuming we have variadic generics:

```swift
enum RegexBuilder {
  static func buildBlock() -> Regex<Substring>
  static func buildBlock<Match>(_ x: Regex<Match>) -> Regex<Match>
  static func buildBlock<
    ExistingWholeMatch, NewWholeMatch, ExistingCaptures..., NewCaptures...
  >(
    _combining next: Regex<(NewWholeMatch, NewCaptures...)>,
    into combined: Regex<(ExistingWholeMatch,  ExistingCaptures...)>
  ) -> Regex<Substring, ExistingCaptures..., NewCaptures...>
}
```

Before we have variadic generics, we can define overloads of `buildBlock(_combining:into:)` for up to a certain arity. These overloads will be much fewer than `2^arity`.
2022-01-18 05:14:08 -08:00
Holly Borla
6cee193fc0 [Type System] When explicit existential types are enabled, wrap Error
in ExistentialType for the type of error values.
2022-01-13 19:30:44 -08:00
Robert Widmann
d37032fd1b [NFC] Refactor Pattern Binding Application in Result Builders
Remove the duplication between this code and CSApply by targeting the pattern binding decl instead of all of its entries.
2021-12-16 13:15:54 -08:00
Robert Widmann
232c51cf53 Fully Check Decls in Result Builders
In particular, this turns redeclaration checking on for variables in
pattern bindings.

rdar://85784090
2021-12-15 11:48:25 -08:00
Pavel Yaskevich
277b0fcca5 [BuilderTransform] Don't skip multi-statement closures during pre-check
Each of the elements in the result builder has to be fully pre-checked
now that multi-statement inference has been enabled.
2021-12-03 11:08:26 -08:00
Pavel Yaskevich
0e6e058e7c [TypeChecker] Fix constraint solver to respect LeaveClosureBodyUnchecked flag 2021-12-03 10:54:07 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Pavel Yaskevich
49c366870c [BuilderTransform] Don't skip multi-statement closures during pre-check
Each of the elements in the result builder has to be fully pre-checked
now that multi-statement inference has been enabled.
2021-11-15 16:48:38 -08:00
Pavel Yaskevich
83033198c3 [TypeChecker] Fix constraint solver to respect LeaveClosureBodyUnchecked flag 2021-11-15 16:42:05 -08:00
Pavel Yaskevich
568c27f551 [ConstraintSystem] Convert Opened{Existential}Types to a map vector to avoid duplicates
Same reasons as with `DefaultConstraints` but also improves
code ergonomics around opened types.
2021-10-22 10:09:08 -07:00
Pavel Yaskevich
da3cef2961 [ResultBuilders] Fix a crash in PreCheckResultBuilderApplication
Cant assume that `shouldTypeCheckInEnclosingExpression` always
implies a single expression closure anymore.
2021-10-08 10:08:03 -07:00
Pavel Yaskevich
b8ea5e794a [ResultBuilders] Print type-checked function body in debug mode 2021-10-04 13:15:31 -07:00