Files
sakurac/docs/later.md
T
2026-10-28 22:13:49 -05:00

30 KiB

Later

What the built plans left for later, and the problems they found and didn't fix. Each item was checked against the rebuild and std on 2026-10-28, and is still open unless it says what's left of it. What was built since went, as did the records of what was built, which the CHANGELOGs keep.

Where the C compiler and the rebuild disagreed and the rebuild still falls short, the item is in inconsistencies.md instead. The plans not yet built keep their own "Later" lists: algorithms.md, benchmarks.md, freestanding.md, linear.md, logging.md, random.md and tui.md.

roadmap.md gives the order the plans are built in up to the language's freeze. It also says which items here must come before the freeze and which can wait.

The language

Lambdas that own what they use

A lambda only refers to the locals it uses. Whatever must outlive its frame is a functor written by hand, or a function holding one. Capture lists, or a func that owns what it captures, would let a lambda be returned or given to a thread. You set both aside when the memory plan was built ("for now"). A function holding such a lambda would own what it captured with nothing in function changed. It's the roadmap's last step, with directions that avoid a list in brackets (roadmap.md).

References and values: what the rule left

What the rule "where a value goes says what happens to it", built on 2026-10-22, left:

  • Only named functions are adapted. A lambda whose parameter types are written, as def(s: &string) given where def(&mut string) is asked, and a function value held in a variable, must still match. A lambda with its types left out takes them from where it goes.
  • A copy of T in generic code is refused only per instance. val x := v[i] in a generic over T copies, and an instance whose T closes reports it, as C++ would. A bound saying "closes nothing" would let the template report it once.
  • &&T still exists inside instances. Where a type parameter is a reference, &x of a T refers to the variable holding it, as the template means. Only generic code sees such a type; a function given where one is asked is adapted.
  • A reference variable is pointed elsewhere by a reference written as one, r = &y, as C++'s pointers are and its references aren't. Refusing it would match C++'s references, but chains walked by reassigning a reference need it.
  • An overloaded member named with its type's arguments, as box::<i64>::get, is the first overload, not the one the type expected chooses. Named without them, box::get chooses.
  • for x copies each element, which for a large struct costs a copy that for &x avoids. How often the optimizer removes it hasn't been measured; for a 256-byte struct at -O2, it did.

Joining text with +

string + strview, with += as an add_assign that appends in place, which a compound assignment calls since the rules were settled (roadmap step 5). The rebuild refuses + today: "string has no add taking a &strview, which + calls."

More operator traits

  • Traits for mixed operands, as scales<S> for a vector times a number, once programs show which ones they need.
  • A partial order for floats, so generic code can say what NaN does.
  • There is no bitwise trait, by decision: a program's own trait gives &, | and the shifts to generic code.

strview has no order

strview::compare takes the other view by value, so strview isn't ordered, and v < w of two views is refused: "strview has no order". So the note refusing s < v of a string and a view, which asks for s.view(), leads to a second refusal.

A trait's defaults reach only the types naming it

A method a trait writes a body for is its default, which a type may leave out. The rebuild counts a type as meeting the trait by its methods, whether or not it names the trait, but only one naming it gets the defaults. So a struct with only put passes where S: sink for a sink asking for put and giving done, and S is sink is true of it, and the instance then fails where the generic calls done: "plain has no field, property, or method done. (In finish<plain>)". Either the defaults should reach every type meeting the trait, or a type leaving a default out should meet the trait only by naming it. The first would let writable give a flush that does nothing, so flushable could go with if const S is flushable in std::io::writer.

Named constants without a type

const pi := 3.14 is an f64, and const k := 7 an i64, so val x: f32 = pi is refused, where the literal would fit. std::math's constants are f64 for that reason, and f32 code writes math::pi as f32.

type_of(f)::name()

It doesn't parse: "Expected ) to close the arguments. Found ::." std::args works around it with generic helpers, as switched::<type_of(f)>(), is_command and shape_of.

A module named as a type it declares hides the type

A path's first name is a module's before a type's, so std::uri's uri::parse would look in the module. So std::regex, std::uri and std::version are std::text, std::net and std::semver. A rule reaching the type is a language addition that could come after the freeze.

Documentation as a reflection intrinsic

An intrinsic giving a declaration's #! comment would let std::args print a field's documentation as its help, rather than help = "..." repeating it. Only the language server reads those comments now.

Thread-local variables

@thread_local var, reached through the thread's record at gs:[offset].

128-bit integers

Their multiplication would serve fma and hashing.

Tracking moved locals

A local moved on every path needn't be closed at all, and reading one after a move could be an error. The checker doesn't track moves: a moved-from value is left zeroed and closed as usual.

equatable and hashable for void

They'd take methods the compiler gives, and nothing needs them yet. So dict<void, V> fails at hash<void> and equals<void>.

Contracts

What the contracts plan left for later:

  • Contracts on a trait's methods, checked for every type implementing it.
  • old of what closes, copied and closed after the check.
  • A type's invariant, checked after each of its pub methods.
  • The checker proving contracts: warning where one always fails, and leaving out one it proved, from what it already knows of bounds.
  • Levels, as --contracts expects, keeping pre-conditions only.

Calling C

What the ffi plan left for later:

  • C's variables, as errno or environ: a var in an extern section is a Sakura global of its own.
  • Variadic C functions, as printf. A parameter written i64... passes a span.
  • A C name that isn't a Sakura name, as a keyword: a name given to the symbol apart from the declaration's.
  • The machine calling C on Linux, with System V's convention, so a program calling C runs without being built. It stops where it reaches one, or a C function's address: "Program uses a construct that cannot be compiled."
  • system::macos and system::freebsd. macOS needs libSystem and a Mach-O writer.

Warnings the checker misses

A lambda returned through a call

A lambda returned directly, or in a struct literal, is warned of: "The value returned refers to s, which ends as the function returns". Returned through a call, as return function::new(def() => ...) or return pass(def() => ...), it isn't. Calling it later reads a frame that's gone. run --checks misses it too, most of the time: the closure's frame is pushed where the ended frame was, so the address it reads lies within frames in use.

A thread handle outliving its closure's locals

A function that starts a thread whose closure updates one of its locals, and returns the handle, gets no warning, where returning the closure itself would. run reads a stale frame, and run --checks prints garbage.

compile_error at the call that made the instance

A compile_error is reported where it's written. In a generic, that's inside std, as std/serial/walk.sakura:45 for json::to_text of a type that isn't @serial, not the user's call. compile_error takes a place (at: site = call_site()), so a library can point at a declaration, but std's walk passes none, and the compiler doesn't note the call that made the instance.

The compiler

Small unions as values

A union of two or three words, as maybe<u64>, would be held as words and returned in rax, rdx and rcx, so a range's next gives its maybe in registers. It's returned in memory now. The iterators plan's numbers held without it.

Lambdas given to adapters

v.iter().filter(lambda).map(lambda).sum() costs 3 to 4 times what functors do: 565 to 599 ms against 144 to 190 ms over ten million elements at -O2 (tools/iterators.sakura). The adapter is built by 16-byte copies, and its lambdas are called through call_value, so they aren't inlined, even one whose function is known as a constant. Reading words through wide copies, or a type of each lambda, would fix it.

box within 10% of raw_allocate

The memory plan asked for it. tools/memory.sakura gives box 1.31 to 1.38 times raw_allocate. What's left:

  • walking a list through a maybe<&T> picks the next node with a select that the loop's exit also reads;
  • every move of a value that closes writes the zeroes its source is left with.

Atomics

  • lock add, lock or and the like where the result isn't used, as _ = hits.fetch_add(1), which is lock xadd. fetch_and, fetch_or and fetch_xor would lose their lock cmpxchg loops.
  • Two-word atomics through cmpxchg16b, for a pointer with a count beside it. The oldest x86-64 processors lack it.

What the vector work left

  • % of lanes is a loop over them, as no instruction divides integers.
  • The least and greatest of real lanes, and the product of integer ones, are loops. smallest and largest work real lanes from lane 0, as which NaN or zero they give depends on the order, which the instructions' pairs of lanes don't keep.
  • scatter writes a lane at a time. Only AVX-512 has an instruction for it.
  • 64 bytes, AVX-512's, were checked only by disassembling what's built, as this machine has no AVX-512. On one that has it, native's test vectors_of_64_bytes_give_the_same_bits_at_every_level works each operation with the instructions, and tests/programs/simd_lanes_agree_everywhere_2, built and run, does too; the corpus itself runs on the machine. Such a vector is held in its slot, never a register, and read a quarter at a time; a mask of one is a vector, and k1 holds it only within an operation. 64 bytes of 8-bit lanes aren't allowed, as their mask's bits wouldn't fit a u32. The least and greatest of real lanes go a half or a quarter at a time, and the sums across the lanes, shuffle, and changing the lanes' type or size a lane at a time.
  • A struct of a size not a multiple of 16, as three f32 fields, is built a field at a time: merging stores fills 16 bytes from a multiple of 16 only.
  • 32-byte vectors go through memory a half at a time in a function working several, as geometry's frustum test of eight planes as one f32x8 did: each select's and splat's result was stored whole and read back as two halves, and each splat was two shuffles where vbroadcastss is one. It ran no faster than a plane at a time, and in one build twice as slow, where two f32x4s run twice as fast, so geometry uses those.
  • A vector's lanes read as numbers, as vec3::dot adds its products' lanes, made geometry's rays two to three times as slow as the same dot worked a number at a time, though linear's bench of dot alone finds the two even. geometry works its dots a number at a time.

What the analyzer's tables left

What making the analyzer's tables smaller and its passes quicker left, as checking the compiler's own sources measured it:

  • Vectors made for each call checked. arg_kinds, try_candidate, the five vectors begin_inference makes, and check_args_bounds's copy of the parameters are made for each call, about 1% of checking. They nest, as checking an argument checks its calls, so a scratch column would need marks, as type_table::substitute's has.
  • Rows for nodes that have no results. A result table has a row for each node, but half are never written: statements, type names, and declarations. Numbering only the nodes checking gives a type would halve r_types, r_refs, and r_flags.
  • Evaluating what checking left. Lowering it, making an interpreter, and running it took 5.5% of checking the compiler, and wasn't looked into.
  • Words written a field at a time. zeroed_cells counts a word as written only where one store covers it whole, so a cell built field by field, of fields narrower than a word, is zeroed though every byte of it is written. Following 4-byte halves would catch most structs.

What @inline left

  • @inline on checker::unalias, a test of a type's flags and a call where it fails, made the compiler 312 KB larger across its 342 calls, about 900 bytes each, and ran no fewer cycles, so it isn't marked. What a copy takes at each call is worth seeing.

  • std's own helpers called in its loops over text aren't marked, std being a repository of its own: json's plain_stops and is_json_space, and yaml's comment_ends.

  • At -O0 a copy still writes each argument into its cell and reads it back, and each span a copy returns waits on the stores that built it, so a chain of copies waits on memory as a chain of calls does. Marked, span::sub and span::over, find_byte, find_last_byte and count_byte, and bytes8::upper and lower were slower at -O0 (find_byte at -O2 too), so they aren't. swar::load_last and u8::digit_value gained only at -O2, by 4%, so they aren't either.

aarch64

There's no aarch64 back end. Atomics would be ldar, stlr and ldaxr/stlxr loops or LSE there, which is why an atomic's order is a value as the program runs, and simd would be NEON.

The command's name

sakurac check --help says usage: sakura check, and a wrong option says "Try sakura build --help", the name the compiler had.

What --checks misses

A reference read only by interpolation isn't checked: val r := &v[k];, then v grows, then println($"{r}") prints a stale value, where val y: u64 = r is stopped. Nor is a view's element read after the memory it covers is released, as a span after raw_release or a vector's view after close, at every level; reading through the pointer itself is stopped. The README's account of --checks claims more than this.

It stops at a read of memory nothing wrote, but not of an undefined number the optimizer holds in a register rather than in memory, and not where formatting reads a struct's bytes, or == compares arrays' bytes.

Checked executables

build --checks makes the checks of a checked program, as indexes, and none of run --checks' of memory. A runtime with a shadow map, as AddressSanitizer has, would check an executable's references and pointers, and the bytes nothing wrote.

Guard pages for the stack

A page nothing may touch below each stack would report an overflow from the fault, and the prologue's compare with the stack's end could go. The rebuild already leaves that compare out of small leaf functions.

Overflow checks

Checked builds could stop where integer arithmetic overflows, for programs that ask for it. Today it wraps in every build, and math::checked_add and its kin are the way to know.

Fresh pages taken as zero

The compiler's result tables read zero as "nothing yet", so they grow by zeroed elements, a file at a time, and every byte is cleared. A vector grown into pages fresh from the system could take them as zero without clearing them, if raw_resize said which bytes it gave fresh. Only a vector's first allocation does that today.

Reading libraries

What the std plan left for later:

  • Files of other systems left unread. A section's when is decided once its file is parsed, so system/on_windows.sakura's 2,449 lines are parsed on Linux. The reader could decide a file's first when from its text, as it reads its first module line.
  • The checked core kept between runs. It's the same for every program, so the time checking it takes could be read from a file the compiler wrote, rather than checked again.
  • Checking only what's reached. Declarations nothing refers to would still be parsed, but not checked. All of std parsed with nothing declared took 37 ms, against 93 ms checked, so that's the most it could save over reading by reference. It matters for large libraries, and for core's 2,590 lines of containers.
  • core written into the compiler whole. It needs the compiler to take a file in while compiling, as an embed intrinsic, which it can't now.
  • An index of a library's modules, written by blossom where it fetches a package, if a library's folders ever grow too many to list.

Large blocks kept at one size

The runtime keeps up to 64 large blocks given back, 32 MB in all, but hands one out again only for as many bytes as it was, so the token and node vectors the lexer and parser trim to fit leave their old blocks resident, and so do the vectors that grew past them. Checking the compiler peaks at 48 MB resident where the analyzer's tables hold 28 MB.

A race checker in the machine

As ThreadSanitizer does. run --checks checks that memory is held, not who writes it when.

The machine interrupting waits

system has no signal to spare on the machine. While threads run, a futex wait without a time lasts 0.1 s and std's waits wait again, a read blocked forever isn't interrupted, and the first thread waits up to 3 s for the others as main ends. With a thread blocked reading, run takes about 3.7 s, where the executable ends at once.

std

function

core's function:

  • Converting where a function is expected, so val f: function<S> = functor; needs no function::new. The compiler would have to know the type by name, and the conversion allocates where the callable doesn't fit.
  • function::bound(&mut x, T::m), binding a method to a value.
  • More held in place, through a constant parameter for the buffer's size, for code that must never allocate. Callables of 24 bytes or fewer are held in place now.
  • An allocator for the box, once box takes one as the containers do.
  • Constants. A constant keeps the buffer's words but not the function a function value among them names, so function::new reaches its buffer through its address as a number, which refuses every constant function. A functor that holds no function value could be allowed.
  • C functions, which function holds, but no test covers: the machine can't take a C function's address.

Threads

  • A pool of threads taking tasks, and a parallel for. The compiler's own crew (compiler/workers.sakura) could seed one.
  • Read-write locks, semaphores and barriers. std::thread has a mutex, a condition, a channel and once.
  • Waiting on several channels at once.
  • Calling C from any thread, on Linux. Threads started by clone keep the first thread's fs, so libc's state for each thread, as malloc's caches and errno, is shared. Five threads calling malloc and free 200,000 times each abort in glibc every time, and nothing warns. Windows starts threads through CreateThread and is fine.
  • Reentrant console locks. A thread holding io::output_locked() that calls println waits forever, even with no other thread.
  • A thread given a value and giving one. spawn_with gives a handle<void>, so such a thread needs a closure, and a loop variable must be moved in by hand. Merging spawn and spawn_with into overloads waits on the checker inferring a closure's type through overloads, which it doesn't: "No overload of go takes these arguments."

Atomics and signals

  • The signals' waiting word as an atomic<u64>. Handlers would set it, dispatch would empty it with exchange, and the take_signals intrinsic would go.
  • Holding signals off for a stretch of code, as a guard over rt_sigprocmask.
  • Timers: alarm, and timers that repeat. signal::alarm exists, but nothing sets one.
  • What a signal says of itself, as who sent it or which child stopped. A handler is given only the signal.
  • Real-time signals, and rarer ones as SIGTTIN, SIGTTOU and SIGPROF.
  • Signals as a stream, through signalfd or a pipe, so poll wakes for them. system::watch and system::watched note a signal, but aren't a handle.
  • Chaining handlers: handle giving back the handler it replaced.

Processes

  • Waiting for whichever of several children stops first, and capturing several at once, for a build tool's jobs. Only system::wait(-1, ...) waits for any child.
  • child::send(signal), to ask a child to stop, and timeouts on wait. child has only kill. system::poll takes a timeout, but std::process doesn't use it.
  • The error merged into the output in order, as 2>&1, and io::file::duplicate.
  • Overlapped reads on Windows, in place of looking at each pipe with PeekNamedPipe and sleeping up to 10 ms between looks.
  • Starting faster with clone(CLONE_VM | CLONE_VFORK), for a large program starting many children.
  • Process groups and sessions, and a child that outlives the program.

Streams

  • Interpolation written straight into a stream, without a string made for each $"...". A language change.
  • Adapters: a tee, a writer that counts, a reader limited to a length, and compression.
  • Reads that don't wait, timeouts, and polling several readers. system::poll does it for handles, but nothing in std::io does.

Text

  • Vectors in more text functions. find_byte, and so index_of, contains, split and read_line, use vectors where they're held, as do memset, memcpy, memcmp and the JSON reader. strview::find, find_any, is_ascii, upper and lower, spans' last_index_of and count_of, and std::serial's is_utf8 read words only.
  • UTF-8 checked a word at a time past ASCII, as simdutf does. is_utf8 skips ASCII by words, then checks each sequence a byte at a time.
  • Hexadecimal and base64, encoded and decoded by words. std has neither.
  • Comparing text without regard to ASCII case, through lower of each word.
  • core::swar lanes of 16 and 32 bits, for UTF-16 and wider tables. It has bytes only.
  • Left a byte at a time, on measurement: trimming (0.76 to 0.93 times as fast by words), and YAML's plain scalars (0.82 to 0.97).

Reading the clock

On Linux, std::time reads the steady clock with a system call, about 211 ns in an executable, where glibc reads it through the vDSO in 25 ns. Programs that time small work, and the benchmarks plan, pay it on every read.

Parsing numbers

integer::parse::<T> checks only the 64-bit limits, so a narrower T wraps: integer::parse::<u8>("300") is 44, and parse::<i8>("-200") is 56. Positive values stop at i64's largest, so std::args reads a u64 with a reader of its own (whole_of, signed_within and unsigned_within).

JSON, YAML and std::serial

  • Fixed arrays, T[n], aren't written or read by the walk, which refuses a type holding one. A type holding one gives a form of its own.
  • The walk over trait references. It's encode<T>(value, out: &mut encoder), one indirect call for each value, because a trait couldn't be a type argument then. That works now (feed<E>(out: E) where E: sink given a &mut sink), so the walk could be generic over its encoder.
  • Faster float printing, as Ryu. About 45% of writing JSON, 0.46 s for a 4.3 MB document, was the runtime's put_float, exact but working in big integers of 128 limbs. Every program printing floats pays it.
  • JSON Pointer, as doc.find("/params/position/line").
  • Trees that can be changed, for JSON and YAML. Both are read-only arrays of 16-byte nodes.
  • A field read as a json::value. json::value is written but not read, so the language server reads method first, then decodes params.
  • YAML: comments kept when read and written again; a writer of comments, flow style and anchors for repeated values; tags in typed values, as !circle {radius: 1}; and keys that are collections, which serial::encoder can't write.

Iterators

  • Splitting a sized iterator across threads.
  • chunks(n) and windows(n) of a view, giving views.
  • Iterators that write, as fill and copy_into, which the algorithms plan has as methods of slices.

Math

  • erf, gamma, lgamma, and the Bessel functions.
  • Correctly rounded versions, from CORE-MATH, for programs that need results never off by a rounding. MIT-licensed, but several times larger and slower than musl's.

Time

  • TZ, and TZDIR beyond Windows, read from the environment. On Linux, zones come from /usr/share/zoneinfo and /etc/localtime only. process::variable exists, so nothing blocks it.
  • Formats written with a pattern, as strftime's.
  • Windows zones by name, and the history of its local zone, from the registry or ICU. zone::local() there is the current rule only.
  • Leap seconds. A day is 86,400 seconds, and a second of 60 is out_of_range.

Arguments

  • std::testing reading its arguments through std::args. tester::run compares --only and --here by hand, since std::args would refuse the other arguments tests are run with.
  • Environment variables as fallbacks, as @option{ env = "SAKURA_TARGET" } for --target. process::variable exists, so nothing blocks it.
  • Suggestions for a misspelled option: "--levle is not an option; did you mean --level?"
  • Shell completion scripts written from the declarations.
  • Response files, @arguments.txt, for lists longer than a system allows.
  • Help wrapped to the terminal's width. It aligns its columns but never wraps.
  • The rest of the declarations checked while compiling. The marks' shapes and types are compile_errors, but duplicate names, duplicate short letters, which letters may be short names, and count of an integer are checked as each run starts. Since 2026-10-28 a compile_error a running condition chooses is reported, so they could be too.

core

  • A core for places with no heap, with the containers in a child of their own.
  • Lang items by attribute, as @lang("string"), rather than by name in the module core, so core could be split into modules of its own.

A failing test

readers_and_writers_close_what_they_own, of std::io, fails natively and on the machine: it expects 4 bytes written once closed. It failed with the compiler from before 2026-10-27 too.

blossom

  • The blossom plan's "Later, where wanted": more install tags than !include, tags for the build and test pipelines, versions resolved from ranges with a lock file, blossom new, compiling in blossom's own process, several projects built as one, and an index of packages by gpid/name.
  • Not run here: an rpm package, as there's no rpmbuild, though the spec it's built from is written and the missing tool said; a Debian package with dpkg, which isn't here either, though ar and tar read it back whole; and blossom on Windows, which was only built and checked. Its tests of its commands run git, sh and tar, so they're Linux's.
  • Building the compiler is checked by hand, not by a test. A test would take minutes.
  • zip files are stored, not compressed, until std has deflate.

Debugging information

  • No Windows debugger has read a PDB file. Visual Studio or WinDbg, stopping in a program built with -g, would show whether they take what LLVM's tools do.
  • What CodeView can't say of a variable: a value known as a constant over a range, which the DWARF gives, isn't named there; a part of a variable of several words held in the frame isn't either; and a variable whose frame slot holds the address of its object of the heap is shown as a pointer to it.
  • Every function's type is void () in the PDB file, as the DWARF gives none, and a debugger can't call them anyway.
  • Names aren't qualified. Two functions of one name in different modules, as two write_alls, are told apart by their IDs, but a debugger finding one by name finds both, as with the DWARF and the symbol tables.
  • Globals aren't described, in the PDB file or the DWARF.
  • binary::amd64's absolute meets std::io's, so a file importing both, as native/native.sakura does, writes amd64::absolute.

Tests not written

  • Writing to the program's own output once nothing reads it. A test can't make its own output a closed pipe. The machine stops with status 141, as it should.
  • A read from a real pipe interrupted by a signal. io::pipe::open() exists, but the test reads a stream made to look interrupted.
  • function holding a C function. See function.
  • Windows, since extern and system. Its sources and std's tests were checked for windows-x86_64, and the compiler's import table matched the seed's. None of it was run, and neither was the machine's test of ucrtbase.dll (tests/machine/machine.sakura): there's no Windows or Wine here. Since core the same holds, with CreateDirectoryW imported too, for the language server's copy of the built-in text.
  • --deps from the compiler's own tests. Only blossom's tests run sakurac with it, through blossom.
  • Native tests reading by reference. The native backend's tests build their programs over every file of core, system, the runtime and std, passing over std's tests, as the compiler did before the std plan, so they take minutes where they took seconds.