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.
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.
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.
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.
Decode a compilation priority and, if present, an optimization priority. Trailing bytes are ignored rather than rejected, per the proposal's forward-compatibility rule.