Commit Graph

13 Commits

Author SHA1 Message Date
Pavel Yaskevich
87e3e3d8a1 [CSBindings] Don't delay inferred loeading-dot base inference if source is a contextual type
Transitively inferring a protocol type binding from a contextual
type means that the binding set for a leading-dot member reference
is complete because there could be no other sources of bindings
when expression is connected directly to a contextual type.

Resolves: rdar://145103149
2025-03-06 14:58:21 -08:00
Pavel Yaskevich
3ff03469e7 [CSSimplify] Propagate contextual result type into result builder transformed closure
Propagate fully or partially resolved contextual type down into
the body of result builder transformed closure by eagerly binding
intermediate body result type to the contextual one. This helps to
determine when closure body could be solved early.

Resolves: rdar://106364495
2023-03-07 16:17:10 -08:00
Pavel Yaskevich
43d83bb461 [BuilderTransform] All if sequences without else should call buildOptional
In cases like:

```
if (...) {
  <body>
} else if (...) {
  <body>
} else if (...) {
  <body>
}
```

Each branch should end with `buildOptional` wrapping `buildEither`
because there is no covering unconditional `else` in the sequence:

```
var $__builder: <<Type>>

if (...) {
  $__builder = buildOptional(.some(buildEither(...)))
} else {
  if (...) {
    $__builder = buildOptional(.some(buildEither(...)))
  } else {
    if (...) {
      $__builder = buildOptional(.some(buildEither(...)))
    } else {
      $__builder = buildOptional(.none)
    }
  }
}
```

Resolves: rdar://104345754
2023-01-18 13:26:20 -08:00
Pavel Yaskevich
87816457c1 [BuilderTransform] AST Transform: Inject buildOptional to top-level if else conditions
Fixes a bug in `buildOptional` injection for `if else` branches
without unconditional `else` which leaves type-join with just `.some(...)`
and results in optionality mismatch if `buildOptional` don't not produce
an optional type.
2022-09-01 13:31:00 -07:00
Pavel Yaskevich
9399451edf [ConstraintSystem] Fix result builder discovery in leading-dot syntax calls
Leading-dot syntax allows implicitly unwrapping result type to form
a base type of the call, `getOpenedResultBuilderTypeFor` needs to
account for that.

Resolves: https://github.com/apple/swift/issues/60586
2022-08-31 11:00:54 -07:00
Anthony Latsis
7fc8377e1c Gardening: Migrate test suite to GH issues: Constraints (1/5) 2022-08-17 15:21:51 +03:00
Pavel Yaskevich
f7c4ff6847 [ConstraintSystem] Adjust getCalleeLocator to handle implicit callAsFunction
A call to `.callAsFunction` could be injected after initializer if the type is
callable, `getCalleeLocator` should recognize that situation and return
appropriate locator otherwise if `callAsFunction` has e.g. a result builder
attached to one of its parameters the solver wouldn't be able to find it.

Resolves: rdar://92914226
2022-05-10 10:04:06 -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
Pavel Yaskevich
59154d6d71 [ConstraintSystem] Support solving expression patterns via injecting call to ~= operator
Augment the constraint solver to fallback to implicit `~=` application
when member couldn't be found for `EnumElement` patterns because
`case` statement should be able to match enum member directly, as well
as through an implicit `~=` operator application.
2022-02-28 17:02:28 -08:00
Pavel Yaskevich
8c401064a5 [BuilderTransform] NFC: Add more pattern matching tests for result builders 2021-09-25 11:43:38 -07:00
Pavel Yaskevich
371096703b [TypeChecker] Prevent pattern resolution from triggering type-checking for unresolved references
Workaround for Clang enum typaliases called `isInvalid()` and `getInterfaceType()`
on discovered declarations. That doesn't play well with result builders because
declarations/patterns used in the body of a result builder don't get a type until
a solution is applied. Calling `isInvalid()` or `getInterfaceType` on declarations
located in the body of a result builder trigger a separate type-check for the
declaration that interferes with builder transformation and leads to crashes.
2021-09-22 16:45:14 -07:00
Pavel Yaskevich
e8a89cc1d1 [CSGen] Don't increase optionality of weak var patterns
If the externally-imposed type is already optional,
let's not add optionality to the pattern.
2021-09-03 10:59:30 -07:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00