Commit Graph

453 Commits

Author SHA1 Message Date
Hamish Knight
cb0a21da2a Merge pull request #83170 from hamishknight/fix-assert
[IDE] Fix assertion failure in `PostfixCompletionCallback::Result::tryMerge`
2025-07-21 18:48:03 +01:00
Hamish Knight
347d94bda5 [test] Add some alias crash signatures
The signatures here are bogus, put the correct signatures in as
aliases.
2025-07-20 18:46:18 +01:00
Hamish Knight
a2d707be2a [test] Remove duplicate test case
This is essentially the same as `8668a3eb11f2baf.swift`.
2025-07-20 18:32:45 +01:00
Hamish Knight
7e22f9264b [test] Update some crasher signatures
The signatures have changed here either due to code changes in the
repo or due to improvements to the signature detection, update the
test cases.
2025-07-20 18:32:38 +01:00
Hamish Knight
62f1303bca [IDE] Fix assertion failure in PostfixCompletionCallback::Result::tryMerge
Unfortunately due to pre-checking multiple times the recorded
application level can change. Just OR the bits together.
2025-07-18 11:00:37 +01:00
Hamish Knight
72db18073c [Sema] Set ReturnStmt result even if type-checking fails
Make sure we set the updated expression since e.g pre-checking may
have folded a top-level SequenceExpr that we need to remove from the
AST.
2025-07-16 14:40:57 +01:00
Hamish Knight
818979fed8 Merge pull request #83034 from hamishknight/origami
[Sema] Avoid folding sequences multiple times
2025-07-15 09:14:55 +01:00
Hamish Knight
7508cb7d3b [test] Add some more known crashers 2025-07-14 19:56:51 +01:00
Hamish Knight
af96c9860c [Sema] Avoid folding sequences multiple times for completion
Completion can end up calling into pre-checking multiple times in
certain cases, make sure we don't attempt to fold a SequenceExpr
multiple times since its original AST is in a broken state
post-folding. Instead, just return the already-folded expression.

rdar://133717866
2025-07-14 17:30:02 +01:00
Hamish Knight
3f74263ab4 Merge pull request #82910 from hamishknight/unbounded 2025-07-10 08:42:55 +01:00
Hamish Knight
adbbb9e3cd [IDE] Fix sort predicate in printCodeCompletionLookedupTypeNames
This wasn't a strict weak ordering, and it turns out violating that
is undefined behavior which can result in buffer overruns.
2025-07-09 19:50:43 +01:00
Hamish Knight
e631a37d0b [Completion] Avoid using unbound contextual type in argument completion
Match the logic in `getTypeForCompletion` and avoid using an unbound
generic type as the expected type for a completion.

rdar://155420395
2025-07-09 12:57:36 +01:00
Hamish Knight
3ab8fb7053 [test] Tweak a couple of crasher test cases
- Make `539adae64314fae.swift` macOS-only and use guard malloc for it.
- Tweak `1e4b431ffe374ef1.swift` such that it succeeds if it either
times out after a minute or crashes. While here, also clean up the
test case a little.
2025-07-09 12:14:02 +01:00
Hamish Knight
5cbdcaf655 Merge pull request #82834 from hamishknight/fuzzy
[test] Add some more known crashers
2025-07-08 08:32:52 +01:00
Hamish Knight
8b3cb86d7f Merge pull request #82802 from hamishknight/context-fail
[Completion] Map failable initializer result type into context
2025-07-08 06:20:17 +01:00
Hamish Knight
5730eb2e10 [test] Add some more known crashers 2025-07-07 11:12:36 +01:00
Hamish Knight
3a8bf75951 Merge pull request #82761 from hamishknight/req-assert
[test] Require asserts for IDE crashers
2025-07-04 14:10:10 +01:00
Hamish Knight
e7bf62dd81 [Completion] Map failable initializer result type into context
Make sure we don't pass an interface type to `setTypeContext`.

rdar://155038769
2025-07-04 13:55:40 +01:00
Hamish Knight
d6037049b1 [CS] Ensure type variables are eliminated by Solution::simplifyType
`TypeSimplifier` may not eliminate type variables from e.g the
pattern types of pattern expansion types since they can remain
unresolved due to e.g having a placeholder count type. Make sure we
eliminate any remaining type variables along with the placeholders.
There's probably a more principled fix here, but this is a quick and
low risk fix we can hopefully take for 6.2.

rdar://154954995
2025-07-03 16:24:31 +01:00
Hamish Knight
4aee90318a [test] Require asserts for IDE crashers 2025-07-03 10:53:27 +01:00
Hamish Knight
3daae5955e [AST] Use ErrorType for invalid value generic parameter
If we fail to resolve the value type for a value generic parameter,
previously we would have returned a null Type, causing crashes
downstream. Instead, return an ErrorType, leaving a null Type for
cases where the generic parameter isn't a value generic at all.

rdar://154856417
2025-07-02 14:46:55 +01:00
Hamish Knight
beb2b58d62 [test] Mark a couple of IDE crashers as fixed (#82685)
Seems like these may have been fixed by #82574, unfortunately there was
a race with #82619
2025-07-01 11:00:29 -07:00
Hamish Knight
b9afc87c28 [test] Add some more known crashers 2025-06-30 20:52:06 +01:00
Hamish Knight
db49faf167 [Sema] Avoid solver-allocated original ErrorTypes in transformDependentMemberType
`substBase` here can contain type variables or placeholders, avoid
using them as the original ErrorTypes since ErrorTypes cannot be
solver-allocated currently. This only affects type printing so
shouldn't matter much.
2025-06-12 17:54:59 +01:00
Hamish Knight
110f11493a [IDE] Avoid uses of isBeforeInBuffer in TypeCheckASTNodeAtLocRequest
Use the higher level APIs on SourceManager that handle locations in
parent vs child buffers. This then allows us to fix `walkToDeclPre`
such that we don't set the found DeclContext unless the location is
actually within that decl (here the location may well be in a
separate buffer as we may have a replaced function body).
2025-05-14 11:15:42 +01:00
Hamish Knight
247dda9639 [ASTPrinter] Add missing null check in isNonSendableExtension
The extended nominal may not be present for an invalid extension.

rdar://149032713
2025-04-23 15:26:10 +01:00
Hamish Knight
9114aad02c [Sema] Ignore types with type variables in filterEscapableLifetimeDependencies
If the type still has type variables, avoid trying to check if it's
escapable.

rdar://148749815
2025-04-08 14:14:42 +01:00
Ben Barham
c2e05c26c2 [Test] Re-enable completion tests that are now fixed 2025-03-12 08:35:50 -07:00
Mishal Shah
9f2ce02cfc [Disabled] 6 tests to support new version of Xcode 16.2 and macOS 15.2 https://github.com/swiftlang/swift/issues/79255 2025-02-09 20:01:27 -08:00
Hamish Knight
4e33cef20c [AST] Walk into LocatableType in TypeWalker
Make sure we walk into the underlying type for
LocatableType.
2025-01-02 15:02:11 +00:00
Hamish Knight
7061a20edd [CS] Remove ConstraintSystem::getVarType
The logic here for completion wasn't actually
helping things since it would result in adding the
var overload to the system, which would result
in an ErrorType binding. We could turn the ErrorType
into a placeholder when resolving the overload,
but the simpler solution is to just allow CSGen
to turn the reference into a PlaceholderType. This
matches what we do for regular solving, and fixes
a crash with an IUO completion.

rdar://89369091
2024-11-04 17:08:20 +00:00
Alex Hoppen
a287e2ae8e [SourceKit] Check if the realpath of a module is inside the SDK to decide if it's system
On Windows, we run into the following situation when running SourceKit-LSP tests:
- The SDK is located at `S:\Program Files\Swift\Platforms\Windows.platform\Developer\SDKs\Windows.sdk` with `S:` being a substitution drive
- We find `Swift.swiftmodule` at `S:\Program Files\Swift\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\Swift.swiftmodule`
- Now, to check if `Swift.swiftmodule` is a system module, we take the realpath of the SDK, which resolves the substitution drive an results in something like `C:\Users\alex\src\Program Files\Swift\Platforms\Windows.platform\Developer\SDKs\Windows.sdk`
- Since we don’t take the realpath of `Swift.swiftmodule`, we will assume that it’s not in the SDK, because the SDK’s path is on `C:` while `Swift.swiftmodule` lives on `S:`

To fix this, we also need to check if a module’s real path is inside the SDK.

Fixes swiftlang/sourcekit-lsp#1770
rdar://138210224
2024-10-19 10:35:09 -07:00
Hamish Knight
3b0d692b30 [test] Restrict complete_sdk_platform.swift to macOS
rdar://135232586
2024-09-04 10:26:23 +01:00
Hamish Knight
142daacd61 [test] Re-enable expectation in complete_sdk_platform.swift
rdar://134963605
2024-09-03 18:40:51 +01:00
Hamish Knight
4f1bebf598 [test] NFC: Factor out %xcode-extra-platform-search-paths 2024-09-03 14:19:59 +01:00
Hamish Knight
51dcc9e0b9 [test] Temporarily remove a check from complete_sdk_platform.swift 2024-08-29 22:19:05 +01:00
Hamish Knight
940f5f7c2a [AST] Treat platform modules as non-user
Modules defined within the SDK are considered
non-user modules, extend this to any module found
within the parent platform directory if there is
one. This ensures we include modules such as
XCTest and Testing.

rdar://131854240
2024-08-23 14:23:37 +01:00
Hamish Knight
26e8245e22 [Sema] Requestify pattern resolution
Add a cached request to perform pattern resolution.
This is needed to prevent the constraint system
from resolving the same pattern multiple times
along different solver paths, which could result
in creating different pattern nodes for each path.
Once pattern resolution is moved to pre-checking
we ought to be able to make this uncached.

rdar://128661960
2024-06-13 15:27:47 +01:00
Alex Hoppen
22f0daf7d5 [CodeCompletion] Don’t compute isolated parameter captures during code completion
Computing capture information requires a type checked AST, which we don’t have during code completion. To fix an assertion failure, don’t look for a captured `isolated` parameter while computing a closure’s actor isolation during code completion.

rdar://126923558
2024-05-31 17:44:00 -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
Alex Hoppen
278ecef284 [CodeCompletion] Don’t report a call pattern as convertible if its result type doesn’t match
To compute the expected type of a call pattern (which is the return type of the function if that call pattern is being used), we called `getTypeForCompletion` for the entire call, in the same way that we do for the code completion token. However, this pattern does not generally work. For the code completion token it worked because the code completion expression doesn’t have an inherent type and it inherits the type solely from its context. Calls, however, have an inherent return type and that type gets assigned as the `typeForCompletion`.

Implement targeted checks for the two most common cases where an expected type exists: If the call that we suggest call patterns for is itself an argument to another function or if it is used in a place that has a contextual type in the constraint system (eg. a variable binding or a `return` statement). This means that we no longer return `Convertible` for call patterns in some more complex scenarios. But given that this information was computed based on incorrect results and that in those cases all call patterns had a `Convertible` type relation, I think that’s acceptable. Fixing this would require recording more information in the constraints system, which is out-of-scope for now.
2024-04-10 16:06:47 -07:00
Alex Hoppen
17520dcf6d [CodeCompletion] Always suggest call pattern for nested function calls
When completing in cases like `bar(arg: foo(|, option: 1)`, we don’t know if `option` belongs to the call to `foo` or `bar`. Be defensive and also suggest the signature.
2024-02-21 18:53:07 -08:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Alex Hoppen
695e69e09e [CodeComplete] Suggest single argument labels if code completion is invoked at start of function call with exiting parameters
This removes the distinction between argument completions and postfix expr paren completions, which was meaningless since solver-based completion.

It then determines whether to suggest the entire function call pattern (with all argument labels) or only a single argument based on whether there are any existing arguments in the call.

For this to work properly, we need to improve parser recovery a little bit so that it parsers arguments after the code completion token properly.

This should make call pattern heuristics obsolete.

rdar://84809503
2024-01-22 12:21:04 -08: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
Alex Hoppen
e56708c84f [CodeCompletion] Fix crash when completing inside a protocol that inherits from other protocol with extension
rdar://119408961
2023-12-13 14:27:50 -08:00
Alex Hoppen
423826f742 [CodeComplete] Add test case for #57148, #57149
The issue no longer occurs on `main`. Add a test case for it.

Fixes #57148
Fixes #57149
2023-11-23 18:01:03 -08:00
Alex Hoppen
a5a17aa955 [tests] Add a %batch-code-completion lit substitution
I could never remember the command to run batch code completion tests. Add a lit substitution for it.
2023-09-18 13:57:49 -07:00
Alex Hoppen
a1bfb510e1 [CodeCompletion] Migrate labeled trailing closure completions to solver-based
rdar://113472967
2023-08-24 15:41:36 -07:00
Alex Hoppen
4f5743c8c6 [IDE] Adjust more test cases 2023-07-07 19:51:01 +02:00