package wax-lib
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=4361e1324b7754a4c08ab5b505df32061f3ce0cea60443fd0d3699e0fa796b32
sha512=fcc756d2f160ba90a9aa1131f2ab22ed7f45466ccd658c21cf9df6868a6aab0cee7f404719d698a379958802f9820398f2fe0685ecc4dda018ca4f653294e39b
doc/wax-lib.wasm/Wax_wasm/Hints/index.html
Module Wax_wasm.HintsSource
Optional compiler hints carried by an instruction.
The branch-hinting and compilation-hints proposals both attach advisory metadata to an instruction through a metadata.code.* custom section keyed by the instruction's byte offset from the start of the function body. The hints have no effect on behaviour: an engine is free to ignore them, and dropping one changes only performance, never semantics.
Hints live in a field of the instruction record rather than in a wrapper node, so that the pervasive matches on an instruction's desc neither see them nor have to see through them. The cost is that a pass which rebuilds an instruction from scratch (instead of with { i with desc = ... }) drops its hints — a lost hint, never a mistyped program.
A hint belongs on the operation itself, never on a Folded wrapper around it: the branch opcode is emitted only after the folded operands, so that is where the encoder takes the offset and where the decoder puts it back.
'idx is how the enclosing AST spells a function reference: an index or a name in the Wasm ASTs, an identifier in Wax.
A hint value together with the span of the annotation or attribute it was written as, so that a diagnostic about a misplaced or malformed hint is blamed at the hint rather than at the instruction it decorates. A hint recovered from a binary was never written down and takes the instruction's own span.
The wire byte of a metadata.code.instr_freq hint: an offset base-2 logarithm of the instruction's expected executions per call of its function, so 32 means once. 0 means "never optimize" and 127 "always optimize"; the proposal's formula otherwise clamps to [1, 64]. Kept as the raw byte so that a value a hand-written binary put outside that range still round-trips.
type 'idx t = {branch : bool hint option;(*
*)metadata.code.branch_hint:Some true= likely taken.freq : freq hint option;(*
*)metadata.code.instr_freq.targets : ('idx * int) list hint option;(*
*)metadata.code.call_targets: the likely targets of an indirect call with each one's frequency as a percentage. The percentages must sum to at most 100; a shortfall says other, unlisted targets take the remainder.
}No hints at all — what an instruction carries unless something says otherwise.
branch loc likely t sets t's branch hint, written at loc.
freq loc f t sets t's instruction-frequency hint, written at loc.
targets loc l t sets t's call-target hint, written at loc.
map_targets f t rewrites the function references of t's call targets, for the conversions that change how an index is spelled.
Instruction frequency
The wire byte is an offset base-2 logarithm of the executions-per-call ratio: max 1 (min 64 (floor (log2 r) + 32)), so 32 means once. The endpoints saturate.
The ratio a byte stands for, or None for the two special values and for a byte a hand-written binary put outside the formula's range — those have no ratio and must round-trip through the raw payload.
Wire payloads
The byte strings the (@metadata.code.…) annotations spell, and the binary sections store.
Decode a run of LEB128 (function index, percentage) pairs. The indices are numeric: only the structured text form can name a target.
Compilation priority
metadata.code.compilation_priority is the one hint of this family that is per-function rather than per-instruction: it says how soon a function should be compiled, and how hard. It lives on the function rather than in t, and is keyed in the section at offset 0.
127: the optimization priority meaning the function runs once.
Decode a compilation priority and, if present, an optimization priority. Trailing bytes are ignored rather than rejected, per the proposal's forward-compatibility rule.