Commit Graph

429 Commits

Author SHA1 Message Date
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
Alex Hoppen
c7e0bfae02 [IDE] Adjust test cases for migrating all completion kinds to solver-based 2023-07-07 19:51:01 +02:00
Alex Hoppen
928a03a2e0 [CodeCompletion] Migrate conforming methods list to solver-based 2023-07-07 19:51:01 +02:00
Alex Hoppen
00eaed3af9 [CodeCompletion] Migrate postfix expr completion to solver-based 2023-07-07 19:51:01 +02:00
Alex Hoppen
4c186c0a9a [CodeCompletion] Fix code completion issues related to type checking tap expressions in the cosntraint system 2023-07-07 19:50:46 +02:00
Alex Hoppen
1eadffcc00 [CodeCompletion] Don’t crash when completing in a parameter position that only constraints one of two primary associated protocol types
When completing, we call `getExistentialType` on the contextual type to get a nice and concise description of the contextual parameter’s type that doesn’t contain archetypes and which we can also serialize into a USR so we are able to calculate type relations for code completion results from the code completion cache.

When completing in a position that has a contextual type which only constrains one of two primary associated protocol types, this fails because `getExistentialType` (which calls `getDependentUpperBounds`) tries to form a `ParameterizedProtocolType`, which fails since not all primary associated types have been constrained.

AFAICT the fix here is to just fall back to the default behavior of returning the plain protocol type instead of `abort`ing.

rdar://108835466
2023-05-10 16:38:30 -07:00
Alex Hoppen
50249551a7 [CodeCompletion] Fix another test that was causing an assertion failure in the stress tester 2023-05-09 17:19:31 -07:00
Alex Hoppen
32eff21977 [IDE] Remove "Begin completions" and "End completions" from test cases
These test lines weren't actually providing any value and were annoying to write. Let's jut remove them.
2023-03-22 09:07:17 -07:00
Alex Hoppen
46f5119113 [CodeCompletion] Don’t crash if constructors in member lookup have an error type 2023-02-22 22:33:42 +01:00
Pavel Yaskevich
bffb8d9ee2 Revert "[CSGen] Handle recursive use of variable declarations" 2023-02-10 16:45:59 -08:00
Pavel Yaskevich
83dd93ad2e [CSGen] Handle recursive use of variable declarations
It's possible for out-of-scope type variable to be the type of
declaration if such declaration is recursively referenced in
the body of a closure located in its initializer expression.
In such cases type of the variable declaration cannot be connected
to the closure because its not known in advance (determined by the
initializer itself).

Resolves: https://github.com/apple/swift/issues/63455
2023-02-07 17:48:26 -08:00
Pavel Yaskevich
697dfbae96 [TypeChecker] Enable result builder AST transform by default 2022-12-21 10:31:30 -08:00
Rintaro Ishizaki
4e334498e8 [CodeCompletion] Don't suggest opaque generic parameter types
'some' parameter types don't have spelling.

rdar://102958462
2022-12-15 13:26:17 -08:00
Anthony Latsis
afb1eecb3e Gardening: Migrate test suite to GH issues: validation-test/IDE 2022-09-19 22:47:19 +03:00
Slava Pestov
7d8f3e6b63 AST: Change return type of Requirement::subst() to Requirement
Instead of returning None, let callers check hasError() if they need to.

Fixes rdar://problem/98565072.
2022-08-12 14:03:57 -04:00
Alex Hoppen
ae53e8a048 [CS] Remove assertion that callee locator has an anchor
When computing type relations of code completion items with respect to the context they are used in, we add a `ConstraintKind::Conversion` constraint with an empty constraint locator. This currently crashes in `hasPreconcurrencyCallee`, but actually having a null anchor doesn’t produce any issues.
2022-07-14 15:45:38 +02:00
Alex Hoppen
7245f5810c Merge pull request #58890 from ahoppen/pr/add-more-fixed-test-cases
[CodeCompletion] Add test cases that were fixed and had reduced reproducers
2022-07-01 15:09:35 +02:00
Pavel Yaskevich
3159591234 [TypeChecker/CodeCompletion] Re-introduce expression sanitization before solving
A call to `SanitizeExpr` has been incorrectly removed from
`typeCheckForCodeCompletion` by refactoring to use `ASTNode`.

It is still required because fallback calls could have partially
type-checked AST.

Resolves: https://github.com/apple/swift/issues/59315
Resolves: rdar://94619388
2022-06-08 13:26:54 -07:00
Alex Hoppen
49f8bdb019 [CodeCompletion] Add test cases that were fixed and had reduced reproducers
The following issues no longer reproduce on `main` and had reduced reproducers. Add them to the test suite.

- SR-12977
- SR-14691
- SR-15113
- rdar://63063279
- rdar://64227741
- rdar://69813796
- rdar://85609548
2022-05-13 15:49:08 +02:00
Luciano Almeida
3f8144c57f [Sema] Allow optional hole propagation in code completion mode 2022-05-11 23:23:46 -03:00
Alex Hoppen
eb8df860e8 Merge pull request #58522 from ahoppen/pr/no-circular-supertypes
[CodeCompletion] Avoid creating circles in the USRBasedType supertype hierarchy
2022-05-03 09:43:08 +02:00
Alex Hoppen
b4fca1a40e [CodeCompletion] Avoid creating circles in the USRBasedType supertype hierarchy
You would think that superclass + conformances form a DAG. You are wrong!
We can achieve a circular supertype hierarcy with

```swift
protocol Proto : Class {}
class Class : Proto {}
```

USRBasedType is not set up for this. Serialization of code completion results from global modules can't handle cycles in the supertype hierarchy
because it writes the DAG leaf to root(s) and needs to know the type offsets. To get consistent results independent of where we start
constructing USRBasedTypes, ignore superclasses of protocols. If we kept track of already visited types, we would get different results depending on
whether we start constructing the USRBasedType hierarchy from Proto or Class.
Ignoring superclasses of protocols is safe to do because USRBasedType is an under-approximation anyway.

rdar://91765262
2022-04-29 12:53:17 +02:00
Alex Hoppen
0a79ab7637 [IDE] Add test case for SR-14708
SR-14708 is no longer happening in the stress tester. Add its test case to the test suite.

rdar://78781625
2022-04-22 09:50:24 +02:00
Alex Hoppen
5d01a097e1 [CodeCompletion] Don't distinguish convertible and idenical type relation
I think that preferring identical over convertible makes sense in e.g. C++ where we have implicit user-defined type conversions but since we don’t have them in Swift, I think the distinction doesn’t make too much sense, because if we have a `func foo(x: Int?)`, want don’t really want to  prioritize variables of type `Int?` over `Int` Similarly if we have `func foo(x: View)`, we don’t want to prioritize a variable of type `View` over e.g. `Text`.

rdar://91349364
2022-04-13 08:28:17 +02:00
Alex Hoppen
f2e1f30f66 [CodeCompletion] Add test case for SR-15502 2022-04-06 09:19:12 +02:00