Commit Graph

1357 Commits

Author SHA1 Message Date
Ben Langmuir
882959b60d [CodeCompletion] Remove incorrect special-casing for throw/catch
It's not okay to filter to only ErrorType results, since we may be
trying to chain to an error type result foo.bar.getError().  And the
existing logic had no way to handle results from other modules, so we
were missing key results like 'NSError'.

Eventually we'll want to bring back something like this that handles all
modules, but as a way to bump the priority of ErrorType results rather
than to filter out everything else.

rdar://problem/20985515

Swift SVN r28716
2015-05-18 19:00:04 +00:00
Ben Langmuir
0fbbe1807b [CodeCompletion] Fix crash completing method with associated type
protocol P { typealias T; func foo() -> T }
    func invalid(x: P) { x.#^COMPLETE^#

We were trying to access a null Type created because the associated type
doesn't make sense in the protocol type P (we can only use P as a
generic constraint, but it shouldn't crash code completion if we use it
incorrectly).

For rdar://problem/20305938

Swift SVN r28588
2015-05-14 22:46:59 +00:00
Ben Langmuir
69fdca43da Fix assertion failure code completing after nil literal
We were asserting (and doing the wrong thing) when trying to code
complete
    nil #^HERE^#

The issue is that we tried to apply a solution to the expression that
contained free type variables (converted to generic parameters). This
trips us up when we expect the new type to conform to protocols. In code
completion we generally only need the type of the expression, so this
commit switches to getting that more explicitly.  That said, this did
cause us to drop non-API parameter names in call patterns after an
opening '(' in some cases (covered by rdar://20962472).

Thanks to Doug for suggesting this solution!

rdar://problem/20891867

Swift SVN r28584
2015-05-14 22:22:37 +00:00
Ted Kremenek
62feb5c949 Change @availability to @available.
This came out of today's language review meeting.
The intent is to match #available with the attribute
that describes availability.

This is a divergence from Objective-C.

Swift SVN r28484
2015-05-12 20:06:13 +00:00
Ben Langmuir
59533a1973 Split off CodeCompletionCache into its own file
Swift SVN r28367
2015-05-09 19:03:22 +00:00
Ben Langmuir
f3ecb63f30 Move caching logic into the code completion consumer
This will let us implement caching in the client (e.g. SourceKit) at
some point and simplifies adding more levels of caching. Requires a
corresponding SourceKit change.

Swift SVN r28365
2015-05-09 18:51:30 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Ben Langmuir
e603126dc0 Factor out copying code completion results from one sink to another
We'll need to be able to do this in the client once we expose caching.

Swift SVN r28176
2015-05-05 19:02:17 +00:00
Ben Langmuir
c40100af66 Factor use of the CodeCompletion sys::Cache into get() and set() methods
Now get() and set() manage determining whether the results are stale,
and getResults() can just rely on that.

Also drive-by fix a data race where we were inserting our results sink
into the cache before it was finished being modified.

Swift SVN r28175
2015-05-05 19:02:16 +00:00
Ben Langmuir
563cd0acf0 Lift the code completion cache interface into the header
The only part that's hidden is the sys::Cache itself now.

Swift SVN r28174
2015-05-05 19:02:15 +00:00
Ben Langmuir
e39fb7224e Expose a libIDE function to lookup the completions for a module
We'll need this in order to move code completion result caching into the
client.

Swift SVN r28173
2015-05-05 19:02:13 +00:00
Doug Gregor
103526b771 Remove code completion's dependencies on getProtocols().
Swift SVN r27976
2015-04-30 16:13:43 +00:00
Ben Langmuir
fc53b6e355 [CodeCompletion] Expose some result creation APIs for SourceKit
We want to be able to synthesize new results inside SourceKit. At this
point, the simplest way to do that is to expose the constructors for
CodeCompletionResult and a create() function for CodeCompletionString.

The expectation that any strings are stored properly inside a
CodeCompletionResultSink is documented.

Swift SVN r27822
2015-04-27 22:27:48 +00:00
Doug Gregor
126e404fe5 Reimplement inference of type witnesses with a separate non-recursive pass.
Inference of type witnesses for associated types was previously
implemented as part of value witness matching in the constraint
solver. This led to a number of serious problems, including:
  - Recursion problems with the solver hunting for a type witness,
  which triggers more attemts to match value witnesses...
  - Arbitrarily crummy attempts to break the recursion causing
  type-check failures in fun places.
  - Ordering dependencies abound: different results depending on which
  value witnesses were satisfied first, failures because of the order
  in which we attempted to infer type witnesses, etc.

This new implementation of type witness inference uses a separate pass
that occurs whenever we're looking for any type witness, and solves
all of the type witnesses within a given conformance
simultaneously. We still look at potential value witnesses to infer
type witnesses, but we match them structurally, without invoking the
constraint solver.

There are a few caveats to this implementation:
  * We're not currently able to infer type witnesses from value
  witnesses that are global operators, so some tricks involving global
  operators (*cough* ~> *cough*) might require some manually-specified
  type witnesses. Note that the standard library doesn't include any
  such cases.

  * Yes, it's another kind of solver. At simple one, fortunately.

On the other hand, this implementation should be a big step forward:
  * It's far more predictable, order-invariant, and non-recursive.
  * The diagnostics for failures to infer type witnesses have
  improved.

Fixes rdar://problem/20598513.

Swift SVN r27616
2015-04-23 00:20:05 +00:00
Argyrios Kyrtzidis
5f6d091efc [AST] Keep track of the type decl that the type witness came from, for protocol conformances.
Swift SVN r27352
2015-04-16 06:23:54 +00:00
Ben Langmuir
f778836934 Add initializers to postfix-expr code completions
Previously, the only way to get initializers was completing after the
name of the type:
    Foo#^complete_here^#
    Foo(#^or_here^#

And now it will also work in unadorned expressions:
    #^a_top_level_completion^#
    bar(a, #^walked_into_a_bar^#

Unfortunately, not all our clients handle this well yet, so it's
protected by a language option.
    -code-complete-inits-in-postfix-expr

Swift SVN r27275
2015-04-14 14:54:08 +00:00
Ben Langmuir
70a93e0bfe Add code completion overload for defaulted arguments
When a call (func, method, initializer) has default arguments, produce
both the *with* and *without* default argument versions as if they were
overloaded.

rdar://problem/18573874

Swift SVN r27118
2015-04-08 02:41:20 +00:00
Jordan Rose
613b194025 [IDE] Honer @testable for top-level completions as well.
This is the last planned Swift-side fix for testability in this release!

rdar://problem/17732115

Swift SVN r26949
2015-04-03 20:20:17 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Doug Gregor
38cc1fe5c6 Remove LazyResolver arguments from API entry points to the conformance lookup table.
Swift SVN r26838
2015-04-02 00:06:01 +00:00
Ben Langmuir
ea6e1f24a7 Avoid unnecessary calls to CodeCompletionString::getName during sorting
This improves run time of this particular function by up to 8x in my
testing. For *really* large sets of code completions (I tested top-level
completion with Cocoa imported) this gives a 30-40% improvement across
the request, not including time spent in the client.  The tradeoff is a
slight increase in peak memory usage (I saw 0.7% or 1.2 MB for the
top-level Cocoa case).

<rdar://problem/20355626>

Swift SVN r26748
2015-03-31 03:27:06 +00:00
Xi Ge
cdf2e853ad [CodeCompletion] Use a better API to retrieve
all the protocols a type conform to.

Swift SVN r26694
2015-03-29 07:08:57 +00:00
Xi Ge
90cf8aec22 [CodeCompletion] Add types whose extensions
conform _ErrorType protocol to the completions of throw statement.

Swift SVN r26691
2015-03-29 05:56:06 +00:00
Jordan Rose
85a3751f6d Remove SourceFile::getImports in favor of FileUnit::getImportedModules.
getImportedModules is the canonical way to get imports, whether private,
public, or both. This is especially true now that we have more flags
for SourceFile imports that really shouldn't be consumed by anyone
outside of SourceFile.

In this same vein, provide addImports instead of setImports, since imports
are always additive.

No visible functionality change.

Swift SVN r26634
2015-03-27 16:36:47 +00:00
Jordan Rose
e334eed7a4 Record @testable in a SourceFile's import list.
No functionality change, since nothing's using it yet.

Swift SVN r26632
2015-03-27 16:36:44 +00:00
Xi Ge
18438647ef [CodeCompletion] Showing the member functions of Optional.
Previously, when code completing Optional<T>., we only show
the member functions of T; This fix adds the member functions
of Optional to the code completion list.
rdar://20316534

Swift SVN r26622
2015-03-27 02:53:09 +00:00
Xi Ge
256e038edf [CodeCompletion] Add exception handle clauses to catch stmt completion.
Swift SVN r26597
2015-03-26 18:32:13 +00:00
Xi Ge
0d9fb1aaa5 [CodeCompletion] Make sure only instantiable types are included
in code completion options when completing a throw statement.

Swift SVN r26571
2015-03-26 00:58:19 +00:00
Xi Ge
6f43e545fb [CodeCompletion] Auto-completing the throw statement.
When the code completion token appears after throw keyword,
a set of visible decls and instances conforming _ErrorType are
recommended as completion.

Swift SVN r26565
2015-03-25 23:46:26 +00:00
Xi Ge
8a64deb828 [codecompletion] auto-completing the catch statement.
When the code completion token is seen after the catch keyword, a set of
visible error types are suggested as completion.

Swift SVN r26519
2015-03-25 04:16:57 +00:00
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
John McCall
a0a16d78d2 Implement the do/catch statement. Tests to follow.
This patch also introduces some SILGen infrastructure for
dividing the function into "ordinary" and "postmatter"
sections, with error-handling-like stuff going into the
final section.  Currently, this is largely undermined by
SILBuilder, but I'm going to fix that in a follow-up.

Swift SVN r26422
2015-03-23 02:08:26 +00:00
Ben Langmuir
fff41e472e Hide _UnderscoredProtocols in code completion
We explicitly whitelist these "stdlib private" decls in interface
generation, because they may contain methods that users are required to
implement.  But in code-completion, there's no good reason to show them.
We still show completions for the methods themselves if you complete on
a public protocol that inherits from the private protocol. So,

<complete> => doesn't show _CollectionType

let a: CollectionType = ...
a.<complete> => *does* show startIndex, which comes from _CollectionType

rdar://problem/20086106

Swift SVN r26355
2015-03-20 17:14:08 +00:00
Doug Gregor
539c4b158e Use getAllConformances() in code completion rather than a manual wordlist.
Swift SVN r26324
2015-03-19 22:10:06 +00:00
Xi Ge
707071daa0 [CodeCompletion] Address Argyrios comments on r26134
Swift SVN r26271
2015-03-18 18:53:37 +00:00
Xi Ge
df187f7280 [CodeCompletion] Address Dmitri's comments on r26230
Swift SVN r26270
2015-03-18 18:53:34 +00:00
Ben Langmuir
5f2bcba8ba Update tests for code-completion modulename change
Add module name to OtherModule result output and update the tests
accordingly.

Swift SVN r26262
2015-03-18 16:40:28 +00:00
Ben Langmuir
ece29ccfa4 Add a module name field to code completion results
For decls, we get the most specific submodule from clang modules.  For
macros, we don't yet have a way to get this information, since the
mapping from module ID to submodule is burried in the ClangImporter.
Having submodule information for macros would also help reduce the space
cost of storing the module names, since we would hit the single-element
module name cache more often.

There is no special handling of imported headers, which currently come
through with their internal clang module name '__ObjC'.  Possibly these
should be treated as part of the current module.

A future commit will add the module name to swift-ide-test's output and update
the tests.

Swift SVN r26260
2015-03-18 16:14:11 +00:00
Xi Ge
a83a8e4f34 [CodeCompletion] avoid duplicating keywords.
When a developer auto-completes an override function,
we collect the keywords that have already been specified
by the developer, so that the code completion strings do
not duplicate them.
rdar://16738036

Swift SVN r26230
2015-03-17 20:35:56 +00:00
Xi Ge
520df97787 [CodeCompletion] Adopt a more efficient algorithm
to find the nearest AST parent that meets a certain condition

Swift SVN r26134
2015-03-14 08:30:16 +00:00
Xi Ge
0ad419cce2 [CleanUp] Remove unnecessary undefs
Swift SVN r26117
2015-03-14 00:34:33 +00:00
Xi Ge
8367428ed0 [CodeCompletion] Literal complete.
When code completing a literal expr, it is likely that code completion engine only collects the expr
that is not fully type checked. Therefore, no members of the literal can be suggested. To address this,
we try to climb up expr hierarchy in AST to find an expr with a nominal type, and use the nominal type
to finish code completion.
rdar://20059173

Swift SVN r26116
2015-03-14 00:34:32 +00:00
Dmitri Hrybenko
129f921a91 Fix a use-after-free in code completion for attributes
The code was binding a temporary std::string to a StringRef.

Swift SVN r26094
2015-03-13 07:35:37 +00:00
Xi Ge
07c16436c2 [cleanup] adding undef to several usages of included def file
Swift SVN r26050
2015-03-12 18:14:44 +00:00
Xi Ge
48ba44dd2c [CodeCompletion] Fxing Dmitri's review comments
Swift SVN r25965
2015-03-10 22:50:13 +00:00
Xi Ge
737f0ca6a6 [CodeCompletion] Using canAttributeAppearOnDecl() to decide whether an attribute is applicable.
Swift SVN r25961
2015-03-10 22:31:43 +00:00
Xi Ge
c0bf1f54ff [CodeCompletion] Further support the context-sensitivity of
auto-completing @attributes. By delaying the handling of code completion token after the entire decl being parsed, we know
what are the targets of the attribute to finishe, thus, only suggesting those applicable attributes.

Swift SVN r25938
2015-03-10 18:40:39 +00:00
Xi Ge
32e9a0aca7 [CodeCompletion] Making the code completion of attributes
context-sensitive. The first step is to recommend parameter-applicable
attributes only when the code completion token is found inside a
param decl.

Swift SVN r25810
2015-03-06 23:20:17 +00:00
Xi Ge
039674b492 Remove most user-inaccessbile attributes from the
code completion strings.

Swift SVN r25790
2015-03-05 23:12:24 +00:00
Xi Ge
f962814017 [CodeCompletion] address Jordan's comments about filtering
out non-usable attributes in code completion strings.

Swift SVN r25786
2015-03-05 21:58:29 +00:00