component "Tools and diagnostics · Weft manual" on browser
state contents: u1 = 0 public
view opened "Chapter list open" = contents
view closed "Chapter list closed" = not contents
action open_contents "Browse chapters" when not contents
  set contents = 1
  ensures can_close = enabled(close_contents)
end
action close_contents "Hide chapters" when contents
  set contents = 0
  ensures can_open = enabled(open_contents)
end
claim navigation = enabled(open_contents) == shown(closed) and enabled(close_contents) == shown(opened)
page "Use the native compiler to build a component, check files already on disk, run event traces, inspect proof obligations, and measure dispatch. The commands below run from the extracted weft directory."
  a "Skip to chapter" href "#chapter" class "skip"
  header class "bar frame"
    div class "brandgroup"
      a href "/" class "brand" label "Weft home"
        span class "mark"
        span "Weft"
      a "Manual" href "/docs/" class "booklink"
    nav label "Site navigation"
      a "Language home" href "/"
      a "Get the compiler ↗" href "/#download" class "get"
  div class "layout frame"
    aside class "rail"
      div class "railinner"
        p "Language manual" class "railtitle"
        press open_contents when closed class "menubutton openmenu"
        press close_contents when opened class "menubutton"
        nav label "Chapters" class "chapters"
          a "Overview" href "/docs/"
          a "Your first component" href "/docs/start/"
          a "Language design" href "/docs/design/"
          a "Syntax and primitives" href "/docs/language/"
          a "Proving UI behavior" href "/docs/behavior/"
          a "Proving information flow" href "/docs/information-flow/"
          a "Pages and styling" href "/docs/pages/"
          a "WebAssembly and hosts" href "/docs/wasm/"
          a "Tools and diagnostics" href "/docs/toolchain/" class "current"
    main id chapter class "reader"
      p "Toolchain reference" class "kind"
      h1 "Tools and diagnostics"
      p "Use the native compiler to build a component, check files already on disk, run event traces, inspect proof obligations, and measure dispatch. The commands below run from the extracted weft directory." class "lead"
      nav label "On this page" class "onpage"
        a "Install" href "#install"
        a "Commands" href "#commands"
        a "Receipts and replay" href "#receipts"
        a "Diagnostics" href "#diagnostics"
        a "Performance" href "#perf"
      section id install
        h2 "Install or build the toolchain"
        p "On Apple Silicon macOS, extract the binary distribution and change into the weft directory. It includes bin/weft, the native dependencies, browser assets, examples, and source. Start with a build to create or refresh the artifacts used by later commands."
        pre
          code "bin/weft build examples/ballot.weft\nbin/weft check examples/ballot.weft"
        a "Download the Apple Silicon distribution" href "/weft-macos-arm64.zip"
        a "Download the C source distribution" href "/weft-source.zip"
        p "For a source build, install a C11 compiler, make, xxd, json-c, Z3 with C headers, and the Wasmtime C SDK. Linux builds also link libcrypto for SHA-256. Each PREFIX points to a directory containing include/ and lib/. Adjust the example paths to match your installation. The packaged binary targets macOS arm64."
        pre
          code "make -j4 Z3_PREFIX=/usr WASMTIME_PREFIX=/opt/wasmtime JSON_PREFIX=/usr\nbin/weft build examples/vault.weft\nbin/weft run examples/vault.weft rotate=143 status"
      section id commands
        h2 "Command reference"
        pre
          code "bin/weft COMMAND FILE.weft [-o DIR] [arguments]"
        dl
          dt "build FILE [-o DIR]"
          dd "Parse, type-check, emit, and verify. The default output is build/<source stem>. The destination receives app.wasm, interface.json, and verification.json, plus the three browser assets for a component with a page."
          dt "check FILE [-o DIR]"
          dd "Read the interface and module on disk, verify them against the source, check generated page assets when applicable, and compare the saved receipt. Use after copying a build or before admitting it to a host."
          dt "smt FILE [-o DIR]"
          dd "Revalidate a saved build and write SMT-LIB queries on standard output. A separate Z3 command-line executable can replay them. Verify the weft command exits successfully before relying on the output."
          dt "run FILE [-o DIR] [ACTION[=VALUE] ...]"
          dd "Recheck and execute the module in Wasmtime. Inputs are decimal and must fit the action width. The command prints the owner’s initial view and an event, view, and outbox row for each dispatch."
          dt "serve FILE [-o DIR] [--port N]"
          dd "Recheck and serve a browser-owned component on loopback. The default port is 8080. Port 0 selects a free port. Run from the project root or set WEFT_ASSETS to the directory containing the browser support files."
          dt "bench FILE [-o DIR] [ACTION]"
          dd "Recheck and run a native dispatch microbenchmark. An omitted action selects the first declared action. After warm-up it reports five samples of one million dispatches each. An action guard may disable later iterations, so choose a workload that measures the transition you intend."
        p "The long spelling --out is equivalent to -o. All commands except build consume existing files from that destination. If you build with -o, pass the same directory to check, smt, run, serve, and bench."
        pre
          code "bin/weft build examples/ballot.weft -o build/demo\nbin/weft run examples/ballot.weft -o build/demo choose=3 annotate=2 review share\nbin/weft serve examples/ballot.weft -o build/demo --port 0"
      section id receipts
        h2 "Inspect and replay proofs"
        p "Open verification.json. Its format field is 1. The component and method fields identify the component and QF_BV / UNSAT method. The sha256 object identifies the source file, Wasm binary, and exact interface bytes. obligations lists the named successful checks. Individual names tell you which action, property, and recipient each result concerns."
        pre
          code "bin/weft build examples/ballot.weft\nbin/weft smt examples/ballot.weft > build/ballot/obligations.smt2\nz3 build/ballot/obligations.smt2"
        p "Each query asks whether a counterexample exists. A successful replay prints unsat for every query. The release ballot has 70 obligations and the vault has 16. Each source change can alter the list. The receipt contains the obligation names and digests. To re-establish the result, run check with the matching toolchain and source."
        a "Inspect the ballot receipt" href "/docs/examples/ballot/verification.json"
        a "Download the ballot’s replayable SMT-LIB queries" href "/docs/examples/ballot/obligations.smt2"
      section id diagnostics
        h2 "Interpret a failure"
        dl
          dt "initial / NAME · induction / ACTION / NAME"
          dd "Inspect the initializer or the named transition. For induction, the solver assumes the conjunction of all the claims in the pre-state. Each claim must still have a valid base case."
          dt "postcondition / ACTION / NAME"
          dd "Examine the action guard and its pre-state writes. In ensures, plain fields refer to the next state. Compare a retained value to old(field)."
          dt "channel policy / ACTION / PEER"
          dd "The named step emitted to the peer under a disallowed action or pre-state. An emitted zero still occupies its slot."
          dt "noninterference / ACTION / PEER or FIELD from GROUP"
          dd "Compare the two executions, conventionally marked s and t. Look for changes in public fields, observed payloads, or observed presence. A protect rule also requires equality for every other field."
          dt "domain · uniform coins · reconstruction"
          dd "These obligations check result widths, the domain-preserving inverse of a randomness pairing, and reconstruction of an enabled split. Inspect source widths, recipient order, the split operand, and the trusted encodings when investigating a failure."
          dt "Wasm refinement / EXPORT · unsupported Wasm opcode"
          dd "The saved module disagrees with the source for a legal input, or the checker cannot interpret its profile. Verify that the checked bytes are the intended release artifact."
          dt "interface differs from source · page artifact mismatch · verification receipt mismatch"
          dd "Match the interface, page files, receipt, and source to the same build. Rebuild any intended source change and ship the complete artifact set together."
          dt "expected predicate · narrowing assignment · invalid view or guard reference"
          dd "Use a u1 condition, a sufficiently wide destination, and an expression legal in that context. The syntax chapter lists the permitted references."
          dt "unresolved"
          dd "The solver returned unknown or hit its configured 15-second query timeout. The check exits unsuccessfully. Simplify the relevant rule or encoding and rerun the proof."
        p "A satisfiable query prints a witness. Names such as s.state.vote identify the compared pre-state field. s.event.choose.value is the corresponding payload. Bit-vector model values may be binary or hexadecimal. Interpret the model within the obligation’s assumptions. A disabled-state witness for an unrelated claim is a different problem from a failed enabled postcondition."
      section id perf
        h2 "Measure the work you care about"
        p "Set WEFT_TIMING=1 to see frontend and verification times. make bench also measures in-memory parsing and code generation and native Wasmtime dispatch. make test runs regression cases, including deliberately invalid source and a valid Wasm module with the wrong semantics. The browser test requires Chromium and the ballot build."
        pre
          code "WEFT_TIMING=1 bin/weft build examples/ballot.weft\nbin/weft bench examples/ballot.weft choose\nmake test\nmake browser-test"
        p "Measure a browser click separately from a direct Wasm call. Entropy, DOM updates, network requests, and painting are different costs. The supplied benchmark report names the machine, workload, and sampling method."
        a "Read performance measurements and methodology" href "/docs/performance.txt"
      nav label "Adjacent chapters" class "pager"
        a "← WebAssembly and hosts" href "/docs/wasm/"
        a "Manual overview →" href "/docs/"
  footer class "foot frame"
    a "Weft" href "/" class "brand"
    a "Page source" href "./page.weft"
    a "Build receipt" href "./verification.json"
end
style "*"
  box_sizing "border-box"
end
style "html"
  scroll_padding_top "24px"
end
style "body"
  margin "0"
  background "#f7f5ec"
  color "#20291e"
  font_family "\"DM Sans\", \"Helvetica Neue\", Arial, sans-serif"
  line_height "1.62"
end
style "a"
  color "#2d553a"
  text_underline_offset ".19em"
  text_decoration_thickness "1px"
end
style "a:hover"
  color "#944420"
end
style "a:focus-visible, button:focus-visible"
  outline "3px solid #067685"
  outline_offset "4px"
end
style ".frame"
  width "min(1248px, 91%)"
  margin "0 auto"
end
style ".skip"
  position "absolute"
  top "-90px"
  left "12px"
  background "white"
  padding ".75rem"
  z_index "5"
end
style ".skip:focus"
  top "8px"
end
style ".bar, .brandgroup, .bar nav, .brand, .foot, .pager"
  display "flex"
  align_items "center"
end
style ".bar"
  min_height "78px"
  justify_content "space-between"
  border_bottom "1px solid #bfc4b2"
end
style ".brand, .bar a, .foot a"
  color "inherit"
  text_decoration "none"
end
style ".brand"
  gap ".55rem"
  font_size "1.55rem"
  font_weight "750"
  letter_spacing "-.065em"
end
style ".mark"
  width "26px"
  height "28px"
  background "repeating-linear-gradient(128deg,transparent 0 3px,#263622 3px 6px),repeating-linear-gradient(48deg,transparent 0 5px,#617859 5px 8px)"
  transform "skewY(-6deg)"
end
style ".booklink"
  border_left "1px solid #b9bfac"
  margin_left "1.1rem"
  padding_left "1.1rem"
  font_size "1rem"
end
style ".bar nav"
  font_size ".9rem"
  gap "1.4rem"
end
style ".get"
  border "1px solid #879078"
  border_radius "30px"
  padding ".38rem .85rem"
end
style ".layout"
  display "grid"
  grid_template_columns "minmax(190px, 245px) minmax(0, 1fr)"
  gap "clamp(2.5rem, 6vw, 7rem)"
  align_items "start"
  padding "clamp(2.5rem, 5vw, 5rem) 0 4rem"
end
style ".rail"
  position "sticky"
  top "1.5rem"
  max_height "calc(100vh - 3rem)"
  overflow_y "auto"
end
style ".railtitle, .kind, .codehead"
  font_family "\"IBM Plex Mono\", Menlo, monospace"
  text_transform "uppercase"
  letter_spacing ".095em"
  font_size ".72rem"
  font_weight "650"
  color "#4b6245"
end
style ".railtitle"
  margin "0 0 .9rem .75rem"
end
style ".chapters"
  display "grid"
  gap "3px"
  border_left "1px solid #bcc3af"
end
style ".chapters a"
  padding ".37rem .75rem"
  color "#424f3f"
  font_size ".91rem"
  text_decoration "none"
end
style ".chapters a:hover, .chapters .current"
  color "#203a27"
  background "#e5ead9"
end
style ".chapters .current"
  box_shadow "inset 3px 0 #426348"
  font_weight "700"
end
style ".menubutton"
  display "none"
end
style ".reader"
  max_width "80ch"
  min_width "0"
end
style ".reader h1, .reader h2, .reader h3, .reader p, .reader pre, .reader dl"
  margin "0"
end
style ".reader h1, .reader h2"
  font_family "\"Instrument Serif\", \"Iowan Old Style\", Georgia, serif"
  font_weight "400"
  letter_spacing "-.045em"
end
style ".reader h1"
  font_size "clamp(3.2rem, 5.5vw, 5.65rem)"
  line_height "1.03"
  margin ".6rem 0 1rem"
  text_wrap "balance"
end
style ".reader .lead"
  font_size "clamp(1.1rem, 1.5vw, 1.33rem)"
  color "#475543"
  max_width "65ch"
  line_height "1.5"
end
style ".reader section"
  margin_top "2.3rem"
  border_top "1px solid #c6cbb9"
  padding_top "1.4rem"
end
style ".reader h2"
  font_size "clamp(2rem, 3.3vw, 3rem)"
  line_height "1.12"
  margin_bottom ".8rem"
end
style ".reader h3"
  font_size "1.12rem"
  margin "1.4rem 0 .25rem"
  line_height "1.35"
end
style ".reader p + p, .reader p + a, .reader pre + a"
  margin_top ".75rem"
end
style ".reader p"
  max_width "72ch"
end
style ".reader p + a, .reader pre + a"
  display "inline-block"
end
style ".reader section > a"
  display "table"
  margin ".65rem 0"
end
style ".reader pre"
  padding ".95rem 1.2rem"
  background "#20372e"
  color "#f2f3df"
  border_radius "6px"
  overflow_x "auto"
  line_height "1.6"
  font_size ".87rem"
  margin ".9rem 0"
end
style ".reader code, .reader dt"
  font_family "\"IBM Plex Mono\", Menlo, Consolas, monospace"
end
style ".reader dt"
  font_weight "650"
  font_size ".92rem"
  margin_top "1rem"
  overflow_wrap "anywhere"
  color "#29442d"
end
style ".reader dd"
  margin ".22rem 0 .65rem"
  max_width "72ch"
end
style ".onpage, .pager"
  display "flex"
  flex_wrap "wrap"
  gap ".4rem 1rem"
end
style ".onpage"
  margin_top "1.1rem"
  font_size ".86rem"
end
style ".reader .note"
  background "#e5ead6"
  border_left "3px solid #6a835b"
  padding ".8rem 1rem"
  margin "1rem 0"
  color "#2c402c"
end
style ".routes"
  display "grid"
  grid_template_columns "repeat(2,minmax(0,1fr))"
  gap "0 2.2rem"
end
style ".routes article"
  padding ".85rem 0 1.05rem"
  border_bottom "1px solid #d1d6c6"
end
style ".routes h3"
  margin "0 0 .25rem"
end
style ".routes p"
  font_size ".93rem"
end
style ".pager"
  border_top "1px solid #9aa890"
  padding_top "1.2rem"
  margin_top "2.7rem"
  justify_content "space-between"
  font_size ".94rem"
  font_weight "600"
end
style ".foot"
  gap "1.2rem"
  border_top "1px solid #c8cdbd"
  padding "1rem 0 1.4rem"
  font_size ".85rem"
end
style ".foot .brand"
  margin_right "auto"
  font_size "1.15rem"
end
style ".layout" below 760
  grid_template_columns "minmax(0,1fr)"
  gap "1.25rem"
  padding "1.2rem 0 2.5rem"
end
style ".rail" below 760
  position "static"
  max_height "none"
  overflow "visible"
end
style ".railtitle" below 760
  display "none"
end
style ".menubutton" below 760
  display "inline-block"
  background "#e5ead9"
  color "#263d2b"
  border "1px solid #a4b299"
  border_radius "5px"
  font "inherit"
  min_height "44px"
  padding ".3rem .8rem"
  cursor "pointer"
end
style ".rail:has(.openmenu:enabled:not([hidden])) .chapters" below 760
  display "none"
end
style ".chapters" below 760
  margin_top ".5rem"
  grid_template_columns "repeat(2,minmax(0,1fr))"
end
style ".reader pre" below 760
  font_size ".81rem"
end
style ".bar" below 760
  min_height "62px"
end
style ".bar nav a:first-child" below 500
  display "none"
end
style ".routes" below 500
  grid_template_columns "1fr"
end
style ".frame" below 500
  width "91%"
end
style ".reader h1" below 500
  font_size "clamp(2.8rem,11vw,3.5rem)"
end
style ".foot" below 500
  gap ".9rem"
end
