Building a Custom Programming Language and OS with OCaml, LLVM, and Generative AI
Explore creating a safer OS kernel and programming language using OCaml, LLVM, and AI to improve system reliability and design innovative abstractions for kernel development.
Welovebuildingoperatingsystems
But the traditionalimplementation language is a problem:
C language gives the kernel complete control
+
C language gives the kernel almost no proof
=
one bad access can corrupt the entire system
We wanted a language designed for the place where a crash is least recoverable.
Could more kernel failures become compile-time errors?
2 / 15
OCaml Meeting 2026 in Tokyo
2
3.
WhyOCaml+LLVM+GenerativeAI?
Ingredient Role
OCaml Makesyntax and static semantics explicit and changeable
LLVM Produce real native code without writing machine backends
Generative AI Implement enough compiler and kernel code to test ideas end-to-end
The LLVM project officially maintains OCaml bindings.
LLVM IR is still hard. AI made it easy.
3 / 15
OCaml Meeting 2026 in Tokyo
3
4.
Thesetup,keepsthehumanontheloop
Linux Desktop
devcontainer
Takibi toolchain
RaspberryPi 5
USB storage (ext2)
Memory
Takibi kernel
AI Agents Internet
AI coding CLIs
Claude Code · Codex · Copilot
Ethernet
validate httpd
TCP/IP stack
UART
monitor logs
UART monitor
SWD
memory + debug
OpenOCD + GDB
SWD debug interface
hardware memory access
Takibi compiler
OCaml + LLVM
kernel image
BusyBox (httpd)
UART driver
4 / 15
OCaml Meeting 2026 in Tokyo
4
Thekernelisthelanguage-designworkload
1
AI implements
a realkernel path
2 Repeated
Takibi code patterns
expose missing guarantees
3 The OCaml
compiler learns
a checked abstraction
4
The next
kernel path
becomes safer and simpler
6 / 15
OCaml Meeting 2026 in Tokyo
6
7.
Ctechnique:describeNICstatewithbooleans
frame->valid = true;
frame->tx_in_flight= true;
frame->released = false;
The representation also permits contradictions:
frame->valid && frame->released
frame->tx_in_flight && frame->available
Every caller must remember which combinations are legal.
The compiler sees only fields and integers.
7 / 15
OCaml Meeting 2026 in Tokyo
7
MakeinvalidNICstatesunrepresentable
The type checkerprevents:
releasing the same RX frame twice;
transmitting before validation;
reacquiring a descriptor before TX completes;
forgetting to return an active descriptor to DMA.
detect an invalid state later C flags
make the invalid state impossible Takibi types
The capability types add no new descriptor identity at runtime.
9 / 15
OCaml Meeting 2026 in Tokyo
9
10.
Ctechnique:returnapointerintoanRXbuffer
uint8_t *packet =net_rx_frame(frame);
net_rx_release(frame); /* DMA owns it again */
parse(packet); /* use after release */
The pointer still looks valid.
Its type does not remember:
the available length;
the descriptor it came from;
when ownership returned to DMA.
10 / 15
OCaml Meeting 2026 in Tokyo
10
11.
Takibitechnique2:tietheslicetodescriptor
authority
fn net_rx_frame(frame: borrowNetRxValidated[desc])
-> [u8; 1514..] @ desc;
The result carries two proofs:
at least 1514 bytes are available
+
the slice is derived from descriptor desc
let packet = net_rx_frame(frame);
let ready = net_rx_release(frame);
parse(packet); // compile error
11 / 15
OCaml Meeting 2026 in Tokyo
11
12.
AproblemeventheAIcouldnotsolve:STM32
UART
AI: "Serial outputis lost while using the SD card."
It kept investigating symptoms.
Human:
Our UART is polling, while the SD card uses DMA. ChibiOS/RT normally uses
DMA and interrupts for both. What happens if we change UART to DMA + IRQ?
AI: Implemented it, tested it on the board -- problem solved.
12 / 15
OCaml Meeting 2026 in Tokyo
12
13.
Anotherblindway:kernelprintfdebugging
AI: Added moreand more kernel-side prints to infer userspace behavior.
Human:
If we need to know what BusyBox does, why not read the BusyBox source?
AI: Read the actual userspace implementation -- problem solved.
more observability is not always more understanding
The human changed the source of evidence, not the amount of logging.
13 / 15
OCaml Meeting 2026 in Tokyo
13
14.
TheoneOCaml-sideroughedge:DWARF
Takibi emits DWARFand supports source debugging through GDB.
LLVM's OCaml bindings still lack convenient APIs for:
dbg.value locations for SSA and entry parameter values;
DISubrange construction for natural fixed-array display.
Takibi currently works around those gaps with debug-only allocas,
volatile preservation stores, and GDB artificial arrays.
We would like to contribute these capabilities upstream.
Details: Takibi's open DWARF issues
14 / 15
OCaml Meeting 2026 in Tokyo
14