Skip to content

refactor(ir): move indentation and GEP layout out of model Display - #20

Open
Boreas618 wants to merge 2 commits into
mainfrom
refactor/ir-printer-boundary
Open

refactor(ir): move indentation and GEP layout out of model Display#20
Boreas618 wants to merge 2 commits into
mainfrom
refactor/ir-printer-boundary

Conversation

@Boreas618

Copy link
Copy Markdown
Contributor

Printer-boundary unification from the cross-layer audit:

  • Stmt's Display baked a leading \t into every instruction — the model owned the printer's layout policy. Instructions now render bare text; IrPrinter::emit_function_def owns the indent column.
  • GepStmt::fmt embedded struct/array layout computation that could fail with fmt::Error — formatting doubled as a late error path. The fallible logic is now an explicit GepStmt::render helper returning Result<_, ir::Error>, consumed by the printer's Result-returning emit path.
  • //! module docs for ir/stmt.rs and ir/printer.rs.

Emitted IR is byte-identical (diffed --emit ir against the pre-change binary across the tests/ corpus). Verified: cargo test 30/30 green.

Stmt's Display used to bake a leading tab into every instruction,
making the model own the printer's layout policy; GepStmt's Display
embedded struct/array layout computation and could fail with
fmt::Error, so formatting doubled as a late error path.

Both concerns now live at the printing boundary: instructions render
as bare text, IrPrinter::emit_function_def owns the indent column,
and the fallible GEP computation moved into the explicit
GepStmt::render helper, which the printer consumes through its
Result-returning emit path.  GepStmt keeps no Display impl of its
own; the Stmt::Gep Display arm preserves historical behaviour for
hypothetical direct consumers (text for well-typed GEPs, fmt::Error
for ill-typed ones).

Emitted IR is byte-identical (verified by diffing --emit ir output
against the pre-change binary across the tests/ corpus).
Rewrote 4 historical narratives as present-tense contracts (§3.1/§3.2): the removed-`\t` reference on Stmt's Display doc, "preserves their historical behaviour" in the GEP Display arm, "the previous fmt::Error-based failure" in GepStmt::render, and a "now needs" temporal marker on TARGET_TRIPLE. Fixed 1 stale claim against current code (§4.1/§8.1): emit_stmt's doc no longer asserts block labels are not statements — Label statements exist in the flat IR and are consumed when BasicBlocks are built. No commented-out code, dividers, or annotation tags found in these files.
@Boreas618
Boreas618 force-pushed the refactor/ir-printer-boundary branch from dd50b34 to 7f641f5 Compare August 1, 2026 10:58
@Boreas618
Boreas618 changed the base branch from assign3 to main August 1, 2026 11:12
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