Skip to content

Xo v0.46.0

Choose a tag to compare

@josephspurrier josephspurrier released this 11 Nov 00:44
· 2836 commits to main since this release

Xo 0.46.0 adds FreeBSD (amd64 and arm64) and linux/riscv64 as experimental cross targets, makes xo check about six times faster on a warm run by reading std's declaration record instead of checking all of std, matches routes as Go 1.22's ServeMux does, gives xo repl a JSON protocol and editing, and fixes a host name lookup that could return wrong IPv4 addresses.

Upgrade if your programs look up host names on networks with both IPv4 and IPv6, or if xo check time matters to you. Two changes can stop a program that compiled with 0.44.0 from compiling or change how it answers requests: std/http's Router matching, and exhaustive matches on TargetArch or TargetOs; a third makes some existing xo.lock lines fail to verify (see Breaking changes).

Breaking changes

  • std/http Router matches as Go 1.22's ServeMux. A pattern without a trailing slash is an exact path (GET /healthz no longer answers /healthz/), a pattern ending in / is a subtree route, {$} is the exact slash path, {name} needs a non-empty segment, unclean paths get a 307 to the cleaned path, a GET route serves HEAD (it was a 405), and a 405's Allow is sorted with HEAD. Migration: register the exact path and, for a tree, a /dir/ or {p...} route.

  • TargetArch gains Riscv64 and TargetOs gains FreeBSD (decisions 0571 and 0573), so an exhaustive match target.arch or match target.os with no _ => arm is now XO0301 on every target. Migration: add the new variant to an arm (Linux | FreeBSD => ..., Arm64 | Riscv64 => ...) or add _ =>; XO0301 names the missing variant.

  • A module in a subdirectory of its repository carries the repository's root LICENSE (decision 0590) when it has none of its own, as Go's module zips do, so its zip hash changes. An xo.lock line for such a module written by an older xo now fails with XO1304, with a note naming this change. Migration: delete the line and run xo mod tidy.

Platforms

  • FreeBSD (experimental cross target, decision 0573): programs build with the native backends for freebsd/amd64 and freebsd/arm64, with threads, the kqueue poller, signals, the file system, sockets, HTTP and TLS, faults recovered by isolate and defer, and asynchronous preemption (a loop with no call yields as on Linux). Every golden program that builds passes on both (642 of 642, in FreeBSD 14.5 VMs). use c bindings compile with clang against a FreeBSD sysroot (C that calls the C library is not supported yet). FreeBSD is not in --targets=all and has no prebuilt xo.
  • linux/riscv64 (experimental cross target, decision 0571): xo build --targets=linux/riscv64 --backend=llvm builds 64-bit RISC-V Linux programs (RV64GC) against a riscv64 glibc sysroot (XO_LINUXSYSROOT), with asynchronous preemption; LLVM backend only, not in --targets=all, no prebuilt xo. Under qemu-user all 523 LLVM goldens that need no network pass, and std's 60 test modules.
  • windows/arm64 (experimental, decision 0569): use c programs link with Xo's PE linker, weak C references work, functions over 1 MB get segmented unwind data, a debug build writes a PDB, and --backend=arm64 assembles with Xo's own COFF writer, so a build needs no clang unless it has a use c source. The native backend is not yet the default there.
  • Windows debuggers: WinDbg and cdb load the PDB xo writes on windows/amd64 and windows/arm64.
  • xo debug on Intel Macs (darwin/amd64, decision 0253): runs, steps and attaches to programs, with backtraces through x86_64's compact unwind data; it said "xo debug runs programs on macOS arm64, Linux and Windows".

Language

  • Integer bounds are type constants (decision 0587): Int.max, Int.min and every sized integer type's bounds (Int8.min, UInt64.max) work in a const or a pattern; Int.max(a, b) is XO0407 naming a.max(b).
  • Effects (decision 0582): an interface value's effect argument widens where the interface's effect parameter is covariant, so a Cred[fs.read] may go where a Cred[(fs.read, proc)] is expected.
  • Os { ... } may leave out fields (decision 0585): each omitted fs, net, env, proc or stdio denies everything, so a test or sandbox names only what it grants.
  • C libraries (decision 0574): xo build --lib=shared or --lib=static builds a package as a C library with a generated header (NAME.h), and pub fn add(a: Int, b: Int) -> Int as c "geo_add" is its C function geo_add. Int, Float, Bytes (XoBytes) and Str (XoStr, UTF-8 with a length, no NUL needed) cross directly; any other value but Bool and functions crosses as an XoHandle that C releases with xo_release. A function that can fail (-> T ! E) takes an int32_t *err last and leaves the error's text for xo_last_error(). The runtime starts when the library loads, and any C thread may call in. Works on darwin and linux, arm64 and amd64, with the native backends, linked with cc. Not yet: Windows DLLs, the LLVM backend, Optional and List results except as handles, and Bytes borrowed without a copy.

Tools

  • xo check reads std's declaration record (decision 0388) and parses std's trees only where a body is needed: a warm check of fib went from 352 to 56 ms and of bench/perf/http from 365 to 52 ms on the Mac; output unchanged (XO_STD_EXPORT=0 restores the earlier path).
  • xo repl no longer needs XO_REPL=1 (it stays experimental): --json speaks one request and one reply a line, --effects=LIST limits what entries may use, :defs, :save and :load manage a session, redefining a fn or type replaces it, and a terminal session edits entries in place with history.
  • Diagnostics for code written the Go way: if v, ok := m[k]; ok { is one XO0177 naming if let Some(v) = m.get(k); "n = " + n notes the interpolation form; xs.sort(fn(a, b) { a > b }) is one XO0403 naming sort_by; XO0701 names the corrected uses clause with a machine-applicable fix; xo vet XO0542 warns of x ?? lit <op> z.
  • xo check --fix parenthesizes its .or(x) to ?? rewrite when an operator is next to it (m.get(w).or(0) + 1 became m.get(w) ?? 0 + 1, which adds 1 to the default only).
  • xo lsp: hover on std names links to the std reference page, and a std source opened in the editor is not checked as a module. Every prelude fn now has a doc comment.
  • Module tools (decision 0568): xo mod sumdb keygen and serve, --copy-to and restore, --refresh, and xo mod proxy fill run a checksum log and module proxy; every git fetch fails a remote slower than 1 KB/s for a minute instead of hanging.
  • xo init writes .gitignore only inside a git repository.
  • xo vet XO0541 warns of a raw.bytes_buf slice kept past the loop iteration that reads into the buffer again, without .clone() (a Bytes slice is a view).

Fixes

  • Windows: xo fix, xo check --fix and xo mod outside a module no longer loop forever: the search for xo.mod stops at the drive's root (C:/).
  • A host name lookup that asks for IPv4 and IPv6 at once no longer returns IPv4 addresses read from the IPv6 answer's bytes (programs dialed addresses such as 38.6.71.0 when a resolver answered both back to back).
  • Large darwin/arm64 programs link: a separately compiled program whose code ends more than about 112 MiB past std's start failed with a branch range error.
  • Float conversions: UInt64(f) from 2^63 up to 2^64 converts on the native and LLVM backends (it faulted), and a failing Float to sized integer conversion names the type and value.
  • xo check ./... (decision 0513) over 8 or more modules no longer reports "expected Str, found Str"; a package below its module root named as . keeps its import path (no false XO0604).
  • A stopped build (ctrl-c, SIGTERM) leaves no hidden stage or tomb file beside the output.
  • xo doc DIR/... documents every module at and below DIR, as its help says (it looked ./... up as a declaration name).
  • darwin builds with --release or --trimpath write no debug map naming the builder's cache under $HOME (decision 0563).

Standard library

  • Stdio.raw_input(on) (decision 0581) switches a terminal to raw input and back, restored on exit, fault or crash (Linux, macOS, Windows).
  • Ordering and comparator sorts in the prelude (decision 0586): Ordering with reverse and then, a.cmp(b) on every Ord type, the stable sort_with and sort_in_place_with, and sort_by_desc and sort_in_place_by_desc.
  • std/image (decision 0578), ported from Go's image, image/color and image/draw with Go's output as each test's oracle: color conversions, Image.at and set, sub_image and crop, YCbCr planes, PNG and JPEG in and out (from_png, to_png, from_jpeg, to_jpeg), draw, draw_mask and fill, Floyd-Steinberg dithering onto palettes, and scale with nearest neighbor, bilinear and Catmull-Rom kernels (x/image/draw).
  • std/gif (Go's image/gif: decode, decode_all, encode, encode_all, animations) and LZW in std/compress (lzw_encode, lzw_decode).
  • std/htmlparse: golang.org/x/net/html's tree builder and Render (decision 0570), checked against Go on 1,789 html5lib and other cases.
  • std/trace records OpenTelemetry spans (ids, parent, kind, attributes, events, status, a Recorder), and std/otlp encodes them (decision 0580).
  • Aead.Aes128CbcHmacSha256, JWE's A128CBC-HS256 (RFC 7518), checked against Go.
  • Go compatible error texts: json.decode_go (decision 0553) follows encoding/json's rules for null and missing fields and words a type error as it does; DecodeErr.go_text() and timego.go_text(e) give encoding/json's and time.Parse's texts.
  • std/protojson: editions 2023 descriptors, groups as JSON objects, proto2 required fields checked, unknown fields kept by normalize.
  • std/testing: FakeProc.runs() lists the commands the code asked to run.
  • Fixes: File.read_at and write_at keep the file position on Windows; http.redirect's body ends as Go's does; under FakeNet a client request reaches a bare Listener.

Performance

  • List slices allocate their length at once (bench/perf/listslice: 64 Ints of 256 in 0.198 of the time, linux/arm64).
  • Str.rune_count counts 32 bytes at a time; arm64 drops the bounds check of b[n - 1] under n > 0; wide struct == passes addresses; interpolations starting with a literal copy it inline (bench/perf/interpcat 0.937, linux/arm64); the LLVM backend writes 4 KiB values field by field.
  • Build time: register allocation and copy propagation do less work per register, and a parallel move of more than 16 words is ordered in O(n log n).

Xo against Go

Measured on linux/arm64 (12 CPUs) during the 0.46.0 cycle, against Go 1.26.1; Xo and Go alternate within each round.

  • Run time: Xo is faster on 16 of 20 release benchmarks, from 0.89x of Go's wall time (fib) to 0.18x (collection iteration); it is slower on sieve (1.19x), rwmutex (1.13x), pmap (1.06x) and nbody (1.02x). Peak memory is 0.21x to 0.68x of Go's.
  • Tests: xo test of std's base64 and json runs in 0.79x and 0.46x of go test's wall time cold, 0.89x and 0.24x after an edit.
  • Builds: a cold build takes 1.1 to 1.3 s against Go's 1.3 s, at 220 to 240 MB peak against Go's 280 to 300 MB; an edit rebuilds in 40 to 110 ms (Go 70 to 80 ms), but an unchanged rebuild is 40 to 110 ms against Go's 20 ms.
  • HTTP server: against Go at its defaults Xo serves 3.4x to 6.0x the requests per second on a JSON route and 1.3x to 1.8x on a plain one, at about a quarter of Go's memory; against Go tuned (GOGC=off, a 1 GiB memory limit) 1.27x to 1.38x and 1.15x to 1.23x, at under 1% of its memory. Against 0.44.0 the JSON route is 6% to 9% faster; the plain route is 0.6% to 1.0% slower.
  • The macOS rows of this release are measured separately on the Mac.

Known issues

  • windows/arm64's native backend is not the default yet (decision 0569's prerequisite 2: internal/arm64 has 11 failures on windows/arm64); target 0.47.