Commit Graph

582 Commits

Author SHA1 Message Date
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
Xi Ge
fd91b119a7 Merge pull request #1600 from apple/unhide-important-underscored-protocols
stdlib: unhide important underscored protocols in the generated interface
2016-03-11 17:44:28 -08:00
Ben Langmuir
49b70ebe56 Fix formatting missed in previous commit NFC
Argh, forgot to git-add.
2016-03-11 17:16:08 -08:00
Ben Langmuir
47723848bd [CodeCompletion] Fix crash in override completion in a bogus context
Use the right context for getting the formal access. To get the
completions right, we should fix the FIXME about not backtracking the
parser so far.
2016-03-11 17:15:19 -08:00
Xi Ge
f602f5c6e9 [CodeCompletion] Exclude underscored stdlib protocols from code completion items. 2016-03-11 14:08:31 -08:00
Max Moiseev
885b564bf5 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-09 17:16:37 -08:00
Ben Langmuir
0bc2cc4290 [CodeCompletion] Negate incorrect comment NFC 2016-03-09 16:20:24 -08:00
Ben Langmuir
4a30637e08 [CodeCompletion] Don't complete unavailable methods in override
We generally don't want to override unavailable methods.  We already
filter out unavailable decls when completing values, but that's in a
separate visible decl consumer.

rdar://problem/25058233
2016-03-09 16:20:23 -08:00
Max Moiseev
1fae0d1325 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-08 12:48:48 -08:00
Ben Langmuir
ce3c2de4a6 [CodeCompletion] Convert optionals when checking for literal protocol conformance
Except for nil literals, we don't want to look at the optional itself,
since the typechecker would implicitly look to the underlying type.

rdar://problem/24707210
2016-03-08 09:39:04 -08:00
Ben Langmuir
09754f21cd [CodeCompletion] Don't add type-relation for SequenceType protocol in loop
We don't want to prioritize the type name for protocols, since they
can't be used (generally) to construct an instance of the type. Ideally
we would prioritize types that conform to the protocol.

For rdar://problem/24873625
2016-03-07 22:22:18 -08:00
Chris Lattner
fe9fe47b7e Implement support for generic typealiases. 2016-03-07 22:20:16 -08:00
Max Moiseev
7fe6916bf6 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-07 12:10:47 -08:00