Commit Graph

24 Commits

Author SHA1 Message Date
Hamish Knight
1138bcc800 [Sema] Remove generic environment tracking from StmtChecker
This is no longer necessary now that we use
`mapLocalArchetypesOutOfContext` to assign depths for generic
signatures involving element archetypes.
2025-02-26 12:02:05 +00:00
Slava Pestov
f35dd66b77 Revert "Sema: Don't generate OneWayEqual constraints for pattern bindings"
This reverts commit 5071e96a78.
2025-02-02 00:43:15 -05:00
Pavel Yaskevich
e7a9bcb303 [TypeChecker] Type-check where clauses for for-in statements separately
Instead of using `one-way` constraints, just like in closure contexts
for-in statements should type-check their `where` clauses separately.

This also unifies and simplifies for-in preamble handling in the
solver.
2024-12-21 00:42:13 -08:00
Slava Pestov
5071e96a78 Sema: Don't generate OneWayEqual constraints for pattern bindings 2024-12-21 00:42:13 -08:00
Hamish Knight
cd0e5217fd [Sema] Add SyntacticElementTarget::getPattern
And use it for walking the SyntacticElementTarget
such that patterns for uninitialized vars are
walked too.
2024-08-03 16:05:09 +01:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Hamish Knight
5ec4d1cc98 [CS] Fill in ErrorTypes for expressions that fail to type-check
Ensure we always produce typed AST, even if we
fail to apply a solution. This fixes a cursor info
issue where we'd to type-check a closure twice
due to it not having a type set.

rdar://129417672
2024-06-17 17:58:52 +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
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
Hamish Knight
4fc5009a7f [CS] Invalidate VarDecls in targets that fail to type-check
This avoids a crash that could occur when
attempting to query their interface type later,
which could cause us to attempt to type-check
the Decl separately from its enclosing closure.

Eventually we also ought to use this to fill in
ErrorTypes for expressions (since type-checking
ought to only produce typed AST), but I'm leaving
that as future work for now.

rdar://120012473
2024-03-01 23:16:31 +00:00
Hamish Knight
ab4731c9ee [CS] Avoid walking a for-in body in SyntacticElementTarget::walk
This more closely lines up with what we end up
type-checking. This doesn't affect the only
current client, code completion, AFAIK.
2024-03-01 23:16:31 +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
1003b2f30b [CS] Remove CTP_ImpliedReturnStmt
Unify with `CTP_ReturnStmt`, and have the
SyntacticElementTarget carry the ReturnStmt for
regular type-checking, which we can use to record
implied returns.
2024-02-07 18:14:23 +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
Sima Nerush
066f253d2e Merge pull request #70196 from simanerush/nested-pack-iteration
[SE-0408] Enable nested iteration
2024-01-27 10:18:12 -08:00
Sima Nerush
0b167b55b1 [ConstraintSystem] Cache pack element generic environments associated withfor-in loops over parameter packs to apply in getPackElementEnvironment. 2024-01-27 00:12:33 -08: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
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
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Hamish Knight
a64ba23d7b [CS] NFC: Store ContextualTypeInfo in SyntacticElementTarget
Move the contextual type locator onto
ContextualTypeInfo, and consolidate the separate
fields in SyntacticElementTarget into storing a
ContextualTypeInfo. This then lets us plumb down
the locator for the branch contextual type of an
if/switch expression from the initial constraint
generation, rather than introducing it later. This
should be NFC.
2023-07-26 16:46:54 +01:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Kavon Farvardin
3e4bc82aa8 rename _forget to discard; deprecate _forget
SE-390 concluded with choosing the keyword discard rather than forget for
the statement that disables the deinit of a noncopyable type. This commit
adds parsing support for `discard self` and adds a deprecation warning for
`_forget self`.

rdar://108859077
2023-05-08 21:42:19 -07:00
Hamish Knight
c77caf2c72 [CS] NFC: Simplify SyntacticElementTarget construction for ExprPattern 2023-03-14 11:56:01 +00:00
Hamish Knight
2976edbe20 [CS] Rename SolutionApplicationTarget -> SyntacticElementTarget 2023-03-06 20:54:06 +00:00