Commit Graph

155 Commits

Author SHA1 Message Date
maustinstar
037edf3a8c [SR-11711] Refactor shared parser code for single-expression returns 2020-11-03 22:03:11 -05:00
maustinstar
37b17338e5 [SR-11711] Single-expression returns for #if declarations within functions 2020-11-03 12:47:39 -05:00
Slava Pestov
dbdbbff743 SILParser: Overhaul to not rely on parse-time lookup 2020-09-11 20:05:47 -04:00
Nathan Hawes
198687018c [IDE] Fix typo to address unused warning (NFC) 2020-08-29 08:06:09 -07:00
Nathan Hawes
3e8278ae71 Merge pull request #33676 from nathawes/parser-completion-fixes
[Parse][IDE] Various parser fixes for code completion
2020-08-28 22:11:31 -07:00
Nathan Hawes
3e0500d73c [Parse][IDE] Don't drop default argument init exprs containing code completion exprs and type check them for code completion.
Fixes up some tests marked as non-ideal to give the ideal result now too.
2020-08-28 17:09:37 -07:00
Rintaro Ishizaki
c48a676a1c Merge pull request #31679 from Jumhyn/implicit-member-chains-different-types
[SE-0287] [Sema] Implementation for implicit member chains
2020-08-28 10:47:53 -07:00
Rintaro Ishizaki
e013ebd388 [CodeCompletion] Ensure all ExtensionDecl's extended nominal are computed
Fixes an assertion failure in ASTScope lookup

rdar://problem/67102794
2020-08-27 16:17:43 -07:00
Frederick Kellison-Linn
352adc3b5d Remove Argument from UnresolvedMemberExpr
Instead, an expresison like `.foo()` is represented as an `UnresolvedMemberExpr` nested inside a `CallExpr`.
2020-08-26 22:42:30 -04:00
Suyash Srijan
a577a87f99 [ExprContextAnalysis] Look into base type of optional as well when collecting callees for unresolved member (#33292) 2020-08-05 12:54:05 +01:00
Rintaro Ishizaki
69d8398b04 Merge pull request #33270 from rintaro/ide-completion-typecheckcontextat
[CodeCompletion] Cleanup typeCheckContextAt()
2020-08-04 15:53:18 -07:00
Anthony Latsis
78f0259bfb Merge pull request #33283 from AnthonyLatsis/type-locura-2
ASTWalker: Offload TypeLoc
2020-08-05 00:17:33 +03:00
Robert Widmann
b50a2cf430 Merge pull request #33251 from AnthonyLatsis/type-locura-1
Rid performTypeLocChecking of TypeLoc
2020-08-04 12:04:10 -07:00
Anthony Latsis
7bcc4baa33 [NFC] TypeLoc: Rid performTypeLocChecking off TypeLoc 2020-08-04 19:15:55 +03:00
Anthony Latsis
b26310ee97 TypeLoc: Offload TypeLoc off the ASTWalker 2020-08-04 18:13:28 +03:00
Rintaro Ishizaki
ec8637c197 [CodeCompletion] Cleanup typeCheckContextAt()
There's no need of separate 'Impl' function
2020-08-03 15:31:12 -07:00
Rintaro Ishizaki
3e558f064f [CodeCompletion] Handle @autoclosure in context type analysis
If the context is '@autoclosure' parameter, the context type should be
the result type of it.

rdar://problem/65802490
2020-07-30 14:58:26 -07:00
Rintaro Ishizaki
12762a2a30 [CodeCompletion] Only type check related statements in function body
Introduce 'TypeCheckSingleASTNode' mode that only type checks single body
element and dependent necessities (i.e. referencing ValueDecls and their
dependencies).

Renamed swift::typeCheckAbstractFunctionBodyAtLoc() to
swift::typeCheckASTNodeAtLoc(DeclContext *, SourceLoc). That type checks
innermost 'ASTNode' at the location. Also, 'TypeCheckSingleASTNode' mode
skips type checking any "body" of the node (i.e. BraceStmt elements for
function body, if statement body, closure body, etc.)

Added on-demand type checking using it:
 - VarDecl in TapExpr
 - ParamDecl in ClosureExpr
 - Return type of ClosureExpr
 - Binding value in control statements
   (e.g. ForEachStmt, SwitchStmt, DoCatchStmt, etc.)

rdar://problem/63932852
2020-07-24 10:48:51 -07:00
Rintaro Ishizaki
dab216dc49 [CodeCompletion] Use TypeContextInfo to get expected return types
If the type check return type from the context has unresolved types, it
can't be used for checking convertibility. Fallback to get
'TypeContextInfo' of the closure position.

rdar://problem/66002497
2020-07-23 14:34:54 -07:00
Suyash Srijan
58a84ea4c1 [NFC] Cleanup some code to use 'swift::getParameterList(ValueDecl)' to fetch parameter lists (#32979) 2020-07-20 19:50:37 +01:00
Rintaro Ishizaki
f7fc1ed7b5 [CodeCompletion] Fix a crash in CCExprRemover
- Handle cases where getArgumentLabelLocs().size() == 0
- Add some assertions to verify invariants
- Explicit handling of 'llvm::Optional' for 'getUnlabeledTrailingClosureIndex()'
- Avoid walking into nodes after the removing happens

rdar://problem/65556791
2020-07-15 09:56:20 -07:00
Rintaro Ishizaki
a778f517d1 [CodeCompletion] Remove redundant entries from possible callee analysis
This used to cause duplicated results in call signature completions.
i.e.:

  AlertViewController(#^HERE^# // 2 x (coder: NSCoder)

rdar://problem/65081358
2020-07-08 14:30:32 -07:00
Rintaro Ishizaki
5db0f1a40b [CodeCompletion] Typecheck without CodeCompletionExpr
when falling back to "postfix expression completion" after labeled
trailing closure completion.

rdar://problem/64176730
2020-06-15 21:40:40 -07:00
Rintaro Ishizaki
38d8b13520 [CodeCompletion] Add keypath apply subscript after open bracket
rdar://problem/61016147
2020-06-09 11:04:02 -07:00
Rintaro Ishizaki
65b8cf76f3 Merge pull request #32086 from rintaro/ide-completion-skipbody-rdar58687608
[CodeCompletion] Skip type checking unrelated statements in function body
2020-06-02 17:10:07 -07:00
Rintaro Ishizaki
e6ce361042 [CodeCompletion] Rename typeCheckContextUntil to typeCheckContextAt 2020-06-01 12:36:39 -07:00
Rintaro Ishizaki
ebc99c60fb [CodeCompletion] Separate TypeCheckFunctionBodyAtLocRequest
from TypeCheckFunctionBodyRequest, and only do necessary operations.
2020-06-01 12:36:39 -07:00
Varun Gandhi
c14e934563 [NFC] Remove redundant includes for llvm/ADT/SmallSet.h. 2020-05-31 13:07:45 -07:00
Rintaro Ishizaki
6c61e605f2 [CodeCompletion] Skip typechecking preceding top level decls 2020-05-29 14:45:04 -07:00
Rintaro Ishizaki
0a72d023f3 [TypeChecker] Rename 'typeCheckAbstractFunctionBodyUntil()'
to 'typeCheckAbstractFunctionBodyNodeAt()' because that only typecheck
a statement at the position.
2020-05-29 14:45:04 -07:00
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