package wax-lib
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=4361e1324b7754a4c08ab5b505df32061f3ce0cea60443fd0d3699e0fa796b32
sha512=fcc756d2f160ba90a9aa1131f2ab22ed7f45466ccd658c21cf9df6868a6aab0cee7f404719d698a379958802f9820398f2fe0685ecc4dda018ca4f653294e39b
doc/wax-lib.wasm/Wax_wasm/Resolve/index.html
Module Wax_wasm.ResolveSource
Name resolution for Wasm-text modules: maps each use of an index (a symbolic $id or a numeric index) to the definition it refers to, with source spans on both ends. This is the WAT counterpart of the use -> definition table the Wax type checker builds (Wax_lang.Typing.reference), and it powers the editor's go-to-definition, find-references, document-highlight and rename for Wasm text.
It is a pure structural pass over the AST — no type checking — so it is cheap and never raises, and is safe to run on the best-effort parse of a broken buffer.
type binding = {defs : Ast.location list;(*The span of each definition's
*)$id. Usually one; several when the same name is defined in more than one conditional-compilation branch (each an alternative). Empty for an anonymous (numeric-only) definition.uses : Ast.location list;(*Every use site's span — the
*)$idor numeric-index token of each reference.kind : kind;hover : string option;(*A one-line summary for hover over the name.
*)
}type expected = {e_loc : Ast.location;(*The span of an index use — a symbolic
*)$id, a numeric index, or the zero-width point where error recovery inserted a placeholder0for a missing one.e_candidates : unit -> (string * kind * string option) list;(*The named definitions in scope at
*)e_locfor the index space expected there: each(name without [$], kind, hover). A thunk so a consumer pays the snapshot only for the one use-site it cares about. Empty when nothing of that kind is in scope.e_type_slot : type_slot option;(*Some slot at a type position: abstract heap types (Heaptype), reference type abbreviations (Reftype), or value types (Valtype) are legal here in addition to/instead of index names.
*)
}Where an index is expected, for completion: the kind of index a position wants is fixed by the instruction it sits in, so recovery inserting a placeholder index lets the editor offer exactly the names of that space.
f modul returns one binding per named symbol, across every module-level index space (functions, globals, types, memories, tables, tags, elem and data segments), plus each function's locals and labels and each struct type's fields. Labels obey lexical scoping with shadowing; locals are per-function. A name defined in several conditional-compilation branches yields one binding carrying all its definition spans. A binding with an empty uses list is simply unreferenced.
When expected is given, every index use-site is appended to it as an expected (whether or not it resolves), so completion can find the one at the cursor and offer the in-scope names of the space it wants. Off (no recording) otherwise.