Skip to content

flowc: issues batch 4 (statics, imports, &call(), range loops, *p, strict checks) - #1082

Merged
godofecht merged 13 commits into
mainfrom
fix/flowc-issues-batch-4
Sep 30, 2026
Merged

godofecht merged 13 commits into
mainfrom
fix/flowc-issues-batch-4

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Flowc fixes, batch 4. Each issue was reproduced on main first, and each fix comes with a tests/lang or tests/cgen case that fails on main.

Fixes #1078
Fixes #1074
Fixes #1073
Fixes #1066
Fixes #1009
Fixes #952
Fixes #1004
Fixes #1046
Fixes #1045
Fixes #1080
Fixes #986

Changes

  • flowc: prefix *p dereference is a parse error #1046 *p = 7 on the line after let p: ptr<i32> = &x parsed as &x * p = 7. When a * is the first token on its line and touches its operand, it now starts a new statement. The same rule is in the parser (flowc_parse_binop_kind) and the formatter, so fmt no longer rewrites the line as * p = 7. A continued product keeps its space ( * b) and still parses as one. Test: tests/lang/test_prefix_deref.flow (new case).
  • flowc: field read through a module-level ptr<T> emits (tab).len #1078 Reading or writing a field through a module-level ptr<T> now emits ->. CgenBuf records the module root, and flowc_cgen_expr_type_node resolves a module static's annotation. Test: tests/lang/test_static_ptr_field.flow.
  • flowc: struct literal copying an array field of an imported struct emits invalid C #1074 A struct literal that copies a sized array field of a struct from another module now goes through the memcpy path. Each module writes [Struct.field entries for its array fields into the bundle signature table. Test: tests/lang/test_import_struct_array_field.flow with tests/fixtures/modules/testlib/lattice.flow.
  • flowc bundle: a module imported by two string-path spellings is emitted twice #1073 String imports that step back (m/../x/c.flow) are normalized before the already-bundled check, so the module is bundled once. Only paths with an interior . or .. segment change. Test: tests/lang/test_import_dot_paths.flow with tests/fixtures/modules/dotpath/. The fixture module has a top-level const, which is the case where bundle typecheck used to fail.
  • flowc: address-of a call result emits invalid C #1066 &f() now becomes (&((__typeof__(f()))[1]){ f() })[0]): a one-element compound literal that lives to the end of the block. The call still runs once. Test: tests/lang/test_addr_of_call.flow.
  • flowc: a float array element as a string + operand gets no number-to-string conversion #1009 Cases 1 and 2 already worked on main: divs calls div_Dual_f32, and load_file(&reader, path) takes the address. The fix covers case 3: in "x" + p[0], a numeric or bool element of a pointer or array (including array_f32) is converted by its element type. examples/gpu/gpu_fft.flow now compiles, and its link step still needs the runtime. Test: tests/lang/test_concat_index_number.flow.
  • flowc strict check: sizeof<T>() is an undefined function (sizeof_i64) #952 The strict checker (sem_check) now types sizeof<T>() as i64, which is how cgen emits it, as long as no user function is named sizeof. The stdlib/concurrent.flow half of the issue already worked on main when the program passes &m. The program in the issue passes m by value, which is flowc strict check accepts a struct value for a ptr<T> parameter #1080. Test: tests/lang/test_sizeof_generic.flow. compiler/fixtures/stage_a_sizeof.flow is now accepted where the retired Python checker rejected it, so the Darwin py-only ceiling in compiler/fixtures/typecheck_parity/ceiling.txt goes from 5 to 6. That file lists it as an intended difference.
  • for loops emit a select-based step that blocks LLVM vectorization #1004 Loops written for i in a to b with no step used to choose their step on every iteration (__flowc_up ? 1 : -1). The direction is now decided once. With literal bounds, only the loop that runs is emitted. Otherwise an ascending and a descending loop sit under a single if ((a) <= (b)). Each loop has a constant step. At -O3 on arm64, scale_for from the issue went from 0 to 10 fmla.4s instructions. Test: tests/cgen/for_range_affine checks the text and the run in both directions. The cgen_for self-test was updated to match.
  • flowc: a user function named like a libc function that is not a builtin (wait) clashes with the libc prototype #1045 User functions named wait, waitpid, wait3, wait4, chmod, umask or getline are renamed for the unit, the way heapsort and index already are. Names that flowc already treats as libc externs (stat, mkdir, system, ...) were left out of the list. Test: tests/lang/test_posix_named_functions.flow.
  • flowc strict check accepts a struct value for a ptr<T> parameter #1080 The strict checker now rejects a struct value passed to a ptr<T> parameter of a plain call. A method receiver (m.take()) is still accepted, because cgen takes its address there. Tests: tests/cgen/struct_for_ptr_param (reject) and tests/lang/test_method_receiver_address.flow.
  • flowc: else if parse error should suggest elif #986 A parse error at if directly after else now adds the note "Flow spells else if as elif", instead of the reserved-word note. Test: tests/cgen/else_if_hint.

Bootstrap C is regenerated in its own commit (fixed point at gen2).

Checked on main and already fixed

#1005, #954, #1010, #1036, #1037, #1038 (it compiles, and linking needs the concurrency runtime that test-lang adds), #1039, #1040, #1042, #1043, #1044, #1047, #1048, #1049, #1050, #1051, #1052. #1041 is a merged PR.

Emitted C for unaffected programs

Every tracked .flow file (3093) was emitted with the main flowc and with this branch, and the outputs were diffed.

Gates (macOS arm64)

All run on this branch with the regenerated bootstrap:

  • bootstrap_from_c.sh --verify, self_host_full.sh, roundtrip.sh: pass
  • parse_coverage.sh --check, fmt_check.sh --check: pass
  • tests/cgen/run.sh: 105 passed, 0 failed
  • ./flow test-lang: 227 of 227 pass
  • corpus_parity.sh --check: pass
  • parity_typecheck.sh --check: pass. The py-only ceiling went from 5 to 6 for sizeof<T>(), see flowc strict check: sizeof<T>() is an undefined function (sizeof_i64) #952 above.
  • typecheck_rules.sh: pass
  • parity_dap, parity_dynamics_dsl, parity_effects, parity_field_dsl, parity_flow_blocks, parity_lowering, parity_mlir, parity_project_test, parity_proofs, parity_targets: pass
  • parity_shader_dsl: passes except the Metal compile step. This Mac has no Metal toolchain.
  • tests/mlir_commands/run.sh: 72 passed, 0 failed

The MLIR corpus digests of test_parser_python_forms.flow and test_parser_span_mutability.flow are refreshed, because both import compiler/src/parser.flow.

A prefix dereference at the start of a line, touching its operand, ends the
expression on the line before it. `let p: ptr<i32> = &x` followed by
`*p = 7` used to parse as `&x * p = 7`.
String imports that step back (m/../x/c.flow) are normalized before the
already-bundled check, so the module is emitted once. Paths without a
. or .. segment are unchanged.
sem_check looked the call up as a generic instance named sizeof_T and
reported it undefined. With no user function named sizeof, it is the
builtin cgen emits as ((int64_t)sizeof(T)).
…d indexed concat operands

- A field read or store through a module-level ptr<T> uses -> (#1078):
  expr_type_node now resolves a module static's annotation.
- A struct literal copying a sized array field of a struct from another
  bundle module copies it with memcpy (#1074). Each module records its
  structs' array fields in the signature table as [Struct.field.
- &f() spills the call result to a one-element compound literal and
  takes the element's address (#1066).
- A numeric or bool element of a pointer or array as a string + operand
  is formatted by its element type (#1009, third case).
for i in a to b chose its step per iteration with (a <= b) ? 1 : -1, so
LLVM saw a non-constant stride and did not vectorize. The direction is
now taken once: with literal bounds only the loop that runs is emitted,
otherwise an ascending and a descending loop sit under one test of the
bounds. scale_for from the issue goes from scalar fmadd to fmla.4s at -O3.
…1046)

The formatter read `*p = 7` at the start of a line as a continued product
and wrote `    * p = 7`, which the parser now reads differently.
A Flow function named like a POSIX function the preamble's headers
declare with another signature is renamed for the unit, as heapsort and
index already are. `function wait(t: ptr<Tapper>, frames: i32)` clashed
with <sys/wait.h>, which <stdlib.h> includes.
)

sem_is_compatible lets a struct meet any pointer, which cgen honours only
for a method receiver (it takes the address). A plain call such as
take(m) with m: M now fails overload matching instead of reaching cc.
The note under a parse error at `if` straight after `else` now says Flow
spells it `elif`, in place of the reserved-word note, which misled here.
@godofecht
godofecht force-pushed the fix/flowc-issues-batch-4 branch from db534da to 3a660bc Compare September 30, 2026 12:53
@godofecht
godofecht merged commit fd73172 into main Sep 30, 2026
33 checks passed
godofecht added a commit that referenced this pull request Sep 30, 2026
…1090)

Ports the two fixes in #1081 that #1082 did not cover, with their tests.

- #1050: an array literal used as a value (indexed, cast or measured with len) gets a compound literal's type, `(int32_t[]){ ... }`, because a bare initializer list is not a C expression. `let a = [1, 2, 3]` takes its element type and dimensions from the literal, and a statement-level literal evaluates nested rows for their effects.
- #1048: a module static of type `&[T]` or `&mut [T]` initialised from `null` is the empty span, as `span<T>` already was.

Tests, from #1081: `tests/lang/test_array_literal_value.flow`, `tests/lang/test_static_span_null_forms.flow` and the `tests/cgen/array_literal_value` golden. Both lang tests failed on main before this change.

Local gates: bootstrap fixed point, self_host_full, roundtrip, cgen 107/0, test-lang 230, every parity gate (parity_shader_dsl only at its Metal step, as always on this Mac), parity_typecheck, typecheck_rules, conformance, mlir_commands 72/72, fuzz, corpus parity and the ratchet.
godofecht added a commit that referenced this pull request Sep 30, 2026
New stdlib modules: std.process (argv, captured output, exit status, timeout, env and cwd; #961), std.regex with Python re semantics (#962), and std.os for errno and signals, with extern const for C constants and layouts (#1075). The DSL expanders share compiler/src/bytebuf.flow (#985). repo_stats and python_ratchet run git through std.process.

Import paths: #1082 and this PR each normalized import paths. There is now one normalization, flowc_resolve_normalize, applied to every import form. A path that still differs is compared with the known ones as an absolute path. #1082's flowc_resolve_normalize_dots is removed. Both tests pass: test_import_dot_paths (#1073) and test_import_normalized_path.

API change, on purpose: lib/stdlib/process.flow is rewritten, and the old helpers it exported (run_cmd, have_cmd, env_is, str_eq) are gone. No tracked program or document imported them from std.process, so they get no forwarding exports. The LSP completion transcript is re-recorded without str_eq.

The MLIR corpus is re-recorded for the programs that import changed compiler modules, and #908's span_elem_addr golden is kept as merged.
godofecht added a commit that referenced this pull request Sep 30, 2026
…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.
godofecht added a commit that referenced this pull request Oct 1, 2026
Both bugs are fixed on main (#1082, #1102). Read SINK fields straight off
the module static, and spell the C strings in the sys.flow and
std.process shims as quoted literals instead of char arrays.
godofecht added a commit that referenced this pull request Oct 1, 2026
* cli, process: drop the #1078 and #1089 workarounds

Both bugs are fixed on main (#1082, #1102). Read SINK fields straight off
the module static, and spell the C strings in the sys.flow and
std.process shims as quoted literals instead of char arrays.

* packaging: drop flow-driver from the Homebrew formula

flow-driver was deleted in #1095. The ./flow stub builds tools/flow_cli
from compiler/bootstrap, so tools/ is always installed beside it.

* parity_typecheck: read logs as text with grep -a

Some frontend logs echo source bytes that are not valid UTF-8. GNU grep
then printed "binary file matches" on stderr 151 times per CI run and
left the message empty. The verdicts and the class table are unchanged.

* cli: keep the toolchain state in string statics

#1103 allows module-level strings (#1086), so the Toolchain struct
behind a pointer static and its tc() accessor (a #1078 workaround) go.

* parity_typecheck: keep the shell line count flat

The shell ratchet counts lines; the rationale for grep -a lives in the
previous commit message.
godofecht added a commit that referenced this pull request Oct 1, 2026
Both bugs are fixed on main (#1082, #1102). Read SINK fields straight off
the module static, and spell the C strings in the sys.flow and
std.process shims as quoted literals instead of char arrays.
@godofecht
godofecht deleted the fix/flowc-issues-batch-4 branch October 1, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment