Repository navigation
Flag 0.4.0 - #2
Merged
Merged
Conversation
…es its result Thread[T] is the type of a running call, done(t) asks without waiting, and main waits for every thread before the program ends. A context is state of each thread; a variable at the root of a file, name: T = value, is shared by all of them. core has Lock, Channel and cores; its table of files and the arguments of os are file variables behind a lock, and print still allocates nothing. -memory follows a Thread like a block of the heap. QBE: thread data on amd64_win, and the address of a thread datum is computed once per function on Apple and Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
&str, &list and &map take a fourth word, arena, and grow in the arena where
they live; arena(a, []) and arena(a, {}) build the literal there with the
type of the place where it lands. clear(a) keeps the blocks for the next
frame, and the scratch memory of each thread is an Arena too. -memory knows
what lives in an arena: never a leak, used after free or clear of its arena,
freed by hand, and the arena itself never freed.
With threads: the take and give of a Lock are acquire and release, -memory
read any take of core as a piece of an arena and saw a leak in a struct
with a Lock. A thread frees its scratch arena when it ends, parallel of
arena(a, [...]) is an error, and an arena is not shared between threads
without a Lock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ters, constants in data A direct call to a function of 45 instructions or less is replaced by its body when the program is written, after -memory, and inline func does it for every call. QBE cuts a stack slot of 32 bytes or less whose address stays in the function into its pieces, so promote keeps them in registers. A constant whose value the compiler knows is kept once in read-only data, and text literals with the same text share theirs. With threads: a constant and a file variable are written to data by the same image of their value, so a file variable no longer drops the data of the constants and texts its value used, and an array of an enum is kept in data too. The call -memory sees at parallel f(x) is never inlined, it ran in both threads, and the function a thread starts with is kept alive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g writes DWARF After its place a runtime error writes the functions of yours that led to it, read from the frame pointers with a table of the functions in the program. A crash says what happened and writes the chain too, a stack overflow included. -debug puts DWARF 4 in the program for gdb and lldb. With the rest: -debug inlines nothing and qbe -g keeps every slot whole, so -w goes. The table and the DWARF come from the functions listing writes, in that order. Each thread keeps its own stack for the crash handler, taken with malloc so a Windows program doesn't carry 64 KiB of thread data, and an error in a thread writes the chain of that thread. In the DWARF a context is thread-local and a file variable is global. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ros out of the macOS file, big frames not inlined - flag_frame gives the frame of its caller: its own is gone when it returns, and on arm64 trace read its locals there - QBE writes hlt as udf on arm64 and unimp on rv64, an illegal instruction like ud2, not a breakpoint the crash handler doesn't take - QBE puts thread data that starts at zero in __thread_bss on macOS - a function with more than 4 KiB of slots is not inlined on its own: on Windows main took the 3 MB of huge() in big_by_value and overflowed its stack - test.sh: on Windows a crash ends with its exception code, and the shell said it was a signal Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efore the parameters, loops - an untagged union lists its members in the DWARF, it listed itself and gdb recursed until it crashed - the first .loc of a function is the line of its declaration, and QBE writes it before the prologue and not again after it: a breakpoint in a function stopped before the parameters were in their slots - with -debug each block starts a row of the line table, so step comes back to the line of a loop on each turn - a struct or an enum you declare is also a typedef, so ptype Point works as in C - test.sh runs name.gdb in gdb where there is one; CI installs gdb on Linux and Windows Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ge, a missing cc and the unpacked library - a literal that gives its values in order puts its numbers, bools and enums smaller than 8 bytes together in words of 8 bytes, so a copy reads each word from one store and doesn't wait on store forwarding: json parse takes 4 % fewer cycles - test.sh finds the tests by what they expect, so a test with no files gives the usage, and name.env runs a copy of the compiler alone, the way it is installed, with that environment - tests for the usage, a missing input, overlay and cc, an output that cannot be written, a library that cannot be unpacked and one that is Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ength - a set of temporaries keeps only its words that are not zero, by their index, where the sets of each block had a bit for every temporary; spilling reuses two sets instead of making one at each instruction - zeroval stops before the first definition of the value, lca climbs from one side until it dominates the other, and bestbid jumps to the closest dominator in fewer loops: none of them walks a chain of elif as deep as it is - amd64 isel clears the entries of the temporaries a block uses, not the whole table QBE writes the same assembly. 20000 elif with a print each took 3.1 s and 1.9 GB and take 1.6 s and 0.4 GB; on a value known only at run time 5000 took 3.6 s and 1.8 GB, and 20000 take 2.8 s and 0.5 GB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gdb on Windows reads the end of a prologue from .pdata and takes a function without it for a leaf, so a breakpoint stopped before the parameters were in place and the frames above it were wrong. QBE writes .seh_proc, .seh_pushreg, .seh_setframe, .seh_stackalloc and .seh_endprologue for amd64_win, in the order of its prologue, as gcc does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ows says Thread 1 hit - chopnext took for granted that the end of a slot was cut, and when no access reached it it read past the array: AddressSanitizer saw it on every seed and target, and on macOS it was a Bus error building the seed. The assembly of the compiler is the same, and QBE with AddressSanitizer is clean on the three seeds for the six targets and on the IL of the 469 test programs - test.sh drops the "Thread 1 hit " that gdb on Windows writes before a breakpoint, where a program always has more than one thread Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…run by CI on Linux The read past an array in chop passed on Linux and broke the seed on macOS. ./build.sh sanitize builds QBE with -fsanitize=address,undefined and turns the three seeds into assembly for the six targets, with and without -g, and CI runs it on Linux. UBSan also stopped on alias.c, where QBE adds offsets with signed numbers that wrap, as it folds constants: QBE is built with -fwrapv, so C doesn't leave that undefined. The assembly of the compiler is the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…db calls, lines, errors - a field, an element, a slice or a union member of a constant keeps being a literal, so a pointer to it is a copy, as in 0.3: bump(POINTS[1]) wrote into read-only data and crashed - a function with more than 32 bytes of slots is not inlined on its own into a recursive one, each level took them: a walk of 60000 levels overflowed at 29119 - a function that takes or gives an aggregate is DW_CC_nocall: QBE passes them unlike C, and gdb called them with wrong values - elif, each case and the step of a for, where continue lands, have their own line in DWARF - a file variable named like a function is an error; the data of the compiler is $flag.const.N, $flag.str.N and $flag.sv.N, no function takes those names; a constant reads the constants it names, not a local that hides one; inline main in a module is fine; Channel[T, 0] has its own error - a function that reads flag_frame, panic, is never inlined - typedefs for the structs of modules and for aliases; arena messages point at the arena Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… finds the type Point In C an enumerator and a typedef share their names. With the enumerator Point of a union's tag and the typedef Point, gdb 12 took the typedef and the gdb of CI the enumerator, so ptype Point showed the tag. A member with data is (Point) in the enumeration; one with no data, like null, keeps its name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…emporaries, crashes told - try_lock: receive, flush, exit, panic and a crash write the streams that are free and leave the one another thread is writing; a thread stuck sending to a peer that doesn't read hung every read, exit, runtime error and crash - wait moves the scratch of the thread into the scratch of the waiter, so a result with temporaries, like the FsError of a read, lives as a temporary of a call - main waits for the threads that run alone before its defers, when the program starts any - a crash asks for no memory and waits for no lock, so one inside malloc is told; the chain starts from the return address of a leaf of C; one thread tells and the others wait, with no SA_RESETHAND, so two crashes at once don't dump core and two reports don't mix - done of a thread never started has its error; close marks the stream closed under io.lock before it gives back the descriptor - docs: random starts the same in each thread, free of an Arena on the heap, the stack of the main thread on Windows, a &map in an arena doesn't grow in its place Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ose of two With the runtime fixes print_line became small enough to be inlined into main, and its slot of 16 bytes, whose address goes to a call, was the same slot as the V of the loop of structs.flg: chop kept it whole and the loop took 1.20 G instructions instead of 0.60 G. A pooled slot belongs to one callee now. The probes are as before and the build takes 1 % more instructions than before the review fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inear, latent bugs - a function whose frame can go past a page touches each page as it lowers the stack, on amd64, arm64 and rv64, so a big frame stops at the guard and never writes over the stack of another thread; on Windows it replaces ___chkstk_ms - amd64_win saves the registers with mov under rbp after it sets the frame, so the unwinder finds rbx, rsi, rdi, r12-r15 and xmm6-xmm15, and keeps xmm6-xmm15 as the ABI asks: a callback of Flag clobbered the floats of the C that called it - the address of thread data goes at the start of the function, so sel0 and sel1 stay together: selsel aborted on Windows and macOS x86_64 - the fixed points of chop are a work list and phiins no longer walks the whole function for each temporary: 3000 struct copies in a row compile in 0.15 s, they took 1.1 s; the build takes 3.9 % fewer instructions - phieq compares the class, promote keeps the sign of loadsw, load.c masks a narrow store, the bounds check of chop doesn't overflow, coalesce has no undefined shift, the zeros of chop go after the pars, tlv_get_addr is called with the stack aligned in a leaf on macOS - the CFI of -g says where the saved registers are Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… copies in use, fewer false warnings - a temporary given to parallel or sent through a channel warns when its with scratch() may release it while a thread still uses it, unless the thread is waited inside it; a result lives until the with scratch() around its wait - a pointer to a local that leaves with a thread that runs alone warns outside main, which waits for its threads now; so does a Thread with one sent through a channel - copying an Arena, a Lock or a Channel that is in use warns, also inside a struct or an element, and passing one by value to your function always does; a copy at zero doesn't - send gives what the value owns, not its views, the arena word or a pointer inside a block; the cells of an array stay apart from the fields after it; a list of threads waited in a loop doesn't warn - the warnings name the fields you wrote, free cannot release level.boss, it lives in level.arena, and a second wait says wait cannot release t Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gen gives a slot of temporaries back after a statement and uses it again, and -memory named the slot once, after the first value it held: print(s) warned about t, whose wait had filled the slot before. A copy into a slot that is not a variable gives it the name of what it copies, in the pass that names the temporaries and as the checker walks; a variable keeps its name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Flag 0.4.0: threads, arenas, small functions and structs that cost what they cost in C, and a program that fails says the chain of calls that led there.
The full list is in
CHANGELOG.mdunder 0.4.0. The main points:parallel f(x)gives aThread[T]andwait tgives its result. AlsoLock,Channel[T, N],cores(), a context per thread, and variables at the root of a fileArenaandarena(a, v), which builds values, text, lists and maps in the arena.free(a)andclear(a)release everything at once, and-memoryknows arenasinline func, small structs live in registers, known constants are kept in the data of the program, and literals write their small values a word at a time-debugwrites DWARF for gdb and lldbA review of this PR found 23 problems, all fixed or documented here, each with a test. Checks:
./build.sh(stage 2 and stage 3 emit the same QBE),./build.sh sanitize(QBE with AddressSanitizer and UBSan) and./test.sh build/flagcwith 992 tests, on Linux, macOS and Windows in CI, with gdb tests on Linux and Windows.🤖 Generated with Claude Code