Skip to content

[compiler] carry Python containers through dynamic if/for/while/ifexp#874

Draft
xudoyuan wants to merge 3 commits into
mainfrom
xudoyuan/dyn-cf-list-carry
Draft

[compiler] carry Python containers through dynamic if/for/while/ifexp#874
xudoyuan wants to merge 3 commits into
mainfrom
xudoyuan/dyn-cf-list-carry

Conversation

@xudoyuan

Copy link
Copy Markdown
Collaborator

Dynamic scf.if / scf.for / scf.while / ifexp previously required every carried variable to be a single ir.Value, so a reassigned list/tuple/dict local raised "state variable '...' is list, not an MLIR Value".

Route the four dispatchers through an explode/assemble step that reuses the existing DSL<->ir.Value protocol (protocol.extract/construct): each carried value (possibly a nested container) is exploded to per-element iter_args/ results and assembled back from the pre-region value used as the structural template on exit. Scalars stay the degenerate single-slot case so existing behaviour is unchanged; a branch/body that changes a container's shape or an element's dtype now fails with a clear error.

Adds MLIR-level unit tests and device system tests for list/tuple/dict/nested carry across if/for/while/ifexp.

Motivation

Technical Details

Test Plan

Test Result

Submission Checklist

xudoyuan and others added 3 commits July 20, 2026 10:23
Dynamic scf.if / scf.for / scf.while / ifexp previously required every
carried variable to be a single ir.Value, so a reassigned list/tuple/dict
local raised "state variable '...' is list, not an MLIR Value".

Route the four dispatchers through an explode/assemble step that reuses the
existing DSL<->ir.Value protocol (protocol.extract/construct): each carried
value (possibly a nested container) is exploded to per-element iter_args/
results and assembled back from the pre-region value used as the structural
template on exit. Scalars stay the degenerate single-slot case so existing
behaviour is unchanged; a branch/body that changes a container's shape or an
element's dtype now fails with a clear error.

Adds MLIR-level unit tests and device system tests for list/tuple/dict/nested
carry across if/for/while/ifexp.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The device/launch test belongs with the other end-to-end tests under
tests/system (renamed to the *_e2e.py convention); the MLIR-level unit test
stays under tests/unit. Aligns the header with the existing e2e tests
(direct torch import + skip).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rename the test class to *E2E, reword the module docstring, and use the
direct `import torch` + skip style shared by the other tests/system e2e files.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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