Skip to content

[DNM] test swiftlang/swift-syntax#2944 #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed

Conversation

kkebo
Copy link
Owner

@kkebo kkebo commented Jan 20, 2025

rintaro and others added 28 commits January 2, 2025 14:51
Mark `SyntaxArena` and `ParsingSyntaxArena` with `@_spi(RawSyntax)`.

`SyntaxArena` and its subclass `ParsingSyntaxArena` were only meant be
used when dealing with `RawSyntax` which is already a SPI.
Although type type itself was `public`, most initializers were SPI, also
there was no way to retrieve it from existing types via public API. So we
assume no one was actually using it directly.
Rework `Syntax` internals. "Red" tree is now bump-pointer allocated and
visited children are cached.

* `Syntax` is a pair of the allocator (strong reference to
  `SyntaxDataArena` class) and a pointer to the allocated data
  (`SyntaxData` struct).
* All the red-tree data (parent and positions) are
  bump-pointer-allocated and cached.
* The arena and the tree are 1:1. Each mutation creates a new arena.
* `child(at:)` is now O(1) because the red-tree children are cached in
  the arena.
* `root` is now O(1) regardless of the depth because the arena holds the
  reference.
* Simplify `SyntaxChildren`. `SyntaxChildrenIndex` is now just a `Int`

Remove some hacks as they aren't needed anymore:
* `UnownedSyntax` because `SyntaxDataReference` replaces it.
* `SyntaxNodeFactory` because `Syntax.Info` is gone.

Additionally:
* Flatten `AbsoluteSyntaxInfo` to simplify the data and clarify what
  `advancedBySibling(_:)` and `advancedToFirstChild()` do.
* Remove `RawSyntaxChildren` and `RawNonNilSyntaxChildren` as they were
  implementation detail of `SyntaxChildren`.
* Remove `AbsoluteRawSyntax` and `AbsoluteSyntaxPosition` as nobody was
  really using it.
* Rename `Syntax.indexInParent` to `layoutIndexInParent` because it was
  confusing with `SyntaxProtocol.indexInParent: SyntaxChildrenIndex`
[Syntax] Use BumpPtrAllocator for Syntax node internals
…tax-builder-initializer

Remove default values for leftParen and rightParen parameters in the FunctionCallExprSyntax initializer
…ata-arena

Revert "[Syntax] Use BumpPtrAllocator for Syntax node internals"
Describe an RFC process to request feedback for public API changes
…925-syntax-data-arena

Revert "Revert "[Syntax] Use BumpPtrAllocator for Syntax node internals""
There was no reason to convert it to UInt.
i.e. 'previousToken', 'nextToken', 'firstToken', and 'lastToken'

Iterate over 'layoutBuffer' directly to avoid 'SyntaxChildren' which
implies retaining 'SyntaxDataArena' for each element.

This way, it only retains the found 'TokenSyntax', nothing else.
[Syntax] Let SyntaxIdentifier use RawSyntax.ID directly
…ritten node

When an accessor macro contains a closure, it gets rewritten to a new node in `MacroSystem` by calling `super.visit`. That rewritten node doesn’t have any parents (because `SyntaxRewriter` is expecting that node to get inserted into the tree when the node’s parent gets rewritten). This caused us to generate an empty lexical context in these situations.

To fix this, generate the lexical context based on the node before we rewrite it.

rdar://142639902
Compute the lexical context of an accessor macro based on the pre-rewritten node
Can be detected with `defined(__wasi__) && !defined(_REENTRANT)`
@kkebo kkebo mentioned this pull request Jan 20, 2025
@kkebo kkebo self-assigned this Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants