Commit Graph

22 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
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
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
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
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
Sima Nerush
0482bd3652 [Sema] Refactor code and improve documentation pertaining to SE-0408. 2023-12-15 20:39:40 -08:00
Sima Nerush
5832181077 Sema 2023-12-03 21:51:22 -08:00
Pavel Yaskevich
b405cee1df [ConstraintSystem] Bring back one-way pattern solving for for-in statements (outside closures)
Type-checker separates `where` clause from `for-in` statement's pattern/sequence
in closure contexts  which works as a natural barrier for inference, but
for-in statements in i.e. function bodies still type-check all of the for-in
statement components together, so we need to make sure that where clause
cannot be used to infer a type of the pattern before its sequence expression.

Resolves: rdar://117220710
2023-10-20 08:53:33 -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
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
Hamish Knight
c44675ca46 [CS] Add null check for the pattern in SyntacticElementTarget::getSourceRange
For an external property wrapper, there may not be
a pattern here. I believe this should only be hit
during `-debug-constraints` or if there's a too
complex error (which I'm not sure is possible to
produce in this case), so no test.
2023-03-14 11:56:01 +00: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