Commit Graph

246 Commits

Author SHA1 Message Date
kitasuke
b583fef8e2 Consolidate StringInterpolationExpr to StringLiteralExpr 2019-05-12 11:23:00 +09:00
Argyrios Kyrtzidis
3612cd3d72 [utils/gyb_syntax_support] Add collection_element_name for when specifying a Child
This is useful to provide `add<ELEMENT_NAME>` APIs for SwiftSyntax that are better named
and without having name conflicts.
2019-04-23 18:14:39 -07:00
Xi Ge
ddd643fe89 syntax: perform rename to avoid name collision in syntax builder. NFC 2019-04-20 16:04:41 -07:00
Xi Ge
1015a6024d Syntax: use child name instead of type name for gyb-generated functions
ParsedSyntaxBuilder has a convenient function to add member to a syntax-collection
child. The function name uses the type name of the collection's members,
which can lead to name collision. This patch renames it.
2019-04-19 18:16:13 -07:00
Saleem Abdulrasool
8ed5c1a4bc build: introduce and switch to GYB_SOURCES
This avoids us having to pattern match every source file which should
help speed up the CMake generation.  A secondary optimization is
possible with CMake 3.14 which has the ability to remove the last
extension component without having to resort to regular expressions.  It
also helps easily identify the GYB'ed sources.
2019-03-11 13:48:54 -07:00
Aleksey Kladov
8c77e08fad Clarify the rule for leading trivia
The "contiguous sequence" is not necessary and is confusing.
2019-02-20 13:26:21 +03:00
Xi Ge
e07a8cf2a6 SyntaxParser: set up a C API to get a hash value indicating the node declaration set
To ensure SwiftSyntax calls a compatible parser library, this patch sets
up a C API that returns a constant string calculated during compilation time to indicate
the version of syntax node declarations. The same hash will be calculated
in the SwiftSyntax (client) side as well by using the same algorithm.

During runtime, SwiftSyntax will verify its hash value is identical to the
result of calling swiftparse_node_declaration_hash before actual
parsing happens.

This patch only sets the API up. The actual implementation of the
hashing algorithm will come later.
2019-02-06 17:33:48 -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
668fa1d721 [ParsedRawSyntaxNode] Fix ParsedRawSyntaxNode::dump()
Using dumpTokenKind() function instead of getTokenText().
2019-01-07 19:56:37 -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
Michael Gottesman
a761d7c0ba Revert "Revert "Revert "[Build System: CMake] make add_swift_library a wrapper to add_llvm_library"""
This reverts commit 121f5b64be.

Sorry to revert this again. This commit makes some pretty big changes. After
messing with the merge-conflict created by this internally, I did not feel
comfortable landing this now. I talked with Saleem and he agreed with me that
this was the right thing to do.
2018-11-06 13:24:00 -08:00
Saleem Abdulrasool
121f5b64be Revert "Revert "[Build System: CMake] make add_swift_library a wrapper to add_llvm_library""
This reverts commit 103f9a8246.
2018-11-05 14:37:40 -08:00
Xi Ge
103f9a8246 Revert "[Build System: CMake] make add_swift_library a wrapper to add_llvm_library" 2018-11-02 12:49:07 -07:00
Saleem Abdulrasool
c3555cf0c4 add_swift_host_library: special handling for GYB sources 2018-10-31 12:46:31 -07:00
Michael Gottesman
3f17bb6ddf Carefully split the build's invocation of add_swift_library into host/target variants.
The key thing here is that all of the underlying code is exactly the same. I
purposely did not debride anything. This is to ensure that I am not touching too
much and increasing the probability of weird errors from occurring. Thus the
exact same code should be executed... just the routing changed.
2018-10-27 12:58:51 -07:00
Rintaro Ishizaki
891cca14b4 [incrParse] Skip missing node in getNextNode()
Taking Missing node into account confuses reusability checking in
incremental parsing.

rdar://problem/45215049 https://bugs.swift.org/browse/SR-8976
rdar://problem/45287031 https://bugs.swift.org/browse/SR-9006
2018-10-24 23:58:46 +09:00
Xi Ge
957155dd8f [Doc] Update libSyntax document for how to use it in Swift tools. NFC 2018-09-25 17:49:53 -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
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
Alex Hoppen
9eb0208bb5 [libSyntax] Add support for incremental serialization of ByteTrees 2018-08-21 10:55:15 -07:00
Alex Hoppen
093f9179b0 Merge pull request #18698 from ahoppen/leak-fix
[libSyntax] Resolve a memory leak leaking the syntax tree
2018-08-14 14:11:37 -07:00
Alex Hoppen
79e9113a58 Merge pull request #18677 from ahoppen/ref-counted-owned-string
[libSyntax] Add a reference counted version of OwnedString
2018-08-14 11:37:40 -07:00
Alex Hoppen
e5c8440fe4 [libSyntax] Make RawSyntaxCacheNode retain its underlying RawSyntax node
Previously RawSyntaxCacheNode was not increasing the RawSyntax refCount
and accessing a cached node would fail if the node had been deleted in
the meantime. We weren't hitting this so far, because all nodes were
allocated using a bump allocator and thus the underlying memory never
freed.
2018-08-14 07:42:45 -07:00
Alex Hoppen
1529d65748 Merge pull request #18684 from ahoppen/enable-cache-token-nodes
[libSyntax] Reenable caching of token nodes
2018-08-14 07:40:46 -07:00
Alex Hoppen
4369b36f21 Merge pull request #18497 from ahoppen/bytetree-infrastructure
[libSyntax] Add a binary serialization format for syntax trees
2018-08-13 15:41:30 -07: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
Alex Hoppen
32a3a31684 [libSyntax] Reenable caching of token nodes 2018-08-13 15:14:37 -07:00
Alex Hoppen
280b186fa0 [libSyntax] Add a binary serialization format for syntax trees 2018-08-10 10:13:00 -07:00
Alex Hoppen
13aeb5440b [libSyntax] Lazily compute a node's text length 2018-08-09 15:39:48 -07:00
Alex Hoppen
3deee08f70 Merge pull request #18314 from ahoppen/remove-syntax-classifier
[libSyntax] Remove the C++ SyntaxClassifier
2018-07-30 14:52:15 -07:00
Alex Hoppen
749a13a6fe [libSyntax] Remove the C++ SyntaxClassifier
The recommended way forward is to use the SyntaxClassifier on the Swift
side.

By removing the C++ SyntaxClassifier, we can also eliminate the
-force-libsyntax-based-processing option that was used to bootstrap
incremental parsing and would generate the syntax map from a syntax
tree.
2018-07-30 09:26:18 -07:00
Liigo Zhuang
15a539d6fd parse file contents
currentFile -> currentFileContents
2018-07-30 16:41:03 +08:00
Richard Wei
4de4f34329 Fix libsyntax doc
`gyb_syntax_support.py` does not exist. It's a directory.
2018-07-26 02:56:06 -07:00
Xi Ge
7126544a03 Merge pull request #18132 from alanzeino/lib_syntax_typo
[Syntax] Fix typo in code example in libSyntax README
2018-07-24 15:29:04 -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
Alan Zeino
b1f67720a9 Fix typo in code example in libSyntax README 2018-07-21 15:37:42 -07:00
Alex Hoppen
419ba044f1 [libSyntax] Record reused node IDs
This is cheaper than recording reused region offsets and the reused node
IDs will later be used to incrementally transfer the syntax to
SwiftSyntax.
2018-07-19 13:55:57 -07:00
Alex Hoppen
705f5b79a2 [libSyntax] Rename getAbsolutePosition-related methods for more clarity 2018-07-19 09:15:53 -07:00
Alex Hoppen
8430eff670 [libSyntax] Add syntax coloring based on the syntax tree 2018-07-13 17:48:47 -07:00
Alex Hoppen
03a7042712 [libSyntax] Disable caching of token nodes
Since nodes have unique IDs now, we cannot reuse the nodes at multiple
locations in the source file
2018-07-13 16:56:03 -07:00
Alex Hoppen
9d59cd286b [incrParse] Add a stable id to the syntax nodes
The id is meant to be stable across incremental parses
2018-07-13 16:56:03 -07:00
John McCall
3247232aa3 Remove some gratutious uses of GCC extensions from the Syntax library.
Naming the bit-field structs is a significant readability improvement
because it's very clear that you shouldn't touch e.g. Bits.Token
without having checked/asserted that you're in a token case.

The assertions are all in statement context (which was obvious
because the NDEBUG versions all included semicolons), so there's no
reason not to use the traditional `do { } while (false)` trick instead
of a statement-expression.

This also clears up some warnings in atypical build configurations.
2018-06-30 03:59:49 -04:00
Alex Hoppen
15b2bae80a [libSyntax] Improve syntax related dump functions 2018-05-22 09:07:55 -07:00
Alex Hoppen
b2ebc96510 [incrParse] Reparse a node if the next leaf node has been modified 2018-05-22 09:07:55 -07:00
Alex Hoppen
a137e0da7d [libSyntax] Omit unknown nodes if they do not have any children 2018-05-22 08:52:40 -07:00
Alex Hoppen
2c02b1e1b4 [incrParse] Fix lexer offset issue when missing tokens get synthesized 2018-05-22 08:52:39 -07:00
Alex Hoppen
e1a99efd57 [incrParse] Fix parsing of nodes covering no source text 2018-05-22 08:52:39 -07:00
Alex Hoppen
60d11d24f8 [incrParse] Reparse a node if the next leaf node has been modified 2018-05-22 08:52:33 -07:00
Alex Hoppen
f8cd1ca749 [libSyntax] Compute the text length of every node on the fly 2018-05-22 08:52:32 -07:00