Skip to content

Stage-A batch 3: libc builtins, generic calls, ptr receivers, &[T] spans, unit dimensions, parse-reject audit - #1015

Merged
godofecht merged 6 commits into
mainfrom
fix/stage-a-batch-3
Sep 29, 2026
Merged

godofecht merged 6 commits into
mainfrom
fix/stage-a-batch-3

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Stage-A batch 3. Built on #1012 (merged in, together with origin/main), so it also carries #1001 and #1003 until those land.

Fixes #1006
Fixes #1007
Fixes #1008
Fixes #997

flowc changes

  • flowc typecheck: know the libc functions the Python checker knows (printf without an extern) #1006 typecheck knows the Python checker's BUILTIN_FUNCTIONS table (printf, strlen, sqrt, malloc and the rest), so these calls need no extern block.

  • flowc: three gaps found by the #996 parity corpus (generic call check, ptr<Struct> argument, span<f64>) #1007

    • An explicit instantiation f<T>(args) is no longer held to the template's T-typed parameters. An implicit generic call still reports no matching overload, as the Python checker does.
    • recv.method(args) passes &recv when the receiver is a by-value struct and the first parameter is ptr<ThatStruct> (the rule in _gen_method_call).
    • &[T] / &mut [T] parameters declare their flowc_span_T typedef, and an array argument converts to the parameter's span type. It used to always be flowc_span_int32_t.
    • A capturing lambda takes its lambda_N_env* _env first, which matches the closure's fn(&env, ...) call. This was behind 08_types_patterns once the typecheck error was gone.
  • flowc: check unit dimensions like the Python checker #1008 A units-of-measure pass in typecheck.flow, ported from type_checker.py:

    • unit registration, with the duplicate and unknown-factor errors
    • * and / composition and canonical names
    • the + - % and comparison rules
    • logical, bitwise and shift operators on units
    • casts into and out of units
    • the dimensionless-or-Radian rule for sin and related functions
    • the unit branch of coercion at let, assignment, return, call arguments, struct literals, consts and statics

    The messages match word for word, including line N:, so binary-operator nodes now span their operator token. All 31 cases in tests/unit/test_units.py and 12 more produce identical error sets on both checkers. Unknown types never report.

  • The bundle typecheck now sees C functions declared in an imported module's extern block, and collect_sigs records their return types. This fixed ui2d.flow (SDL_Init) and the Vulkan layout demos.

Parity corpus

  • All 8 flowc-side lines left compiler/parity_lowering/divergent.txt.
  • The remaining 11 lines are Python host import failures. flowc now builds all 11 (one needed a source fix: demos/vulkan_tetris_flow read _ui_state[0].unit through the untyped pointer).
  • Added 7 negative unit fixtures and tests/lang/test_units_dimensions.flow, with goldens from the Python host at 5f36fc6.
  • A Python type error's golden is now its first ✗ line.

#997 audit

python_rejects.txt now files every entry under a reason:

  • negative fixtures
  • source for a pre-parse DSL expansion
  • Flow-only \x escapes
  • docs/vision sketches
  • the flow-verify proof corpus

Two files were broken and now parse on both parsers: wasm_crossings/main.flow, which used the local name module, and tests/runtime/wip/test_short_circuit.flow, which used block expressions. 23 files the Python parser rejects were missing from the list and are now listed. The list matches the Python parser exactly (checked over all 2341 tracked files).

Verification

Check Result
Fixed point OK
bootstrap_from_c.sh --verify pass
self_host_full.sh pass
roundtrip.sh ALL PASS
parse_coverage.sh --check 2141/2141, floor 2141
parity_lowering.sh 74 files, fail 0. --python HEAD also fail 0
Bootstrap suite (env-var form, link) 155/10, was 147/18 on the same files
Bundle emit + cc -c over all tracked .flow 939 pass, was 816

In the bundle emit row, the only files that went from pass to fail are the five new negative unit fixtures.

New tests in tests/lang: test_libc_builtins, test_generic_explicit_call, test_method_ptr_receiver, test_slice_f64_param, test_imported_extern, test_units_dimensions. Each runs with exit 0 on both hosts.

…receivers, declare &[T] spans (#1006, #1007)

- typecheck: the Python checker's BUILTIN_FUNCTIONS table (printf, strlen,
  sqrt, malloc and the rest) is known without an extern block.
- typecheck: an explicit instantiation f<T>(args) is not held to the
  template's T-typed parameters; an implicit generic call still reports
  no matching overload, as the Python checker does.
- cgen: recv.method(args) on a by-value struct passes &recv when the first
  parameter is ptr<ThatStruct>, as _gen_method_call does.
- cgen: &[T] / &mut [T] parameters declare their flowc_span_T typedef, and
  an array argument converts to the parameter's span type.
- cgen: a capturing lambda takes its environment pointer first, matching
  the closure's fn(&env, ...) call.

The eight flowc-side lines leave compiler/parity_lowering/divergent.txt.
typecheck.flow gains the units-of-measure pass from src/flow/type_checker.py:
unit registration (base and derived, duplicate and unknown-factor errors),
dimension composition through * and /, the + - % and comparison rules, the
operator rule for logical, bitwise and shift, casts into and out of units,
the dimensionless-or-Radian rule for sin and friends, and the unit branch
of coercion at let, assignment, return, call arguments, struct literals,
consts and module statics. Messages match the Python checker word for word,
including the line of the operator, so binary-operator nodes now span their
operator token.

Unknown types never report, so a gap can only accept what Python rejects.
All 31 cases of tests/unit/test_units.py and 12 more give the same errors
on both checkers.

compiler/parity_lowering gains seven negative unit fixtures and a runtime
test, with goldens from the Python host; a Python type error's golden is its
first ✗ line.
compiler/parse_coverage/python_rejects.txt now files each entry under its
reason: negative fixtures, source for a pre-parse DSL expansion, Flow-only
\x escapes, docs/vision sketches, and the flow-verify proof corpus. None is
a broken program.

Two files were broken and now parse on both parsers:
- scripts/tools/wasm_crossings/main.flow named a local `module`, a keyword
  in the Python lexer.
- tests/runtime/wip/test_short_circuit.flow used block expressions; it now
  counts evaluations through a pointer and passes on both hosts.

23 tracked files the Python parser rejects were missing from the list
(fixtures added since, and tools/repl); they are listed and classified.
The bundle typecheck seeded an import's functions and consts but not the C
functions its extern block declares, so lib/stdlib/ui2d.flow (SDL_Init from
stdlib/sdl2.flow) and the Vulkan layout demos stopped at `unbound call`.
They are now seeded, and flowc_cgen_collect_sigs records their return types
so an importer's inferred `let` gets the C type.

demos/vulkan_tetris_flow read `_ui_state[0].unit` through the untyped
layout pointer, which neither host can compile; it now calls
ui_layout_unit(_ui_state) like the examples/demos copy.

The 11 lines left in compiler/parity_lowering/divergent.txt are Python host
import failures; flowc builds all 11.
@godofecht
godofecht merged commit e2c8283 into main Sep 29, 2026
10 checks passed
@godofecht
godofecht deleted the fix/stage-a-batch-3 branch October 1, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant