Commit Graph

894 Commits

Author SHA1 Message Date
Rintaro Ishizaki
1d845d6e3f [IDE/SourceKit] New SourceKit request for filtered method list
`source.request.conformingmethods` is a new SourceKit request which
receives a source position and a list of protocol namses, returns a list
of methods whose return type conforms to the requested protocols.

rdar://problem/44699573
2019-02-08 12:56:58 -08:00
Robert Widmann
c5b7230d22 [NFC] Upgrade EnumElementDecl to a DeclContext
Pure plumbing for the sake of default arguments.
2019-01-16 18:39:30 -05:00
Slava Pestov
e3c5eb7d3a IDE: Remove unused function 2019-01-14 14:57:03 -05:00
Rintaro Ishizaki
b446d6b051 Merge pull request #21377 from rintaro/ide-contextinfo
[SourceKit][IDE] New SourceKit request to retrieve context type information
2019-01-15 01:54:16 +09:00
Rintaro Ishizaki
cc1d5c1147 [IDE] Move typeCheckContext() to ExprContextAnalysis.cpp
NFC
2019-01-10 17:52:37 +09:00
Rintaro Ishizaki
2fbd3fe682 [IDE] Move ExprContextAnalyser to its own file
NFC
2019-01-10 17:52:37 +09:00
Rintaro Ishizaki
d17bb78a0b [AST] Add shouldHideFromEditor() method
This replaces shouldHideDeclFromCompletionResults() in IDE.
2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
867c28ea74 [IDE] Rename collectArgumentExpectation() to analyzeApplyExpr()
Removed unnecessary arguments.
2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
e3387c6fdb [IDE] ExprContextAnalyzer::Analyze() doesn't need to return success 2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
758ba5e5d0 [IDE] Decouple ExprContextAnalyzer and ExprContextInfo
Just refactoring.
ExprContextInfo automatically construct analyzer and analyze().
2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
5c64324740 [IDE] Refactor ExprContextAnalyzer. NFC
We don't need to keep ExprFinder beyond analysis.
2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
2fb542537f [IDE] Rename CodeCompletionTypeContextAnalyzer to ExprContextAnalyzer
NFC
2019-01-10 17:52:36 +09:00
Rintaro Ishizaki
b033f4880c [CodeCompletion] Only analyze inner most context
Now that this passes all test cases we currently have. Stop analyzing
outer contexts because it may emit invalid context type.
2019-01-10 17:52:36 +09:00
Parker Schuh
f5859ff46e Rename NameAliasType to TypeAliasType. 2019-01-09 16:47:13 -08:00
Rintaro Ishizaki
4b39c20ace [CodeCompletion] Unresolved member completion at type parameter context
We need to map 'GenericTypeParamType' to 'ArchetypeType' to lookup its
members.

rdar://problem/46657585
2019-01-09 14:44:29 +09:00
Slava Pestov
dffa857b2a Merge pull request #21704 from slavapestov/remove-restate-filtering-consumer
Fix a crash by removing the RestateFilteringConsumer
2019-01-08 08:03:59 -05:00
Slava Pestov
c41be6ee0c IDE: Fix another usage of lookupVisibleMemberDecls() to not pass in an existential type
It's better to use the 'Self' archetype here.
2019-01-08 00:14:52 -05:00
Slava Pestov
8a201af7e6 IDE: Fix a usage of lookupVisibleMemberDecls() to not pass in an existential type
It's better to use the 'Self' archetype here.
2019-01-08 00:14:52 -05:00
Slava Pestov
f81c23d154 IDE: Replace some dead code with an assert 2019-01-08 00:14:52 -05:00
Argyrios Kyrtzidis
ab7427723e [Parse/Syntax] Refactoring to decouple the parser from syntax tree creation
Instead of creating syntax nodes directly, modify the parser to invoke an abstract interface 'SyntaxParseActions' while it is parsing the source code.
This decouples the act of parsing from the act of forming a syntax tree representation.
'SyntaxTreeCreator' is an implementation of SyntaxParseActions that handles the logic of creating a syntax tree.
To enforce the layering separation of parsing and syntax tree creation, a static library swiftSyntaxParse is introduced to compose the two.

This decoupling is important for introducing a syntax parser library for SwiftSyntax to directly access parsing.
2019-01-07 19:52:59 -08:00
swift-ci
39161d5b36 Merge pull request #20600 from adrian-prantl/36032653 2018-12-05 17:01:58 -08:00
Adrian Prantl
d63debeb60 Experimental: Extend ClangImporter to import clang modules from DWARF
When debugging Objective-C or C++ code on Darwin, the debug info
collected by dsymutil in the .dSYM bundle is entirely
self-contained. It is possible to debug a program, set breakpoints and
print variables even without having the complete original source code
or a matching SDK available. With Swift, this is currently not the
case. Even though .dSYM bundles contain the binary .swiftmodule for
all Swift modules, any Clang modules that the Swift modules depend on,
still need to be imported from source to even get basic LLDB
functionality to work. If ClangImporter fails to import a Clang
module, effectively the entire Swift module depending on it gets
poisoned.

This patch is addressing this issue by introducing a ModuleLoader that
can ask queries about Clang Decls to LLDB, since LLDB knows how to
reconstruct Clang decls from DWARF and clang -gmodules producxes full
debug info for Clang modules that is embedded into the .dSYM budle.

This initial version does not contain any advanced functionality at
all, it merely produces an empty ModuleDecl. Intertestingly, even this
is a considerable improvement over the status quo. LLDB can now print
Swift-only variables in modules with failing Clang depenecies, and
becuase of fallback mechanisms that were implemented earlier, it can
even display the contents of pure Objective-C objects that are
imported into Swift. C structs obviously don't work yet.

rdar://problem/36032653
2018-12-05 13:54:13 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Rintaro Ishizaki
337d53f217 [CodeCompletion] Be lenient in callee analysis
Accept `getInterfaceType->hasError()` declarations. Even if the part of
the declaration has error, we still have chance to get context info from
the other part of it. For instance:

  func foo(x: Int, y: INt) { }
  foo(x: #^COMPLETE^#

We should resolve 'Int' as the context type even if parameter `y` is an
error type.
2018-12-03 17:26:12 +09:00
Rintaro Ishizaki
56c531d05a [CodeCompletion][NFC] Add some doc comments 2018-11-27 08:02:47 +09:00
Rintaro Ishizaki
c55d6ce7bd [CodeCompletion] Fix call arguments completion in overloaded case
In `<expr> '(' <code-completion-token>` case, we usually complete call
arguments. If '<expr>' isn't typechecked, for example, because of
overloading, we used to give up arguments completions.

Now, use possible callee informations from the context type analyzer. This
increases the chance to provide accurate completions.

rdar://problem/43703157
2018-11-27 02:41:11 +09:00
Rintaro Ishizaki
8a6c540e74 [CodeCompletion][NFC] Collect possible callees instead of params
in context type analysis.
Still NFC, but this is needed by later commits.
2018-11-27 02:41:03 +09:00
Rintaro Ishizaki
1af807894e [CodeCompletion][NFC] Store context results in analyzer member fields
To simplify call-site code.
2018-11-26 23:09:29 +09:00
Rintaro Ishizaki
bd4f20dd5f [CodeCompletion][NFC] Move collectArgumentExpectation()
These functions are only used by CodeCompletionTypeContextAnalyzer.
Move them into it.
2018-11-26 20:06:38 +09: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
Arnold Schwaighofer
2ac6cda9a7 Make sure the code completion takes both private imports and testable
imports into account separately.
2018-11-12 14:53:56 -08:00
Pavel Yaskevich
b3f86259a8 [CodeCompletion] Add isAutoClosure flag to parameter builder 2018-11-10 11:59:28 -08:00
Arnold Schwaighofer
6cc3d377ff Refactor part2 2018-11-08 18:16:17 -08:00
Rintaro Ishizaki
8d1dca822e [CodeCompletion] Revert: "Restrict ancestor search to brace"
(part of 63356a2f48)

NFC because `ParentFarthest` result isn't used from anywhere.
2018-11-05 17:33:36 +09:00
Brent Royal-Gordon
9bd1a26089 Implementation for SE-0228: Fix ExpressibleByStringInterpolation (#20214)
* [CodeCompletion] Restrict ancestor search to brace

This change allows ExprParentFinder to restrict certain searches for parents to just AST nodes within the nearest surrounding BraceStmt. In the string interpolation rework, BraceStmts can appear in new places in the AST; this keeps code completion from looking at irrelevant context.

NFC in this commit, but keeps code completion from crashing once TapExpr is introduced.

* Remove test relying on ExpressibleByStringInterpolation being deprecated

Since soon enough, it won’t be anymore.

* [AST] Introduce TapExpr

TapExpr allows a block of code to to be inserted between two expressions, accessing and potentially mutating the result of its subexpression before giving it to its parent expression. It’s roughly equivalent to this function:

  func _tap<T>(_ value: T, do body: (inout T) throws -> Void) rethrows -> T {
    var copy = value
    try body(&copy)
    return copy
  }

Except that it doesn’t use a closure, so no variables are captured and no call frame is (even notionally) added.

This commit does not include tests because nothing in it actually uses TapExpr yet. It will be used by string interpolation.

* SE-0228: Fix ExpressibleByStringInterpolation

This is the bulk of the implementation of the string interpolation rework. It includes a redesigned AST node, new parsing logic, new constraints and post-typechecking code generation, and new standard library types and members.

* [Sema] Rip out typeCheckExpressionShallow()

With new string interpolation in place, it is no longer used by anything in the compiler.

* [Sema] Diagnose invalid StringInterpolationProtocols

StringInterpolationProtocol informally requires conforming types to provide at least one method with the base name “appendInterpolation” with no (or a discardable) return value and visibility at least as broad as the conforming type’s. This change diagnoses an error when a conforming type does not have a method that meets those criteria.

* [Stdlib] Fix map(String.init) source break

Some users, including some in the source compatibility suite, accidentally used init(stringInterpolationSegment:) by writing code like `map(String.init)`. Now that these intializers have been removed, the remaining initializers often end up tying during overload resolution. This change adds several overloads of `String.init(describing:)` which will break these ties in cases where the compiler previously selected `String.init(stringInterpolationSegment:)`.

* [Sema] Make callWitness() take non-mutable arrays

It doesn’t actually need to mutate them.

* [Stdlib] Improve floating-point interpolation performance

This change avoids constructing a String when interpolating a Float, Double, or Float80. Instead, we write the characters to a fixed-size buffer and then append them directly to the string’s storage.

This seems to improve performance for all three types, but especially for Double and Float80, which cannot always fit into a small string when stringified.

* [NameLookup] Improve MemberLookupTable invalidation

In rare cases usually involving generated code, an overload added by an extension in the middle of a file would not be visible below it if the type had lazy members and the same base name had already been referenced above the extension. This change essentially dirties a type’s member lookup table whenever an extension is added to it, ensuring the entries in it will be updated.

This change also includes some debugging improvements for NameLookup.

* [SILOptimizer] XFAIL dead object removal failure

The DeadObjectRemoval pass in SILOptimizer does not currently remove reworked string interpolations as well as the old design because their effects cannot be described by @_effects(readonly). That causes a test failure on Linux. This change temporarily silences that test. The SILOptimizer issue has been filed as SR-9008.

* Confess string interpolation’s source stability sins

* [Parser] Parse empty interpolations

Previously, the parser had an odd asymmetry which caused the same function to accept foo(), but reject “\()”. This change fixes the issue.

Already tested by test/Parse/try.swift, which uses this construct in one of its throwing interpolation tests.

* [Sema] Fix batch-mode-only lazy var bug

The temporary variable used by string interpolation needs to be recontextualized when it’s inserted into a synthesized getter. Fixes a compilation failure in Alamofire.

I’ll probably follow up on this bug a bit more after merging.
2018-11-02 19:16:03 -07:00
Rintaro Ishizaki
9df8b2f2a6 [CodeCompletion] Preserve completion status in 'let' pattern
Also, stop context type analysis at outer most expression that matches
the position. It seems that that produces more appropriate results.

rdar://problem/30103287
2018-10-30 19:14:03 +09:00
Rintaro Ishizaki
74356d655c [CodeCompletion] Implement context type analysis at subscript position
This improves completion for index part of subscript expression.

rdar://problem/38920581
2018-10-30 10:58:32 +09:00
Rintaro Ishizaki
c84ea2b281 [CodeCompletion] Improve context type analysis for overloaded method
For:

    class MyClass {
        func foo(x: SomeType)
        func foo(x: OtherType)
    }

    func test(obj: MyClass) {
        obj.foo(x: <HERE>)
    }

Type checker doesn't keep overloaded choices for 'obj.foo' in the AST
after typechecking. Code completion need to lookup members to collect
possible parameter types.
2018-10-30 09:02:00 +09:00
Rintaro Ishizaki
b0c8fc5709 Merge pull request #19953 from rintaro/ide-completion-unresolvemember-polish
[CodeCompletion] Polish unresolved member completion
2018-10-23 08:16:27 +09:00
Rintaro Ishizaki
04aba4465b [CodeCompletion] Don't emit member type construction for the same type
in unresolved member completion. e.g.

  struct Node {
    typealias Child = Node
    init(children: [Child]) {}
  }
  let node: Node = .#^COMPLETE^#

This used to emit `.init(children:)` and `.Child(children:)`.
2018-10-19 19:21:39 +09:00
Rintaro Ishizaki
54f2aa3147 [CodeCompletion] Tiny optimization for unresolved member compilation
* Early exit for operators
* Early exit for equal types
2018-10-19 19:21:39 +09:00
Rintaro Ishizaki
459e07fc73 [CodeCompletion] Don't emit failable initialization for member types
in unresolved member completion.
2018-10-19 19:21:39 +09:00
Rintaro Ishizaki
90fe0a7e86 [CodeCompletion] Implement completion for 'get', 'set', 'willSet', 'didSet'
Implement 'get', 'set', 'willSet', 'didSet' completion at the beginning
of accessor position.

  var value: Ty {
    <HERE> // 'get', 'set', 'willSet' and 'didSet' along with normal
           // completion.
  }

  var value: Ty {
    get { return ... }
    <HERE> // 'get', 'set', 'willSet' and 'didSet' only.
  }

rdar://problem/20957182
2018-10-19 14:28:56 +09:00
Rintaro Ishizaki
b1ae8efd77 [CodeCompletion] Enable case enum pattern completion in top level
rdar://problem/21001526
2018-10-12 16:56:52 +09:00
Rintaro Ishizaki
8d37c79ed6 Merge pull request #17649 from AnthonyLatsis/code-compl-precedencegroups
[Parse][CodeCompletion] Completions for precedencegroup decls
2018-10-11 15:45:17 +09:00
Doug Gregor
264b680e96 Merge branch 'master' into immortal-type-checker 2018-10-10 20:36:23 -07:00
Doug Gregor
599e07e5d9 [Type checker] Keep the type checker alive as long as the ASTContext is.
It is possible for the SIL optimizers, IRGen, etc. to request information
from the AST that only the type checker can provide, but the type checker
is typically torn down after the “type checking” phase. This can lead to
various crashes late in the compilation cycle.

Keep the type checker instance around as long as the ASTContext is alive
or until someone asks for it to be destroyed.

Fixes SR-285 / rdar://problem/23677338.
2018-10-10 16:44:42 -07:00
Anthony Latsis
f2ff87e652 Merge branch 'master' into code-compl-precedencegroups 2018-10-09 18:08:16 +03:00
Rintaro Ishizaki
f5f4fa6d15 [CodeCompletion] Handle TupleShuffleExpr in completion context analyzer
(and TupleExpr at non-call argument position).
Now, unresolved member completion in array literal should work.

Also, Don't calculate convertibility to 'Any' type. That would be a
noise to type relation because anything is convertible to 'Any'.

rdar://problem/43302814
2018-10-09 20:41:40 +09:00
Rintaro Ishizaki
3d80635cf4 [CodeCompletion] Fix completion for local decls in trailing closure
Previously, local decls in trailing closure didn't show up if the
closure had preceding arguments and the completion was triggered at
beginning position of expression context. like:

   funcName(x: arg1) {
      var localVar = 12
      if <HERE>
   }

The completion mode used to be overwritten in 'completeCallArg()' which
is called from 'parseExprCallSuffix(). We should detect completion for
immediate argument position in 'parseExprList()'.

rdar://problem/41869885
2018-10-04 16:56:07 +09:00