Commit Graph

32 Commits

Author SHA1 Message Date
Pavel Yaskevich
45edfc359b Merge pull request #63768 from xedin/issue-63764
[BuilderTransform] Rework missing `buildWithLimitedAvailability` detection
2023-02-21 14:38:50 -08:00
Pavel Yaskevich
c4ea02c2d7 [BuilderTransform] Rework missing buildWithAvailability detection
Since all of the branches of an `if` statement are joined together
and hence produce the same type, that type should be used to
check whether `buildWithAvailability` is required but missing
regardless of availability condition kind.

Resolves: https://github.com/apple/swift/issues/63764
2023-02-18 01:04:15 -08:00
Hamish Knight
f7191b35b6 [CS] Add contextual Bool type to switch-case where clause
Seems this was accidentally omitted, which would
crash in CSApply for any non-Bool-convertible type.
2023-02-17 20:58:46 +00:00
Hamish Knight
eac3fb4506 [CS] NFC: Default the allowFreeTypeVariables parameter
All but one client wants to set this to anything
other than `FreeTypeVariableBinding::Disallow`.
2023-02-17 20:58:46 +00:00
Alex Hoppen
395df14960 [CodeCompletion] Skip conjuction elements that are unrelated to the code completion token 2023-02-14 09:40:56 +01:00
Pavel Yaskevich
8e82f1d68b [CSGen] Detect nested out-of-scope variables in recursive declarations
Follow-up to https://github.com/apple/swift/pull/63505

Since, when the type is not stated, a variable assumes the
type of its initializer that enables out-of-scope variables
to be nested inside of some other concrete type i.e. Optional.

Resolves: https://github.com/apple/swift/issues/63455
2023-02-11 19:19:09 -08:00
Pavel Yaskevich
bffb8d9ee2 Revert "[CSGen] Handle recursive use of variable declarations" 2023-02-10 16:45:59 -08:00
Pavel Yaskevich
9401926304 Merge pull request #63505 from xedin/issue-63455
[CSGen] Handle recursive use of variable declarations
2023-02-09 11:20:43 -08:00
Pavel Yaskevich
83dd93ad2e [CSGen] Handle recursive use of variable declarations
It's possible for out-of-scope type variable to be the type of
declaration if such declaration is recursively referenced in
the body of a closure located in its initializer expression.
In such cases type of the variable declaration cannot be connected
to the closure because its not known in advance (determined by the
initializer itself).

Resolves: https://github.com/apple/swift/issues/63455
2023-02-07 17:48:26 -08:00
Pavel Yaskevich
f1051f1520 Merge pull request #63465 from xedin/issue-63264
[CSSyntacticElement] Correctly determine whether body is a "single ex…
2023-02-07 01:09:13 -08:00
Pavel Yaskevich
e3ea597241 [CSSyntacticElement] Correctly determine whether body is a "single expression"
Result builder transformed bodies are always multi-statement.

Resolves: https://github.com/apple/swift/issues/63264
2023-02-06 10:46:27 -08:00
Hamish Knight
6c4b3daa23 [CS] Connect isolated conjunctions to referenced VarDecls
Currently we only consider ParamDecls, but isolated
conjunctions can reference external VarDecls too.

This fixes a spurious "cannot reference invalid declaration"
error when the result builder transform is disabled
in the test case rdar104687668.swift. It also fixes
the attached test case, where an if expression
references a pattern var in a for loop.

rdar://105080067
2023-02-06 14:25:13 +00: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
Hamish Knight
4e414b1cf7 [Sema] Avoid forming double braced single expression closures
For a single expression closure, just use the
expression as the body in the case where we're
coercing to Void, as the return is already
implied. This avoids crashing in
`ClosureExpr::getSingleExpressionBody` with a
double braced body.

Surprisingly it seems nothing is currently calling
`ClosureExpr::getSingleExpressionBody` after
type-checking, so no test case, but later commits
in this patch will exercise this case.
2023-02-01 15:30:16 +00:00
Pavel Yaskevich
51b2481091 [AST] Expand TypeJoin expression to support joining over a type
(cherry picked from commit 4efc35a76c)
2023-02-01 15:13:58 +00:00
Pavel Yaskevich
f8bf74b457 Merge pull request #62773 from xedin/rdar-83418797
[CSClosure] Fix handling of non-representivate variables
2023-01-04 09:48:54 -08:00
Pavel Yaskevich
47893695be [CSClosure] Fix handling of non-representivate variables
All of the type variables referenced by a type had to be
handled by `inferVariables` otherwise it would to possible
to bring non-representative variable into scope which in
turn later would get simplied into a variable that doesn't
exist in the active scope and solver would crash.

Resolves: rdar://83418797
2022-12-23 20:08:09 -08:00
Alex Hoppen
3c90c892e9 [CodeCompletion] Drop ForCodeCompletion constraint system option for syntactic elements that don't contain completion token 2022-12-21 12:17:56 -08:00
Pavel Yaskevich
36a50c7070 [ResultBuilder] Don't run syntactic diagnostics on transformed do statements
Visiting of transformed `do` shouldn't run syntatic diagnostics because
they are going to be performed by `visit` that called `visitDoStmt`.
2022-12-21 10:31:36 -08:00
Pavel Yaskevich
6c02e51817 [CSSyntacticElement] Replace global flag check with info from the solver
`transformedBody` is available only if the flag is set, so there
is no reason to double-check it before application, the presence
of the transformed body is evidence enough.
2022-12-19 12:16:54 -08:00
Hamish Knight
791e2cd7ff Requestify computation of break/continue targets
Introduce BreakTargetRequest and
ContinueTargetRequest that perform the ASTScope
lookup for the target of a break or continue.
2022-12-01 19:08:27 +00:00
Pavel Yaskevich
4e3a4ffbe9 Merge pull request #62120 from xedin/rdar-100753270
[CSSyntaxElement] Detect type variables in sequence expressions of `for-in` loops
2022-11-17 09:54:22 -08:00
Angela Laar
b6637e4586 [CSSyntacticElement] Only add constraints when brace statement represents the whole body 2022-11-16 22:39:41 -08:00
Angela Laar
45fb9899d6 [CSSyntacticElement] Only set default if generator has no errors 2022-11-15 23:38:01 -08:00
Angela Laar
5d93b99a91 [CSClosure] Move participatesInInference check to Constraint Generator 2022-11-15 17:28:43 -08:00
Angela Laar
8257cc1e10 [CSClosure] Generate constraints for empty closure body
We should do this in the ConstraintGenerator instead of in a ConstraintSystem method.
2022-11-15 16:14:38 -08:00
Angela Laar
b4549d63f0 [Constraint System] Refactor generateConstraints
We don't need a separate generateConstraints function for closures.
2022-11-15 16:13:58 -08:00
Pavel Yaskevich
cab0cb52ab [CSSyntaxElement] Detect type variables in sequence expressions of for-in loops
Invalid syntax could introduce type variables into sequence which
have to be brought into scope otherwise solver is going to crash.

Resolves: rdar://100753270
2022-11-15 11:56:36 -08:00
Pavel Yaskevich
f5f94fd8ee [CSClosure] Introduce SyntacticElementContext
Replace `AnyFunctionRef` as "context" for syntactic element with
a custom `SyntacticElementContext` to support type-checking of
other constructs in the future.
2022-11-14 20:03:42 +00:00
Hamish Knight
1846276a13 [CS] Factor out brace element handling in a couple of cases
Split out brace element handling for a couple of
walkers into a new function. The diff for this is
best viewed without whitespace changes. This
should be NFC.
2022-11-14 20:03:41 +00:00
Hamish Knight
0faa0b60d4 [CS] NFC: Remove unused method 2022-11-14 20:03:40 +00:00
Hamish Knight
fd9fa72f0f [CS] NFC: Rename CSClosure.cpp -> CSSyntacticElement.cpp
We want to generalize this conjunction logic to
not just be applicable to closures, so rename the
file to match.
2022-11-14 20:03:39 +00:00