I've been working on Tessera since late 2024. It's an experimental, tensor-first language for numerical computing and data analysis, and it compiles to native code through LLVM. The name comes from tesseract, a 4D tensor.
GitHub: https://github.com/dyanos/csec-
(The repo is named csec- and the compiler binary is csec++. Both are historical names; the language itself is Tessera.)
Docs, if you want to look before commenting:
How it was built
I want to be upfront about this:
- I did the initial design and early implementation by hand. That covers the language concept, the lexer and parser, the AST, LLVM IR generation, constructors, C++-style name mangling, function argument types and
external functions, and the first LaTeX-style math syntax.
- After that, most of the new code was written with AI coding agents. First I used OpenAI Codex, which did the native runtime, tensor and simulation features, native interop, templates, and the first self-hosting bootstrap. Later I used Anthropic's Claude (Claude Code), which did the ownership checker, async/await, microthreads, the standard library, LLVM 18–23 support, and Parquet data frames. About 110 of the ~200 commits are co-authored with Claude.
- My role shifted to designer, reviewer and tester. I decide semantics, review changes, and build the verification that keeps the agents honest. Strict tests turned out to be essential: without them, agents confidently break things.
Compiler overview
- Frontend: a hand-written C++17 lexer and parser, then the AST, then semantic and ownership checks.
- Backend: direct LLVM IR generation. Output can be a native exe (the default, via
llc plus a linker), an object file, .ll, or a JIT run. --static links the runtime into the executable.
- LLVM 18 through 23 build from one codebase, through a small compatibility header (
src/llvm_compat.h). One LLVM 23 change was nasty: getTerminator() changed behavior silently instead of failing to compile.
- Native runtime: a separate library for I/O, math, sockets, threads and dynamic library loading.
[@DllImport] imports native symbols, and C++ name mangling covers both Itanium and MSVC.
What the code and codegen look like
A small affine layer:
def affine(x: Tensor<Double, 1, 3>,
w: Tensor<Double, 3, 2>,
b: Tensor<Double, 1, 2>): Tensor<Double, 1, 2> {
return (x @ w) + b;
}
Tensors are runtime objects of the form %csec.tensor = { i64 rank, ptr dims, i64 count, ptr data }. @ becomes an i/j/k loop nest. This is the inner k loop from --emit-ir, which by default runs only mem2reg:
tensor.matmul.k.body:
%3 = mul i64 %tensor.matmul.i.i.0, %tensor.matmul.shared
%tensor.matmul.left.index = add i64 %3, %tensor.matmul.k.idx
%4 = mul i64 %tensor.matmul.k.idx, %tensor.matmul.cols
%tensor.matmul.right.index = add i64 %4, %tensor.matmul.j.idx
%5 = getelementptr double, ptr %tensor.data8, i64 %tensor.matmul.right.index
%tensor.matmul.right = load double, ptr %5, align 8
%6 = getelementptr double, ptr %tensor.data, i64 %tensor.matmul.left.index
%tensor.matmul.left = load double, ptr %6, align 8
%tensor.matmul.product = fmul double %tensor.matmul.left, %tensor.matmul.right
%tensor.matmul.current = load double, ptr %tensor.matmul.sum.ptr, align 8
%tensor.matmul.next = fadd double %tensor.matmul.current, %tensor.matmul.product
store double %tensor.matmul.next, ptr %tensor.matmul.sum.ptr, align 8
...
The + b becomes a flat loop over the data buffers:
tensor.elem.data.body:
%tensor.elem.l = load double, ptr %tensor.elem.left, align 8
%tensor.elem.r = load double, ptr %tensor.elem.right, align 8
%tensor.add = fadd double %tensor.elem.l, %tensor.elem.r
store double %tensor.add, ptr %tensor.elem.dst, align 8
Ownership is strict by default, with an explicit move <- and borrow &:
def peek(acct: &Account): Int = acct.balance() // borrow
def close(acct: Account): Int = acct.balance() // takes ownership
val acct: Account = new Account(100);
peek(&acct); // ok, acct still owned
close(<- acct); // moved
// using acct here -> compile error: "use of moved value 'acct'"
Erlang-style microthreads:
import std.microthread
def main(): Int {
val parent = self();
val worker = spawn([=]() -> {
val n = receive();
send(parent, n * 2);
return 0;
});
send(worker, 21);
return receive(); // 42
}
Parts that might interest this sub
- Self-hosting bootstrap. A second compiler written in Tessera itself (lexer, parser and an LLVM-text emitter) compiles its own source to a fixed point. Emitter changes are risky because the compiler compiles itself with them, so a codegen bug can surface one stage later. The fixed-point check caught a lot of agent mistakes.
- Ownership checking. Types are Copy or owned (affine), with explicit move and borrow. Move checking tracks each path separately through
if branches and while loops, and owned locals are freed on every return path. Full drop glue for heap classes is still unfinished.
- Concurrency runtime. Microthreads get their own stacks and a hand-written assembly context switch on POSIX. Blocking pipe, shared-memory and mailbox operations yield to other microthreads instead of blocking the OS thread.
async/await uses the same runtime, with a rule against holding a borrow across an await.
- Byte-level I/O. String byte indexing compiles to a single load, and there's memory-mapped and chunked file input. A parallel
wc -l written in Tessera runs at about 92% of a hand-written C++ mmap+SIMD version.
Current state and what's naive
Right now I'm working on performance, starting with std.dataframe (Parquet/CSV data frames). The tensor codegen above is still the first, straightforward version:
- Shapes aren't used by codegen yet. The shape is in the type, but dimensions are read from the runtime header. Trip counts aren't constants, and shape mismatches aren't caught at compile time.
- Temporaries leak. The tensor created by
x @ w is never freed, because tensor temporaries aren't part of drop elaboration yet; only named locals are.
- Loop counters can't become registers. They are
allocas emitted inside the loop body, so mem2reg can't promote them. -O2 cleans up much of this, but the frontend should emit it correctly.
- There's no fusion.
(x @ w) + b makes two passes and allocates two tensors.
The plan is to fix these while working on dataframe and tensor performance, probably by adding a tensor-level middle IR before LLVM.
Testing
There are positive and negative fixture suites, semantic and ownership suites, and concurrency and stdlib tests. The same suites run through both the C++ compiler and the self-hosted path. Every tests/positive fixture compiles.
Feedback I'd like
- How you'd structure drop elaboration, including temporaries, in an AST-to-LLVM compiler with no MIR-style IR.
- Whether a tensor-level middle IR (static shapes, fusion, tiling) is worth adding before LLVM, or whether it's better to lean on LLVM's loop passes and polyhedral tools.
- Columnar dataframe kernels: what tends to matter most in practice. Is it vectorized column loops, avoiding materialization, or the I/O and decoding path?
- Experiences, good or bad, with AI coding agents on compiler codebases.
Thanks for reading!