Commit Graph

293 Commits

Author SHA1 Message Date
Ben Langmuir
61a151989a [code-completion] Add filter rules for description in addition filter-name
The filter name isn't helpful if you want to make rules about specific
overloads - e.g. only show the [Int] subscript on Array.

rdar://problem/28920034
2017-06-15 16:32:29 -07:00
Robert Widmann
6509f78f13 tests: replace remaining 'mkdir -p' calls with %empty-directory(...)'
These changes were made manually.
2017-06-04 11:08:39 -07:00
Pavel Yaskevich
f09d2ad397 [ConstraintSolver] Forbid forming solutions with free generic type parameters
`FreeTypeVariableBinding::GenericParameters` mode allowed to bind
all free type variables with fresh generic parameter types, which
is incorrect (at least) if there are multiple generic solutions
present, because such parameters couldn't be compared.

This mode was used for code completion, which is now switched to use
`FreeTypeVariableBinding::UnresolvedType` instead.
2017-06-01 14:05:05 -07:00
Norio Nomura
3da7926a5e Revert "Revert "Enable SourceKit tests if building SourceKit""
This reverts commit a383adf9df.
2017-04-26 21:16:36 +09:00
Arnold Schwaighofer
a383adf9df Revert "Enable SourceKit tests if building SourceKit" 2017-04-24 17:59:03 -07:00
Alex Blewitt
71987b90b2 Merge pull request #8485 from norio-nomura/enable-sourcekit-test
Enable SourceKit tests if building SourceKit
2017-04-24 17:37:30 +01:00
Ben Langmuir
9d745fa18f [test] Fix SourceKit test harder against unnecessary USRs
This time make sure I actually got *all* the associated_usrs, d'oh.
2017-04-21 15:25:28 -07:00
Ben Langmuir
83c43544ab [test] Cleanup a test relying on USRs that didn't need to
We don't care what the USRs are here, we were just using them to avoid
results slipping in between the start of the structure and the module
name.  This patch does that in a way that doesn't use the USR.
2017-04-18 19:48:00 -07:00
Max Moiseev
2e67c13d15 Fixing some tests 2017-04-14 16:19:06 -07:00
Norio Nomura
0c2a4461fb [SourceKit] Mark test failing on Linux 2017-04-04 18:46:01 +09:00
Norio Nomura
c49fa3c6d2 [SourceKit] Mark some tests requires objc_interop 2017-04-04 18:45:04 +09:00
Max Moiseev
7d73b2e1ca Arithmetic => Numeric 2017-03-13 11:50:02 -07:00
Max Moiseev
835b8809d2 Merge branch 'master' into new-integer-protocols 2017-03-07 16:18:54 -08:00
Erik Eckstein
7995d3d35a SourceKit: Use new mangling for USR generation. 2017-02-23 12:47:10 -08:00
Max Moiseev
1814e4fce3 Fixing tests 2017-01-23 10:59:31 -08:00
Max Moiseev
e1de9fcf0c More test fixes 2017-01-09 16:17:21 -08:00
Max Moiseev
6a06b667da Fixing some and XFAILing other failing tests 2017-01-06 17:56:20 -08:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Slava Pestov
cfe9e6a3de IDE: Use GenericSignatures and interface types (mostly)
There was a ton of complicated logic here to work around
two problems:

- Same-type constraints were not represented properly in
  RequirementReprs, requiring us to store them in strong form
  and parse them out when printing type interfaces.

- The TypeBase::getAllGenericArgs() method did not do the
  right thing for members of protocols and protocol extensions,
  and so instead of simple calls to Type::subst(), we had
  an elaborate 'ArchetypeTransformer' abstraction repeated
  in two places.

Rewrite this code to use GenericSignatures and
GenericFunctionType instead of old-school GenericParamLists
and PolymorphicFunctionType.

This changes the code completion and AST printer output
slightly. A few of the changes are actually fixes for cases
where the old code didn't handle substitutions properly.
A few others are subjective, for example a generic parameter
list of the form <T : Proto> now prints as <T where T : Proto>.

We can add heuristics to make the output whatever we want
here; the important thing is that now we're using modern
abstractions.
2016-10-02 23:49:15 -04:00
Rintaro Ishizaki
b827298892 [CodeCompletion] Modifier related improvements in CompletionOverrideLookup
* If "required" or "convenience" is specified, emit only initializers
* If "final" or "open" is specified, don't emit initializers or typealias
* If "typealias" is specified, emit only associated type implementation
* Emit "override" or "required" modifier for initializers
* Emit access modifier for initializers
* Emit designated initializers even if "override" is specified
* Don't emit inheritance clause for associated type implentation
2016-08-27 03:48:51 +09:00
Slava Pestov
79a1512576 Sema: Three fixes for the new @escaping attribute
- If a parameter type is a sugared function type, mark the type
  as non-escaping by default. Previously, we were only doing this
  if the parameter type was written as a function type, with no
  additional sugar.

  This means in the following cases, the function parameter type
  is now non-escaping:

  func foo(f: ((Int) -> Void))

  typealias Fn = (Int) -> Void
  func foo(f: Fn)

- Also, allow @escaping to be used in the above cases:

  func foo(f: @escaping ((Int) -> Void))

  typealias Fn = (Int) -> Void
  func foo(f: @escaping Fn)

- Diagnose usages of @escaping in inappropriate locations, instead
  of just ignoring them.

It is unfortunate that sometimes we end up desugaring the typealias,
but currently there are other cases where this occurs too, such as
qualified lookpu of protocol typealiases with a concrete base
type, and generic type aliases. A more general representation for
sugared types (such as an AttributedType sugared type) would allow
us to solve this in a more satisfactory manner in the future.

However at the very least this patch factors out the common code
paths and adds comments, so it shouldn't be too bad going forward.

Note that this is a source-breaking change, both because @escaping
might need to be added to parameters with a sugared function type,
and @escaping might be removed if it appears somewhere where we
do not mark function types as non-escaping by default.
2016-08-17 19:37:23 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Slava Pestov
ddc51c5917 AST: Implement SE-0102, introducing new semantics for Never alongside @noreturn
No migrator support yet, and the code for @noreturn is still in
place.
2016-07-22 14:56:39 -07:00
Ben Langmuir
f962e74017 [CodeCompletion] Rebalance match score and semantic context
The high weight on semantic context turns out to give a lot of
unreasonable completions on common types. For example
  [0].ma<here>
was suggesting withUnsafeMutable... over map.

rdar://problem/27393776
2016-07-20 16:37:58 -07:00
Jordan Rose
aee92ff612 SE-0025: Parsing and basic completion for 'fileprivate'. (#3391)
Right now 'fileprivate' is parsed as an alias for 'private' (or
perhaps vice versa, since the semantics of 'private' haven't changed
yet). This allows us to migrate code to 'fileprivate' without waiting
for the full implementation.
2016-07-07 15:20:41 -07:00
Chris Lattner
ffcafd7c00 fix the AST printer to stop omitting parens around "simple enough" parameter
lists.
2016-07-02 20:24:58 -07:00
Ben Langmuir
f72bd5453f [CodeCompletion] Fix a crash when completing typealiases for protocol conformance
The index may be at the end of the ArrayRef of chunks if the completion
ends with a simple parameter with no type annotation.  Check that the
index is in-bounds before adding text.

rdar://problem/26273906
2016-06-21 16:56:29 -07:00
Ben Langmuir
3c9c52010b [CodeCompletion] Add image and color literals to results
Surface these results in the codecomplete code path (they're already
there in the codecomplete.open code path) so we can use them from IDEs.
For now, just use ad-hoc filtering to show them when the type matches
(or there is no expected type).  Ideally we would make this filtering
configurable like we do in the codecomplete.open code path.

rdar://problem/25836544
2016-06-21 11:41:15 -07:00
Brian Croom
b9b565aaed [SourceKit] Mark more tests as needing ObjC interop 2016-06-20 10:35:27 -04:00
Doug Gregor
e2632c1cfa [Code completion] Teach code completion to use declarations for postfix completions.
Code completion had the ability to use declarations to provide better
code completion results for postfix completions, e.g., calls to
functions/methods, but it wasn't trying to get these declarations from
anywhere. Now, get these declarations from the solution to the
constraint system.

The impetus for this is to use default-argument information from the
declaration rather than the type, but plumbing this information
through also means that we get proper "rethrows" annotations, covered
by <rdar://problem/21010193>, and more specific completions in a
number of other places.

Fixes <rdar://problem/21010193>.
2016-06-16 11:44:42 -07:00
Brian Croom
98e3ca8bc4 Annotate some SourceKit tests that fail on Linux.
* A bunch of them require objc_interop because they import code containing
  Objective-C.
* Many others fail on Ubuntu 14.04 because the C++ there doesn't have a
  functional std::regex implementation which is required by the
  `complete-test` tool.

It may be possible to adjust some of these tests in the future to not
need these extra requirements, but this is a straightforward way to
clean up Linux test results for now.
2016-06-14 08:55:48 -04:00
Ben Langmuir
4600b1dd12 [CodeCompletion] Fix incorrect upper bound for assertion
This assertion was bogus if there were fewer results than N.
2016-06-04 18:22:18 -07:00
Ben Langmuir
122350d450 [CodeCompletion] Apply filter rules directly to inner results
... and don't try to filter the extended results.  Once the results are
extended with the common prefix they will not match identifier filter
rules, which will create differences between completions depending on
whether they had a filter text or were a postfix expression.  Also,
allow filtering by name directly on the inner operator name for inner
operators.

rdar://problem/26312235
2016-05-25 12:07:17 -07:00
Ben Langmuir
5615b38040 [CodeCompletion] Show 'return' completion by default when appropriate
Ideally we would have precise completion for all our keywords; for now,
just imporove handling of 'return', which we can do by checking if the
current context is a function/closure/init/subscript/etc.

rdar://problem/26307555
2016-05-24 11:01:22 -07:00
Ben Langmuir
c77af6907e [CodeCompletion] Switch filter-rules and popular api to follow SE-0021 naming
We want inputs for function names to follow SE-0021 with the exception
that a function with no arguments is spelled `foo()` instead of `foo`,
because we have no type to disambiguate with and it's not ambiguous with
a call in this context.

Internally, we use a filter name without underscores because we don't
want to introduce spurious matches to the `_` character which might be
part of identifiers.

For now, continue to accept the old names to ease the transition.

rdar://problem/24350800
2016-05-10 11:13:46 -07:00
Ben Langmuir
b4ce34aba9 [CodeCompletion] Remove ... and & from function filter names
The filter name of a function should match the spelling of the function
name according to the language except that we don't insert _ for unnamed
parameters because underscores are legal inside identifiers and we don't
want to introduce spurious matches (also, we keep the () on a
parameterless function for disambiguation).

rdar://problem/26118915
2016-05-10 11:13:45 -07:00
Ben Langmuir
2ef514ea98 Revert "[CodeCompletion] Don't complete .members after a space"
It was pointed out to me that this syntax is legal (d'oh).  Maybe we
should delete the extra spaces when we insert the ".", but otherwise
this is working as-is.

This reverts commit 1878be2c1f.
2016-05-03 13:14:30 -07:00
Ben Langmuir
1878be2c1f [CodeCompletion] Don't complete .members after a space
This lets us filter down to binary operators, etc.

rdar://problem/25994246
2016-05-03 10:23:14 -07:00
Ben Langmuir
69967ca45c [CodeCompletion] Identify known operators and force a fixed sort order
In the new code-completion code path, force any known operators to go
through a fixed sort order. To identify operators unambiguously, add a
new BuiltinOperator code-completion kind to handle non-decl operators
(!, ., ?., and =).

rdar://problem/25994246
rdar://problem/23440367
2016-05-03 10:23:13 -07:00
Ben Langmuir
f1ba846c78 [CodeCompletion] Swap the exact-match if one is a better case-sensitive match
Instead of just taking the first one, consider whether there is a better
result because of case-sensitivity.

rdar://problem/25994202
2016-05-03 10:23:12 -07:00
Ted Kremenek
b8bbed8c13 [WIP] Implement SE-0039 (Modernizing Playground Literals) (#2215)
* Implement the majority of parsing support for SE-0039.

* Parse old object literals names using new syntax and provide FixIt.

For example, parse "#Image(imageLiteral:...)" and provide a FixIt to
change it to "#imageLiteral(resourceName:...)".  Now we see something like:

test.swift:4:9: error: '#Image' has been renamed to '#imageLiteral
var y = #Image(imageLiteral: "image.jpg")
        ^~~~~~ ~~~~~~~~~~~~
        #imageLiteral resourceName

Handling the old syntax, and providing a FixIt for that, will be handled in a separate
commit.

Needs tests.  Will be provided in later commit once full parsing support is done.

* Add back pieces of syntax map for object literals.

* Add parsing support for old object literal syntax.

... and provide fixits to new syntax.

Full tests to come in later commit.

* Improve parsing of invalid object literals with old syntax.

* Do not include bracket in code completion results.

* Remove defunct code in SyntaxModel.

* Add tests for migration fixits.

* Add literals to code completion overload tests.

@akyrtzi told me this should be fine.

* Clean up response tests not to include full paths.

* Further adjust offsets.

* Mark initializer for _ColorLiteralConvertible in UIKit as @nonobjc.

* Put attribute in the correct place.
2016-04-25 07:19:26 -07:00
practicalswift
db452dcbe9 [gardening] "[ a, b ]" → "[a, b]" 2016-04-17 21:26:08 +02:00
practicalswift
c2107f456c [gardening] "[ a, b ]" → "[a, b]" (#2227) 2016-04-17 21:02:18 +02:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Ben Langmuir
6c2ec9a1b1 [CodeCompletion] Do our best to set NotRecommended on other-module results
These results are cached, so we can't use the type-relation.  Instead we
use a small hack of checking the textual return type for "Void".  This
is obviously not ideal, but it lets us detect the most important cases.

rdar://problem/22810741
2016-03-30 16:57:18 -07:00
Ben Langmuir
968b0491b8 [CodeCompletion] Make Void-returning functions "NotRecommended" in typed context
When we know we're expecting an expression that returns a value, make
the completion "NotRecommended" to deprioritize it.

rdar://problem/22810741
2016-03-29 14:20:25 -07:00
Manav Gabhawala
7862f104c9 [Parser] Cleans up parsing of parameter attributes. Implements SE-0053. Fixes SR-979, SR-1020 and cleans up implementation of SE-0003. Provides better fix-its and diagnostics for misplaced 'inout' and prohibits 'var' and 'let' from parameter attributes 2016-03-29 13:55:46 -04:00
Ben Langmuir
4e33d50c7f [CodeCompletion] Bump the priority on keywords in the
experimental code-completion path. Move them right before "other module"
results. This is a bit of a hack. Ideally, we would have a much better
idea which keywords are actually legal/likely in a given context and
could prioritize them even more.  Since today we basically splat in all
the keywords, keep them below the current module results so they don't
overwhelm us.

rdar://problem/25119529
2016-03-16 14:58:35 -07:00
Ben Langmuir
88c1065133 [CodeCompletion] Expose the existing option for whether to include exact matches
So we can play with it more easily.
2016-03-16 14:21:53 -07:00