Compiler options

Every flag accepted by python3 main.py <file.tryc> [flags], grouped by what it touches. Flags that change the runtime are baked into the assembled runtime object and become part of its cache name, so switching them never reuses a stale std_foo.*.o. The code generator is LLVM: the IR is optimised with opt -O2, compiled with llc and linked with clang.

python3 main.py program.tryc -o program

Output and inspection

FlagMeaning
-o <path>Name and location of the executable. The intermediate files (.i, .ll, .opt.ll, .o) are always written next to the source.
--dbiRun only the precompiler and show the .i file it produced (includes resolved, macros expanded, inline def bodies copied). The first thing to look at when a macro or an include does not do what you expect.
--keep-scratchKeep the per-process scratch assembly files that the final assembly %includes, for when something outside the compiler needs to reassemble that file later.
--first_runInstall the toolchain dependencies with the system package manager.

Code generation

FlagMeaning
--target <system-arch>The system and architecture to compile for; the default is the current machine. linux-x86_64, windows-x86_64 (a .exe, linked with lld-link, Win64 calling convention) and linux-aarch64. The compiler predefines the target's macros (__unix__/__linux__ or _WIN32/_WIN64, __x86_64__ or __aarch64__). From a machine of another architecture the program is linked with lld; an aarch64 binary built on x86_64 runs under qemu-aarch64. libstd works on aarch64 too: every Linux back end has an aarch64 version (system calls with svc; open, stat, access, dup2, pipe, readlink and fork, which aarch64 does not have, go through openat, newfstatat, faccessat, dup3, pipe2, readlinkat and clone). A module with libextern (sqlite3, mysql, vulkan, xlib) needs the aarch64 build of its library and of libc, looked up in /usr/lib/aarch64-linux-gnu, /lib/aarch64-linux-gnu and /usr/aarch64-linux-gnu/lib. With TRYC_TEST_EXTRA_ARGS="--target linux-aarch64" the test runners build for aarch64 and run the binaries under qemu-aarch64.
--llvm-staticIf the program declares libextern on a libLLVM*.so (the self-hosted compiler does, to run LLVM in-process), replace the shared library with the static archives of the target architecture's component (x86 or aarch64) and of passes and irreader from llvm-config --link-static (the llvm-config of the toolchain that resolved libLLVM.so, see FFI). Loading libLLVM.so costs about 12 ms per process start (350,000 relocations, 8 MB of .data.rel.ro copied on write, 590 constructors); a static non-PIE binary has none of that. TryC symbols that collide with libc/libstdc++ exports (strlen, memcpy, open, ...) are renamed tryc__name with objcopy so LLVM keeps using its own, and a small C glue object provides _start (running .init_array, which nobody else does without libc) and __dso_handle. Cost: about 46 MB on disk.

Memory and runtime

FlagMeaning
--bss-size NNumber of blocks in chunk 0 of the arena (default 4096 = 2 MB with 512-byte blocks). Without --noheap it is also the size of every chunk the pool maps when the current one is full, and it sizes alloc_log and the checkpoint stack: how many allocations can be alive at the same time, not how many bytes in total (both grow through mmap when needed).
--block-size NBytes per arena block (default 512, a power of two). Every allocation occupies a whole number of blocks: a 40-byte string kept alive still costs a block. Smaller blocks reduce memory (64-byte blocks cut the self-hosted compiler's RSS from 72 to 54 MB) but the bitmap scans cost the same, so wall time does not change.
--hugepagesAsk the kernel for transparent huge pages (2 MB, madvise(MADV_HUGEPAGE)) on the three large BSS buffers of the runtime: the allocation hash table (8 MB) and chunk 0 of the arena and of the string-builder pool (2 MB each). Worth it only for programs that allocate a lot (the self-hosted compiler: page faults 5,201 → 153, −9% time); a hello world pays the zeroing of whole 2 MB pages instead (0.2 → 1.4 ms), hence opt-in.
--noheapThe program never uses the heap: no mmap/munmap is ever emitted, every allocation (new, string concatenation, buffers) comes from the fixed BSS pool sized by --bss-size, and running out of it is a fatal error rather than a growth. raw_alloc()/raw_free() (used by libstd/thread and libstd/process) are refused. For targets where memory syscalls do not exist yet: a kernel in its first instructions.
--nosyscallThe program never executes a syscall instruction, explicitly or implicitly: _start no longer installs the SIGSEGV handler (sigaction/sigaltstack) and ends with a cli; hlt loop instead of exit_group. Only for freestanding ring-0 targets: hlt is privileged and would #GP in a normal Linux process. Every function gets noredzone and the runtime is linked in its nosyscall variant (built with -mno-red-zone and the portable vector code instead of AVX2): without an operating system an interrupt arrives on the stack of the code it interrupts, and the CPU writes its frame over the 128 bytes below rsp that the System V ABI otherwise lets a function use without reserving them. Independent from --noheap; the two combine for a real bare-metal target.
--linker-script FILELink with a GNU ld script (-Wl,-T): the script decides addresses, section order and output format. For a freestanding target such as the kernel in kernel/, loaded by its bootloader at a fixed physical address (its linker.ld puts a small header first, with the address of _start and the bounds of .bss, which the bootloader zeroes). Not on Windows: lld-link does not read GNU scripts.
--no_stdlibDo not make the standard library available (no #include <libstd/...>). Useful for kernel code.
--no_startfileDo not emit the _start procedure; the program supplies its own entry point and declares the runtime globals as extern.

Verification

FlagMeaning
--check-arenaBuild against the verification runtime (-D CHECK_ARENA when assembling the runtime): every allocation lives on pages of its own with canaries in front of it and after it, freed pages become inaccessible and are never reused while in quarantine. A use-after-free or an overflow becomes a SIGSEGV with a report naming the allocation, the function that allocated it and the one that freed it; a double free or the promotion of a freed pointer aborts with exit code 134. At exit (also when main simply returns) it checks the canaries once more and lists on stderr the allocations still pinned, grouped by the place that pinned them. About 7× slower and memory hungry: for tests only. Incompatible with --noheap. See Memory safety.
--legacy-castsAccept pointer-to-integer, integer-to-pointer and as ptr T casts outside unsafe:, and a long where a ref is expected, for a source not yet migrated to ref. A transition flag: the casts still pin as before, but nothing is checked.
--check-arena-guardLike --check-arena plus a PROT_NONE guard page after every allocation, so that even a read past the end faults immediately. Two kernel VMAs per live allocation: programs with many live allocations need a higher vm.max_map_count.

Environment variables

VariableMeaning
TRYC_TEST_EXTRA_ARGSExtra flags appended to every build made by the two test suites (test_llvm.py, test_automa.py), e.g. "--check-arena".
TRYC_DEBUG_SCOPE=fn1,fn2Print why a loop or a function of the listed names needs (or does not need) its own arena scope, statement by statement. See scope elision.

Runtime build-time constants

A few knobs are NASM %defines in the runtime source, all under %ifndef so they can be overridden with -D when assembling the runtime by hand:

ConstantDefaultMeaning
SINGLE_BLOCK_SIZE_HEAP_BSS512Block size (--block-size).
TOTAL_BLOCKS4096Blocks per chunk (--bss-size; always injected by the compiler).
RT_HASH_BITS20Maximum size of the allocation lookup table (220 slots, 8 MB reserved in .bss).
RT_HASH_MIN_BITS16Size the lookup table starts at (216 slots, 512 KB); it doubles when more than one slot in eight is live.
SCOPE_CKPT_DEPTH16384Maximum number of simultaneously open scopes (a runaway recursion hits this first).
MAX_POOL_CHUNKS4096Maximum number of mapped chunks.
BT_STACK_DEPTH500Depth of the function history printed in crash reports.
CHECK_QUARANTINE, CHECK_QUARANTINE_PAGES16384, 16384Verification runtime: how many freed ranges (and pages, 64 MB) stay protected before being recycled.
POOL_FREE_LISToffEnable the free-run list in the pool allocator (measured slower than the next-fit hint, kept for experiments).