fix(wasm): load supertype tables for ABI 15 grammars#5605
Conversation
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.
|
Successfully created backport PR for |
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>
|
@amaanq @WillLillis @clason Are you guys ok with doing a 0.26 patch release just for this? |
|
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. |
|
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 🙂 |
|
Yes, #5569 Seems like it'd be good to get in too. |
|
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. |
|
While we wait, you could take a look at @WillLillis' last comment on the CSR PR ;) |
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.
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.
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.
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.
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 forLANGUAGE_VERSION_WITH_RESERVED_WORDSand fixes the crash.This was observed as a SIGSEGV in
ts_language_subtypesreaching 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.