Commit Graph

894 Commits

Author SHA1 Message Date
Ben Langmuir
34da079aa6 Pass DynamicLookupInfo through VisibleDeclConsumers NFC
This commit adds a new type DynamicLookupInfo that provides information
about how a dynamic member lookup found a particular Decl. This is
needed to correctly handle KeyPath dynamic member lookups, but for now
just plumb it through everywhere.
2019-05-06 10:02:39 -07:00
Slava Pestov
fa12d85739 AST: Clean up associated type default representation a bit 2019-04-26 21:47:02 -04:00
Ben Langmuir
81ce653bc3 Merge pull request #23587 from benlangmuir/cc-omit-return
[code-completion] Add type context for single-expression function bodies
2019-04-25 13:49:45 -07:00
Rintaro Ishizaki
502a7bf3d7 Merge pull request #24180 from rintaro/ide-completion-static-subscript-rdar49131687
[CodeCompletion] Completion support for static subscript
2019-04-22 09:59:07 -07:00
Rintaro Ishizaki
6e0b8c2b67 [CodeCompletion] Completion support for static subscript
rdar://problem/49131687
2019-04-19 21:36:17 -07:00
Rintaro Ishizaki
3a2454c2c7 [CodeCompletion] Use opaque type for override completion if preferable
rdar://problem/49354106
2019-04-19 17:34:08 -07:00
Rintaro Ishizaki
8055583ddf [IDE] Print opaque result type as protocol composition
rdar://problem/49354663
2019-04-19 17:34:08 -07:00
Rintaro Ishizaki
7078862921 [CodeCompletion] Provide 'some' keyword where applicable
rdar://problem/49353647
2019-04-19 17:11:16 -07:00
Alexis Laferrière
007fbb6ebd Merge pull request #23932 from xymus/IsFinalRequest
Sema: implement `isFinal` using a request evaluator
2019-04-19 13:02:07 -07:00
Joe Groff
71912bbfd6 AST: Represent OpaqueTypeDecls.
To represent the abstracted interface of an opaque type, we need a generic signature that refines
the outer context generic signature with an additional generic parameter representing the underlying
type and its exposed constraints. Opaque types also need to be keyed by their originating decl, so
that we can treat values of the same opaque type as the same. When we check a FuncDecl with an
opaque type specified as its return type, create an OpaqueTypeDecl and associate it with the
originating decl. (A representation for *types* derived from the opaque decl will come next.)
2019-04-17 14:43:32 -07:00
Alexis Laferrière
98059831c9 Sema: implement isFinal using a request evaluator
Add the request evaluator `IsFinalRequest` to lazily determine if a
`ValueDecl` is final.
2019-04-17 09:17:44 -07:00
Slava Pestov
5062a81e3d AST: Start returning SelfProtocolConformances from ModuleDecl::lookupConformance()
Fixes <rdar://problem/49241923>, <https://bugs.swift.org/browse/SR-10015>.
2019-04-16 23:02:50 -04:00
Slava Pestov
91dffc9d44 Sema: Use AnyFunctionType::printParams() to print argument lists instead of printing a tuple type
Once the '@escaping' bit is removed from TupleTypeElt, it no longer makes
sense to print argument lists as if they were TupleTypes or ParenTypes,
since function types are '@escaping' by default inside tuples but not
in argument lists.

Instead, print ArrayRef<AnyFunctionType::Param> directly. For now this
introduces some awkward usages of AnyFunctionType::decomposeInput();
these will go away once the AST is changed to represent the argument list
as a list of expressions and not a single tuple expression.
2019-04-15 00:22:29 -04:00
Rintaro Ishizaki
93632f0bbe Merge pull request #23716 from rintaro/ide-completion-calleedecl-rdar49158044
[CodeCompletion] Associate callee declaration with call patterns
2019-04-05 17:50:37 -07:00
Slava Pestov
3095c36585 IDE: Remove prepareForRetypechecking() 2019-04-02 01:51:57 -04:00
Rintaro Ishizaki
0c38f2df8a [CodeCompletion] Associate callee declaration with call patterns
In `addFunctionCallPattern()` we should associate declarations if
possible.

rdar://problem/49158044
2019-04-01 11:21:43 -07:00
Jordan Rose
0ba6c495ba Add @_implementationOnly
This is an attribute that gets put on an import in library FooKit to
keep it from being a requirement to import FooKit. It's not checked at
all, meaning that in this form it is up to the author of FooKit to
make sure nothing in its API or ABI depends on the implementation-only
dependency. There's also no debugging support here (debugging FooKit
/should/ import the implementation-only dependency if it's present).

The goal is to get to a point where it /can/ be checked, i.e. FooKit
developers are prevented from writing code that would rely on FooKit's
implementation-only dependency being present when compiling clients of
FooKit. But right now it's not.

rdar://problem/48985979
2019-03-28 15:57:53 -07:00
Jordan Rose
9ed3fe061d Change ModuleDecl::getImportedModules to take an option set
...in preparation for me adding a third kind of import, making the
existing "All" kind a problem. NFC, except that I did rewrite the
ClangModuleUnit implementation of getImportedModules to be simpler!
2019-03-28 14:44:41 -07:00
Ben Langmuir
e255bac6be [code-completion] Fix type context for single-expression implicit getter
This adds an implicit body so that we can dig out the return type
context the same way as a normal function. For now, we are also treating
the first expression in a multi-statement implicit getter body the same
way; we'll need to refactor how we complete in accessors to
differentiate those cases.
2019-03-26 16:45:32 -07:00
Ben Langmuir
b14cd916a3 [code-completion] Add type context for single-expression functions
Extend the support for single-expression closures to handle
single-expression functions of all kinds. This allows, e.g.

    func foo() -> MyEnum { .<here> }

to complete members of `MyEnum`.
2019-03-26 16:45:27 -07:00
Rintaro Ishizaki
42d36431f0 Merge pull request #23502 from rintaro/ide-completion-unresolvedoptional-rdar47806831
[CodeCompletion] Don't provide 'init(nilLiteral:)' et al in optional context
2019-03-26 11:31:03 -07:00
Rintaro Ishizaki
e64b037962 Merge pull request #23542 from rintaro/ide-completion-keypathcontext-rdar46102807
[CodeCompletion] Infer keypath root type from the context type
2019-03-26 10:16:04 -07:00
Ted Kremenek
fe215edb9b Merge pull request #19743 from Azoy/smarter-struct-init
[Sema] Synthesize default values for memberwise init
2019-03-25 17:31:01 -07:00
Rintaro Ishizaki
65d8d29d2a [CodeCompletion] Infer keypath root type from the context type
So that this works:

```
func foo(_: KeyPath<SomeObject, Int>) {}
foo(\.<HERE>)
```

rdar://problem/46102807
2019-03-25 16:29:19 -07:00
Rintaro Ishizaki
b1efc21e08 [CodeCompletion] Don't ignore .some(Wrapped) and .none for now
with "TODO: ignore them in expression context".
They are useful in pattern context, so we should provide them in
completion.
2019-03-25 16:08:44 -07:00
Rintaro Ishizaki
7e3a5dc50b [CodeCompletion] Don't provide 'init(nilLiteral:)' et al in optional context
For unresolved member completion, member decls in `Optional`
referenceable by implicit member expression are useless in most cases.
- `init(_: <#Wrapped#>)`
- `init(nilLiteral: ())`
- `.some(<#Wrapped#>)`
- `.none`

Instead, provide `nil` with erasing `.` instruction.

rdar://problem/47806831
2019-03-22 15:21:15 -07:00
Rintaro Ishizaki
7ae18ff0f1 [CodeCompletion] Provide empty call pattern after paren
This improves discoverability of no-parameter initializers.

rdar://problem/46215262
2019-03-22 10:56:40 -07:00
Ben Langmuir
f5a216fc04 Merge pull request #23411 from benlangmuir/cc-1-close
[code-completion] Add type context for single-expression closures
2019-03-20 06:56:49 -07:00
Rintaro Ishizaki
1b3c4ad4a5 Merge pull request #23372 from rintaro/ide-completion-escapedident-16232627
[CodeCompletion] Escape declaration base name if needed
2019-03-19 22:22:32 -07:00
Rintaro Ishizaki
df473f641d [CodeCompletion] Escape declaration base name if needed
There should be escaped identifiers in code completion:
- As primary expression: Any keyword name except for `self` and `Self`.
- After dot: Something named `init`.

rdar://problem/16232627
2019-03-19 16:42:46 -07:00
Ben Langmuir
f8a3afb7bb Fix lifetime of type context in result builder
There usually won't be a lot of expected types, so just use a
SmallVector and copy it instead of trying to get tricky with the
lifetime.
2019-03-19 07:04:39 -07:00
Ben Langmuir
b817cbb9bc [code-completion] Add type context for single-expression closures
When completing in the only expression of closure, use the return type
of the closure as the type context for the code-completion. However,
since code-completion may be on an incomplete input, we only use the
return type to improve the quality of the result, not to mark it
invalid, since (a) we may add another statement afterwards, or (b) if
the context type is Void it doesn't need to match the value.
2019-03-18 17:04:33 -07:00
Rintaro Ishizaki
fd542e267c [CodeCompletion] 'case' keyword completion at the top of 'switch' stmt
rdar://problem/35943849
2019-03-18 16:58:52 -07:00
Rintaro Ishizaki
df20597e8f [Gardening][CodeCompletion] Remove unused parameter
Non-`Outermost` parameter isn't used anymore. It used to be used for
adding tuple label in calling parameter.
2019-03-17 14:25:09 -07:00
Rintaro Ishizaki
71aeea93f5 [CodeCompletion] Fix an assertion failure
If the type has unbound generic parameter, we cannot substitute types
for member decls.

rdar://problem/48896424
2019-03-14 12:22:19 -07:00
Azoy
6f7d20b99e Synthesize default values for memberwise init
Introduce stored property default argument kind

Fix indent

Assign nil to optionals with no initializers

Don't emit generator for stored property default arg

Fix problem with rebase

Indentation

Serialize stored property default arg text

Fix some tests

Add missing constructor in test

Print stored property's initializer expression

cleanups

preserve switch

complete_constructor

formatting

fix conflict
2019-03-13 18:57:36 -05:00
Rintaro Ishizaki
97d7111fa6 [CodeCompletion] Clean-up result build for method/function all
Don't emit duplicate results for implicitly curried instance methods
with defaulted parameters.
2019-03-05 16:45:48 -08:00
Rintaro Ishizaki
489a53864c [CodeCompletion] Display mapped type for subscript result 2019-03-05 16:45:48 -08:00
Rintaro Ishizaki
c99af83901 [CodeCompletion] Consolidate parameter list processing funcitons
There were 2 functions to output argument list. Consolidate them and
consistently use it from every call like production (i.e. function call,
constructor call, enum with associated values, subscript)
2019-03-05 16:45:48 -08:00
Rintaro Ishizaki
82b5f2a195 [CodeCompletion] Find parsed expression from typechecked decl context
Instead of re-typechecking parsed expression, find typechecked
expression that corresponds to the parsed expression from the
typechecked decl context, because the sub expressions of the parsed
expression can be weirdly mutated/replaced by decl context typechecking.

rdar://problem/48141174
2019-02-28 18:39:46 -08:00
Rintaro Ishizaki
6872f6c0cb Merge pull request #19742 from AnthonyLatsis/class-var-override-compl
[CodeCompletion][Parser] Completions for overridable static members
2019-02-26 09:52:37 -08:00
Rintaro Ishizaki
dc8508435b [CodeCompletion] Show bound generic types for enum elements
We weren't displaying bound generic types for enum elements. It's
inconsistent with functions and initializiers.
2019-02-20 11:31:04 -08:00
Rintaro Ishizaki
25f9b8843c [CodeCompletion] Show the enum type for enum element with assoc values
enum MyEnum {
    case null
    case str(String)
}

When completing elements for enum like this, the former shows `MyEnum`,
but the latter shows `(String) -> MyEnum`. This is inconsistent with
function call pattern which only shows the result type.

rdar://problem/48220244
2019-02-20 10:29:59 -08:00
fischertony
ae415b2a4b When followed by an 'override' or CC token inside a class, treat 'class' as a modifier rather than an introducer. 2019-02-16 16:02:22 +03:00
fischertony
ecfce56110 Don't exclude @autoclosure from the attribute list when printing override completions 2019-02-16 16:02:22 +03:00
fischertony
86d9d7a6b5 Fix override completions when a valid introducer is present but the override keyword is not. 2019-02-16 16:02:22 +03:00
fischertony
bb9482bab5 [CodeCompletion][Parser] Completions for overridable static members 2019-02-16 16:02:06 +03:00
Rintaro Ishizaki
0bebba840e Merge pull request #22539 from rintaro/ide-codecompletion-dottype-rdar22072865
[CodeCompletion] Implement .Type completion in expression context
2019-02-12 16:03:29 -08:00
Rintaro Ishizaki
ec85151a80 [CodeCompletion] Add '.Protocol' completion for protocol in type context 2019-02-12 10:58:30 -08:00
Rintaro Ishizaki
01b8fbc1bf [CodeCompletion] Implement .Type completion in expression context
rdar://problem/22072865
2019-02-12 10:40:08 -08:00