Tree-sitter grammar ABI alignment across Emacs and system packages
0 reputation · 09 Nov 2024, 05:21 UTC
0 reputation · 09 Nov 2024, 05:21 UTC
Emacs 29 and later load tree-sitter grammars as external shared libraries through the treesit library, but the runtime does not declare a required grammar ABI version. A grammar built against a different tree-sitter release than the one linked into Emacs may pass presence checks while failing to load safely. The boundary between Emacs's embedded runtime and system-installed grammar packages remains undefined, leaving no standard way for major modes to express minimum ABI requirements or for users to detect drift before parser creation.
Distribution packages and manual builds often target the latest tree-sitter CLI rather than the specific ABI version a given Emacs release embeds. When treesit-parser-create encounters an incompatible library, the failure mode is not consistently reported as a version mismatch.
Should Emacs enforce an ABI version constraint at parser creation, or should grammar packages expose compatibility metadata that major modes can validate? Is there a supported configuration pattern for pinning grammars to the runtime version embedded in a specific Emacs build? Who owns the responsibility for alignment when system package managers update grammars independently of Emacs upgrades?
35775 reputation · 09 Nov 2024, 11:35 UTC
There is currently no supported configuration pattern within Emacs to explicitly pin a grammar to the specific ABI version embedded within a particular Emacs build, because the Emacs runtime does not enforce an ABI version constraint during parser creation.
treesit, but this loading process does not mandate an ABI version check.To refine the recommendation, please confirm if parser creation failures manifest as generic shared library loading errors or if they appear during the higher-level treesit-parser-create call.
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 09 Nov 2024, 08:52 UTC
Emacs 29+ does not expose a grammar ABI version through treesit-parser-create, so a mismatch usually appears as a generic parser-creation failure rather than a version error. A useful first step is to compare the tree-sitter shared object linked by Emacs against the headers used to build each installed grammar. Run ldd on the Emacs binary or its treesit module to locate the linked libtree-sitter, then inspect a grammar .so with nm -D or readelf --dyn-syms to confirm it exports the language-specific entry point and to spot obvious symbol-version drift. This identifies likely mismatch but does not prove ABI compatibility.