Repository navigation
Kairo 0.2.0 #113
Ze7111
announced in
Announcements
Kairo 0.2.0
#113
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Warning
This is an alpha. It's the first public build of the self hosted compiler, released so people can try Kairo, break it, and report what broke. The syntax, command-line flags and standard library will change before v1.
Kairo is a statically typed systems programming language with bidirectional C++ interop. You import C and C++ headers directly and use them as if they were Kairo, and C++ code can include what Kairo exports. There are no bindings, wrappers or generated glue to maintain.
Kairo builds native executables on Linux, Windows, macOS, FreeBSD and NetBSD. From any host it cross-compiles to Linux, Windows (MinGW), FreeBSD, NetBSD and WebAssembly with the bundled sysroots; macOS and MSVC targets need your own SDK.
Highlights
kairo,kcc,kldandkfmtship with the runtime and 18 cross-compile sysroots. Clang and LLD run inside the tools, so you don't need a separate C/C++ compiler, linker or SDK for the bundled targets.kcc, a clang-compatible C/C++ driver, lets a C++ file#include "foo.k"and call into it.kfmt, the Kairo formatter.--cache-dirkeeps an object cache that the tools share; unchanged files skip code generation on the next build.if,tryandmatch. A value arm is introduced with=>, and braces after a control keyword always mean a block. Code reads the same way in every position.match. Missing cases are compile errors.eval, parameter modes, f-strings, named and default arguments, variadic functions, operator overloading, and generics with specialization.Install
Quick install
Linux, macOS, FreeBSD and NetBSD (any shell):
curl -fsSL https://kairolang.org/install.sh | shWindows (PowerShell 5.1 or 7):
Both are the same script, also attached below as
install.shandinstall.ps1. It detects your OS and CPU, downloads the matching archive andSHA256SUMS, verifies the checksum before unpacking, and never needs root or administrator rights. On Linux, macOS and the BSDs it installs to~/.local/share/kairo/0.2.0and links the tools into~/.local/bin. On Windows it installs to%LOCALAPPDATA%\Kairo\0.2.0and adds itsbinto your userPath. SetKAIRO_PREFIXto install elsewhere, orKAIRO_TRIPLEto pick a different archive.Downloads
Linux (the compiler is statically linked against musl and runs on any distribution)
kairo-0.2.0-x86_64-linux-musl.tar.xzkairo-0.2.0-aarch64-linux-musl.tar.xzkairo-0.2.0-armv7-linux-musl.tar.xzkairo-0.2.0-i686-linux-musl.tar.xzkairo-0.2.0-riscv64-linux-musl.tar.xzWindows (MinGW builds; no extra runtime needed)
kairo-0.2.0-x86_64-windows-gnu.zipkairo-0.2.0-aarch64-windows-gnu.zipkairo-0.2.0-armv7-windows-gnu.zipkairo-0.2.0-i686-windows-gnu.zipmacOS
kairo-0.2.0-arm64-apple-macosx11.0.zipkairo-0.2.0-x86_64-apple-macosx10.15.zipBSD
kairo-0.2.0-x86_64-unknown-freebsd.tar.xzkairo-0.2.0-aarch64-unknown-freebsd.tar.xzkairo-0.2.0-x86_64-unknown-netbsd.tar.xzThe i686 builds need an SSE2-class CPU (Pentium 4 or newer), and the ARM builds need ARMv7 or newer.
To install by hand, download an archive and
SHA256SUMS, verify it, unpack it anywhere and add itsbinfolder to yourPATH:Keep the folder layout as it is: the tools find their libraries, runtime and sysroots relative to
bin.Archives downloaded with a browser may be blocked on first run on macOS and Windows; see Troubleshooting.
SHA-256 checksums
The same values as the attached
SHA256SUMS(which covers the archives; the installers are listed here too). On macOS useshasum -a 256 <file>; on Windows,Get-FileHash -Algorithm SHA256 <file>.kairo-0.2.0-aarch64-linux-musl.tar.xz4370035d6fec76908f84f1de6c9bd3510c69e9a119664b6a5bdda05098b65267kairo-0.2.0-aarch64-unknown-freebsd.tar.xz3fc4c37ec6ff6fcdea23dd56cf3325ae73a707b4640830b9c62e366b980aa501kairo-0.2.0-aarch64-windows-gnu.zipc1b2c5383e7c5be064d4add7c1f5fe24db3d28e05f89d8ce04b3be414542e45dkairo-0.2.0-arm64-apple-macosx11.0.zipd8786f3bce77f23ad2c40560b5b48315866b4d3bb48ded3b2ab36e9e17bad17akairo-0.2.0-armv7-linux-musl.tar.xze0a74096e268c091f00d01f17c6ecf6efbe83670432614c00d8b1bd5966d0f7ekairo-0.2.0-armv7-windows-gnu.zip5a5930c857cf6704724a92fcf361dc762d1ac1abb01b8c94f1b20e8e058a770ekairo-0.2.0-i686-linux-musl.tar.xz1ea27397781f483922062b37094a4c9d985735b63d49cd61410a9d45f11ddc41kairo-0.2.0-i686-windows-gnu.zipf8044c7772af2f38602008b15c62cf3f14ba3ff3fc7dd2773820ae691a1de821kairo-0.2.0-riscv64-linux-musl.tar.xzd30f991372b2d21918fab1167c2dc52b8bfd864e3e3df08489e051cc33b1c89fkairo-0.2.0-x86_64-apple-macosx10.15.zipd9a1074177a30a8cb2d12575b4ab08a03f057bc44fc5fd1f8215c6f2a5d9b81akairo-0.2.0-x86_64-linux-musl.tar.xz93c4190798267f00e7744222339143ba6910f80eb6f5b57a9d71694181241fa4kairo-0.2.0-x86_64-unknown-freebsd.tar.xzd4691c189e28f3365f156310d4db14b03b4c4572e13e6010e4bbe3972d468699kairo-0.2.0-x86_64-unknown-netbsd.tar.xz7a39ade94d6d7e2dfbfe7b446267e826af682b2c91c7f2bc38da4e20979e6eb5kairo-0.2.0-x86_64-windows-gnu.zip6be5a6a4eff764028e206af18956e317df79157dc39ea716a265b728737b1012What's in the archive
bin/:kairo(the compiler),kcc(a clang-compatible C/C++ driver that can#include "x.k"),kld(the linker driver, for every object format),kfmt(the formatter),llvm-symbolizer,llvm-ar,llvm-ranlibandllvm-lib.lib/: Kairo'sbuiltin,stdandrtlibraries and the clang resource directory.sysroot/: 18 cross-compile sysroots: Linux musl and glibc 2.31 for x86_64, aarch64, i686, riscv64 and armv7; MinGW for x86_64, aarch64, i686 and armv7 Windows; FreeBSD x86_64 and aarch64; NetBSD x86_64; and wasm32-wasi.scripts/:msvc-sysroot.sh/msvc-sysroot.ps1anddarwin-sysroot.sh, which build MSVC and macOS sysroots from your own SDK. Apple's and Microsoft's SDKs are never shipped.share/kairo/runtimes/: the LLVM runtime sources those scripts compile.LICENSE,NOTICE,LICENSES/andTHIRD-PARTY-NOTICES.Language
Control flow
if,tryandmatchcan be used as expressions, with=>introducing each value arm.matchcovers enums, integers, ranges, tuples, negative literals and alternatives, and is checked for exhaustiveness.forloops with an empty initializer (for ; i < n; i += 1).switchstatement is gone; usematch.Functions
@inoutfor mutable references and@movefor ownership transfer. Using a moved-from value is a compile error.@copyand@move.fn op finally(self).-> yield Tproduces values lazily.panic,try/catch(as a statement and as an expression) andfinally, with each function's panic set inferred and checked.@no_unwindmarks functions that never throw.constor@purewithout being marked (-fno-infer-purityturns it off).Types
implandderivesbounds,requiresclauses, and value arguments. Generic bodies are checked by Kairo; duck-typed generics are off by default.f16,bf16,f32,f64andf128. The 80-bitf80is available on targets whoselong doubleis x87 extended precision, and anywhere else you get a clear error explaining why.??.constcorrectness throughout. Const and non-const overloads behave the way they do in C++.evalconstants,eval fnandeval for.Operators
!=is derived automatically from==, and<,<=,>,>=from<=>.[]returns an assignable location, sox[i] = vworks on your own types.op ()can be called like a function.^^for exponentiation.asnow binds looser than prefix operators, so casts of negative numbers and addresses do what they look like.Strings
{x=}. Format specs are checked at compile time.stringowns its memory: it is copied and freed correctly, and==compares two strings.Loops and ranges
for ... inworks over ranges, arrays, slices, vectors, sets, maps (for (k, v) in m), generators, your own types (by definingop in), and C++ containers.Modules and imports
import self::ximports the file beside this one, andimport module::ximports from the root of the current module.pubandprotimports.pub,protandpriv. A declaration with no visibility written isprivto its file, orprotto its module when amodule.ksits at or above the file.module fooline in amodule.knames the library, whatever its folder is called.-I diradds a Kairo search directory and a C/C++ include directory at once.import std::io. Built-in types are always available.Macros
C and C++ interop
ffi "c"and C++ headers withffi "c++". C headers get C linkage automatically.stdis reached ascxx::std. Plainstdis always Kairo's standard library.T¶meter is an@inoutparameter in Kairo, and the call site passes&x.@cxx::newand@cxx::deleteallocate and free with C++newanddelete.unsafepointers, so it's always clear where Kairo's safety guarantees end.size_tand its relatives map tousizeandisize.__builtin_popcountare available directly..kfiles and are compiled and linked in the same command.kcccan#include "foo.k"and use itspubdeclarations.--emit-headers=<dir>writes C++ headers for your Kairo modules, so C++ projects can use them.Tools
kairo, the compiler.kcc, a drop-in forclang/clang++that also understands Kairo: it compiles C, C++ and Kairo inputs, and C++ inputs can#includeKairo files.kld, the linker driver, for ELF, Mach-O, PE/COFF and WebAssembly.kfmt, the formatter:kfmt --check,--writeor--stdouton files or directories.--cache-dir, unchanged files skip code generation on the next build, and the cache is shared across the tools.--force-recompileignores it.--progress=auto|always|never|lines;linesprints machine-readable progress events).Platforms and targets
--targetand the matching bundled sysroot is used automatically. Bundled targets: Linux (glibc 2.31 and musl), Windows (MinGW), FreeBSD, NetBSD and WebAssembly (WASI).<arch>-linux-musltarget builds a static executable.scripts/;kairothen finds it with no flags.--freestandingcompiles without a C library, CRT or prelude, for bare-metal and kernel code.--print-cpusto see what a target supports.Diagnostics
kairo --explain <CODE>).--error-format=basicprints one line per diagnostic, with fix-its in a machine-applicable form for editors and scripts.--error-format=jsonis also available.privconstructor or aprotdeclaration from outside its scope is a Kairo error with a fix-it.Performance
--threads,--sema-threads,--codegen-threads).--cache-diris reused.--time-passesand--time-traceshow where compile time goes.## Coming from Stage 0
This release includes breaking changes. Every removed form is a compile error, and many of those errors carry a fix-it that rewrites the code for you (for example braced value arms,
op deleteandimport module foo)..kextension instead of.kro.=>. Braced value arms are an error, and the fix-it rewrites them.switchis replaced bymatch.ref!andmref!parameters become@inoutand@move.T¶meter is@inout, and the call site needs&x.fn op finally(self); the fix-it renamesop delete. Thedelete pexpression is removed: use@destroy p, or@cxx::delete pfor memory from C++new.asbinds looser than prefix operators.b""byte strings are removed, andr""is now a true raw string.\x27and\x22escape workarounds are no longer needed.priv(orprotunder amodule.k) unless markedpub.import module Xis removed; writeimport X,import self::Xorimport module::X.-I name=pathis removed; name a library with amoduleline in itsmodule.k.unsafepointers.concat!is renamedpaste!, and variadic macro parameters are written...name.===,.*and->*can no longer be overloaded.conston a method is rejected; useconst selfinstead.--out-diris renamed--cache-dir.Fixed issues
stringowns heap memory but has no destructor or copy: every f-string leaks, and a destructor alone would double-free #103stringowned heap memory but had no destructor or copy, so every f-string leaked.string == stringhas no operator (SC066E) #99string == stringhad no operator (SC066E).module fooin a module.k names the library, not its folder name or the -I basename #109 Module pinning: amodule fooline in amodule.know names the library, rather than its folder name or the-Ipath.includefail with R018E "duplicate module root", although none holds a .k file #102 Several-Iheader directories all namedincludefailed with R018E "duplicate module root".privconstructors and same-module access now get Kairo diagnostics.derives u8) is ignored; the tag is always u32 #98 A payload enum's declared underlying type (derives u8) was ignored; the tag was always 32 bits.unioncaused an internal compiler error during code generation.emplace_back(x)on acxx::std::vectorfound no viable overload.L<i32>::P), loses the instance's arguments #91 A type nested in a generic class, named through an instance (L<i32>::P), lost the instance's arguments.Foo<i32>::Inner) were treated as dependent.Box<i32>) failed with SC116E..Variant == xis SC123E: a dotted variant gets no expected type as the LEFT operand #83.Variant == xfailed with SC123E when the dotted variant was the left operand.Selfwas reported as "used outside of a type body" inside a generic or structuralextend.i32default.<>marker was rejected as an empty parameter list (S049E).fnwas rejected in expression position..*and->*from the operator-overloading page (they are not overloadable since 7e4d5330) #110 The operator-overloading docs no longer list.*and->*as overloadable.Plus many other crash and correctness fixes.
Known limitations
for ... inover a Kairostringisn't supported yet (SC116E). Vectors, sets, maps, slices, arrays and ranges work.x.finally()is reserved and not implemented until 0.3 (SC116E).<=>on two primitive values doesn't yield a usableOrderingyet. User types with their ownop <=>work.byte & bytehas no operator yet.Slice[i]) or astringis not bounds-checked. Vector indexing is.await,spawnand thethreadexpression are not compiled yet:spawnandthreadstop with an internal compiler error, andawaitis rejected (SC086E).*Iface) are not compiled yet.fn <T>(x: T)) are rejected (SC116E).constmove-only value by value ([bug] A const MOVE value passed by value is a copy no one reports until clang #89) or passing a non-transferable value by value ([bug] A NON_TRANSFER value passed or returned by value passes Sema and fails in clang #84), are reported by the C++ step (CL001E) rather than by Kairo.unsafe { expr }in value position is mistyped (SC028E) ([bug]unsafe { expr }in value position is typed as a one-element set literal #96).-fsanitizeis not supported yet ([bug] -fsanitize never reaches clang: kairo rejects it, and kcc accepts it but leaves Kairo code uninstrumented #101).@packedand@align(N)work, but@pack(N),@bitfield(N)and@voidedaren't implemented yet ([feature] Type layout attributes: honor @packed / @align(N), add @pack(N), @bitfield(N), @voided, and diagnose unknown attributes #105).f80literals are not always correctly rounded, and very long fractions are dropped ([bug] f80 literals are not correctly rounded, and long fractions are silently dropped #79).x + 1is warned about twice, once by Kairo and once by the C++ step ([bug] A discarded value has no Kairo warning;x + 1gets clang's C1119W instead, and an f-string gets nothing #100).kairo sysrootgenerator isn't in this release; the prebuilt sysroots ship instead. Targets without a bundled sysroot need--sysrootor--freestanding.The full, current list is on the Implementation Status page.
Troubleshooting
macOS: "cannot verify this app is free of malware" when running a downloaded release binary. Release binaries aren't notarized yet. If you downloaded the archive with a browser, clear the quarantine flag on the unpacked folder (the curl installer doesn't need this):
Windows: Defender or SmartScreen flags the downloaded binary. Release binaries aren't code-signed yet, so SmartScreen shows "Windows protected your PC" on first run. Click More info -> Run anyway. If Defender quarantines the archive outright, unblock it before extracting:
The PowerShell installer (
irm https://kairolang.org/install.ps1 | iex) downloads without the browser's mark of the web, so it usually avoids both prompts.kairo: command not foundafter installing. The installer links the tools into~/.local/bin(on Windows it adds the install'sbinfolder to your userPATH). Open a new terminal, or add~/.local/bintoPATHif your shell doesn't include it.error [P008E]: no sysroot found for target ...for a*-apple-macosxor*-windows-msvctarget. Apple's and Microsoft's SDKs can't be redistributed, so those sysroots don't ship. Build one from your own SDK with the scripts in the archive'sscripts/folder (darwin-sysroot.sh,msvc-sysroot.sh/msvc-sysroot.ps1); Kairo finds the result with no flags.Feedback
This is exactly what an alpha is for. Please file issues using the templates. If the compiler reports an internal error, paste the full output and the smallest file that reproduces it.
Report security issues privately, as described in SECURITY.md: through GitHub's private vulnerability reporting, or by email to security@kairolang.org.
License
Kairo is licensed under Apache-2.0 WITH AdditionRef-Kairo-Runtime-exception.
Compiler/Spec/is licensed CC BY 4.0.THIRD-PARTY-NOTICESandLICENSES/in each archive.This discussion was created from the release Kairo 0.2.0.
All reactions