Skip to content

Compile 2-D grids: string(row) of a [][]rune row, and make([][]T, n) - #215

Merged
tylerlaprade merged 2 commits into
masterfrom
claude/grid-rows
Nov 24, 2026
Merged

tylerlaprade merged 2 commits into
masterfrom
claude/grid-rows

Conversation

@tylerlaprade

@tylerlaprade tylerlaprade commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Fixes DEV-159.

Grid programs, such as game boards and matrices, hit three translator bugs:

Go Before Now
for _, row := range board { fmt.Println(string(row)) } with board [][]rune E0599: the row was borrowed as a cell the row is a bare slice and is read as one. The same for string(board[i]) and for [][]byte
grid := make([][]Cell, h) when nothing else names the row type E0282: the rows were Vec::nil() with no element type the rows are <Vec<Cell>>::nil()
b.cells[y][x].Alive = true for a pointer b, in a program with goroutines did not parse: *{ ... }[x]... at the start of a statement is a block followed by [x] the block is in parentheses

The third one also hits ordinary programs, because strings, bufio and the other packages translated from source make a program use the goroutine form.

Fixtures: grid_rows and grid_rows_goroutines. They run a small life board made row by row, print rows of a [][]rune and a [][]byte with string(row), and make a [][]T whose rows stay nil. Both match Go. The board depends on #213 (make([]T, n) elements), which has landed.

11 other snapshots change, for the typed nil rows and the parentheses. Each was built and run, and all match Go. The ratchet is unchanged. TestNestedIndexThroughArrayOfSlicesUsesBareInnerSlice pinned the unparenthesized form and now expects the parentheses.

— agent: claude-chat


Generated by Claude Code

Summary by Sourcery

Fix translation of nested slices and grid operations so generated programs compile and preserve Go behavior.

Bug Fixes:

  • Correct slice-of-slices translation so grid rows are treated as complete slices for string conversion and nested indexing.
  • Preserve element types when creating nil rows with make([][]T, n).

Enhancements:

  • Parenthesize generated block expressions before indexing to produce valid Rust in regular and goroutine-enabled programs.

Tests:

  • Add grid and goroutine regression fixtures covering rune/byte row conversion, typed nil rows, nested indexing, and output parity with Go.
  • Update affected generated snapshots and nested-index expectations.

Grid programs, such as game boards and matrices, hit three translator bugs
(DEV-159):

- string(row) for a row of a [][]rune or [][]byte borrowed the row as a
  cell, and did not compile (E0599). A row, as board[i] or as the value
  of a range over board, is a bare slice, and is now read as one.
- make([][]T, n) wrote its rows as Vec::nil(), with no element type. When
  nothing else pinned the row type down, the declaration did not compile
  (E0282). The rows are now <Vec<T>>::nil().
- In a program with goroutines, b.cells[y][x].Alive = true for a pointer b
  wrote "*{ ... }[x]...". At the start of a statement Rust reads the block
  as a statement of its own, and the line did not parse. The block is now
  in parentheses.

Fixtures: grid_rows and grid_rows_goroutines run a small life board made
row by row, print rows of a [][]rune and a [][]byte with string(row), and
make a [][]T whose rows stay nil. Both match Go. 11 other snapshots
change, for the typed nil rows and the parentheses. Each was built and
run, and all match Go. The ratchet is unchanged;
TestNestedIndexThroughArrayOfSlicesUsesBareInnerSlice now expects the
parentheses.

Agent: claude-chat
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TkCXVghVg3khqYkpQSWyEM
@tylerlaprade tylerlaprade added the agent:claude-chat Work by the Claude chat agent (claude.ai session), acting as the repo owner label Nov 24, 2026 — with Claude
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T11:06:18.211227Z
We couldn’t complete this review. Comment @codex review to try again.
9e02d4a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7f6f100d-0e80-4e30-af39-b333b41a292e
Commits

Reviewing files that changed from the base of the PR and between 260e22e and 1f94ae3.

Files selected for processing: 24

  • go/expr.go
  • go/expr_test.go
  • go/grid_rows_test.go
  • go/stdlib.go
  • tests.bats
  • tests/append_growth_copies_struct_elements_goroutines/main.rs
  • tests/byte_tables_and_named_byte_slices/main.rs
  • tests/evaluation_order_of_element_writes_goroutines/main.rs
  • tests/generic_struct_pointer_receiver_goroutines/main.rs
  • tests/grid_rows/Cargo.toml
  • tests/grid_rows/expected_output.txt
  • tests/grid_rows/main.go
  • tests/grid_rows/main.rs
  • tests/grid_rows_goroutines/Cargo.toml
  • tests/grid_rows_goroutines/expected_output.txt
  • tests/grid_rows_goroutines/main.go
  • tests/grid_rows_goroutines/main.rs
  • tests/named_slices_print_and_nested_index/main.rs
  • tests/named_slices_print_and_nested_index_goroutines/main.rs
  • tests/nested_slice_array_append/main.rs
  • tests/nested_slice_element_updates/main.rs
  • tests/nested_slice_element_updates_goroutines/main.rs
  • tests/slice_expr_into_raw_element_slot/main.rs
  • tests/statement_reads_what_it_writes_goroutines/main.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@tylerlaprade
tylerlaprade merged commit 17ed6d8 into master Nov 24, 2026
0 of 2 checks passed
@tylerlaprade
tylerlaprade deleted the claude/grid-rows branch November 24, 2026 11:55
@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Sorry @tylerlaprade, this account has used its review budget of 1,500,000 diff characters for the last 7 days.

You can request another review in 1 day and 13 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Treat bare inner slices as slice values in string conversions and parenthesize block-valued inner slices before indexing, preventing incorrect borrowing and Rust parse errors.

  • go/expr.go L15289-15300, L19505-19511, L19537-19551 (+1 small edits)

Emit a typed nil value for each row when transpiling make([][]T, n), so the row element type is known.

  • go/stdlib.go L6041-6046

Configuration

Add Cargo package manifests so the new grid fixtures can be built and run.

  • tests/grid_rows/Cargo.toml L1-11
  • tests/grid_rows_goroutines/Cargo.toml L1-11

Tests

Add grid fixtures and regression checks for row string conversions, typed nil rows, and indexing block-valued rows, and register the fixtures.

  • go/grid_rows_test.go L1-87
  • tests.bats L1630-1637
  • tests/grid_rows/expected_output.txt L1-25
  • tests/grid_rows/main.go L1-102
  • tests/grid_rows/main.rs L1-910
  • tests/grid_rows_goroutines/expected_output.txt L1-27
  • tests/grid_rows_goroutines/main.go L1-119
  • tests/grid_rows_goroutines/main.rs L1-1194

Update the nested-index regression assertion to expect parentheses around a block-valued inner slice.

  • go/expr_test.go L2140-2142

Refresh generated Rust snapshots affected by typed nil rows and parenthesized inner-slice expressions.

  • tests/append_growth_copies_struct_elements_goroutines/main.rs L1158
  • tests/byte_tables_and_named_byte_slices/main.rs L866
  • tests/evaluation_order_of_element_writes_goroutines/main.rs L1112
  • tests/generic_struct_pointer_receiver_goroutines/main.rs L289
  • tests/named_slices_print_and_nested_index/main.rs L760
  • tests/named_slices_print_and_nested_index_goroutines/main.rs L929
  • tests/nested_slice_array_append/main.rs L954-955
  • tests/nested_slice_element_updates/main.rs L821-822, L858
  • tests/nested_slice_element_updates_goroutines/main.rs L985-1070 (7 small edits)
  • tests/slice_expr_into_raw_element_slot/main.rs L621
  • tests/statement_reads_what_it_writes_goroutines/main.rs L1024-1026

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:claude-chat Work by the Claude chat agent (claude.ai session), acting as the repo owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants