Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Zed 7 min read Deep dive mediumAdept

Extensible Language Support in Zed - Part 1

Zed loads third-party Tree-sitter grammars as WebAssembly modules using a hybrid design. Native code consumes the parser's static parse tables after they are copied out of wasm linear memory, while only the lexing functions, including hand-written external scanners, run inside Wasmtime. This avoids depending on the user's C compiler and keeps buggy scanners from crashing the editor. It also avoids copying large syntax trees out of wasm memory on every keystroke. A new `WasmStore` API lets wasm-loaded languages behave identically to native ones, and a bundled mini-libc with a bump allocator that is reset each parse makes scanner memory leaks impossible.

Assumes: Tree-sitter basicsWebAssembly linear memorylexing and parsing concepts

Related posts

  • Life of a Zed Extension: Rust, WIT, Wasm

    Zed mediumAdept

    Zed extensions are written in Rust but never compiled on the user's machine. A CI step in the zed-industries/extensions repository runs a small extensions CLI that compiles each extension's Rust code to a Wasm component targeting wasm32-wasip1 and its Tree-sitter grammars to Wasm. It packages them with Tree-sitter query files into an archive plus a manifest.json, uploads both to S3, and zed.dev mirrors the manifests into a database for the in-editor extension list. The extension API is a hand-written Rust trait layered over types that wit_bindgen generates at compile time from WIT definitions, so the WebAssembly Component Model can pass strings, records and resources like Worktree between the Wasm module and the Zed host.

  • A new way to bring garbage collected programming languages efficiently to WebAssembly · V8

    V8 hardMaster

    Garbage-collected languages like Java, Kotlin, Dart, Python and C# can reach WebAssembly in two ways: compile an existing language VM to linear-memory WasmMVP, or lower the language's objects onto WasmGC structs and arrays managed by the host VM's garbage collector. WasmGC produces smaller binaries because no GC or malloc is shipped, collects cycles between JS and Wasm at fine granularity, sees stack references without shadow stacks, and avoids linear-memory fragmentation. It also reuses the browser's generational and incremental GC and integrates with DevTools heap profiling. The costs are substantial new toolchain work and possible compromises in language semantics, since struct fields have fixed indexes and types and there are no interior pointers, whereas a traditional port preserves exact semantics with little effort. Later sections cover V8 and toolchain optimizations for WasmGC, with benchmark numbers.

  • Contributing support for a Wasm instruction to Winch

    Shopify Engineering hardMaster

    Adding a WebAssembly instruction to Winch, Wasmtime's baseline non-optimizing compiler, touches several layers: the wasmparser VisitOperator visitor, the CodeGenContext that manages the value stack, register allocation and spilling, an ISA-independent MacroAssembler, and an x86_64 assembler built on Cranelift's ISLE-generated instruction definitions. The i32.clz example shows how the MacroAssembler emits lzcnt when the CPU supports it and otherwise falls back to a bsr/setne sequence. Changes are tested in two ways: filetests check the emitted machine code without running it, so they work on AArch64 Macs, and differential fuzzing on x86_64 hardware compares Winch's results against another Wasm engine.

  • Enabling low-latency, syntax-aware editing using Tree-sitter

    Zed mediumAdept

    Zed builds its syntax-aware features on Tree-sitter, a GLR-based incremental parsing framework with error recovery that produces concrete syntax trees. Syntax-aware selection uses the CST directly. Highlighting, symbol outlines, auto-indentation and language injections are each driven by declarative Tree-sitter queries, which compile to state machines matched in a single depth-first walk, so adding a language needs only a grammar and query files. Injected trees, such as JavaScript inside HTML or Rust macro arguments, are kept in a copy-on-write B-tree called a sum tree, which lets edits be re-parsed incrementally on a background thread while the main thread keeps reading the previous snapshot.

  • Why is WebAssembly a second-class language on the web?

    Mozilla Hacks mediumAdept

    WebAssembly remains second-class on the web because it can only load code and reach Web APIs through JavaScript. That forces arcane instantiation boilerplate, language-specific glue code from tools like wasm-bindgen and embind, JS-centric documentation, and real runtime overhead. A 2020 TodoMVC experiment with the Dodrio Rust framework found that removing JS glue cut DOM-update time by 45%. The esm-integration proposal, being implemented in Firefox, simplifies loading, and the WebAssembly Component Model with WIT interfaces is proposed as a standardized artifact that could let Wasm call Web APIs directly with no JavaScript in between.

The quest for software engineering knowledge.

Look:
Layout: