Commit Graph

294 Commits

Author SHA1 Message Date
Hamish Knight
54e0607091 [Sema] Add missing null check for Type
`getType` here can return a null type if the queried expression isn't
part of the solution, which can currently happen for code completion.
I'm working on a more principled fix for this, but until then this is
a low-risk fix that will unblock the stress tester and can be
cherry-picked to 6.2.

rdar://149759542
2025-04-23 12:58:28 +01: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
Allan Shortlidge
af84818e5c IDETool: Register SourceFile for replaced function body.
This prevents a nullptr dereference in `ASTScope::unqualifiedLookup()` after
querying for the `SourceFile` containing a give source location.

Fixes rdar://137652856 and https://github.com/swiftlang/swift/issues/76944.
2024-10-10 17:24:17 -07:00
Alex Hoppen
7691569344 [SourceKit] Update completion cancellation test to a harder type checking example
https://github.com/swiftlang/swift/pull/63585 will resolve rdar://80582770 and the type checker performance problem that we were relying on. Use a harder example (stolen from https://github.com/swiftlang/swift/blob/main/unittests/SourceKit/SwiftLang/CloseTest.cpp#L131-L151), that’s unlikely to get a significant performance improvement soon.
2024-09-16 14:48:18 -07:00
Alexander Cyon
c822965379 [test/SourceKit] Revert incorrect typo changes ('CHECKD'). 2024-07-08 20:37:04 +02:00
Alexander Cyon
ba43236def Update test/SourceKit/CodeComplete/complete_typerelation.swift.identical.response
Co-authored-by: Ben Barham <b.n.barham@gmail.com>
2024-07-08 20:33:23 +02:00
Alexander Cyon
906585ba74 Update test/SourceKit/CodeComplete/complete_typerelation.swift.identical.response
Co-authored-by: Ben Barham <b.n.barham@gmail.com>
2024-07-08 20:33:17 +02:00
Alexander Cyon
44fea1f810 Update test/SourceKit/CodeComplete/complete_typerelation.swift.identical.response
Co-authored-by: Ben Barham <b.n.barham@gmail.com>
2024-07-08 20:33:10 +02:00
Alexander Cyon
27ff8b9480 Update test/SourceKit/CodeComplete/complete_typerelation.swift.convertible.response
Co-authored-by: Ben Barham <b.n.barham@gmail.com>
2024-07-08 20:33:02 +02:00
Alexander Cyon
b85054907a Update test/SourceKit/CodeComplete/complete_typerelation.swift.convertible.response
Co-authored-by: Ben Barham <b.n.barham@gmail.com>
2024-07-08 20:32:56 +02:00
Alexander Cyon
bda8314044 Update test/SourceKit/CodeComplete/complete_typerelation.swift.convertible.response
Co-authored-by: Ben Barham <b.n.barham@gmail.com>
2024-07-08 20:32:48 +02:00
Alexander Cyon
10447c32d2 [test/SourceKit] Fix typos 2024-07-06 13:28:59 +02:00
Hamish Knight
ddd1bde60e [Completion] Don’t generate USRs for local decls
Doing so can cause issues since we cannot guarantee
that e.g any parent closures have been type-checked.

rdar://128294522
2024-06-17 22:20:57 +01:00
Alex Hoppen
743d29ced3 Merge pull request #73473 from ahoppen/import-extern-c-from-bridging-header
[ClangImporter] Import `extern "C"` declarations from the bridging header
2024-05-08 15:06:30 -07:00
Alex Hoppen
9fdbb86cbd [ClangImporter] Import extern "C" declarations from the bridging header
We do iterate into extern C declarations when building the Swift lookup table during PCH generation.

0fad799f51/lib/ClangImporter/SwiftLookupTable.cpp (L2140-L2146)

However, we don’t import `extern "C"` declarations while parsing the bridging header (eg. when no `-pch-output-dir` is specified during code completion). This caused us to miss functions annotated as `extern "C"` in code completion.

rdar://127512985
2024-05-08 11:01:21 -07:00
Alex Hoppen
0c24f3f71c [Lexer] Fix an assertion failure when invoking code completion inside a single-quoted string literal
rdar://126924962
2024-05-06 15:25:00 -07:00
Alex Hoppen
7ce41252e7 [SourceKit] Print compilerargs and sourcetext keys last
That way, when the request gets truncated by os_log in sourcekit-lsp, we see most of the request. Most likely the sourcetext and the compiler args wouldn't have made it into the log message completely anyway.

rdar://121322828
2024-02-29 20:45:55 -08: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
Rintaro Ishizaki
47f18d492e [ASTGen] Move regex literal parsing from SwiftCompilerSources to ASTGen
ASTGen always builds with the host Swift compiler, without requiring
bootstrapping, and is enabled in more places. Move the regex literal
parsing logic there so it is enabled in more host environments, and
makes use of CMake's Swift support. Enable all of the regex literal
tests when ASTGen is built, to ensure everything is working.

Remove the "AST" and "Parse" Swift modules from SwiftCompilerSources,
because they are no longer needed.
2023-11-16 10:59:23 -08:00
Alexis Laferrière
8b098ab487 [Tests] Remove the flag AccessLevelOnImport from all tests but one 2023-10-10 09:09:22 -07:00
Alex Hoppen
c7e0bfae02 [IDE] Adjust test cases for migrating all completion kinds to solver-based 2023-07-07 19:51:01 +02:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Hamish Knight
be31c22e58 Update to use --leading-lines for split-file 2023-04-26 12:38:38 +01:00
Hamish Knight
4606b14fea Refactor a couple of tests
Match the format of the spi and package variants of
these tests.
2023-04-26 12:38:38 +01:00
Hamish Knight
4e838e0a26 Serialize package and SPI doc comments in swiftsourceinfo
Previously we were using the same set of conditions
for serializing as for swiftdoc, so excluded them.
However it's reasonable to have them in the
swiftsourceinfo.
2023-04-26 12:38:38 +01:00
Ben Barham
31dee1ce1c [Completion] Only provide macro completions when they are valid
Only return macros that are valid in their current position, ie. an
attached macro is not valid on a nominal.

Also return freestanding expression macros in code block item position
and handle the new freestanding code item macros.

Resolves rdar://105563583.
2023-04-07 18:43:06 -07:00
Doug Gregor
68b367b266 Disable macros-related tests harder 2023-03-29 16:32:32 -07:00
Doug Gregor
30f17940f9 Require the Swift swift parser for a few tests affected by macros 2023-03-29 16:32:32 -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
Doug Gregor
56bf3dfa05 Update tests 2023-03-02 22:17:23 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Doug Gregor
5936b7b585 Add test that started crashing with my initial rework of closure discriminators.
Thanks to Alex Hoppen for providing this test!
2023-01-02 21:22:05 -08:00
Ben Barham
8cce534878 [NFC] Remove SK test for overrides
The IDE tests already cover overrides, in much more detail than this
test.
2022-10-27 13:29:00 -07:00
Rintaro Ishizaki
7ab18ff8ce Merge pull request #42545 from jsoref/spelling-sourcekit
Spelling sourcekit
2022-09-22 16:26:17 -07:00
Anthony Latsis
a8b83b4e06 Gardening: Migrate test suite to GH issues: SourceKit 2022-09-22 03:21:39 +03:00
Josh Soref
436484c8c8 Gardening: Fix spelling mistakes in */SourceKit
* about
* and
* answering
* because
* before
* cancellation
* clear
* comment
* complete
* corresponding
* cursor
* custom
* dependencies
* doesn't
* expression
* extension
* immediately
* implementation
* implicit
* innovation
* intentionally
* occasionally
* oldest
* parameter
* property
* response
* reuseastcontext
* snapshot
* sourcekit_swift_runtime_link_flags
* synchronously
* target
* that
* unlabeled
* usefulness
* work

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-09-21 02:03:25 -04:00
Hamish Knight
53994d1faa [Parse] Fix code completion crash when avoiding skipping
Fix a crash that could occur when performing
completion at the start of an accessor body.
Previously we assumed `CodeCompletion` would never
be null due to function body skipping in the first
pass of code completion. However with the
introduction of the ability to avoid skipping in
certain cases, it might be now be null if we need
to avoid skipping. Found by the stress tester.

rdar://95772803
2022-06-23 15:57:05 +01:00
Rintaro Ishizaki
9f3bc0e85b [CodeCompletion] _compilerInitialized and _local are UserInaccessible
These declaration modifiers are not meant to be used from user source
code. Mark them 'UserInaccessible' so code completion don't show them.

rdar://92970201
2022-05-09 15:30:59 -07:00
Rintaro Ishizaki
2805864bb5 [CodeCompletion] Suggest 'actor' decl introducer keyword
Previously 'actor' keyword was suggested as (deprecated) 'actor' decl
modifier, and it was gated by '-enable-experimental-concurrency'
compiler argument.
Add 'actor' as a type decl introducer. This causes duplicated 'actor' in
code completion if '-enable-experimental-concurrency', but that option
is basically useless at this point, so I assume not many people is using
it. Also 'actor' as a modifier will be removed soon.

[#58520] rdar://92511769
2022-05-05 14:37:44 -07:00
Rintaro Ishizaki
eade9b7bc9 [LookupVisibleDecls] Implement shadowing for unqualified lookups
Tweaked usable check:
  * Local type/func decls are usable even before declaration
  * Outer nominal Instance member are not usable
  * Type context cannot close over values in outer type contexts

Added shadowing rule by the base name:
  * Type members don't shadow each other as long as they are in the
    same type context.
  * Local values shadow everything in outer scope
    * Except that 'func' decl doesn't shadow 'var' decl if they are in the
      same scope.

rdar://86285396
2022-04-28 16:36:54 -07: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
Ben Barham
ff5f1b9bff Merge pull request #41929 from bnbarham/ast-manager-use-overlays
[SourceKit] Make sure to use overlays when reading files
2022-03-25 10:02:32 -07:00
Kavon Farvardin
053286a805 fix code completion test 2022-03-24 16:20:06 -07:00
Ben Barham
15ada41a5a [SourceKit] Make sure to use overlays when reading files
Two paths missed setting up overlays:
  - `CompletionInstance` when checking files from dependencies
  - `SwiftASTManager` when reading in files that it would later replace
    all inputs with

(1) would cause the AST context not to be re-used, even though nothing
had changed. (2) caused all non-completion functionality to fail for any
symbols within files only specified by the overlay.

Resolves rdar://85508213.
2022-03-24 15:30:02 -07:00
Konrad `ktoso` Malawski
b92874c1a2 [Distributed] fix source completion test; it suggests distributed too now 2022-03-12 00:13:50 +09:00
Alex Hoppen
94351a2f82 [CodeComplete] Compute type relations for global cached results
Computing the type relation for every item in the code completion cache is way to expensive (~4x slowdown for global completion that imports `SwiftUI`). Instead, compute a type’s supertypes (protocol conformances and superclasses) once and write their USRs to the cache. To compute a type relation we can then check if the contextual type is in the completion item’s supertypes.

This reduces the overhead of computing the type relations (again global completion that imports `SwiftUI`) to ~6% – measured by instructions executed.

Technically, we might miss some conversions like
- retroactive conformances inside another module (because we can’t cache them if that other module isn’t imported)
- complex generic conversions (just too complicated to model using USRs)

Because of this, we never report an `unrelated` type relation for global items but always default to `unknown`.

But I believe this change covers the most common cases and is a good tradeoff between accuracy and performance.

rdar://83846531
2022-03-02 23:13:09 +01:00
Hamish Knight
1f5845d9d9 Revert "[CodeComplete] Compute type relations for global cached results" 2022-03-02 21:43:31 +00:00
Alex Hoppen
640cfac61c [CodeComplete] Compute type relations for global cached results
Computing the type relation for every item in the code completion cache is way to expensive (~4x slowdown for global completion that imports `SwiftUI`). Instead, compute a type’s supertypes (protocol conformances and superclasses) once and write their USRs to the cache. To compute a type relation we can then check if the contextual type is in the completion item’s supertypes.

This reduces the overhead of computing the type relations (again global completion that imports `SwiftUI`) to ~6% – measured by instructions executed.

Technically, we might miss some conversions like
- retroactive conformances inside another module (because we can’t cache them if that other module isn’t imported)
- complex generic conversions (just too complicated to model using USRs)

Because of this, we never report an `unrelated` type relation for global items but always default to `unknown`.

But I believe this change covers the most common cases and is a good tradeoff between accuracy and performance.

rdar://83846531
2022-03-01 09:16:23 +01:00