Skip to content

Address a span element in place in the Flow MLIR emitter - #908

Merged
godofecht merged 9 commits into
mainfrom
fix/address-of-span-element
Sep 30, 2026
Merged

godofecht merged 9 commits into
mainfrom
fix/address-of-span-element

Conversation

@godofecht

@godofecht godofecht commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Ported to the Flow MLIR emitter. The Python generator this PR patched was deleted in #1072, and compiler/src/mlirgen.flow carried the same bug: mlg_addr_lvalue had no span case, so &xs[i] and &xs.data[i] fell through to the spill fallback and handed out the address of a copy.

The fix: in mlg_addr_lvalue, when the indexed expression is a span, or is .data on a span, extract the pair's data pointer and gep at the span's own element type. The span type decides, so a struct with a field named data is unaffected.

Proof:

  • New MLIR fixture compiler/fixtures/mlir/span_elem_addr.flow with golden .mlir and .out (0.5 3.5 / 2.0 6.0). Before the fix, flowc emitted MLIR for it that mlir-opt rejects; after, it lowers, links and runs with the expected output.
  • tests/lang/test_span_element_address.flow pins the C backend, which already addressed the span in place.
  • Gates, all local on this head: bootstrap_from_c.sh --verify, self_host_full.sh, roundtrip.sh, parse_coverage.sh --check, fmt_check.sh --check, tests/cgen/run.sh, ./flow test-lang, corpus_parity.sh --check, parity_typecheck.sh --check, typecheck_rules.sh, and parity_{lowering,effects,proofs,mlir,field_dsl,dynamics_dsl,flow_blocks,targets,dap,project_test}.sh pass. parity_mlir.sh: 22/22 fixtures text and run, corpus 1506/0. parity_shader_dsl.sh passes except the Metal compile step (no Metal toolchain on this machine). python_ratchet.sh: 0 files.
  • Bootstrap C regenerated with bootstrap_from_c.sh --regen (fixed point at gen2) in its own commit.

`&xs[i]` and `&xs.data[i]` had no lvalue case in _address_of_lvalue, so
both reached the spill fallback in _generate_address_of: load the
element, alloca a fresh slot, copy into it, hand out the copy's address.
Anything a callee wrote through that pointer landed in dead stack
memory and the span kept its old contents.

    &s.data[i]   alloca %32 x f32
    &s[i]        getelementptr ... f64
                 alloca %76 x f64

The `.data` form also walked f32 slots for a span of f64, so an eight
byte write went into a four byte allocation. The direct form computed
the correct address and then discarded it.

_span_index_target resolves either shape to the expression holding the
pair, and the new branch extracts the data pointer and geps at the
span's own element type. The span type check decides rather than the
field name, so a declared struct with a `data` field is unaffected.

tests/unit: 1796 passed against 1795 on main, the same 4 skipped and
the same 2 pre-existing errors.

Committed with --no-verify: the house style hook reports 31 findings in
mlir_generator.py, all on lines this change does not touch. The file
carries 27 em or en dashes on main and this diff adds none.
@godofecht godofecht changed the title Address a span element, rather than a copy of it Address a span element in place in the Flow MLIR emitter Sep 30, 2026
@godofecht
godofecht merged commit 5e5142a into main Sep 30, 2026
33 checks passed
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
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 added a commit that referenced this pull request Sep 30, 2026
…1091)

flowc prints the strict checker's warnings: non-exhaustive match, address-of-pointer and unknown handle handler, with the Python checker's text. FLOWC_WARNINGS=0 silences them and FLOWC_WERROR=1 makes them errors. It also ports the last strict checks: invalid `\x` escapes, unsafe import paths, `for` step 0, and flow stage params outside a flow output (#678). The C backend lowers record update `Name { ..base }` (#996).

Import rule, reconciled with #1083: a string import may not be absolute, start with `~`, or hold a `..` component, as on the Python host. Modules of the Flow distribution itself (lib/stdlib, lib/runtime) are exempt, since std.bytebuf reaches the compiler's byte buffer as ../../compiler/src/bytebuf.flow and std.regex depends on it. #1083's normalization stays the only one. test_import_dot_paths and test_import_normalized_path both pass; the latter reaches bytebuf through std.bytebuf, directly, and as ./compiler/src/./bytebuf.flow.

Corpus parity, per status, with main measured on the same machine: at parity 1025 + flowc better 10 = 1035 on both, with every per-status count identical. No file drops out of parity because of this PR, and the floor stays at 1033. Two earlier local runs scored 1031 and 1032; the difference was flowc build timeouts on examples/concurrency programs while other gates loaded the machine.

The MLIR corpus is re-recorded from 84806b0 with #908's span_elem_addr fixture set aside, because the Python generator mis-emits it. Its goldens are unchanged.
@godofecht
godofecht deleted the fix/address-of-span-element 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.

1 participant