Commit Graph

1224 Commits

Author SHA1 Message Date
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
Rintaro Ishizaki
a6f7a8ea35 [Parser] Set local discriminator to ParamDecls
We have to discriminate between params and local variables.
2018-05-11 15:37:40 +09:00
Alex Hoppen
05350cd0bb [libSyntax] Fix parsing of delayed function bodies 2018-04-27 08:10:19 -07:00
Alex Hoppen
94b8a3545b [libSyntax] Fix parsing for KeyPath 2018-04-25 13:30:31 -07:00
Alex Hoppen
3e9ae802c2 [libSyntax] Make parsing of attribute arguments more structured
This also fixes several issues where attribute arguments could not be
parsed as a TokenList since some of its arguments already had structure
and were not tokens
2018-04-24 13:18:15 -07:00
Alex Hoppen
c52f4a8131 [libSyntax] Fix parsing of operators passed to higher order functions 2018-04-23 12:23:27 -07:00
Rintaro Ishizaki
338cedd6d5 [Syntax] Parse '#selector' expression syntax 2018-04-12 13:56:04 +09:00
Xi Ge
3ee5954341 Merge pull request #15653 from rintaro/quickfix-rdar38988444
[code-completion] Fix compiler crash on implicit member expression in string interpolation
2018-04-02 10:03:25 -07:00
Rintaro Ishizaki
7a80547819 [code-completion] Fix compiler crash on implicit member expression in string interpolation
Resetting Lexer to the start of the line result re-tokenizning whole
string literal as a single token, and go past artificial EOF.
This used to end up with assertion failure or infinite-loop in
no-assertion builds.

Quick fix for: rdar://problem/36881302
2018-03-31 16:18:35 +09:00
David Zarzycki
67710606e6 [Parse] Move tok::amp_prefix closer to parameter list logic
The amp_prefix token is currently tolerated in any unary expression
context and then diagnosed later by Sema. This patch changes parsing to
only accept tok::amp_prefix in its allowed position: parameter lists.

This also fixes two "compiler crasher" tests.
2018-03-30 17:56:36 -04:00