Commit Graph

313 Commits

Author SHA1 Message Date
Hamish Knight
f1ad703430 [CS] Avoid skipping SingleValueStmtExpr branch with ReturnStmt for completion
We still need to solve a branch with a ReturnStmt to avoid leaving
the contextual result type unbound. This isn't currently legal anyway,
so isn't likely to come up often in practice, but make sure we can
still solve.
2025-09-13 19:15:34 +01:00
Hamish Knight
84befd43ab [AST] Make case body variables for CaseStmt non-optional
We don't really care about the distinction between empty and nil here.
2025-09-09 13:48:40 +01:00
Hamish Knight
d7fea157a1 [IDE] Remove fallback type-checking logic
This should no longer be necessary, rip it out.
2025-08-30 14:08:42 +01:00
Hamish Knight
eb7aa6281c [CS] Record SkipUnhandledConstructInResultBuilder for completion
We still want to record this fix when falling back to type-checking
as a regular function body to ensure that in cases where there is a
disjunction of multiple result builders we favor the one that actually
supports the body.
2025-08-14 11:57:11 +01:00
Hamish Knight
27e2514eff [CS] Better handle unsupported result builder elements for completion
Instead of failing, fall back to solving as a regular function body.

rdar://144303920
2025-08-11 11:19:14 +01:00
Hamish Knight
e0791bb38d [CS] Fix check in applyResultBuilderBodyTransform
If `matchResultBuilder` returns `nullopt` we should be bailing,
rather than continuing, which would attempt to solve with an empty
constraint system.
2025-08-11 11:19:14 +01:00
Hamish Knight
931289988e [CS] NFC: Remove an unused return value
`isBuildableIfChainRecursive` never returned anything other than `true`,
change it to just be a void call.
2025-08-11 11:19:14 +01:00
Hamish Knight
1e012fea05 [CS] Avoid bailing on result builder return for completion
Make sure we continue to solve the body normally rather than bailing
early.
2025-08-11 11:19:14 +01:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Pavel Yaskevich
1bd0cd7b94 Merge pull request #79928 from xedin/support-debug-constraints-on-line-for-result-builders
[ResultBuilders] NFC: Support `-debug-constraints{-on-line=}` for dec…
2025-03-12 00:29:41 -07:00
Pavel Yaskevich
6197aab467 [ResultBuilders] NFC: Support -debug-constraints{-on-line=} for declaration transforms 2025-03-11 15:13:58 -07:00
Allan Shortlidge
7a514c99e2 Sema: Adjust result builder operation lookup for MemberImportVisibility.
To avoid spurious diagnostics about unavailable operations when checking uses
of functions that take result builder closures, lookup of result builder
operations needs to ignore the restrictions of the `MemberImportVisibility`
feature. The result builder transform should simply use the operations that are
found and allow later checks to diagnose the use of inaccessible builder
operations.

Resolves rdar://144100445.
2025-03-10 20:54:41 -07:00
Rintaro Ishizaki
5eac58e1e0 [AST] SwitchStmt only hold CaseStmt
Now that there is no way SwitchStmt to hold AST nodes other than
CaseStmt.
2025-03-08 09:14:40 -08:00
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -08:00
Pavel Yaskevich
51c833f2a9 Merge pull request #79617 from xedin/isolate-buildBlock-in-if-and-case-statements
[BuilderTransform] Type-check `buildBlock` of each condition body separately from "join" operation
2025-02-27 16:45:22 -08:00
Pavel Yaskevich
d70f14e936 [BuilderTransform] If: Save result of buildBlock into a variable before using in buildEither
Similar to `case` statements, if chain is non-optional, let's
isolate `buildBlock` of every branch into a separate type variable.
2025-02-25 13:09:35 -08:00
Pavel Yaskevich
3add37514e [BuilderTransform] Case: Save result of buildBlock into a variable before using in buildEither
Fixes implementation issue where build block is type-checked as part
of `buildEither(...)`. This is incorrect according to the original
proposal (SE-0289), `buildBlock` should be type-checked independently
and `buildEither` should have no effect on what overload of `buildBlock`
gets selected.
2025-02-25 13:09:34 -08:00
Doug Gregor
50801f9c05 [SE-0458] Implement "unsafe" effect for the for-in loop
Memory unsafety in the iteration part of the for-in loop (i.e., the part
that works on the iterator) can be covered by the "unsafe" effect on
the for..in loop, before the pattern.
2025-02-23 22:50:39 -08:00
Slava Pestov
c0787f337f Sema: Fix soundness hole with variable initializers and opaque return types
Just because the type of the initializer expression is an opaque return type,
does not mean it is the opaque return type *for the variable being initialized*.

It looks like there is a bit of duplicated logic and layering violations going
on so I only fixed one caller of openOpaqueType(). This addresses the test case
in the issue. For the remaining calls I added FIXMEs to investigate what is
going on.

Fixes https://github.com/swiftlang/swift/issues/73245.
Fixes rdar://127180656.
2024-12-04 15:13:22 -05:00
Hamish Knight
73fb36f371 [AST] Split out "is compound" bit on FunctionRefInfo
FunctionRefKind was originally designed to represent
the handling needed for argument labels on function
references, in which the unapplied and compound cases
are effectively the same. However it has since been
adopted in a bunch of other places where the
spelling of the function reference is entirely
orthogonal to the application level.

Split out the application level from the
"is compound" bit. Should be NFC. I've left some
FIXMEs for non-NFC changes that I'll address in a
follow-up.
2024-12-02 14:11:33 +00:00
Hamish Knight
a4d51419ba [AST] NFC: Rename FunctionRefKind -> FunctionRefInfo 2024-12-02 14:11:32 +00:00
Doug Gregor
f89218941b [Result builder transform] Don't abort when we encounter a case with no statements
Remove code that aborts the result builder transform when we encounter
a case that has no statements in it. This can occur when the only
statements were behind a `#if` that evaluataed empty, so it should not
cause an abort.

Previously, the presence of an IfConfigDecl within the case statement
would have prevented us from aborting the traversal here. However, the
removal of IfConfigDecl from the AST turned this previously-accepted
code into a compiler crash.

Fixes rdar://139312426.
2024-11-07 22:58:18 -08:00
Allan Shortlidge
919ec930f9 Merge pull request #77384 from tshortli/rename-unmet-availability-requirement 2024-11-05 10:56:55 -08:00
Allan Shortlidge
161dc2e09e Sema: Rename getUnmetDeclAvailabilityRequirement().
Name it `getUnsatisfiedAvailabilityConstraint()` to match
`AvailabilityConstraint`.
2024-11-04 19:58:28 -08:00
Pavel Yaskevich
c5d0916746 [BuildTransform] Fix walkExplicitReturnStmts to walk implicit statements
Some statements introduce implicit braces and other things,
`walkExplicitReturnStmts` cannot ignore that while trying
to find explicit returns.

Resolves: rdar://139235128
2024-11-04 16:42:50 -08:00
Allan Shortlidge
7b5757b29b Sema: Replace TypeChecker::checkDeclarationAvailability().
Adopt `getUnmetDeclAvailabilityRequirement()` instead.
2024-11-03 11:37:01 -08:00
Hamish Knight
2bcffc56d0 [CS] Fix source range for for loop result builder transform
Ensure the implicit `do` statement has a source
range that covers the `for` loop by changing the
source location for the initial binding. This ensures
we correctly detect the code completion child and
avoid skipping it.
2024-10-29 20:35:40 +00:00
Anthony Latsis
41adfec8da [NFC] AST, Sema: Move TypeChecker::findReturnStatements into AnyFunctionRef
Also rename it to `getExplicitReturnStmts` for clarity and have it
take a `SmallVector` out parameter instead as a small optimization and
to discourage use of this new method as an alternative to
`AnyFunctionRef::bodyHasExplicitReturnStmt`.
2024-10-11 03:57:43 +03:00
Anthony Latsis
e31e8773d5 [NFC] Sema: Reimplement ReturnStmtFinder as a function with a callback
A callback enables the caller to control whether to abort the walk. This
is handy for `BraceHasExplicitReturnStmtRequest`.
2024-10-11 03:46:35 +03:00
Anthony Latsis
244185c4f4 [NFC] AST: Rename BraceHasReturnRequest to BraceHasExplicitReturnStmtRequest 2024-10-11 03:44:43 +03:00
Anthony Latsis
c7ea672463 [NFC] AST, Sema: Internalize BraceHasReturnRequest evaluation in AnyFunctionRef method 2024-10-11 03:44:43 +03:00
Slava Pestov
877c60e3d0 Sema: Rename applySolution() to replaySolution() 2024-10-08 16:16:01 -04:00
Slava Pestov
892e79cd70 Sema: Use an xmacro to clean up some duplication in CSTrail.cpp 2024-10-07 16:50:46 -04:00
Slava Pestov
c7edc3494e Sema: Record result builder transforms in the trail 2024-10-07 16:50:45 -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
a73e44a78f [Sema] Split out result builder pre-checking
Use `preCheckTarget` to pre-check the body,
allowing us to replace `PreCheckResultBuilderRequest`
with a request that only checks the brace for
ReturnStmts.
2024-08-03 16:05:09 +01:00
Hamish Knight
816f0b97e9 [Sema] NFC: Remove SuppressDiagnostics from PreCheckResultBuilderRequest
This is always `false`.
2024-08-03 16:05:08 +01: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
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Hamish Knight
f7753de1c8 [Completion] Only skip result builder expressions in the same builder
Previously we would skip any expression in a
result builder that didn't contain the completion
token, but that would cause issues if e.g the
result builder was needed to infer the type of a
variable that we're completing on. Instead, only
skip expressions in a result builder if the
completion token is in the same builder and the
expression itself doesn't contain the completion.

rdar://127154780
2024-06-07 21:06:16 +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
cbbb1c9eca [CS] Avoid creating placeholder var if skipping for completion
Otherwise we'd crash in CSApply since we'd have no
type recorded for the var.

rdar://127838305
2024-05-17 15:46:40 +01:00
cui fliter
127077b3aa chore: fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 17:23:22 +08: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
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
c97d80b1c3 [AST] NFC: Add convenience constructors for ReturnStmt
Add `ReturnStmt::createParsed` and `createImplict`.
2024-01-23 19:30:18 +00:00
Alex Hoppen
09ae4f5d5d [CodeCompletion] Fix issue in which parts of a result builder were incorrectly skipped
`getLoc` does not necesarrily return the start location of the location (e.g. for `a.b().c()` it returns the location of `c` because that’s the location of the call). But we used the location from `getLoc` as the start location of the synthesized `buildExpression` call. In the added test case, this means that the `buildExpression` call only contained `everlay() {}` and not the code completion token. We thus infered that we could skip it the entire `MyStack {}.pnTabGesture {}.everlay() {}` call for code completion, which isn’t correct.

rdar://120798355
2024-01-12 15:03:57 -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
Alex Hoppen
18979b304b [Sema] Delete ClosuresInResultBuilderDontParticipateInInference
Since we migrated all of code completion to solver-based, this flag is no longer needed.
2023-09-07 13:15:23 -07:00