Skip to content

Xo v0.48.2

Choose a tag to compare

@josephspurrier josephspurrier released this 11 Nov 17:30
· 2720 commits to main since this release

Xo 0.48.2 fixes two bugs of separate compilation (the default for a native build, run or test since 0.34.0). A program with a few constants of collection types could crash or silently read wrong values when it also ran std code with constants of its own (every platform). And on windows/amd64, once std's prebuilt stores were cached, a program that uses concurrency was linked against std's single-threaded store: HTTP servers faulted and some programs using std/sql did not link. Both are in 0.46.0, the last release. Everyone on 0.34.0 or later should upgrade. On an older version, set XO_SEPCOMP=0 to avoid both (or build with --release, or the LLVM backend, for the first).

0.48.2 also carries everything of 0.48.0, which had no release of its own. Since 0.46.0, Xo reaches the user's secret stores (the Linux kernel keyring, the macOS keychain and Windows' DPAPI, each with an in-memory fake in tests), builds C libraries as Windows DLLs, reads multipart bodies as they arrive, adds Go's slices, maps, strings.Replacer and io.Copy helpers to the prelude, rebuilds small programs faster, and runs std/sqlite on FreeBSD.

Upgrade if you build small programs often, or if a program uses std/base64 together with another std module such as crc32 (it could fail to build with XO1201). One change can stop a program that compiled with 0.46.0 from compiling: std/amqptest's broker methods declare the clock effect (see Breaking changes).

The fixes in 0.48.2

  • Constants read from the wrong slot (gotchas/sepcomp-const-ids-shared-with-std.md): a constant of a List, Map, Set or Bytes type, or one computed by a call, lives in one table of the process, read by a number the compiler gives it. A separately compiled program numbered its constants from 0, as std's prebuilt store numbers its own, so a program constant and a std constant could share a slot. A program with five such constants calling mime.detect_content_type crashed with SIGTRAP on 0.48.0 (150 constants on 0.44.0 and 0.46.0); in other orders it crashed with SIGSEGV, or read another constant's value with no crash (xo test --std-module=mime returned wrong content types). The program's constants now number from 2048, and building std's store fails loudly if std ever has 2048 of its own. Native backends only: LLVM, wasm and Go builds, and --release builds, compile std with the program and were never affected.
  • Windows: concurrent programs linked against the single-threaded std (windows/amd64): std's prebuilt store comes in two forms, with and without concurrency support, and the Mach-O and ELF links pick by the program. The PE link read only one of them, so once both were cached, a program that uses concurrency got the other: on 0.46.0 with both stores cached, an HTTP server and an HTTPS server faulted, and two programs using std/sql failed to link (0 of 4; with XO_SEPCOMP=0, 4 of 4). Now the PE link picks the store as the others do. On an older version, set XO_SEPCOMP=0 (or XO_SEPCOMP_DEFAULT=0) on windows/amd64.

Breaking changes

  • std/amqptest (decision 0591): Broker.event_hub, put, ready, locked and scheduled declare uses clock, since they read the broker's clock. Migration: a caller that passes them as a pure fn (a closure, say) needs the clock effect.

Platforms

  • Windows DLLs (decision 0574): xo build --lib=shared builds a DLL for windows/amd64 and windows/arm64 with Xo's PE linker, exporting the runtime's and the as c functions by name; the runtime starts on the first call (DllMain starts nothing), each thread's runtime state is released when the thread exits, and XoBytes and XoStr cross by reference as Win64 passes them. -o geo.dll writes the header geo.h and the import library geo.lib, which MSVC's link.exe and lld-link link a C program with. --lib now exports the as c functions even with no -o.
  • FreeBSD (experimental, decision 0573): std/sqlite builds and runs on freebsd/arm64 and freebsd/amd64 (a database file in WAL or rollback journal mode; SQLite's localtime is UTC there). A use c binding's C may call printf's family, <ctype.h>, calloc, realloc, the str functions, memchr, strtol and atoi, though an Xo program on FreeBSD links no C library: Xo's runtime and a small C file the build adds define them. A static link names every missing function at once.
  • windows/arm64 (experimental, decision 0569): a program built against std's separately compiled store no longer crashes before main (a branch between two atoms of an object was resolved in place, and the store's layout moved them apart).

Language and prelude

  • Float type constants (decision 0592): Float.inf, Float.nan, Float.pi, Float.e, Float.max, Float.min and Float.smallest_nonzero, as Int.max (Go's math.Inf, NaN, Pi, E, MaxFloat64, SmallestNonzeroFloat64).
  • Lists and maps (decision 0592): List.clone(), List.concat(lists), binary_search(x), max() and min() (Go's slices.Clone, Concat, BinarySearch, Max and Min); Map.extend(other) and Map.clone() (maps.Copy and maps.Clone).
  • Copying streams (decision 0593): copy_stream(dst, src), File.copy_to(dst) and File.copy_from(src), with CopyErr[R, W] (Go's io.Copy between connections and files).
  • Replacer.new(pairs) and r.replace(s) (decision 0594): Go's strings.Replacer, one pass over several old and new pairs.
  • Runes, integers and time (decision 0595): Rune.max, Rune.max_ascii, r.simple_fold(), n.bit_len(), n.add_carry(m, c), n.sub_borrow(m, b), t.unix_micros(), t.unix_nanos(), t.nanosecond(), Time.from_unix_micros and Time.from_unix_nanos.

Standard library

  • os.secrets (decision 0584): the user's secret stores. Secrets.keyring() is the Linux kernel keyring (Keyring.add, search, read, unlink, user_persistent, KeyErr); keychain() the macOS login keychain's generic passwords (get_generic, set_generic, delete_generic, KeychainErr); dpapi() Windows' Data Protection API (Dpapi.protect and unprotect with optional entropy, DpapiErr), with Env.local_app_data(). In a test, each is an in-memory store on every OS, empty per test. An Os literal without secrets has none.
  • std/multipart (decision 0597): multipart.reader(src, boundary) reads a body's parts as they arrive, as Go's multipart.Reader does (next_part, read, PartHead.header_values); it is effect generic, so the source may read a connection. http.BodyReader.multipart is built on it.
  • Fixed: UuidErr.msg is pub again (decision 0440).

Tools

  • Warm builds of small programs reuse their generated code: a separately compiled program of fewer than 256 functions skipped the function cache and generated all of its code on every build. The collections benchmark's warm rebuild went from 110 to 53 ms on linux/arm64, with a byte identical binary.
  • Build time (arm64 and amd64 native backends): two code generation passes that were quadratic in a block of many word loads are linear; output unchanged.
  • xo test --std-module after an edit uses about half the memory: std's test variant now holds facts for every std function, and a test build loads std's declarations from their record and parses std's trees only where needed, as xo build does (decision 0596).
  • xo lsp: go to definition and peek on a std name open its implementation in std's native sources (Str.split_where, http.Request), not the bodyless declaration; a name with no implementation (an intrinsic) keeps its declaration. New: textDocument/typeDefinition.
  • The playground's compiler parses runtime bodies only when it checks them and skips test files, as xo build does, and can load std from its declaration record; a wasm program's memory grows by a quarter instead of doubling. The playground's 30-entry REPL test session (headless Chrome) went from 608 to 265 MB of memory (decision 0583).

Fixes

  • std/base64 with std's declaration record: a program using std/base64 and another module in the record (crc32, say) failed with XO1201 base64.encode (decision 0588).
  • Windows drive paths: xo doc --dir=C:\x\app read the directory alone, xo query --dir=C:\x missed callers in the workspace's packages, and xo serve never forwarded a lookup with a drive path (and kept C:\x and C:/x as two cache entries).
  • xo doc std summaries of the std modules merged with their implementation (decision 0588), and of std/amqptest, std/timego, std/base32 and std/uuid, read their description again, not an origin or license line.
  • Interfaces: a call through an interface that omits an argument uses the interface method's default on the native backends (it was XO1201).
  • xo dev new-golden --dir=DIR with an absolute DIR wrote under the checkout; the directory is used as given.

Known issues

  • windows/arm64's native backend is not the default yet (decision 0569).