Commit Graph

75 Commits

Author SHA1 Message Date
Rintaro Ishizaki
2eb623ec4c [CodeCompletion] Handle variadic parameter in expr context analysis
for call arguments. Consider variadic arguments 'skippable'. Also, don't
treat 'VarargExpansionExpr' as a "context providing" expression.

rdar://problem/62479469
2020-05-20 22:51:49 -07:00
Rintaro Ishizaki
3337d7b25b [CodeCompletion] Avoid re-typechcking pre-checked expressions
in expression context analysis. They are simply not necessary.

rdar://problem/60982638
2020-05-13 16:59:06 -07:00
Rintaro Ishizaki
c0bf473cb6 [CodeCompletion] Fix a crash regression 2020-05-06 01:56:41 -04:00
Rintaro Ishizaki
7407a8092d [CodeCompletion] Postfix expr completion after trailing closures 2020-05-06 01:56:41 -04:00
Rintaro Ishizaki
1cbb1e76d4 [CodeCompletion] Update for braceless multiple trailing closure 2020-05-06 01:56:41 -04:00
Rintaro Ishizaki
fd68f092f2 [CodeCompletion] Completion inside multiple trailing closure
rdar://problem/59688477
2020-05-06 01:56:40 -04:00
Robert Widmann
1319b53528 Hide the TypeExpr in ClosureExpr 2020-04-29 13:40:39 -07:00
Robert Widmann
5b3060318e [NFC] Strip ClosureExpr of its TypeLoc 2020-04-28 20:10:10 -07:00
Robert Widmann
a6fc9b3679 Merge pull request #31253 from CodaFi/casting-call
Strip TypeExpr of its TypeLoc
2020-04-28 09:45:53 -07:00
Robert Widmann
09db2902d2 Strip TypeExpr of its TypeLoc
Remove duplication in the modeling of TypeExpr. The type of a TypeExpr
node is always a metatype corresponding to the contextual
type of the type it's referencing. For some reason, the instance type
was also stored in this TypeLoc at random points in semantic analysis.

Under the assumption that this instance type is always going to be the
instance type of the contextual type of the expression, introduce
a number of simplifications:

1) Explicit TypeExpr nodes must be created with a TypeRepr node
2) Implicit TypeExpr nodes must be created with a contextual type
3) The typing rules for implicit TypeExpr simply opens this type
2020-04-23 17:04:38 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Rintaro Ishizaki
47e303a98d [CodeCompletion] Fix a crash in context type analysis for tuple expr
When completing inside tuple expressions, the context tuple type may
have fewer number of elements. In such cases, we cannot provide the
expected type.

rdar://problem/61668779
2020-04-16 09:24:00 -07:00
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