Skip to content

Green-node flags for fast trivia/content queries#33

Merged
dsisco11 merged 8 commits into
masterfrom
sisco/green-node-flags
Jan 11, 2026
Merged

Green-node flags for fast trivia/content queries#33
dsisco11 merged 8 commits into
masterfrom
sisco/green-node-flags

Conversation

@dsisco11

Copy link
Copy Markdown
Owner

Summary
This PR introduces cached bitflags on green AST nodes to enable O(1) checks for trivia/content properties (newline/whitespace/comment/error/keyword/tagged-ident) and to support faster subtree pruning in hot query paths.

Key changes

  • Add GreenNodeFlags + mask helpers for boundary vs subtree “contains” semantics: GreenNodeFlags.cs
  • Add GreenNode.Flags virtual (default None) so concrete node types can expose computed flags: GreenNode.cs
  • Compute flags in leaves from trivia + kind-derived bits (ContainsErrorNode, ContainsKeyword, ContainsTaggedIdent) and cache them: GreenLeaf.cs
  • Aggregate flags in containers (GreenBlock, GreenList, GreenSyntaxNode), with boundary flags taken from the first child’s leading boundary + last child’s trailing boundary, and subtree “contains” flags OR’d across children:
    • GreenBlock.cs
    • GreenList.cs
    • GreenSyntaxNode.cs
  • (Perf helper) Precompute child offsets for containers with ≥10 children to make GetSlotOffset() O(1): GreenBlock.cs, GreenList.cs

Tests added

  • Flags correctness + parsed “ownership” cases for newline/comments: GreenNodeFlagsTests.cs
  • Equality/hash stability + cache/non-cache consistency + structural sharing immutability: GreenNodeEqualityTests.cs

@dsisco11 dsisco11 merged commit 267012c into master Jan 11, 2026
2 checks passed
@dsisco11 dsisco11 deleted the sisco/green-node-flags branch January 11, 2026 05:31
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.

1 participant