Skip to content

Kairo 0.3.1

Latest

Choose a tag to compare

@Ze7111 Ze7111 released this 30 Nov 22:23
· 827 commits to release/0.3.x since this release
Immutable release. Only release title and notes can be modified.
86676db

Kairo 0.3.1 is a fix release on top of 0.3.0. Most of it turns compiler crashes and errors from the backend into proper Kairo diagnostics, and fixes the places where 0.3.0 quietly built the wrong thing. It also adds a few features: T? as U? conversions, @export for plain C symbols and wasm exports, [T]::emplace, a clang-cl mode for kcc, and ASan / TSan on glibc Linux. Same LLVM (23.1.6) and the same 14 hosts as 0.3.0. There are a few small breaking changes, listed at the end.

Highlights

  • T? as U?: converts the value and keeps null (code as string?, ptr as *Dog?).
  • @export("name"): a free function also gets the plain C symbol name; on wasm it's the module export too.
  • kcc and build systems: kcc --version prints clang's banner, so CMake detects kcc as Clang; --driver-mode=cl takes clang-cl's command line.
  • Sanitizers: -fsanitize-address and -fsanitize-thread instrument Kairo code on glibc Linux targets.
  • [T]::emplace(args...): builds the new last element in place.
  • Fewer crashes: a long list of ICE's (I003E, CL001E) and backend verif errors are now checked and error correctly instead, and several of them compile fully now.
  • Windows: a crash exits with status 134 like everywhere else, and sources and headers aren't locked while a compile or kals has them open.
  • CRLF sources lex and report lines and columns the same as LF sources.

Platforms and downloads

Archive Host
kairo-0.3.1-x86_64-linux-musl.tar.xz Linux, x86-64
kairo-0.3.1-i686-linux-musl.tar.xz Linux, 32-bit x86 (Pentium 4 class or newer)
kairo-0.3.1-aarch64-linux-musl.tar.xz Linux, 64-bit Arm
kairo-0.3.1-armv7-linux-musl.tar.xz Linux, 32-bit Arm (ARMv7 or newer)
kairo-0.3.1-riscv64-linux-musl.tar.xz Linux, RISC-V 64
kairo-0.3.1-x86_64-unknown-freebsd.tar.xz FreeBSD, x86-64
kairo-0.3.1-aarch64-unknown-freebsd.tar.xz FreeBSD, 64-bit Arm
kairo-0.3.1-x86_64-unknown-netbsd.tar.xz NetBSD, x86-64
kairo-0.3.1-x86_64-windows-gnu.zip Windows, x86-64
kairo-0.3.1-i686-windows-gnu.zip Windows, 32-bit x86
kairo-0.3.1-aarch64-windows-gnu.zip Windows, 64-bit Arm
kairo-0.3.1-armv7-windows-gnu.zip Windows, 32-bit Arm
kairo-0.3.1-x86_64-apple-macosx10.15.zip macOS 10.15 or newer, Intel
kairo-0.3.1-arm64-apple-macosx11.0.zip macOS 11 or newer, Apple silicon

Every archive holds:

  • bin/: kairo, kcc, kld, kfmt, ksys, kals, llvm-symbolizer and llvm-ar (with llvm-ranlib and llvm-lib links).
  • lib/: the compiler's resource directory (lib/clang/23) and Kairo's builtin, std and rt libraries.
  • sysroot/: on Linux the host's prebuilt musl and glibc sysroots, on Windows the host's windows-gnu sysroot; the BSD and macOS archives ship none. Every other target's sysroot (the BSD host's own included) is built by ksys from share/kairo/sysroot/ the first time --target names it (about 10 to 30 s), then cached.
  • scripts/: darwin-sysroot.sh and msvc-sysroot (.sh / .ps1), which build the macOS and MSVC sysroots from your own Apple SDK or Microsoft CRT and Windows SDK. We never ship those SDKs; the Kairo half of each root is prebuilt in share/kairo/sdk-overlays/, and share/kairo/runtimes/ holds the LLVM runtimes source for a full build.
  • share/kairo/templates/: the projects kairo --init copies.
  • LICENSE, NOTICE, LICENSES/ and THIRD-PARTY-NOTICES.

Installing

curl -fsSL https://www.kairolang.org/install.sh | sh          # Linux, macOS, FreeBSD, NetBSD
irm https://www.kairolang.org/install.ps1 | iex                # Windows PowerShell 5.1 or pwsh 7

install.sh and install.ps1 are one script that runs under both POSIX sh and PowerShell. It detects the host's triple, downloads the archive and SHA256SUMS from this release, checks the archive's SHA-256 before unpacking anything, and needs no root:

  • sh: the tree goes to ~/.local/share/kairo/0.3.1 and the tools are linked into ~/.local/bin (KAIRO_PREFIX moves both); it prints the line to add that directory to PATH when it's missing. On macOS it clears the quarantine flag (the binaries aren't notarized) and assembles the macOS sysroot from the Command Line Tools or Xcode SDK.
  • PowerShell: the tree goes to %LOCALAPPDATA%\Kairo\0.3.1 and its bin is added to the user Path (older Kairo entries under the same root are dropped). With Visual Studio's C++ tools and a Windows SDK installed it also assembles the optional MSVC sysroot (x86_64 and aarch64); the default windows-gnu target needs nothing. Run under pwsh on another OS, it hands over to the sh installer.
  • The sysroot step never fails the install: a missing SDK or a failure prints the command to run later. KAIRO_NO_SYSROOT=1 skips it.
  • Environment: KAIRO_VERSION (default 0.3.1), KAIRO_PREFIX, KAIRO_BASE_URL (where the archive and SHA256SUMS live; a file:// URL works), KAIRO_TRIPLE (overrides detection).
  • Installer: --archive <path-or-url> / --sha256 <hex> (KAIRO_ARCHIVE, KAIRO_SHA256; PowerShell -Archive, -Sha256) installs a release archive you already downloaded.

Language

Types, conversions and expressions

  • T? as U?: converts the value and keeps null (code as string?, ptr as *Dog?); a conversion T as U? doesn't have is SC027E. x as U from a T? whose T converts is SC027E ("converts, but may be null") instead of failing in the emitted code.
  • s as [T]: a slice [T;] or [const T;] casts to its vector, a new [T] copying each element (same as s.to_vec()); it needs T impl Copyable (SC153E), and a vector of other elements is SC027E.
  • op as with a requires clause: a source that doesn't meet it is SC153E at the cast.
  • var *d = x is accepted after a null check proves x non-null (no false SC266E); d is *T, same as var d: *T = x.
  • assert c, msg: prints the evaluated message when msg isn't a literal (it printed the statement's source); a message that isn't a string is SC028E.
  • Statement breaks: a line after a tuple literal that starts with *, -, &, ( or .. is its own statement, not a continuation of the line above.
  • var g = f where f is a generic function without its type arguments, an overload set or a method is SC094E at type check, with notes at its declarations (was a build failure, or a compiler crash at file scope).
  • Closure default arguments don't apply once the closure variable is reassigned (it silently used a wrong value; now SC099E).

Generics and extensions

  • extend blocks: a member declared twice across the blocks of one type in a file is R041E (was a build failure).
  • Packs: a pack forwarded into an overload set is checked against the candidates' bounds at the definition (R051E / R025E) when no candidate's pack bounds are met.
  • Const C++ objects in generics: calling a non-const C++ method through a const dependent C++ object (const v: cxx::std::vector<T>) is SC063E at type check instead of a build failure.
  • v[i] in a generic class, where i's type depends on the class's parameter, compiles (was a crash, I003E [] on a record).
  • Duck mixins, slicing: a bound from a duck call in a mixin body (s[1..self.dyn()->n()]) compiles (was I003E); an open range on a duck receiver (self.dyn()->xs()[1..]) is accepted.
  • Duck mixins, for i in a..b with a bound only the instance types compiles (was I003E); a bound that isn't an integer, or one that narrows, is a normal error.
  • Duck mixins, stored ranges: a range stored, passed or returned with such a bound (var r = k..self.dyn()->n()) compiles; with only a literal as the other bound it's SC001E with a note; eval for over such a bound is SC192E.

Moves and ownership

  • cxx::std::move(v[i]) / cxx::std::move(m[k]) moves the element out and leaves the container moved-from (SC052E on a later use), as a @move argument does; on a map a missing key gets a default value first (was a build failure on a move-only element).
  • C++ move check: a pointer passed through a C ... argument in a C++ body counts as an unknown call (a move under -fstrict-cxx-moves).
  • SC182E on a loop binder suggests const *x where the loop yields read-only elements (a const vector, a set, a const-only op in).
  • Messages: SC182E's note names std::move(...) for the explicit hand-off; R068E, S089E and S090E are reworded.

C and C++ interop

  • @export("name"): gives a free function the unmangled C symbol name beside its own; on wasm it's also the module export (instance.exports.name). C signatures only (SC369E); one name defined twice is SC370E.
  • P012W (new): warns when a host system header stands in for a missing --cxx-include / --ffi-include / -I root, or one that lacks the header, for ffi imports, C/C++ inputs and kcc.
  • ffi "c++" import <h> is S064E with a fix-it that quotes the header (import "h"); the header is still imported, so its names don't cascade into more errors.
  • A primitive after :: in a type (cxx::std::i32<N>) is R025E with a fix-it naming the primitive bare (was a compiler crash).

Allocation

  • Global allocator: the kairo_global_* functions of a @set_global_allocator allocator must return with the scoped-allocator stack as they found it (stated in global_alloc.h).

Library

  • [T]::emplace(args...): builds the new last element in place from a constructor of T; nothing is copied, moved or dropped into the slot.
  • Slices for C++ hosts: size() and data() are members of a slice, so a C++ file that includes a .k file can call s.size() and s.data().
  • copy() and to_owned(): string.copy() is always a deep copy and to_owned() is gone (see breaking changes).

Toolchain

kairo

  • --linker-arg=<arg>: passes one argument to the linker, repeatable and in order (a second spelling of --ld-flags); --linker-arg=--import-undefined leaves body-less ffi "c" functions as wasm imports.
  • -Xlinker <arg> (also --Xlinker) is accepted and joins --ld-flags / --linker-arg in command-line order.
  • --print-target-info needs no input file and reports the CPU a compile with the same flags uses (host default, --mcpu, --march).
  • --emit-headers: a command-line input outside every search directory and library (no module path, so no header) is U026W naming the -I <dir> that gives it one (was a silent exit 0).
  • Sanitizers: -fsanitize-address / -fsanitize-thread instrument Kairo code and link the runtime from --sanitizer-runtime-dir=<dir> (none ships). glibc Linux targets only; musl, --static or both sanitizers together are L002E. ASan sees malloc only with --heaplib=libc.
  • wasm32-unknown-unknown: Kairo code for it is refused up front (P011E, any WebAssembly triple with no OS) with a pointer to wasm32-wasi, instead of failing in the runtime's headers; plain C/C++ builds are unchanged.
  • wasm32 and --cache-dir: no more unknown directive; the object cache is off for wasm targets.
  • Library cache: a leftover .copy- / .tmp- / .stale- tree from an interrupted publish counts toward the 2 GB cap and is removed after a day.
  • Reproducible links: PE programs are linked with -Brepro (no wall-clock timestamp), and Mach-O programs don't carry the object-cache record.
  • CRLF sources lex and report line ends and columns like LF sources; incremental replay scripts with CRLF line ends work.
  • Windows: a crash exits with status 134, as on every other target, with no abort dialog.
  • Windows: sources aren't held open while compiling, so saving a file during a compile or while kals runs, and --incr-replay edits, work; a C/C++ header of 16 KiB or more isn't locked either (headers are read, not mapped).

kcc

  • --version / -v print clang's banner (kcc-clang version 23.1.6 (...), Target:, Thread model:, InstalledDir:), so CMake identifies kcc as Clang for C and assembly. -v goes to stderr, exits 0 with no input, and no longer turns on kairo's log (that's -Xkairo -v).
  • clang-cl mode: --driver-mode=cl and a -cl program name take clang-cl's command line (/c, /Fo, /Fe, /I, /D, /O2, /std:, /Tc, /Tp); an object with no /Fo is <stem>.obj; /Fo<dir>/ is refused.

kfmt

  • kfmt keeps = NAME! on a declaration whose macro isn't defined, and formats expression-bodied functions whose body starts with a parenthesized operand (-> bool = (v as u32) < 0x80).

kals

  • kals: the live worker's aside check no longer leaks a diagnostic collector per request.

ksys and sysroots

  • glibc sysroots: the compiler-rt directory is named for the normalized triple (x86_64-unknown-linux-gnu), so a C/C++ compiler given a glibc target and the root's resource dir finds crtbegin and the builtins.
  • glibc roots are link-only: running the stub ld.so or a library prints that and how to run the program, exit 127 (was SIGSEGV).
  • ksys build --out keeps file permissions, and with --libc-only keeps a root's symlinks (sonames, loader links) as symlinks.
  • SYSROOT.toml extra_cflags apply to C/C++ inputs (wasm32-wasi C++ exceptions are caught); thumbv7 Linux C/C++ compiles as Thumb-2, not A32.
  • Soft-float Arm (thumbv7m-none-eabi): no more spurious "+soft-float-abi is not a recognized feature" warning.

KaTAR

  • ktextract reports a malformed archive trailer or table with a message and exits 1 instead of aborting, and rejects a name length larger than the archive.

Build

  • build.py and Scripts/cross_llvm.py seed from the release tree before N-1, and cross_llvm.py honours $KAIRO_SEED.
  • build.py: a host build whose LLVM major differs from the bundled fork's stops at once and names the command that works (--target x86_64-linux-musl --stale-llvm=use).

Fixes

Language and code generation

  • Fixed: null as T? compiles to the target's null (was an internal compiler error).
  • Fixed: a negative integer literal of 2^63 or more assigned to i256 or i512 is sign-extended (it was zero-extended, a wrong value).
  • Fixed: an imported int typedef and long typedef are distinct base types on LLP64 and 32-bit targets (R028E where they clash); Darwin and wasm32 call size_t's own C overload for a usize argument; non-ASCII command-line arguments work on Windows.
  • Fixed: eval string constants (eval LIT: string = "abc") compile, and an eval fn that takes or returns a string by value compiles.
  • Fixed: F256, F512, F8E4M3 and F8E5M2 resolve in a file with no literal or keyword of the type.
  • Fixed: eval if in an interface or extension body keeps its taken branch: its requirements are required and its members are emitted (an untaken branch contributes nothing; a var there is SC231E).
  • Fixed: ffi import "sys/time.h" before ffi import "time.h" no longer hides time.h's names.
  • Fixed: overloads that differ only by a requires T derives B clause (against !(T derives B) or none) compile instead of aborting with I003E.
  • Fixed: importing a C++ header with a partial specialization whose argument names its own parameter (LLVM's cl::applicator<char[n]>, for one) no longer crashes the compiler (a stack overflow in the name printer).
  • Fixed: for *x / for const *x over a C++ range whose iterator is a raw const T* (llvm::SmallVector) binds a pointer to const (was CL001E).
  • Fixed: passing [T;] to a generic [const T;] parameter (f<T>(s), [T]::from_slice(s)) no longer fails at build (CL001E).
  • Fixed: a const parameter of an imported type with deleted copy and move constructors compiles when a later argument of the call has a side effect (was CL001E).
  • Fixed: a generic call with a move-only T argument beside a later argument that could change it no longer copies it (it failed to build); the operand is bound per instance.
  • Fixed: collect on a chain over a generic parameter is no longer ambiguous (SC064E).
  • Fixed (memory safety): a value built under an if arm of a for header and passed to a const parameter lives through the loop (it was read after it ended).
  • Fixed: a closure holding a MOVE capture, passed beside a panicking argument, trapped at run time.
  • Fixed: embed_str! crashed the compiler; it's reported as not supported yet (SC116E), and --print-tokens and --dump-preprocessed no longer crash on it.
  • Fixed: turning on a sanitizer no longer crashes the compiler (SIGSEGV in code generation while compiling the builtin library).

Toolchain

  • Fixed: a source file rewritten during a compile no longer crashes the compiler (an ICE, or SIGBUS on Linux, macOS and the BSDs) or builds the wrong text.
  • Fixed: kairo no longer stalls (hangs on Windows) when a C/C++ header it imports is missing, such as from a sysroot with no C++ headers.
  • Fixed: --freestanding no longer compiles the hosted runtime (string.h / stdlib.h not found with --builtins-dir on a bare-metal target).
  • Fixed: --disable-kairo-pass=spec-devirt also turns off the backend's speculative devirtualization of single-target virtual calls.
  • Fixed: kcc -std=c++20 builds programs that use the library again.

Breaking changes

  • Closure defaults: a short call through a closure variable that's reassigned, passed as &f, or captured by |*f| / |*| is SC099E; pass every argument.
  • Literals: a character literal holding zero or several characters ('', 'ab') and a base prefix with no digits (0x, 0b, 0o) are S001E ('ab' was accepted as a multi-character constant); use a string literal for text.
  • Generic bounds: a generic body that builds a bounded generic record at one of its own parameters (Box<U>(u), Box<U>{ .. }, @create Box<U>(u), through an alias too) needs that parameter's bounds to grant the record's: R051E for an unbounded parameter, R025E for one bounded by something else. A requires clause of alternatives (T impl A || T impl B) is held to the same rule. Add the bound to the caller's parameter.
  • string.copy() is the deep copy: a view's copy owns its bytes (it was a view); a literal's copy is still the literal. to_owned() is removed, use copy().
  • Slices: to_owned() is to_vec(); copy() is still the view copy.

Known issues

  • ThinLTO bitcode from clang 22: linking third-party ThinLTO objects or archives written by clang 22 (or older) with 0.3.1's LLVM 23 linker can drop symbols that kept code still calls, so the link fails with undefined symbols. Link those libraries as non-LTO objects, or rebuild their bitcode with 0.3.1's kcc; -fgc-sections hides it on most ELF links but not on COFF.
  • ASan on the default heap: an ASan program on the default mimalloc heap crashes before main; link it with --heaplib=libc.
  • meson can't detect kcc's linker yet: kcc -Wl,--version isn't forwarded.
  • embed_str! isn't supported yet (SC116E).
  • Placeholder diagnostic codes: some diagnostics still carry a placeholder code (R001E, SC001E, SC001W, U001E) and SC182E covers several situations, so --explain can show general text. They get their own codes in a later release.
  • i686-linux-musl: a 64-bit __atomic_* operation that isn't lock-free (an object not 8-byte aligned) fails to link (__atomic_compare_exchange undefined).
  • CL001E instead of a diagnostic: returning a const [T] parameter or a const local (SC182E by the language reference) passes the checks and fails in code generation.
  • override against a C++ base class isn't checked, so --type-check-only and kals miss a removed virtual.
  • NetBSD on 64-bit Arm has no archive; the installer says so and prints the command to build from source.