Commit graph

6342 commits

Author SHA1 Message Date
Max Brunsfeld 5e2fb7d8bb Store compressed parse state symbols and values in one array 2026-05-23 19:19:14 -07:00
Will Lillis 591847a7d0
wip(generate): bias the 3-way picker toward CSR over Small
The bytes-optimal pick is not the parse-time-optimal pick. CSR uses
O(log n) binary search; Small uses an O(group_count + nnz) linear
scan over grouped sections. The unbiased picker put ~50% of states
into Small, causing parse-time regressions of up to +24% on grammars
like kotlin and javascript.

Add a SMALL_VS_CSR_BIAS constant (0.6) that requires Small to be at
least 40% smaller than CSR before the picker prefers it, applied both
to the per-state argmin and the canonical-group dedup-promotion pass.
This keeps each grammar's parse-time delta within roughly the ±10%
band that csr-clean already occupies vs master, while still
delivering ~7pp of the ~11pp size win available from the unbiased
picker (~38% .so reduction vs master across the corpus).
2026-05-19 18:18:20 -04:00
Will Lillis 65e8b25413
wip(generate): emit 3-way per-state parse table layout (plan B)
Replace the per-grammar CSR-vs-hybrid choice with a per-state picker
that places each state in the smallest of dense / CSR / small. State
ids are partitioned into contiguous tiers [Dense | CSR | Small] driven
by `large_state_count` and a new `csr_state_count` field on
TSLanguage. The runtime dispatches on two range checks; the rest of
the lookup logic per tier is unchanged.

States 0 (error) and 1 (start state) are pinned to the Dense tier so
they remain at indices 0 and 1, matching the runtime's hard-coded
expectations. Cost is bounded at ~2 * SYMBOL_COUNT * 2 bytes per
grammar.

Cleanup: drop --table-fmt CLI, OptLevel::ForceHybridTable /
ForceCompressedTable, RenderError::ConflictingParseTableFlags,
heuristic_should_compress, and use_compressed_tables since the free
picker provably picks the smallest representation per state.

Tests pass against the regenerated fixtures. The size savings are
measured in a follow-up corpus run.
2026-05-19 18:18:20 -04:00
Will Lillis 73f7a94151
wip(generate): state renumbering scaffold for plan B
Add `assign_initial_state_repr` + `reorder_states_by_repr` so the
picker output drives a contiguous [Dense | CSR | Small] tier layout
with all Shift/Goto state references remapped through the new ids,
plus parallel state-indexed arrays permuted to match.

Step 2 wires this with the existing 2-way decision as input, so the
permutation is the identity and parser.c output is byte-identical
across the 320-grammar corpus. Step 3 will switch the input to the
free 3-way picker and add three-way emission.
2026-05-19 17:58:09 -04:00
Will Lillis 0532e54465
wip(generate): per-state representation picker for plan B
Add dense/CSR/small picker keyed on overhead-aware per-state cost
plus a dedup-promotion pass for canonical small-table groups. Emits
PER_STATE_* defines for corpus-runner CSV. No emission change yet:
the picker only reports stats while the existing 2-way path drives
parser.c output.
2026-05-19 17:58:09 -04:00
Christian Clason 2b8647fc52
fixup: language test ABI>=15 2026-05-19 17:57:49 -04:00
Will Lillis d4d7c1b68f
fix(lib): remove unused section_index field from LookaheadIterator 2026-05-19 17:57:49 -04:00
Will Lillis 8f663fbb36
perf(generate): deduplicate identical small parse table entries
When generating the hybrid format's small parse table, some grammars
emit many states with identical grouped (symbol, action) data.Detect
duplicates and reuse a single table offset for them.

Co-authored-by: Tuomas Hietanen <thorium@iki.fi>
2026-05-19 17:57:49 -04:00
Will Lillis ea90489d7a
perf(generate): add CSR-compressed parse tables (ABI 16)
Apply Compressed Sparse Row (CSR) compression to the parse table for
grammars that benefit, replacing the original dense + small split with
three flat arrays:

  uint32_t parse_table_row_offsets[STATE_COUNT + 1]
  uint16_t parse_table_columns[TOTAL_NNZ]
  uint16_t parse_table_values[TOTAL_NNZ]

Heuristic for enabling CSR (per grammar, all three must hold):

  1. LARGE_STATE_COUNT * SYMBOL_COUNT > STATE_COUNT * 40
     Ensures the dense table is large enough relative to total state
     count that savings outweigh the small-state grouping penalty.

  2. dense table density < 45%
     Ensures CSR actually saves space. Above ~50% density, CSR's
     per-entry column indices cost more than the zeros they eliminate.
     45% adds margin below the theoretical crossover.

  3. LARGE_STATE_COUNT * SYMBOL_COUNT > 50,000
     Avoids applying a format change to tiny grammars where fixed
     overhead dominates.

Co-authored-by: Tuomas Hietanen <thorium@iki.fi>
2026-05-19 17:57:49 -04:00
Will Lillis f535c3bb97 fix(test): write fixture headers once
Several test functions compile the same grammar fixture.
Tests sharing a grammar name also share a src_dir. Each test also
unconditionally writes the three tree-sitter headers into
src_dir/tree_sitter/, leading to a race.

Write the three headers exactly once per src_dir, controlled via a
global `HashSet`.
2026-05-17 19:55:37 -04:00
Will Lillis 71040925fe perf(cli): stream CST rendering via Display wrappers
Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-05-17 15:02:08 -04:00
Will Lillis ffea4e8e58 fix(cli): rework coloring abstraction and fix NO_COLOR handling
Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-05-17 15:02:08 -04:00
Christian Clason d4e7f9793c build(deps): bump wasi-sdk to v33 2026-05-16 11:45:48 +02:00
Christian Clason 3a260021dd build(deps): bump wasmtime-c-api to v36.0.9 2026-05-16 11:45:39 +02:00
dependabot[bot] a858378ce7 build(deps): bump cc from 1.2.61 to 1.2.62 in the cargo group
Bumps the cargo group with 1 update: [cc](https://github.com/rust-lang/cc-rs).


Updates `cc` from 1.2.61 to 1.2.62
- [Release notes](https://github.com/rust-lang/cc-rs/releases)
- [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.2.61...cc-v1.2.62)

---
updated-dependencies:
- dependency-name: cc
  dependency-version: 1.2.62
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-12 09:13:21 +02:00
dependabot[bot] aa83bf0402 ci: bump korthout/backport-action in the actions group
Bumps the actions group with 1 update: [korthout/backport-action](https://github.com/korthout/backport-action).


Updates `korthout/backport-action` from 4.5.0 to 4.5.1
- [Release notes](https://github.com/korthout/backport-action/releases)
- [Commits](https://github.com/korthout/backport-action/compare/v4.5.0...v4.5.1)

---
updated-dependencies:
- dependency-name: korthout/backport-action
  dependency-version: 4.5.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-12 09:13:01 +02:00
Will Lillis 50bb81484d fix(generate): consider reserved words when removing unused rules 2026-05-10 23:53:48 -04:00
Will Lillis 3b328005c9 fix(generate): rewrite parse_grammar with forward DFS
The previous implementation of `InputGrammar::normalize` (inlined  in
`parse_grammar` iterated over every variable, checking whether  it was
reachable _backwards_ from teh root by recursing over rules that
referenced it.

This means that each and every top level call re-traversed the entire
graph. The runtime performance of this backwards walk was dependent on
the _order_ of rules as declared in `grammar.js`. All existing grammars
have an ordering that's reasonably friendly to this iteration pattern
(BFS-ish order, top down from the start rule), but this leaves us open
to a catastrophic performance cliff.

Instead, seed a `used` set with the start rule, the word token, and an
names referenced from `extras`/`externals`. Then propagate via direct rule
references. This yields anywhere from a 2-~2200x speedup for
`parse_grammar`. This greatly speeds up `--no-parser` runs, but is
relatively unimportant for `parser.c` generation for _existing_
grammars. The important piece is eliminating the potential cliff.
2026-05-10 23:53:48 -04:00
Will Lillis a376ad491f fix(generate): improve error message for nonterminals used in immediate token rule 2026-05-10 10:39:48 -04:00
𝙽!𝙻 21cfae7b56
Validate Wasm language memory reads (#5569) 2026-05-06 11:54:31 -07:00
Will Lillis 5cac4316db fix(cli): account for process versions > 5 in the parse command's pretty
debug output.

The initial implementation of `--debug pretty` assumed process version
was bounded by `MAX_VERSION_COUNT`. However, we also have to account for
`MAX_VERSION_COUNT_OVERFLOW` as well as `halted_version_count`.
2026-05-05 18:17:07 -04:00
dependabot[bot] bc2802abed build(deps): bump clap_complete from 4.6.2 to 4.6.3 in the cargo group
Bumps the cargo group with 1 update: [clap_complete](https://github.com/clap-rs/clap).


Updates `clap_complete` from 4.6.2 to 4.6.3
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.6.2...clap_complete-v4.6.3)

---
updated-dependencies:
- dependency-name: clap_complete
  dependency-version: 4.6.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-05 08:19:48 +02:00
dependabot[bot] 16e48018b3 ci: bump korthout/backport-action in the actions group
Bumps the actions group with 1 update: [korthout/backport-action](https://github.com/korthout/backport-action).


Updates `korthout/backport-action` from 4.4.0 to 4.5.0
- [Release notes](https://github.com/korthout/backport-action/releases)
- [Commits](https://github.com/korthout/backport-action/compare/v4.4.0...v4.5.0)

---
updated-dependencies:
- dependency-name: korthout/backport-action
  dependency-version: 4.5.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-05 08:19:21 +02:00
Christian Clason 85f985a778 build(deps): bump wasmtime-c-api to v36.0.8 2026-05-05 08:19:02 +02:00
Will Lillis 8d737aa238 docs: note zero point unbounded behavior in query functions 2026-04-30 04:28:59 -04:00
dependabot[bot] aedab6e0f2 build(deps): bump postcss from 8.5.8 to 8.5.12 in /lib/binding_web
Bumps [postcss](https://github.com/postcss/postcss) from 8.5.8 to 8.5.12.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.5.8...8.5.12)

---
updated-dependencies:
- dependency-name: postcss
  dependency-version: 8.5.12
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-29 11:12:37 +02:00
dependabot[bot] fb3e029911 ci: bump the actions group with 2 updates
Bumps the actions group with 2 updates: [korthout/backport-action](https://github.com/korthout/backport-action) and [actions/setup-node](https://github.com/actions/setup-node).


Updates `korthout/backport-action` from 4 to 4.4.0
- [Release notes](https://github.com/korthout/backport-action/releases)
- [Commits](https://github.com/korthout/backport-action/compare/v4...v4.4.0)

Updates `actions/setup-node` from 6.3.0 to 6.4.0
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v6.3.0...v6.4.0)

---
updated-dependencies:
- dependency-name: korthout/backport-action
  dependency-version: 4.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
- dependency-name: actions/setup-node
  dependency-version: 6.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-28 09:30:25 +02:00
dependabot[bot] 6c674cb5bd build(deps): bump cc from 1.2.60 to 1.2.61 in the cargo group
Bumps the cargo group with 1 update: [cc](https://github.com/rust-lang/cc-rs).


Updates `cc` from 1.2.60 to 1.2.61
- [Release notes](https://github.com/rust-lang/cc-rs/releases)
- [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.2.60...cc-v1.2.61)

---
updated-dependencies:
- dependency-name: cc
  dependency-version: 1.2.61
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-28 09:29:50 +02:00
Wilco Kruijer fb348c3493 wasm: add Language.loadSync for synchronous loading
Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-04-26 18:58:50 -04:00
Amaan Qureshi 43dc8eadbe query: fix finished state heap invariants 2026-04-26 18:03:55 -04:00
Will Lillis 123fb1c13c perf(query): use min-heap for finished_states in next_capture
`ts_query_cursor_next_capture` linearly scanned all finished states to
find the one with the earliest next capture byte offset. With deeply
nested code, this O(n) scan per capture caused the highlight crate to
hang for minutes on large files.

Replace the linear scan with a min-heap over the finished_states array,
keyed by (next_capture_byte_offset, pattern_index, id). The heap is
maintained lazily: ts_query_cursor__advance uses plain array_push
(preserving FIFO insertion order), and next_capture sifts new elements
into the heap on entry via a tracked heap_size boundary. This preserves
the documented "order found" guarantee for next_match while giving
next_capture O(log n) per call.
2026-04-26 18:03:55 -04:00
Will Lillis 361f293a73 fix(query): widen capture list pool from uint16_t to uint32_t
Commit 1f6eac55 ("query: Use uint32_t for capture list IDs") widened
QueryState.capture_list_id to uint32_t and removed the 65536 pool cap,
but left the pool function signatures as uint16_t. This caused silent
truncation when the pool exceeded 65535 entries, leading to a segfault.
2026-04-26 18:03:55 -04:00
Amaan Qureshi e24c109c82 ci: run on illumos 2026-04-26 13:23:32 -04:00
Petr Sumbera 77cb23fccc lib: add Solaris support to the portable endian header
Solaris does not provide <endian.h> or <sys/endian.h>, but it does expose
byte-order definitions and conversion helpers via <sys/isa_defs.h> and
<sys/byteorder.h>.

Add a __sun branch so the portable header defines __BYTE_ORDER and the
htobe*/le*toh conversions on Solaris.

Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-04-26 13:23:32 -04:00
Daniel Jalkut 0f6780b9a3 lexer: pass code-unit length to U16_NEXT in UTF-16 decoders
`ts_decode_utf16_le` and `ts_decode_utf16_be` passed a byte length to
`U16_NEXT_LE` and `U16_NEXT_BE`, but those macros count `uint16_t` code
units. If a lead surrogate was the last code unit in a chunk, the decoder
could peek past the chunk and combine it with adjacent memory.

This commit passes the code-unit length to the UTF-16 macros, and fails
with `TS_DECODE_ERROR` when a chunk is too short to contain even one full
code unit. This lets the lexer retry with a fresh chunk or advance through
the invalid byte as it already does.

Co-authored-by: Will Lillis <will.lillis24@gmail.com>
Co-authored-by: Amaan Qureshi <git@amaanq.com>
2026-04-26 03:38:47 -04:00
Amaan Qureshi 475c48d1e3 docs: add AI policy
Co-authored-by: Christian Clason <c.clason@uni-graz.at>
2026-04-26 02:58:56 -04:00
Will Lillis 457eb295b7 fix(generate): pass default optimization level in
`generate_parser_for_grammar`

Passing `empty` here causes some grammars (i.e. tree-sitter-cpp) to fail
to generate.
2026-04-24 08:52:18 +02:00
Antonin Delpeuch eccef997df
feat(dist): enable install via cargo binstall (#5533) 2026-04-24 08:52:01 +02:00
Will Lillis 15154504de fix(ci): include fixture lockfile in cache hash 2026-04-23 03:31:00 -04:00
Will Lillis d6e33d0722 test: bump c test fixture to v0.24.2 2026-04-23 03:31:00 -04:00
Volker Mische 4cb11acd46
fix(loader): allow filenames with dots (#5529) 2026-04-22 03:41:04 -04:00
dependabot[bot] 4701df97c0 build(deps): bump the cargo group with 3 updates
Bumps the cargo group with 3 updates: [clap_complete](https://github.com/clap-rs/clap), [webbrowser](https://github.com/amodm/webbrowser-rs) and [bitflags](https://github.com/bitflags/bitflags).


Updates `clap_complete` from 4.6.1 to 4.6.2
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.6.1...clap_complete-v4.6.2)

Updates `webbrowser` from 1.2.0 to 1.2.1
- [Release notes](https://github.com/amodm/webbrowser-rs/releases)
- [Changelog](https://github.com/amodm/webbrowser-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/amodm/webbrowser-rs/compare/v1.2.0...v1.2.1)

Updates `bitflags` from 2.11.0 to 2.11.1
- [Release notes](https://github.com/bitflags/bitflags/releases)
- [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitflags/bitflags/compare/2.11.0...2.11.1)

---
updated-dependencies:
- dependency-name: clap_complete
  dependency-version: 4.6.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: webbrowser
  dependency-version: 1.2.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: bitflags
  dependency-version: 2.11.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-21 09:38:08 +02:00
dependabot[bot] 5c1dd38c45 ci: bump actions/setup-node from 6 to 6.3.0 in the actions group
Bumps the actions group with 1 update: [actions/setup-node](https://github.com/actions/setup-node).


Updates `actions/setup-node` from 6 to 6.3.0
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v6...v6.3.0)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: 6.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-21 09:37:49 +02:00
Chinmay Dalal 20bdf3a8a0
feat(bindings): update zig template to 0.16 2026-04-20 09:31:18 +02:00
changw98ic aff9b9d92e fix: update broken link to Parser.Language in template
The link `https://tree-sitter.github.io/node-tree-sitter/interfaces/Parser.Language.html` returns a 404 error.

In the current typedoc output, the Language interface is at `/interfaces/Language.html` (without the `Parser.` prefix), as the documentation flattens namespace members.

Fixes #5525
2026-04-17 08:20:05 +02:00
Chinmay Dalal 24a64db7cc build(zig): update to zig 0.16 2026-04-15 14:54:53 +02:00
dependabot[bot] b3a752aa5b ci: bump the actions group with 2 updates
Bumps the actions group with 2 updates: [actions/upload-pages-artifact](https://github.com/actions/upload-pages-artifact) and [actions/github-script](https://github.com/actions/github-script).


Updates `actions/upload-pages-artifact` from 4 to 5
- [Release notes](https://github.com/actions/upload-pages-artifact/releases)
- [Commits](https://github.com/actions/upload-pages-artifact/compare/v4...v5)

Updates `actions/github-script` from 8 to 9
- [Release notes](https://github.com/actions/github-script/releases)
- [Commits](https://github.com/actions/github-script/compare/v8...v9)

---
updated-dependencies:
- dependency-name: actions/upload-pages-artifact
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/github-script
  dependency-version: '9'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-14 08:19:47 +02:00
dependabot[bot] 63b7d3b811 build(deps): bump rand from 0.10.0 to 0.10.1
Bumps [rand](https://github.com/rust-random/rand) from 0.10.0 to 0.10.1.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/compare/0.10.0...0.10.1)

---
updated-dependencies:
- dependency-name: rand
  dependency-version: 0.10.1
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-14 08:18:47 +02:00
Christian Clason 75fe13e7aa build(deps): cargo update 2026-04-11 18:29:00 -04:00
Christian Clason 8178cfddd8 build(deps): bump wasmtime-c-api to v36.0.7 2026-04-10 00:41:06 +02:00