Philosophy

stone aims to be as simple to write as Python, as fast and memory-safe as Rust, and to report errors as clearly as Rust does, while compiling to programs that need nothing from the system they run on, not even a C library. These goals can conflict, and stone resolves the conflict the same way every time: the compiler takes on the complexity so the programmer does not have to.

This page describes those goals, how they guide decisions, and how far stone has come toward each one. Parts of it describe where stone is going rather than where it is today, and each section says which is which.

The compiler does the work

If the compiler can figure something out, stone does not make the programmer write it. Annotations, keywords, and options that exist only to help the compiler, such as lifetimes, mut, &, lazy, or inline, are left out of the language. The language is defined so that the compiler can always infer them instead.

Python 3.15’s lazy import numpy is a good example. Python needs the keyword because importing a module runs its top-level code, which can be slow and can have side effects, so the interpreter cannot delay it without being told to. stone avoids the problem by design: a library module holds only use, fn, const, enum, struct, trait, and impl, and a constant’s value is worked out when the program is built, so importing it runs nothing, and the compiler links in only what the program uses. Every import is effectively lazy, and there is no keyword for it.

Status: a library’s fixed values are constants, const dns_port = 53, which the compiler works out while it builds the program from literals, operators, and other constants, exactly as they would compute at runtime. const is a keyword because it says something to the reader rather than to the compiler: the name means one value everywhere, before its line as after, in functions and tests alike, and nothing ever assigns it, so a library needs no top-level code to have one.

The pattern applies to the whole language. When a feature would need a keyword to be fast or safe, the better fix is to change the semantics so that the compiler can always choose the fast, safe option on its own and the programmer never sees the difference.

The one exception to this rule is a function’s signature: the type of each parameter and of the value it returns, as in fn mean(xs: list[float]) -> float:. Signatures are written for the reader and for error messages, not for the compiler. A signature is the function’s contract, readable without its body, and it lets the checker report a mistake where it is made: a wrong argument at the call, and a wrong value inside the function, rather than wherever two inferences happen to disagree. Everything else is still inferred, as in Rust, so no variable is ever annotated.

What stone already infers:

  • Types. The checker infers the type of every variable and expression from the values assigned to it and the signatures of the functions it calls, so the only types written are the parameter and return types of functions.

  • Specialized generic functions. A generic function writes its type parameters in brackets, as in fn first[T](xs: list[T]) -> T:, and every call infers its own types for them, so no type is ever written at a call. The compiler makes a copy of the function for each set of types it is called with, the way Rust compiles generics, so a generic function is as fast as one written for a single type. Structs and enums can be generic the same way, as in struct Pair[A, B]:. Even option[T] and result[T, E] are, written in stone in the prelude that every program is linked with, so they follow the same rules as the programmer’s own enums.

  • Which function a function value calls. A function passed by its name to a parameter of a function type, as double is to xs.map(double), is compiled into a copy of the callee that calls it directly, so passing functions costs nothing over writing the loop by hand.

  • Which method a bound calls. A trait lists methods that types implement, and a bound such as fn total[T: Shape](xs: list[T]) lets a generic function call them. Each copy of the function calls the method of its own type directly, with no lookup while the program runs, and a list of several types holds trait values, list[Shape], which values become where one is expected, so there is no dyn or Box to write. Whether a trait’s method changes self is decided by the trait, from its default body, so no mut marks it either. Even == and < are the prelude’s traits eq and ord, which a struct can implement to compare its own way, printing is its trait display, + and the other arithmetic operators are its generic traits add[R], sub[R], mul[R], div[R], and rem[R] (and neg for -x), and int(s) is its generic trait try_from[str], which a type implements once for each type it converts from. The impl a call uses is picked by the types of its arguments, so no turbofish or cast names it, and a conversion that can fail gives a result, so it cannot stop a program by surprise.

  • Memory management. Compiled programs count references, with no garbage collector. The compiler places every retain and release, decides which parameters are only borrowed, and skips counting where it can prove a count would not matter.

  • What to include. Imports run nothing, and runtime routines are compiled into a program only if it calls them.

What it should infer next:

  • Where values live. Values that never escape a function should live on its stack. An update to a value nothing else refers to already happens in place; see value semantics.

  • Dead code. A library’s functions, and the runtime routines only they call, are already left out unless the program reaches them; the entry file’s own functions that are never called should be left out too.

Status: packages apply the same idea to versions. A stone.toml gives each dependency only the oldest version it works with, and stone uses the newest version anything in the program asks for, as Go does, so there are no version ranges to write, no solver to fail, and the same manifests always give the same versions without a lockfile choosing them. stone.lock only records a hash of what each package held when it was first downloaded, so a release that changes fails to build rather than changing a program. Two major versions of one package can be used at once, linked under different names, so there is no conflict to resolve by hand. Packages are downloaded from GitHub and GitLab releases, so there is no registry to run or to trust beyond the host and the hashes. Not done yet: packages in a subdirectory of a repository, sources other than GitHub and GitLab, and a shared database of checksums beyond trust on first use.

Status: a project’s layout is a convention rather than configuration. stone init writes a stone.toml and a main.stn (or a library’s lib.stn) side by side, the program always starts at main.stn, and every module is found from that directory, so stone run, stone build, and stone check find the program from anywhere inside it with no entry point to declare.

Simple like Python

The code a programmer reads and writes should look like Python’s and need as few concepts. stone keeps Python’s structure (indentation, for x in xs, if, while) and its habit of having one obvious way to do something. It does not take on Python’s dynamic features, such as eval, monkeypatching, or values whose type changes at run time, because a compiler cannot make those fast or safe. stone gets static types by requiring the annotations Python makes optional on a function’s parameters and return value, and inferring the rest.

A feature belongs in stone only if a newcomer can understand it without knowing what the compiler does with it. If a feature makes sense only to someone who knows how it is compiled, the compiler should handle it instead.

stone’s syntax differs from Python’s in a few small ways (functions return with ret, and loops skip ahead with cont), listed in syntax.

Status: every string writes the values of the expressions in braces inside it, as Python’s f-strings do, but with no f to remember, since a string that should hold braces writes {{ and }}. str and print write any value, through the prelude’s trait display, which a struct can implement to say how it is written everywhere it appears. Format specs such as {x:.2f} and {n:>5} are Python’s, so a program moved from Python writes the same text, and the compiler checks each against its value’s type. The one obvious way extends to layout: stone fmt (and the editor’s Format Document) writes every file in one standard style, changing only whitespace.

Memory safety and value semantics

A program the checker accepts can never read freed memory, read outside a list, read a variable before it is assigned, or follow a null reference. Anything that cannot be ruled out before the program runs, such as an index out of range or division by zero, is checked while it runs and stops the program with a clear error, never undefined behavior.

stone already guarantees this. Every list index is checked, there is no null (a value that may be missing is an option[T], which match or unwrap must open, and none is one of its values), an error a program expects is a result[T, E] that the caller must open or pass on with ?, never an exception that unwinds through code that did not ask for it, reading an unassigned variable is a checker error or a runtime error, and reference counting frees every string, list, and enum value exactly once. The checker rules out cyclic values, and enum values never change, so reference counting never leaks. A shift is checked too, where C leaves it undefined: its count must be from 0 to 63, and << stops the program rather than lose bits off the top of an int.

Value semantics

stone has value semantics: assigning a value, passing it to a function, or putting it in a list behaves as if it were copied, so changing one variable never changes another.

a = [1, 2]
b = a
b.append(3)
print(a)  // [1, 2], where Python would print [1, 2, 3]

This is the one place stone deliberately differs from Python. Sharing mutable values is the main source of aliasing bugs, and it is what makes memory safety hard: it allows cycles once there are user-defined types, and it forces a language either to use a garbage collector or to make the programmer prove ownership, as Rust’s borrow checker does. Value semantics avoids both. Programmers never have to think about who else holds a value, and the compiler is free to optimize.

The copies are only conceptual. The compiler shares the underlying memory and copies it only when a value that something else also refers to is about to change (copy on write), and it uses the reference count it already keeps to update a value in place when nothing else refers to it. In the common case, a value with one owner, nothing is ever copied.

A few rules follow from this, and the checker enforces each with an error that says what to do instead:

  • A function changes a value that belongs to its caller by returning it: xs = add(xs, 1). A function can read globals but never change them, just as it cannot assign them. The checker warns when a function changes a parameter and then never uses it, since the caller would not see the change. The one exception is a method that changes self, which changes the value it is called on, as append changes a list: p.shift(1.0) means p = Point.shift(p, 1.0), so it is still a change made by returning, written the way Python programmers expect. The compiler sees which methods change self, so no mut keyword marks them.

  • A change is a statement of its own (xs.append(1), grid[i][j] = 0) made to a variable or an element of one. Changing a temporary, as in f().append(1), would have no effect.

  • A for loop walks the list as it was when the loop started, so appending to the list inside the loop does not make the loop run longer.

Status: lists, maps, which compiled code stores as lists of entries with a hash table beside them, and sets, which are maps whose entries are their keys alone, have value semantics in both backends, and a change reaches into any of them through any place, such as p.counts[k] += 1 or g.edges[i].add(j). An empty {} is a map or a set by its use, so the language never asks which. Compiled code checks a list’s reference count before changing it and copies the list only when something else refers to it (list_unique in the IR), so changing a list that only one variable holds is still done in place. A function owns each parameter it assigns or changes, and the caller hands it a reference for it. When nothing reads the argument after the call, as in xs = f(xs) or ret f(xs), the caller moves its own reference in instead of keeping one, so the function changes the list in place. More generally, both backends find each variable’s last use, and a value moves there instead of being copied: into a call (ys = f(xs)), another variable (ys = xs), or a list (rows.append(row)) when nothing reads it afterward. A global moves only into a function that never reads it, directly or through the functions it calls. Arithmetic on lists, such as xs = xs * 2.0 + ys or xs += ys, writes its result over an operand’s list when that operand is at its last use or is the variable being assigned and nothing else refers to its list, so it allocates nothing. Adding to a string or bytes the same way, as in s += t in a loop or s = s + a + b, writes onto the string in place when nothing else refers to it, growing its block to at least twice its size when it is full, so building text a piece at a time takes time in proportion to its length in both backends, with no builder type to ask for. A map of at most eight entries keeps no hash table until it grows past that, and a lookup compares its keys in turn, so the many small maps a program such as a JSON reader makes cost neither the table’s memory nor its hashing. Tuples never change, so they need nothing of this: the compiler keeps each of a tuple’s values as a variable of its own, counting only the strings and lists among them. Structs are kept the same way, so changing a field of a struct in a variable (p.x = 1.0) is an assignment to that field’s variable, and a field holding a list follows the rules for lists, including moving into a call that replaces it (p.items = f(p.items)). A method that changes self takes the receiver’s values moved in, as from a variable at its last use, and returns them after its result for the caller to store back where they came from, a variable, an element, or a field, so stack.push(x) changes the stack in place; a method that only reads self borrows it. Enum values never change either, so they are shared freely: each is stored once, with a count of the variables that hold it, and a match hands out its values with a reference each.

A connection is the one thing that is not a value, since it cannot be copied: a socket or listener from the net module is a handle, and copies of it refer to the same connection, and so is a gui window, which holds a connection to the display or, on Windows, a native window. Nothing asks the programmer to close one, as nothing asks them to free memory: both backends close it right after the last statement that uses it, the point where the interpreter drops the variable and compiled code releases it, so the other end sees the connection close at the same moment under stone run and in a built program. A closure that captured one holds a copy, so the connection stays open until the closure, too, is used for the last time. close() closes one sooner.

Fast like Rust

A compiled stone program should run about as fast as the equivalent C or Rust. The benchmarks compare stone build with gcc -O2, gcc -O0, and Python.

Speed comes from what the language guarantees, not from hints the programmer adds. Static types mean values are unboxed and calls are direct. Value semantics means no aliasing, so the compiler can keep values in registers and reorder freely. Runtime checks such as list bounds stay in the language, and the compiler’s job is to prove them unnecessary and remove them, not to let the programmer turn them off.

Status: the compiler lowers to an IR, inlines small functions that call no others, folds operations of constants and branches on them, computes repeated arithmetic once and arithmetic a loop never changes before the loop, drops work and whole loops whose results nothing reads (a loop only when it is sure to end, so a program that never stops still never stops), removes index checks, reads, and uniqueness checks it can prove repeated (moving those a loop repeats before it) and index checks a loop’s own test proves (comparing a loop’s bound with a list’s length once, before the loop, when the bound is not the length itself), removes checks that facts about values prove never fail (an index from 0 to below its list’s length, by any loop’s test or by the appends that built the list, a branch whose comparison those bounds decide, and the domain check of math.sqrt on a sum of squares), allocates registers with linear scan, keeping floats in the processor’s floating-point registers, and specializes a few cases such as division and remainder by a constant, which multiply by a magic number, and constants and globals that hold one literal for the whole program, which read as that literal. Arithmetic on whole lists, such as a * 2.0 + b, compiles to one loop with no intermediate lists and no index checks, which handles two elements at a time with SSE2 or NEON where the operations allow (four with AVX2 for --target x86_64v3, eight with AVX-512 for v4, and as many as the vectors hold with SVE for aarch64v9-linux, each of which then checks the processor at startup), so on the vector benchmark it is about 3.8 times as fast as numpy, which builds a temporary array for each operator. A tuple is never allocated: its values live in registers like any other variables, a function takes and returns them as separate values, and a list of tuples stores each element’s values side by side, like a Rust Vec<(i64, String)>, which is a first step toward choosing where every value lives. Structs are compiled the same way, so a list[Point] is a flat array of coordinates whose fields are read at fixed offsets, so the nbody benchmark runs within about 1.4 times of C. The trigonometric functions of math are expanded inline at each call, from the same code the interpreter runs, so both give the same bits, and the compiler computes each value once, a sine and a cosine of the same value with one reduction, so the trig benchmark runs about 15% faster than C calling glibc. A generic function, or a method of a generic struct or one with type parameters of its own, is compiled once for each set of types it is used with, so its copies are as fast as functions written for each type, and a generic struct is flattened like any other. A call through a trait’s bound is a direct call in each copy, and a trait’s default method is compiled once for each type that keeps it. A conversion T(x) is a direct call of its impl, or the builtin conversion’s own instructions, in each copy, while the interpreter, which makes no copies, carries each generic call’s type arguments with it to pick the same impl. An operator on a struct is a direct call of its trait’s impl, and the same operator through a bound, as a + b under [T: add[T]], is the number’s own instruction in the copy for int. A trait is also a type of values, as dyn Shape is in Rust but with nothing to write: a value becomes a Shape wherever one is expected, and is then one counted object holding the value and the address of its type’s table of methods, a table of jumps in the code so no executable needs its data relocated, and a call through it is an indirect call of the table’s entry. A method that changes self through one makes a new object for now, where a uniquely held one could change in place, and match finds the type back by comparing the table’s address. A function value is the address of its function, so a call through one is an indirect call, but a call that passes a function by its name, as xs.map(double) does, compiles to a copy of the callee that calls that function directly, as a copy of a generic function does its bound’s methods, so the list helpers cost no more than the loops they stand for. A lambda, such as |x| x * 2, is a function of its own that linking names, so it costs what a named function does, and xs.map(|x| x * 2) calls it directly. A lambda that uses variables from outside it is a closure, which with value semantics captures copies of them where it is written, so no closure ever shares a variable; one passed straight to a function, as xs.filter(|x| x > limit), is still called directly, its copies passed with the other arguments. A closure kept as a value is one object holding its code’s address and its copies, counted like any other, and a variable used for the last time where the closure is made moves into it rather than being counted twice. A closure in a generic function is compiled once for each copy of the function, like a call. An enum that holds itself, as a tree or linked list does, is stored on the heap, which lets it do so without the Box Rust asks for. Every other enum, options and results included, is kept in registers as its tag and its values side by side, as a tuple is, once its type arguments are known, so some(x) allocates nothing and a function returns an option[int] in two registers; the compiler decides this for each type, boxing one that would be wider than eight values or make a list’s element or a boxed variant hold more than 32. The same arithmetic on lists is the first code stone writes for GPUs: on a machine with an NVIDIA GPU, which it finds itself (--no-gpu opts out), stone build turns each such expression into a kernel, in PTX for NVIDIA GPUs, that computes every element exactly as the processor does, rounding each float operation on its own and flagging a zero divisor for the program to report. No keyword marks the code for a GPU, since the compiler finds it. An x86-64 Windows program launches the kernels through NVIDIA’s CUDA driver interface, nvcuda.dll, which it loads only when it runs, from a driver written in stone (gpu_cuda) over three native primitives (load the DLL, find a function, call it), so the same executable computes on the processor on a machine without one; STONE_GPU=off keeps it there, and STONE_GPU=require makes it an error not to use the GPU. A Linux program, which uses no C library and so cannot load libcuda, speaks to NVIDIA’s kernel driver itself, through ioctls on /dev/nvidia*, from a driver written in stone (gpu_nv) over a few native primitives, and runs the machine code ptxas made at build time; so far it knows driver version 595 and Ampere and Ada GPUs, and computes on the processor anywhere else. The compiler also decides where each piece runs, since a GPU pays only when what it saves outweighs reaching it: it records each kernel’s cost per element on either side, the build measures this machine’s GPU’s latency and bandwidth once (kept for later builds) and bakes the shortest list worth each launch into the program, and a list too short to repay a launch stays on the processor for the price of one compare. Lists stay on the GPU through runs of statements and loops that only compute on them, coming back once, where the processor next reads them, which the compiler finds by the same liveness that moves values. Both systems share one planner, written in stone (gpu_plan), for these decisions. On Windows those lists live in the GPU’s own memory; on Linux they live in processor memory the GPU reads so far, not in its own. A program starts the GPU’s driver only for arithmetic worth the GPU, which on Windows takes a fifth of a second the first time. Putting the lists in the GPU’s memory on Linux, other drivers and generations, a cheaper start on Windows, and AMD GPUs are future work. Vector code beyond arithmetic on lists (searching strings, comparing lists, summing them), splitting a value’s live range around calls, and removing reference counts it can prove redundant beyond moves at last use are future work.

Proofs are how stone means to reach C’s speed without giving up a check: the facts that make an access safe are the same ones that let the compiler drop its check, so the language keeps every check and the compiler’s job is to prove each one away, never to let the programmer turn it off. The facts are inferred, as types are, never written as refinement types or regions, and they are a small, decidable kind (bounds between ints and lengths, signs of floats) so building stays fast. A proof the compiler gets wrong would be unsafe, so a build with STONE_VERIFY_FACTS set keeps every check it removed, failing with compiler bug if one would fail, and the golden programs and the fuzzer run that way. STONE_STATS counts the checks, counting, and allocation a program still does, so each step shows what it removed. A list the function never changes cannot change while it runs, rows included, so a loop nest over the rows of a list of lists (matmul) tests their lengths once before it and runs a copy with no checks. The next steps: keeping fields of a list element in registers across a loop that provably never touches it (nbody), reserving room for appends a loop’s count bounds, allocating values that never escape a statement from a region freed at once (binary_trees), and choosing smaller layouts, such as bytes for a list that only holds 0 and 1, from what the facts show.

Errors like Rust

An error should say what went wrong, where, why, and how to fix it. The goal is diagnostics as good as rustc’s:

  • the main location with its source line, plus labels on every other location that explains the error (“first assigned here”, “expected int because of this”),

  • note: lines that explain the rule involved and help: lines that suggest a fix, as code where possible,

  • an error code for each kind of error, with a longer explanation available from the CLI,

  • as many errors as possible from one run, without a cascade of follow-on errors,

  • runtime errors that give the location and the chain of calls that led there, from compiled programs as well as from the interpreter.

Status: every error from the lexer, parser, linker, and checker prints as file:line:col: error[E0005]: message with the source line and a caret, and the language server shows the same errors in the editor. Each has a code for its kind, which stone explain explains with a program that fails with it and the same program fixed, and which the documentation lists. Runtime errors print the same way, pointing at the expression that failed, from compiled programs as well as from the interpreter: the compiler renders each place an error can happen into the executable, so it costs nothing until the error happens. A failed unwrap of an err shows the error it found, as in cannot unwrap err: end of input, and a failed assert of a comparison shows both sides, as in assertion failed: [1, 2] == [1, 3]. stone test runs each test block alone, interpreted or compiled, with the same report from both. Errors from the checker label the other places that explain them, in any file of the program (the parameter’s type an argument does not fit, the return type a ret value does not match, a variable’s first assignment), add notes on the rule involved, and help with the fix, as a rewritten line where the checker knows it, such as a parameter’s missing type, or by naming a similar name for a misspelled one. A runtime error also shows the calls that led to it, innermost first, a run of calls from one place as one frame with a count, at most 20, byte for byte the same from stone run and from every compiled target: an executable walks its own frame pointers at the error, looks each return address up in a table of its calls, and remembers the calls stone build inlined in each site’s record, allocating nothing. The walk and the table cost about 1.3 KB per executable plus 12 bytes per call, 8% over the benchmarks, and nothing until an error happens. More of the checker’s errors in this form are future work.

Run anywhere: no libc

A program built with stone build should depend on nothing but the operating system kernel: no C library, no dynamic linker, no runtime to install. One file should run on any machine with the right processor and kernel, whatever distribution or libc version it has.

On Linux this is fully achievable because the kernel’s system call interface is stable. The runtime makes system calls directly, allocates memory with its own allocator on top of mmap, and formats and parses numbers itself, which also lets it guarantee that compiled programs print floats exactly like the interpreter does.

macOS and Windows do not have a stable system call interface. Apple supports only programs that call the kernel through libSystem, and Windows only through kernel32.dll. On those systems the goal is the thinnest possible layer: call only the system’s own interface, never a C library’s higher-level functions.

The same idea applies to the toolchain. stone build should write executables itself, with no assembler, linker, or C compiler installed, so that installing stone is all it takes to build stone programs.

Status: on Linux, compiled programs need no C library. They start at their own _start, make system calls directly, allocate memory with their own allocator on top of mmap, read input through their own buffer, and format and parse floats themselves, digit for digit like the interpreter, so each one is a static executable. On arm64 macOS, the same runtime calls only libSystem’s system call wrappers (read, write, open, mmap, sysctl, and a few more), each through a shim that keeps the contract of a Linux system call, error numbers included, so the rest of the runtime is shared. The one exception is reading a directory, for fs.list_dir: Linux’s getdents64 has no public counterpart on macOS, so there the runtime calls opendir and readdir, the interface Apple supports. Running another program, for os.run, forks and calls execve itself on Linux, searching PATH as the interpreter does, and goes through the fork, execve, pipe, poll, and wait4 wrappers on macOS. Networking makes the socket system calls itself on Linux and goes through libSystem’s socket wrappers on macOS, and finds the addresses of a host without the C library’s getaddrinfo: the net module is written in stone, reads /etc/hosts and /etc/resolv.conf, and asks DNS servers itself, over one primitive that sends a UDP packet and waits for its reply, so both backends find the same addresses the same way. On macOS that skips the system’s own resolver, which also knows names from mDNS and per-network DNS settings. Windows from the gui module are drawn the same way: the module, written in stone, speaks the Wayland or X11 protocol to the display server over a Unix socket, with no libwayland, Xlib, or xkbcommon (it reads the compositor’s keymap itself, with a table of keysyms generated from X11’s), so a built program that opens windows is still a static executable. Its only native help is a routine that packs pixels into bytes and four that share memory with a local server: memfd_create, pwrite, sendmsg with the memory’s descriptor, and recvmsg and pread for a descriptor the server sends, which the interpreter calls through the C library and compiled code makes as system calls. On Windows, which has no display protocol over a socket, a window is a Win32 window, kept as thin as the protocols: a native layer (the same user32.dll and gdi32.dll calls under stone run and in a built program) opens it on a thread of its own, which runs the window’s messages, records each as 16 bytes, and paints the last image shown, so the window keeps drawing while Windows holds that thread in a drag or resize, and waits for the desktop’s next frame with DwmFlush, while gui’s stone code turns the records into events. Windows are in logical pixels on every system, and the native help scales an image up to the screen’s pixels, to the nearest, as it packs it. A built program picks its system’s half when it is compiled, so one for Windows holds none of the X11 and Wayland code, and one for Linux none of the Win32. A socket’s timeout is a poll before each read, send, or accept, in both backends, so a wait runs out at the same point under stone run and in a built program. stone build writes either executable itself, with its own assembler and linkers, including the Mach-O file’s imports and its code signature, so it needs no assembler, linker, or C compiler installed, and builds for every target from any machine.

On x86-64 Windows, a built program is a console executable that imports only from kernel32.dll (plus BCryptGenRandom from bcrypt.dll, to seed random, and ws2_32.dll if it uses net), which stone build links itself as it does Mach-O files. The runtime is the Linux one: every system call it makes goes through a shim that keeps the call’s Linux contract, Linux error numbers included, by calling the kernel32.dll function that does the same (ReadFile and WriteFile, VirtualAlloc, CreateFileW, FindFirstFileW, and so on), converting paths and names between UTF-8 and UTF-16, and writing text to a console with WriteConsoleW so that it is never garbled by a code page. Windows error codes become the Linux numbers that mean the same, so a file error is worded the same on every system, and the interpreter running on Windows maps them the same way. _start splits the command line into arguments by the rules Rust’s standard library follows, and the environment’s names are found without regard to case, as Windows finds them. The gui module opens Win32 windows there, through user32.dll, gdi32.dll, and dwmapi.dll, which a program imports only if it opens one, and stone build --windows-gui makes a program that starts with no console. os.run starts a program with CreateProcessW, after looking for it in PATH by one rule both backends follow, with the command line Rust’s standard library would write, and reads its output from two named pipes with overlapped reads, as Rust does. The net module’s sockets go through the same kind of shims, over Winsock: each keeps its Linux call’s contract, poll included, which select stands in for as it does in Rust’s connect_timeout. Windows keeps its hosts file and DNS settings to itself, so there net.stn asks the system’s resolver for a name’s addresses rather than reading /etc/hosts and /etc/resolv.conf, under both backends. Only net.connect_unix is not supported on Windows yet: the checker reports its use when building for Windows, or when running on it.

Two backends, one behavior

stone run interprets a program and stone build compiles it, and both must behave exactly the same on everything the checker accepts: the same output, down to float formatting, and the same runtime errors with the same messages. The checker rejects anything the two cannot run identically. Every program in the test suite runs through both, so the interpreter serves as the specification the compiler is tested against.

Making decisions

When choosing between designs, stone puts these first, in this order:

  1. Safety. No accepted program has undefined behavior.

  2. Speed. As fast as possible, accelerated by any available resources.

  3. Clear errors. A design whose failures are hard to explain is worse than one whose failures are easy to explain.

  4. Simplicity for the programmer. Fewer concepts and less to write, even if the compiler has to do much more work.

  5. Compiler simplicity. This comes last. A complicated compiler is an acceptable price for a simpler language.