Commit Graph

404 Commits

Author SHA1 Message Date
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
Alex Hoppen
458ce70245 Merge pull request #41633 from ahoppen/pr/solver-based-global-completions
[CodeCompletion] Migrate expression completions to solver-based
2022-03-21 20:02:47 +01:00
Alex Hoppen
e2a62f1a60 [CodeCompletion] Migrate expression completions to solver-based 2022-03-21 13:00:33 +01:00
Alex Hoppen
1680ec3f08 Merge pull request #41853 from ahoppen/pr/add-fixed-test-cases
[CodeCompletion] Add test cases
2022-03-18 17:09:11 +01:00
Alex Hoppen
f538d33e5f [CodeCompletion][Sema] Migrate CallArgurment position completion to the solver-based implementation
This hooks up call argument position completion to the typeCheckForCodeCompletion API to generate completions from all the solutions the constraint solver produces (even those requiring fixes), rather than relying on a single solution being applied to the AST (if any).

Co-authored-by: Nathan Hawes <nathan.john.hawes@gmail.com>
2022-03-17 15:15:54 +01:00
Alex Hoppen
4af49e3479 [CodeCompletion] Add test cases
Add test cases for three issues that have been fixed on main
- SR-14693
- SR-14704
- SR-14739
2022-03-17 09:03:17 +01:00
Alex Hoppen
f42f961faf [Sema] Copy key path component types when merging solutions
In 2eeff365b1 I forgot to copy key path component types when applying a solution to the constraint system. That caused a crash in key path code completion.

Fixes rdar://81118700 [SR-14979]
2021-07-30 11:07:21 +02:00
Alex Hoppen
1a7d98795c Merge pull request #38474 from ahoppen/pr/dont-precheck-twice
[CodeCompletion] Allow preChecking an expression twice in code completion
2021-07-28 21:51:16 +02:00
Alex Hoppen
fec7f6c3c0 [CodeCompletion] Fix issue causing the completion status to not be set correctly for pattern completion
We weren’t setting the code completion token status correctly when parsing patterns with code completion tokens.

Because of this, in the added test case, the `searchSubject` gets added as a member of `Foo` twice - once in the first pass and once in the second pass, causing an assertion failure.

Fixes rdar://80575116 [SR-14687]
2021-07-26 20:50:10 +02:00
Hamish Knight
2d951efd8b [CS] Don't bail out of CollectVarRefs early
Upon encountering an ErrorExpr, we were previously
bailing from the walk. However, for multi-statement
closures, that could result in us missing some
variable references required to connect to the
closure to its enclosing context. Make sure to
continue walking to catch those cases.

SR-14709
rdar://78781677
2021-07-21 23:04:06 +01:00
Alex Hoppen
202905fe40 [CodeCompletion] Allow preChecking an expression twice in code completion
In code completion we might call `preCheckExpression` twice - once for the first pass and once for the second pass. This is fine since `preCheckExpression` idempotent, so don't assert if we are in code completion mode.

Fixes rdar://79136653 [SR-14755]
2021-07-21 11:16:16 +02:00
Hamish Knight
74b6dd8404 [test] Fix validation-test/IDE/slow/rdar45511835.swift 2021-07-19 15:24:06 +01:00
Rintaro Ishizaki
aa182ac8e0 [Parse] Don't skip '}' when recovering from 'default' outside 'switch'
That caused assertion failures in code completion.

rdar://78781163
2021-06-23 08:44:32 -07:00
Rintaro Ishizaki
6dd5d9482f [CodeCompletion] Introduce "Flair" in code completion
To describe fine grained priorities.

Introduce 'CodeCompletionFlair' that is a set of more descriptive flags for
prioritizing completion items. This aims to replace '
SemanticContextKind::ExpressionSpecific' which was a "catch all"
prioritization flag.
2021-06-07 17:25:01 -07:00
Alex Hoppen
3b2372307c Merge pull request #37421 from ahoppen/pr/fix-crash-complete-in-result-builder-with-nil
[CodeComplete] Fix crash when completing inside a result builder containing a variable initialized with `nil`
2021-05-17 18:56:45 +02:00
Alex Hoppen
ad5dc2d76f [CodeComplete] Fix crash when completing inside a result builder containing a variable initialized with nil
Resolves rdar://78017503
2021-05-14 17:21:26 +02:00
Alex Hoppen
4566bf3136 [Sema] Remove TypeCheckExprFlags::AllowUnresolvedTypeVariables
Remove the `TypeCheckExprFlags::AllowUnresolvedTypeVariables` flag, fixing another occurance of rdar://76686564 (https://github.com/apple/swift/pull/37309)

This does not break anything in the test suite, so I think the removal of the flag is fine.

Resolves rdar://76686564 and rdar://77659417
2021-05-10 20:11:43 +02:00
Alex Hoppen
759419190e Merge pull request #36992 from ahoppen/pr/wrapping-lvalue
[TypeChecker] Clear param specifiers before re-typechecking expression for completion
2021-05-07 14:10:45 +02:00
Alex Hoppen
74ff6923a1 [Sema] Don’t allow unresolved type variables if LeaveBraceStmtBodyUnchecked is true
According to Pavel, we want to eliminate allowing unresolved variables as much as possible. Removing this flag doesn’t break any test cases (at least not in a meaningful way) and fixes a crasher, so it seems reasonable to remove it.

Fixes rdar://76686564
2021-05-06 10:19:05 +02:00
Alex Hoppen
b1a4708782 [TypeChecker] Clear param specifiers before re-typechecking expression for completion
Because we are completing inside a result builder, we are never calling into `typeCheckExpression` and thus never call into `typeCheckForCodeCompletion` before `fallbackTypeCheck` (SR-14601).

This works fine in most cases, but in the added test case, we are hitting an assertion because the specifiers are not correctly erased from the `ClosureExpr` before re-typechecking for completion. Erasing them before fixes the test case until the underlying issue described above is fixed.

Fixes rdar://76710904 [SR-14494]
2021-05-06 10:00:25 +02:00
Nathan Hawes
b8f5bf3434 [CodeCompletion][Parse] Don't drop the contained expression when completing within an InOutExpr
When completing within an InOutExpr like `&foo.<complete>`, we were forming a
CodeCompletionExpr with a base when parsing the content of the InOutExpr and
storing it in CodeCompletionCallbacksImpl::CodeCompleteTokenExpr. When the
result of that parse contained a code completion though, we were dropping the
sub-expression completely and forming an empty code completion result in place
of the inout expression, which resulted in later code inserting a code
completion expression with no base into the AST. The solver based completion
was later asking for the type of the code completion and its base using the
expression stored in CodeCompletionCallbacksImpl::CodeCompleteTokenExpr, but
that never ended up in the AST so we hit an assertion about the expression not
have a type in the formed solutions.

Resolves rdar://75366814
2021-04-03 13:39:23 +10:00
Alex Hoppen
2c0b8ac479 Merge pull request #36517 from ahoppen/pr/rdar64141399
[CodeComplete] Fix code completion of initialization for variable wrapped by generic property wrapper
2021-03-26 11:24:52 +01:00
Alex Hoppen
ef75cf7c77 Merge pull request #36534 from ahoppen/pr/rdar64265821
Add test case for rdar://64265821
2021-03-23 08:29:33 +01:00
Alex Hoppen
efbfbc4200 Merge pull request #36495 from ahoppen/pr/rdar71566576
Add test case for rdar://71566576
2021-03-22 17:32:52 +01:00
Alex Hoppen
86e5e7dbf3 Add test case for rdar://64265821
rdar://64265821 [SR-12985] appears to have been fixed already. Let’s add a test case for it.
2021-03-22 14:02:11 +01:00
Alex Hoppen
28ee60e893 [CodeComplete] Fix code completion of initialization for variable wrapped by generic property wrapper
If completing the initialization of a variable that’s wrapped in a generic, unbound property wrapper, the expression's type is an `UnboundGenericType`. AFAICT that’s expected and the correct type to assign.

We hit the first assertion failure by trying to retrieve that type's substitution map. `UnboundGenericType`s were not handled here, so we crashed. AFAICT we can't get any substitutions out of an unbound generic type, so we should just continue looking into the parent type.

We hit the second assertion when trying to retrieve the property wrapper’s backing type, which is null (becuase it couldn't be resolved). However, we haven’t emitted a diagnostic because the variable declaration is perfectly valid. Hence I’m removing the assertion.

Fixes rdar://64141399
2021-03-19 20:51:48 +01:00