Commit Graph

434 Commits

Author SHA1 Message Date
Rintaro Ishizaki
fad6ba9459 Merge pull request #23243 from rintaro/ide-completion-rdar48698892
[CodeCompletion] Move a test to long test suite
2019-03-12 16:55:25 -07:00
Rintaro Ishizaki
51234d498a [CodeCompletion] Move a test to long test suite
rdar://problem/48698892
2019-03-12 12:26:35 -07:00
Rintaro Ishizaki
19e54fed78 [CodeCompletion] Fixed a crasher regarding malformed operator decl
Infix operator completion used to crash if multiple infix operators with the
same name are declared in the module.

rdar://problem/48648877
2019-03-08 16:31:31 -08:00
Rintaro Ishizaki
5df5711b67 [CodeCompletion] Rework getOperatorCompletions() (#20632)
In postfix completion, for operator completion, we do:

  1. Type check the operand without applying it, but set the resolved
     type to the root of the expression.
  2. For each possible operators:
      i. Build temporary binary/postfix expression
      ii. Perform type checking to see whether the operator is applicable 

This could be very slow especially if the operand is complex.

* Introduce `ReusePrecheckedType` option to constraint system. With
  this option, CSGen respects pre-stored types in expressions and doesn't
  take its sub-expressions into account.
  * Improve type checking performance because type variables aren't
     generated for sub-expressions of LHS (45511835)
  * Guarantee that the operand is not modified by the type checker because
     expression walkers in `CSGen` doesn't walk into the operand.

* Introduce `TypeChecker::findLHS()` to find LHS for a infix operator from
  pre-folded expression. We used to `foldSequence()` temporary
  `SequenceExpr` and find 'CodeCompletionExpr' for each attempt.
  * No need to flatten folded expression after initial type-checking.
  * Save memory of temporary `BinaryExpr` which used to be allocated by
    `foldSequence()`.
  * Improve accuracy of the completion. `foldSequence()` recovers invalid
    combination of operators by `left` associative manner (with
    diagnostics). This used to cause false-positive results. For instance,
    `a == b <HERE>` used to suggest `==` operator. `findLHS()` returns
    `nullptr` for such invalid combination.

rdar://problem/45511835
https://bugs.swift.org/browse/SR-9061
2018-11-22 21:20:51 +09:00
Pavel Yaskevich
0a3f666367 [IDE] NFC: Add a test-case for a fixed SourceKit crasher
Resolves: rdar://problem/41331096
2018-11-06 11:58:38 -08:00
Rintaro Ishizaki
07172f47c3 [CodeCompletion] Don't try to resolve generic env for extension in inactive block
Fixes code-completion crash in validateExtension().

When code completion happens, it tries to validate decl contexts. If
it's in an extension in inactivec conditional block, the extension
haven't been bound to nominal type. That used to cause crash because its
GenericParams hasn't been set.

rdar://problem/45275782
https://bugs.swift.org/browse/SR-9001
2018-10-26 10:08:51 +09:00
Rintaro Ishizaki
c6017095c3 [AST] Use invalid conformance for unsatisfied requirement
There is an invariant that SignatureConformances should have the same
size as the number of conformance requirements in the signature.
Previously, since unsatisfied requirements weren't reflected in it,
that caused a crash.

rdar://problem/43625800
2018-10-10 21:03:25 +09:00
Rintaro Ishizaki
592b5de206 [CodeCompletion] Remove a wrong assert()
`CS.solve()` with `FreeTypeVariableBinding::Disallow` still may emit
unresolved type. e.g. `DeclRefExpr` to decl with unresolved type.

https://bugs.swift.org/browse/SR-8568
rdar://problem/43433253
2018-08-20 19:50:09 +09:00
Rintaro Ishizaki
682fc12c39 [Parse] Don't use getAsNominalTypeOrNominalTypeExtensionContext in Parse
`getAsNominalTypeOrNominalTypeExtensionContext()` requires fully parsed
AST. Use `isTypeContext()` instead.

https://bugs.swift.org/browse/SR-8554
rdar://problem/43394866
2018-08-18 12:48:13 +09:00
Rintaro Ishizaki
c68157a27d [CodeCompletion] Remove unresolved type in prepareForRetypechecking()
Unresolved type attached to expressions may fail re-typechecking.
Also, disallow unresolved type in typeCheckCompletionSequence(). It doesn't
provide useful completions to developers.

rdar://problem/41224316
2018-08-15 20:39:12 +09:00
Rintaro Ishizaki
7532da4e37 [ConstraintSystem] Remove any semantic expression in SanitizeExpr
Existence of semantic expr (`getSemanticExpr()`) prevents ASTWalker
walking into the *original* sub expressions which may cause
re-typechecking failure. For example,
`ConstraintGenerator::visitArrayExpr()` assumes we already visited its
elements, but that's not the case if the semantic expr exists.

rdar://problem/42639255
2018-08-13 20:36:07 +09:00
Rintaro Ishizaki
5e001f1913 Merge pull request #18626 from rintaro/ide-completion-unresolved-refactor
[CodeCompletion] Completion for UnresolvedMember via CodeCompletionExpr
2018-08-11 09:10:28 +09:00
Rintaro Ishizaki
b5a537ea26 [CodeCompletion] Add fixed test case fixed in previous commit
rdar://problem/42828673
2018-08-10 22:23:23 +09:00
Rintaro Ishizaki
33e7d06cbf [CodeCompletion] Add previously crashing test case. 2018-08-10 20:30:19 +09:00
Pavel Yaskevich
dc6f86d9b7 [CSRanking] Fix solution filtering not to erase everything when set is completely ambiguous
Since constraint solver has been improved to diagnose more problems
via "fixes", sometimes applying fixes might lead to producing solutions
which are completely ambiguous when compared to each other, and/or are
incomparable, which leads to `findBestSolutions` erasing all of them
while trying to compute best "partial" solution, which is incorrect.

Resolves: rdar://problem/42678836
2018-08-06 17:25:58 -07:00
Rintaro Ishizaki
c5a84565d7 [Parse] Fix end location of dummy top level code for code completion
Fix ASTVerifier error for end location of 'IfConfigDecl'.
Previously, for:
```
  #if
  // something
  <COMPLETE>
```
End location of the dummy body of 'TopLevelCodeDecl' was at the eof, but the
end loc of the 'IfConfigDecl' was at the code-completion token. That
caused the ASTVerifier error "invalid IfConfigStmt end location".

https://bugs.swift.org/browse/SR-2364
rdar://problem/41217187
2018-07-30 20:23:26 +09:00
Rintaro Ishizaki
21db9723e4 [Lexer] Don't include backtick length into comment length
Although backtick is a kind of trivia piece, Token::getCommentRange doesn't
take it into account. Invalid Token::getCommentRange used to cause
compiler crash.

rdar://problem/42492793
https://bugs.swift.org/browse/SR-8315
2018-07-24 04:37:07 +09:00
Rintaro Ishizaki
4a01a28282 [Lexer] Add crashing test case for SR-8315 2018-07-23 17:52:43 +09:00
Pavel Yaskevich
939f6d402c [TypeChecker] NFC: Add test-case for rdar://problem/42056741 2018-07-13 23:47:09 -07:00
Pavel Yaskevich
d3249695a9 [Diagnostics] Transfer previously resolved types directly from expressions
While trying to diagnose the problem with previously type-checked
sub-expression, use its type-checked variant as a source of type
information, instead of transferring from its original constraint system,
because if expression was type-checked successfully it would
have all of the required information in AST, and that doesn't
rely on associated constraint system being present.

Resolves: rdar://problem/42056741
2018-07-13 16:38:48 -07:00
Slava Pestov
1d2d653844 IDE: Redo typeCheckContext()
- Don't type check top-level contexts multiple times
- Use validateDecl() instead of typeCheckDecl() when possible
2018-06-30 00:20:37 -07:00
Pavel Yaskevich
f49aad16b7 [Parser] Set decl context to be typealias when completing its underlying type
Parser didn't capture correct context when code completion
was attempted on typealias' right-hand side which, if there are
generic parameters present, would result in a crash. These
changes make it so completion gets a correct declaration
context in aforementioned case and typealias declaration is marked
invalid because it doesn't have a proper type.

Resolves: rdar://problem/39909829
2018-05-04 17:39:55 -07:00
Slava Pestov
0cbbd9ae5d Sema: Don't set 'validation started' bit on ParamDecls from validateDecl()
Otherwise, when the horrible ExprCleanser comes along, it will set
the interface type of the ParamDecl to nullptr. However there is
no way to clear the 'validation started' bit, so the next time
validateDecl() is called on this ParamDecl we will just return,
causing crashes downstream when callers expect it to already have
an interface type set.

Fixes <rdar://problem/38189778> and possibly some instances of
<rdar://problem/36434823>.
2018-04-25 18:04:58 -07:00
Nathan Hawes
d6894b82b3 Merge pull request #15247 from nathawes/rdar38144409-code-completion-assertion-hit-in-getTypeOfReference
[code-completion] Fix assertion hit in getTypeOfReference via code completion
2018-03-23 12:08:41 -07:00
Nathan Hawes
a0cf755528 Update fixed IDE validation-test crasher and move into IDE/crashers_2_fixed 2018-03-22 13:18:36 -07:00
David Zarzycki
c00c18fc68 [Tests] Consolidate stress/long tests in validation-tests 2018-03-20 22:19:37 -04:00
Rintaro Ishizaki
24c7ea15e7 [Parse] Disable token receiver while parsing types in editor placeholder
Otherwise, for `<#T##Type#>`, `TokReceiver` records
 `{'<#T##Type#>', 'Type'}`.
2017-12-16 10:48:12 +09:00
Slava Pestov
3b54234c6e Add two new crasher test cases found with the code completion fuzzer 2017-09-20 23:41:57 -07:00
Slava Pestov
ddd0666e94 IDE: Fix mismatched ErrorType check
In one place we were calling hasError() and in another directly checking
for ErrorType; if we had a type containing an ErrorType as a structural
component, we would hit an assertion.
2017-09-19 23:08:37 -07:00
Slava Pestov
7ba0f1ac82 IDE: Fix crash when completing unbound generic type in type context 2017-09-19 23:08:37 -07:00
Slava Pestov
ab8677faab IDE: Always use the right DeclContext
We have a hack where we use the ParsedDecl as the DeclContext,
to handle completion during function signature parsing, which
happens before the FuncDecl has been created.

While fixing this properly would require a bigger change to the
parser and AST, for now we just check if the ParsedDecl is a
child context of CurDeclContext, and only use it then.
2017-09-19 23:08:37 -07:00
Ben Langmuir
534c0cc2cb [code-completion] Generic where clauses
Complete generic parameters and their members inside generic where
clauses on structs, classes, enums, extensions, typealiases, funcs,
subscripts and inits.

Still not handled correctly are associatedtypes.

rdar://problem/20582394
2017-07-31 09:57:00 -07:00
Doug Gregor
9f0f71dea1 Resolved another crasher 2017-06-19 23:38:55 -07:00
Slava Pestov
773d7b3225 Sema: Remove more methods from GenericTypeResolver
resolveGenericTypeParamType(), resolveTypeOfDecl() and
resolveTypeOfContext() would all take the type of a
declaration, and optionally map it into context.

Replace them with a mapTypeIntoContext() that takes a
type and either returns it verbatim or maps it into
context.
2017-06-15 21:31:35 -07:00
Pavel Yaskevich
f09d2ad397 [ConstraintSolver] Forbid forming solutions with free generic type parameters
`FreeTypeVariableBinding::GenericParameters` mode allowed to bind
all free type variables with fresh generic parameter types, which
is incorrect (at least) if there are multiple generic solutions
present, because such parameters couldn't be compared.

This mode was used for code completion, which is now switched to use
`FreeTypeVariableBinding::UnresolvedType` instead.
2017-06-01 14:05:05 -07:00
Slava Pestov
e58ae766a3 Fix and un-XFAIL regressed crashers from recent stdlib change 2017-05-17 05:51:51 -07:00
practicalswift
4f05554682 [gardening] Remove assert requirement from fixed crashers 2017-05-13 10:57:05 +02:00
Huon Wilson
8c8f35ee78 [Parse] Don't tell CodeCompletion nonsense about protocol/AT where clauses.
This doesn't give particularly useful information yet (i.e. Self isn't
listed, see rdar://problem/31981641 ), but it does stop the completion
code from just directly crashing.

Fixes rdar://problem/31981486.
2017-05-12 16:00:00 +10:00
Pavel Yaskevich
ddaccf88bb [QoI] Properly diagnose closure parameter distructuring after SE-0110
Swift 3 supported limited argument destructuring when it comes to
declaring (trailing) closures. Such behavior has been changed by
SE-0110. This patch aims to provide better error message as well
as fix-it (if structure of the expected and actual arguments matches)
to make the migration easier and disambiguate some of the common
mistakes.

Resolves: SR-4738, SR-4745, rdar://problem/31892961.
2017-05-08 23:04:37 -07:00
Slava Pestov
2fe863266c AST: Fix crashes when name lookup finds declarations outside of a protocol or extension that's nested in another type
When performing a name lookup from inside of a protocol
or extension, skip directly to the source file context
when we are done visiting the protocol or extension.

Otherwise, if we have invalid code where the protocol
or extension is nested inside another type, we might
find a member whose type contains generic parameters
of the outer type; these parameters will not resolve,
since we do not model protocols or extensions nested
inside generic contexts (yet?).

This supercedes an earlier workaround for a similar
issue; the new workaround fixes more crashes.

This is needed to avoid crasher regressions with an
upcoming patch.
2017-05-07 03:01:47 -07:00
Maxim Moiseev
1c1b2b966d [stdlib] String : RangeReplaceableCollection & BidirectionalCollection (#8921)
* [stdlib] String : RangeReplaceableCollection & BidirectionalCollection

* Add source compatibility hack for Swift.max

* Add source compatibility hack for Swift.min

* Remove redundant conformance in benchmarks

* Fix stupid typo I thought I'd already pushed

* XFAIL testing now-redundant conformance

* XFAIL an IDE test for now
2017-04-23 20:04:54 -07:00
Slava Pestov
4817bd4214 Add some SourceKit crasher test cases
The unfixed ones were discovered by fuzzing. I have fixes for most
of them in an in-progress PR.

One that was already fixed is just a regression test I'm adding.
2017-04-11 14:26:10 -07:00
Slava Pestov
730cd388b4 Re-add a 'REQUIRES: asserts' that was spuriously deleted to fix no-asserts build 2016-12-12 17:42:36 -08:00
Slava Pestov
e063e8297c Sema: Some fixes for the ITC
- In functions called from resolveType(), consistently
  use a Type() return value to indicate 'unsatisfied
  dependency', and ErrorType to indicate failure.

- Plumb the unsatisfiedDependency callback through the
  resolution of the arguments of BoundGenericTypes, and
  also pass down the options.

- Before doing a conformance check on the argument of a
  BoundGenericType, kick off a TypeCheckSuperclass request
  if the type in question is a class. This ensures we don't
  recurse through NominalTypeDecl::prepareConformanceTable(),
  which wants to see a class with a valid superclass.

- The ResolveTypeOfDecl request was assuming that
  the request was satisfied after calling validateDecl().
  This is not the case when the ITC is invoked from a
  recursive call to validateDecl(), hack this up by returning
  *true* from isResolveTypeDeclSatisfied(); otherwise we
  assert in satisfy(), and we can't make forward progress
  in this case anyway.

- Fix a bug in cycle breaking; it seems if we don't invoke
  the cycle break callback on all pending requests, we end
  up looping forever in an outer call to satisfy().

- Remove unused TR_GlobalTypeAlias option.
2016-12-09 17:36:49 -08:00
Xi Ge
6bbdf4a837 [Mangler] Check the order of generic type parameters before mangling them to avoid assertion hit. 2016-12-09 09:51:40 -08:00
Jordan Rose
49e6c06eef [validation-test] Remove "REQUIRES: asserts" from /fixed/ crash cases. (#6156) 2016-12-08 19:06:32 -08:00
swift-ci
bff17cb5ee Merge pull request #6119 from bitjammer/sr-3354-crash-case 2016-12-06 19:20:25 -08:00
David Farler
ff830ce4aa Add separate compiler crasher case for SR-3354
This isn't specifically related to code completion, but an
infinite recursion in the type checker.

https://bugs.swift.org/browse/SR-3354
2016-12-06 19:03:06 -08:00
Xi Ge
54e8527d5c [code-completion] Ensure consumeDecl() does not alter the state of parser. (#6110)
This also fixes IDE/crashers/029-swift-decl-walk.swift.
2016-12-06 16:01:29 -08:00
Ben Langmuir
ef7f8f7c9a Merge pull request #6102 from benlangmuir/fix-032
[code-completion] Allow ErrorType in solution to avoid assertion failure
2016-12-06 12:26:33 -08:00