Skip to content

Stage-A batch 2: precedence, scoped name types, sort-modifier names, libc externs, diagnostics - #1003

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

godofecht merged 13 commits into
mainfrom
fix/stage-a-batch-2

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Stage-A bug batch 2: fixes found while porting the Python tools to Flow.

Fixes

Also in this PR

Workarounds removed

Verification

  • Fixed point: the Python-host emit of main.flow is byte-identical to the rebuilt bootstrap's emit. bootstrap_from_c.sh --verify, self_host_full.sh and roundtrip.sh all pass. roundtrip.sh also runs the new keyword_param diagnostic check.
  • Bootstrap suite (tests/lang through the regenerated Stage-A): 138 pass, 19 fail, 3 abort at run time. On origin/main it is 132/25/4. The 6 new passes are the new tests plus test_ordering_hints_port. Every remaining failure also fails on main.
  • Every tracked .flow file emitted by origin/main's flowc and by this branch's, then syntax-checked with cc: 833 → 859 compile, and no file regresses.
  • ./flow test-lang (Python host) passes all new tests plus test_generic_channels.
  • Tools: python_ratchet.sh PASS. challenges/flow-specific/check.sh self-test passes 4 checker cases and 43 regex cases. check_doc_links.sh passes. The Flow repo_stats output matches update_repo_stats.py --check; before this PR it did not compile because of Stage-A: string + on a string const compiles to pointer addition #967.

Not done

Fixes #995
Fixes #994
Fixes #968
Fixes #957
Fixes #993
Fixes #967
Fixes #992
Fixes #984
Fixes #990
Fixes #963
Fixes #970
Fixes #969
Fixes #958
Fixes #988
Fixes #953

…rds as names

flowc put | ^ & << >> on one level below the comparisons. It now uses the
Python parser's levels: or, and, |, ^, &, equality, comparison, shifts,
additive, multiplicative. cgen emits comparison and logic operators without
parens, so a child binop is now wrapped whenever C would regroup it.
Emitting every tracked .flow file before and after the change gives
identical C apart from compiler/src itself, so no program changes meaning.

The parser now marks the modifier identifiers it collects after
`|> sort`, and cgen and the typechecker substitute only marked nodes.
A variable called desc, descending, unique and so on is an ordinary name.

Fixes #995
Fixes #994
Fixes #968
cgen decided whether `+` is string concatenation, and which printf
format print uses, by scanning every parameter and let in the module for
the name. A same-named declaration in another function could turn string
concatenation into pointer addition or print a string with %d.

cgen now resolves an identifier to the latest let that precedes it in the
function being emitted, then that function's parameters, then a module
const. The old module-wide scan stays only as the fallback for code
outside a function body. The same lookup resolves struct field types, so
println of an f64 field uses %f, a string field concatenates, and field
access through a local ptr<Struct> emits ->.

A string const is emitted as `const char* const` instead of
`const const char*`.

Fixes #957
Fixes #993
Fixes #967
Fixes #992
Fixes #984
Fixes #990
A parse failure printed only a byte offset, and in bundle mode not even
that. Every parse failure site now also prints path:line:col and the
token, and a note when the token is a reserved word.

Fixes #970
The preamble now includes <time.h>, so an extern time() or clock() has a
declaration. The libc allowlist covers the rest of the stdlib.h,
string.h, math.h and time.h functions a Flow extern is likely to name, so
their prototypes no longer clash with the headers. The clang pragmas that
silence int-conversion and incompatible-pointer-types get GCC twins, and
gcc-15 now builds the Stage-A bootstrap C.

Fixes #969
Fixes #958
The Python host puts every declaration of an imported module into the
program, so a call to a plain function of an imported module compiles
there. flowc seeded only exported functions and consts. It now seeds
every top-level function (except an imported main) and every const,
and the seed tables are larger to hold them. docs/language/modules.md
states the rule and how it meets the #950 private-name renaming; its
dashes are replaced to satisfy the copy check.

Fixes #988
flow_rt_support.c calls CoreFoundation for its fatal-error popup, and
test-lang linked the concurrency sources without the framework. The
concurrency link flags now carry it on Darwin, so test_generic_channels
and any test importing stdlib/concurrent.flow link.

Fixes #953
PR #1002 rewrote the em dashes in the Python proof generators. The Flow
ports of math_prose, proof_document and claim_path now emit the same
sentences, so both hosts produce the same text.
With uncommitted compiler/src edits, ensure_flowc runs roundtrip.sh on the
Python host. Every `./flow run` in the roundtrip checks project
dependencies with a flowc-built tool, which calls ensure_flowc again,
which starts another roundtrip. The processes multiplied until fork
failed. The roundtrip now marks itself in the environment, and nested
calls use the checked-in bootstrap C.
The preamble now includes <time.h>, so an extern prototype for
clock_gettime, clock_gettime_nsec_np, nanosleep, gmtime_r or localtime_r
would clash with it. The bench tools and the publish benchmarks declare
some of these.
- tools/python_ratchet: print with println; the puts wrapper worked
  around #948.
- scripts/tools/lib/text.flow: ft_join returns a + b directly; the typed
  local worked around string + on parameters (#957).
- scripts/tools/lib/regex.flow: return not (...) directly (#963).
- scripts/tools/build_tool.sh: use cc; the clang preference worked
  around the clang-only pragmas (#958).
#1002 made the repo-stats generator write '-' where it wrote 'n/a' and
left test_repo_stats expecting the old text, which turned Python tests red
on main.
@godofecht
godofecht merged commit e74c99a into main Sep 29, 2026
29 checks passed
godofecht added a commit that referenced this pull request Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's
parse-only mode, located parse errors (flowc_parser_print_error, which the
driver, emit and bundle paths now use), theorem/assume/therefore/claim
references, flow blocks, handle, ui layout and pipeline blocks, let without
initializer, contextual unit, distinct, effect rows, or-patterns, guards,
nested patterns, [T; N], capability types, ?, vector literals, soft names,
sort-by keys, entropy policies and module blocks, the parse coverage script
and its CI floor, and the Python-grammar parser contract test. The
#1001/#1003 reconciliation follows the one in #1012.
godofecht added a commit that referenced this pull request Sep 29, 2026
…ders retired (#999)

The dynamics DSL expander and flow-block lowering run in flowc (dynamics_dsl.flow, flow_blocks.flow) at every source read through flowc_expand_stages_in_place, with parity gates parity_dynamics_dsl.sh and parity_flow_blocks.sh and committed run goldens. The Python expanders become flowc bridges. CI builds flowc before the fuzz run and gives the self-host roundtrip 30 minutes. Bootstrap C regenerated after rebasing onto #1003: fixed point, bootstrap_from_c --verify and self_host_full pass.
godofecht added a commit that referenced this pull request Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's
parse-only mode, located parse errors (flowc_parser_print_error, which the
driver, emit and bundle paths now use), theorem/assume/therefore/claim
references, flow blocks, handle, ui layout and pipeline blocks, let without
initializer, contextual unit, distinct, effect rows, or-patterns, guards,
nested patterns, [T; N], capability types, ?, vector literals, soft names,
sort-by keys, entropy policies and module blocks, the parse coverage script
and its CI floor, and the Python-grammar parser contract test. The
#1001/#1003 reconciliation follows the one in #1012.
godofecht added a commit that referenced this pull request Sep 29, 2026
#1001 and #1003 both reworked parse diagnostics. With both merged the
located form from #1001 wins, and it now also prints the #1003 note when
the failing token is a keyword. roundtrip.sh's keyword_param check
expects the merged form.
godofecht added a commit that referenced this pull request Sep 29, 2026
Rebased onto main containing #1003, #999, #998 and #989. Carries #1001's
parse-only mode, located parse errors (flowc_parser_print_error, which the
driver, emit and bundle paths now use), theorem/assume/therefore/claim
references, flow blocks, handle, ui layout and pipeline blocks, let without
initializer, contextual unit, distinct, effect rows, or-patterns, guards,
nested patterns, [T; N], capability types, ?, vector literals, soft names,
sort-by keys, entropy policies and module blocks, the parse coverage script
and its CI floor, and the Python-grammar parser contract test. The
#1001/#1003 reconciliation follows the one in #1012.
godofecht added a commit that referenced this pull request Sep 29, 2026
#1001 and #1003 both reworked parse diagnostics. With both merged the
located form from #1001 wins, and it now also prints the #1003 note when
the failing token is a keyword. roundtrip.sh's keyword_param check
expects the merged form.
godofecht added a commit that referenced this pull request Sep 29, 2026
…ors as #1003 does

roundtrip.sh builds the frontend module by module, so proof_lower.flow
(called from cgen, jsgen and the typecheck) is compiled, given a header
and linked into flowc_frontend.o and flowc_jsgen_fmt.o.

driver.flow keeps #1003's flowc_parser_report where #1001 and #1003
both changed the same line; the roundtrip's keyword_param check (from
godofecht added a commit that referenced this pull request Sep 29, 2026
…ors as #1003 does

roundtrip.sh builds the frontend module by module, so proof_lower.flow
(called from cgen, jsgen and the typecheck) is compiled, given a header
and linked into flowc_frontend.o and flowc_jsgen_fmt.o.

driver.flow keeps #1003's flowc_parser_report where #1001 and #1003
both changed the same line; the roundtrip's keyword_param check (from
@godofecht
godofecht deleted the fix/stage-a-batch-2 branch October 1, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment