Commit Graph

894 Commits

Author SHA1 Message Date
fischertony
d2e7c785bb Create utility function for Associativity spelling 2018-10-04 00:38:20 +03:00
fischertony
e505d417fa [Parse][CodeCompletion] Completions for precedencegroup decls
Added the 'Module::getPrecedenceGroups' API to separate precedence group lookup
from 'Module::lookupVisibleDecls', which together with 'FileUnit::lookupVisibleDecls',
to which the former is forwarded, are expected to look up only 'ValueDecl'. In particular, this
prevents completions like Module.PrecedenceGroup.
2018-10-03 22:12:20 +03:00
Rintaro Ishizaki
e5d8113eee [CodeCompletion] Pre-remove argument labels from function types
Before checking type relation between candidate types and expected
types. In normal compilation, this removal is done in CSGen. However,
since code-completion directly uses Constraint System, we have to
manually remove argument labels before checking convertibility.

We can remove argument labels unconditionally because function types as
as value cannot have argument labels. (i.e. `let f: (a: Int) -> Int` is
illegal). That means, expected types shouldn't have any argument labels.

This fixes regression revealed in 5e75b1ad3b
rdar://problem/41496748
2018-10-01 17:31:20 +09:00
Rintaro Ishizaki
f40c3b19c8 [CodeCompletion] Improve accuracy of unresolved member completion
* Handle generic base types
* Suggest '.some' and '.none' for optional types
* Don't look through too many parameter lists for function types
* Include members with convertible type result

rdar://problem/44803439
2018-09-28 15:36:11 +09:00
Ben Langmuir
cad921d2fd Merge pull request #19567 from benlangmuir/complete-unresolved-optional
[codecomplete] Fix unresolved member completion for T within Optional<T>
2018-09-27 08:51:59 -07:00
Ben Langmuir
4deb2d6de3 [codecomplete] Fix unresolved member completion for T within Optional<T>
We need to look through the optional and find the members of T when
doing completion in Optional<T>.

let x: Foo? = .foo

We still don't correctly complete .some/.none, which requires
reconciling the unbound generic type we get from the decl with the real
bound generic type.

rdar://44767478
2018-09-26 11:52:48 -07:00
Slava Pestov
3b60ae153d AST: Rename AnyFunctionType::Param::getType() to getOldType() 2018-09-26 11:05:23 -07:00
Michael Gottesman
c62f31f5dc Inject llvm::SmallBitVector into namespace swift;
I also eliminated all llvm:: before SmallBitVector in the code base.
2018-09-21 09:49:25 -07:00
Slava Pestov
e520dd613b IDE: Remove hasAccess() checks 2018-09-05 16:51:42 -07:00
Harlan
dc1bc823e6 [InterfaceGen] Remove #ifs from default arguments (#19075)
* [InterfaceGen] Remove #ifs from default args

This patch removes all #if configs form the bodies of default arguments,
which can contain multiline closures, while preserving the bodies of the
clauses that are active.

This code is generalized and should "just work" for inlinable function
bodies, which will come in a later patch.

* Address review comments

* Fix and test CharSourceRange.overlaps

* Fix CharSourceRange::print to respect half-open ranges
2018-08-31 20:18:48 -07:00
Rintaro Ishizaki
4797a7caf6 Merge pull request #18919 from rintaro/ide-complete-pound
[CodeCompletion] Implement completion for # directives
2018-08-31 10:50:40 +09:00
Rintaro Ishizaki
de0599a11b Merge pull request #18884 from rintaro/ide-complete-keypath
[CodeCompletion] Improve completion for Swift keypath expression
2018-08-31 09:44:28 +09:00
Brent Royal-Gordon
9893c392ec [IDE] Correct uninitialized boolean
CompletionLookup::IsStaticMetatype was not explicitly initialized during construction, so it could sometimes have garbage values. This caused UBSan to error out on IDE/complete_enum_elements.swift and IDE/complete_unresolved_members.swift.
2018-08-29 22:53:40 -07:00
Rintaro Ishizaki
deb4aa84e0 [CodeCompletion] Add completion for platform condition
* 'true'/'false' keyword
* 'os(<name>)', 'canImport(<module>)' etc.
* Custom flags specified with '-D'

rdar://problem/19572779
2018-08-24 12:24:54 +09:00
Rintaro Ishizaki
5ef5f5ed84 [CodeCompletion] Implement completion for # directives
rdar://problem/29976235
2018-08-24 12:24:54 +09:00
Rintaro Ishizaki
bce3326840 [CodeCompletion] Rename completeAfterPound() to completeAfterPoundExpr()
Also, `CompletionKind::AfterPound` to `CompletionKind::AfterPoundExpr`.
2018-08-24 11:12:48 +09:00
Rintaro Ishizaki
2052d4bc83 [CodeCompleiton] Enable after '#' completion in arbitrary expr position
Previously, it's enabled only at stmt condition position.
2018-08-24 11:12:48 +09:00
Rintaro Ishizaki
814476ad98 [CodeCompletion] Rename CompletionKind::SwiftKeyPath to KeyPathExprSwift 2018-08-22 11:08:53 +09:00
Rintaro Ishizaki
1ac6afb3cf [CodeCompletion] Improve completion for Swift keypath expression
* Handle completion in 'parseExprKeyPath()' instead of
  'parseExprPostfixSuffix()'.
* Fix a crash for implicit type keypath. e.g. '\.path.<complete>'. (SR-8042).
* Use 'completeExprKeyPath()' callback.
* Implement completion without '.'. e.g. '\Ty.path<complete>'
* Improved handling for 'subscript' in completion.
* Improved handling for optional unwrapping in completion.

https://bugs.swift.org/browse/SR-8042
rdar://problem/41262612
2018-08-22 11:08:53 +09:00
Rintaro Ishizaki
8467203b9e [CodeCompletion][NFC] Tweak completion for ObjC keyPath expression
* Consolidate CompletionKind::KeyPathExpr and CompletionKind::KeyPathExprDot
  to CompletionKind::KeyPathExprObjC
* Make completeKeyPath() to receive DotLoc.
2018-08-22 11:08:53 +09:00
Rintaro Ishizaki
36ee937412 Merge pull request #18786 from rintaro/parse-istypecontext
[Parse] Don't use getAsNominalTypeOrNominalTypeExtensionContext in Parse
2018-08-18 15:41:07 +09:00
Rintaro Ishizaki
32da3c3cf2 Merge pull request #18787 from rintaro/ide-complete-declintro
[CodeCompletion] Don't suggest keywords after decl introducer
2018-08-18 15:17:27 +09:00
Rintaro Ishizaki
682fc12c39 [Parse] Don't use getAsNominalTypeOrNominalTypeExtensionContext in Parse
`getAsNominalTypeOrNominalTypeExtensionContext()` requires fully parsed
AST. Use `isTypeContext()` instead.

https://bugs.swift.org/browse/SR-8554
rdar://problem/43394866
2018-08-18 12:48:13 +09:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Rintaro Ishizaki
70fba3f38d [CodeCompletion] Don't suggest keywords after decl introducer
If any decl introducers (e.g. 'func', 'let', 'typealias', etc.) are
included in parsed keywords, don't emit any keywords in completion.
2018-08-17 19:54:31 +09:00
Rintaro Ishizaki
5753e122cf Merge pull request #18721 from rintaro/ide-rdar41224316
[CodeCompletion] Remove unresolved type in prepareForRetypechecking()
2018-08-16 15:46:51 +09:00
Rintaro Ishizaki
c68157a27d [CodeCompletion] Remove unresolved type in prepareForRetypechecking()
Unresolved type attached to expressions may fail re-typechecking.
Also, disallow unresolved type in typeCheckCompletionSequence(). It doesn't
provide useful completions to developers.

rdar://problem/41224316
2018-08-15 20:39:12 +09:00
Doug Gregor
58d60e268f [Code completion] Delete redundant code handling declarations.
A significant chunk of the handling for LookupKind::ValueExpr
was duplicated in the handling for the ValueInDeclContext and
ImportFromModule cases. Use a fall through to unify the
code paths here.
2018-08-14 08:31:01 -07:00
Slava Pestov
31a570d53c AST: Replace TypeBase::getRValueInstanceType() with getMetatypeInstanceType()
That is, don't look through InOutType anymore, and update callers to
call getInOutObjectType() as well (or not, where it was obvious to me
that InOutType could not appear).

This surfaces more remaining uses of getInOutObjectType() directly.
2018-08-13 21:13:10 -07:00
Rintaro Ishizaki
aac92da252 [CodeCompletion] Completion for UnresolvedMember via CodeCompletionExpr
Using dummy UnresolvedMemberExpr doesn't give us much benefit. Instead, use
CodeCompletionExpr which is type checked as type variable so can use
CodeCompletionTypeContextAnalyzer to infer context types.
This way, we can eliminate most of special logic for UnresolvedMember.

rdar://problem/39098974
2018-08-10 22:23:23 +09:00
Rintaro Ishizaki
254be25f4d Merge pull request #18564 from rintaro/ide-completion-contextanalysis
[CodeCompletion] Improve context type analysis
2018-08-10 10:53:44 +09:00
Rintaro Ishizaki
31f0f28236 [CodeCompletion] Guard for null interface type in calculateTypeRelationForDecl (#18591)
Fixes a crash.

https://bugs.swift.org/browse/SR-8470
rdar://problem/43057054
2018-08-10 10:51:45 +09:00
Rintaro Ishizaki
137ca6551b [CodeCompletion] Simplify getPositionInArgs()
* Don't need to look for CodeCompletionExpr. It's wrong anyway because
  what we are looking for is not neccessarily a 'CodeCompletionExpr'.
* Use getElementLoc(i).isValid() instead of !getElementName(i).empty().
  Just in case users write '_:' for call argument.
* Don't suggest argument labels for implicit call expression. For
  instance, string interpolation segments.
2018-08-09 19:49:43 +09:00
Rintaro Ishizaki
18582d3406 [CodeCompletion] Handle ExprPattern in context type analysis
This improves type inference for code completion in argument position of
EnumElementPattern.
2018-08-09 19:49:25 +09:00
Rintaro Ishizaki
c01eb93e9a [CodeCompletion][NFC] Use ASTWalker::ParentTy instead of ASTNode
in 'ExprParentFinder'. There's no reason to re-pack into ASTNode.
2018-08-09 19:48:23 +09:00
Rintaro Ishizaki
d898f6d664 [CodeCompletetion] Handle binary/unary expression in context type analyzer
Don't discard parsed expression in Parser. This improves type inference
for CodeCompletionExpr.
2018-08-09 19:48:23 +09:00
Rintaro Ishizaki
0dfbf76354 [CodeCompletion] Improve getReturnTypeFromContext()
* For methods, un-curry function interface type so we can get declared
return type.
* For closures, fall back to getting explicit result type in case we
cannot retrieve it from the type of closure itself.
2018-08-09 19:48:16 +09:00
Rintaro Ishizaki
4e1147df04 [IDE][gardening] Inline getPositionInTupleExpr() 2018-08-07 12:57:14 +09:00
Rintaro Ishizaki
f04be1457c [IDE][gardening] Inline overloaded collectArgumentExpectation 2018-08-07 12:57:14 +09:00
Rintaro Ishizaki
733e96b877 [IDE][gardening] Refactoring around collectArgumentExpectation() 2018-08-07 11:43:05 +09:00
Rintaro Ishizaki
46d418f232 [IDE][gardening] Factor out getPositionInArgs()
This function get the index of specified expression in the arguments.
2018-08-07 11:43:05 +09:00
Rintaro Ishizaki
81cae7309d [IDE][gardening] Rename collectionInputTypes()
To 'collectPossibleParamLists()'.
2018-08-07 11:43:05 +09:00
Rintaro Ishizaki
6088b794a8 [IDE][gardening] Removed unused function
The last usage have been removed in
c0f5711ee5.
2018-08-07 10:42:54 +09:00
Doug Gregor
3018becde7 [Type checker] Eliminate type checking from early extension binding.
Use ExtensionDecl::getExtendedNominal() to wire up extensions to their
nominal types early in type checking (the bindExtensions()) operation,
rather than going through type validation to do so.
2018-08-03 11:26:49 -07:00
Doug Gregor
792d934e3e [Clang importer] Avoid recursion through isObjC more directly.
Also address some review comments related to the name lookup requests.
2018-07-31 10:20:15 -07:00
Doug Gregor
d07fa5ab69 Switch many callers of ClassDecl::getSuperclass() to ClassDecl::getSuperclassDecl().
ClassDecl::getSuperclass() produces a complete interface type describing the
superclass of a class, including any generic arguments (for a generic type).
Most callers only need the referenced ClassDecl, which is (now) cheaper
to compute: switch those callers over to ClassDecl::getSuperclassDecl().

Fixes an existing test for SR-5993.
2018-07-31 10:14:44 -07:00
Pavel Yaskevich
0a404529c3 [Sema] Adjust Diagnostics/IDE to not assume that parameters always have types 2018-07-28 20:28:41 -07:00
Rintaro Ishizaki
9e7fa99689 [CodeComplete] Use PrintOptionalAsImplicitlyUnwrapped to print IUO
Other instances of fb9c65e. Consistently use
PrintOption.PrintOptionalAsImplicitlyUnwrapped to print IUO.

rdar://problem/41046225
rdar://problem/42443512
2018-07-26 07:55:25 +09:00
Rintaro Ishizaki
0547f1bcdc Merge pull request #18209 from rintaro/ide-compilation-rdar42452085
[CodeComplete] Strip out try and optional eval expo in operator completion
2018-07-26 07:52:19 +09:00
swift-ci
e9cb62d476 Merge pull request #17987 from brentdax/youll-get-no-argument 2018-07-24 23:39:05 -07:00