46 Commits

Author SHA1 Message Date
Hamish Knight
6dfff1ce9c [CS] Remove getImplicitValueConversionLocator & ImplicitConversion
These are now unused.
2025-11-15 19:26:46 +00:00
Slava Pestov
3a01f206c5 Sema: Rename LocatorPathElt::OptionalPayload to ::OptionalInjection 2025-02-25 17:22:41 -05:00
Slava Pestov
fca570ca91 Sema: Don't use ExistentialLayout for DeepEquality matching 2024-09-24 19:12:44 -04:00
Anthony Latsis
d18a7fd073 Sema: Require CS to certify conversions associated w/ existential member accesses 2024-04-18 22:54:19 +03:00
Pavel Yaskevich
31e385f20e [Sema] WitnessMatching: Anchor ProtocolRequirement on the requrement declaration
Locators used to support only expressions which is no longer the case.
2024-03-18 10:43:41 -07:00
Hamish Knight
61a4148925 [CS] Generalize implied result handling
Track the implied result exprs in the constraint
system, and allow arbitrary propagation of
implied results down if/switch expression
branches. This is required for allowing implied
results in non-single-expression closures.
2024-02-07 18:14:22 +00:00
Pavel Yaskevich
d542ab99f0 [ConstraintSystem] Add a new locator for key path subscript parameter 2023-11-17 13:21:42 -08:00
Pavel Yaskevich
a4bda00e5b [ConstraintSystem] Add a locator element to represent a fallback type 2023-11-01 09:14:15 -07:00
Doug Gregor
4b3d2f47d9 [Typed throws] Handle function conversions involving different thrown errors
Teach the constraint solver about the subtyping rule that permits
converting one function type to another when the effective thrown error
type of one is a subtype of the effective thrown error type of the
other, using `any Error` for untyped throws and `Never` for
non-throwing.

With minor other fixes, this allows us to use typed throws for generic
functions that carry a typed error from their arguments through to
themselves, which is in effect a typed `rethrows`:

```swift
func mapArray<T, U, E: Error>(_ array: [T], body: (T) throws(E) -> U)
throws(E) -> [U] {
  var resultArray: [U] = .init()
  for value in array {
    resultArray.append(try body(value))
  }
  return resultArray
}
```
2023-10-05 11:55:05 -07:00
Doug Gregor
7f82b2a9aa [Typed throws] Enable checking of thrown types on closures.
Enable typed throws on explicit closures, either due to contextual
type information or due to explicit specification.
2023-09-29 10:51:54 -07:00
Hamish Knight
6ee44f09b4 Introduce then statements
These allow multi-statement `if`/`switch` expression
branches that can produce a value at the end by
saying `then <expr>`. This is gated behind
`-enable-experimental-feature ThenStatements`
pending evolution discussion.
2023-09-01 14:32:14 +01:00
Amritpan Kaur
1384ff0038 [CSBinding] Allow inference to bind AnyKeyPath as a KeyPath
that can be converted to AnyKeyPath later.
2023-08-01 09:15:04 -07:00
Hamish Knight
b43d351197 [CS] Improve diagnostics a bit for pattern mismatch
There's still plenty of more work to do here for
pattern diagnostics, including introducing a
bunch of new locator elements, and handling things
like argument list mismatches. This at least lets
us fall back to a generic mismatch diagnostic.
2023-06-07 00:35:02 +01:00
Pavel Yaskevich
ed23aec47e [ConstraintSystem] Record opened pack expansion type in the locator element 2023-05-02 09:32:19 -07:00
Pavel Yaskevich
6769e39ed7 [ConstraintSystem] Add a new locator element to identify pack expansion types 2023-05-02 09:31:56 -07:00
Luciano Almeida
d5a9d6ab83 [ConstraintSystem] Introduce new locator path elemet to identify coercion 2023-03-11 18:47:53 -03:00
Pavel Yaskevich
17b09a801e [ConstraintSystem] Add a locator element to represent a generic type
This locator is going to be used as a "parent" element for
"generic argument" elements.
2023-03-03 18:50:46 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Luciano Almeida
e513d23c0b [Sema] Improving global actor function mismatch diagnostic 2023-01-13 20:47:23 -03:00
Holly Borla
6e28f996ce [ConstraintSystem] Create opened pack element generic environments lazily
in the constraint system.
2023-01-07 09:50:14 -08:00
Holly Borla
dc941de45e [ConstraintLocator] Add a locator path element that stores an opened pack element
generic signature.
2022-12-14 20:45:51 -08:00
Holly Borla
72d87b5ca5 [ConstraintSystem] Add a locator path element for the pattern of a pack expansion. 2022-11-16 09:06:58 -08:00
Holly Borla
5218a0d77a [ConstraintSystem] Add a locator path element for pack shapes, and use it for
type variables representing pack shapes.
2022-11-15 21:33:17 -08:00
Slava Pestov
11eb11833f Sema: Fix deep equality matching for parameterized protocol types
Fixes rdar://problem/98356057.
2022-08-09 23:45:39 -04:00
Pavel Yaskevich
dee6a31ac9 [ConstraintLocator] Generalize pattern decl locator to support "named" and "any" 2022-08-03 15:50:33 -07:00
Alex Hoppen
eba95bacbd [CS] Delay type resolution of variables for variables in named pattern 2022-07-20 09:46:14 +02:00
Anthony Latsis
a07f2b4889 Sema, DiagQoI: Fix and tailor diagnosis of explicit closure result type conflicts 2022-06-20 22:20:32 +03:00
Pavel Yaskevich
6a65810d30 [Constraint] NFC: Rename ClosureBodyElement to SyntacticElement
`SyntacticElement` represents a statement, pattern, declaration,
condition, or expression and could originate from i.e. a closure,
a function or a result builder body.
2022-04-26 09:55:04 -07:00
Pavel Yaskevich
9d5ee7a081 [ConstraintLocator] Add a new element - pattern binding element
The new element points to an index of a particular pattern in a
pattern binding declaration.
2022-03-07 10:51:40 -08:00
Robert Widmann
b3f70c960e Implement Pack Locators 2021-12-16 01:16:45 -08:00
Hamish Knight
f26f136569 [CS] Tweak dynamic member constraint generation
In order to fit with the new IUO model where
functions with IUO results have the disjunction
formed when matching result types, we need to
update this logic to form applicable fn
constraints for the implicit `x[dynamicMember:]`
subscript call.

This is done using a new ImplicitDynamicMemberSubscript
locator path element to allow easy identification of
what the right callee and argument list should be.
2021-10-12 14:14:32 +01:00
Hamish Knight
a1abcee108 [CS] Introduce ConstructorMemberType locator elt
Use this new element to represent the overload type
for a constructor call, and have it store a bit
indicating whether the call is for a short-form
`X(...)` or self-delegating `self.init(...)` call.
2021-10-12 09:51:44 +01:00
Pavel Yaskevich
84ca85dc01 [ConstraintLocator] Add a new element to track closure body elements 2021-10-08 10:08:01 -07:00
willtunnels
319b3e64aa Add support for opaque result types in structural positions (#38392)
* [TypeResolver][TypeChecker] Add support for structural opaque result types

* [TypeResolver][TypeChecker] Clean up changes that add structural opaque result types
2021-08-03 23:45:02 -04:00
Holly Borla
939a861fe1 [ConstraintSystem] Add a constraint locator path element for tuple types,
which will provide context for tuple element mismatch diagnostics.
2021-06-23 19:18:11 -07:00
Pavel Yaskevich
b7a7024e0a [ConstraintLocator] Add information about expected value type to key path locator
Record a "value" type associated with this location to be able to
reference during inference.
2021-05-28 17:51:58 -07:00
Pavel Yaskevich
51ff12d06e [ConstraintLocator] Augment ContextualType element to carry its purpose
Having purpose attached to the contextual type element makes it much
easier to diagnose contextual mismatches without involving constraint
system state.
2021-04-26 09:51:21 -07:00
Strieker
4e2b67cbae [NFC] Resolved merge conflict in CSSimplify.cpp after making changes to improve error handling for composed wrapped value mismatches 2021-04-22 11:49:21 -07:00
Strieker
3891dc7fdc [ConstraintSystem] Added necessary logic so that a constraint locator can recognize a composed property wrapper’s wrapped value type. 2021-04-22 11:31:41 -07:00
Pavel Yaskevich
389fd29e6c [ConstraintSystem] Add a path element to represent an implicit conversion 2021-03-17 00:18:06 -07:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Pavel Yaskevich
dbfeb5eea1 [ConstraintLocator] Add a new locator path element - ConformanceRequirement
Records protocol requirement associated with a particular type in
the constraint system, also useful to track parent conformance
for conditional requirements.
2021-01-06 10:13:55 -08:00
Pavel Yaskevich
1683fb91b6 [ConstraintSystem] Remove RValueAdjustment locator element
It was used for unresolved member and `.dynamicType` references
as well as a couple of other places, but now unresolved member
references no longer need that due to new implicit "chain result"
AST node and other places could use more precise locators
e.g. new `.dynamicType` locator or `sequence element` for `for in`
loops.
2020-10-26 00:40:45 -07: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
f2614dec4a [ConstraintSystem] NFC: Move ConstraintLocator.h to include/swift/Sema 2020-10-08 10:42:39 -07:00