Repository navigation
selfhost: restore the C backend features #1027 dropped, in flowc - #1058
Merged
godofecht merged 48 commits intoSep 29, 2026
Merged
Conversation
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.
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).
# Conflicts: # compiler/src/cgen.flow
…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
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.
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
@inline,@always_inline,@noinline,@target("...")static inline,extern inlinefor main, exported,@flow_apiand library units, validatedtarget). Goldensfunction_attributes*.@only/@guardbuild-mode guardstest_only_guard, goldensonly_guard*._loop_body_is_simple; the same loops get the hint. Goldensfor_vectorize_pragma*.parallel forwith OpenMP#ifdef _OPENMP/#pragma omp parallel for, serial descending branch. Built and run with libomp and gcc-fopenmp.sort_plans.flowandsort_sites.flowport plan_selector, ordering_plans and the provenance walk. Plan choice matches Python on every compared program, including elif conditions.flow explainFLOWC_EXPLAIN=1;./flow explainis back. Report text equals Python's on 12+ programs, except the closing cost note, now two sentences.--exportaliases and--librarymodeflow_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--libraryagain. One module built with emcc; the exports are in the wasm table and node calls them.handleblocksrequire/preferconstraints: the Python C backend never called constraints.py or general_plans.py. The constraints that act on a sort site are thegeneral,adaptive,uniqueandunstablepolicies and the scratch budget, and those are ported. docs/language/multi-implementation.md says so.Bugs fixed
...elsea = b = 1==/!=compare contents,lenof a string isstrlenimport concurrent; flowc: import M as name is a parse error #1039import M as nameBox { value: 1.5 }infersBox<f64>findorbsearchwin over the builtin and libc; the browser interpreter parses|>at the lowest precedence (the clamp difference)*pdereference is a parse error #1046 prefix*p, flowc: function type inside a generic declaration emits an invalid typedef #1047 function types in generic declarations, flowc: module-levelspan<T> = nullemits= NULLfor a struct #1048span = nullat module level, flowc: overloaded prototypes without bodies share one C name #1049 overloaded prototypes, flowc: array literal used as a statement emits a bare initializer list #1050 array literal statement, flowc: a field namedIcollides with the complex.h macro #1051 field namedI, docs: effects preambles definemain, so doc blocks were never compiled #1052 effects preambles that definedmainEvery fix has a tests/cgen golden or a tests/lang program that fails with #1027's flowc.
Docs and tools
expect-error, since the page shows it failing.Gates