What does not work yet
generated from midad spec --json at build time; not edited by hand
A plain list, so you find the wall before you hit it. Nothing here is a plan; RESOURCES.md and ../SPEC.md hold the intentions.
Structure
- Imports exist, a package manager does not.
imports:in the frontmatter joins files into one program and each file's declarations are reached through itsmodule:name (or anasalias). What is missing is everything above that: no versioning, no registry, no dependency resolution.midad vendorcopies a library in and records a fingerprint of each file, so a copy that has drifted is aW003warning frommidad check; that is drift detection, not dependency management. - No types of your own. No structs, records, enums or classes. A map with string keys is the only record.
- No generics, no closures, no function values. A function name can be an
argument for a
fnparameter and nothing else. See "Functions are arguments, not values" below. - No tests framework and no debugger.
midad check,midad fmtand running the program are the tooling.
Types
- Lists and maps are untyped.
at(list, i)returnsany, so every read needsint(...)orstr(...)before it is arithmetic or a comparison. This is the most common friction in practice; see LLM-EVAL.md. - Numbers are
number(i64) andfloat(f64) and nothing else. No decimal, no big integers, no unsigned. optionandresultcarry no payload type.number?parses as sugar foroption; the payload is checked when used, not when declared.- Map key order is byte order of the key, not insertion order.
keys()returns sorted keys in the interpreter and in the C backend (pinned bykeys-sortedinfour_paths.rs, with mixed case and a prefix key). Iteration over a map is not separately pinned: usekeys()when order matters. - No string formatting control.
printadds the newline; there is no padding, precision or alignment.
Backends
The C backend (midad build --native-all, the default when cc exists) covers a
subset and refuses the rest by name rather than miscompiling it:
- FFI
- a route written with an inline body (a route answered by a named handler does compile; see "A native build cannot serve HTTP" below)
read_fileand the other blocking builtinseval_source- assigning a different type to an existing variable
- a local variable whose name is a C keyword (
short,int,free, ...)
A state block is a file-scope cell in a C build, and an ai:intent call
lowers to the intent's own fallback value, because a native binary has no
model to call; an intent with no fallback is refused by name. A function named
main is emitted as mxf_main rather than refused, and the binary runs the
exec block and then the entry function (entry: or main), like the
interpreter.
db.* is not on that list: the C backend covers it, loading the system's
SQLite at run time. Cranelift and midad-rt refuse it by name.
Anything on that list runs in the interpreter and needs --backend cranelift
or plain midad run. Cranelift in turn refuses par ("par is only supported
by the C backend"); it builds state blocks and an ai:intent that has a
fallback:, which earlier revisions of this page said it did not. Its builtin
coverage is counted in NATIVE.md: 23 of 72 build, 39 are refused
by name.
Concurrency
paris the only parallel construct. No threads you can create, no channels, no atomics, no locks, noasync/awaitin the language.- The interpreter runs
parserially. Same answer, no speedup. - The HTTP server runs one interpreter instance per core (override with
MIDAD_WORKERS, 1 turns the pool off), each behind its own mutex, so a CPU-bound route holds one instance and the others keep answering. A request that finds every instance busy gets 503. A program with astate:block, or one served by native handlers, runs a single instance. See READINESS.md for what several workers do to a program that writes a shared document. - No speedup has been measured on more than one core. On one vCPU the
parform costs 33% more than the serial loop; the cause is an open question in ../BENCHMARKS.md.
Memory
- The native C runtime counts references and frees what it made. Every string, list, map and option payload carries a count; a variable, list slot, map slot or state cell that keeps one takes its own reference, and gives it back when it is overwritten or when its scope ends. A statement that allocates gives its temporaries back when it ends. Measured on the template workload, peak RSS is 1.6 MB at 100,000 renders, the same at 200,000 and at 400,000, with the runtime's own counter at zero live objects on exit. The allocating runtime that came before was 16.7 MB, 32.0 MB and 62.6 MB on the same three counts (../BENCHMARKS.md has the table).
- A value the program keeps still holds memory, which is the point: a list of 200,000 renders costs what a list of 200,000 strings costs.
- The interpreter caps what one operation can build, not the whole heap. A
string may not pass 64 MiB (
a + b, andreplacewhen it would), and a list built withpushmay not pass 4,194,304 elements; either is a runtime error the program sees, not a process killed by the OS. Before this, fortys = s + ssteps ran out of memory. This is a per-operation cap, not a budget: many values under the cap still add up. A single file read or write is capped at 16 MiB, the same ceilinghttp_getputs on a body, checked before the read and again on what came back; over the cap is a named runtime error, so a route that reads a path it did not choose cannot take the process down. The C backend and Cranelift apply the same caps to+,pushandreplace(same error text, pinned bystring-cap,list-capandreplaceinfour_paths.rs), and a nativeread_fileover the cap traps with the same message. Not measured: what the extra compare costs on a hot append loop. - No whole-heap budget, so there is no bounded-memory mode.
- Source nesting is capped. An expression nested more than 256 levels (each
parenthesis or list costs about two) and blocks nested more than 64 deep are a
diagnostic (
E0100,E0102). Before this a few thousand(overflowed the stack and aborted the process.
Network
http_getrefuses private and local addresses. Thenetgrant names a host as text; the address it resolves to is checked too, and loopback, private, link-local (including169.254.169.254), carrier-grade NAT, multicast and reserved ranges are refused, for IPv4, IPv6 and v4-mapped IPv6."*"never allows one. A program that needs a local service names it innetas an IP literal orlocalhost("http://127.0.0.1:8080"). The checked address is pinned for the request, so DNS cannot answer differently between the check and the connection.http_getis an in-process client (ureqwith rustls). There is nocurlto install, proxy environment variables and~/.curlrcare not read, and the checked address is pinned through the client's resolver. Redirects are followed by hand (3 hops, absolute or root-relativelocationonly), each hop checked againstnet. A body over 16 MiB, a 4xx/5xx, or any failure answersNone. The user agent ismidad. Cost, measured: the release binary grew from 9,429,984 to 11,612,536 bytes (+23%) and Cargo.lock from 152 to 177 packages. The hostname pin has no offline test (it needs a name that resolves to a local address); the literal, redirect, status and refusal paths are tested against a local server intests/http_client.rs.- The native runtime's
http_getis the interpreter's client, with a stricter address rule.crates/midad-netholds the one client: in-process (ureqwith rustls), so a host needs nothing installed, and the proxy environment and~/.curlrcare never read. It refuses any URL whose host resolves to a non-public address, with no exception list: a native program has no permission table (see below), so it cannot tell a host the program named from one it did not, and it refuses every private address even when the interpreter would allow a granted one. The checked address is pinned through the client's resolver, so a second DNS answer cannot swap it. A redirect is not followed, because a hop cannot be re-checked without a permission table; the interpreter follows up to three, each one re-checked. Cost, measured on one stripped static binary: a program that never callshttp_getis 900,472 bytes, the same program with onehttp_getcall is 5,071,056 bytes, so the client costs about 4.2 MB and only a program that fetches pays it. Test:a_compiled_binary_refuses_a_private_addressinfour_paths.rs.
Request parsing
- A query string over 8,192 bytes, more than 128 fields (1,024 in a form body),
a field name over 256 bytes or a query value over 4,096 bytes is a 400. A
%not followed by two hex digits, or escapes that decode to non-UTF-8, is a 400 (it used to stay literal). A repeated name keeps the last value. HEADruns the matchingGETroute and sends no body. A program cannot declare aHEADroute: the five methods a route may name are GET, POST, PUT, PATCH and DELETE, androute:HEADisE0170. Header size and count are hyper's defaults.
Native builds and persist:
A native build refuses a program with persist: by name. The interpreter loads
the state block from that file at startup and writes it back after every run;
nothing in the native runtime does, so a binary built from such a program used to
run, print the right output and silently lose the state (two runs of the same
binary both started from zero, and no file was written). Until the native runtime
persists, the refusal is the honest answer.
HTML templates
html:NAME blocks are Pug-style: indentation is the nesting, {{ expr }}
inserts a value with HTML escaping on, {{! expr }} inserts it raw, and
html("NAME") renders the template to a string, and html("NAME", {"k": v})
binds those names for the holes, so a template can be called from anywhere
instead of only where its data happens to be in scope. What they do not have:
-
No typed parameters. The second argument is a map of values, so every bound hole is typed
anyinside the template: a hole that expects a list and gets a number fails at render time, not at check time. A misspelled hole name is still a static error (E0241) when the map is written out at the call, because its literal keys are bound for the hole check. Pass a map held in a variable and the holes go unchecked entirely. -
Every backend renders a template that branches or loops. The interpreter runs the template's instruction list, the C backend emits that list as C (one buffer, a real
if, aforover the list's items), and the Cranelift backend emits it as blocks with the output buffer as each block's parameter.four_paths.rschecks that the three render the same bytes for a template with a loop, nested loops, a nestedif/else, a raw hole in a loop and a loop over an empty list. One native limit: a loop variable is a string, number or float, because the native subset has no dynamic values, so a loop over a list of lists is refused by name on a native build. - A native build binds a template's holes by name. The interpreter reads a
hole's value from the map you pass, so
html("t", {"name": other})rendersother. A native build reads it from the variable named after the hole, so on a native build the map must map each key to the variable of that name;html("t", {"name": other})is refused by name there instead of silently renderingname. - No partials, includes or layout inheritance. One template cannot use
another;
html("NAME")is the only way in and only from program code. - No filters or pipes.
{{ ... }}holds the language's own expression syntax and nothing else. - No unescaped-by-default mode.
{{ expr }}escapes& < > " '. Markup you built yourself goes in through{{! expr }}. - No whitespace control. Text is emitted exactly as written: no trimming and no pretty-printing, so nested elements come out on one line.
- Rendering is shared, not reimplemented. A template compiles to one
instruction list (
html::program), which the interpreter runs and the C backend emits; the flat plan is that list without control flow. A template produces the same bytes on every path.examples/html_page.mdis checked for exactly that bybench/examples_parity.py, andfour_paths.rsfor a template that branches and loops. - Sibling lines must share one indentation. A dedent that lands between two
levels is an error (
E0253), not something to guess at.
Runtime behaviour
- A runtime error aborts the program with a span, not a resumable error.
resultis a value you build yourself; nothing in the runtime produces one except your own code. midad runstops a program that is not a server after 120 seconds, and after 10 billion steps if the clock check cannot reach them first: anexecblock with an infinite loop ends withR0001: time budget exhausted, naming the limit and the way past it.--no-limitremoves both, which is what the bench harness passes because there the run time is the measurement. A program that serves is exempt - routes or a grantedlistenaddress mean it is meant to keep running - and an HTTP request keeps its own smaller budget: 50M steps and 2 seconds.MIDAD_RUN_BUDGET_MSsets the deadline in milliseconds.- A native program has no step budget and no deadline.
midad build --native-allproduces a program that runs until it returns or the operating system stops it; a compiled route handler insidemidad runis bounded only by the request budget, not by the run budget. - Blocking builtins block a runtime thread.
ai:intentblocks only run theirfallback:; there is no LLM provider in this build.
Integer safety
- Checked by default in every backend.
+ - * / %refuse to overflow: the interpreter stops withR0001: integer overflowordivision by zero, and every compiled build (C and Cranelift) prints one line,midad runtime error: integer overflow(ordivision by zero), and exits 1. A compiled program no longer dies on SIGFPE and no longer wraps around to a wrong number. - The checks cost something. On the 2e9-iteration
heavyworkload the C backend takes 1543 ms with checks and 1393 ms without (about 11% slower), min of 5 runs on one vCPU.MIDAD_C_UNCHECKED=1 midad build ...restores the old behaviour for benchmarking only; do not ship a binary built that way. int()refuses rather than guesses. A string that is not a whole number, or a float outside the i64 range, is an error instead of a zero or a saturated maximum. For input that may be bad, useint.parse(s)(an option) orint_or(s, n)(a fallback); both now work in the interpreter, the C backend and the JIT.floatarithmetic is unchecked.f64overflow becomesinf, not an error, and there is no integer type wider than i64.
The database layer
- SQLite only. PostgreSQL and MySQL are designed in
docs/DATABASE.mdand not built. db.queryanswers at most 10,000 rows, then refuses with an error that says to add alimitor aggregate in SQL. The cap is the same number in the interpreter and in a compiled build.- A parameter can be a string, a number, a float, a boolean or null. A list or a
map in
paramsis an error naming the position, not a stringified value. - Identifiers cannot be bound in any SQL dialect, so a table or column name built
from input is still a name built from input.
docs/DATABASE.mdsays so. - Not built: a caller-set row cap, a prepared-statement cache, a per-connection
timeout, and a
db.txcallback form.
Not built at all
- WebAssembly target, JS target, mobile targets.
- A language server, editor integration, or a real formatter beyond
midad fmt. - Incremental builds; every
--native-allbuild callsccon the whole program.
Directory grants
fs_read: ["data/"] (or "data/**", the same thing) allows every path under
data/, and the same for fs_write. The interpreter decides each call on real
paths: the target, or for a write to a file that does not exist yet its parent
directory, is canonicalized and must sit inside the canonical grant directory,
so .. and a symlink that leaves the directory are refused, and so is a path
that cannot be resolved or that contains a NUL. A relative grant is relative to
the directory the program runs in. The granted directory itself is a slot: a
symlink standing at it is refused, so a grant only ever covers a real
subdirectory, while a grant under a symlinked parent still works. A computed target (read_file(p)) is
accepted by the checker when a directory grant exists, and checked at run time.
The grant directory itself is not a file and is not matched.
An exact grant (fs_read: ["/srv/app/config.json"]) names one file and is
decided the same way at run time: the grant's parent directory is canonicalized
and its own name kept, and the target must resolve to exactly that. A symlink
standing at the granted name is therefore refused instead of followed, a grant
under a symlinked directory still works, a granted file that does not exist yet
can still be written, and one that does not exist answers None on read. *
means what it always meant, and midad check does not warn about * yet.
Native builds refuse a directory grant by name, like *, because the native
runtime binds an exact grant and has no directory rule of its own. An exact
grant is enforced the same way there as in the interpreter: the built binary
carries its fs_read and fs_write paths and refuses a call whose path is not
one of them, or whose path has a symlink in it, with the interpreter's message. Not covered: a file that is replaced by a
symlink between the check and the open (a race), which needs openat-style
handling and is not built.
Wildcard permissions do not compile
fs_read: ["*"] (and the same for fs_write, net, env, db) is honoured
by the interpreter, which checks each call at runtime, and refused by the native
backends, which bake the allowed paths into the binary and cannot enforce a set
that has no members. db: ["*"] is therefore refused by a native build too.
db grants
A db grant is a file grant: it is decided on real paths the way fs_read is,
so ./data/app.db and data/app.db are one file, a directory grant such as
db: ["data/"] covers every database under it, and a symlink standing at the
granted name is refused instead of opened. A grant names one database file, so
the connection refuses ATTACH and DETACH: without that, one line of SQL
opens a database at any path the process can reach, which is a file the
permission block never named. db.exec still runs arbitrary SQL inside the
database it was granted, which is what the grant is for. The message is "a native build cannot enforce
fs_read: ["*"]: grant exact paths or hosts, or run the program interpreted".
The same rule reaches one level up: a computed target such as
read_file(path) passes the static checker only with "*" or a directory
grant (E0300), and a native build refuses both, so a program that reads a path
chosen at runtime runs interpreted only. A literal path is what compiles.
examples/sales_report.md is the worked example.
A native build cannot serve HTTP
midad build --native-all produces one executable that runs the exec block
and the functions it calls. It does not listen on a socket: use midad run for
anything that serves.
What a native C build does give you is the handler itself. A route answered by a
named handler (route:GET /links/:id show) compiles to an exported function
with the ABI a server can call:
MxMap *mx_route_show(MxMap *req); /* one map in, one map out */
The caller owns the request map and the response map; the runtime drains
everything the call made before it returns, because the caller is outside the
runtime and has no pool. A route written with an inline body has no such
function and is still refused by name, and so is a handler that is not
function h(req: map): map. The Cranelift backend still refuses a program with
routes.
command: blocks are different, and the C backend builds them: the executable
dispatches on argv[1] the way midad run file.md <command> does, binds args
to the words after the command name as a list of strings, runs only that command
(exec does not run), and exits 2 with unknown command `name` on stderr
for a name it does not have. The Cranelift backend does the same: each command
body is compiled to a function of one parameter, args, and the generated C
main dispatches to it.
How a native C binary frees
The C runtime counts references. Every string, list, map and option payload carries a count; a new object starts with one reference, which belongs to the statement that made it, and a variable, list slot, map slot or state cell that keeps the object takes its own. Overwriting a slot, leaving a scope or freeing a container gives those references back, and a statement that allocates gives its temporaries back when it ends. Nothing is left to collect later, so a native C binary that loops a million times holds one render at a time instead of a million (16.7 / 32.0 / 62.6 MB before, 1.6 MB flat after, ../BENCHMARKS.md).
What that does not do:
- A value the program still holds stays. A list of 200,000 renders is 200,000 strings, which is what the program asked for.
- The counts are plain integers until a program uses
par, where the runtime is compiled with atomic counts.parpays a little more per retain than a serial program does. - Nothing frees what a program never lets go of: a
statecell holds its value for the life of the process, by design.
Native builds and upper / lower
A native C build refuses upper(s) and lower(s) by name. The interpreter maps
the whole of Unicode (Rust's to_uppercase and to_lowercase) and the C runtime
carries no case tables, so the alternative was mapping ASCII and quietly
disagreeing on every other script. The refusal is a compile-time message naming
the function, not a wrong answer at run time. trim, contains and replace are
supported and match the interpreter byte for byte, including trim over the
Unicode space characters.
A statement that throws a container's result away
A native C build refuses put(m, k, v) written as a statement. It answers a new
map in the interpreter, so a bare statement discards the answer and leaves the
map alone; the C runtime grows it in place, so the same statement would change
what the interpreter does not. The refusal says so. push, set_at and sort
are statements by definition (they change their first argument and answer
nothing), so a native build runs them.
Functions are arguments, not values
A parameter typed fn takes the name of a function (twice(double, 3), see
SPEC 6.2). It is done by writing one ordinary copy of the callee per function
passed, before the checker runs. That keeps all four backends identical and
keeps permissions static, and it has these limits, which are by design:
- No closures: nothing captures a variable.
- A function name cannot be stored in a list or map, returned, bound with
letor computed. There is no run-time function value, so there is nomap(xs, f)over a list of functions and no callback table chosen by data. fnhas no signature. Wrong argument types surface as ordinary type errors inside the copy, with a note saying which function it was made for.- A function with a
fnparameter is only checked once it is called; aW009warning marks one that never is. - Every distinct function passed makes another copy, so a function called with many different names grows the compiled program by that many copies.
- There are no builtin
map,filterorsort_by: lists are untyped, so a general one would need the same untyped-list casts the language already asks for. Write the loop, or write the smallfnhelper you need.
Run-time function values (a function in a list, returned from a function) would need a function type in the checker and an indirect call in each backend, and closures would also need captured environments and effect tracking. Neither is planned.
- Recursion has a depth limit, and the stack is sized to hold it. A program
that calls itself stops with
call depth limit (4096) exceededinstead of aborting the process with a stack overflow. The number is not a promise about memory:midadruns the interpreter on a thread whose stack is4096 * 64 KiB, andMIDAD_MAX_DEPTHchanges both together, so a bigger limit gets a bigger stack rather than moving the abort further out. A server sizes each worker's stack the same way, so one recursive handler answers with a diagnostic and the process keeps serving. Both native backends count their own calls the same way, from the same variable, so a recursive function in a compiled program stops with the same message instead of overflowing the stack.