flat codegen: lower a user `impl transfer` body at its site
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 14
- Forks
- 2
- Avg merge
- 12h 42m
- Merged PRs (30d)
- 61
Description
The largest remaining group in the flat corpus sweep (Vx#383) is the four programs whose transfer sema matched to a user lowering: backend/pass/custom_topology_user_lowering.vx, user_lowering_name_collisions.vx, user_lowering_uncountable.vx, user_lowering_waste.vx. flatten.rs declines at Expr::Transfer when t.lowering.is_some(), and the whole program falls to the AST path. Vx#353 tracks the feature; nothing tracks its flat-path half.
What the oracle does (codegen/lower/tensors.rs, hiraditya/Vx.1#353 A3)
It emits the vx.transfer with user_lowered so the C++ side keeps the allocation half (alloca, offsets, space propagation) and skips its own copy and barrier. Then it pastes the body into the site with (src, dst) bound to the source value and the placed tile. Inlined rather than called: a func.call inside a kernel region costs the kernel its device twin (isDeviceLowerableDialect excludes func).
The body is written against raw:: primitives (codegen/lower/mod.rs): extent (the static element count, with the linear-index unflattening the surface's flat indexing needs), load/store (memref.load/memref.store through that unflattening), barrier (gpu.barrier), async_copy (a load and a store today), async_wait (nothing).
What the flat path needs
raw::opcodes.RawExtent,RawLoad,RawStore,RawBarrier,RawAsyncCopy/RawAsyncWait, with the same unflattening in the emitter as the oracle's (a linear i64 index over a rank-N static memref). The tensor operand is a memref value the flat path already carries.- The site.
Transferkeeps itsimmand grows auser_loweredflag (imm bit, or a second opcode) so the emitter writes the attribute and the C++ side behaves as for the oracle. - Inlining. The body is a
Functiononprogram.transfer_impls, checked withlowering_edgeset. The clean shape is to lower it at the site in the HIR: bind its two parameters to the source register and the transfer's result register, then lower its statements as if written there, with the lowerer's binding maps saved and restored around it (the oracle learned that lesson the hard way; see the comment at the inlining site). Areturninside the body ends the body, not the enclosing function, solower_stmtneeds a mode for that, the same one a value-iftail already has in spirit. - Names.
user_lowering_name_collisions.vxexists because the oracle's flat name maps once leaked a body'sletinto the site. The HIR lowerer's scoped bindings make that a save/restore rather than a hazard, but the fixture will say.
Item 3 is the design choice: inline in the HIR (one lowerer, no new emitter machinery, but a body is lowered once per site) versus emit the body as a function and inline on the C++ side (one lowering, but the device-twin rule above has to be re-earned). The oracle chose the first; matching it keeps the two paths diffable.
The four fixtures run on both paths, so their CHECKs will need to hold on flat output as each lands.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with flatten.rs at Expr::Transfer and compare the oracle in codegen/lower/tensors.rs and raw primitives in codegen/lower/mod.rs. Trace transfer_impls, lowering_edge, and the HIR binding maps, then run the four fixtures—backend/pass/custom_topology_user_lowering.vx, user_lowering_name_collisions.vx, user_lowering_uncountable.vx, and user_lowering_waste.vx—on both paths; done means their CHECKs hold for flat output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100