Sign in

    marianoguerra/wax/compile does not have a README file

    Define

    Conditional compilation resolved ahead of checking -- what -D does -- re-exported from the checker: parse_define reads one NAME[=VALUE], and specialize_defines resolves every conditional the defines decide, returning the source ranges it dropped so their comments can be dropped too (@trivia.Context::drop_in_ranges).

    CompileError

    What can stop a checked module from becoming output.

    Three packages sit on this path and each raises its own error: the lowering to the wasm module model, the binary encoder, and the text printer. A caller handed the open Error type can only print what it catches; naming the three lets it match on them, and says up front that there is no fourth.

    None of these are a rejected module. A module the checker rejected is reported through Session::reports and rejected before anything is lowered -- these are the lowering's own gaps, and reaching one on a module that checked clean is a bug in this port rather than in the input. The one exception is LowerError::AmbiguousBinding, which only a generated tree can reach and which names what the generator has to fix.

    CompileError::diagnostic

    The error as a located diagnostic, when it is the module's rather than this port's: a construct the binary format has no way to hold, which the reference refuses with the same diagnostic. None for a gap in the port, which is reported as one instead.

    Checked

    A module that has been through the type checker.

    It holds the four things the lowering needs and that a caller would otherwise have to keep together by hand: the session (for its type store), the module context the checker built, the source AST, and the per-node inferred types the checker left alongside it. The lowering reads the types off typed, which is the entire interface between the two stages.

    Holding a Checked is NOT a claim that the module is valid -- see Session::check. Lowering one the checker rejected raises, or produces a module derived from something known to be wrong.

    Checked::rewrite_legacy_try

    The module with each legacy try_legacy rewritten into the structured try, which lowers to the standard try_table (--try-table on a Wax-to-Wax conversion).

    The rewrite needs the types the checker inferred -- an unannotated try takes its result type from its context -- which is why it is a step of a CHECKED module. A legacy try that takes parameters has no structured equivalent and is reported to the session.

    Checked::to_bytes

    fn Checked::to_bytes(self : Checked, label_names? : Bool, try_table? : Bool) -> Bytes raise CompileError

    Encode to a .wasm binary.

    label_names false leaves the label names out of the name section: Binaryen's wasm-opt does not know that subsection and warns about it.

    Checked::to_module

    fn Checked::to_module(self : Checked, keep_conditionals? : Bool, try_table? : Bool) ->
    Module
    raise
    LowerError

    Lower to the wasm module model, shared by both output forms.

    keep_conditionals retains the conditional sections rather than resolving them, which only the text form wants: a module with an unresolved conditional has no single binary form, and that is what a conditional is for.

    try_table rewrites the legacy try/catch into the standard try_table, for engines and tools that only accept the current exception-handling proposal.

    Checked::to_wat

    fn Checked::to_wat(self : Checked, trivia? :
    Context
    , try_table? : Bool) -> String raise CompileError

    Print in the WebAssembly text format.

    The same lowered module the binary form comes from, printed rather than encoded, so the two cannot drift. trivia carries the source comments; they were written against Wax source and come out as WAT comments, with the same text and different delimiters.

    Session

    One compilation.

    A session is single-use per module. The type store it carries is filled by checking, so checking a second module through the same session would build on the first module's type section.

    Session::check

    Type-check a module.

    This ALWAYS returns a Checked, even for a module it rejected, because whether a run is rejected is not decided here: a warning is hidden, shown or promoted to an error by a @warning.Policy the caller owns. Ask reports for the diagnostics under that policy and rejected whether they stop the compilation, and only then lower.

    warn_unused turns on the lints that report what a module declares and never uses. It is off by default because a conversion reports what stops it producing a module and a style warning does not -- the reference draws the same line, and wax f.wax -f wasm is silent on a module wax check comments on.

    lowering says the module is checked to be converted to wasm or WAT: a conditional module is then also rejected for a construct whose form differs between its configurations, which each configuration accepts on its own but no single lowered module can express.

    suggest also offers the machine-applicable simplifications -- a redundant annotation, a compound assignment, a punned field -- as Suggestion diagnostics carrying their edits; they are shown only where the warning policy enables them, as wax check does.

    Session::new

    fn Session::new(features? :
    Set
    , source? : String) -> Session

    Start a compilation.

    source is the module's text, used only to render snippets in diagnostics. A generator that has no text to point at leaves it out; the diagnostics then carry their locations and their messages and no excerpt.

    Session::reports

    What the compilation reported, under policy.

    Without a policy this is the raw collection, warnings and all. With one, a hidden warning is dropped and a promoted one comes back with severity Error -- which is what makes -W name=error mean something, and why a lint that is off by default costs nothing to have implemented.

    apply_policy

    Resolve every named warning in collected against policy.

    The collector buffers diagnostics RAW: the policy belongs to whoever finally re-reports them. Order is preserved, hidden warnings are dropped, and a warning promoted to an error comes back with its severity replaced rather than duplicated.

    parse_define

    fn parse_define(s : String) -> Result[(String,
    Define
    ), String]

    Parse one -D argument: a bare name, or NAME=true, sets a boolean; NAME=false clears it; NAME=A.B.C with three non-negative integers sets a version; anything else sets a string. The name must be a Wax identifier -- a keyword is allowed -- since no conditional could name anything else.

    rejected

    fn rejected(diagnostics : Array[
    Diagnostic
    ]) -> Bool

    Whether any of these diagnostics rejects the module.

    Apply the policy first: a warning promoted to an error rejects, and one hidden by the policy does not.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io