Commit Graph

44 Commits

Author SHA1 Message Date
swift-ci
e0e2634b84 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-06 09:35:07 -07:00
hiro
923fba78e1 Fixed typos (#38247)
* fix: typo occured -> occurred

* fix: typo occured -> occurred

* fix: typo depenedency -> dependency
2021-07-03 14:56:44 -03:00
Evan Wilde
e316724243 Fix reference to in_place_t
in_place_t was pulled out of optional_detail and moved up to the llvm
namespace.
2021-06-07 11:52:40 -07:00
Alex Hoppen
3fb5dd1c68 [libSyntax] Create SyntaxRef, which uses SyntaxDataRef internally
Now that we have a fast SyntaxDataRef, create a corresponding SyntaxRef hierarchy. In contrast to the Syntax, SyntaxRef does *not* own the backing SyntaxDataRef, but merely has a pointer to the SyntaxDataRef.
In addition to the requirements imposed by SyntaxDataRef, the user of the SyntaxRef hierarchy needs to make sure that the backing SyntaxDataRef of a SyntaxRef node stays alive. While this sounds like a lot of requirements, it has performance advantages:
 - Passing a SyntaxRef node around is just passing a pointer around.
 - When casting a SyntaxRef node, we only need to create a new SyntaxRef (aka. pointer) that points to the same underlying SyntaxDataRef - there's no need to duplicate the SyntaxDataRef.
 - As SyntaxDataRef is not ref-counted, there's no ref-counting overhead involved.

Furthermore, the requirements are typically fulfilled. The getChild methods on SyntaxRef return an OwnedSyntaxRef, which stores the SyntaxDataRef. As long as this variable is stored somewhere on the stack, the corresponding SyntaxRef can safely be used for the duration of the stack frame. Even calls like the following are possible, because OwnedSyntaxRef returned by getChild stays alive for the duration of the entire statement.
```
useSyntaxRef(mySyntaxRef.getChild(0).getRef())
```
2021-03-11 19:34:49 +01:00
Alex Hoppen
c5fd7eb594 [libSyntax] Add getChild accessors for SyntaxDataRef 2021-03-09 10:37:05 +01:00
Alex Hoppen
da8357157d [libSyntax] Hide null AbsoluteRawSyntax behind a custom OptionalStorage implementation
This splits the previous null AbsoluteRawSyntax type into two categories
and removes the public null initializer and isNull method.

1. The default initializer of AbsoluteRawSyntax now create uninitialized
   memory. This is exactly what we need since we just need to allocate
   the memory to initialise  it using the SyntaxDataRef::getChild method
   wherever we use it.
2. Make Optional<AbsoluteRawSyntax> and Optional<SyntaxDataRef> zero-cost
   wrappers around their underlying type. These use the old null type
   to indicate a missing optional value.

Overall, I believe this makes the code both safer (we now enforce null
types properly in the type system) and potentially faster (although I
haven't been able to measure an improvement)
2021-03-05 16:59:54 +01:00
Alex Hoppen
c6a04392fa [libSyntax] Model IsRef in SyntaxDataRef by a a virtual isRef method 2021-03-05 16:59:54 +01:00
Alex Hoppen
f284529bd3 [libSyntax] Add a unsafe but fast SyntaxDataRef version of SyntaxData
In contrast to SyntaxData, SyntaxDataRef is not memory-safe, but
designed to be fast. In particular, the following guarantees from
SyntaxData are being dropped:
 - SyntaxDataRef does not retain the SyntaxArena containing its
   RawSyntax. The user of SyntaxDataRef has to provide that guarantee.
   However, that's usually pretty easily done by just retaining the
   SyntaxArena of the tree's root node.
 - The parent of a SyntaxDataRef must outlive the child node. This is
   the more tricky constraint, but if a tree is just walked top to
   bottom with nodes stored on the stack, this is given by the way the
   stack is being unrolled.
2021-03-05 16:59:54 +01:00
Alex Hoppen
56a923475f [libSyntax] Reference count SyntaxData
Instead of having a heap-allocated RefCountedBox to store a SyntaxData's
parent, reference-count SyntaxData itself. This has a couple of
advantages:
 - When passing SyntaxData around, only a pointer needs to be passed
   instead of the entire struct contents. This is faster.
 - We can later introduce a SyntaxDataRef, which behaves similar to
   SyntaxData, but delegates the responsibility that the parent stays
   alive to the user. While sacrificing guaranteed memory safety, this
   means that SyntaxData can then be stack-allocated without any
   ref-counting overhead.
2021-03-03 08:48:24 +01:00
Alex Hoppen
28f5f79bb7 [libSyntax] Don't reference count RawSyntax
Instead, only reference count the SyntaxArena that the RawSyntax nodes
live in. The user of RawSyntax nodes must guarantee that the SyntaxArena
stays alive as long as the RawSyntax nodes are being accessed.

During parse time, the SyntaxTreeCreator holds on to the SyntaxArena
in which it creates RawSyntax nodes. When inspecting a syntax tree,
the root SyntaxData node keeps the SyntaxArena alive. The change should
be mostly invisible to the users of the public libSyntax API.

This change significantly decreases the overall reference-counting
overhead. Since we were not able to free individual RawSyntax nodes
anyway, performing the reference-counting on the level of the
SyntaxArena feels natural.
2021-03-01 09:43:54 +01:00
Alex Hoppen
65f3d47c2d [libSyntax] Pass RC<RawSyntax> by reference whenever possible 2021-01-29 13:08:12 +01:00
Alex Hoppen
a356c89e92 [libSyntax] Don't reference count SyntaxData
Instead, reference count the SyntaxData's parent. This has a couple of
advantages:
1. We eliminate a const_cast that was potentially unsafe
2. It more closely resembles the architecture on the Swift side
3. It has the potential to be optimised further if the parent can be
   accessed in an unsafe, non-reference-counted way
2021-01-29 13:08:12 +01:00
Alex Hoppen
8bb1167e21 [libSyntax] Restructure RawSyntax to more closely resemble the SwiftSyntax implementation 2021-01-29 13:08:12 +01:00
Alex Hoppen
5bf93d860b Remove SyntaxASTMap
As far as I can tell, this hasn't ever been really used, it's certainly
not used anymore.
2021-01-15 11:08:59 +01: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
2ec16f0600 [Syntax] Make getRaw() return const reference
This saves reference-counting operations.
2019-10-14 15:37:43 -07:00
Rintaro Ishizaki
601c90d3cf Revert "Merge pull request #27024 from rintaro/syntaxparse-endloc-composition"
This reverts commit 99c65211e6, reversing
changes made to 3ddfcae24b.
2019-10-14 13:43:22 -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
9612f447c1 [SyntaxParse] Fix the end location for CompositionTypeRepr
The end loc should be the loc of the last token of the last type
element.
2019-09-04 12:11:19 -07:00
Marc Rasi
00c0a03637 disable sized deallocation for SyntaxData 2019-08-12 13:23:04 -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
Saleem Abdulrasool
813f712ad5 adjust declarations of DenseMapInfo for GCC
Remove the extra qualification and place explicitly in the LLVM
namespace.  This fixes some build issues with GCC 8.2.
2018-10-23 08:29:13 -07:00
Alex Hoppen
705f5b79a2 [libSyntax] Rename getAbsolutePosition-related methods for more clarity 2018-07-19 09:15:53 -07: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
92f8f34d22 [incrParse] Store reused regions and output them after parsing 2018-05-22 08:52:34 -07:00
Xi Ge
5a8053e7ef libSyntax: add getAbsoluteEndPosition() method to syntax nodes.
This implementation uses sibling's absolute start position to help
populate caches while getting the end position.
2018-05-01 12:06:41 -07:00
Xi Ge
7b4218c2f7 libSyntax: cache absolute positions on SyntaxData.
Aligning with what we did for SwiftSyntax, this patch uses caches for
absolute position calculation on the C++ side.
2018-04-30 15:09:00 -07:00
Rintaro Ishizaki
6108c881be [Syntax] Use TrailingObjects for SyntaxData (#14301)
This should optimize memory usage for SyntaxData.
2018-01-31 21:50:04 +09:00
Rintaro Ishizaki
fced748790 [Syntax] Represent missing optioanl nodes as nullptr (#14300)
Allocating RawSyntax/SyntaxData for missing optional node is a waste of
resource.
2018-01-31 19:24:00 +09:00
Rintaro Ishizaki
0780c529c4 [Syntax] Unify RawSyntax and RawTokenSyntax using union and TrailingObjects
It better matches with SwiftSyntax model.

Using TrailingObjects reduces the number of heap allocation which
gains 18% performance improvement.
2018-01-18 14:49:46 +09:00
Harlan
a5098e6b69 Generate libSyntax API (#10926)
* Generate libSyntax API

This patch removes the hand-rolled libSyntax API and replaces it with an
API that's entirely automatically generated. This means the API is
guaranteed to be internally stylistically and functionally consistent.
2017-07-25 18:19:58 -07:00
Harlan
70089a7bcc [Syntax] Represent TokenSyntax as a Syntax node (#10606)
Previously, users of TokenSyntax would always deal with RC<TokenSyntax>
which is a subclass of RawSyntax. Instead, provide TokenSyntax as a
fully-realized Syntax node, that will always exist as a leaf in the
Syntax tree.

This hides the implementation detail of RawSyntax and SyntaxData
completely from clients of libSyntax, and paves the way for future
generation of Syntax nodes.
2017-06-27 11:08:10 -07:00
Harlan Haskins
0e61e50ebb Fix UnknownSyntaxTests. One test still fails. 2017-06-23 11:59:16 -07:00
Harlan Haskins
972502d024 Remove subclasses of SyntaxData and move validation logic into Syntax subclasses. 2017-06-22 21:52:59 -07:00
practicalswift
7eb7d5b109 [gardening] Fix 100 typos. 2017-04-18 17:01:42 +02:00
David Farler
303a3e5824 Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.

The basic pipeline in the frontend is:

- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
  set to 7 based on prior migrator seasons.  Right now, this is just set
  to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
  file that Xcode knows how to understand.

Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.

- Add -emit-remap frontend option
  This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
  This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
  Useful for debugging, this skips the phase in the Migrator that
  automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
  This is used for testing/debugging scenarios. This takes the final
  migration state's output text and writes it to the file specified
  by this option.
- Add -dump-migration-states-dir

  This dumps all of the migration states encountered during a migration
  run for a file to the given directory. For example, the compiler
  fix-it migration pass dumps the input file, the output file, and the
  remap file between the two.

  State output has the following naming convention:
  ${Index}-${MigrationPassName}-${What}.${extension}, such as:
  1-FixitMigrationState-Input.swift

rdar://problem/30926261
2017-04-17 16:25:02 -07:00
David Farler
7ce3b81001 Add generic Syntax collection for unbounded list of nodes
Just a little reusable collection type for things like argument lists,
statement lists, etc.
2017-03-02 17:02:50 -08:00
David Farler
c958cd65eb [Syntax] Allow UnknownSyntax to have children
This will make it easier to incrementally implement syntax nodes,
while allowing us to embed nodes that we do know about inside ones
that we don't.

https://bugs.swift.org/browse/SR-4062
2017-02-28 14:30:57 -08:00
David Farler
c343298b8f [Syntax] Implement return-statement and integer-literal-expr
A return statement needs something to return, so implement
integer-literal-expression too. This necessarily also forced
UnknownExprSyntax, UnknownStmtSyntax, and UnknownDeclSyntax,
which are stand-in token buckets for when we don't know
how to transform/migrate an AST.

This commit also contains the core function for caching
SyntaxData children. This is highly tricky code, with some
detailed comments in SyntaxData.{h,cpp}. The gist is that
we have to atomically swap in a SyntaxData pointer into the
child field, so we can maintain pointer identity of SyntaxData
nodes, while still being able to cache them internally.

To prove that this works, there is a multithreaded test that
checks that two threads can ask for a child that hasn't been
cached yet without crashing or violating pointer identity.

https://bugs.swift.org/browse/SR-4010
2017-02-22 18:45:29 -08:00
David Farler
7ee42994c8 Start the Syntax library and optional full token lexing
Add an option to the lexer to go back and get a list of "full"
tokens, which include their leading and trailing trivia, which
we can index into from SourceLocs in the current AST.

This starts the Syntax sublibrary, which will support structured
editing APIs. Some skeleton support and basic implementations are
in place for types and generics in the grammar. Yes, it's slightly
redundant with what we have right now. lib/AST conflates syntax
and semantics in the same place(s); this is a first step in changing
that to separate the two concepts for clarity and also to get closer
to incremental parsing and type-checking. The goal is to eventually
extract all of the syntactic information from lib/AST and change that
to be more of a semantic/symbolic model.

Stub out a Semantics manager. This ought to eventually be used as a hub
for encapsulating lazily computed semantic information for syntax nodes.
For the time being, it can serve as a temporary place for mapping from
Syntax nodes to semantically full lib/AST nodes.

This is still in a molten state - don't get too close, wear appropriate
proximity suits, etc.
2017-02-17 12:57:04 -08:00