Commit Graph

304 Commits

Author SHA1 Message Date
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
Hamish Knight
6ee44f09b4 Introduce then statements
These allow multi-statement `if`/`switch` expression
branches that can produce a value at the end by
saying `then <expr>`. This is gated behind
`-enable-experimental-feature ThenStatements`
pending evolution discussion.
2023-09-01 14:32:14 +01:00
Alex Hoppen
ed4dc1becd Change Optional -> llvm::Optional 2023-07-07 21:16:33 +02:00
Alex Hoppen
527a79e9f8 [IDE] Set constraint system options from solveForCodeCompletion in applyResultBuilderBodyTransform when solving for code completion 2023-07-07 19:51:01 +02:00
Alex Hoppen
1bacfe9cd4 [IDE] Ignore unspported constructs in result builders in code completion mode 2023-07-07 19:51:01 +02:00
Alex Hoppen
0c413109d3 [CodeComplete] Skip conjunction elements unrelated to the code completion token 2023-07-07 19:50:46 +02:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07: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
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Hamish Knight
21e787bae8 [Sema] Walk SyntacticElementTarget for completion
Instead of walking the single ASTNode from the
target, walk all AST nodes associated with the
target to find the completion expr. This is needed
to find the completion expr in a pattern for an
initialization target.
2023-06-07 00:35:01 +01:00