An open API service indexing awesome lists of open source software.

https://github.com/kardashevlang/kardashev

A Rust-flavored systems language with lightweight effect labels in the type system โ€” LLVM backend (JIT + AOT), ownership + borrow checking, generics, traits, and #[derive].
https://github.com/kardashevlang/kardashev

borrow-checker compiler effect-system jit language llvm programming-language rust systems-programming type-system

Last synced: 8 days ago
JSON representation

A Rust-flavored systems language with lightweight effect labels in the type system โ€” LLVM backend (JIT + AOT), ownership + borrow checking, generics, traits, and #[derive].

Awesome Lists containing this project

README

          

# kardashev

A systems programming language with lightweight effect-label typing, built on LLVM.

**[๐Ÿ“– Documentation](https://kardashevlang.github.io/kardashev/)** ยท [Language Reference](https://kardashevlang.github.io/kardashev/language-reference.html) ยท [Effects](https://kardashevlang.github.io/kardashev/effects.html) ยท [Stdlib](https://kardashevlang.github.io/kardashev/stdlib.html) ยท [Architecture](https://kardashevlang.github.io/kardashev/architecture.html) โ€” Licensed [MIT](LICENSE-MIT) OR [Apache-2.0](LICENSE-APACHE)

## What it is

kardashev is a Rust-flavored systems language whose signature feature is **lightweight effect labels in the type system**: every function declares which side-effects it can produce (`io`, `alloc`, `panic`, `async`, ...) as part of its signature, and the compiler tracks them across call chains. Unlike Koka, there are no handlers or continuations โ€” effects are pure type-system information, with zero runtime cost.

```rust
fn add(a: i64, b: i64) -> i64 { a + b } // pure

fn read_cfg(path: &str) -> Result ! { io, alloc } { // effects in signature
let s = std::fs::read_to_string(path)?;
parse(s)
}

fn map(xs: Vec, f: fn(T) -> U ! {e}) -> Vec ! { e, alloc } {
let mut out = Vec::with_capacity(xs.len());
for x in xs { out.push(f(x)); }
out
}
```

The `! { ... }` syntax after the return type is the effect row. `e` is a row variable making the function effect-polymorphic โ€” `map` is pure when `f` is pure, and propagates whatever effects `f` introduces.

## Design

- **Memory model**: ownership + borrowing (Rust-style affine, non-lexical lifetimes)
- **Type system**: HM-based with generics, ADTs, traits + `impl`, monomorphization
- **Errors**: `Result` + `?` operator
- **Concurrency**: `async` / `await` lightweight tasks + OS threads with a checked `Send` / `share` rule
- **Memory management**: deterministic `Drop` / RAII (constant-memory loops)
- **Effect labels**: row-polymorphic effect sets, no handlers, compile-time only
- **Backend**: LLVM (AOT to a native binary + ORC JIT for the REPL)
- **Build**: Bazel + `rules_kardashev`, or a `Makefile.local` LLVM/clang shim
- **Source extension**: `.kd`

### Built-in effect labels

| Label | Meaning |
|----------|---------------------------------------------------------------|
| `pure` | No effects (empty row; the default if `! { ... }` is omitted) |
| `alloc` | Heap allocation |
| `io` | File / network / stdio / general syscalls |
| `panic` | Unrecoverable failure |
| `async` | Yields to the scheduler |
| `unwind` | Stack unwinding for cancellation (distinct from `panic`) |
| `share` | Crosses a thread boundary (gates the `Send` rule) |

Effect sets are unioned across the call graph and checked at definition sites; no runtime cost.

## A taste

```rust
// Generics + traits + borrowing + effects
trait Show { fn show(self) -> i64; }
struct Point { x: i64, y: i64 }
impl Show for Point { fn show(self) -> i64 { self.x + self.y } }

fn read(p: &Point) -> i64 { p.x + p.y } // borrow; NLL lets you move after its last use

fn raw_read() -> i64 ! { io } { 42 }
fn main() -> i64 ! { io } { raw_read() } // a pure-declared caller would be rejected
```

```rust
// async / await
async fn add(a: i64, b: i64) -> i64 { a + b }
async fn double(n: i64) -> i64 { add(n, n).await }
fn main() -> i64 ! { async, io } { print(double(21).await); 0 } // 42
```

`Option` / `Result` ship via a built-in prelude; `Vec`, growable `String`, and `HashMap` are built-in containers. Multi-file programs use `mod foo;` (resolves `foo.kd` siblings); a `kard.toml` manifest with local-path dependencies drives `kard build` / `kard run`. More in the [examples](examples/) and the [docs site](https://kardashevlang.github.io/kardashev/).

## Using it

```
kardc # JIT-run main() and print its result
kardc -o # AOT-compile to a native executable
kardc --test # run every `test_*() -> i64` fn (0 = pass)
kardc -O0|-O1|-O2|-O3 ... # optimization level (default -O2)
kardc # interactive REPL (JIT each expression)
kard-lsp # Language Server (diagnostics, hover, completion, rename, โ€ฆ)
kard build | kard run # build/run a kard.toml project
```

Build with Bazel (`bazel build //... && bazel test //...`) on ubuntu or macOS, or โ€” when Bazel isn't available โ€” the `Makefile.local` LLVM/clang shim. Programs compile through lexer โ†’ parser โ†’ HM typechecker โ†’ NLL borrow-checker โ†’ effect inference โ†’ LLVM IR โ†’ ORC JIT (or an AOT native object linked with `clang`). `kardc -o` uses a content-addressed incremental AOT compile cache (under `${XDG_CACHE_HOME:-~/.cache}/kardashev`, keyed on the resolved source + flags); pass `--no-cache` to bypass it.

## Status

Nineteen roadmaps (**v1โ€“v19**, Phases 0โ€“114) have shipped and are merged to `main`, each green on a cleared clean build โ€” 6 unit suites plus the full smoke / fuzz aggregate, **JIT and AOT**, on ubuntu + macOS CI. Current release: **[v0.19.0](https://github.com/kardashevlang/kardashev/releases/latest)**.

The north-star arc is **self-hosting**: v15โ€“v17 build a complete compiler *in* kardashev โ€” lexer โ†’ parser โ†’ type checker โ†’ code generator + VM, with `examples/selfhost/compile.kd` type-checking a whole function and then compiling + running its body. Dogfooding it found and fixed three real host-compiler bugs. v18โ€“v19 added a differential fuzzer (random programs, `JIT == AOT == reference`) across the arithmetic, control-flow, memory-safety, and integer codegen paths.

> The per-phase history and every release's details live in **[CHANGELOG.md](CHANGELOG.md)**.

## Roadmap

| Version | Theme |
|---------|-------|
| v1 | MVP: the full pipeline (lexer โ†’ HM types โ†’ LLVM JIT/AOT), ownership + NLL borrow check, ADTs, traits/generics, `Result`/`?`, **effect labels**, `async`/`await`, modules, LSP |
| v2 | Iteration, closures + effect-carrying fn types, `dyn Trait` dispatch, a growable stdlib, `kardfmt` |
| v3 | `Drop` / RAII (constant memory), panic + unwinding, OS threads + `Mutex`, opt-levels + `--test` |
| v4 | Generic trait params + associated types + `where`, arrays/tuples, `const` evaluation, `extern "C"` FFI |
| v5 | Stdlib depth (strings, generic `HashMap`), file I/O + CLI args, self-written capstones (`calc`, `rpn`) |
| v6 | "make the heap recursive" โ€” `Box` / recursive enums; a JSON parser written in kardashev |
| v7 | "real numbers, real abstraction" โ€” `f64`, `#[derive]` Clone/Eq; JSON 2.0 |
| v8 | "generics, finished" โ€” `Ord`/`Hash`/`Default` derives, generic trait objects; JSON 3.0 |
| v9 | "data in motion" โ€” `Vec` combinators, string tools; a word-frequency capstone |
| v10 | "sized and sound at compile time" โ€” const-generics, dimension-checked matrices, effect-subset soundness |
| v11 | "real machine integers" โ€” the numeric tower (sized int/float, `as`, bitwise, defined wrapping) |
| v12 | "real stdlib" โ€” parsing, `Vec`/`HashMap`/`String` methods, math helpers |
| v13 | "concurrency" โ€” the `share` effect, typed MPSC channels, the structural `Send` rule |
| v14 | "hardening" โ€” cross-platform CI (macOS green), a JIT-vs-AOT differential sweep |
| v15 | "self-hosting" โ€” a compiler front-end written in kardashev |
| v16 | "self-hosting, continued" โ€” the body grammar (parser + interpreter) |
| v17 | "a compiler in kardashev" โ€” a self-hosted type checker + code generator; capstone `compile.kd` |
| v18 | "hardening II" โ€” review-followup fixes + a differential fuzzer |
| v19 | "hardening III" โ€” memory-safety + integer fuzzers, cleaner diagnostics |

## Why "kardashev"?

The [Kardashev scale](https://en.wikipedia.org/wiki/Kardashev_scale) ranks civilizations by how much energy they can harness. A systems language, in its own small way, is about controlling resources at scale โ€” a fitting name for one that aims to be precise about effects, ownership, and computation.

## License

Licensed under either of

* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.