Commit Graph

582 Commits

Author SHA1 Message Date
Ben Langmuir
32f131e9ab [code-completion] Handle func-reference syntax for optional expected type
The underlying type-check was correct, but I forgot to consider it in
the outer code, and embarassingly never tested this case.

rdar://problem/28435922
2016-10-28 13:41:45 -07:00
Doug Gregor
6ce4be96f1 Merge pull request #5261 from DougGregor/type-checker-extra-constraints
[Type checker] Eliminate generation of useless constraints NFC.
2016-10-13 13:40:09 -07:00
Doug Gregor
735ef839e2 [Code completion] Suppress vacuous infix operator completions.
With the previous type-checker change, we end up with some vacuous
infix operator completions, where the right-hand side and result type
are *both* type variables. Suppress these; they aren't useful to the
developer.
2016-10-13 10:16:20 -07:00
Bob Wilson
dfa207b7ae Use std::function to fix unsafe use of llvm::function_ref.
This was exposed by building with a recent version of clang. Without this
change, the following tests were failing:

    Swift(macosx-x86_64) :: IDE/complete_assignment.swift
    Swift(macosx-x86_64) :: IDE/complete_enum_elements.swift
    Swift(macosx-x86_64) :: IDE/complete_stmt_controlling_expr.swift
    Swift(macosx-x86_64) :: SourceKit/CodeComplete/complete_structure.swift

I did not narrow it down to which uses of DeclFilter were problematic.
The global variables certainly do not seem like a good place to use a
function_ref. rdar://problem/28699882
2016-10-12 16:44:11 -07:00
Ben Langmuir
114d836737 Merge pull request #5183 from benlangmuir/cc-inst-curry-ref
[code-completion] Fix type-relation check on implicitly curried instance methods
2016-10-07 15:46:32 -07:00
Ben Langmuir
a6934d1e6d [code-completion] Fix type-relation check on implicitly curried instance methods
We strip the first input type on instance methods like,
struct S { func foo(T) -> U } // (S)->(T)->U

but we should not do that when it's actually a curried instance method,
such as S.foo.
2016-10-07 13:55:13 -07:00
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -07:00
Doug Gregor
66e20116f2 Extend ErrorType with an "original type" and use it to clean up substitution.
Type::subst()'s "IgnoreMissing" option was fairly unprincipled, dropping
unsubstituted types into the resulting AST without any indication
whatsoever that anything went wrong. Replace this notion with a new
form of ErrorType that explicitly tracks which substituted type caused
the problem. It's still an ErrorType, but it prints like the
substituted type (which is important for code completion) and allows
us to step back to the substituted type if needed (which is used by
associated type inference). Then, allow Type::subst(), when the new
UseErrorTypes flag is passed, to form partially-substituted types that
contain errors, which both code completion and associated type
inference relied on.

Over time, I hope we can use error-types-with-original-types more
often to eliminate "<<error type>>" from diagnostics and teach
Type::subst() never to return a "null" type. Clients can check
"hasError()" to deal with failure cases rather than checking null.
2016-10-06 16:40:28 -07:00
Ben Langmuir
d2e2d5fe84 [code-completion] Complete as function reference when the type matches
If we're completing in a context that expects a function type, try to
match methods/functions as function references before trying them as
calls.  This means that

func take(_: (Int)->()) {}
func foo(a: Int) {}
take(#^A^#)  // completes foo(a:)  instead of foo(a: {#value#})

Note: doesn't yet work with generic types.

rdar://problem/28435922
2016-10-05 14:25:38 -07: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
Slava Pestov
0b8beea69b IDE: Add CodeCompleteInitsInPostfixExpr to completion cache key
This fixes a source of non-determinism. The IDE/complete_constructor
test would sometimes fail depending on the order in which prior tests
ran, since those prior tests might populate the code completion cache.
2016-10-02 23:49:14 -04:00
Slava Pestov
a9c68c0736 AST: Remove archetype from AbstractTypeParamDecl
There's a bit of a hack to deal with generic typealiases, but
overall this makes things more logical.

This is the last big refactoring before we can allow constrained
extensions to make generic parameters concrete. All that remains
is a small set of changes to SIL type lowering, and retooling
some diagnostics in Sema.
2016-09-22 19:48:30 -07:00
practicalswift
ad02d73ee6 Remove unused method isOptionSetDecl(...).
Last usage removed in 31f583f164
2016-09-16 18:37:42 +02:00
Xi Ge
f37f189fcd Refactor a long macro definition to a more readable function. NFC (#4734) 2016-09-12 23:56:09 -07:00
Ben Langmuir
c8cf118b12 [codecompletion] Complete initializers after 'self'
... in other initializers.  We don't restrict it to convenience inits
because you might have forgotten the convenience keyword and the
compiler will give you a fixit.

rdar://problem/20913297
2016-09-12 13:40:47 -07: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
Ben Langmuir
4136f919ce Merge pull request #4348 from rintaro/cc-override-access
[CodeCompletion] Never emit 'private' for conformance or override declarations
2016-08-25 08:29:16 -07:00
Ben Langmuir
d8fa0b00ba [codecomplete] Handle null type in AbstractClosureExpr context
rdar://problem/27643235
2016-08-23 14:58:44 -07:00
Ben Langmuir
2855634999 [codecomplete] Check for ErrorType before asking for CD->getResultType()
Fixes a crash where we try to cast ErrorType to a function type to get
the result.

rdar://problem/27763826
2016-08-23 13:14:56 -07:00
Rintaro Ishizaki
526139986a [CodeCompletion] Emit access modifier for override or conformance member only if 'public'
At least, because of SE-0025, we cannnot emit 'private' for them.

Consider:
  protocol P {
    func meth()
  }
  private class C : P {
    #^TOKEN^#
  }
2016-08-20 05:12:01 +09:00
Rintaro Ishizaki
81c1edee5d [CodeCompletion] Suffix ": " instead of "=" when completing attribute argument names
In addtion, renamed DeclAttrParamEqual to DeclAttrParamColon.
2016-08-17 02:33:04 +09:00
Ben Langmuir
89fd31d78f [codecompletion] Add @escaping to override completions
Flush out the ASTPrinter's ability to exclude and include specific
attributes to cover TypeAttrKinds and have code-completion use this to
print @escaping in override completions.  Incidentally fix a case where
we weren't forwarding important options after type transformation, which
prevented printing @escaping in transformed parameter types.

rdar://problem/27772722
2016-08-11 16:43:32 -07:00
Argyrios Kyrtzidis
8b1dde645a [IDE] Fix code-completion fallout after changes for SE-0111.
rdar://27642873
2016-08-09 18:07:58 -07:00
Ted Kremenek
c9e57af9c0 Merge pull request #4174 from nkcsgexi/type-translate
[CodeCompletion] Refactor archetype transform to avoid using recursion.
2016-08-09 17:41:14 -07:00
Xi Ge
2ae236808c [CodeCompletion] Refactor archetype transform to avoid using recursion. rdar://27615558
We have a radar (rdar://27615558) complaining the exiting recursive calls in type transform
of code completion hangs. This patch refactor the existing code to avoid using
recursion. From existing tests' perspective, this is NFC. I am not able to contrive the
test case that leads to the hang, neither is given by the radar.
2016-08-09 16:33:17 -07:00
Slava Pestov
173658a5d8 SIL: Round-trip DynamicSelfType properly
When DynamicSelfType occurs outside of a class body (for example,
inside of a SIL function), it is not enough to simply utter 'Self',
because then we lose the underlying type.

Instead, print it out as '@dynamic_self Foo', where 'Foo' is the
underlying class type or archetype, and add parser support for
the same.

Fixes <rdar://problem/27735857>.
2016-08-09 14:18:03 -07:00
practicalswift
31f583f164 Remove unused method isOptionSet(...).
Last usage removed in 468e6d9c3d
2016-08-06 13:05:14 +02:00
Ben Langmuir
468e6d9c3d [CodeCompletion] Complete unresolved members that are not enums or OptionSets
Replace the enum and OptionSet-specific code with static member lookup
that checks the type against the contextual type.  This lets us complete
static variables, static functions, and initializers.  In particular,
this fixes completion of NS_EXTENSIBLE_STRING_ENUM types from
Objective-C.

rdar://problem/26628652
2016-07-29 14:51:40 -07:00
Andrew Trick
a18d490d6a Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3773)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 14:21:15 -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
Andrew Trick
0ed9ee8dee Revert "Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3724)"
This reverts commit ece0951924.

This results in lldb failues on linux that I can't readily debug.
Backing out until they can be resolved.
2016-07-26 02:50:57 -07:00
Andrew Trick
ece0951924 Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3724)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 02:18:21 -07:00
Doug Gregor
847b78245a [Type checker] Use argument labels from the expression for type-checking calls.
When we are type-checking calls, subscripts, or other call-like
expressions, use the argument labels provided by the various
expression nodes rather than those encoded in the tuple type. This
means that argument label matching now matches the callee
declaration's argument labels against the argument labels, without
relying on encoding the argument labels within types in the AST.

This refactor is a stepping stone torward SE-0111.
2016-07-25 13:27:35 -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
Doug Gregor
42a3e36c15 [SE-0091 Follow-up] Move !, &&, and || onto an extension of Bool.
The diagnostics changes make the compiler more robust in its diagnosis
of uses of operators defined in types.
2016-07-21 12:54:27 -07:00
Doug Gregor
0bf7c005b3 [SE-0091 Follow-up] Move global operators for non-generic concrete types into the type.
In various cases where we had global operators for non-generic
concrete types (such as String + String), move those operators into
the type. This should not affect the sources, but makes the exposition
of the library cleaner.

Plus, it's a good test for the compiler, which uncovered a few issues
where the compiler was coupled with the library.
2016-07-21 12:54:27 -07:00
Alex Hoppen
4aa6485ba0 [Printer] Rename ArchetypeTransformer to TypeTransformer
The ArchetypeTransformer isn't actually limited to transforming archetypes
but can transform arbitrary types. Thus, we can rename it to TypeTransformer
2016-07-20 10:55:50 +02:00
Joe
67dccb283e [SE-0095] Code feedback changes; Any is parsed as a keyword
- Any is made into a keyword which is always resolved into a TypeExpr,
allowing the removal of the type system code to find TheAnyType before
an unconstrained lookup.
- Types called `Any` can be declared, they are looked up as any other
identifier is
- Renaming/redefining behaviour of source loc methods on
ProtocolCompositionTypeRepr. Added a createEmptyComposition static
method too.
- Code highlighting treats Any as a type
- simplifyTypeExpr also does not rely on source to get operator name.
- Any is now handled properly in canParseType() which was causing
generic param lists containing ‘Any’ to fail
- The import objc id as Any work has been relying on getting a decl for
the Any type. I fix up the clang importer to use Context.TheAnyType
(instead of getAnyDecl()->getDeclaredType()). When importing the id
typedef, we create a typealias to Any and declare it unavaliable.
2016-07-19 12:01:37 -07:00
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