Commit Graph

47 Commits

Author SHA1 Message Date
Alex Hoppen
2abea17187 [libSyntax] Add a dumpStack method to SyntaxParsingContext
This function walks the stack of `SyntaxParsingContext`s and dumps their kind. Useful for debugging.
2021-05-04 14:53:10 +02:00
Alex Hoppen
ab7c51b9e2 [libSyntax] Improve data structure in RawSyntax
It turns out that the bitpacked Commons struct is actually fairly expensive because the CPU needs to apply bitmasks to fetch the IsToken and Presence flag. We've got padding space available, so we might as well properly align these boolean flags.

Also on a source level, replace a couple of bit-restricted unsigned fields by their representing type (e.g. SyntaxKind).

Finally, we can pull out the common bits to RawSyntax and have the Bits union only contain the token- or layout-specific fields.
This also allows us to initialise these fields in the constructor's initialiser list (instead of in the initialiser body).

Lastly, change copyToArenaIfNecessary to work on a char *& and length, which allows us to initialise leading/trailing trivia/token text in the initialiser list and adjust if necessary later.
2021-03-11 07:56:47 +01:00
Alex Hoppen
efb91f70a1 [libSyntax] Handle deferred node data in SyntaxParseActions
By now ParsedRawSyntaxNode does not have any knowledge about deferred
node data anymore, which frees up SyntaxParseActions (and, in
particular its sublass SyntaxTreeCreator) to perform optimisations to
more efficiently create and record deferred nodes.
2021-03-09 14:26:08 +01:00
Alex Hoppen
648edaadbe [libSyntax] Mark parameters that are always passed with move semantics as move-types 2021-02-10 12:16:48 +01:00
Alex Hoppen
08ad703553 [Lexer] Push trivia piece lexing down to SyntaxParsingContext
This is again a transitional state before SyntaxParsingContext hands
the responsibility over to SyntaxTreeCreator and from there to
SyntaxParseActions.
2021-02-05 08:15:54 +01:00
Alex Hoppen
c27a96cc1a [syntax-parse] Make the SyntaxParsingContext move-only 2020-12-16 12:35:39 +01:00
Argyrios Kyrtzidis
6bfde00934 [Parser/libSyntax] For accessor parsing only backtrack until the accessor introducer
Previously it was backtracking for the duration of the whole property body which was preventing re-use of previously parsed nodes for incremental re-parsing.
2020-05-09 20:23:41 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Rintaro Ishizaki
aeec682c90 [SyntaxParse] Prevent memory leak in Syntax parsing
Essentially re-applying b09f87594a
2019-10-15 16:27:32 -07:00
Rintaro Ishizaki
8a03e08966 Revert "Merge pull request #26403 from rintaro/gsoc-2019-part1"
This reverts commit 1a211e6e5f, reversing
changes made to 482d0621a6.
2019-10-14 15:18:05 -07:00
Rintaro Ishizaki
570ed9361f Revert "Merge pull request #26883 from rintaro/revert-revert-26478-gsoc-2019-parser-types"
This reverts commit faaa3a859d, reversing
changes made to 62f947d6ba.
2019-10-14 15:18:05 -07:00
Rintaro Ishizaki
00613db8db Revert "Merge pull request #27230 from rintaro/syntaxparsse-rdar55421369"
This reverts commit b09f87594a, reversing
changes made to d0b7ecab00.
2019-10-14 12:47:23 -07:00
Rintaro Ishizaki
fbc7c6c1c5 Revert "Merge pull request #27416 from rintaro/syntaxparse-declassociatedtype"
This reverts commit 5726179da9, reversing
changes made to d5adbe2c55.
2019-10-14 12:19:53 -07:00
Rintaro Ishizaki
9eb4c216ee Revert "Revert "[SyntaxParse] Parse associatedtype decl""
This reverts commit 859f90afc1.
2019-09-27 23:52:39 -07:00
Rintaro Ishizaki
859f90afc1 Revert "[SyntaxParse] Parse associatedtype decl" 2019-09-25 11:00:21 -07:00
Rintaro Ishizaki
fc8a2e6f86 [SyntaxParse] Parse associatedtype decl
Along with inheritance clause.
2019-09-24 12:03:06 -07:00
Rintaro Ishizaki
4527711c52 [SyntaxParses] Address memory issue in popTokenSyntax()
Don't return reference for local temporary object

rdar://problem/55421369
2019-09-17 22:24:17 -07:00
Rintaro Ishizaki
9f642f0bc1 Revert "Merge pull request #27203 from CodaFi/movin-on-up"
This reverts commit 387d2a9aee, reversing
changes made to bf1ab6c29d.
2019-09-17 16:42:44 -07:00
Robert Widmann
d8aaf29617 Revert "Merge pull request #27132 from rintaro/syntaxparse-parsedrawsyntax-moveonly"
This reverts commit e675c4947d, reversing
changes made to 73315ba01e.
2019-09-16 15:10:33 -07:00
Robert Widmann
6dc63e21e9 Revert "Merge pull request #27190 from compnerd/27132"
This reverts commit 4838791937, reversing
changes made to 4c3f044a46.
2019-09-16 15:08:46 -07:00
Saleem Abdulrasool
15dc24ee2d Parse: repair build after #27132
The type deduction here will copy the returned ParsedTypeSyntax which
is no longer copy constructible. Use a reference to hold the result
instead which should fix the build on Windows.  The returned value of
the `popToken` returns a `ParsedTokenSyntax` which is no longer copy
constructible.  Explicitly move the value.
2019-09-13 22:29:25 -07:00
Rintaro Ishizaki
80085e0d27 [SyntaxParse] Make ParsedRawSyntaxNode move-only
So that we can easily detect 'ParsedSyntaxNode' leaking. When it's
moved, the original node become "null" node. In the destructor of
'ParsedSyntaxNode', assert the node is not "recorded" node.
2019-09-11 16:33:49 -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
Rintaro Ishizaki
3f4a4c0e2f [SyntaxParse] Don't record tokens while skipping 2019-08-26 19:10:51 +02:00
Rintaro Ishizaki
1551db619e [SyntaxParse] Support kindof() in isTopNode() 2019-08-26 19:10:51 +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
kitasuke
c8dcbfcfef Fix example doc of SyntaxParsingContext 2019-08-05 14:18:57 +09:00
Rintaro Ishizaki
94f0c14675 [SyntaxParse] Return dedicated pointer from HiddenLibSyntaxAction
SyntaxParseActions::recordToken() et al. may return the same pointer
value for different nodes (e.g. `nullptr`). So we cannot use DenseMap to
associate the node from the explicit syntax parsing actions to libSyntax
node. Instead, use a structure that wraps them.
2019-07-31 16:14:32 -07:00
Jan Svoboda
f0395a469a Revert "Revert "[Parser] Decouple the parser from AST creation (part 1)"" 2019-07-30 04:34:09 +00:00
Brent Royal-Gordon
c66a8be4eb Revert "[Parser] Decouple the parser from AST creation (part 1)" 2019-07-09 14:07:43 -07:00
Jan Svoboda
44d7769238 [Parser] Decouple the parser from AST creation (part 1)
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-06-28 14:28:19 +02:00
Argyrios Kyrtzidis
57c1f72cc3 [Parse] Optimize syntax parsing: Make ParsedRawSyntaxNode a POD type
This eliminates the overhead of ParsedRawSyntaxNode needing to do memory management.
If ParsedRawSyntaxNode needs to point to some data the memory is allocated from a bump allocator.

There are also some improvements on how the ParsedSyntaxBuilders work.
2019-01-17 12:17:28 -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
Argyrios Kyrtzidis
da6de4b095 Address PR feedback
* Add and improve documentation comments
* Adjust formatting
* Rename recordExactRawSyntax -> rec.recordRawSyntax
2019-01-07 19:56:37 -08:00
Argyrios Kyrtzidis
1f1eab638f [Parse/Syntax] Replace ParsedSyntaxRecorder::record* calls from the parser with ParsedSyntaxRecorder::make*
Doing a "direct ParsedSyntaxRecorder::record[some syntax]" call from the parser is not a good idea due to possibility
of being in a backtracking context when the call is made. Replace them with "ParsedSyntaxRecorder::make[some syntax]"
which will implicitly check for backtracking and create a recorded or deferred node accordingly.
2019-01-07 19:56:36 -08:00
Argyrios Kyrtzidis
ab7427723e [Parse/Syntax] Refactoring to decouple the parser from syntax tree creation
Instead of creating syntax nodes directly, modify the parser to invoke an abstract interface 'SyntaxParseActions' while it is parsing the source code.
This decouples the act of parsing from the act of forming a syntax tree representation.
'SyntaxTreeCreator' is an implementation of SyntaxParseActions that handles the logic of creating a syntax tree.
To enforce the layering separation of parsing and syntax tree creation, a static library swiftSyntaxParse is introduced to compose the two.

This decoupling is important for introducing a syntax parser library for SwiftSyntax to directly access parsing.
2019-01-07 19:52:59 -08:00
Argyrios Kyrtzidis
cbad3492e4 [Parse/Syntax] Simplify how the final SourceFileSyntax root is formed
Instead of creating multiple CodeBlockItemList nodes, that need to get merged and discarded later on, do this:

* Ensure for libSyntax parsing that we parse the whole file
* Create top-level CodeBlockItem nodes that we just directly wrap with a single CodeBlockItemList node at the end

The importance of this change will become more obvious later on when we'll decouple syntax parsing from the formation of libSyntax tree nodes.
2018-12-10 13:37:15 -08:00
fischertony
46dc36536c [Gardening] Typo and indentation fixes 2018-10-03 22:12:51 +03:00
Alex Hoppen
38732abd46 [libSyntax] Pass RC<SyntaxArena> by reference where possible 2018-08-24 08:39:54 -07: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
Xi Ge
fd6b5941dd libSyntax: rename SyntaxParsingContext.setDiscard() to SyntaxParsingContext.setBackTracking(). NFC 2018-07-09 14:02:26 -07:00
Alex Hoppen
4e44e6805d [libSyntax] Store shared SyntaxParsingContext data in RootContextData 2018-05-22 09:07:57 -07:00
Alex Hoppen
9a3ff5bdfd [libSyntax] Add a debug dump function to SyntaxParsingContext 2018-05-22 08:52:39 -07:00
Alex Hoppen
de9737c946 [incrParse] Support incremental parsing for edited files 2018-05-22 08:52:33 -07:00
Xi Ge
a1a6c19959 libSyntax: add a mechanism to synthesize syntax nodes in SyntaxParsingContext.
To enhance the error-recovery of syntax parsing, this patch allows the
parser to synthesize missing nodes to satisfy the requirement of a
syntax node under parsing. As proof-of-concept, we synthesize r-braces
for function body to avoid regressing a function decl to an unknown
decl.
2018-04-26 10:48:57 -07:00
Rintaro Ishizaki
2134f9f768 [Parse] Move SyntaxParsingContext to Parse (#14360)
This is only for the Parser.
Also, this resolves layering violation where libAST and libSyntax
depends on each other.
2018-02-03 10:43:52 +09:00