Familiar as TypeScript. Fast as Rust.
Familiar as TypeScript. Fast as Rust.
Velt compiles typed, modern TypeScript (classes, interfaces, generics, async/await) ahead of
time to one native executable. No interpreter, no garbage collector, every core in use.
veltlang.com · Getting started · Tour · Docs · Benchmarks · VS Code extension
// src/main.velt of a package made with `velt new hello --template api`: `velt run`
import { serve } from "http-server";
interface User {
id: string;
name: string;
}
const users = new Map<string, User>();
users.set("42", { id: "42", name: "Ada" });
await serve({ port: 8080 }, async (req: Request): Promise<Response> => {
const id = new URL(req.url).searchParams.get("id") ?? "";
const user = users.get(id);
if (user === undefined) {
return Response.json({ error: `no user ${id}` }, { status: 404 });
}
return Response.json(user);
});
That is a complete HTTP server, and every core answers requests. It serves as many JSON requests a second as Rust's axum and over ten times as many as Node, in a fraction of Node's memory (benchmarks, with their method and raw data in bench/).
async/await, the JavaScript
APIs you know. What is left out is left out on purpose: eval, prototypes, with, delete,
1 == "1".number becomes a machine integer wherever
that gives the same result. Integer types from i8 to u64 are there when you want them.await is a compile error.velt build --release writes a self-contained executable, and
cross-compiles from any OS. Also to WebAssembly and Cloudflare Workers.velt dev hot-swaps the functions you change on every save.declare c calls C libraries, checked against their headers.Velt is a language of its own: TypeScript's syntax, plus what a native language needs.
i8 to u64, f16 and bf16a + b * 0.5 on vectors and matricesshared<T>, Atomic<T>, Mutexthrows clauses the compiler checksdeclare cAn operator is a method with a well-known symbol key; a + b compiles to one direct call:
class Vec3 {
constructor(public x: f64, public y: f64, public z: f64) {}
[Symbol.add](o: Vec3): Vec3 { return new Vec3(this.x + o.x, this.y + o.y, this.z + o.z); }
[Symbol.sub](o: Vec3): Vec3 { return new Vec3(this.x - o.x, this.y - o.y, this.z - o.z); }
[Symbol.mul](k: f64): Vec3 { return new Vec3(this.x * k, this.y * k, this.z * k); }
static [Symbol.mul](k: f64, v: Vec3): Vec3 { return v * k; }
[Symbol.neg](): Vec3 { return new Vec3(-this.x, -this.y, -this.z); }
toString(): string { return `(${this.x}, ${this.y}, ${this.z})`; }
}
const a = new Vec3(1, 2, 3);
const b = new Vec3(4, 5, 6);
const c = new Vec3(1, 1, 1);
console.log((a + b * 0.5 - -c).toString()); // (4, 5.5, 7)
console.log((2 * a).toString()); // (2, 4, 6)
Whole programs in examples/apps: vindex, a disk-based vector search index on SIMD kernels and memory-mapped files; seek, a ripgrep-style search; redis-clone, a Redis-compatible server; and web services, a chat and server-rendered TSX apps.
The differences in one place: Velt for TypeScript developers. What comes next: the roadmap.
curl -fsSL https://github.com/velt-lang/velt/releases/latest/download/get-velt.sh | sh # Linux, macOS
irm https://github.com/velt-lang/velt/releases/latest/download/get-velt.ps1 | iex # Windows (PowerShell)
The toolchain brings its own linker: no Visual Studio, Xcode or C compiler needed.
velt new hello # or: --template api | cli | websocket | lib
cd hello
velt run # build and run src/main.velt
velt dev # run it, and hot-swap your changes on every save
velt test # run the tests
velt build --release # an optimized native executable
Then read Getting started and the tour.
Everything lives on veltlang.com/docs: the Book (guides), the Reference (the language rules), the standard library, packages (the HTTP server, SQLite, PostgreSQL, Redis, Cloudflare) and tooling.
This repository holds the compiler, the runtime, the standard library (std/) and the first-party packages (packages/). How the compiler works and why the language is designed the way i
Objects built from a record in a generic body list a static-order type's keys in its literals' order, not the order they were set
https://github.com/velt-lang/velt/issues/4482
Labels: None
Member key text: a string key starting with U+FFFF loses it in a null/undefined read's TypeError
https://github.com/velt-lang/velt/issues/4481
Labels: area:sema, kind:bug, ts-compat
Generator.return(value) (typed and through any) gives { value, done: true } as in Node
https://github.com/velt-lang/velt/issues/4479
Labels: None
std: WeakMap and WeakRef don't build for the JS host (#weak-os has no js variant)
https://github.com/velt-lang/velt/issues/4478
Labels: None
ICE in a hook call's operand and a std move error for async try/catch shapes with a then callback
https://github.com/velt-lang/velt/issues/4476
Labels: None
release: a field a toString assigns through a generic template reads back as another object
https://github.com/velt-lang/velt/issues/4475
Labels: None
sema: a catch whose try assigns another union member mid-way keeps never, so a conversion's TypeError ends the program
https://github.com/velt-lang/velt/issues/4474
Labels: None
Thanks for helping. This page covers building, testing, the coding standards, and how to propose changes. How the compiler is put together is in docs/internals.
Open an issue with a minimal .velt program, the command you ran, what happened and what you
expected, and velt --version. An internal compiler error (a message starting with
internal compiler error, exit code 101) is always a bug, whatever the input. Security problems
go through SECURITY.md, not public issues.
You need Rust (stable) and a system linker: the Visual Studio Build Tools ("Desktop development
with C++") on Windows, build-essential on Linux, the Xcode command line tools on macOS. Release
builds compile with a clang of the pinned zig's LLVM version (22.1.8): a system one of exactly that
version, else the pinned zig's, downloaded on first use ($VELT_ZIG names one); a system clang 16
or newer is the fallback, and what the LLVM backend's in-process
tests use, so install one too for the release-mode tests. Programs built in a checkout
link with the system linker; to try the bundled linker released toolchains use, see
Linking.
cargo build --workspace
cargo run -p veltc --bin velt -- run tests/golden/m1/hello.velt
Builds are large. Point CARGO_TARGET_DIR at a disk with room if needed; VELT_GOLDEN_WORK
moves the end-to-end tests' build directories the same way (the goldens build in it, and the
LLVM, wasm, playground, panic, debugger and debug-info tests in subdirectories of it).
Debug builds of the compiler carry line tables only (file and line in backtraces and panics);
set CARGO_PROFILE_DEV_DEBUG=full when you want to inspect local variables in a debugger
(dependencies stay without debug info).
| Command | What it runs |
|---|---|
cargo test -p <crate> | one crate's unit and integration tests |
cargo test --workspace --test golden | the end-to-end tests: every tests/golden/**/*.velt with an expected .out, built and run in debug and release mode (filter with VELT_GOLDEN=m1/strings) |
cargo test -p veltc --test std_tests | the standard library's tests: velt test <dir> of the directories of test files of tests/std/<module>/ (black-box) and of std/ (its white-box *.test.velt files), in debug mode with a leak check and in release mode, split into eight shards (filter with VELT_STD_TESTS=http, VELT_STD_TESTS=std for the white-box ones) |
cargo test -p veltc --test docs | the documentation tests: every ts code block in README.md and the http-server package's README.md and docs/ must compile (filter with VELT_DOCS=<file:line>); the user docs are on the website, which checks its own examples |
cargo test -p veltc --test packages | velt test in each of the repository's packages (packages/<name>/, the database drivers), in debug and release mode, after building a package's native crate, whose cargo test runs too; the database tests need VELT_TEST_PG_URL, VELT_TEST_REDIS_URL (and VELT_TEST_REDISS_URL + _CA), which scripts/linux-check.sh --services sets (filter with VELT_PACKAGES=sqlite) |
cargo test -p veltc --test example_apps | velt test --locked for every example application with tests (examples/apps/<app>/tests/), each in a copy of the app (filter with VELT_EXAMPLE_APPS=chat,seek) |
cargo test -p veltc --test standards | the coding standards below (file sizes) |
cargo clippy -p <crate> --all-targets -- -D warnings | lints |
cargo xtask precheck | the fast mechanical checks on the changed files only (below) |
Run the end-to-end tests with --workspace, not -p veltc: -p resolves the crates' features
differently from the gate's --workspace build (velt_opt loses interp), so switching between
the two rebuilds velt_opt and everything above it. (--workspace --test golden also runs
velt_syntax's parser goldens, which take a second.)
The end-to-end tests take VELT_GOLDEN=a,b (files matching any of the substrings),
VELT_GOLDEN_MODES=debug or release (one build mode only), VELT_GOLDEN_JOBS=<n> (default
one per core, at most 16), VELT_GOLDEN_TIMEOUT=<s> (default 120), VELT_GOLDEN_SHARD=<i>/<n>
(the i-th of n interleaved shards) and VELT_GOLDEN_STRICT=1 (failures under a .pending
directory fail the run too). The debug runs use the runtime's checking allocator
(VELT_RT_DEBUG_ALLOC=1; =0 turns it off): a use after free (a read through a dangling
pointer, a write, a double free) or overflow aborts with velt debug-alloc: …, and a captured
variable's cell used by two tasks (a closure assigning it reached another task or HTTP request
without a copy) aborts with velt debug-cells: … (rt_abi.md "Counted objects").
velt_syntax's robustness test (prefixes_never_panic_*) cuts the goldens and parses what comes
before and after each cut, which must never panic. It cuts the kitchen sink and the goldens in
VELT_ROBUSTNESS_FILES at every character (comma-separated paths such as
tests/golden/lang/foo.velt; cargo xtask check sets it to the goldens you changed), and the
other goldens where each token starts or ends plus a fixed sample of characters.
VELT_ROBUSTNESS=full cuts every golden at every character (about eight times the work): the
nightly gate sets it, and so does cargo xtask check (and the merge queue, and the label ci:full)
when velt_syntax, a crate it depends on, rust-toolchain.toml or the root Cargo.toml changed,
or when the changes can't be told. For any other change cargo xtask check and the merge queue set
VELT_ROBUSTNESS=changed, which cuts only the kitchen sink and the changed goldens: the same parser
gives the other goldens the same answers. velt_fmt's corpus tests work the same way
(VELT_FMT_CORPUS=changed, VELT_FMT_CORPUS_FILES): the changed .velt files unless the formatter or
what it depends on changed. The nightly gat