Skip to content

selfhost: restore the C backend features #1027 dropped, in flowc - #1058

Merged
godofecht merged 48 commits into
selfhost/retire-python-c-hostfrom
selfhost/restore-c-features
Sep 29, 2026
Merged

godofecht merged 48 commits into
selfhost/retire-python-c-hostfrom
selfhost/restore-c-features

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Restores in flowc the C backend features that #1027 dropped, and fixes the flowc bugs #1027 found. This must merge together with #1027, or be merged into its branch (selfhost/retire-python-c-host) before #1027 merges. It is based on that branch and also merges origin/main (the #1025 squash).

Features restored

Feature Issue Evidence
@inline, @always_inline, @noinline, @target("...") #1028 Prototypes and definitions match the Python host (static inline, extern inline for main, exported, @flow_api and library units, validated target). Goldens function_attributes*.
@only / @guard build-mode guards #1029 A guarded function whose mode is off is dropped, as on Python. test_only_guard, goldens only_guard*.
Vectorize pragmas on simple stepped loops #1031 Same condition as Python's _loop_body_is_simple; the same loops get the hint. Goldens for_vectorize_pragma*.
parallel for with OpenMP #1032 Ascending branch under #ifdef _OPENMP / #pragma omp parallel for, serial descending branch. Built and run with libomp and gcc -fopenmp.
Sort and find plan selection #1054 sort_plans.flow and sort_sites.flow port plan_selector, ordering_plans and the provenance walk. Plan choice matches Python on every compared program, including elif conditions.
flow explain #1055 FLOWC_EXPLAIN=1; ./flow explain is back. Report text equals Python's on 12+ programs, except the closing cost note, now two sentences.
--export aliases and --library mode #1030 flow_export_<name> wrappers with Python's shape; library units have plain names, no checks, extern inline. The runtime modules, wasm_build and wasm_crossings use --library again. One module built with emcc; the exports are in the wasm table and node calls them.
Direct capability calls inside handle blocks #1056 Same calls as Python on two programs (nested blocks, multi-effect block, lambda keeps the vtable).

require/prefer constraints: the Python C backend never called constraints.py or general_plans.py. The constraints that act on a sort site are the general, adaptive, unique and unstable policies and the scratch budget, and those are ported. docs/language/multi-implementation.md says so.

Bugs fixed

Every fix has a tests/cgen golden or a tests/lang program that fails with #1027's flowc.

Docs and tools

  • Doc example ledger: 623 verified, 0 unverified (was 603 and 21 on selfhost: retire the Python C host; flowc is the only C compiler #1027, 624 and 0 on Python). Two blocks gained the struct declaration they used without declaring. The import-inside-module block in docs/language/modules-namespacing.md is tagged expect-error, since the page shows it failing.
  • scripts/verify_browser_interp.py: 239 pass, 0 fail (was 3 differences).
  • roundtrip.sh and both self-emit generations build the new modules.

Gates

Gate Result
bootstrap_from_c.sh --regen fixed point at gen2 (separate commit)
bootstrap_from_c.sh --verify PASS
self_host_full.sh PASS
roundtrip.sh ALL PASS
parse_coverage.sh --check OK
fmt_check.sh --check OK
tests/cgen/run.sh 99 passed, 0 failed (64 on #1027)
./flow test-lang 216/216 (test_c_import_dirs needs /tmp/flow_test_inc/myheader.h, which nothing creates; it fails the same way on #1027's flowc)
corpus_parity.sh --check OK, 1041 >= floor 1033
parity_dynamics_dsl, effects, field_dsl, flow_blocks, lowering, mlir, proofs PASS
parity_shader_dsl fixtures pass; the Metal step needs the Metal toolchain this machine lacks
python_ratchet.sh PASS, baseline lowered to 67002 lines

flowc-parity-gates runs parity_lowering, parity_field_dsl, parity_shader_dsl, parity_dynamics_dsl, parity_flow_blocks and parity_effects in golden mode and fmt_check --check; flowc-corpus-parity runs corpus_parity --check. fmt_check and corpus_parity link libm; test_sort_nan forces positive NaNs (0/0 is a negative NaN on x86-64); runtime_strict_abort flushes stdout before its abort.
FLOWC_EXPORT (flowc_emit.sh --export NAME) appends a visible
flow_export_NAME alias for each named function, forwarding to its C
symbol, as the Python host's --export did. In a bundle each module
aliases the names it defines, and names no module defines get a
not-found comment.

FLOWC_LIBRARY=1 (flowc_emit.sh --library) leaves out the runtime checks
and the fault handler and never moves main onto a fiber, as the Python
host's --library did.
a = b = 1 nests the inner assignment as the right side and emits
a = (b = 1), as the Python host did. import M as name records the alias
in the parser, and name.f reads as f.
import concurrent and import std.vec now resolve in lib/stdlib after the
module and search directories, as in the Python resolver. test-lang links
the concurrency runtime for these import forms too.
The capture scans now treat a let in the lambda body as a local for the
statements after it and a for variable as a local in its body, so the
closure environment holds only names from the enclosing function.
flow-driver (runtime archive and gfx_record), the wasm_build and
wasm_crossings tools and wasm/crossing_common.py compile lib/runtime
modules with --library (FLOWC_LIBRARY=1) again, as they did with the
Python host's --library. Document the flowc --export and --library
flags in docs/language/export-abi.md.
The parser keeps each function attribute as an AST_ATTR node that points
at its function. cgen lowers @inline, @always_inline, @noinline and a
validated @target onto the prototype and the definition, as the Python
host did. The typecheck reports unknown attributes, a malformed @target
and @noinline with @inline. A function whose @only or @guard modes are
all off is dropped at parse time; FLOWC_MODE adds a mode.
String == and != go through __flowc_str_eq, a strcmp wrapper that treats
equal pointers as equal and null as equal only to null. len of a string
is its strlen, and 0 for null. Array len is unchanged.
…stive match else

Port four C shapes the Python host emitted and flowc dropped:

- A stepped, non-parallel for loop whose body is lets and assignments
  with only math calls gets the clang vectorize and GCC ivdep pragmas,
  under the Python host's _loop_body_is_simple rule (#1031).
- `parallel for` keeps its keyword in the AST and lowers to an
  ascending loop under a guarded `#pragma omp parallel for`, with a
  serial descending loop for a negative step (#1032).
- A variadic extern prototype keeps its `, ...` (#1033).
- The last arm of a match that covers every enum variant, or true and
  false on a bool, is a plain else (#1034).

A literal negative step now stops before the end value, since `to` is
exclusive in both directions (#1035).
A library unit keeps every function externally linked, so the inline
specifier from #1028 is extern inline there, as the Python host chose
for --library.
…libc (#1045)

A call to find goes to the flowc builtin only when no function of that
name is defined in the module or recorded by an imported one. A Flow
function named like a fixed-arity libc function but taking a different
number of parameters is its own function: it is emitted as
__flowc_libc_<name> and every call is routed to it, as for the
allocator and struct-receiver cases. The Python host reached the user
definitions through its parameter-type mangling.
The native parsers read -5 |> clamp(0, _, 100) as clamp(0, -5, 100).
The interpreter treated |> as a postfix operator and computed
-(clamp(0, 5, 100)), so pipelines-3 disagreed with native output in
scripts/verify_browser_interp.py.
- Parse prefix `*p` as a dereference, lowered to `p[0]` (#1046).
- Emit no closure typedef for a function type that names a type
  parameter of an enclosing generic declaration (#1047).
- Initialize a module-level `span<T> = null` with `{0}` (#1048).
- Mangle body-less prototypes that overload a name with different
  parameters (#1049).
- Evaluate the elements of an array literal used as a statement
  instead of emitting a bare initializer list (#1050).
- Undefine the complex.h macro I after the include and build complex
  values with _Complex_I, so a Flow name `I` compiles (#1051).
The two -all preambles defined main. The Python host dropped the
block's own main as a duplicate, so those blocks were never compiled.
Rename the preamble main, declare the five capabilities the page names
but never declares, and drop the preamble copies of TestBackend and
NullLogger that the page blocks declare themselves.
A module with several functions of one name records each overload's
parameter type names in the bundle signature table (!name). A call in a
later module to a name it does not define picks the overload the
arguments fit (exact first, then the best score, arity must match) and
emits name_T0_T1, the name the defining module gives it. The bundle
type checker accepts a call whose argument count matches any seeded
overload of the name. The Python host called area_f64 and area_i32_i32
the same way.
Both blocks named a type the page never declared. The Python host
compiled them only because it made up an empty struct for any unknown
type name.
…d the rest of #1018's gaps (#1025)

One closure representation for function types, the Python host's runtime checks under FLOWC_CHECKS=1, generic templates across bundle modules, impl blocks and flow.toml [paths] imports, Tensor operator sugar, quantity literals, FLOWC_LENIENT=1, pointer receivers across modules, array<T>(N), @cImport as a plain include, for ranges without a step. Files marked flow:flowc-only are skipped by the Python-host test sweep. Corpus parity 1044 >= 1033 (Darwin); every parity gate passes.
A step that is not an integer literal now goes into a loop-scoped
variable whose sign picks the < or > test, as on the Python host.
Literal steps keep the plain comparison (#1004).
This was referenced Sep 30, 2026
@godofecht
godofecht deleted the selfhost/restore-c-features branch October 1, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant