Commit Graph

1181 Commits

Author SHA1 Message Date
Slava Pestov
1c3ac86796 AST: Banish OptionalTypeKind to ClangImporter.h
The only place this was used in Decl.h was the failability kind of a
constructor.

I decided to replace this with a boolean isFailable() bit. Now that
we have isImplicitlyUnwrappedOptional(), it seems to make more sense
to not have ConstructorDecl represent redundant information which
might not be internally consistent.

Most callers of getFailability() actually only care if the result is
failable or not; the few callers that care about it being IUO can
check isImplicitlyUnwrappedOptional() as well.
2019-08-15 18:41:42 -04:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
Xi Ge
7658d63d62 IDE+Evaluator: refactor IDE type-checking utilities for subscript decl into requests
We used to have a function getRootAndResultTypeOfKeypathDynamicMember to return
both the root and result type of a subscript. This patch splits the function
into two functions returning root type and result type respectively. It also refactors
the implementation into the evaluator model.
2019-07-30 11:54:16 -07:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
Rintaro Ishizaki
4d076e85c7 [CodeCompletion] Enable 'openArchetypes' when checking if convertible
```swift
protocol Proto {}
struct ConcreteProto {}
struct MyStruct<T> {}

extension MyStruct where T: Proto {
  static var option: MyStruct<ConcreteProto> { get }
}
func foo<T: Proto>(arg: MyStruct<T>) {}
func test() {
  foo(arg: .#^HERE^#)
}
```
In this case, the type of `MyStruct.option` is `MyStruct<ConcreteProto>`
whereas the context type is `MyStruct<T> where T: Proto`.
When checking the convertibility of them , we need to "open archetype types".

rdar://problem/24570603
rdar://problem/51723460
2019-06-28 15:25:52 -07:00
Rintaro Ishizaki
257b61744e [CodeCompletion] Eliminate super related completion
In parser, 'parseExprPostfixSuffix()' can parse postfix expression for
'super'. 'parseExprSuper()' doesn't need to parse them.

In code-completion, 'completeExprSuper()' and 'completeExprSuperDot()'
can be consolidated to 'completePostfixExpr()' and 'completeDotExpr()'.
2019-06-26 09:59:47 -07:00
Rintaro Ishizaki
35f8686574 [CodeCompletion] Remove getTypeContextEnumElementCompletions()
Use getUnresolvedmemberCompletion() instead.

rdar://problem/45219937
2019-06-25 11:58:12 -07:00
Rintaro Ishizaki
588d87b90e [CodeCompletion] Remove completeCaseStmtDotPrefix() completion
Now that, normal dot-member completion works at case position. We don't
need to handle it specially.

rdar://problem/45219937
2019-06-25 11:18:14 -07:00
Rintaro Ishizaki
e7c8e22ce9 Merge pull request #25717 from rintaro/ide-completion-keypathlookup-rdar50073837
[CodeCompletion] Map the result type for keypath member lookup
2019-06-24 14:48:44 -07:00
Rintaro Ishizaki
9f02fa7b06 [CodeCompletion] Map the result type for keypath member lookup
rdar://problem/50073837
2019-06-24 12:34:31 -07:00
Rintaro Ishizaki
bb3edd5dde [CodeCompletion] contextual attribute completion only on the same line
It's common to have decls on consecutive lines. Better to show too many
attributes than too few.
2019-06-21 14:03:09 -07:00
Rintaro Ishizaki
bc037967d1 [CodeCompletion] Stop using DeclKind::Module as a isIndependent indicator 2019-06-21 11:15:25 -07:00
Rintaro Ishizaki
09ca68e485 [CodeCompletion] Don't attach attr to decl if blank line exists
```
@#^COMPLETE^#

public func something() {}
```
In this case, we can't say the user is adding attribute to the func or
starting a new declaration. So if there're one or more blank lines after the
completion, suggest context free attribute list.

rdar://problem/50441643
2019-06-20 17:06:32 -07:00
Rintaro Ishizaki
db2c11787b [AST] Inherit doc-brief comment from protocol, superclass, and requirement
rdar://problem/38422822
2019-06-20 10:04:05 -07:00
Rintaro Ishizaki
be2fabe762 [CodeCompletion] Enable custom attribute completion for func decl
rdar://problem/50352482
2019-06-18 16:09:49 -07:00
Hamish Knight
a3ead02902 Merge remote-tracking branch 'upstream/master' into a-couple-of-tangents 2019-06-13 14:46:55 +01:00
Rintaro Ishizaki
04ca9752cf [CodeCompletion] Enable type name completion for param decl attribute
rdar://problem/50074177
2019-06-11 17:34:45 -07:00
Doug Gregor
0494574706 Factor the computation of default arguments into ParameterListInfo.
Provide a place where we can capture more information about the parameters
from a declaration being called.
2019-06-11 17:34:44 -07:00
Rintaro Ishizaki
32a0b2e771 [CodeCompletion] Exclude precedence groups from type completion 2019-05-31 11:10:04 -07:00
Rintaro Ishizaki
9ba232d718 [CodeCompletion] Implement completion at custom attribute argument 2019-05-31 11:09:54 -07:00
Rintaro Ishizaki
878c9c600b [CodeCompletion] Enable type completion at beginning of attribute
for 'VarDecl' or if we don't know the kind of the decl.
Property delegate allows arbitrary type name (with `@propertyDelegate`
attr).
2019-05-31 09:44:19 -07:00
Rintaro Ishizaki
afd6d66130 [CodeCompletion] Fix attribute completion for var/let decl
There's no attribute declared for PatternBindingDecl. There are for
VarDecl. Code completion should consider DeclKind::PatternBinding as
DeclKind::Var.
2019-05-31 09:42:50 -07:00
Hamish Knight
2872210735 [CodeCompletion] Fix a call to computeDefaultMap
Resolves SR-10795.
2019-05-31 15:53:27 +01:00
Slava Pestov
c947eda18f AST: Use ProtocolDecl::getAssociatedTypeMembers() where possible 2019-05-28 22:08:31 -04:00
Rintaro Ishizaki
e2a4621b14 [CodeCompletion] Suggest #selector and #keyPath after # only if applicable
Also, add type annotation, and make it `TypeRelation[Identical]`.
'ExprSpecific' is too strong.
2019-05-21 17:25:53 -07:00
Rintaro Ishizaki
3c957de1c9 [CodeCompletion] Use CompletionLookup.CurrModule instance property 2019-05-21 17:24:59 -07:00
Rintaro Ishizaki
83084e2b5f [CodeCompletion] Suggest 'file', 'line', et al. after #
rdar://problem/47169238
2019-05-21 17:24:59 -07:00
Rintaro Ishizaki
1b688d5e21 [CodeCompletion] Implement call signature completion for subscript
rdar://problem/28874899
2019-05-17 14:20:28 -07:00
Rintaro Ishizaki
5b5d342995 [CodeCompletion] Enable call signature completion for unresolved member
rdar://problem/50696432
2019-05-15 17:31:19 -07:00
Rintaro Ishizaki
14d2f7c0a7 [CodeCompletion] Enable context type analysis for implict member expression
At argument part of implict member expression, we need context type
analysis to complete arguments.

rdar://problem/50696432
2019-05-15 12:34:26 -07:00
Rintaro Ishizaki
7b7c320bd5 [CodeCompletion] Allow ErrorType in constructor
Even if the constructor has `ErrorType` we can suggest it as long as it's
`FunctionType`.

rdar://problem/49480808
2019-05-13 01:32:57 -07:00
Rintaro Ishizaki
558cc6382e Merge pull request #24455 from rintaro/ide-complete-import-swiftmodule
[CodeCompletion] Complete Swift only module name after 'import'
2019-05-08 14:02:34 -07:00
Rintaro Ishizaki
ffde2280c9 [CodeCompletion] Hide 'SwiftOnoneSupport' from module name completion 2019-05-08 10:12:29 -07:00
Rintaro Ishizaki
6956089b0b [CodeCompletion] Complete Swift only module name after 'import'
rdar://problem/39392446
2019-05-08 10:11:52 -07:00
Gwen Mittertreiner
06ac6f4753 Properly Iterate Through RequestedCachedResults
Clearing the cache and the end of the for loop invalidates the interator
and prevents iterating through the rest of the vector. This should be
cleared after we're done iterating.
2019-05-07 17:33:13 -07:00
Ben Langmuir
8f38e4b765 [code-completion] Avoid invalid member substitution for keypath dynamic lookup
When performing keypath dynamic member lookup, avoid substituting the
base type in override detection and completion, as the base type of the
lookup is not the base type of the member. For now, we just avoid the
substitution entirely to fix potential crashes; in a future commit we
will change to using the subscript return type and substituting with the
base type of the subscript instead of the base type of the lookup.

rdar://50449788
2019-05-06 10:02:39 -07:00
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