Commit Graph

1233 Commits

Author SHA1 Message Date
Rintaro Ishizaki
797761adae [CodeCompletion] Try to parse complete expression after CC token
Type may depend on its suffix. Parsing complete expression including its
suffix improves context type info around the CC token.

rdar://problem/44143964
2018-10-16 06:08:29 +09:00
Christopher Ian Stern
469a0f3eb0 fix stack overflow on deeply nested parens [SR-4866] (#19631)
Make sure StructureMarkerRAII checks structure nesting level on all paths.  Previously swift crashed with  no diagnostic on deeply nested '('. Now we print an error when more than 256 parens deep, just as we always have for '['.

fixes SR-4866
2018-10-10 13:42:18 +09:00
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
John Holdsworth
4da8cbe655 Implement SE-0200 (extended escaping in string literals)
Supports string literals like #"foo"\n"bar"#.
2018-09-06 15:19:52 -07:00
Brent Royal-Gordon
df22ea1bfb Revert "[Parse] Implementation for SE-200 (raw strings)" 2018-09-06 12:22:41 -07:00
swift-ci
192587c98a Merge pull request #17668 from johnno1962a/master 2018-09-06 11:47:36 -07:00
John Holdsworth
dc96342368 Response to xwu's review 2018-09-02 11:37:02 +01: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
Alex Hoppen
66374a14ea [libSyntax] Make RawSyntax nodes hold a strong reference to their arena
This allows an elegant design in which we can still allocate RawSyntax
nodes using a bump allocator but are able to automatically free that
buffer once the last RawSyntax node within that buffer is freed.

This also resolves a memory leak of RawSyntax nodes that was caused by
ParserUnit not freeing its underlying ASTContext.
2018-08-24 08:39:54 -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
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
1155adeef1 [Parse] Remove special handling for .<keyword><code-complete> (#18869)
At the time this logic was introduced in 8f83ca67, `<expr>.<keyword>` wasn't
allowed. Now that SE-0071 has been implemented, this logic doesn't provide any
positive effects.
2018-08-22 13:37:08 +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
Alex Hoppen
cc4cc4cb27 [libSyntax] Fix places in which RawSyntax nodes were created without an arena 2018-08-21 15:30:04 -07:00
Rintaro Ishizaki
5e001f1913 Merge pull request #18626 from rintaro/ide-completion-unresolved-refactor
[CodeCompletion] Completion for UnresolvedMember via CodeCompletionExpr
2018-08-11 09:10:28 +09:00
Slava Pestov
4b258e86e6 AST: Stop setting contextual types on ParamDecls
VarDecl::getType() lazily maps the interface type into context if needed.
2018-08-10 13:33:12 -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
Argyrios Kyrtzidis
a6fd08226e Merge pull request #18616 from akyrtzi/input-complete-invalid-interpolation
[parser] Make corrections for the isInputIncomplete() functionality
2018-08-09 18:46:21 -07:00
Argyrios Kyrtzidis
1f117b4848 [parser] Make sure the isInputIncomplete() function works as expected for multi-line strings 2018-08-09 17:30:49 -07: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
swift-ci
101bd5055e Merge remote-tracking branch 'origin/master' into master-next 2018-08-02 12:49:55 -07:00
Doug Gregor
9a9b4af4c7 [Parser] Remove custom diagnostic that relies on AST-level name lookup.
The parser was using an AST-level name lookup operation to provide a
slightly improved diagnostic (suggesting "self." if there was a member
of that name in the enclosing type context). This is a fairly unfortunate
layering violation: name lookup cannot produce correct results at this
point. Remove the custom diagnostic and the lookup; this can come back
when all lookup moves out of the parser.
2018-08-02 09:33:50 -07:00
swift-ci
506def6dc1 Merge remote-tracking branch 'origin/master' into master-next 2018-08-01 09:49:54 -07:00
Argyrios Kyrtzidis
a061077bd8 [Parser] Keep source location info for the ownership keywords inside a closure capture list (#18432)
* [Parser] Keep source location info for the ownership keywords inside a closure capture list

This allows to do syntax coloring for 'weak'/'unowned' inside a capture list
rdar://42655051
2018-08-01 09:39:20 -07:00
swift-ci
b3f2a1a819 Merge remote-tracking branch 'origin/master' into master-next 2018-08-01 08:29:47 -07:00
Rintaro Ishizaki
203a253687 [Parse/Migrator] Drop Swift3 migration support for type(of:) (#17932)
In Swift3, shadowning type(of:) was impossible, because it was a parser
magic. In Swift4, type(of:) is resolved as normal function in stdlib so
it can be shadowed. 'TypeOfMigratorPass' was a targeted migrator pass
that prepend 'Swift.' to 'type(of:)' so that it refers Swift.type(of:)
stdlib builtin function.
2018-08-01 08:22:28 -07:00
swift-ci
685b007c3f Merge remote-tracking branch 'origin/master' into master-next 2018-07-23 20:39:45 -07:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
swift-ci
196b29576c Merge remote-tracking branch 'origin/master' into master-next 2018-07-10 10:09:26 -07:00
Xi Ge
fd6b5941dd libSyntax: rename SyntaxParsingContext.setDiscard() to SyntaxParsingContext.setBackTracking(). NFC 2018-07-09 14:02:26 -07:00
swift-ci
ed21529b6f Merge remote-tracking branch 'origin/master' into master-next 2018-07-06 10:48:57 -07:00
Hamish Knight
c66e68fb93 [Parse][Sema] Emit immediate deallocation warning on the '=' token for PBDs (#17700)
Pass through the location of the equal '=' token for pattern binding decl entries, and use this location for the immediate deallocation diagnostic. Previously, we were just diagnosing on the start of the initialiser expression.

Additionally, this commit moves the call to `diagnoseUnownedImmediateDeallocation` from `typeCheckBinding` to `typeCheckPatternBinding`. This not only gives us easier access to the PBD entry, but also avoids calling the diagnostic logic for statement conditions such as `if let x = <expr>`. We currently never diagnose on these anyway, as the 'weak' and 'unowned' keywords cannot be applied to such bindings.

Resolves [SR-7340](https://bugs.swift.org/browse/SR-7340).
2018-07-06 10:47:49 -07:00
swift-ci
d9df1cdd29 Merge remote-tracking branch 'origin/master' into master-next 2018-07-03 11:08:56 -07:00
Pavel Yaskevich
2f07663265 [Parser] {pre,post}fix operator calls with tuple arguments should implicit parens 2018-07-02 08:56:45 -07:00
Pavel Yaskevich
2ce5ae34c1 [Parser] Make sure to add implicit parens to call for prefix/postfix operators when needed
Currently when call involving prefix/postfix operator is formed we
don't wrap argument in implicit parens (like we do with other calls)
when user didn't provide any explicitly, this is bad because
argument-to-parameter matcher requires multiple special cases to handle
such behavior, so let's start wrapping arguments in implicit parens instead.

Resolves: rdar://problem/40722855
Resolves: [SR-7840](https://bugs.swift.org/browse/SR-7840)
2018-07-02 06:07:15 -07:00
swift-ci
23d51dd4fb Merge remote-tracking branch 'origin/master' into master-next 2018-06-18 16:08:52 -07:00
Brent Royal-Gordon
27dfa51be5 Wrap interpolated tuples in parens
Keeps them from being interpreted as parameter lists. Fixes SR-7958.
2018-06-13 22:55:48 -07:00
swift-ci
3317671848 Merge remote-tracking branch 'origin/master' into master-next 2018-06-13 17:29:07 -07:00
Robert Widmann
dfe42d2e55 Revert "Reject bad string interpolations (#17074)"
This reverts commit fc23f3404d.
2018-06-13 15:06:33 -07:00
swift-ci
346d31c16e Merge remote-tracking branch 'origin/master' into master-next 2018-06-12 18:49:16 -07:00
Brent Royal-Gordon
fc23f3404d Reject bad string interpolations (#17074)
* Reject bad string interpolations

String interpolations with multiple comma-separate expressions or argument labels were being incorrectly accepted.

* Tweak error name to match message

* Diagnose empty interpolations more clearly

* Don’t double-diagnose parse errors

Fixes a test at Parse/recovery.swift:799 which the previous commit broke.

* Fix incorrect test RUN: line

A previous version of this test used FileCheck instead of -verify, and the run line wasn’t properly corrected to use -verify.

* Update comment

* Add more argument label tests

Ensures that we don’t get different results from an initializer that doesn’t exist or doesn’t take a String.

* Resolve the SR-7958 crasher test

We now diagnose the error and remove the label before it has an opportunity to crash.
2018-06-12 18:46:52 -07:00
Bob Wilson
c3e02955bb [master-next] Adjust for VersionTuple moving from clang to llvm.
LLVM r334399 (and related Clang changes) moved clang::VersionTuple to
llvm::VersionTuple. Update Swift to match.

Patch by Jason Molenda.
rdar://problem/41025046
2018-06-12 16:44:11 -07:00
Pavel Yaskevich
82025f8e2d [Parse] Don't try to diagnose extraneous & while parsing
Trying to diagnose extraneous use of `&` in parser is too early
and affects some valid cases like patterns in `case` statements,
where we still want to allow use of `&`.
2018-06-08 20:14:45 -07:00
Rintaro Ishizaki
c83917ce07 Merge pull request #16763 from rintaro/parse-type-argumentlabel
[Parse] Parse label in tuple type as tok::identifier
2018-05-23 09:22:34 +09:00
Alex Hoppen
082086c687 [libSyntax] Fix parsing of StringLiterals with invalid interpolation segments 2018-05-22 08:52:40 -07:00
Rintaro Ishizaki
4a247efc0a [Parse] Parse label in tuple type as tok::identifier
Made an utility method 'consumeArgumentLabel', and use it for:
* Labels in tuple type
* Labels in tuple expression
* Argument and parameter names in parameter clause
2018-05-22 13:46:42 +09:00