Skip to content
Latest release

What's new in Velt 0.6

C libraries, JavaScript hosts, and more of TypeScript. Use any C library straight from Velt (the packages already do), deploy the same server to Cloudflare Workers, and write default exports, decorators and operators as you would in TypeScript. Velt files are now .velt.

At a glance

The details

New

Any C library is one declaration away

Velt talks to C directly now. Declare a function from any library with a C header and call it: databases, compression, image and audio codecs, system APIs. No wrapper language, no build script, no Rust toolchain. velt/ffi covers pointers, buffers, C strings and out-parameters, and C structs and constants work too.

Every call is checked against the library’s real C headers, and bundled C sources build with a pinned compiler on every platform. You stay in control: a dependency with native code only builds if your package.velt lists it in allowNative, and velt check lists every unsafe place for review.

Native packages →
abs.velt
declare c("c") function llabs(x: i64): i64;

export function absolute(x: i64): i64 {
  // SAFETY: `llabs` takes any `long long` but LLONG_MIN.
  return unsafe { llabs(x) };
}
Breaking

Velt files are .velt now

Source files end in .velt and the manifest is package.velt. .vlt is in wide use on GitHub, mostly by Verilator configuration files, which stood in the way of GitHub ever recognising Velt. .velt is Velt’s alone, so it can get its own language entry and highlighting.

.vlt sources still build for one more release, with a warning. package.vlt is no longer read: the error tells you to rename it.

Help get Velt on GitHub →
my-app/
package.velt        // was package.vlt
velt.lock.json
src/
  main.velt         // was main.vlt
  routes.velt
New

Run on JavaScript hosts and Cloudflare Workers

A WebAssembly program can call functions the JavaScript host provides, use the host’s fetch, and wait on timers without busy-waiting. velt build --host deploys the same http-server program to Cloudflare Workers, and the cloudflare package reaches R2, D1, KV, the cache and Durable Objects.

Conditional imports (#name) let a package ship different files per target.

WebAssembly →
terminal
$ velt add cloudflare host-cloudflare
$ velt build --release --host host-cloudflare
$ npx wrangler deploy        # in the output directory
New

Default exports, decorators and operators

export default, default imports and export * as ns work as in TypeScript. Typed decorators attach checked data to classes, fields and functions at compile time. And classes can define operators, so a + b * 0.5 works on your own vector type.

Decorators are read at compile time: nothing runs. TC39 run-time decorators are still not supported.

Modules →
vec.velt
export default 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);
  }
}

const p = a + b;  // calls a[Symbol.add](b)
New

Half-precision floats and faster numeric code

f16 and bf16 store two bytes per value and compute as number, matching JavaScript’s Float16Array. velt/half loads and converts them in bulk, and SIMD gains f16x8, bf16x8, int8 dot products and fused multiply-add.

Integers gain checked, saturating and wrapping arithmetic, and rotateLeft, rotateRight and swapBytes.

Types →
half.velt
const w: f16 = 0.1;   // stores 0.0999755859375
const x = w * 0.1;      // a number, as in JS

let acc: f16 = 0;
acc += 0.1;             // as Float16Array's e[0] += 0.1
New

Crypto, TLS, compression and a web framework, in Velt

velt/crypto adds X25519, ChaCha20-Poly1305, AES-GCM (with hardware AES), HKDF and P-256. velt/compress can compress now: gzip, deflate and Brotli. And the new web package is a router with middleware, including rateLimit, bodyLimit and compress().

startTls is a TLS 1.3 client that doesn’t check certificates yet, so it needs verify: false for now.

velt/crypto →

Language

  • NewJSX uses TypeScript’s automatic runtime (jsx/jsxs).
  • Newlib.dom’s types (HTMLElement, Event, …) exist as types, for code shared with the browser.
  • NewBetter inference for untyped arrows, module-level destructuring, flatMap, reduce(f) and reduceRight.
  • Newunique symbol types, and a[i]! += 1 as an assignment target.
  • Changedobject | undefined is no longer accepted where a plain object is expected.

Standard library and packages

  • NewCookies in velt/net/http: getCookies, setCookie and deleteCookie.
  • Newhttp-server: serveFile, Range and conditional requests, and req.signal aborts when the client leaves.
  • NewcatchPanic in velt/task; a panicking handler gets a 500 and the server keeps serving.
  • NewopenRead byte ranges and realpath in velt/fs.
  • Changedsqlite calls SQLite directly (bundled 3.53.2), and redis is plain Velt.

Tooling

  • NewLint profiles: velt check --perf, --fix, and lint settings in the manifest.
  • NewDebug builds use every core; VELT_JOBS sets how many.
  • NewDependencies from a release archive (url + sha256), and velt add <url>.
  • ChangedOn macOS, release builds use the newest clang found; velt doctor says which.

Fixes

  • Fixedu8[] write, set and copy throw a catchable RangeError instead of panicking.
  • FixedCalling an any that holds no function throws a catchable TypeError.
  • FixedTimers under Promise.all and yieldNow resume in Node’s order.
  • Fixedconsole.log in a source generator no longer breaks the build.

Upgrading

Velt is pre-1.0, so old syntax is removed rather than deprecated. The compiler explains how to update anything it no longer accepts.

$ velt toolchain install 0.6.0

Versions install side by side. In a package, change the velt field of package.velt and run velt update (how toolchains work). New to Velt? Install it.

  1. 1Rename your files. *.vlt to *.velt, and package.vlt to package.velt.
  2. 2Allow native dependencies. List packages with native code in allowNative in package.velt (for example allowNative: ["sqlite"]). The error shows the line to add.
  3. 3Run velt install once. The lock now records allowNative, and velt install --locked checks it.
  4. 4Run velt check. A few patterns are new errors: a server handler that changes captured state (use shared(...), a Mutex or an Atomic), and object | undefined where object is expected.
  5. 5Re-test what changed behaviour. RangeError from u8[] methods, TypeError from calling a non-function any, timer order, and a fixed workerCount().

Coming next

Decided designs that aren't built yet.

The roadmap →

Earlier releases

The story behind a release is on the blog.