Skip to content

SEARCH.md: a code query engine on treebank, and its prior art - #140

Open
zmaril wants to merge 1 commit into
mainfrom
search-design
Open

SEARCH.md: a code query engine on treebank, and its prior art#140
zmaril wants to merge 1 commit into
mainfrom
search-design

Conversation

@zmaril

@zmaril zmaril commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

A design sketch, not a commitment. Independent of the measurement stack —
based on main, no code.

The design. An indexed structural engine: supertype bits materialised at
index time (DESIGN.md §2 fact 4 says supertype membership is
derivation-based, so it is not recoverable from (kind, parent) after the
fact — it has to be written while the tree is in hand); (pre, post)
interval labels so containment is an integer comparison rather than a tree
walk; a trigram prefilter; and a re-parse verification pass so the index is
allowed to be approximate. Crates named throughout — roaring,
bitpacking, fst, tantivy, rkyv, memmap2, redb.

One nice accident: the per-(parent, field, child) edge counts added in
#137 for coverage measurement are exactly the cardinality estimator a query
planner needs.

The prior art, which is the part worth reading. My first draft claimed
this approach had "never been applied to code." That is false:

  • srcML (Collard & Maletic, 2002 onward) marks code up as XML and
    queries it with XPath/XSLT.
  • Babelfish / bblfsh (source{d}, ~2017–2019) parsed many languages into
    a Universal AST annotated with language-agnostic roles — the same word
    this repo uses — and queried it with XPath so one query worked across
    languages. That is the thesis of DESIGN.md §3, shipped eight years
    earlier.
  • Kythe, Glean and CodeQL all index code structure and query it.

What survives is narrow, and the doc says so: where the vocabulary is
enforced (in the parse, versus Babelfish's post-hoc annotation layer — which
is precisely the "query layer that can drift" the project exists to avoid),
and published per-language confidence, which none of them have.

And a warning. source{d} shut down; Babelfish is unmaintained. The hard
part was never the index — it was keeping N language frontends mapped onto
one vocabulary while N languages kept moving. That is exactly this repo's
cost structure, and it belongs in the record.

A sketch of an indexed structural search engine: supertype bits
materialised at index time (§2 fact 4 makes them underivable afterwards),
interval labels so containment is an integer comparison, a trigram
prefilter, and a re-parse verification pass so the index is allowed to be
approximate.

The first draft claimed the XML twig-query approach had never been applied
to code. That is false, and the correction is worth more than the design.
srcML has marked code up as XML and queried it with XPath since 2002.
Babelfish parsed many languages into a Universal AST annotated with
language-agnostic ROLES -- the same word this repo uses -- and queried it
with XPath, which is the thesis of DESIGN.md §3 shipped eight years
earlier. Kythe, Glean and CodeQL all index structure and query it.

What is left is narrow and stated as such: where the vocabulary is enforced
(in the parse, not a post-hoc annotation layer that can drift), and
published per-language confidence. And a warning -- source{d} shut down and
Babelfish is unmaintained. The hard part was never the index, it was
keeping N frontends mapped onto one vocabulary while N languages moved.
That is exactly this repo's cost structure.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ZQR1QTvqArX8vMxYKK3rv
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