Commit Graph

1994 Commits

Author SHA1 Message Date
Rintaro Ishizaki
3d80635cf4 [CodeCompletion] Fix completion for local decls in trailing closure
Previously, local decls in trailing closure didn't show up if the
closure had preceding arguments and the completion was triggered at
beginning position of expression context. like:

   funcName(x: arg1) {
      var localVar = 12
      if <HERE>
   }

The completion mode used to be overwritten in 'completeCallArg()' which
is called from 'parseExprCallSuffix(). We should detect completion for
immediate argument position in 'parseExprList()'.

rdar://problem/41869885
2018-10-04 16:56:07 +09:00
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
Jordan Rose
985dbee199 Simplify the integrated REPL code completion a little
Parsing additional declarations from a separate buffer into an
existing SourceFile is definitely a hack, but again, the integrated
REPL is deprecated and does not deserve real attention.
2018-09-25 09:13:52 -07:00
Graydon Hoare
14db5d2285 [AST] Add and use NominalTypeDecl::LookupDirectFlags rather than booleans. 2018-09-21 14:34:26 -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
Joe Groff
93b5de61e7 Implement the final approved syntax for SE-227 identity key paths.
`\.self` is the final chosen syntax. Implement support for this syntax, and remove the stopgap builtin and `WritableKeyPath._identity` property that were in place before.
2018-09-19 11:45:13 -07:00
Jordan Rose
ac4a92a968 Merge pull request #19292 from jrose-apple/get-out-the-map
Minor improvements to the use of StringMap/StringSet
2018-09-14 10:52:59 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Jordan Rose
245b06b832 Use llvm::StringSet instead of StringMap where appropriate
That is, where we aren't using the value for anything.

No functionality change.
2018-09-13 15:15:24 -07:00
Slava Pestov
8801aa67d3 Merge pull request #19133 from slavapestov/access-level-cleanup
Access level cleanup
2018-09-06 16:46:40 -07:00
Xi Ge
24b0eac9a4 Parser: parse members in extension decls incrementally. 2018-09-05 17:00:39 -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
Jordan Rose
2f6b4cdbe8 Merge pull request #19054 from jrose-apple/nocturnal
Honor #sourceLocation filenames in several more places
2018-08-30 13:02:50 -07: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
Jordan Rose
63cd1258ea Stop using SourceManager::getBufferIdentifierForLoc to find buffer IDs
The right way is findBufferContainingLoc. getBufferIdentifierForLoc is
both slower and wrong in the presence of #sourceLocation.

I couldn't come up with a test for the change in IDE/Utils.cpp because
refactoring still seems to be broken around #sourceLocation. I'll file
bugs for that.
2018-08-29 11:46:41 -07:00
Jordan Rose
933bee62da [IDE] Honor #sourceLocation in comment-to-XML conversion 2018-08-29 11:46:41 -07:00
Xi Ge
01ecfdaaf0 IDE: use more efficient API to collect default implementations for protocol members. NFC (#19032) 2018-08-28 18:19:41 -07:00
Slava Pestov
677f500426 TypeReconstruction: Replace FunctionType::getOld() with explicit decomposeInput()
This is not any "better" because we also want to eventually
remove decomposeInput() too. However we're planning on
scrapping TypeReconstruction altogether so its unlikely that
refactoring this to do the right thing will be worth it.

Instead just inline what getOld() does so we can move forward.
2018-08-27 21:15:38 -07:00
Xi Ge
e4388af6be swift-module-digester: refactor the ABI/API diagnostics to use DiagnosticEngine. NFC (#18957)
Before this patch, we used to define tooling-specific diagnostics. With adding more
checking logics, we found this mechanism hard to extend. This patch
eliminates the home-made diagnostics model to use the one from compiler, which provides
several benefits: less boiler-templates, better integration with DiagnosticConsumer,
and easy ordering of detected issues.
2018-08-24 13:11:32 -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
b31bd99313 Merge pull request #18754 from rintaro/ide-rdar41593893
[IDE] Fix a crasher in SynthesizedExtensionAnalyzer
2018-08-18 15:19:14 +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
Slava Pestov
a5ddd53227 Merge pull request #18812 from slavapestov/easy-function-type-conversions
Port almost all remaining FunctionType::get() usages to new representation
2018-08-18 00:11:52 -04: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
Slava Pestov
527ff375dc AST: Rename old form of {Generic,}FunctionType::get() to getOld()
This makes it easier to grep for and eventually remove the
remaining usages.

It also allows you to write FunctionType::get({}, ...) to call the
ArrayRef overload empty parameter list, instead of picking the Type
overload and calling it with an empty Type() value.

While I"m at it, in a few places instead of renaming just clean up
usages where it was completely mechanical to do so.
2018-08-17 19:28:17 -04:00
Slava Pestov
a54251074c AST: ExtInfo just wraps an unsigned integer, no need to pass it by reference 2018-08-17 19:27:43 -04:00
Xi Ge
c069090afe Merge pull request #18788 from brentdax/indigestion
Add some proper diagnostics to the API digester
2018-08-17 15:55:51 -07: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
Brent Royal-Gordon
88ac6f11a2 Add error for invalid SDKNodeKind 2018-08-17 00:27:38 -07:00
Jordan Rose
d6c8ca016b Constify PrintOptions in ShouldPrintChecker::shouldPrint
No functionality change.
2018-08-16 17:59:24 -07:00
Ben Cohen
428c580158 Fix unused variable warnings in release builds. (#18755) 2018-08-16 11:46:45 -06:00
Rintaro Ishizaki
baa690306d [IDE] Fix a crasher in SynthesizedExtensionAnalyzer
Count inheritance by 'getInheritedForPrinting()' (align with ASTPrinter).

rdar://problem/41593893
2018-08-16 20:09:44 +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