sysl

The command line

The subcommands, the flags they share, and what each one leaves as an exit status.

Every subcommand takes a path, which is either a project root or a single file. Both follow from one rule: a module is a directory, named by its path relative to the root. Naming a directory compiles the whole tree under it, one module per directory, and naming a file compiles that file alone. The modules reference describes the rule in full.

The subcommands

what it does
sysl run [<path>]compile and execute
sysl build [<path>] -o <exe>compile to a native executable
sysl build-lib <path>check a library for one machine, writing nothing
sysl build-c <path> -o <archive>compile to a static archive and a C header, for a C project; with --shared, a shared library
sysl test [<path>]run the @test functions
sysl emit-llvm <path>print the generated LLVM IR
sysl stack <path>print the deepest stack each entry point can need, or why it has no bound
sysl emit-ast <path>print one file’s untyped parse tree, as deterministic text
sysl emit-typed <path>print one module’s typed tree, as deterministic text
sysl emit-header <path>print the C header for what a module exports
sysl weave <path>render a literate source as an HTML document
sysl tangle <path>print the program a literate source holds
sysl deps <path>print the dependency graph the project resolves to
sysl add <coordinate>add a dependency to the project’s manifest
sysl vendor <path>put what the project depends on into vendor/
sysl tidy [<path>]drop the sysl.sum lines for versions the project no longer resolves
sysl doc <path>generate an API reference from declarations and their doc comments
sysl import-c <header.h>write the sysl declarations for a C header — the raw layer of a binding
sysl targetslist the machines sysl can build for
sysl prove <path>discharge the contracts with Why3 — see verification
sysl lspserve the Language Server Protocol to an editor, on standard input and output

run, build and test take their path from the working directory when none is given, so sysl run, sysl build -o app and sysl test in a project’s directory mean sysl run ., and sysl run -- a b passes a and b to the program. A directory, named or implied, must hold a sysl.hocon: there is no searching upward for one, and a directory without it is refused, with status 1, on stderr:

sysl: error: there is no sysl.hocon in '/home/me/scratch' — 'sysl init' creates one there, or name a .sysl file to use it without a manifest

A single named .sysl file needs no manifest, and an empty sysl.hocon is a manifest. A program in a package’s examples/ directory is a project of that package and needs none of its own, and sysl test --std takes the standard module’s tree, which is no project. This is a behaviour change: a bare directory of .sysl files that sysl run <dir> used to build now needs a sysl.hocon beside it. The manifest used to be called package.hocon. A directory holding only that name still builds, with one warning asking for the rename; a directory holding both names is refused.

A subcommand is required. Run with none, sysl says so on stderr, prints its usage, and exits 2.

An unknown subcommand is refused on stderr with the list of valid ones, and sysl exits 2. Every command is built in; sysl does not look for external commands on the PATH:

sysl: error: 'wave' is not a sysl command — the commands are run, build, build-lib, build-c, emit-header, weave, tangle, test, emit-llvm, stack, emit-ast, emit-typed, prove, deps, add, vendor, tidy, doc, import-c, targets, lsp

A command’s product goes to stdout, and everything it reports about the run goes to stderr: a diagnostic, a refusal, a command-line error with the usage under it, wrote <exe>, and what --verbose reports. sysl emit-llvm hello.sysl > hello.ll therefore holds a complete module or nothing. sysl --help and sysl --version produce what was asked for, so they write to stdout and exit 0.

run

sysl run hello.sysl

run parses and checks the source, emits textual LLVM IR, has clang assemble and link it, and runs the binary.

A project with several executables runs one: the one --bin <name> names, else the one the manifest’s default_run names, else the first its binaries block names, else the only one. With several and nothing saying which, run is refused, listing them (packages):

sysl run . --bin emu -- rom.bin

The program does not outlive run. Ctrl-C at a terminal reaches both, as it reaches every process in the foreground job. A signal sent to the runner alone — kill of a sysl run p &, a job scheduler giving up on it, even SIGKILL — ends the program too: a binary built for run watches the runner that started it and, once the runner is gone, sends itself SIGTERM, so a program that watches that signal can clean up, and SIGKILL two seconds later if it is still there. Its exit status is still the runner’s — a program that exits 3 makes run exit 3, and one that traps makes it exit 133. A binary built by build carries no such watch.

Running an unchanged program a second time builds nothing. The executable is kept, keyed on everything that can affect its bytes:

  • the compiler’s build, the target, what the target provides, the allocator, the optimization level and --cc;
  • the clang the build uses — the file it runs, as the PATH finds it, and the first line of its --version — so another clang first on the PATH, another named by --cc, or one upgraded in place is another key. The standard module’s artifact and the C object cache are keyed on it too: bitcode one LLVM wrote under --lto is never handed to a link through an older one;
  • every source file of the program, of every package and of every --lib root, the C and headers beside them, and where each tree is;
  • every file the build’s C read, wherever it is — a header in an --include-path directory, one a package’s headers variable or a pkg-config path reached, the SDK’s own — by its bytes, as each C compilation and each c const block reported reading it. Editing such a header rebuilds; putting it back runs the binary the first text built;
  • every header that would now be found first: for each header read, every place clang searches ahead of where it was found (-iquote, -I, -isystem, the SDK, frameworks, and the directory of the file including it). A file appearing at one of them rebuilds; taking it away runs the binary built without it;
  • every file the linker loaded — the objects, archives, shared libraries and SDK stubs it reports under -t (ld64 on macOS, GNU ld or lld on Linux) — by its bytes, and every library that would now be found ahead of one it loaded in a --link-path or pkg-config directory. A shared library is also loaded again at every run, which is where its code comes from; keying the bytes the link read means a rebuilt one relinks rather than replays;
  • every manifest in the build, whole — the project’s and every package’s, every key but the four that are prose about a package (description, license, authors, keywords) and the test block, which is read afresh on every run;
  • the graph as resolved: the version selection settled on for each package, and the features and option values each one is built with — so a value set by a package between yours and the one that reads it is in the key as surely as one you set;
  • the feature request (--features, --no-default-features, --all-features), -D, --include-path (and any path a package’s headers variable supplied), --link-path, --link, --lto, --profile-generate, --profile-use (by the profile’s bytes), --no-bounds-locations, --const-steps, --cpu (by the processor’s name and, for native, its feature list) and --no-std-lib;
  • the standard module, and the environment that reaches the toolchain: SYSL_EXTRA_CFLAGS, SYSL_COUNT_ALLOCS, SYSL_COUNT_RETAINS, WASI_SDK_PATH and the four Android variables.

With nothing changed, the same binary runs again; change any of these and the key changes, so a kept binary cannot be stale. A kept binary is also sealed: a file beside it records the key and the binary’s digest, so one that was truncated, damaged, or copied from another key’s entry is rebuilt rather than run.

What is deliberately not in the key cannot change the binary: the program’s own arguments (sysl run p -- a and sysl run p -- b run one binary twice), -o, -v, --explain-escapes, --explain-borrows and --explain-checks (a run that asks for a report compiles again), SYSL_TIMINGS, SYSL_CODEGEN_UNITS (how many pieces the program is compiled in, not what it is), and where the caches and the library are (HOME, XDG_CACHE_HOME, PATH, the spelling of SYSL_LIB — the library’s contents are keyed, and so is the clang a PATH finds).

What the key does not watch is the toolchain’s own installation: a library added to the linker’s built-in directories ahead of another one there. That is an install of the toolchain or the SDK, and SYSL_NO_CACHE is for it.

This saves most of what run costs, because compilation usually dominates. In a 9,600-line module with three git dependencies, a program whose body is print("hi") takes 9.2 seconds to compile and almost no time to run; with the binary kept, only the run remains.

test keeps its binary the same way, which matters most for a suite you run repeatedly while working. --filter, --file, --jobs, --timeout and --fail-fast choose among the tests or how they run rather than changing what is compiled, so they are not part of the key. A --lib root’s compiled half is kept under the same key, so a value or feature that reaches the root from anywhere in the graph — your manifest, an intermediate package’s, a version a second consumer bumped — gives it a new entry rather than another build’s.

SYSL_NO_CACHE, set to any non-empty value, compiles every time. It is meant for working on the compiler, where the version in the key stays the same while the code it produces changes — the one case the key cannot detect, and the same one the standard module’s cache has. No other subcommand consults it: build writes a binary to the path you named, and build-c and build-lib write artifacts for another toolchain.

SYSL_TIMINGS=1 reports how long each phase of a compilation took, one line on standard error as each phase ends:

sysl: phase parse std 130ms
sysl:   memory 240MB resident, 117MB in use
sysl: phase parse program 0ms
sysl:   memory 251MB resident, 124MB in use
sysl: phase declarations 52ms
sysl:   memory 262MB resident, 133MB in use
sysl: phase bodies 23ms
sysl:   memory 270MB resident, 139MB in use
sysl: phase checks 4ms
sysl:   memory 270MB resident, 139MB in use
sysl: phase prune 0ms
sysl:   memory 270MB resident, 139MB in use
sysl: phase std 33ms
sysl:   memory 271MB resident, 139MB in use
sysl: phase codegen 2ms
sysl:   memory 272MB resident, 140MB in use
sysl: phase link 90ms
sysl:   memory 272MB resident, 120MB in use

The phases sum to the whole compilation, with nothing counted twice. The checks phase is followed by one indented line per whole-program check (sysl: check keeps 12ms), which are parts of that phase’s time, not further phases. std is the time to find the standard module’s compiled artifact, or to build it on first use. Use these timings to find out why a build is slow.

Each phase is followed by what the compiler holds as it ends: its resident memory, and — on macOS — how much of that the allocator holds for live data. The gap between the two is memory that was freed and kept by the allocator rather than given back; only the end of a process returns it, which is why sysl test compiles a suite in one child process and links it in another (below). A large link also says what it holds as its clangs start (sysl: memory as the clangs start …).

When a phase is slow, a sampling profiler shows which functions are responsible. On a hosted target sysl keeps the frame pointer wherever the platform’s C compiler does (Apple platforms, and AArch64 Linux and Android), so sample on macOS or perf on Linux can walk the stacks of a sysl program, including the compiler itself, and report callers as well as the functions where the time went.

The kept binaries, and the C objects every build keeps beside them, are bounded. Each directory — ~/Library/Caches/sysl/run/ and ~/Library/Caches/sysl/cobj/ on macOS, under ~/.cache/sysl/ on Linux — holds at most 4 GB. Beyond that the oldest entries are removed, except any written in the last hour and any the current build used. Using an entry refreshes its age, so “the last hour” means used in the last hour, and the oldest entries are the least recently used. Beyond 256 entries, anything more than a week older than the newest entry is removed too. The sweep runs once, after a build that compiled something, and is skipped if another build swept the same directory in the last ten minutes. Deleting either directory costs one rebuild and nothing else. The same bound, sweep and exemptions apply to the compiled roots under roots/ and to the standard module’s entries (one directory per compiler build, target and optimization level, directly under sysl/), which are removed whole, oldest first, and never the one the running compiler uses.

Everything after a bare -- belongs to the program, not to sysl:

sysl run report.sysl -- --verbose report.txt

The split is made before sysl parses its own options. --verbose is also one of sysl’s options, so without the -- sysl would take it; after the -- it belongs to the program, and neither side needs to know the other’s flags. main(args: []string) receives the executable’s own path followed by those two words, so args.len is 3 and args[0] is the program, as C’s argv[0] is.

run exits with the program’s exit status. sysl exits 1 on its own behalf only when the compilation fails.

The program reads sysl’s standard input, so a program that reads input behaves under run exactly as the built binary does:

printf 'one\ntwo\n' | sysl run count.sysl

Output appears as the program writes it, not all at once when it finishes, so an interactive program that prompts for input works under run.

build

sysl build hello.sysl -o hello

The same compilation as run, stopping at the executable instead of running it. wrote hello goes to stderr, so that stdout carries only the build’s product.

-o is optional, and the default location depends on what you named. For a file, the executable takes the file’s name without its extension, in the current directory: src/tools/fmt.sysl becomes ./fmt.

For a directory, the executable goes inside it, named after it. sysl build ., sysl build fmt and sysl build ../fmt name the same project, and all three write fmt/fmt, so the result does not depend on the directory you run the command from.

A project with several executables — bin/<name>.sysl files, or a binaries block (packages) — has every one built by a bare build, each inside the project under its own name. --bin <name> builds one, and is what -o needs where there are several:

sysl build . --bin asm -o out/asm

--emit config and --emit config:<package> report the generated C configuration headers (sysl/<package>.h, see packages) the build wrote: one wrote <path> line each, on stderr, after the build has run, so what is shown is what it used. They accept a comma-separated list. --emit link reports the linker script a freestanding build generated from its manifests (.sysl/out/<target>/link.ld, see packages), and --emit all the headers and the script.

If the project’s sysl.hocon names dependencies, build fetches any this machine does not have yet — see packages. run and test do the same, so there is no separate fetch step, and a project with no dependencies fetches nothing.

build-lib

sysl build-lib mylib --target thumbv7em-freestanding
checked mylib

build-lib runs a library through the full analysis, against the standard module, for one machine, and writes nothing. Its purpose is to check a board package on a host, where nothing else can. A library is passed to a program as the directory its source is in, never as a named artifact (modules explains why), so build-lib takes no -o:

sysl: error: build-lib writes nothing anybody names — it checks a library, and what it compiles is this compiler's cache, found by the compiler alone — so it takes no -o

A library may depend on another, and --lib with the other library’s directory declares it, as it does for any compilation.

Unlike build, run and test, build-lib does not fetch. It resolves a dependencies block the same way they do — optional dependencies that no feature enables are pruned first, and the feature flags decide which those are — but only over directories. A path dependency is read in place, and a coordinate must be supplied by a --lib root or by a path dependency that stands in for it. A coordinate nothing supplies is refused, with a message naming it and the directory that would supply it. A command whose job is to check one tree for one machine does not go to the network.

--cc names the clang to use when a search would not find the right one.

sysl build hello.sysl --cc /opt/homebrew/opt/llvm/bin/clang

It is for a machine with more than one toolchain: a vendor’s clang limited to that vendor’s processors, an LLVM installed beside the system one, or a cross toolchain reached by path. A named compiler is used exactly as given, with no search and no fallback: if you named a compiler, you get an error rather than a different compiler, so naming one that cannot run is refused.

--cc applies everywhere sysl runs clang: the link, a package’s own C, the c const probe, and the rebuild of the standard module. The last matters because the standard module is rebuilt automatically when no usable copy is cached; if the flag did not apply there, the build would switch compilers partway through.

build-lib compiles the package’s C, so it requires what that C needs. A package that declares header requirements is refused without --include-path <name>=<dir>, exactly as it is for build, because build-lib is the command a package is checked with before it is published. Only the package’s own manifest is consulted: the C of a --lib source root is not compiled here, so that root’s header requirements do not apply to a library built against it.

build-c

sysl build-c mylib -o libmylib.a
sysl build-c mylib -o libmylib.a --header include/mylib.h

build-c produces two outputs for an existing C project: a static archive to link, and a C header declaring everything the module marked @export. The compilation is the ordinary one, not a library check — the module is lowered for this target with its calls resolved — and the difference from build is that no entry point is emitted, since the C side supplies its own main. The archive holds native objects by default. A manifest’s lto key does not apply to build-c, because LLVM bitcode links only under a linker with LLVM’s plugin, and optimizing across the archive is the C project’s link step’s responsibility. A C project that links with clang and lld can request it on the command line: --lto thin (or full) makes the archive LLVM bitcode, compiled as sysl build compiles its own objects in that mode, so the host’s link optimizes across the boundary. build-c then notes on stderr that the archive must be linked with -fuse-ld=lld.

The archive is always a static one, so -o may not give it a shared library’s name: -o libmylib.dylib (or .so, .so.1, .dll) is refused unless --shared is given, and the refusal names the .a to use instead. Without -o the archive is named for the project, with .a.

The header is written beside the archive, with .h appended, unless --header names another path. Its include guard is SYSL_<NAME>_H for a project whose manifest names it. A project without one is named for where it is — its directory’s own name, resolved even when it was given as ., or a bare file’s stem — with eight hex digits of its canonical path’s fingerprint after the name (SYSL_LIB_3F09A1C2_H), so two such headers included in one C file never hide each other. Both paths are reported on stderr, together with the libraries the C project’s link line still needs: what @link named, and the pkg_config modules the packages in the build require, given as the pkg-config --libs … command that produces their flags. A missing library shows up on the C side as an unresolved sysl symbol, which looks like a missing definition rather than a missing archive, so build-c lists them up front. With --no-std-lib the standard library is folded into the object, and the archive is self-contained.

--emit-llvm <out.ll> also writes the LLVM text the archive is compiled from, and the archive and the header are still built:

sysl build-c mylib -o libmylib.a --emit-llvm mylib.ll

The text is the module as build-c reads it, which is not always what emit-llvm would print for the same path. A file with no module line is an archive’s module to build-c and a program’s entry body to every other command, so private var count = 0 beside a private function that writes it is module storage here and is refused by emit-llvm, build and run. It is the text clang is handed, carrying the target’s target datalayout as well as its target triple, before any optimization: it is the same at every -O level and under --lto. The file is written before clang runs, so a module clang rejects can still be read; a directory that is not there is made, as it is for the archive and the header. --emit-llvm given twice is refused, as -o given twice is.

A shared library

sysl build-c mylib --shared -o libmylib.dylib
sysl build-c mylib --shared -o libmylib.so --target x86_64-linux --soname libmylib.so.1

--shared links what the archive would hold into a shared library for a host that opens it with dlopen, or links against it: a plugin, the reloadable half of a game, a JNI or Python extension. It is a Mach-O .dylib on macOS and an ELF .so on Linux and Android; without -o it is named for the project, with the platform’s suffix. The header is written as it is for an archive, beside the library with .h appended unless --header names another path. What the library needs — libm, what @link named, what the packages’ pkg_config modules link with — is linked into it, so the loader finds it when the host opens the library and nothing is left for the host’s link line.

Each library is self-contained: it carries its own copy of the standard library code it reaches, its own module storage, and its own copy of the runtime. Only the @export functions and storage are exported — the symbols the header declares. The runtime’s own C-named symbols (sysl_bounds_fail, the sysl_trap hook, the standard library’s own @exports such as sysl_io_flush) are global inside the library, where its own objects find them, and are not offered to the loader. Two sysl libraries opened by one process therefore never bind to each other’s code, which is also why a sysl object crosses between two of them only through their C API: a &T, a Buf or a closure made by one is owned by that library’s runtime, and the other library cannot take a share of it or free it. Pass data as C does — scalars, pointers, structs of those, and handles each library hands out and takes back itself. One runtime shared between libraries is not built.

Module storage with a computed initializer is filled by a constructor the loader runs when the library is opened, before dlopen returns. A @thread_local in the library is reached the way a library opened with dlopen has to reach one: ELF code is compiled position-independent, which gives its thread-locals the general dynamic model, and Mach-O reaches every thread-local through its descriptor.

The library’s own name and version are settable, each for the object format that has it:

flagformatwhat it setswithout it
--install-name <name>Mach-Othe install name a program linked against the library records, and so where the loader looks@rpath/ and the file’s name
--current-version <v>Mach-Othe library’s current version, X[.Y[.Z]]the linker’s, 0
--compatibility-version <v>Mach-Othe oldest version it stands in for, X[.Y[.Z]]the linker’s, 0
--soname <name>ELFthe sonamethe file’s name
--version-script <file>ELFthe version script the link usesone that exports the @export symbols and makes everything else local

A version script given with --version-script replaces the one the compiler writes, so it decides what the library exports; end its last node with local: *; to keep the runtime’s symbols in. A setting of the other object format is refused rather than ignored, and so is any of them without --shared:

$ sysl build-c mylib --shared --soname libmylib.so.1 -o libmylib.dylib
sysl: error: '--soname' is an ELF setting, and aarch64-macos links Mach-O: its library's own name is given with '--install-name'
$ sysl build-c mylib --soname libmylib.so.1 -o libmylib.a
sysl: error: '--soname' is a setting of a shared library, and is given with '--shared'

A version ld64 cannot hold — more than three parts, a first part over 65535 or another over 255 — is refused before anything is built, and so is -o naming a static archive (.a, .lib) beside --shared, and --lto, whose bitcode is for a host’s link to optimize when this link is the compiler’s own. A Windows DLL is not built yet; a freestanding target has no loader to open one.

The library is written under a temporary name and moved onto the path -o names, so the file there is always a whole library, and a rebuild is a new file rather than the old one written over: a process that has the previous build open keeps running it, and a host watching the path never opens half of one. That is what makes a hot reload work — close the library, rebuild it, open the same path again, and the new build’s code is what runs, with whatever state the host owns kept. On macOS the closed image stays mapped, because macOS never unloads a library that has thread-local storage, and every sysl library that uses the heap has some (the runtime keeps a per-thread list for tearing structures down). The loader still opens the new file as a new library, so each reload leaves the previous build in memory, not in charge. A build copied over the old file in place is not a reload: the loader does not see a new file, so opening the path answers with the old code, and on macOS a process with the old pages mapped can be killed outright for running a file whose signature no longer matches. Move a new build into place, as build-c does; never copy it over.

Like build-lib, build-c needs llvm-ar as well as clang. FFI covers @export itself: what may be exported, how a symbol is named, and how module storage with a computed initializer is initialized when there is no entry point to do it.

emit-header

sysl emit-header mylib

Prints the header build-c writes to stdout, without building anything, for a project that generates its headers as a build step.

test

sysl test <path>
sysl test <path> --filter <text>
sysl test <path> --file <name>
sysl test <path> --fail-fast
sysl test <path> --show-output
sysl test <path> --jobs <n>
sysl test <path> --build-jobs <n>
sysl test <path> --timeout <seconds>
sysl test <path> --std

The tree is compiled once, into a binary that runs one named test per process, and the runner starts it once for each test. Attributes covers @test itself: what a test may be, what other builds do with one, and why each test runs in its own process.

test runs the tests of the tree you name, and no others. A dependency is compiled into the binary because the tree’s code calls it, but its @test functions are left out. They belong to its author, to run in its own repository; a consumer cannot change that code, so its tests are not reported in the consumer’s run.

test takes the search-path flags as well — --link-path, --include-path and -D, exactly as build does, and for the same reasons. If a tree’s C includes a header the toolchain does not already know, or its constants come from a c const block over one, its tests must compile that C just as its programs do. A package binding a system library is the common case, so most packages need these flags to run their tests.

test takes the feature flags too, and with none given it enables every feature the manifest declares, not only default.

test also runs the tests a project’s executables carry. Each binary whose bin/ file (or file the binaries block names) holds a @test function is compiled into a suite of its own, with the package’s modules and none of their tests, and run after the package’s under a testing binary '<name>' (<file>) line (packages).

test also compiles each program in the root’s tests/refused/, one at a time with the package’s modules in scope, and passes it only if the compiler refuses it with a diagnostic containing every // error: line at its head. These entries are named by path, counted with the other tests, and selected by --filter (packages).

--std declares that the tree is the standard module; this is how sysl’s own library is tested. The compiler supplies sysl to every compilation, so without the flag the library would appear twice — once as the tree being compiled and once as the supplied copy — and every declaration would be a duplicate. The flag is never inferred: a program with its own sysl directory is almost always a mistake, and inferring --std would turn that clear refusal into a collision at link time.

The report groups tests by the file they are written in, keeps source order within a file, and shows a test’s output only when it failed:

running 4 tests

clamp.sysl
  ok    clamps below the low bound   6ms
  ok    clamps above the high bound  5ms
  FAIL  leaves a value in range      5ms
        did not return — exit status 134
        at clamp.sysl:31
        > panic: clamp(4, 1, 3) should be 3
  ok    is idempotent                5ms

3 passed, 1 failed — 21ms

A failure’s own line is one of three messages: did not return — exit status n, which is how a failed assert appears, because assert prints and exits; returned, and was expected to trap; and trapped, but printed nothing holding "…", for a @test(should_trap: "…") whose run trapped without printing the expected text. Everything the run printed follows underneath, prefixed >.

A passing test’s output is hidden, whether it went to standard output or standard error, and so is a @test(should_trap: "…") test’s that trapped as it promised; a failing test shows everything it printed, as above. --show-output shows a passing test’s output too, under its row in the same > lines, so a test that prints a measurement can be read:

$ sysl test . --show-output
running 2 tests

size.sysl
  ok    code size fits  3ms
        > code size: 412 bytes
  ok    is idempotent   2ms

2 passed, 0 failed — 5ms

A test that printed nothing is its row alone. Each test’s lines come after its own row, in the report’s order, however many tests ran at once, and a failing row reads as it does without the flag. The flag shows the output of every suite the run reports — a workspace’s members and a project’s binaries — and of a passing tests/refused/ program, whose output is the diagnostic the compiler refused it with.

The hooks a module may write change what a FAIL line can report, without adding a fourth verdict. A fault in @setup or @setup_all means the test it guards never runs, so there is no assertion to report; the test’s FAIL line names the setup function instead of the usual message. A @setup_all fault guards the whole module, so every test in it fails that way and none is reported as started. A fault in @teardown or @teardown_all does not affect the test’s verdict, since the test has already returned or trapped when its teardown runs. It is reported as a separate failing entry, named after the hook, alongside the result of the test it followed.

--filter keeps the tests whose name or module contains the text, and the header reports how many of the total are running.

--file <name> keeps the tests written in one file, the file a report heads their rows with. The name is the file’s base name, with or without .sysl (--file clamp and --file clamp.sysl are the same), or as much of its path as is needed to distinguish two files with the same name (--file geom/clamp). It matches whole path components, never part of one, so --file clamp does not also run clamps.sysl. --filter and --file are independent: given both, a test must match each. A refused program under tests/refused/ is a file of its own, so --file selects one the same way.

--file may be repeated: sysl test . --file clamp --file geom/lerp runs the tests of both files in one invocation, each test once (naming a file twice, or by two spellings, does not run it twice). A name that reaches no file holding a test is refused, naming it, even when the others match.

--filter may be repeated too, and the filters are OR’d: sysl test . --filter clamp --filter lerp runs every test whose name or module contains either text, each test once however many filters match it. A filter that matches nothing beside one that does is not a mistake — the header’s count says how many were kept — and when none of them matches, the run says so, naming each:

no test matches 'clamp' or 'lerp' — 12 to choose from

Both flags work with --std and with SYSL_DOCS, which they select among the tests the binary holds.

--file also decides what is built. The @tests files it names are compiled with every file that is not @tests, and of the other @tests files only those the named ones need: a file that declares a name they spell (and, in turn, what that file spells), and one that acts without being named — a hook, an @export, an @section, a calling convention, module asm, or a header clause such as @link. The rest are left out before anything is analyzed, so a run naming one file of a large tree costs that file and what it reaches, not the whole suite. The report is the same: a test in a file left out is still counted in running 3 tests of N. A mistake in a @tests file the run neither names nor needs is not reported by that run; a run of the whole suite reports it. The narrowed binary is kept in the run cache under the names given, and a binary of the whole suite answers any --file as well. SYSL_TEST_EVERY_FILE=1 builds every file, as a run without --file does. --std builds every file.

--keep-binary <dir> leaves a copy of the test binary in <dir> as <project>-tests and prints kept: <path>. A binary replayed from the run cache is copied too; the cache entry stays. A -fsanitize= in SYSL_EXTRA_CFLAGS is confirmed before any test runs: the report starts with instrumented: address (1 binary), and a binary holding none of the sanitizer’s runtime references (__asan_report, __tsan_func_entry, __msan_warning, __hwasan_) is refused. undefined is reported when present and never refused, since sysl’s own code is not instrumented by UBSan.

A test that cannot hold under a sanitizer skips itself with #if sanitize_address (or sanitize_thread), which is true exactly when the build is instrumented (#if). A test that counts what the allocator frees, say, is measuring ASan’s allocator rather than sysl’s:

import sysl.testing.skip

@test
closing_frees()
#if sanitize_address
    skip("AddressSanitizer replaces the allocator this test counts")
#endif
    assert(freed_after_close() == 1, "the handle's storage is freed")

The report then shows the row as skip with that reason under ASan, and runs it everywhere else.

Tests run in parallel — one per processor, or --jobs <n> — and the report is identical to a sequential run’s: each row waits for every row above it, so rows appear in source order, and --jobs 1 runs them sequentially. Each test already has its own process, so running them in parallel shares nothing in memory. What tests can still share is anything that outlives a process, such as a file at a fixed path or a port. A test that needs exclusive use of one should create its own, with a temporary directory or a port the system picks, or be listed in its manifest’s test.alone, which runs it with nothing else alongside. The manifest’s test block can also set the run’s jobs and timeout, and the flags override it.

The same count bounds the build, unless --build-jobs <n> gives the build its own. A large tree’s link compiles its code in several pieces at once, and --jobs <n> keeps at most n of those compiles running too. --build-jobs <n> (or the test block’s build_jobs) bounds the compiles alone, and --build-jobs 1 compiles the pieces one after another — the slower build that holds the least memory at once, for a machine running other work. The pieces and the binary are the same at any count, so neither flag makes a different cached build. The suite is compiled by a second sysl process, which exits before the first test starts. A long run therefore holds only what its tests need, not what the compile needed. A suite that has to be linked is linked by a third, which takes up the compiled text once the second has exited, so the link’s compiles never run beside the memory the compile left behind. Its notes and errors appear exactly as they would from one process.

--features <list> and --option <name=value> choose what the package’s own suite is built with. The test block’s features and options are the defaults, --features replaces the block’s list, and each --option overrides one key (it may be repeated). They are the same flags and the same resolution as build‘s, an undeclared name or a value out of range is refused, and a different setting is a different cached build. See testing a package under its options. A module’s @setup_all finishes before any of its tests starts, and its @teardown_all starts after all of them have finished.

--fail-fast stops new tests from starting after the first failure. Tests already running finish and are reported, everything that ran is reported, and tests that never started are omitted rather than reported as skipped, since “skipped” is not a verdict.

Every test has a time limit, so a test that never ends fails instead of hanging the run. --timeout <seconds> sets the limit for each test — 300 seconds by default, and --timeout 0 for no limit — and a test’s own @test(timeout: n) overrides it for that test. A test that exceeds its limit is stopped, together with every process it started, and its FAIL line reads timed out after Ns, followed by whatever it had printed; the run continues with the next test. A module’s hooks are held to the run’s limit.

A test process does not outlive its run. Each one watches the runner that started it, and if the runner stops — interrupted, killed, or its terminal closed — the test ends itself and everything it started, so a stopped run leaves nothing running.

A stopped run says what it was doing. The report is written as the run goes, at most twice a second, so a log followed from outside is never more than half a second behind. On SIGTERM or SIGINT the runner writes what it still holds, then interrupted by SIGTERM after 12.3s and an in flight: list — the file, the test and how long it had been running, or the project and compiling where the stop came during the build — kills the test processes, and exits non-zero (143 for SIGTERM, 130 for SIGINT) within a few milliseconds.

The exit status is 0 if and only if every test that ran passed. A tree with no tests, and a filter that matched none of the tests present, both exit 0. Neither is a failure, and the report says which of the two occurred.

None of this mechanism exists on a microcontroller. A board has no processes, no argv and no exit status, so sysl test cannot run code there. sysl.harness covers that case: a framework linked into the image, which names its tests, locates a failure and prints a tally through a writer you provide. Use sysl test for code that runs on your development machine, and sysl.harness for checks that can only run on the target.

emit-llvm

sysl emit-llvm hello.sysl

Prints the IR to stdout. It is the same text run and build pass to clang except for one line: the printed module’s header has only target triple, while the text clang compiles also carries the target’s target datalayout, obtained from that clang. Without it, LLVM would treat every 64-bit access the text leaves unannotated as four-byte aligned, which on a machine without unaligned access (riscv64) splits each one in two. Nothing is assembled, and no toolchain is needed. What is printed is a current LLVM’s text: an older clang is handed that text in a form it can read (Installation gives the oldest), and build-c --emit-llvm writes the form that clang was actually handed. A program with a function marked @stack(n) is the one exception: that bound is checked against the frames clang lays out, so it needs clang here as every build does.

stack

sysl stack [--target <name>] [-O<level>] <path>

Prints, for each way into the program — main, a bare image’s own entry, and every function it exports — the deepest stack a call can need, at the level and for the machine named, with the way down that needs it:

main: 896 bytes, by 'main' → 'sysl.printi' → 'sysl.digits_long', not counting the C it calls: 'fflush', 'sysl_install_stack_guard', 'sysl_stdout_write', 'write'
handler: 4192 bytes, by 'handler' → 'deep'
rec: unbounded — 'fib' recurses by the cycle 'fib' → 'fib'
apply: unbounded — 'apply' calls through a pointer — a trait object, a '&Fn' closure or a function pointer — whose target is not known, and it says nothing with '@stack(calls: n)'

The numbers are the back end’s: the program is lowered with the standard module’s bodies in the text, so a call into the library is followed, and clang reports each function’s frame — the frame --stack-usage lists and @frame_limit(n) limits — and the optimized text those frames belong to, whose calls are the graph. A function the optimizer inlined is counted once, in the frame it was inlined into. What has no bound says so, and why: a cycle of calls, a frame sized at run time, or a call through a pointer in a body that did not say what such a call needs with @stack(calls: m). A C function’s frame is not in the text; it counts as nothing, and the line names every C function it reaches. The deepest way may run through a failed check’s report (sysl_trap), which is a way the program can take. To hold a function to a number at build time, mark it @stack(n).

emit-ast

sysl emit-ast hello.sysl
sysl emit-ast hello.sysl --no-spans

Prints one file’s untyped parse tree as deterministic text: one node per line, indented under its parent, with every field the tree carries. It only parses: no analysis runs and the standard module is not read, so it works on a file that would fail to compile, and it needs no toolchain. --no-spans omits each node’s source position, so a diff does not change when lines move. A parse error exits non-zero and prints the ordinary diagnostic instead.

emit-typed

sysl emit-typed hello.sysl
sysl emit-typed hello.sysl --no-spans
sysl emit-typed hello.sysl --tables

Prints one module’s typed tree, in the same format as emit-ast; it is the analysed counterpart of emit-ast. It runs the whole front end: parsing, then analysis against the standard module exactly as emit-llvm does, with every name resolved and every type inferred. Nothing is lowered or emitted — no pruning, no code generation, no clang — so, like prove, it needs no toolchain. Every expression’s resolved type is printed as the compiler’s own diagnostic text (int, a slice of u8, Point) rather than as the type’s internal structure. --no-spans leaves out each node’s source position, exactly as it does for emit-ast. --tables prints the module’s declaration tables instead of its tree — every struct, enum, trait implementation, extern, module val and function, sorted by name, with every signature resolved. An analysis error, or a parse error, exits non-zero and prints the ordinary diagnostic instead, with nothing on stdout.

weave

sysl weave library/sysl/regex/vm.lsysl -o vm.html
sysl weave library/sysl/regex -o documents/

weave [-o <path>] <path> renders a literate source as an HTML document. A .lsysl file is a Markdown document whose four-column-indented lines are the program, so it reads well as plain text. An indented code block carries no language, though, so a Markdown renderer cannot highlight it. weave renders exactly the lines the compiler reads as program text as sysl code, as one block across any blank lines between them, and renders every other line as Markdown, so prose, tables, illustrations and heading levels are entirely up to the author.

The Markdown renderer is sysl-lang/markdown: CommonMark 0.31.2 with the GitHub extensions — tables, strikethrough, bare links, task lists, footnotes, emoji shortcodes, alerts (> [!NOTE]), mathematics as $…$ and $$…$$, and mermaid diagrams — and every heading gets GitHub’s id, so # The greeting becomes <h1 id="the-greeting">. The whole file is one document, so a link reference defined anywhere in the prose applies to a link anywhere else, and a program block closes whatever paragraph, list or quote was open before it. Raw HTML passes through, under GitHub’s tag filter.

The output is a single self-contained file. It carries its own styling, with light and dark palettes. Its code — every block whose language is sysl, including an illustration fenced as sysl — is coloured by keyword, type, function, string, number, comment and punctuation, using the lexer’s own reserved words. Its mathematics is typeset by KaTeX, which the page links to; that is the only part of a woven document that needs the network. Read offline, the document shows its equations as TeX source and is otherwise complete.

$ cat greeting.lsysl
# The greeting

A program of one statement.

    print("hi")
$ sysl weave greeting.lsysl
<!doctype html>
…
<h1 id="the-greeting">The greeting</h1>
<p>A program of one statement.</p>
<pre><code class="language-sysl"><span class="hl-function">print</span><span class="hl-punctuation">(</span><span class="hl-string">&quot;hi&quot;</span><span class="hl-punctuation">)</span>
</code></pre>
…

The output goes to standard output, or to the path -o names. A path containing several literate sources produces one document for each, and -o then names a directory, because each source file is a document in its own right. Ordinary .sysl files alongside are skipped, and a tree with no literate source is refused rather than producing an empty page.

weave is a source-level command: it needs no target, no standard module and no libraries, so a package’s documentation can be rendered on a machine that cannot build the package. It reads the source exactly as the compiler does, so a file the compiler would refuse — a tab in an indent, a fence that is never closed — is refused here too, with the same message.

weave does not generate an API reference from declarations; that is doc, below, which reads sysl’s documentation comments. The two serve different purposes — weave renders a document someone wrote, doc renders what the declarations say — so a tree often uses both.

tangle

sysl tangle library/sysl/regex/vm.lsysl
sysl tangle library/sysl/regex/vm.lsysl -o vm.sysl

tangle [-o <path>] <path> is the counterpart of weave: it writes the program with the prose removed, to standard output or to the path -o names. A path containing several literate sources produces their programs one after another; ordinary .sysl files beside them are skipped, and a tree with none is refused. Every build tangles a .lsysl file internally in order to compile it; tangle lets you see the result.

That is useful when a literate file behaves unexpectedly — a block indented by mistake, a fence that swallowed a function — because it shows exactly what the compiler read. It also provides the program to anything that does not understand the format, such as another tool or a bug report.

The prose is replaced by blank lines rather than removed, so line 100 of the output is line 100 of the source. This keeps a diagnostic’s line number valid in the original document, and is why the output is longer than the program itself.

deps

Prints the dependency graph the project resolves to: every package it will be compiled against, the version selected, and which package asked for it at what minimum version.

sysl deps .
syslui-demo 0.0.1

github.com/sysl-lang/plutovg     0.2.1
    github.com/sysl-lang/syslui-sdl asks for 0.2.1
    github.com/sysl-lang/syslui asks for 0.2.1
github.com/sysl-lang/sdl3        0.3.1
    github.com/sysl-lang/syslui-sdl asks for 0.3.1
github.com/sysl-lang/syslui      0.1.0
    github.com/sysl-lang/syslui-sdl asks for 0.1.0
github.com/sysl-lang/syslui-sdl  0.1.0
    syslui-demo asks for 0.1.0

That project’s manifest names only one dependency. Because imports are transitive, the other three packages are pulled in indirectly, and nothing in the project’s own files mentions them; deps shows them.

A coordinate marked (raised) is one for which some package asked for a lower version.

github.com/e/buf  1.4.0  (raised)
    github.com/e/a asks for 1.2.0
    github.com/e/b asks for 1.4.0

This answers why did I get this version, which a build cannot tell you: selection keeps only the highest minimum, so the lower request is no longer visible afterwards. The note a build prints covers only the case where your own manifest’s version was raised; deps also covers a dependency raised by one of its siblings, where the version you are running is one that none of your files mentions.

A coordinate marked (dev) is reached only by this project’s tests.

github.com/sysl-lang/quickjs  0.1.0  (dev)

It is declared in dev_dependencies, so sysl test resolves it, and no project that depends on this one ever fetches it. The listing includes it because a project’s dependencies are a property of its manifests rather than of one build, and the mark tells you that a consumer does not pay for it.

It is a mark rather than a separate section because a package reached through a dev dependency is in the same position without being named in either block, and a separate section would have no place for it.

A path dependency shows its directory where a coordinate shows a version, since it has no version and the directory identifies it.

deps resolves exactly as a build does, so it fetches what this machine does not have and records it in sysl.sum. It needs nothing else — no target, no standard module, and no source is read — so you can inspect a project that cannot be built on this machine.

add

Adds a dependency to sysl.hocon, at the newest version the repository has tagged or at the version you name.

sysl add github.com/sysl-lang/sdl3
sysl add github.com/sysl-lang/sdl3@0.3.1
added sdl3 github.com/sysl-lang/sdl3 0.3.1

The version comes from git ls-remote --tags, not from a hosting service’s API. A coordinate is a git identity, and the build clones it with plain git, so this works with a self-hosted server or a mirror as well as with GitHub. A tag that is not a version, such as latest or nightly, is skipped rather than refused, since a manifest cannot pin one.

add edits your manifest in place and changes nothing else in it. Re-printing the parsed file would discard every blank line, every comment explaining why a dependency is there, and your layout, so add inserts only the new text. A new entry takes the indentation of its siblings and aligns with their column where they have one.

Nothing is fetched: add records the dependency, and the next build fetches it. The result is read back through the manifest reader before it is written, so if the edit would produce an unreadable file, the file is left unchanged.

vendor

Copies every package the project depends on into a vendor/ directory beside the manifest.

sysl vendor .
fetching github.com/sysl-lang/parsing v0.12.0
vendored 1 package into vendor/

vendor/ is the machine’s package cache placed inside the project, not a separate mechanism: the same layout, the same resolution, the same sysl.sum. A project with a vendor/ directory builds without network access, and someone who clones it needs no extra steps: the directory’s presence is all that enables it.

The graph is resolved against the machine’s cache first, so anything missing is fetched (the fetching line, on standard error) and any package sysl.sum has no line for gets one, exactly as in a build. Each package is then copied out of the cache, and the copy’s hash is checked against its sysl.sum line before it is put in place, so a cached package edited after it was fetched is refused rather than copied into your project. A repository’s .git is not copied. Running the command again copies only what is missing.

vendor copies the graph sysl test resolves — every feature the project declares, unless the feature flags say otherwise, and its dev_dependencies as well as its dependencies — so a vendored project’s own tests fetch nothing either. Inside a workspace there is one vendor/, at the workspace root, holding every member’s packages.

vendor/ is not part of the project’s own source, just as examples/ is not, so nothing in it is compiled as one of your modules. Commit it if you want builds that keep working even if an upstream repository disappears; leave it out of the repository if you prefer to fetch.

A path dependency is not vendored. It is a directory you are editing alongside this project, which is why sysl.sum keeps no hash for it, and a frozen copy would defeat its purpose. The command reports how many path dependencies it skipped.

tidy

Removes from sysl.sum every line for a package version the project no longer resolves to. A build only adds lines, so a version the project has moved away from stays recorded until tidy runs.

sysl tidy
removed github.com/sysl-lang/skitter v0.1.0
removed github.com/sysl-lang/box2d v0.1.0

With no path, it uses the working directory. It resolves the complete graph — every feature the manifest declares, and the dev_dependencies too — because a pruned graph would drop the lines for features not currently selected. A line that stays is left exactly as it was, a file that is already tidy is left untouched with nothing printed, and a project whose dependencies are all paths ends up with no sysl.sum at all.

--check writes nothing and fails if the file is not tidy, naming what it would change; this is the form to use in CI. Outside a project, with no sysl.hocon, the command is refused. Packages has the rule.

init

Starts a project in a directory, and asks nothing.

sysl init [<dir>]
created /home/me/tool/sysl.hocon
created /home/me/tool/main.sysl

With no directory it uses the working directory; a named one is created if it does not exist. It writes a minimal sysl.hocon — name is the directory’s, version is 0.1.0, and sysl is the compiler’s own version, the floor a build is checked against — and a main.sysl that prints a greeting, unless the directory already has one, which is left alone. The result builds and runs as it stands: sysl run.

A directory that already holds a manifest, under either name, is refused and nothing is written.

doc

Generates an API reference for a tree from its declarations and their doc comments, one Markdown page per module.

sysl doc library --out docs/api
sysl doc: 27 modules -> docs/api

doc writes Markdown rather than a website. A docs/ folder of generated Markdown is readable directly in a repository host such as GitHub, with no tooling, hosting or installation, and it can be reviewed as a diff in a commit, which generated HTML cannot.

The unit is a module, not a type, because a module is what you import.

A page lists every public declaration of its module, each group under its own heading: constants, values (val), variables (var and static var), functions, externs, types, aliases, traits and implementations. A declaration’s signature is shown as it was written, and its doc comment beneath it; a function whose result is read off its body is shown at that result, -> T and all, and its body is never shown. A variable is listed because storage a caller may write is as much a part of a module’s API as storage it may only read.

FlagMeans
-o, --out <dir>where the Markdown goes (default docs/api)
-t, --title <text>the index page’s title
-n, --note <text>a note under the index page’s title
-V, --docversion <v>the version being documented, shown on the pages
--privateinclude file- and module-private declarations
--site <dir>after writing, build the juicer site rooted at <dir>
--checkwrite nothing; exit non-zero if what is committed is stale

--check keeps committed documentation current. Generated files kept in a repository go stale, so a CI job regenerates them and compares:

sysl doc library --out docs/api --check
sysl doc: docs/api is stale — 2 file(s) differ:
  sysl-text.md
  sysl-slices.md

Regenerate with 'sysl doc' and commit the result.

It exits 1 in that case and 0 when everything matches, so a CI build fails when a doc comment was edited without regenerating the pages.

doc reads only the syntax. Nothing is analysed, so a package whose dependencies are missing, or which does not currently compile, can still be documented.

A literate source is tangled first, so a .lsysl file’s narrative never reaches the generator; that prose documents the program as a whole and is rendered by weave. A doc comment written inside its code blocks is read like any other. A literate module whose author explained everything in the narrative therefore produces bare signatures here, by design.

Building an HTML site

sysl doc is built into the compiler, and it writes only Markdown. --site passes the pages to the juicer command, found on your PATH, to build the HTML. A site generator needs a templating engine, an asset pipeline and a web server, none of which belong in a compiler. If juicer is not installed, sysl doc says so and where to get it.

import-c

sysl import-c /opt/homebrew/include/tree_sitter/api.h --prefix ts_ --include-as tree_sitter/api.h
sysl import-c -I vendor/include vendor/include/fx.h --prefix fx_ --module sh.sysl.fx.c \
    --shim sh/sysl/fx/c/shim.c -o sh/sysl/fx/c/c.sysl

import-c [-I <dir>] [-D <macro>] [--prefix <p>] [--module <name>] [--link-lib <lib>] [--include-as <path>] [--follow <header>] [--shim <file.c>] [--target <name>] [-o <path>] <header.h>. The raw layer of a binding, read out of the header rather than transcribed from it, as one module: an opaque struct for each handle, a struct or union for each record with a complete definition, an extern for each function and variable, a type alias for each callback and scalar typedef, and every number in a c const block — each enum a c type with its enumerators at it, each #define of a number by name. The pleasant layer above it is still written by hand: who owns what, which pointer may be null, and what a callback’s trampoline looks like are decisions the header does not record.

Records are written as C declares them. A C union is a sysl union, an anonymous member is an anonymous union/struct block in place, and a named member of an unnamed record type (union { … } v;) gets a type of its own named for both (HolderV). A bitfield T name : W is a C bitfield, name: uW in T; __attribute__((packed)) is @packed and __attribute__((aligned(16))) is @align(16). A union member sysl cannot express (a long double, a record withheld here) is kept as its bytes, _ld: [SIZEOF_ALT_LD]u8, with the union’s boundary said by @align(ALIGNOF_ALT). A plain char is i8 as a value and u8 behind a pointer.

--follow <header> brings across the records and enums another header declares where this header uses them — struct timespec passed to a function by value, say, laid out with the same checks as its own, or an enum a function takes, written as a c type with its enumerators at it whether it is tagged, typedef’d or an anonymous enum named by a typedef. A header is matched by its path or by the end of it (--follow _timespec.h). Only what is used is written. Without it such a declaration is refused, and the refusal of a record names the --follow that would lay it out.

--shim <file.c> writes a C wrapper for each static inline function and each function-like macro, which have no symbol to link against, and an extern for it in the module:

int sysl_fx_twice(int x) {
    return fx_twice(x);
}

A function-like macro is wrapped when its body is one call of a function the header declares, each of its parameters one whole argument — that function’s types are the macro’s; any other is refused by name, as is a function or macro taking .... Put the file in the module’s directory: a .c file beside a module is compiled with it, so the pair builds with nothing more said.

clang is the front end. The header is compiled twice — once with -E -dD for its own #defines, once with -ast-dump=json for its declarations — for the target --target names (the host by default) and with every -I, --include-path and -D on the command line, which are the flags a c const is measured with. A header clang cannot compile is refused in clang’s own words.

What it writes checks itself on every build. A record that is laid out carries an @assert for its size and for each field’s offset — and for its boundary, where that is not simply its fields’ (a union, an @align, C bitfields) — against c consts holding clang’s sizeof, _Alignof and __builtin_offsetof for the target being built, so a layout that differs on another machine stops the build at that record, naming it, instead of reading the wrong bytes. A bitfield has no offset to check; its record’s size and boundary are. C’s long is a c type (CLong) for the same reason: it is four bytes on one machine and eight on the next.

--prefix is taken off every name, ignoring case: with ts_, ts_parser_new is parser_new, TSNode is Node and TSQuantifierZero is QUANTIFIER_ZERO. A type is UpperCamel with any _t dropped; a constant is SCREAMING_SNAKE; a reserved word is written between backticks. --include-as is how the module’s @include names the header, which by default is its path under the first -I holding it, or its file name. --module and --link-lib put a module line and an @link at the top.

What cannot be generated is said, not guessed — on stderr as sysl: note: not generated: …, and again in a comment at the foot of the module. A record with a flexible array member, one laid out under #pragma pack, one with an aligned whose value is not a literal, and one with a bitfield whose unit is not an integer of 8 to 64 bits (long x : 3) stay opaque, with SIZEOF_/ALIGNOF_ constants so a caller can still allocate one. A record passed by value or an enum from another header without --follow, a wide string macro (L"…") and a macro that is an address, are refused by name. The command still succeeds: a header with one unbindable macro is worth the rest.

targets

Lists the target registry, one line per machine: the name to write after --target, the LLVM triple it stands for, and, for a target sysl knows but cannot build for, the reason:

aarch64-macos                arm64-apple-macosx
x86_64-macos                 x86_64-apple-macosx
aarch64-linux                aarch64-unknown-linux-gnu
x86_64-linux                 x86_64-unknown-linux-gnu
riscv64-linux                riscv64-unknown-linux-gnu
x86_64-windows               x86_64-pc-windows-msvc
aarch64-android              aarch64-linux-android24
aarch64-freestanding         aarch64-none-elf
x86_64-freestanding          x86_64-unknown-none-elf
riscv64-freestanding         riscv64-unknown-elf
thumb-freestanding           thumbv8m.main-none-eabihf
thumb-freestanding-softfp    thumbv8m.main-none-eabi
thumb-freestanding-soft      thumbv8m.main-none-eabi
thumbv6m-freestanding        thumbv6m-none-eabi
thumbv7m-freestanding        thumbv7m-none-eabi
thumbv7em-freestanding       thumbv7em-none-eabihf
thumbv7em-freestanding-soft  thumbv7em-none-eabi
thumbv7em-freestanding-dp    thumbv7em-none-eabihf
riscv32-freestanding         riscv32-unknown-elf
wasm32-freestanding          wasm32-unknown-unknown
wasm32-wasi                  wasm32-wasip1
craft-freestanding           craft
x86-linux                    i386-unknown-linux-gnu  (no C calling convention has been measured for x86)

The line for the machine you are on is marked (this machine), and a final line reports which processor and operating system sysl detects — this machine reports: aarch64 / macos on an Apple silicon Mac. On a machine with no entry in the registry, that line is the only place to see what sysl detected.

aarch64-android is the only row whose triple carries a version number, and the only one that needs an environment variable. The 24 is an Android API level, which determines which of Bionic’s declarations exist. It is in the triple because clang requires it there: without a level, __ANDROID_API__ is not defined, and the first system header that guards a declaration on it fails to compile. Its C calling convention is the same as aarch64-linux (both are AAPCS64); everything above the ABI differs, which is why Android is a separate system and #if android is a symbol distinct from #if linux.

The variable says which clang to use. Every other target here works with any clang that has the right back end, but a back end is not a toolchain: Android’s headers and libraries come from the NDK, and no clang outside it carries them. sysl therefore reads the environment. ANDROID_NDK_ROOT or ANDROID_NDK_HOME names an NDK directly; otherwise ANDROID_HOME names the SDK, and the newest ndk/<version> under it is used.

export ANDROID_HOME=~/Library/Android/sdk
sysl build --target aarch64-android hello.sysl

ANDROID_SDK_ROOT is also read and means the same thing, but Android’s documentation marks it deprecated in favour of ANDROID_HOME, so set ANDROID_HOME. If you have both, keep them pointing at the same directory, which Android Studio and the Gradle plugin check.

sysl does not search for an NDK. An NDK can be installed anywhere, so a search through your home directory could find the wrong one, or none, and building against the wrong platform headers fails in ways that are hard to see. With nothing set, the build stops and says what to set:

sysl: error: building for Android needs the NDK's own clang, and nothing here says where it is — no clang outside the NDK carries Bionic's headers, so one picked for having the back end fails at the first '#include'. Set ANDROID_HOME to the Android SDK (the directory holding 'ndk/'), or ANDROID_NDK_ROOT to one NDK directly

Without this check, the host’s clang would be chosen because it has an aarch64 back end, and the build would fail on a missing dirent.h inside the standard library’s C, which looks like a broken library rather than the wrong compiler.

Naming the NDK is all that is required. Its clang finds its sysroot from its own location, so there is no --sysroot to pass and no include or library path to configure. The result is an ordinary position-independent Android executable, which is what an APK loads.

Eight of the freestanding rows are 32-bit microcontrollers. The RP2350 (Raspberry Pi Pico 2) boots either a pair of Cortex-M33 cores or a pair of RV32IMAC cores; the RP2040 (the original Pico) has two Cortex-M0+ cores; the Armv7E-M rows cover ST’s parts; and Armv7-M is the Cortex-M3. Microcontrollers are the main use of freestanding targets; the three 64-bit freestanding rows serve kernels and hypervisors. The Arm rows are named thumb rather than arm because a Cortex-M executes only Thumb code, so a target named arm and built for A32 would produce code the core cannot run.

The Cortex-M33 has three rows, because both the float ABI and the presence of an FPU depend on your project and board. thumb-freestanding passes floating-point arguments in VFP registers, which is what eabihf selects; thumb-freestanding-softfp passes them in core registers, which is what -mfloat-abi=softfp means and what pico-sdk builds by default. The two cannot be mixed — GNU ld refuses the link, saying one object “uses VFP register arguments” and the other “does not” — so a sysl archive linked into a C build must match that build. Pick the one your project already uses; if you are not sure, softfp is the pico-sdk default.

Both of those rows use the M33’s own FPU, which is single precision. f32 arithmetic compiles to instructions, and f64 arithmetic compiles to calls — __aeabi_dmul and its family, which the program carries in sysl.softfloat.binary64 — because an fpv5-sp-d16 has no double-precision instructions. This is a property of the hardware, not a setting, and worth knowing before putting f64 in an inner loop.

The third row, thumb-freestanding-soft, is for a board with no FPU. softfp is not soft: -mfloat-abi=soft means no FPU instructions at all, while softfp uses the core’s fpv5-sp-d16 and changes only the calling convention. A triple cannot express that distinction — both rows are thumbv8m.main-none-eabi — so sysl states it on every clang command line, together with the convention: -mfloat-abi=soft -mfpu=none for the soft row, -mfloat-abi=softfp -mfpu=fpv5-sp-d16 for softfp, and -mfloat-abi=hard -mfpu=fpv5-sp-d16 for the first. None of this is left to the compiler’s default, because the default varies: the same triple reports a floating-point unit under some clang builds and none under others, so a row that relied on the default would describe a different machine depending on which clang was installed. Use the soft row when your board’s headers say the FPU is off. That is where the difference becomes visible: CMSIS refuses the build with “Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)”, and every Zephyr MPS2 board is configured that way. The opposite mistake is harder to find: the image links and boots, then faults at the first arithmetic that reaches a VFP instruction.

thumbv7em-freestanding and thumbv7em-freestanding-soft are the same pair for Armv7E-M: an STM32 F4 with the FPU enabled, and one without.

thumbv7em-freestanding-dp targets the Cortex-M7’s double-precision FPU. The thumbv7em-freestanding row names an fpv4-sp-d16, which does single precision in hardware and calls a library routine (__aeabi_dmul and the rest) for every f64 operation. A Cortex-M7 with a double-precision FPU (an STM32 F7 or H7) has an fpv5-d16, so this row — the same triple, -mfloat-abi=hard, and -mfpu=fpv5-d16 — lets an f64 multiply compile to vmul.f64. Use it only on a part that has the double-precision unit: on a single-precision M7 the first f64 instruction takes a usage fault.

thumbv6m-freestanding and thumbv7m-freestanding are different architectures, not further conventions. The first is the RP2040’s Cortex-M0+ — Armv6-M, an earlier architecture rather than a subset of Armv8-M — and the second is the Cortex-M3. Build programs for the original Pico with thumbv6m; a thumb- row produces instructions the core cannot execute, and the failure is a fault at run time rather than an error at link time. Neither architecture includes a floating-point unit, so neither needs a -soft variant.

Build a Cortex-M3 program for thumbv7m rather than thumbv6m, even though Armv6-M code runs on an M3. The difference is in the headers: a real project reads its own configuration, takes CONFIG_CPU_CORTEX_M3 to mean Armv7-M and uses BASEPRI, while CMSIS, seeing an Armv6-M triple, provides an intrinsic set without it.

On Armv6-M, one feature needs support from the board. Armv6-M has no atomic instructions, so a program using &sync — the shared counted reference — compiles to calls the toolchain does not supply, and the link fails naming __atomic_fetch_add_4. Other programs are unaffected, because those calls are emitted only for a program that uses &sync. The pico package implements them with one of the chip’s hardware spinlocks, which a dual-core part requires: masking interrupts affects only one core, and the other core could still lose the update.

wasm32-freestanding is 32-bit and freestanding, but not a board. It is WebAssembly, run by a browser, wasmtime, or any other host that embeds a module. As unknown-unknown in the triple indicates, it has no libc, no loader and nothing that runs before an exported function is called. sysl links it with -nostdlib and names main as the module’s entry, which keeps main reachable and exports it under that name. A program that does not print produces a few hundred bytes of .wasm that wasmtime can run; a program that prints fails at the link naming putchar, as on any other bare target.

It needs a clang with the WebAssembly back end. Apple’s clang does not include it, so on a Mac sysl uses Homebrew’s LLVM automatically, as it does for the RISC-V rows, and says so if it cannot find one.

wasm32-wasi is the same machine with a libc, and it is the one to use unless you specifically need the bare target. WASI is a standard set of imports — file descriptors, clocks, randomness, arguments, exit — that a module requests from its host by name instead of making system calls, and wasi-libc is a full libc built on them. A program that prints therefore links and runs, sysl.fs and sysl.env work, and nothing needs to be written by hand before the first build:

export WASI_SDK_PATH=~/wasi-sdk-34.0-arm64-macos
sysl build --target wasm32-wasi hello.sysl -o hello.wasm
wasmtime hello.wasm

It needs wasi-sdk: clang, wasi-libc and a sysroot in one download from the project’s releases. This is the same arrangement as Android’s NDK, for the same reason: a clang with the wasm32 back end is not a complete toolchain, and one chosen for the back end alone fails at the first #include. sysl does not search for it; with WASI_SDK_PATH unset, the build stops and says what to set.

The WASI version is preview1, which every runtime supports and which the browser shims (@bjorn3/browser_wasi_shim, Node’s node:wasi) implement. preview2 — the Component Model, with WIT interfaces and resource handles — produces something that is not a core wasm module and that browsers do not run natively; the standard preview1-to-preview2 adapter converts a module into a component, so a preview1 module can still be used there.

craft-freestanding is 16-bit, and it is the one row for which sysl does not drive the whole build. CRAFT is a teaching ISA with eight registers, a 64 KiB virtual address space and a software-managed TLB. Its LLVM back end is maintained out of tree, so it provides an llc rather than a compiler driver. The machine has no libc, no object format and no linker: its assembler reads one file and resolves every label inside it. sysl therefore emits the LLVM IR and stops, and two more commands finish the build:

sysl emit-llvm hello.sysl --target craft-freestanding > hello.ll
llc -march=craft hello.ll -o hello.s
craft as hello.s

Every other subcommand refuses this target and says why. sysl can lower for it — emit-llvm produces an ordinary module — but there is no compiler driver for it to call.

The 16-bit width is visible in your code. usize is pointer-width by definition, so a slice’s length is a u16 and the address space bounds everything. An int is still 32 bits and a long still 64, because the language fixes those widths rather than the machine, so ordinary arithmetic here is multi-word and the back end expands it, as every 32-bit target expands a long. Indexing with an int needs no conversion: an index wider than an address is checked against the address range and then narrowed, so for i in 0..<4 do b[i] … means what it means everywhere else.

x86-linux is listed because it cannot be built for, so that naming it produces an explanation rather than “unknown target”. The limitation is in the compiler, not the machine, and it is not the 32-bit width: what is missing is a C calling convention verified against clang, which is required before sysl supports a target.

Freestanding does not mean self-contained. A program built for a bare board still refers to C symbols that its runtime must define: putchar wherever anything prints, free wherever a reference count can reach zero, and memcpy and memset for structure assignments. These are not sysl-specific dependencies; any C compiler emits the same calls for the same code, and a real project already has them because its SDK links a libc.

What the program does carry is the arithmetic the machine has no instruction for. A long is 64 bits everywhere, and no Cortex-M or 32-bit RISC-V core has a 64-bit divide instruction, so dividing one — and formatting one, which divides by ten, and therefore any reachable panic — is a call to compiler-rt’s __aeabi_ldivmod or __divdi3. An f64 on a machine with no double-precision unit is a call per operation, __aeabi_dmul or __muldf3. The standard module defines these routines (sysl.softint, sysl.softfloat.binary64) as weak symbols, and a build for a 32-bit machine keeps them exactly where reachable code divides a 64-bit integer or computes with an f64. An image therefore links with -nostdlib, and if a libgcc also defines them, its definitions take precedence. An f32 on a core with no FPU at all — a Cortex-M0+ or M3, or RISC-V without F — works the same way: __aeabi_fmul or __mulsf3, kept where reachable code computes with one. Armv6-M lacks more: 32-bit division, 64-bit multiply, variable shifts and leading-zero count are all calls there, which LLVM generates from code that does not mention them, so sysl.softint is kept in every Armv6-M build. Every Thumb core calls the run-time ABI’s __aeabi_memcpy4 and its relatives for a large struct copy, so sysl.softint.aeabi provides them in every Thumb build, built on C’s memcpy and memset, which the board supplies as on any freestanding target.

lsp

sysl lsp is a Language Server Protocol server on standard input and output, for an editor to start and communicate with. It takes --stdio, which is what an editor’s client library passes, and no other option. Standard output carries the protocol; anything the server reports about itself goes to standard error.

Every answer comes from the same analysis sysl build performs, rerun in full after a change to an open file, using the text the editor holds, saved or not. Changes that arrive faster than they can be analysed are coalesced: the server reads every message already waiting, keeps only the latest text of each file, and analyses once the input has been quiet for about a tenth of a second, so the diagnostics after the last keystroke wait for one analysis, not one per keystroke. Requests are answered in the order they came, and a hover or definition is answered after the latest text has been analysed.

An analysis is published in two steps. What the program’s own text says — a syntax error, a type error in a body, anything the declarations and the package’s own bodies reveal — is published as soon as it is known. The package’s @tests files are left out of this first step, unless the file being edited is one, so their mistakes arrive with the second. What only the whole program decides — the generic instances it uses, its module storage evaluated, and the whole-program checks such as whether a function keeps a pointer it was handed — follows, and when it does the published lists are exactly what sysl build would report. A whole-program diagnostic in a file whose text has not changed stays up in between, so it does not flicker while another file is edited. A change that arrives while an analysis is running stops it, and the newer text is analysed instead; nothing is ever published about a text the editor has since replaced.

requestanswer
textDocument/didOpen, didChange (full text)textDocument/publishDiagnostics: the file’s syntax error, or every diagnostic the analysis reports, ranged in UTF-16 columns as the protocol counts them — for the file itself and for every other file the analysis found a mistake in, open or not; a file whose mistakes are gone gets an empty list
textDocument/hoverthe type of a local or a module val/var, or a function’s signature
textDocument/definitionwhere that name is declared — in the file, another file of the package, or the standard library

A file is analysed with the package whose sysl.hocon is nearest above it. A file of the standard library is analysed with the whole library, as sysl test --std checks it. A file with no manifest above it, whose directories spell the module its header declares, is analysed with the tree above those directories; any other file is analysed alone. The standard library is parsed once and kept for the life of the server, except while the editor holds unsaved text for one of the library’s own files. Each package file’s parse is kept as well, and a file is parsed again only when its text, or the features and options its package gates it with, has changed — whether the editor changed it or something changed it on disk. A message that is not JSON is answered with the JSON-RPC parse error (-32700); a request the server does not answer, with -32601. The server ends at exit, with status 0 after shutdown and 1 without; input that ends or cannot be framed ends it with status 1.

Visual Studio Code: the sysl extension starts sysl lsp --stdio and colours sysl with the grammar the documentation uses. Install the .vsix from its releases (Extensions: Install from VSIX…). Its settings are sysl.server.path (the compiler, sysl on the PATH by default) and sysl.lib (passed as SYSL_LIB; an installed sysl needs none). The grammar itself ships in the release at share/sysl/editors/sysl.tmLanguage.json, for any editor that reads TextMate grammars.

Flags every subcommand takes

--target <name>the machine to build for; defaults to this one
--lib <dir>a library’s source directory to compile against; may be given more than once
--no-std-libcompile the standard module from source rather than linking the cached one
--link-path <dir>where to look for a library a link directive named; may be given more than once
--include-path <dir>where to look for a header the C beside a module includes; may be given more than once
--include-path <name>=<dir>the same, and it answers the header requirement a package declared under that name
-D NAME or -D NAME=valuea macro the C beside a module is compiled with; may be given more than once
-O <level>the optimization level handed to clang; -Os also marks every function optsize and -Oz marks it optsize minsize, as clang does for C, so the optimizer keeps fixed-count loops rolled
--debug, --releasethe build mode: whether integer overflow of a plain operator stops the program or wraps
--lto <mode>optimize across every object at the link: thin or full
--link <how>link pkg_config libraries from their static archives: static, dynamic, or a comma-separated list of their names
--profile-generate <dir>build an instrumented program that writes its counters into this directory
--profile-use <file>build against a merged profile
--no-bounds-locationsleave the file:line:column out of a failed bounds check’s report — the bounds_locations key for one build
--no-error-tracesrecord no error return trace — the error_traces key for one build
--general-regs-onlykeep the code out of the floating-point and SIMD registers — the codegen block for one build
--strict-alignmake every access aligned — the codegen block for one build
--cpu native or --cpu <name>generate code for a processor: native is the machine running the build, and any other value is an LLVM processor name such as apple-m4 or skylake. Every function carries the "target-cpu" attribute, and so does every clang the build drives; clang --target=<triple> -print-supported-cpus lists the names. native is refused beside a --target that is not this machine, and a name LLVM does not know is refused; the processor is part of every cache key
--frame-limit <bytes>fail the build where a function’s stack frame is larger — the frame_limit key for one build; @frame_limit(n) above a function and a dependency’s own key are nearer
--stack-usage <file>write every compiled function’s stack frame to this file, largest first: bytes, static or dynamic, the function, where it was written
--error-limit <n>how many errors a failed compilation shows; defaults to 20, and 0 shows every one
-p <member>, --package <member>in a workspace, the member to build, test or run
-v, --verbosereport what the build decided: the files read, the standard module and how it was reached, the search paths, the allocator, and the clang and linker command lines
--explain-escapesreport every local array promoted to the heap, and every &T box on the heap and why
--explain-drop-orderreport every local declared below a defer in its block, whose release the 0.8.0 drop order moves ahead of that defer
--explain-borrowsreport, for every function, whether its answer is a place of a parameter, +0 from one, or why not
--explain-checksreport every run-time check that survives optimization: where it was written, what it checks, the function it is in, and why the hoist left it

An unknown option is refused, never ignored. Each mistake is reported on a line of its own, with the command’s usage below, on standard error, and the exit status is 2. A misspelt --relase is therefore never silently built as a debug binary, nor mistaken for the path and compiled:

Error: Unknown option --relase
usage: sysl build [--target <name>] [--cc <path>] [-O<level>] [-o <exe>] …

An option that needs a value and was given none is reported the same way, as Error: Missing value after --target. An option that takes one value and is given twice is refused too, on every command, rather than the last one silently counting — --target, --cc, -o, --bin, -p, -O, --cpu, --lto, --keep-binary, --timeout and every other single-valued flag, under any of its spellings (-o a --output b, -O2 -O3):

Error: --target is given more than once ('aarch64-macos', then 'x86_64-macos') — it takes one value
usage: sysl --version | --help | …

The options that say “may be given more than once” above add to each other instead, as do --filter, --file, --features, --option and --emit. An option that one command takes and another does not, such as -o on test, is unknown to the second. A lone - is a path, and everything after -- in run belongs to the program, options included.

The standard-module flags and -O are covered in installation, including why the default is -O1 rather than -O0. --lto is the flag form of the lto manifest key, --link of the link key, and the two profile flags are the first and last steps of the workflow below.

How many errors are shown

A compilation that fails shows its first 20 errors, in source order (by file, then line, then column), and closes with a line saying how many more there were:

10 more errors not shown; '--error-limit 0' shows all

--error-limit <n> shows n instead, and --error-limit 0 shows every one, as clang’s -ferror-limit does. Every command that compiles takes it, sysl test included; a value that is not a whole number is refused before anything is built. Only errors count: a compilation that succeeds prints each of its warnings however many there are, and one that fails prints its errors alone. The language server is handed every diagnostic whatever the limit.

Debug and release

Every build is debug or release, and the mode decides one thing: what a plain integer +, -, *, a unary - and a written integer conversion such as u8(n) do when the answer does not fit the type. In a debug build they stop the program with a report naming the operation, its types and the line — integer overflow: int * int (main.sysl:3:13). In a release build they wrap at the declared width, which is defined behaviour.

commandbuilds in
sysl run, sysl testdebug
sysl build, build-lib, build-c, emit-llvm and the restrelease

--debug or --release on any of them says otherwise. The two together are refused, in either order, rather than the last one silently winning, with status 2 and the usage under the mistake:

Error: --debug and --release cannot be given together — a build is debug or release, not both
usage: sysl --version | --help | …

Either one given twice says the same thing twice and is not refused. No other flag sets the mode: --overflow belongs to sysl prove alone, where it chooses whether overflow is a proof obligation (check or ignore), and every command that builds refuses it as an unknown option beside either mode, in either order. On sysl prove it stands beside --debug or --release and changes nothing about the mode. The mode is not the optimization level: sysl run -O2 is an optimized debug build and sysl build -O0 --release an unoptimized release one. Nothing else differs between them — bounds checks, contracts, invariants and a ranged type’s checks are in every build (traps) — and the operators that say their overflow, +% and +| and the rest, do the same in both.

A conversion of a constant is the bit pattern written down and is the same in both modes: u32(-1) is 4294967295, exactly as it is in a const. A const itself is worked out exactly by the compiler and refused if it does not fit its type, in every mode; the modes reach only what runs.

Each body keeps the mode it was compiled in. The standard module’s cached artifact is built once per mode, so a program and its standard library always agree. A .syslib made by build-lib records the mode in its metadata, and a debug program may link one built in release: the library’s compiled functions wrap and the program’s own code is checked. A generic function the program instantiates from it is compiled with the program, in the program’s mode.

Profile-guided builds

A profile-guided build has three steps, two of which are sysl builds. The optimizer is told what the program actually did — which branches are taken, which calls are hot, which functions are never reached — and lays out the code accordingly, rather than relying on static analysis alone.

sysl build . --lto thin --profile-generate prof -o myprog-instr
./myprog-instr <each job in the training set>
"$(clang -print-prog-name=llvm-profdata)" merge -output my.profdata prof/*.profraw
sysl build . --lto thin --profile-use my.profdata -o myprog
  1. Instrument. --profile-generate applies to every clang invocation in the build — the module, each C file a package carries, and the link, which supplies the counting runtime. The instrumented program is larger and slower than a normal build.
  2. Train. Run it on work that resembles its real workload. Each run writes into the named directory, under a name derived from the binary, and the runtime merges into that one file rather than overwriting it, so any number of training runs leave a single .profraw holding all of them.
  3. Merge, then build against the result. --profile-use takes the indexed profile that llvm-profdata merge writes, not the raw counters the program wrote.

Giving both flags at once is refused, because clang would accept both and silently instrument the build you asked it to optimize. Neither is a manifest key: a profile describes one measurement on one machine, and a path to it in a manifest that consumers read would be wrong for everyone but its author.

Use the llvm-profdata the compiler names, not the one on the PATH

A .profraw file carries a format version, and llvm-profdata reads only the version its own LLVM writes, so the tool must match the compiler, not whatever is installed on the machine. On a Mac the two often differ, and the failure looks like a corrupt profile rather than the wrong tool:

warning: default_15853205779378358405_0.profraw: raw profile version mismatch: Profile uses raw
profile format version = 10; expected version = 11
error: no profile can be merged

clang -print-prog-name=llvm-profdata always gives the right answer, because it asks the driver where its own tools are. Apple’s clang reports the one inside Xcode’s toolchain, which is not on the PATH, while the llvm-profdata that Homebrew’s LLVM puts on the PATH belongs to a different LLVM.

Ordinary builds carry no instrumentation

A build that did not request instrumentation contains none: nm finds no __llvm_profile symbol in a plain build, nor in a binary built with --profile-use, because a profile is read at compile time and leaves nothing in the output.

Measured effect

Measured on the slate interpreter, trained on its own benchmark suite and measured on the same suite by alternating best-of-9 runs, in addition to -O2 with thin LTO:

geomeanbinary
-O2, --lto thin—6,013,000 bytes
the same, instrumented(not for use)10,162,936 bytes
the same, --profile-use−12.5 %5,880,888 bytes

Compared with the plain -O2 build, LTO and the profile together give about −31 %, and the profile-guided binary is smaller than the one built without a profile, because cold code is moved away from the hot path. All 64 programs checked produced byte-identical output.

Training on the same work you then measure overstates the gain, and the table above does exactly that. A profile helps most on jobs that resemble the training set; for a workload unlike anything in training, expect less.

The feature flags

run, build, build-c, build-lib, test, deps and vendor take three more flags, which select the root project’s features, and therefore which optional dependencies are fetched:

--features <a,b>a feature of the root project to turn on, beside default; comma-separated, and may be given more than once
--no-default-featuresleave the root’s default feature off
--all-featuresturn on every feature the root’s manifest declares

--all-features cannot be combined with either of the others. It requests every feature the manifest declares, while each of the others requests something narrower about the same set, so no precedence rule could honour both.

sysl: error: --all-features says every feature the manifest declares is wanted, and
--features/--no-default-features each say something narrower about the same set — a compilation
cannot ask for both

With none of the three, sysl test enables every feature the manifest declares, so that no feature-gated code goes untested. Giving any of them turns that off, so a suite can be run in exactly the configuration a consumer would get.

A module that binds a C library carries C of its own, and that C has to be found, compiled and linked. The three flags address the three ways this fails, in the order the failures occur:

  • --include-path — the shim #includes the library’s header and cannot find it. This is the first failure, and often unexpected, because it happens before anything reaches the linker.
  • -D — the header is found but refuses to compile, because a sizeable C project configures its headers with macros that have not been set. pico-sdk’s pico/cyw43_arch.h, for example, stops with #error rather than guess which architecture variant is meant.
  • --link-path — everything compiles, but the library archive is not where the linker looks.

sysl supplies no defaults for any of these. It does not add /opt/homebrew/lib, and it does not define macros: a compiler that assumed where a platform keeps its libraries, or how a project configures its headers, would be wrong on some machine, and the resulting build failure would occur where the project’s author cannot reproduce it. These settings belong to the project.

A build system that already knows these values can pass them through: from CMake, read the target’s INCLUDE_DIRECTORIES and COMPILE_DEFINITIONS and pass each one along.

A package whose C includes headers it does not carry can declare them, which turns the first failure above into a clear message. Written as --include-path <name>=<dir>, the flag satisfies a requirement the package declared, and a build missing one is refused by name before clang runs. See packages.

--lib takes a source tree

A library is passed as the directory its source is in — a source root — and the compiler keeps what it builds from it in its own cache, which is never named directly. A path to a .syslib file is refused:

sysl: error: --lib takes the directory a library's source is in, and 'mylib.syslib' is a '.syslib' — a library is handed over as the tree it is written in, and the compiler keeps its own cache of what it compiled from one, which nobody names

A source tree that is a dependency’s package overrides that dependency. To build against a working copy of a package the manifest names, pass one flag and leave the manifest unchanged:

sysl build . --lib ../geom

If ../geom/sysl.hocon names the package geom and the project depends on github.com/e/geom, the checkout is compiled in its place — for that dependency and for any other package in the graph that depends on it — and the coordinate is never fetched, so the working copy can contain changes that are not yet published. A tree that merely contains a module a dependency also provides, without being that package, is refused as a collision. Packages § A source root stands in for the package it is has the rule.

--target, and cross targets under run

With no --target, a build targets the machine it runs on. If sysl has no registry entry for that machine, it says so and stops rather than guessing, because a wrong guess produces a module that looks correct and is not.

run executes what it builds, which only the current machine can do, so a cross target is refused before the build starts:

sysl: error: 'run' executes what it builds, and 'x86_64-linux' is not this machine — use 'sysl build --target x86_64-linux'

An unknown target name is answered with the list of known ones:

sysl: error: unknown target 'arm-linux' — sysl knows aarch64-macos, x86_64-macos, aarch64-linux, x86_64-linux, riscv64-linux, x86_64-windows, aarch64-android, aarch64-freestanding, x86_64-freestanding, riscv64-freestanding, thumb-freestanding, thumb-freestanding-softfp, thumb-freestanding-soft, thumbv6m-freestanding, thumbv7m-freestanding, thumbv7em-freestanding, thumbv7em-freestanding-soft, thumbv7em-freestanding-dp, riscv32-freestanding, wasm32-freestanding, wasm32-wasi, craft-freestanding, x86-linux

-v, --verbose

Reports what the build decided, on stderr, each line prefixed sysl:: the files it read, which standard module it used and how it obtained it, its search paths and allocator, and then every command line it passed to clang:

sysl: 1 source file(s) under hello.sysl
sysl:   read hello.sysl
sysl: standard module linked from ~/Library/Caches/sysl/<version>+…/std.syslib
sysl: allocator: malloc / free (the C default)
sysl: link: clang --target=arm64-apple-macosx -Wno-override-module -O1 -Wl,-dead_strip hello.ll ~/Library/Caches/sysl/<version>+…/std.syslib -o hello
wrote hello

Under --no-std-lib the third line is standard module compiled from source, not linked from an artifact, and a compile: line follows for each of the library’s C files. Each --lib, --link-path, --include-path and -D is reported too (library:, link path:, include path:, define:), before the allocator line, which names the package or project that chose the allocator where one did. A test suite links like any other build and reports the same lines. --verbose reports what the build did, not how long it took; for phase timings, use SYSL_TIMINGS=1.

--explain-escapes

Reports on stderr one line for each local array the compiler moved to the heap, and the view that required the move:

$ sysl build --explain-escapes tty.sysl
tty.sysl:31:12: 'buf' is promoted to the heap, because this view of it is returned

The position given is the view, not the declaration, because the view is the part that is hard to find by reading. When nothing was promoted, the flag says so explicitly, so you know it took effect. Memory explains what promotion is and when it happens.

After those lines comes one for each &T box, and each call of a factory, that is built on the heap rather than in its frame, at the construction or the call, with the first way out that put it there:

$ sysl build --explain-escapes main.sysl
main.sysl:12:23: a 'Counter' is boxed on the heap, because it is stored in 'kept' on line 14

--explain-drop-order

Reports on stderr one line for each local whose release changes place when sysl 0.8.0 adopts the interleaved drop order. In that order, leaving a block undoes it in reverse order of where each thing was written, so a defer runs after the locals declared below it are released. The current order runs every defer first. A local qualifies when it is declared below a defer or an errdefer in the same block and its type carries a count. The line says whether that release can run a destructor:

$ sysl build --explain-drop-order server.sysl
server.sysl:169: 'conn' (&Connection) is declared after the defer at line 167: leaving the block will release it before that defer runs, not after -- a release that can run Connection's Drop

It reads every body in the project’s own files, including bodies nothing calls. build, run, test, build-c, build-lib and emit-llvm all take it. A run or test that asks for it compiles instead of replaying a cached binary. When no block is affected, the flag says so. A local listed here may not actually be released by its block, for example one handed to a callee that keeps it, so read each line rather than counting them.

--explain-borrows

Reports on stderr one line for each function of the program’s own files that takes a parameter and answers a value: whether that answer is a place of a parameter — the parameter’s own storage, at the path given — or +0 from one — a value built on the spot every counted part of which is read out of the parameter — or, where it is neither, the first reason found:

$ sysl build --explain-borrows hashlife.sysl
hashlife.sysl:8:5: 'Node.quad' answers a place of 'self': self.kids.unwrap()
hashlife.sysl:23:5: 'Table.find' answers +0 from 'self': self.items.walk()[_]
hashlife.sysl:30:5: 'Table.take' answers +0 from 'self': self.items[_], but its body may write or release what it was handed
hashlife.sysl:36:1: 'make' is not borrowed: a reference made here, at 37:5

A path is written as the program reaches it: .field, [_] for an element, .Some for the payload a match binds, and .method() for a call into another module whose own answer is a place of its receiver. Two paths joined by | are two ways out. A function is answered for each instantiation of a generic, and the answer is worked out over the whole call graph, so a recursion settles on “not borrowed”. Where no body is in sight — a call through a trait object or a function value, an extern — the answer is “not borrowed”. A function whose answer is borrowed but whose body may write or release something (it calls, or writes, more than its own locals) says so; such a function is called the ordinary way, its answer carrying a count of its own.

Nothing in the build changes with the flag. The report is what the build decides from: a call to a function whose answer is a place or +0 is read where the answer lies, with no copy or count (a method’s answer borrowed from its receiver). When no function answers a borrow, the flag says so.

After the functions, once the program is lowered, it reports each local read out of storage — a var, val, arm binding or is binding one of whose values is read from a parameter or a local of the function’s top block: either that it holds no count, with the roots and the fields it is borrowed through, or that it is counted, with the first thing in its scope that could cut the chain (a local that walks storage takes no count):

list.sysl:18:22: 'x_tail' holds no count: borrowed from 'x' through Element.next, sysl.Option[&Element].Some.value
list.sysl:21:15: 'yt' holds no count: borrowed from 'y' through Element.next, sysl.Option[&Element].Some.value
walk.sysl:12:15: 'cur' is counted: 'clear' at 14:9 may write Node.next
walk.sysl:20:15: 'cur' is counted: the root 'l' is written at 22:13

A local’s line points at its first value: the initializer of a var or val, the subject a pattern binds out of. A generic function speaks for its first instance. A local each value of which arrives with a count — a call’s answer, a constant — gets no line.

A parameter the function assigns or calls itself with gets a line of the same kind, naming its function and pointing at the function’s declaration: it holds no count when every value it is given is borrowed from what the caller handed over; it is borrowed on entry and owned after the first self-call when every self-call hands it a value of its own making; otherwise it is counted, and the line says why:

list.sysl:30:1: 'go' parameter 'p' holds no count: borrowed from 'p' through Node.next, sysl.Option[&Node].Some.value
list.sysl:41:1: 'tail' parameter 'x' borrowed on entry; owned after the self-call at 43:9 (fresh arguments)
list.sysl:52:1: 'mix' parameter 'p' is counted: it is assigned a value with a count of its own at 56:13

It reports each argument read out of storage too — a field or an element read through a reference, handed to a direct call, or in a program’s own build to a call through a closure or a trait object (named as the program wrote it, f or w.look): either that it needs no count, since the call writes no field on its way, or that it takes one, with the first thing that could cut the chain between the read and the call’s return — the parameter being one the callee keeps, a field the callee or a later argument may write, code nobody can see (passing a reference to a call usually costs nothing):

list.sysl:32:28: argument 'x.unwrap().next' of 'tail' needs no count: 'tail' writes no field on its way
havlak.sysl:263:9: argument 'self.nodes[_]' of 'init_node' needs no count: 'init_node' writes no field on its way
dfs.sysl:24:37: argument 'outs[_]' of 'walk' takes a count: 'walk' keeps it
walk.sysl:9:10: argument 'h.next' of 'pair' takes a count: 'cut' at 9:18 may write Node.next
look.sysl:20:46: argument 'n.next' of 'w.look' takes a count: 'w.look' may write Node.next

An argument that is a local, a parameter or a call’s answer gets no line: it needs no count anyway.

--explain-checks

Reports on stderr which of the program’s run-time checks are still there once the optimizer has run: every bounds check, overflow check, division by zero, contract, constrained type’s range, enum conversion, and every call into a @track_caller body such as unwrap. The first line counts them; then each check that survives gets a line saying where it was written, what it checks, the function it survives in, and — for a subscript — why the hoist left it:

$ sysl build -O2 --explain-checks walk.sysl
3 of the 9 run-time checks in this program's files survive -O2
walk.sysl:4:36: bounds (index) survives in 'at'; no counted loop holds it, and the hoist considers no other
walk.sysl:7:16: bounds (index) survives in 'main', inlined from 'pick'; the hoist could not prove it in the loop at line 6: its index is not built with '+' and '-' from the loop's variable, literals, locals the loop leaves alone and the lengths of views it leaves alone
walk.sysl:10:7: call to 'must' survives in 'main'; the call was not inlined, so the check is made inside it

The lines are sorted by the function the check survives in. A check inlined into a caller is listed under the caller, with the function it was written in. A check the optimizer removed is not listed. The report reads the program as the build compiles it, at the build’s level and in the build’s codegen units. At -O0 nothing is optimized, so the report lists every check. Under --lto, the link optimizes again, which the report cannot see, and it says so.

Each check is found by the location it reports when it fails, not by the call that reports it. So the flag needs those locations, and a build with --no-bounds-locations gets one line saying so. With the flag, every check gets a location of its own: two checks written at one place, such as a division’s zero and its overflow, are listed apart. The text of each location is the same, so the program prints exactly what it did. The count covers every check the lowering laid down. A counted loop the hoist copies has its subscripts’ checks in its copy as written only, and that copy runs only when the test in front of the loop fails. build, run and emit-llvm take the flag, and a run that asks for it compiles instead of replaying a cached binary.

-O2 is written the way clang writes it

A short option normally takes its value as the next argument, but C compilers write the optimization flag joined to its level. sysl therefore rewrites -O2 into -O 2 before parsing options — only for that letter, and only when something follows it — so a bare -O still takes the next argument and --optimize is unaffected. The rewrite cannot reach the program’s own arguments, which have already been split off at the --.

Counting what a program does

Three environment variables build or run a program that counts something its output cannot show, and says the count on standard error as it exits. Each is a mode of build, run and test for a POSIX host — the report is a dprintf from an atexit — and asks for nothing elsewhere. Only the value 1 asks.

variableread whenwhat is said at exit
SYSL_COUNT_ALLOCS=1buildingsysl: N counted allocations still live at exit, only where N is not zero
SYSL_COUNT_BYTES=1running a program built with SYSL_COUNT_ALLOCS=1sysl: N bytes allocated in all — every allocation’s size added up, never subtracted
SYSL_COUNT_RETAINS=1buildingsysl: N retains, M releases (atomic A/B, views V/W), always

SYSL_COUNT_RETAINS counts every share of a counted value the runtime takes and gives back: a &T copied into a buffer, a closure’s capture, a view of a string or a slice kept. N and M are all of them; A/B are the atomic ones among them — a &sync T, a task, a string shared between threads — and V/W the views among them. A share of nothing — a static string’s — is not counted, nor is a weak reference’s own count (the share get takes is). A count starts once module storage is filled, so a module-level val adds nothing, and ends when the program exits: a program that calls exit reports what it still held, and one that panics aborts and reports nothing.

What it counts is what the compiler wrote, after its own elision of shares a value did not need: so the count is the same at every optimization level, and a change that makes a program take fewer shares shows up as a smaller number where the output and the timing say nothing:

import sysl.buf.{Buf, buf}

struct Node
    v: int

look(n: &Node) -> int = n.v

main()
    val a: &Node = Node(7)
    var xs: Buf[&Node] = buf()
    var t = 0

    for i in 0..<5
        xs.push(a)
        t += look(a)

    print(t)
35
$ SYSL_COUNT_RETAINS=1 sysl run nodes.sysl
sysl: 5 retains, 8 releases (atomic 0/0, views 0/1)
35

The five pushes are five retains; the five calls to look, which only reads its parameter, are none. The releases are those five, the node’s own, the buffer’s, and the buffer’s element storage — a view.

The counters are in every module of the program, the standard module’s prebuilt half among them, so the standard module’s artifact is built apart for a counted program, and the run cache keeps a counted binary under a key of its own. With nothing set, a build carries no counter and no report at all.

The standard module is never named

The compiled standard module lives in the compiler’s cache, so no flag points a build at one. Every command refuses --std-lib with the same message, before reading its own options:

sysl: error: --std-lib names a '.syslib', and a '.syslib' is this compiler's cache, which nobody names — to compile against another standard module, set SYSL_LIB to the root its source is in

Exit statuses

0success — and for test, every test that ran passed
1a compiler diagnostic, a driver error, or a failing test
2the command line did not parse — an unknown option, a missing value, no subcommand
the program’srun only, once the program has started

Every command prints a compiler diagnostic on standard error in the same form: the message, the location, the source line, and the offending part underlined beneath it. The underline is as wide as what the diagnostic is about — a name, a literal, or a whole expression where the expression is at fault — and stops at the end of the line, since only that one line is quoted.

error: 'b' of 'add' is int, but string was given
 --> hello.sysl:7:14
  |
7 | print(add(x, "two"))
  |              ^^^^^

A driver error — a problem around the compilation rather than inside it — is prefixed sysl: error: and written to standard error, which is why the messages quoted on this page carry that prefix and those on the language pages do not. The one exception is a command line that did not parse: it is reported as Error: … with the command’s usage below, as shown above.


Next: the tour, which uses run throughout.

Search

Esc
↑↓ to navigate ↵ to open Esc to close