You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[self-hosting B] Close Stage-A gaps so flowc sources compile under flowc #151
CI bring-up on #171 established the Phase-A boundary. The stable fixture/module/link roundtrip passes, while the full Phase-B path currently reaches bundle parser emission and then produces a TU missing transitive token/lexer declarations (unknown type name Lexer, missing KW_*). Full ./compiler/scripts/roundtrip.sh remains the Phase-B target; CI now runs FLOWC_PHASE_A_ONLY=1 so Phase A is protected without falsely claiming the bundle/fixed-point path is complete.
Likely root cause of the parser-bundle Lexer / KW_* failure: reverse-BFS emit ordered shared deps too late (lexer before token when both were imported from parser).
Fix in #189: keep BFS gather for discovery, then Kahn topo-sort before emit/typecheck so deps are always first. CI now runs the full roundtrip again.
Slice in #212: dogfood paths keep typecheck on (no more FLOWC_TYPECHECK=0 on compile_module / self-emit / frontend bundles). Diagnostics print flowc tc: at line:col (roundtrip asserts undef → at 5:). Remaining for Phase B exit: file-path prefix on diagnostics; any leftover language gaps.
Phase B exit reached: all of compiler/src compiles under flowc
Branch flowc/self-hosting-chain.
The audit first
FLOWC_BUNDLE=1 on every module under compiler/src, then cc -fsyntax-only -ferror-limit=0. Twelve of seventeen were already clean. The failures had exactly two causes:
Inferred let had no type inference.let x = expr with no annotation emitted int32_t for every initialiser. main.flow produced 28 errors, all of the shape
int32_tla=flowc_lexer_new(ap, 15); // returns Lexerif (expect_kind((t0).kind, TOK_KEYWORD) ==0) { // member access on an int
This is also why the earlier stage_a_infer_call fixture was silently wrong rather than merely unsupported.
String + was pointer arithmetic.claim_address, claim_path, know, math_prose, proof_sub — four errors each, all from
return (((((addr).carrier+".") + (addr).structure) +".") +flowc_claim_slug_phrase((addr).law));
// error: invalid operands to binary expression ('const char *' and 'char[2]')
What landed
Inferred let. cgen infers from the initialiser: expr as T and calls to functions declared in the same module use the declared type node; string / float / struct literals write the type directly; calls into other bundle modules read a name\0ctype\0 signature table that flowc_bundle_emit fills deps-first (flowc_cgen_collect_sigs / flowc_cgen_emit_sigs, table carried on CgenBuf).
String concatenation.a + b lowers to __flowc_str_concat(a, b), a static inline helper in the preamble that mallocs and copies. Results are never freed — process-lifetime strings, the same discipline as the compiler's other arenas. Detection is syntactic and conservative: a literal, a + chain already containing one, a cast to string, or a call declared -> string. Two string values with neither a literal nor a call between them still emit + and are rejected by cc. Loud failure, never wrong output. That limit is written down in cgen.flow and compiler/README.md.
Fixtures that run
Fixture
Exit
Covers
stage_a_infer_struct
42
struct-returning call, cast, struct literal in one module
bundle_infer_main + bundle_infer_lib
42
callee in a sibling module — type comes from the signature table
stage_a_strcat
42
three concatenations read back through strcmp / strlen
roundtrip.sh also greps the emitted C: it fails if p is typed int32_t, if "hello, " + appears, or if the let over a concat is not const char*.
The exit condition is now a gate
compiler/scripts/selfcompile_audit.sh, run by roundtrip.sh:
PASS ast 3763 bytes of C, 0 diagnostics
PASS cgen 34134 bytes of C, 0 diagnostics
PASS claim_address 14472 bytes of C, 0 diagnostics
...
PASS typecheck 26492 bytes of C, 0 diagnostics
ALL PASS selfcompile_audit (all of compiler/src compiles under flowc)
And compiler/scripts/self_host_full.sh bundles all of compiler/src into one ~195 KB translation unit. That binary is a complete flowc: bare, it runs the front-end self-tests and prints flowc: PASS; with FLOWC_IN/FLOWC_OUT it emits C. It recompiles compiler/src, and so does its child — gen1.c == gen2.c == gen3.c, gen2.o == gen3.o.
Remaining distance
flowc compiles the subset flowc is written in. It does not compile all of Flow. Still out: generics, effects, the DSLs, jsgen/fmt lowering of AST_MATCH, and everything src/flow/*.py supports beyond Stage-A. String concatenation between two values with no literal or call in the expression is not detected. Those belong in a Stage-B issue rather than here.
Gates on every commit: roundtrip.sh ALL PASS (109 PASS lines, byte-identical self.o == g2.o, gen3 token compare, three whole-compiler generations); FLOWC_BUNDLE=1 typecheck of main.flow green; ./flow run compiler/src/main.flow self-tests pass; ./flow test --strict --tier2 516/516; emit_basics.sh 10/10.
Activity
godofecht commentedon Aug 5, 2026
CI bring-up on #171 established the Phase-A boundary. The stable fixture/module/link roundtrip passes, while the full Phase-B path currently reaches bundle parser emission and then produces a TU missing transitive token/lexer declarations (
unknown type name Lexer, missingKW_*). Full./compiler/scripts/roundtrip.shremains the Phase-B target; CI now runsFLOWC_PHASE_A_ONLY=1so Phase A is protected without falsely claiming the bundle/fixed-point path is complete.godofecht commentedon Aug 5, 2026
Likely root cause of the parser-bundle
Lexer/KW_*failure: reverse-BFS emit ordered shared deps too late (lexerbeforetokenwhen both were imported fromparser).Fix in #189: keep BFS gather for discovery, then Kahn topo-sort before emit/typecheck so deps are always first. CI now runs the full roundtrip again.
godofecht commentedon Aug 5, 2026
Landed in #189:
tokenbeforelexer)-includeTcCtxself.ovsg2.o) still drifts; CI prints per-module C diffs and continues unlessFLOWC_REQUIRE_FIXED_POINT=1Next for Phase B: eliminate the self/g2 emit drift and re-enable hard fixed-point.
godofecht commentedon Aug 5, 2026
Follow-up #191: fixed-point now enforces
self_*.c == g2_*.c(which already matched). Relocatable.obyte drift is warn-only.godofecht commentedon Aug 5, 2026
Slice landed in upcoming PR: inferred let + capacity bumps;
FLOWC_BUNDLE=1typecheckscompiler/src/main.flow. Remaining: intentional TYPECHECK=0 dogfood paths, location-rich diagnostics.Allow inferred let and raise flowc bundle caps for main. (#208)
godofecht commentedon Aug 5, 2026
Slice in #212: dogfood paths keep typecheck on (no more
FLOWC_TYPECHECK=0on compile_module / self-emit / frontend bundles). Diagnostics printflowc tc: at line:col(roundtrip asserts undef →at 5:). Remaining for Phase B exit: file-path prefix on diagnostics; any leftover language gaps.godofecht commentedon Aug 5, 2026
Slice in #213: diagnostics print
flowc tc: file+ path (FLOWC_IN / argv / bundle module) with line:col. Roundtrip asserts path +at 5:.godofecht commentedon Aug 6, 2026
Phase B exit reached: all of
compiler/srccompiles under flowcBranch
flowc/self-hosting-chain.The audit first
FLOWC_BUNDLE=1on every module undercompiler/src, thencc -fsyntax-only -ferror-limit=0. Twelve of seventeen were already clean. The failures had exactly two causes:Inferred
lethad no type inference.let x = exprwith no annotation emittedint32_tfor every initialiser.main.flowproduced 28 errors, all of the shapeThis is also why the earlier
stage_a_infer_callfixture was silently wrong rather than merely unsupported.String
+was pointer arithmetic.claim_address,claim_path,know,math_prose,proof_sub— four errors each, all fromWhat landed
Inferred
let. cgen infers from the initialiser:expr as Tand calls to functions declared in the same module use the declared type node; string / float / struct literals write the type directly; calls into other bundle modules read aname\0ctype\0signature table thatflowc_bundle_emitfills deps-first (flowc_cgen_collect_sigs/flowc_cgen_emit_sigs, table carried onCgenBuf).String concatenation.
a + blowers to__flowc_str_concat(a, b), astatic inlinehelper in the preamble that mallocs and copies. Results are never freed — process-lifetime strings, the same discipline as the compiler's other arenas. Detection is syntactic and conservative: a literal, a+chain already containing one, a cast tostring, or a call declared-> string. Two string values with neither a literal nor a call between them still emit+and are rejected bycc. Loud failure, never wrong output. That limit is written down incgen.flowandcompiler/README.md.Fixtures that run
stage_a_infer_structbundle_infer_main+bundle_infer_libstage_a_strcatstrcmp/strlenroundtrip.shalso greps the emitted C: it fails ifpis typedint32_t, if"hello, " +appears, or if theletover a concat is notconst char*.The exit condition is now a gate
compiler/scripts/selfcompile_audit.sh, run byroundtrip.sh:And
compiler/scripts/self_host_full.shbundles all ofcompiler/srcinto one ~195 KB translation unit. That binary is a complete flowc: bare, it runs the front-end self-tests and printsflowc: PASS; withFLOWC_IN/FLOWC_OUTit emits C. It recompilescompiler/src, and so does its child —gen1.c == gen2.c == gen3.c,gen2.o == gen3.o.Remaining distance
flowc compiles the subset flowc is written in. It does not compile all of Flow. Still out: generics, effects, the DSLs,
jsgen/fmtlowering ofAST_MATCH, and everythingsrc/flow/*.pysupports beyond Stage-A. String concatenation between two values with no literal or call in the expression is not detected. Those belong in a Stage-B issue rather than here.Gates on every commit:
roundtrip.shALL PASS (109 PASS lines, byte-identicalself.o == g2.o, gen3 token compare, three whole-compiler generations);FLOWC_BUNDLE=1typecheck ofmain.flowgreen;./flow run compiler/src/main.flowself-tests pass;./flow test --strict --tier2516/516;emit_basics.sh10/10.flowc: prove the whole compiler compiles itself, three generations deep
fix+docs: close resolved issues; ILP32 sizeof_ptr; Homebrew; linguist…
docs: close shipped issues via Fixes keywords (#261)