Skip to content

fix(mlir): type a string index as u8 - #1561

Closed
godofecht wants to merge 7 commits into
mainfrom
fix/mlir-string-index
Closed

godofecht wants to merge 7 commits into
mainfrom
fix/mlir-string-index

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Cause

Indexing a string (s[i]) gave the MLIR emitter no element type, so it
refused the program with "unsupported: index into a pointer of unknown
element type". The checker types s[i] as u8 since #1147, and the C
backend reads a byte. 5 corpus programs stopped there, among them
tests/lang/test_string_index_type.flow, examples/rosetta/string-reversal.flow
and the mlir_async, mlir_pipeline and mlir_static_memory tools
(through their imports).

Fix

mlg_expr_ft gives the index of a string the type u8. The load is then
an i8 marked unsigned, so a byte above 127 widens to a positive value, as
in C. Stores through s[i] take the same path.

Regression fixture: compiler/fixtures/mlir/string_index.flow (bytes of an
ASCII string, a sum over them, and the two bytes of "é", which must read
195 and 169). On main it fails with "unsupported: index into a pointer of
unknown element type".

Counts

mlir_vs_c --only on the 5 affected programs:

same mlir-emit
main 7bbb4b3 0 5
this branch 5 0

Full corpus run (mlir_vs_c --jobs 8): queued behind the machine-wide corpus lock; the before and after counts will be added here.

Gates

  • selftest: flowc: PASS
  • bootstrap_from_c.sh --regen, then --verify: PASS
  • self_host_full, roundtrip: PASS
  • parity_mlir: PASS (25 fixtures, 2721 corpus programs)
  • tests/cgen: 152 passed, 0 failed
  • test-lang: all 309 passed
  • test-scripts: all pass except mlir_math_override, which fails in its
    C-backend half (flow run --backend=c exits 1). This change touches only
    the MLIR emitter, so the C path is the same as on main.

Regenerated state

  • compiler/bootstrap/flowc_stage_a.c and compiler/bootstrap/flowc_stage_a,
    in their own last commit.
  • compiler/fixtures/mlir/string_index.mlir and .out, recorded with
    parity_mlir.flow --record.
  • compiler/fixtures/mlir/corpus.txt: two digests added, for examples/rosetta/string-reversal.flow and tests/lang/test_string_index_type.flow, which flowc now accepts; no existing digest moved. --record also wanted to add 11 programs this change does not affect (corpus drift on main); those lines are left out.

Risk

Low. Only string indexing changes, and it was refused before.

Needs review by a CODEOWNER (touches compiler/).

s[i] on a string had no element type in the MLIR emitter, which refused
the program ("index into a pointer of unknown element type"). The
checker types it u8 (#1147) and the C backend reads a byte; the emitter
now does the same, so the load is an unsigned i8.

Fixture: compiler/fixtures/mlir/string_index.flow.
@godofecht
godofecht added this pull request to the merge queue Oct 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 14, 2026
@godofecht
godofecht enabled auto-merge October 15, 2026 16:07
godofecht and others added 3 commits October 20, 2026 12:34
…#1587)

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: godofecht <[email protected]>
Resolve merge conflicts in flowc_stage_a.c and corpus.txt.
Regenerate docs.
Regenerate bootstrap C.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: godofecht <[email protected]>

Copy link
Copy Markdown
Contributor Author

Resolved against current main in merge commit 7e9df9cd6f87dd5ba71e7040000ce9a130b5532b. Preserved the mlg_expr_ft u8 string-index semantic fix, its matching generated C hunk, and the three string-index regression fixtures. Dropped unrelated stale generated temporary renumberings and previous shared bundle changes; CI validation is pending before merge.

Copy link
Copy Markdown
Contributor Author

Superseded by merged #1665 (merge commit e3a9361), which explicitly migrates this MLIR string-indexing fix onto main with regenerated bootstrap and UTF-8 regression coverage. #1665's exact-head full CI and Linux/macOS qualification completed successfully. Closing the historical PR to avoid a duplicate/conflicting merge; its branch and commits remain preserved for reference.

@godofecht godofecht closed this Nov 3, 2026
auto-merge was automatically disabled November 3, 2026 21:35

Pull request was closed

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