Skip to content

fix(wasm): load supertype tables for ABI 15 grammars#5605

Merged
maxbrunsfeld merged 1 commit into
masterfrom
fix/wasm-supertypes-abi-15
May 18, 2026
Merged

fix(wasm): load supertype tables for ABI 15 grammars#5605
maxbrunsfeld merged 1 commit into
masterfrom
fix/wasm-supertypes-abi-15

Conversation

@maxbrunsfeld

@maxbrunsfeld maxbrunsfeld commented May 18, 2026

Copy link
Copy Markdown
Contributor

Problem

Query construction can crash when grammars that use supertypes, are compiled with ABI version 15, and are loaded via Wasm.

Background

Supertypes were introduced in ABI version 15, the same ABI version that introduced reserved words. Methods that access a language's supertypes check that the grammar's ABI version is greater than or equal to 15.

But when loading a language via Wasm, we were neglecting to load supertype data unless the language's abi version was strictly greater than 15.

Switching the check to >= matches the convention used everywhere else for LANGUAGE_VERSION_WITH_RESERVED_WORDS and fixes the crash.

This was observed as a SIGSEGV in ts_language_subtypes reaching users via Zed loading tree-sitter grammars compiled to Wasm.

AI Use

I found this bug by showing Claude Opus 4.7 the crash backtrace and directing it to inspect ts_wasm_store_load_language, since that Wasm loading logic has been problematic in the past.

The wasm store gated supertype_symbols / supertype_map_slices /
supertype_map_entries copies on abi_version > LANGUAGE_VERSION_WITH_RESERVED_WORDS,
but every other consumer (language.c, query.c) treats those tables as
present when abi_version >= LANGUAGE_VERSION_WITH_RESERVED_WORDS.

A Wasm grammar built at ABI exactly 15 with supertype_count > 0 ends up
with supertype_count copied into the native TSLanguage but supertype_map_slices
left NULL. ts_query__analyze_patterns then calls ts_language_subtypes,
which dereferences self->supertype_map_slices[supertype] and crashes.
@maxbrunsfeld maxbrunsfeld enabled auto-merge (squash) May 18, 2026 20:32
@maxbrunsfeld maxbrunsfeld merged commit a53c3b0 into master May 18, 2026
22 checks passed
@maxbrunsfeld maxbrunsfeld deleted the fix/wasm-supertypes-abi-15 branch May 18, 2026 20:33
@tree-sitter-ci-bot

Copy link
Copy Markdown

Successfully created backport PR for release-0.26:

maxbrunsfeld added a commit that referenced this pull request May 18, 2026
The wasm store gated supertype_symbols / supertype_map_slices /
supertype_map_entries copies on abi_version > LANGUAGE_VERSION_WITH_RESERVED_WORDS,
but every other consumer (language.c, query.c) treats those tables as
present when abi_version >= LANGUAGE_VERSION_WITH_RESERVED_WORDS.

A Wasm grammar built at ABI exactly 15 with supertype_count > 0 ends up
with supertype_count copied into the native TSLanguage but supertype_map_slices
left NULL. ts_query__analyze_patterns then calls ts_language_subtypes,
which dereferences self->supertype_map_slices[supertype] and crashes.

(cherry picked from commit a53c3b0)

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
@maxbrunsfeld

Copy link
Copy Markdown
Contributor Author

@amaanq @WillLillis @clason Are you guys ok with doing a 0.26 patch release just for this?

@clason

clason commented May 19, 2026

Copy link
Copy Markdown
Member

We've been conscientious in backporting other fixes, so there's more than this in the pipeline.

Let me check if there are recently merged PRs missing a (merged) backport, then I can trigger the release if @WillLillis agrees.

@WillLillis

Copy link
Copy Markdown
Member

@maxbrunsfeld

The NO_COLOR fix that was bundled in with #5594 could be done separately on the release branch (without the painting changes) but isn't super important.

#5569 might be nice to have but that's completely up to you, I'm not sure how that would impact Zed.

Beyond those two I think our release branch is in solid shape, I don't see any issue with another patch release 🙂

@maxbrunsfeld

Copy link
Copy Markdown
Contributor Author

Yes, #5569 Seems like it'd be good to get in too.

@clason

clason commented May 19, 2026

Copy link
Copy Markdown
Member

Luckily it backported cleanly, so I'll merge it once the CI is green, re-trigger the release checks, and publish once they pass, too.

@clason

clason commented May 19, 2026

Copy link
Copy Markdown
Member

While we wait, you could take a look at @WillLillis' last comment on the CSR PR ;)

pull Bot pushed a commit to Jaleel-zhu/zed that referenced this pull request May 20, 2026
This PR upgrades `tree-sitter` to v0.26.9.

We're interested in
tree-sitter/tree-sitter#5605, which should fix a
panic when loading certain grammars.

Closes FR-1.

Release Notes:

- Fixed a panic when loading certain Tree-sitter grammars containing
supertypes.
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request May 20, 2026
This PR upgrades `tree-sitter` to v0.26.9.

We're interested in
tree-sitter/tree-sitter#5605, which should fix a
panic when loading certain grammars.

Closes FR-1.

Release Notes:

- Fixed a panic when loading certain Tree-sitter grammars containing
supertypes.
jasonsmithio pushed a commit to paddleboarddev/paddleboard that referenced this pull request May 31, 2026
This PR upgrades `tree-sitter` to v0.26.9.

We're interested in
tree-sitter/tree-sitter#5605, which should fix a
panic when loading certain grammars.

Closes FR-1.

Release Notes:

- Fixed a panic when loading certain Tree-sitter grammars containing
supertypes.
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 2, 2026
This PR upgrades `tree-sitter` to v0.26.9.

We're interested in
tree-sitter/tree-sitter#5605, which should fix a
panic when loading certain grammars.

Closes FR-1.

Release Notes:

- Fixed a panic when loading certain Tree-sitter grammars containing
supertypes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants