Commit Graph

133 Commits

Author SHA1 Message Date
Slava Pestov
ac17292dfe Sema: Record preconcurrency closures in the trail 2024-10-07 16:50:48 -04:00
Slava Pestov
8c8a385a4a Sema: Record SyntacticElementTargetKeys in the trail 2024-10-07 16:50:47 -04:00
Doug Gregor
5b2520e379 Remove IfConfigDecl from the AST
The swift-syntax tree retains information about the parsed #if
regions. Drop it from the semantic AST.
2024-09-18 20:51:54 -07:00
Hamish Knight
1cc00e3676 [CS] NFC: Remove SolutionApplicationToFunctionResult
This is now no longer needed.
2024-09-17 12:35:11 +01:00
Hamish Knight
1f79cbdca1 [CS] Sink closure attribute/param checking into applySolution
The cases where CSApply fails should be fairly
limited these days, and there doesn't seem to be
any reason we shouldn't run these on failure anyway.
2024-09-17 12:35:11 +01:00
Hamish Knight
930dc18eb7 [CS] Avoid delaying application for multi-statement closures
We ought to be able to apply the solution to them
immediately now.
2024-09-17 12:35:11 +01:00
Hamish Knight
f0151c1d21 [CS] Delay type-checking of local decls
Delay `typeCheckDecl` for local decls until the
end of CSApply. This replaces the existing logic
for delaying type-checking for local functions.
2024-09-17 12:35:10 +01:00
Hamish Knight
d99d881af5 [CS] NFC: Factor out base class SyntacticElementTargetRewriter
Pass this instead of a function for rewriting
targets.
2024-09-17 12:35:10 +01:00
Hamish Knight
002c6d169b [CS] Remove some calls to setExprTypes
`rewriteTarget` already calls `setExprTypes` for
expressions, so these are redundant.
2024-09-17 12:35:10 +01:00
Hamish Knight
b1c90feb52 [CS] Sink closure property wrapper application into applySolution
We need to make sure property wrappers are
applied before `checkParameterList`.
2024-09-14 15:37:21 +01:00
Hamish Knight
ee0e408a8c [Sema] Remove separate closure type-checking logic
`participatesInInference` is now always true for
a non-empty body, remove it along with the separate
type-checking logic such that empty bodies are
type-checked together with the context.
2024-09-08 16:17:11 +01:00
Hamish Knight
840ed6adff Merge pull request #75891 from hamishknight/fellthrough
[Sema] Improve handling of `fallthrough` in `if`/`switch` expressions
2024-08-19 17:59:24 +01:00
Hamish Knight
55aed16ee6 Requestify FallthroughStmt source and destination lookup
Follow a similar pattern to BreakTargetRequest
and ContinueTargetRequest.
2024-08-14 19:59:05 +01:00
Slava Pestov
b601c294ac AST: Replace remaining uses of Type::transform() with transformRec() 2024-08-12 16:05:43 -04:00
Hamish Knight
22b08da0dd [Sema] Remove replaceInvalidRefsWithErrors param
Doesn't seem like anything is relying on setting
this to `false` anymore, remove it.
2024-07-21 15:27:15 +01:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Pavel Yaskevich
bc3b2748bc [CSSyntacticElement] Bring type variables from outer pack expansion into scope
If closure appears inside of a pack expansion, the elements
that reference pack elements have to bring expansion's shape
type in scope to make sure that the shapes match.
2024-05-22 14:43:10 -07:00
Hamish Knight
8b42107a4e [CS] Rename SyntacticElementTarget::forEachStmt -> forEachPreamble
This more closely matches what we're actually
type-checking, since we do not currently include
the body.
2024-03-04 11:56:24 +00:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Hamish Knight
33cdd33f9e [CS] Account for implicit returns in closures
Avoid defaulting to Void if we have an implicit
return from which we can infer the result type.
2024-02-07 18:14:23 +00: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
Hamish Knight
16cfca4186 [ASTWalker] NFC: Rename SkipChildren -> SkipNode
This better describes what the action currently
does, and allows us to re-introduce `SkipChildren`
with the correct behavior.
2024-02-05 15:27:25 +00:00
Hamish Knight
2e20aa5195 Merge pull request #71285 from hamishknight/fix-loc
[CS] Fix locator for `if` expressions
2024-02-01 09:39:43 +00:00
Hamish Knight
956d6d23f2 Merge pull request #71272 from hamishknight/cleanup-return
[CS] Unify ReturnStmt handling
2024-02-01 01:25:08 +00:00
Hamish Knight
185a7d5103 [CS] Fix locator for if expressions
Currently we don't insert an intermediate
`SyntacticElement` locator element for the `if`
statement in a SingleValueStmtExpr, which leads
to an assertion failure when attempting to simplify
a following `TernaryBranch` element.

Move the insertion of the `SyntacticElement` locator
element for the statement into the
SingleValueStmtExpr constraint generation function,
and remove it from the statement visitors themselves.

For the other cases, the `SyntacticElement` was
already being inserted for children of a BraceStmt,
so we were actually previously ending up with
duplicated elements in a couple of places.
2024-01-31 21:37:56 +00:00
Hamish Knight
deaf2dd372 [CS] Unify ReturnStmt handling
Unify the implementation between single-expression
and multi-statement closures. Because we're now
storing a contextual type for single expression
closure returns, update a code completion test to
bring its behavior inline with the multi-statement
case.
2024-01-31 20:26:20 +00:00
Hamish Knight
d9fd4c75b1 [CS] Remove isInputExpression parameter
This wasn't consistently used, and consequently
could result in some expressions getting their
parents invalidated. Instead, replace it with a
query to make sure we don't try and add an
expression we've already computed the parent info
for.
2024-01-31 20:26:20 +00:00
Hamish Knight
8773521d86 [CS] Don't walk into local decls in TypeVariableRefFinder
This could result in us incorrectly walking into
local functions and picking up type variables that
weren't being referenced.
2024-01-31 15:34:34 +00:00
Hamish Knight
0a4c029cfc [AST] Introduce UnreachableExpr
This models the conversion from an uninhabited
value to any type, and allows us to get rid of
a couple of places where we'd attempt to drop
the return statement instead.
2024-01-30 14:08:54 +00:00
Hamish Knight
9b64990d24 [AST] Remove the "single expression body" bit
Remove this bit from function decls and closures.
Instead, for closures, infer it from the presence
of a single return or single expression AST node
in the body, which ought to be equivalent, and
automatically takes result builders into
consideration. We can also completely drop this
query from AbstractFunctionDecl, replacing it
instead with a bit on ReturnStmt.
2024-01-30 14:08:54 +00:00
Hamish Knight
3a8e31d7f6 Merge pull request #71094 from hamishknight/return-tweaks
A couple of ReturnStmt tweaks
2024-01-24 10:07:27 +00:00
Hamish Knight
c97d80b1c3 [AST] NFC: Add convenience constructors for ReturnStmt
Add `ReturnStmt::createParsed` and `createImplict`.
2024-01-23 19:30:18 +00:00
Alex Hoppen
dd5486cda8 [Sema] Remove ConjunctionElement::mightContainCodeCompletionToken
Isn’t used anymore (I think it stopped being used after the new result builder transform was enabled).
2024-01-22 19:52:33 -08:00
Hamish Knight
990d15567d [AST] Split up PatternBindingDecl::setPattern
Most clients only want to set one of the two
parameters, split it into `setPattern` and
`setInitContext` (the latter of which now
handles calling `setBinding`).
2024-01-17 16:02:33 +00:00
Hamish Knight
848574080a [CS] Use correct DeclContext when solving initializations
Use the PatternBindingInitializer context if we
have one. This also uncovered a parser issue where
we would mistakenly create a
PatternBindingInitializer in top-level code after
parsing the initializers.
2024-01-17 16:02:33 +00:00
Doug Gregor
8ad137fb51 [Typed throws] Infer thrown error type for do..catch blocks within closures.
Start classifying all potential throw sites within a constraint
system and associate them with the nearest enclosing catch node. Then,
determine the thrown error type for a given catch node by taking the
union of the thrown errors at each potential throw site. Use this to
compute the error type thrown from the body of a `do..catch` block
within a closure.

This behavior is limited to the upcoming feature `FullTypedThrows`.
2023-12-13 14:59:23 -08:00
Doug Gregor
e1be9c312b Eliminate the DeclContext from ExplicitCaughtTypeRequest
Correctly determining the DeclContext needed for an
ExplicitCaughtTypeRequest is tricky for a number of callers, and
mistakes here can easily lead to redundant computation of the caught
type, redundant diagnostics, etc.

Instead, put a `DeclContext` into `DoCatchStmt`, because that's the
only catch node that needs a `DeclContext` but does not have one.
2023-12-13 11:42:56 -08:00
Doug Gregor
05a4a822ba Tighten CatchNode from an AbstractClosureExpr to a ClosureExpr.
Only real closures can have thrown error types, so we can use the
tighter bound for closures and simplify various CatchNode operations.
2023-12-12 22:30:18 -08:00
Doug Gregor
010a41243e Fix minor regressions from refactoring of caught error types 2023-12-12 15:39:56 -08:00
Doug Gregor
3369e3349f [Typed throws] Handle explicitly-specified throws on do..catch in closures
Teach the constraint system to use the same primitives as elsewhere to
determine the type context for a `throw` statement and the caught
error type within a `do..catch` statement. This makes
explicitly-specified `throws` work on `do..catch` that occurs in
closures.

Cleans up some redundant computations for caught error types.
2023-12-12 00:06:17 -08:00
Doug Gregor
91df336a4d [Typed throws] Unify ThrownTypeRequest and DoCatchExplicitThrownTypeRequest
These two requests are effectively doing the same thing to two
different cases within CatchNode. Unify the requests into a single
request, ExplicitCaughtTypeRequest, which operates on a CatchNode.

This also moves the logic for closures with explicitly-specified throws
clauses into the same request, taking it out of the constraint system.
2023-12-12 00:06:17 -08:00
Hamish Knight
f4e09c5531 [AST] Tighten up invariants around IfStmt
The 'then' statement must be a BraceStmt, and
the 'else' must either be a BraceStmt or an IfStmt.
2023-12-04 11:09:01 +00:00
Alex Hoppen
b603a5e9a0 [Sema] Remove LeaveClosureBodiesUnchecked
This shouldn’t be needed anymore since we migrated code completion to be solver-based.

rdar://91403086
2023-11-23 11:41:29 -08:00
Hamish Knight
5cbdfb8233 [CS] Consolidate conjunction join injection 2023-10-06 11:17:48 +01:00
Hamish Knight
33f94bc874 Introduce do expressions 2023-10-06 11:17:48 +01:00
Pavel Yaskevich
49a63fcc7d Merge pull request #68787 from xedin/separate-solving-for-for-loop-condition
[ConstraintSystem] Solve `where` clauses of for-in loops separately
2023-10-02 09:22:53 -07:00
Pavel Yaskevich
0b4a9f5484 [CSSyntacticElement] NFC: Update comments related to for-in where clause checking 2023-09-29 16:03:21 -07:00
Pavel Yaskevich
72caaa8cfe [ConstraintSystem] Solve where clauses of for-in loops separately
Doing so fits better into conjunction model which leads to more
granular control over what variables are brought into scope during
`where` clause expression checking.

These changes also remove "one-way bind" flag from "for-in" statement
target.
2023-09-29 13:28:46 -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
Pavel Yaskevich
fdd67a6bde [Sema] NFC: Remove obsolete isInResultBuilderContext method
Type-checking of result builder transformed closure is enabled
by default now, so this method is no longer used.
2023-09-18 17:59:30 +01:00