Commit Graph

63 Commits

Author SHA1 Message Date
Rintaro Ishizaki
cbeffb69cd [CodeCompletion] Don't ignore CovariantReturnConversionExpr
in typechecked AST. This is needed to correctly get the type of the
parsed expression when the expression is a calling to a method in super
class returning 'Self'.

rdar://problem/51504896
2020-03-19 11:05:04 -07:00
Rintaro Ishizaki
f8147f72d9 [CodeCompletion] Call argument label with value placeholder
When a completion happens at a call argument position, insert
'label: <#T##TypeName#>' instead of just 'label: '.

rdar://problem/60379654
2020-03-12 11:48:15 -07:00
Rintaro Ishizaki
fbc79d2f47 [CodeCompletion] Support SE-0253 callAsFunction()
- In member completions, when 'callAsFunction' decls are found, suggest
  call patterns
- In call pattern completions, fallback to search 'callAsFunction' if
  the base type is not a function type

rdar://problem/59792682
2020-03-11 16:27:27 -07:00
Rintaro Ishizaki
8f7340cd6e [CodeCompletion] Re-typecheck TypeExpr without call arguments
Call arguments sometimes affect the inference for the generic parameters of the
type expression. When we want to show all initializers from all
extensions, we do not want to infer any generic arguments.

rdar://problem/53516588
2020-03-09 15:48:54 -07:00
Rintaro Ishizaki
78d0f6aa4a [CodeCompletion] Primarily use getPossibleCallees() for call signature completion
instead of the pre-typechecked type and the referenced decl in the AST
so that we can suggests all overloads even if it happen to be
typechecked to a method. For example

    struct MyType {
      func foo() {}
      func foo(_ int: Int) {}
      func foo(name: String, value: String) {}
    }
    func test(val: MyType) {
      value.foo(#^COMPLETE^#)
    }

In this case, the call is typechecked to 'MyType.foo(_:)', but we want
to suggest all overloads.

rdar://problem/59285399
2020-02-28 16:44:03 -08:00
Rintaro Ishizaki
9cb2c057bb [CodeCompletion] Fix a crash in context type analysis
'IfExpr' (ternary expression) does not have condition part before
sequence folding. Add a guard to avoid a crash.

rdar://problem/59344203
2020-02-13 11:38:09 -08:00
Rintaro Ishizaki
afd3be9559 [CodeCompletion] Improve context type analysis for ternary expressions
This improves code-completion for non-type-checked ternary expressions.
2020-01-21 15:30:08 -08:00
Rintaro Ishizaki
95f12afb7c [CodeCompletion] Improve context type analysis for dictionary literal
- Analyze the type of the literal in the context
- If ':' is missing in the literal, treat the expression as a key
  expression
- If the parent expression is TupleExpr, analyze the context type of the
  tuple first, then return the element type of the position

rdar://problem/57096392
2020-01-16 15:52:48 -08:00
Rintaro Ishizaki
7bb01ed271 Merge pull request #28896 from rintaro/ide-completion-rdar58098222
[CodeCompletion] Always look into decls to find the parsed expression
2020-01-13 16:48:34 -08:00
Robert Widmann
96b3b9f0f4 [NFC] Hide SourceFile::Decls
In preparation for installing some stable paths infrastructure here,
hide access to the array of top-level decls.
2020-01-03 14:14:00 -08:00
Rintaro Ishizaki
a7064617b2 [CodeCompletion] Always look into decls to find the parsed expression
In fast completion scenario, 'AbstractFunctionDecl' may have the body
from the different file than the decl itself. Thay may confuses source
range checking.

As a workaround, always look into decls regardless of the range. This
should not regress the speed of the searching much because
statements/expressions (including nested function bodies) in the decl
is still skipped if it's outside the range.

rdar://problem/58098222
2019-12-19 21:50:08 -08:00
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Rintaro Ishizaki
8fae0893e1 [CodeCompletion] Don't use temporary Lexer in the second pass
Since we only call one parsing function (i.e. parseAbstructFunctionBody,
parseDecl, or parseStmtOrExpr), the parser stops at the end of the node.
It's not necessary to limit the Lexer to set an ArtificialEOF.

To minimize the parsing range, modify the Parser to *not* parse the body
if the completion happens in the signature.
2019-11-22 17:18:32 +09:00
Hamish Knight
ed77b86c24 getInterfaceType() always returns a type 2019-11-12 07:50:29 -08:00
Rintaro Ishizaki
d51d8447f0 Do 'bindExtensions()' as a part of 'performParseAndNameBindingOnly()' 2019-11-12 13:30:55 +09:00
Rintaro Ishizaki
2564a6e494 [CodeCompletion] Avoid typechecking all toplevel decls in the current file
- Use `performParseAndResolveImportsOnly()` to invoke the frontend
- Do `bindExtensions()` in `ide::typeCheckContextUntil()`
- Typecheck preceding `TopLevelCodeDecl`s only if the compleiton is in
  a `TopLevelCodeDecl`
- Other related tweaks

rdar://problem/56636747
2019-11-12 12:57:18 +09:00
Robert Widmann
6c6035eca2 Drop TypeCheckers out of TypeCheckStmt 2019-11-05 22:52:28 -08:00
Robert Widmann
8a69f886ad Merge pull request #27955 from AnthonyLatsis/bracestmt_cleanup
NFC: Solidify and tidy up the BraceStmt interface
2019-10-31 13:48:40 -07:00
Robert Widmann
0267384e11 Fixup SourceKit and Tests
Patch up all the places that are making a syntactic judgement about the
isInvalid() bit in a ValueDecl.  They may continue to use that query,
but most guard themselves on whether the interface type has been set.
2019-10-30 15:09:14 -07:00
Anthony Latsis
6325915b4b NFC: Solidify and tidy up the BraceStmt interface 2019-10-30 16:43:59 +03:00
Robert Widmann
3b829943af Uniformly iterate over the pattern binding entry indices
Clarify a bunch of C-style for loops and remove a ton of references to getPatternList().
2019-10-17 13:39:07 -07:00
Slava Pestov
a260d0a445 AST: getInterfaceType() returns ErrorType instead of Type() on circularity 2019-10-08 01:37:09 -04:00
Slava Pestov
7063ecd338 IDE: Eliminate typeCheckCompletionDecl() 2019-10-05 00:39:32 -04:00
Robert Widmann
792e1db448 Port getInterfaceType() patterns in ancillary libraries 2019-09-23 16:49:51 -07:00
Nathan Hawes
feb48a61b9 [code-completion] Fix correctness regressions from disabling diagnostics in code completion
There were some changes to completion results because AST mutations that were
made while diagnosing are no longer happening.

This patch 1) changes expression type checking to allow unresolved types when
solving constraint systems, so we get a solution and apply its types in more
cases, and 2) fixes a parsing issue where we would drop a ternary expression
completely if the code completion point was in its true branch.
2019-08-30 15:26:27 -07:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Slava Pestov
80ccbe5116 AST: Stop passing around a LazyResolver in name lookup
Note that in all cases it was either nullptr or ctx.getLazyResolver().
While passing in nullptr might appear at first glance to mean something
("don't type check anything"), in practice we would check for a nullptr
value and pull out ctx.getLazyResolver() instead. Furthermore, with
the lazy resolver going away (at least for resolveDeclSignature() calls),
it won't make sense to do that anymore anyway.
2019-08-19 23:00:57 -04:00
Slava Pestov
1c3ac86796 AST: Banish OptionalTypeKind to ClangImporter.h
The only place this was used in Decl.h was the failability kind of a
constructor.

I decided to replace this with a boolean isFailable() bit. Now that
we have isImplicitlyUnwrappedOptional(), it seems to make more sense
to not have ConstructorDecl represent redundant information which
might not be internally consistent.

Most callers of getFailability() actually only care if the result is
failable or not; the few callers that care about it being IUO can
check isImplicitlyUnwrappedOptional() as well.
2019-08-15 18:41:42 -04:00
Rintaro Ishizaki
4353a55587 [CodeCompletion] Fix a crash in collectPossibleCalleesByQualifiedLookup
We cannot assume that 'FuncDecls' have 'AnyFunctionType' interface type
or null type. They can be 'ErrorType's.

rdar://problem/54215016
2019-08-12 12:27:30 -07:00
Rintaro Ishizaki
ee2f39cc21 [CodeCompletion] Expr context type analysis for failed array literal expr
let _: [Foo] = [
  .create(str: Int)
  .create(#^COMPLETE^#)
]

Previously, this completion used to fail because the array expression
isn't typechecked. We need to analyze the context type of the array
literal first, that defines the type of the unresolved member
expression.

rdar://problem/50696432
2019-07-18 21:36:47 -07:00
Rintaro Ishizaki
3601cc05fb Merge pull request #25876 from rintaro/ide-completion-checkhasinterfacety-rdar51599533
[CodeCompletion] Add defensive nullptr check
2019-07-16 00:57:08 +02:00
Rintaro Ishizaki
dfc4d77c32 [CodeCompletion] Fix a crash in callee analysis
struct Wrap<T> {
  func method<U>(_ fn: (T) -> U) -> Wrap<U> {}
}
func testGenricMethodOnGenericOfArchetype<Val>(value: Wrap<Val>) {
  value.method(#^HERE^#)
}

In this case, the type of value is `Wrap<Val[archetype]>`.
`Type::getTypeOfMember()` for 'method' method returns
`( (Val[archetype]) -> U[generic param]) -> Wrap<U[generic param]>`
which crashs 'mapTypeIntoContext()' because it already hass archetype.

rdar://problem/52386176
2019-07-01 10:11:07 -07:00
Rintaro Ishizaki
8c8b89c499 [CodeCompletion] Add defensive nullptr check
Prevent crash.
rdar://problem/51599533
2019-06-28 17:45:35 -07:00
Rintaro Ishizaki
4d076e85c7 [CodeCompletion] Enable 'openArchetypes' when checking if convertible
```swift
protocol Proto {}
struct ConcreteProto {}
struct MyStruct<T> {}

extension MyStruct where T: Proto {
  static var option: MyStruct<ConcreteProto> { get }
}
func foo<T: Proto>(arg: MyStruct<T>) {}
func test() {
  foo(arg: .#^HERE^#)
}
```
In this case, the type of `MyStruct.option` is `MyStruct<ConcreteProto>`
whereas the context type is `MyStruct<T> where T: Proto`.
When checking the convertibility of them , we need to "open archetype types".

rdar://problem/24570603
rdar://problem/51723460
2019-06-28 15:25:52 -07:00
Rintaro Ishizaki
f94a6c0d9b [CodeCompletion] Context type analysis for default argument initializer
rdar://problem/51037538
2019-06-17 15:04:30 -07:00
Rintaro Ishizaki
9ba232d718 [CodeCompletion] Implement completion at custom attribute argument 2019-05-31 11:09:54 -07:00
Rintaro Ishizaki
1b688d5e21 [CodeCompletion] Implement call signature completion for subscript
rdar://problem/28874899
2019-05-17 14:20:28 -07:00
Rintaro Ishizaki
557505d599 [CodeCompletion] Look through ApplyExpr to get referenced decl
For example:
  let x: MyClass = .create(<#COMPLETE#>)

This expression ends up with:
  (call_expr
    (dot_syntax_self_apply_expr
      (decl_ref_expr decl='C.create(_:arg1)'
      (type_expr type=MyClass))))
So we need to look through 'DotSyntaxSelfApplyExpr' to get the decl.
2019-05-15 17:31:19 -07:00
Rintaro Ishizaki
14d2f7c0a7 [CodeCompletion] Enable context type analysis for implict member expression
At argument part of implict member expression, we need context type
analysis to complete arguments.

rdar://problem/50696432
2019-05-15 12:34:26 -07:00
Ben Langmuir
81ce653bc3 Merge pull request #23587 from benlangmuir/cc-omit-return
[code-completion] Add type context for single-expression function bodies
2019-04-25 13:49:45 -07:00
Rintaro Ishizaki
6e0b8c2b67 [CodeCompletion] Completion support for static subscript
rdar://problem/49131687
2019-04-19 21:36:17 -07:00
Rintaro Ishizaki
93632f0bbe Merge pull request #23716 from rintaro/ide-completion-calleedecl-rdar49158044
[CodeCompletion] Associate callee declaration with call patterns
2019-04-05 17:50:37 -07:00
Slava Pestov
3095c36585 IDE: Remove prepareForRetypechecking() 2019-04-02 01:51:57 -04:00
Rintaro Ishizaki
0c38f2df8a [CodeCompletion] Associate callee declaration with call patterns
In `addFunctionCallPattern()` we should associate declarations if
possible.

rdar://problem/49158044
2019-04-01 11:21:43 -07:00
Slava Pestov
478c1335a0 IDE: Mark some functions as 'static' 2019-03-31 01:36:19 -04:00
Slava Pestov
1467f554f5 AST: Remove ArgumentShuffleExpr 2019-03-31 01:36:19 -04:00
Parker Schuh
d0779bd771 Convert ArrayExpr to not use callWitness() or generate a SemanticExpr. 2019-03-27 23:21:08 -04:00
Ben Langmuir
b14cd916a3 [code-completion] Add type context for single-expression functions
Extend the support for single-expression closures to handle
single-expression functions of all kinds. This allows, e.g.

    func foo() -> MyEnum { .<here> }

to complete members of `MyEnum`.
2019-03-26 16:45:27 -07:00
Rintaro Ishizaki
bfaa6af57e [CodeCompletion] Look through implicit exprs to find the parsed expr
The parsed expression may be wrapped with various implicit expressions.
For example, if the expression is only element in array literal, it's
wrapped with `(arrayLiteral: <expr>)`.
2019-03-22 15:01:18 -07:00