Commit Graph

510 Commits

Author SHA1 Message Date
Frederick Kellison-Linn
71697c37ca Allow implicit self in escaping closures when self usage is unlikely to cause cycle (#23934)
* WIP implementation

* Cleanup implementation

* Install backedge rather than storing array reference

* Add diagnostics

* Add missing parameter to ResultFinderForTypeContext constructor

* Fix tests for correct fix-it language

* Change to solution without backedge, change lookup behavior

* Improve diagnostics for weak captures and captures under different names

* Remove ghosts of implementations past

* Address review comments

* Reorder member variable initialization

* Fix typos

* Exclude value types from explicit self requirements

* Add tests

* Add implementation for AST lookup

* Add tests

* Begin addressing review comments

* Re-enable AST scope lookup

* Add fixme

* Pull fix-its into a separate function

* Remove capturedSelfContext tracking from type property initializers

* Add const specifiers to arguments

* Address review comments

* Fix string literals

* Refactor implicit self diagnostics

* Add comment

* Remove trailing whitespace

* Add tests for capture list across multiple lines

* Add additional test

* Fix typo

* Remove use of ?: to fix linux build

* Remove second use of ?:

* Rework logic for finding nested self contexts
2019-12-20 02:38:41 +00:00
Rintaro Ishizaki
8edea315cd [Syntax] Abolish 'backtick' trivia
- Stop producing 'backtick' trivia for escaping identifier token. '`'s
  are now parts of the token text
- Adjust and simplify C++ libSyntax APIs
- Add 'is_deprecated' property to Trivia.py to attribute SwiftSyntax
  APIs

rdar://problem/54810608
2019-09-09 11:49:25 -07:00
Rintaro Ishizaki
cb308b7e53 Revert "Revert "[Parser] Decouple the parser from AST creation (part 2)""
This reverts commit 8ad3cc8a82.
2019-08-27 14:36:41 -07:00
Rintaro Ishizaki
8ad3cc8a82 Revert "[Parser] Decouple the parser from AST creation (part 2)" 2019-08-27 12:28:48 -07:00
Jan Svoboda
8da82d3272 Revert Lexer UTF8 replacement char changes 2019-08-26 23:15:45 +02:00
Rintaro Ishizaki
ad5b8253e3 [Lexer] Don't lex trailing trivia for eof (including artificial eof) 2019-08-26 22:37:20 +02:00
Jan Svoboda
77924c4b84 [Parser] Decouple the parser from AST creation (part 2)
Instead of creating the AST directly in the parser (and libSyntax or
SwiftSyntax via SyntaxParsingContext), make Parser to explicitly create
a tree of ParsedSyntaxNodes. Their OpaqueSyntaxNodes can be either
libSyntax or SwiftSyntax. If AST is needed, it can be generated from the
libSyntax tree.
2019-08-26 19:10:51 +02:00
Doug Gregor
7f293f66b3 [Parser] Allow use of $ declarations in all modes.
Allow the use of declarations whose names start with $ in all
modes. However, normal code cannot define new entities with names that
start with $: only the implementation can do that, e.g., for property
delegates.
2019-04-23 11:31:58 -07:00
Davide Italiano
49b2f4eba7 [DebuggerSupport] Unbreak closures in the expression parser.
The new trick is that of leavign an unresolved identifier for
the expression parser to fill in.

<rdar://problem/47982630>
2019-02-12 16:36:47 -08:00
Harlan Haskins
b81c491d3d [Lexer] Allow $-prefixed identifiers for parseable interfaces
We’re printing a new name for lazy storage in parseable interfaces,
`$__lazy_storage_$_{propname}`. This is intentionally $-prefixed so it cannot
conflict with variables written in source, but it doesn’t use a `.` anymore
because parseable interfaces need to be...parseable.
2019-01-22 11:02:36 -08:00
Harlan Haskins
f5fc6f0c57 [Lexer] Handle SwiftInterface files as well as SIL
Previously, the Lexer kept a single flag whether we’re lexing Swift or SIL. Instead, keep track if we’re parsing Swift, SIL, or a Swiftinterface file. .swiftinterface files allow $-prefixed identifiers anywhere.
2019-01-22 11:02:36 -08:00
Argyrios Kyrtzidis
c7ac859310 [Parse] Optimize syntax parsing: Speed-up Lexer::lexTrivia()
Introduce ParsedTrivia which is a more efficient structure to use during lexing than syntax::Trivia.
2019-01-17 12:10:27 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Rintaro Ishizaki
56ce86178c [CodeCompletion] Eat identifier characters after CC position
Text on editors (e.g. Xcode) may contain identifiers following to CC
position which should be considered as "filtering text" for the code
completion.

For example, a user types '@a' the CC position is between '@' and 'a'.
The user probably expects attributes starting with 'a'.

Eat identifier characters after CC token in Lexer. By this change,
for instance for '@<token>IB class', the parser now can detect this
is a start of class declaration and emit class attributes completions.

rdar://problem/46103294
2018-12-04 08:29:26 +09:00
Rintaro Ishizaki
4f058028b7 [Lexer] Micro optimization for getTokenAt()
lex() invokes lexImpl(). It doesn't need to lex next token.
2018-11-02 12:03:54 +09:00
Davide Italiano
3b96d21a2c Merge pull request #19808 from apple/bananaphone
[Lexer] Allow '$x' to be parsed as identifier in debugger mode.
2018-10-10 14:16:46 -07:00
Davide Italiano
2af9a1dc7f [Lexer] Allow '$x' to be parsed as identifier in debugger mode.
This is needed to support `print $0` in lldb where `$0` is the
shortcut for a closure argument. The associated lldb change
will be merged together with this one and will contain a test.

<rdar://problem/201719448>
2018-10-09 15:00:10 -07:00
Rintaro Ishizaki
8f7254d722 [Lexer] Skip comments in interpolated expression in string literal
when skipping to the end of the interpolated expression.
i.e. Skip the comment as a comment.

Previously, ')' or '"' in comment in interpolated expression used to
cause assertion failure or mis-compilation in no-assert build.

rdar://problem/20289969
2018-10-09 09:35:50 +09:00
Rintaro Ishizaki
a0ebdbc089 [Lexer] Fix assertion failure for unterminated string literal
in string interpolation in multiline string literal.

    """
    \("<-this is unterminated.
    """

In this case, the outer multiline literal should form 'tok::unknown'
along with a error message.
2018-09-22 02:09:19 +09:00
Rintaro Ishizaki
a5759b73b5 [Lexer] Improve fix-it to remove "too long" delimiter in string literal
Fix-it to remove extra '#'s at once.
2018-09-19 18:58:54 +09:00
Rintaro Ishizaki
aaa4110a7c [Lexer] Factor out diagnostics for single-quoted string literal
For readability.
2018-09-19 18:58:54 +09:00
Rintaro Ishizaki
7b701d57d3 [Lexer] Improve diagnostics for single-quote string literal
Ignore the contents of interpolation.
2018-09-19 18:58:54 +09:00
Rintaro Ishizaki
e6e55c23e1 [Lexer] Code tweaks in lexStringLiteral()
NFC. Reorder code to improve readability.
2018-09-19 18:58:54 +09:00
Rintaro Ishizaki
1a4d37597f [Lexer] Remove unnecessary logic from lexCharacter
EOF and newline (in non-multiline string literal) must be handled by
call site. lexCharacter doesn't need to handle them. Added assertion
instead.
2018-09-19 18:58:54 +09:00
Rintaro Ishizaki
ba5172738c [Lexer] Advance pointer to the end of end-quote in lexCharacter
This simplifies main lexStringLiteral loop
2018-09-19 18:58:54 +09:00
Rintaro Ishizaki
893524ea77 [Lexer] Add assertion in advanceIfCustomDelimiter()
CurPtr[-1] must be '#' when called.
2018-09-19 18:58:54 +09:00
Rintaro Ishizaki
4536e69dd6 [Lexer] Don't emit diagnostics in skipToEndOfInterpolatedExpression()
Removed Diags parameter from it.
Skipped bytes are revisited by main lexer function anyway. So emitting
diagnostics in it causes duplicated errors.
2018-09-19 18:58:54 +09:00
Rintaro Ishizaki
c9c69633c4 [Lexer] Simplify handling quotes in skipToEndOfInterpolatedExpression()
NFC
2018-09-19 18:58:54 +09:00
Rintaro Ishizaki
0e9b232755 [Lexer] Fix double diagnostics for unterminated string literal
We should not emit diagnostics in skipToEndOfInterpolatedExpression()
2018-09-19 18:58:54 +09:00
Rintaro Ishizaki
143f55a6e5 [Lexer] Add formStringLiteralToken dedicated for forming string literal 2018-09-19 18:58:54 +09:00
John Holdsworth
7ae5a7af6a Point link to Zero-width Jira (#19364) 2018-09-18 23:36:32 +09:00
John Holdsworth
e55d4254d2 [Parse] Allow multiline attribute messages (SE-200) (#19219)
Multiline string literal at attribute message position was disallowed in
59778f8ecb.

Reworked to try to at least get multiline strings working which might be
useful as messages for attributes (for example a detailed “unavailable”
annotation) minus the code which read off the start of the StringRef buffer.
2018-09-14 10:33:32 +09:00
Jordan Rose
e180bf9d4e [Parse] Tweak a utility function that relies on reading past the end (#19230)
Lexer::getEncodedStringSegment (now getEncodedStringSegmentImpl)
assumes that it can read one byte past the end of a string segment in
order to avoid bounds-checks on things like "is this a \r\n
sequence?". However, the function was being used for strings that did
not come from source where this assumption was not always valid.
Change the reusable form of the function to always copy into a
temporary buffer, allowing the fast path to continue to be used for
normal parsing.

Caught by ASan!

rdar://problem/44306756
2018-09-11 20:11:58 -07:00
Rintaro Ishizaki
59778f8ecb [Parse] Disable support for multiline/extended escaping string literal
in attribute message

Strings of diagnostics message processed in EncodedDiagnosticMessage
aren't necessarily from parsed Swift source code. That means, they might
not have quotes around it. Furthermore, memory around them might not be
managed. The logic in 'Lexer::getEncodedStringSegment()' used to cause
access violation.

For now, disable multiline string literal and extended escaping in string
literal for attribute message position. Considering the message might be
from Clang, we cannot simply enable this.

rdar://problem/44228891
2018-09-08 17:32:36 +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
9208c5bca6 Final nits in comments. 2018-09-06 14:20:19 +01:00
John Holdsworth
f0f08e1e86 Remove zero width detection for now 2018-09-05 21:51:19 +01:00
John Holdsworth
999bb40294 New diagnostic for closing delimiter 2018-09-04 20:21:20 +01:00
John Holdsworth
02f7cd5db6 generated zero-width characters 2018-09-02 23:59:34 +01:00
John Holdsworth
dc96342368 Response to xwu's review 2018-09-02 11:37:02 +01:00
John Holdsworth
3fc43bcb80 Check for zero-width characters in delimiters 2018-09-01 21:54:54 +01:00
John Holdsworth
032d865fa1 Response to rintaro's 2nd review 2018-08-31 18:51:37 +01: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
John Holdsworth
9691076af0 Response to rintaro's review 2018-08-27 19:14:26 +01:00
John Holdsworth
4209b72a66 Delimiter specific diagnostic 2018-08-27 10:15:50 +01:00
John Holdsworth
6bd7cb884c Pragmatic support of multiline/delimited in attributes 2018-08-20 08:43:53 +01:00
John Holdsworth
7866093ea5 Extend token boundary to include delimiter 2018-08-17 02:12:01 +01:00
Alex Hoppen
ac512d4341 [libSyntax] Add a reference counted version of OwnedString
We cannot use unowned strings for token texts of incrementally parsed
syntax trees since the source buffer to which reused nodes refer will
have been freed for reused nodes. Always copying the token text whenever
OwnedString is passed is too expensive. A reference counted copy of the
string allows us to keep the token's string alive across incremental
parses while eliminating unnecessary copies.
2018-08-13 15:37:53 -07:00