Skip to content

feat(inspection,parser): print placed types as parser sugar - #166

Merged
zhen8838 merged 21 commits into
tile-ai:mainfrom
zhen8838:test/render-golden-final
Sep 14, 2026
Merged

zhen8838 merged 21 commits into
tile-ai:mainfrom
zhen8838:test/render-golden-final

Conversation

@zhen8838

@zhen8838 zhen8838 commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Why

  • PR feat(inspection,parser): print placed types as parser sugar #166's review: the printer dispatched types through render_value() instead of visiting each expression's type; render_* methods shadowed visit_*; the goldens showed canonical ShardLayout(...) dataclasses instead of parser sugar; the fixtures were too simple to show a composed mesh, a broadcast and a partial together; and the work had grown four tests where two were asked for.
  • The sugar the printer already emitted was never readable back: ((dims), (strides)) and {axis @ P("sum")} had no parser production at all, and a bare (8,) reparsed as a plain Layout that dropped the mesh.

What

  • PythonPrinter inherits PythonTypePrinter. Every type has exactly one visit_<Type>, expression printers emit expr.type through self.visit, and the render_* parallel entries and owner back-delegation are gone.
  • One parser production covers the whole layout sugar — dims with each split written on the dimension it divides, an optional stride tuple, and an optional {axis @ B(), axis @ P("sum")} set. ExplicitLayoutPattern folds into it.
  • Every shard layout over a named mesh prints as that sugar, in type slots and in op-attribute slots. The TIR fixtures are authored in it and print back to their own source.
  • Structurally identical meshes share one prelude name, and a printed type names only a mesh the prelude binds.
  • Withdrew PR feat(inspection,parser): print placed types as parser sugar #166's footprint-by-level projection, its details opt-in, and the spec text describing them, along with the fixtures and tests that existed only to pin that projection.

Contract

  • docs/spec/inspection.md §2.3 states when the printer MUST use placement sugar and how it writes splits, strides and value states; §2.5 states one name per mesh descriptor and no named mesh the prelude does not bind.
  • docs/spec/parser.md's generated grammar: placed-layout now carries the stride tuple and the value-state set; explicit-layout is gone.
  • An unstated stride tuple stays the sugar default a Reshard materializes from the storage tier it moves between; the sugar states strides whenever the layout has them.
  • TensorView.layout is annotated LayoutBase, so its slot parses as a layout.
  • tests/inspection/test_tir_roundtrip.py asserts fixture source equality again, as inspection §2.7 requires.

Risk

  • tests/fixtures/tir/mma.py uses placement sugar with named warp/lane axes; the CUDA MMA tile scope uses the same mesh names so atom fragment layouts remain structurally equal.
  • Annotations are longer now that they state strides. That is what makes an annotation name the same layout the emitted code does.

Comment thread docs/spec/analysis.md Outdated
Comment thread docs/spec/inspection.md Outdated
Comment thread src/tilefoundry/inspection/printer_base.py
Comment thread src/tilefoundry/inspection/printer_base.py Outdated
Comment thread src/tilefoundry/inspection/python_type_printer.py Outdated
Comment thread tests/fixtures/hir/tensor_types.py Outdated
Comment thread tests/inspection/golden/tensor_types.loop_nest.analyze.golden Outdated
Comment thread tests/inspection/golden/tensor_types.loop_nest.golden Outdated
Comment thread tests/inspection/golden/tensor_types.loop_nest.analyze.golden Outdated
Comment thread tests/inspection/test_analyze_render_golden.py Outdated
zhen8838 added a commit to zhen8838/TileFoundry that referenced this pull request Sep 13, 2026
…added

Summing LoopFootprintMetadata.footprints by storage level, the `details`
opt-in that recovered the per-buffer rows, and the analysis spec text
describing both had no reproduced problem behind them: the review's finding
was about a printer duplicating metadata, not about how footprints project.

The fixtures, goldens and focused tests that only existed to pin that
projection go with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@zhen8838 zhen8838 changed the title test(inspection): lock canonical type and analysis goldens feat(inspection,parser): print placed types as parser sugar Sep 13, 2026
PythonPrinter now inherits PythonTypePrinter instead of owning one, so an
expression printer emits `expr.type` through the same `visit` that emits the
type's children. Every `render_<Type>` entry folds into its `visit_<Type>`,
and the `owner` back-delegation is gone.

Mesh aliases are now filtered to the ones the prelude actually binds, so
naming a mesh inside a printed type can no longer emit an undefined
reference.
…added

Summing LoopFootprintMetadata.footprints by storage level, the `details`
opt-in that recovered the per-buffer rows, and the analysis spec text
describing both had no reproduced problem behind them: the review's finding
was about a printer duplicating metadata, not about how footprints project.

The fixtures, goldens and focused tests that only existed to pin that
projection go with it.
The printer could already emit `((dims), (strides))` and `{axis @ P(...)}`
that nothing could read back, and it fell back to the verbose
`ShardLayout(...)` whenever a function held more than one mesh. One parser
production now covers the whole sugar — dims with splits written inline, an
optional stride tuple, and an optional value-state set — so the printer can
emit sugar for every shard layout over a named mesh.

A layout whose mesh axes are all Broadcast now states them, instead of
relying on "the active mesh"; the bare form it used to emit reparsed as a
plain Layout and silently dropped the mesh.

Meshes with the same descriptor share one prelude name, and a printed type
names only a mesh the prelude binds, so a composed mesh rebuilt at each use
site no longer produces a prelude line per copy or an undefined reference.

The TIR fixtures are authored in that sugar and print back to their own
source again, restoring the round-trip contract inspection §2.7 states.
The analyze golden reads the same fixture the round-trip golden does, so a
type that prints one way in emitted code and another inside an annotation is
a diff here rather than two goldens drifting apart.
An unstated stride tuple is not shorthand for C-order: it is the sugar
default a `Reshard` materializes from the storage tier it moves between, so
printing a stated C-order tuple as absent turned one layout into another and
left TIR views with no strides for CUDA codegen to emit.

`render_mode()` and `mesh_count()` go with it — the shared type visitor left
both without a caller.
…adata

`main` now reports compute cost and traffic per topology level, so the
golden's metadata comments carry `cta:`/`thread:` breakdowns. The type text
the goldens exist to pin is unchanged.
zhen8838 added a commit to zhen8838/TileFoundry that referenced this pull request Sep 13, 2026
…added

Summing LoopFootprintMetadata.footprints by storage level, the `details`
opt-in that recovered the per-buffer rows, and the analysis spec text
describing both had no reproduced problem behind them: the review's finding
was about a printer duplicating metadata, not about how footprints project.

The fixtures, goldens and focused tests that only existed to pin that
projection go with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@zhen8838
zhen8838 force-pushed the test/render-golden-final branch from 2c357d0 to 4d56e19 Compare September 13, 2026 07:39
The page reproduces itself from its own blocks, so the reshard it displays
is now the one-line placement sugar rather than a five-line `ShardLayout`,
and the window it prints reaches the matmul that consumes the weight.
Comment thread docs/spec/parser.md Outdated
Comment thread docs/spec/parser.md Outdated
Comment thread src/tilefoundry/inspection/python_printer.py Outdated
Comment thread src/tilefoundry/inspection/python_printer.py Outdated
Comment thread src/tilefoundry/inspection/python_printer.py Outdated
Comment thread src/tilefoundry/inspection/python_printer.py Outdated
Comment thread src/tilefoundry/inspection/python_printer.py Outdated
Comment thread src/tilefoundry/inspection/python_type_printer.py Outdated
Comment thread tests/fixtures/tir/mma.py Outdated
Comment thread tests/fixtures/tir/sync.py Outdated
`named_and_out_of_scope` adds a layout the author names rather than spells,
and a reshard onto a mesh its scope never enters -- reshard is the one
operation allowed to cross that boundary, so its target names a mesh that is
not the scope it runs in.

The golden records what the printer does with them today: the named layout is
expanded back into sugar, the out-of-scope target is written as `thread.warp`
from inside `with cta`, and `@func(mesh=...)` comes back as a `with` in the
body. All three are wrong and none of them had a test.
`composed_mesh_pipeline` reshards to the same constant `named_and_out_of_scope`
holds as a parameter. One function enters that constant's mesh with a `with`;
the other never does.

The golden records both printing identically today. Only the first has a scope
binding a sugar identifier could refer to, so only the first should keep the
sugar once the printer requires one.
A placement states two things — the extents as written, and where they go —
and the layout it implies keeps only the second, divided beyond recovery. So
the shape slot could not reuse the layout slot's pattern: it copied the whole
syntax tree and recovered the extents itself, and `docs/spec/parser.md`
carried that copy as a second production, word for word.

One pattern now answers both halves and each slot takes the part it asked
for. The rules follow: what sat on the placement were the layout slot's
rules, so a placement's own rule reaches the constraints table for the first
time and `PlacedShapeRule` goes with the pattern it guarded.
@zhen8838
zhen8838 force-pushed the test/render-golden-final branch from 1db7e80 to 0a506dd Compare September 14, 2026 03:44
Comment thread tests/fixtures/inspection/type_printer_sugar.analyzed.txt Outdated
Comment thread tests/fixtures/inspection/type_printer_sugar.printed.txt Outdated
Comment thread tests/fixtures/inspection/type_printer_sugar.analyzed.txt Outdated
@zhen8838
zhen8838 merged commit 2af2364 into tile-ai:main Sep 14, 2026
1 check passed
@zhen8838
zhen8838 deleted the test/render-golden-final branch September 14, 2026 16:46
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