Commit Graph

894 Commits

Author SHA1 Message Date
Joe
da94183e35 [SE-0095] [Code completion] for the Any type keyword
Now that Any isn’t in the stdlib we need to add it to code completion
separately.
2016-07-19 12:01:37 -07:00
Doug Gregor
5a83c86455 Eliminate default arguments from TupleType.
In Swift, default arguments are associated with a function or
initializer's declaration---not with its type. This was not always the
case, and TupleType's ability to store a default argument kind is a
messy holdover from those dark times.

Eliminate the default argument kind from TupleType, which involves
migrating a few more clients over to declaration-centric handling of
default arguments. Doing so is usually a bug-fix anyway: without the
declaration, one didn't really have

The SILGen test changes are due to a name-mangling fix that fell out
of this change: a tuple type is mangled differently than a non-tuple
type, and having a default argument would make the parameter list of a
single-parameter function into a tuple type. Hence,

  func foo(x: Int = 5)

would get a different mangling from

  func foo(x: Int)

even though we didn't actually allow overloading.

Fixes rdar://problem/24016341, and helps us along the way to SE-0111
(removing the significance of argument labels) because argument labels
are also declaration-centric, and need the same information.
2016-07-15 13:55:53 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -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
Dmitri Gribenko
acac328eaa stdlib: remove _Reflectable 2016-07-05 14:13:23 -07:00
Ben Langmuir
c8f7da4de1 [CodeCompletion] Support a narrow case for producing trailing closures directly
This adds a narrow special case in code-completion for control-flow-like
methods such as DispatchQueue().sync that are () -> (), to add a new
completion where the trailing closure is immediately expanded rather
than having to invoke placeholder expansion as a second step.

rdar://problem/26628804
2016-07-01 14:16:57 -07:00
Ben Langmuir
ea848aeaae Rename C++ macro 'defer' -> 'SWIFT_DEFER'
In C++ we can't have nice things. The macro name 'defer' collided with
use of 'defer' in the Tokens.def file and we were already doing horrible
workarounds in a couple of places to allow them to be included into the
same file. So use a less awesome but more robust name (thanks to Joe for
suggesting SWIFT_DEFER).

Incidentally, sort a bunch of #inlcudes.
2016-06-29 14:57:58 -07:00
Ben Langmuir
dbf848e9cf [CodeCompletion] Protect against a couple of null Types
Fix two crashes related to unresolved-member completion where either the
EnumDecl itself is missing, or its elements have not been type-checked.
Incidentally, resolve the type of the enum elements in the case where I
have observed this happening.

rdar://problem/26860249
2016-06-29 10:29:09 -07:00
Ben Langmuir
7191333a83 [CodeCompletion] Fix use of dangling pointers to stack memory
These pointers were already dangling, but after the recent change to
cleanup ErrorType values, we would actually dereference them while
walking the expressions.  In debug builds, this manifest as crashes.
2016-06-28 15:46:15 -07:00
Ben Langmuir
d1fd8adbc4 [CodeCompletion] Workaround a bunch of issues with ErrorType in completion
The brief explanation is that we are using the type-checker in a
questionable way where for various reasons we can type-check the same
"context" expression more than once. Until we figure out how to stop
doing that, at least avoid this obvious source of issues with ErrorType
showing up during the initial (poor) typecheck and then blocking
progress when we do a more specific check later.

rdar://problem/26462306
rdar://problem/25248190
2016-06-27 16:50:30 -07:00
David Farler
c9f5504797 Cascading Doc Comments: Look up class hierarchy when doc comments are missing
If a class member doesn't have a doc comment but a base class does, show
the base class's comment and add a note about where it came from.

rdar://problem/16512247
2016-06-27 11:55:31 -07:00
Ben Langmuir
1c00cd9637 [CodeCompletion] Fix dot completion with non-nominals
Completion after dot inside an init (or any other parent expr with a
nominal type) was incorrectly looking at the types of parent expressions
whenever the base type was not a nominal (even an lvalue of a nominal
wasn't working).  This code to look at the type of the parent was never
correct, and fortunately the type-checking issues that prompted it to be
added in the first place have since been fixed, so we can just delete
it.

rdar://problem/25773358
2016-06-21 15:12:22 -07:00
Slava Pestov
7814c47b71 AST: Slightly change meaning of NominalTypeDecl::getDeclaredType()
Consider this code:

struct A<T> {
  struct B {}
  struct C<U> {}
}

Previously:

- getDeclaredType() of 'A.B' would give 'A<T>.B'
- getDeclaredTypeInContext() of 'A.B' would give 'A<T>.B'

- getDeclaredType() of 'A.C' would give 'A<T>.C'
- getDeclaredTypeInContext() of 'A.C' would give 'A<T>.C<U>'

This was causing problems for nested generics. Now, with this change,

- getDeclaredType() of 'A.B' gives 'A.B' (*)
- getDeclaredTypeInContext() of 'A.B' gives 'A<T>.B'
- getDeclaredType() of 'A.C' gives 'A.C' (*)
- getDeclaredTypeInContext() of 'A.C' gives 'A<T>.C<U>'

(Differences marked with (*)).

Also, this change makes these accessors fully lazy. Previously,
only getDeclaredTypeInContext() and getDeclaredIterfaceType()
were lazy, whereas getDeclaredType() was built from validateDecl().

Fix a few spots where the return value wasn't being checked
properly.

These functions return ErrorType if a circularity was detected via
the generic parameter list, or if the extension did not resolve.
They return Type() if the extension cannot be resolved *yet*.

This is pretty subtle, and I'll need to do another pass over
callers of these functions at some point. Many of them should be
moved over to use getSelfInContext(), getSelfOfContext() and
getSelfInterfaceType() instead.

Finally, this patch consolidates logic for diagnosting invalid
nesting of types.

The parser had some code for protocols in bad places and bad things
inside protocols, and Sema had several different bail-outs for
bad things in protocols, nested generic types, and stuff nested
inside protocol extensions.

Combine all of these into a single set of checks in Sema. Note
that we no longer give up early if we find invalid nesting.
Leaving decls unvalidated and un-type-checked only leads to
further problems. Now that all the preliminary crap has been
fixed, we can go ahead and start validating these funny nested
decls, actually fixing some crashers in the process.
2016-06-18 17:15:24 -07: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
practicalswift
57bccc8b06 [gardening] Fix inconsistent formatting. 2016-06-04 00:37:15 +02:00
Ben Langmuir
56158fca08 [CodeCompletion] Don't mark #keyPath as "expression specific" without #
We suggest #keyPath in every String context, so having it be
expression-specific is artificially increasing its priority.

rdar://problem/26544672
2016-05-31 11:42:01 -07:00
Argyrios Kyrtzidis
bb86f41ecb [IDE/completion] Hide clang decls that are marked as 'swift_private', from the code-completion results. 2016-05-28 14:17:10 -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
a629d668ac [CodeCompletion] Mark deprecated completions as "not recommended"
If a declaration is marked deprecated (but not unavailable) we want to
mark it as "not recommended" so that users know this probably isn't what
you want. We already do something like this in Clang code completions of
deprecated ObjC declarations.

rdar://problem/26335424
2016-05-23 09:25:30 -07:00
Ben Langmuir
0963c5ba05 [CodeCompletion] Supress unavailable unresolved member completions
rdar://problem/26335424
2016-05-23 09:25:29 -07:00
Doug Gregor
814a08a5da [IDE] Code completion for Objective-C #keyPath expressions.
Implement code completion support for Objective-C #keyPath
expressions, using semantic analysis of the partially-typed keypath
argument to provide an appropriate set of results (i.e., just
properties and types).

This implements all of the necessary parts of SE-0062 / SR-1237 /
rdar://problem/25710611, although at some point I'd like to follow it
up with some warnings to help migrate existing string literals to
2016-05-21 22:28:51 -07:00
Alex Hoppen
a0a74aeb46 SE-0064 / SR-1239: Code completion for #selector of property getters/setters.
Implement basic code completion support for #selector with property
getters/setters. The vast majority of this implementation comes from
Alex Hoppen (@ahoppen), with only a handful of my own tweaks. Alex has
more interesting ideas on improving this that I wasn't quite ready to
commit to, so this is more basic than the overall goal.
2016-05-11 23:03:37 -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
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
Trent Nadeau
5301d5cd82 Added (non)mutatingvariant doc fields 2016-04-15 16:13:22 -04:00
Jordan Rose
bc83940301 Make pointer nullability explicit using Optional.
Implements SE-0055: https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md

- Add NULL as an extra inhabitant of Builtin.RawPointer (currently
  hardcoded to 0 rather than being target-dependent).
- Import non-object pointers as Optional/IUO when nullable/null_unspecified
  (like everything else).
- Change the type checker's *-to-pointer conversions to handle a layer of
  optional.
- Use 'AutoreleasingUnsafeMutablePointer<NSError?>?' as the type of error
  parameters exported to Objective-C.
- Drop NilLiteralConvertible conformance for all pointer types.
- Update the standard library and then all the tests.

I've decided to leave this commit only updating existing tests; any new
tests will come in the following commits. (That may mean some additional
implementation work to follow.)

The other major piece that's missing here is migration. I'm hoping we get
a lot of that with Swift 1.1's work for optional object references, but
I still need to investigate.
2016-04-11 20:06:38 -07:00
David Farler
a9297eed9f Rename llvm::markup namespace to swift::markup
This was naming was cargoed from long ago and this functionality isn't
directly related to LLVM, it's specific to Swift.
2016-04-10 13:46:25 -07:00
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Dmitri Gribenko
336b7198f7 Merge pull request #2016 from danra/code_completion_includes
Fix includes order in CodeCompletion.cpp and add missing includes in …
2016-04-04 01:44:32 -07:00
danra
dae3731ab0 Cosmetic namespace comments/spacing fixes (NFC)
* Cosmetic namespace comments/spacing fixes (NFC)

* unnamed->anonymous namespace in comments (NFC)
2016-04-02 17:15:44 -07:00
Dan Raviv
af831051a1 Add using statements to improve readability and DRY 2016-04-02 01:01:24 +03:00
Dan Raviv
87a4058fb8 Fix includes order in CodeCompletion.cpp and add missing includes in CodeCompletionResultBuilder.h 2016-04-02 00:26:08 +03:00
Xi Ge
c452f9640f [CodeCompletion] Add a field NotRecommendedReason to code completion result to indicate why an item is not recommended, NFC. rdar://25415947
As implied in rdar://24818863, striking through a module name may be an overkill to suggest the module is redundant to import. We try to
fine-grain not-recommended-reason so that proper UI cue can be adopted in the future.
2016-03-30 16:23:33 -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
Xi Ge
23d1b51e6f [CodeCompletion] Teach override completion to collect the associatedtypes that need to be specified from conforming protocols. 2016-03-29 11:17:00 -07:00
Michael Ilseman
b01caa01c6 Merge remote-tracking branch 'origin/master' into import-as-member 2016-03-25 15:47:47 -07:00
Xi Ge
e7faebeb40 Address @benlangmuir's code review comments. 2016-03-25 14:25:41 -07:00
Xi Ge
c94172869b Re-apply "[CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863" 2016-03-25 14:14:19 -07:00
Dmitri Gribenko
904b7f53c0 Revert "[CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863"
This reverts commit 218010afb9.  It causes
timeouts in IDE/complete_repl_from_cocoa.swift.
2016-03-25 14:14:19 -07:00
Xi Ge
baff806cf6 [CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863
Reported: http://stackoverflow.com/questions/36180575/struck-out-module-xcode-7-3
2016-03-25 14:14:19 -07:00
Xi Ge
016bca6f03 Re-apply "[CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863" 2016-03-25 11:45:51 -07:00
Dmitri Gribenko
856f3b1cb7 Revert "[CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863"
This reverts commit 218010afb9.  It causes
timeouts in IDE/complete_repl_from_cocoa.swift.
2016-03-25 11:01:29 -07:00
Xi Ge
218010afb9 [CodeCompletion] Check the module visibility properly to handle the multi-file case. rdar://24818863
Reported: http://stackoverflow.com/questions/36180575/struck-out-module-xcode-7-3
2016-03-24 17:44:46 -07:00
Ben Langmuir
b842160f85 [CodeCompletion] Don't complete operator = after Void result
print(1) = blah

doesn't make much sense.
2016-03-21 11:39:42 -07:00
Ben Langmuir
8c0d5408b7 [CodeCompletion] Fix call-arg completion when we remove all the overloads we found
We have code for pruning unlikely overloads, but when it pruned all
overloads it was treating that as if there was nothing to complete.
Instead, fallback to postfix-expr-begin.

We should also figure out why we're not getting any viable types here,
but we need to handle failure gracefully.

rdar://problem/24356118
2016-03-15 13:19:11 -07:00
Ben Langmuir
92a038cbe2 [CodeCompletion] Strengthen null check to assert NFC
This function is only called with a non-null type, which is the only
reasonable way to call it anyway.
2016-03-12 09:01:38 -08:00
Ben Langmuir
812d1566a7 [CodeCompletion] Don't look through non-type contexts in override
We don't actually want to skip non-type contexts here, since we should
only be showing override completions in the type context itself. This
was pretty obscure to hit in practice, but I noticed it while fixing the
crasher.
2016-03-12 08:39:11 -08:00
Ben Langmuir
da9c68d373 [CodeCompletion] Don't complete inits after func/var/override keywords
When completing nominal members (overrides, etc.), don't show inits if
the user already added a keyword that can't go before an init.
2016-03-11 23:00:11 -08:00