Skip to content

yeast: Miscellaneous cleanup - #22084

Merged
tausbn merged 10 commits into
mainfrom
tausbn/yeast-miscellaneous-cleanup
Jun 29, 2026
Merged

yeast: Miscellaneous cleanup#22084
tausbn merged 10 commits into
mainfrom
tausbn/yeast-miscellaneous-cleanup

Conversation

@tausbn

Copy link
Copy Markdown
Contributor

A variety of cleanups and improvements, most notably unifying NodeRef and Id into the latter (first commit), which enables us to avoid having to explicitly specify whether we're splicing in a single tree or an iterable of such using the {..foo} syntax (the second commit).

In addition to this, Copilot found a bunch of dead code and other simplifications, which resulted in the remaining commits on this PR.

Needless to say, you'll probably want to review this PR commit-by-commit.

tausbnand others added 9 commits June 29, 2026 10:33
Previously, the `Id` type was a bare usize alias. The `NodeRef` newtype
existed solely to carry the AST-aware `YeastDisplay` /
`YeastSourceRange` impls (so that `#{captured_node}` rendered source
text rather than the numeric id) without colliding with the impls for
raw integer types.
This commit promotes `Id` itself to a (transparent) newtype struct and
moves the AST-aware trait impls directly onto it. With `Id` and `usize`
now being different types, the integer-display impl (for `usize`) and
the source-text impl (for `Id`) coexist without conflict, and `NodeRef`
becomes redundant (and so we remove it).
In the initial implementation of yeast, the splice syntax was needed do
distinguish between splicing multiple nodes or just a single node.
However, this was always an ugly "wart" in the syntax, since the user
shouldn't have to worry about these things.
To fix this, we add an `IntoFieldIds` trait that dispatches on the
value's type: `Id` pushes a single id, and a blanket impl for
`IntoIterator<Item: Into<Id>>` handles `Vec<Id>`, `Option<Id>`, and
arbitrary iterator chains.
With this, we no longer need to use the special splice syntax, and hence
we can get rid of it.
`Captures::map_captures`, `Captures::map_captures_to`, and
`Captures::try_map_all_captures` had no callers. The last one was
subsumed by `try_map_captures_except` (which takes a skip list and
degenerates to the old behaviour when the list is empty).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`translate_opt` was a convenience for the manual_rule! body code,
collapsing `Option<I>` to `Option<Id>` via `translate`. Since the
`@@` raw-capture migration replaced manual_rule! with rule!, no
callers remain — the auto-translate prefix handles `Option<Id>`
captures directly.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`BuildCtx::prepend_field` and the underlying `Ast::prepend_field_child`
existed to support the create-then-mutate pattern in swift.rs (build
an output node, then prepend modifiers to its `modifier:` field). The
SwiftContext-based refactor on the previous branches eliminated all
such call sites: every emitted declaration now carries its modifiers
from birth, so the in-place prepend operation has no users.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Both accessors returned the same private `kind_name: &'static str`
field; `kind_name()` is widely used (mainly by dump.rs and schema
diagnostics) and `kind()` had only 2 internal callers in lib.rs and
a handful in tests. Pick the more descriptive name and update the
callers.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…_ctx_or_implicit`
The empty error string passed to `expect_ident` was dead code (the
preceding lookahead has already confirmed the token is an ident),
but it would have been a confusing message if it ever fired. Replace
with an explicit "unreachable" string that makes the intent
clearer to readers.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The `{expr}.map(p -> tpl)` and `{expr}.reduce_left(first -> init, acc,
elem -> fold)` post-fix chains on `{expr}` placeholders had no
remaining users in the codebase: `.map` was never used, and the
4 `.reduce_left` sites in `swift.rs` were rewritten to plain
`Iterator::reduce` via an `and_chain` helper in an earlier commit.
Removes the entire `parse_chain_suffix` function (~90 lines) and the
`has_chain` detection / dispatch branches at the two call sites
(field-position in `parse_direct_node_inner` and body-position in
`parse_direct_list`). The remaining `{expr}` path is the
trait-dispatched one introduced by the splice-syntax cleanup, which
handles single ids and iterables uniformly via `IntoFieldIds`.
Also strips the chain syntax from the `tree!` macro doc comment.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The trait had a single implementor (`AstCursor`), three type parameters
of which one (`T`) was never used in any method signature, and one
external consumer that needed `use yeast::Cursor;` in scope just to
call methods on the cursor. The abstraction was overhead without a
second implementor to justify it.
Move the six trait methods to an inherent `impl AstCursor` block;
delete `shared/yeast/src/cursor.rs`, the `pub mod cursor;` and
`pub use cursor::Cursor;` lines in `lib.rs`, and the `use yeast::Cursor;`
in `tree-sitter-extractor`'s `traverse_yeast`.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR performs a Yeast-wide cleanup that unifies node identity on a single Id newtype and simplifies macro/template interpolation by introducing IntoFieldIds, allowing {expr} to uniformly handle single ids, iterables, and optional captures without a separate splice syntax.

Changes:

  • Replace NodeRef/usize-based ids with a dedicated yeast::Id newtype and propagate it through AST building, traversal, dumping, and translation code.
  • Simplify tree!/trees!/rule! template interpolation by removing {..expr} splice + chain support and using IntoFieldIds dispatch for {expr}.
  • Update Swift Yeast translation rules, extractor traversal, and Yeast unit tests/docs to the new id and interpolation APIs.
Show a summary per file
FileDescription
unified/extractor/src/languages/swift/swift.rsUpdates Swift translation rules to use Id and {expr}-based interpolation throughout.
shared/yeast/tests/test.rsMigrates tests from kind() to kind_name() and from usize/NodeRef usage to Id.
shared/yeast/src/visitor.rsUpdates visitor-built AST ids to the Id newtype and fixes indexing accordingly.
shared/yeast/src/lib.rsIntroduces Id newtype + IntoFieldIds, removes NodeRef and Cursor trait, and updates core AST APIs.
shared/yeast/src/dump.rsUpdates dump APIs to take Id instead of usize and adjusts imports/signatures.
shared/yeast/src/cursor.rsRemoves the now-unneeded generic Cursor trait.
shared/yeast/src/captures.rsRemoves dead capture-mapping helpers and documents/keeps the one needed mapping API.
shared/yeast/src/build.rsRemoves dead prepend_field/translate_opt helpers and updates docs around translate.
shared/yeast/doc/yeast.mdUpdates documentation examples/explanations for {expr} interpolation and raw captures.
shared/yeast-macros/src/parse.rsImplements {expr} trait-dispatched extension via IntoFieldIds and removes splice/chain parsing logic.
shared/yeast-macros/src/lib.rsUpdates macro docs to describe the new {expr} interpolation model.
shared/tree-sitter-extractor/src/extractor/mod.rsUpdates Yeast node-kind access and removes reliance on the deleted Cursor trait import.

Review details

  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment threadshared/yeast/doc/yeast.md
@tausbn
tausbn marked this pull request as ready for review June 29, 2026 11:42
@tausbn
tausbn requested review from a team as code ownersJune 29, 2026 11:42

@asgerfasgerf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

@tausbn
tausbn merged commit f1cc1e5 into mainJun 29, 2026
112 of 114 checks passed
@tausbn
tausbn deleted the tausbn/yeast-miscellaneous-cleanup branch June 29, 2026 12:14
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@tausbn@asgerf