Skip to content

flowc: print checker warnings, port the last strict checks, record update on C (#678, #996) - #1091

Merged
godofecht merged 7 commits into
mainfrom
fix/flowc-diagnostics
Sep 30, 2026
Merged

godofecht merged 7 commits into
mainfrom
fix/flowc-diagnostics

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Intent

Linked issue or roadmap item: closes #678. Closes the last two items of #996. Closes the open list in docs/design/mlir-in-flow.md ("What the deletion left open").

What changed:

  1. Checker warnings are printed ([Self-Hosting Phase 1] Port Full Pattern Matching to flowc #678). sem_check.flow computed warnings and dropped them. flowc now prints each as FILE:LINE:COL: warning: <message>, in the Python checker's words, in strict and lenient mode:

    • Non-exhaustive match: ... (int, bool and enum forms)
    • Taking the address of a pointer (got ptr<T>); ...
    • Handle handler 'X' is not a known capability

    FLOWC_WARNINGS=0 (flowc_emit.sh --no-warnings) silences them. FLOWC_WERROR=1 (--Werror) prints them as errors and fails the compile. The Python host had no -Werror; --strict and --lenient behave as before. Warnings inside lib/stdlib and lib/runtime are hidden unless FLOWC_WARNINGS=all, the way a C compiler treats system headers. Without that, 15 audio programs printed a warning from lib/stdlib/audio/io.flow.

  2. The last strict checks, ported:

    • Invalid escape sequence: \x is the Python lexer's error, fatal in both modes. Intentional difference: flowc passes strings to C as written, and its own sources use C escapes ("\x01", "\033"), so escapes C defines are still accepted. Rejected: \x with no hex digit after it, unknown letters, and a short \u.
    • Unsafe import path: ../x.flow is the Python resolver's error. It covers a .. component, an absolute path and a ~ path.
    • for range step must not be zero is new. The Python checker had no such rule, and the wording follows range_sums.py.
    • Division by zero, shifts, safety profiles, @rt_safe, and span and domain rules were already ported in selfhost: port the Python type checker to flowc (sem_check) with a parity gate #1071 and have fixtures.
  3. Stage-A: lower the constructs flowc now parses as parse-only nodes #996:

    • cgen lowers record update Name { ..base, f: v } as ({ Name t = base; t.f = v; t; }), the Python C host's shape, with array fields copied by memcpy. The output matches the MLIR emitter's on compiler/fixtures/mlir/record_update.flow.
    • Flow-stage parameters used outside a flow output get fork_records.py's error: "flow stage params Gain { ... } (line N) are only valid for a flow used as a pipeline stage inside a flow output". Before, the message was "unsupported in Stage-A".

Overlap check

  • I searched open pull requests and recent commits for overlapping work.
  • This does not duplicate another active implementation, or the relationship is explained below.

Overlap / dependency notes: rebased on #1082 and #1026. #1082 added tests/lang/test_import_dot_paths.flow, which reached its fixtures through ... That is now an unsafe import path, so the test spells its second path with an interior ./ and still covers #1073. #1083 is still open. Its C changes are independent, but whichever PR lands second needs a bootstrap regeneration.

Evidence

Baseline before this change: on main, flowc_emit.sh --strict accepted "\xZZ", for i in 0..10 step 0, import "../x.flow" and a non-exhaustive match, with no output. Record update failed in cgen with "unsupported in Stage-A".

Targeted proof: 10 new files in compiler/fixtures/typecheck_rules:

  • escape_invalid, for_step_zero, import_traversal, flow_stage_outside_output
  • warn_match_int, warn_match_bool, warn_match_enum, warn_address_of_pointer, warn_handle_handler, werror_match

typecheck_rules.sh now accepts # warn: expectations. tests/cgen/record_update covers struct and array fields and the run.

Why that proof would detect the old failure: with the previous bootstrap, typecheck_rules.sh fails on the 9 fixtures added for #678. flow_stage_outside_output came later and was not part of that run. The record_update cgen case fails because the old cgen refuses it. parity_typecheck.sh --write-warnings REV records the Python checker's warnings in compiler/fixtures/typecheck_parity/warnings.txt (rev f102d88, 47 warnings). --check compares them with flowc's: 3133 inputs agree, 0 differ, and the new classes have ceilings of 0.

Repository gate(s) run: all pass except the one noted below.

  • Bootstrap and self-host: bootstrap_from_c.sh --verify, self_host_full.sh, roundtrip.sh
  • Coverage and format: parse_coverage.sh --check, fmt_check.sh --check
  • Tests: tests/cgen/run.sh (107/107), ./flow test-lang (230/230), tests/conformance/run.sh
  • Type checking: corpus_parity.sh --check, parity_typecheck.sh --check, typecheck_rules.sh (123/123)
  • Parity: parity_lowering, parity_effects, parity_proofs, parity_mlir, parity_field_dsl, parity_dynamics_dsl, parity_flow_blocks, parity_dap, parity_project_test, parity_targets
  • Docs: check_doc_examples.sh --check-ledger
  • parity_shader_dsl fails only at its Metal step: this machine has no Metal toolchain.

Generated/bootstrap state:

Risk

  • Files changed because of the new checks:

    • 7 demos/vulkan_*_flow/src/main.flow dropped import "../../vulkan_abi/renderer.flow". It duplicated the externs in stdlib/vulkan_abi_renderer.flow, and breakout now imports that file instead. The Python host already refused these files.
    • scripts/tools/lattice_allpass and scripts/tools/discord_welcome import their sibling files by name instead of ../<dir>/x.flow. Both still compile.
    • tests/lang/test_import_dot_paths.flow and tests/fixtures/modules/dotpath are covered above.
  • Warnings now appear in flow compile output. On the tracked corpus, outside lib/, they come from about 20 inputs, most of them match fixtures.

  • No unresolved language/API design decision is being implemented implicitly. Two choices are called out above: the stdlib warning filter and the C-escape allowance.

  • No unrelated generated artifacts or local state are included.

  • Docs changed when user-visible behaviour or syntax changed: docs/design/mlir-in-flow.md and docs/book/09-expressions-and-matching.md.

  • docs/project/Questions.md updated if this needs a language-design decision.

Compatibility

  • No user-visible compatibility change.
  • Compatibility change is documented in docs/project/CHANGELOG.md.

The changes: new warnings on stdout; .., absolute and ~ string imports refused; step 0 refused in strict mode; invalid escapes refused.

Agent handoff

Any remaining blocker is recorded in GitHub rather than only in local/session state: none.

The strict checker (sem_check.flow) computed its warnings and never printed
them. flowc now prints non-exhaustive match, address-of-pointer and unknown
handle handler warnings as FILE:LINE:COL: warning: ..., with the Python
checker's text, in both modes. FLOWC_WARNINGS=0 (flowc_emit.sh
--no-warnings) silences them, FLOWC_WERROR=1 (--Werror) makes them errors.
Warnings inside lib/stdlib and lib/runtime show only with
FLOWC_WARNINGS=all.

parity_typecheck.sh --write-warnings records the Python checker's warnings
(warnings.txt, rev f102d88) and --check holds flowc to them: 3135 inputs
agree, none differ.

New strict checks, each with a fixture in compiler/fixtures/typecheck_rules:
- Invalid escape sequence: \x (the Python lexer's error, fatal); C escapes
  flowc's own sources use (\x01, \033) stay accepted.
- Unsafe import path: ../x.flow (the Python resolver's error). The tools
  and vulkan demos that imported with .. now import without it.
- for range step must not be zero.
- flow stage params outside a flow output (fork_records.py's error).
…hon's words (#996)

cgen writes a record update as the Python C host did:
({ Name t = base; t.f = v; t; }), with array fields copied by memcpy. The
output matches the MLIR emitter's on compiler/fixtures/mlir/record_update.flow;
tests/cgen/record_update covers struct and array fields.

Flow-stage parameters x |> Stage { k: v } outside a flow output have no
lowering: the Python host rejected them (fork_records.py). The checker and
the backends now print that error instead of "unsupported in Stage-A".
…igests

test_import_dot_paths reached its fixtures through `..`, which is now an
unsafe import path. It keeps its point, one module through two spellings,
with an interior `./` instead. The 24 corpus programs that import
compiler/src modules get new digests, as #1082 did for parser.flow, and
warnings.txt is recorded again over the current inputs.
#1091 takes the Python resolver's rule: a string import may not be
absolute, start with ~, or hold a .. component. After #1083,
lib/stdlib/bytebuf.flow reaches the compiler's byte buffer as
../../compiler/src/bytebuf.flow, and std.regex depends on it, so the rule
now exempts modules under lib/stdlib and lib/runtime. A program's own
imports keep the Python rule.

test_import_normalized_path still reaches bytebuf three ways: through
std.bytebuf (the .. spelling), directly, and as
./compiler/src/./bytebuf.flow in place of the .. spelling it wrote
itself. test_import_dot_paths and test_import_normalized_path both pass.
Recorded from 84806b0. #908's span_elem_addr fixture was set aside while
recording, since the Python generator at that revision mis-emits it (the
reason #908 added it); its merged goldens are unchanged.
@godofecht
godofecht force-pushed the fix/flowc-diagnostics branch from cf8e790 to 9a5c27d Compare September 30, 2026 17:26
@godofecht
godofecht merged commit 7d87432 into main Sep 30, 2026
36 checks passed
@godofecht
godofecht deleted the fix/flowc-diagnostics 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

Development

Successfully merging this pull request may close these issues.

[Self-Hosting Phase 1] Port Full Pattern Matching to flowc

1 participant