Loading...
Loading...
Migrates Mojo code off legacy parametric closures (`capturing[_]`, `@__parameter` / `@parameter`, `api[fn](args)`) onto value-taking unified closures (`api(args, fn)` with `{imm}` / `{mut}` / `{var}` / named capture lists). Use when removing parametric overloads, fixing "capturing thin" conversion errors, rewriting nested launch/callback closures, or migrating any API that took a comptime function parameter.
npx skill4agent add modular/skills closure_migrationmojo-syntaxmojo-gpu-fundamentals@__parameter@parameter*_value| Do not | Do instead |
|---|---|
| Unified |
| Make the body unified; pass it as a value |
| File-scope / normal function with an imm parameter |
| Capture list ( |
Keep | Migrate or widen that API to value-taking; do not paper over it |
capturing[_]def … capturing -> T@__parameter@__parametercapturingresidual_buf: DeviceBuffer[…]var| Legacy | Preferred |
|---|---|
| |
Comptime param | |
Nested | Unified |
@__parametercapturing thinFuncType@__parameterrg 'api_name\[' --glob '*.mojo'rg '@__parameter|@parameter' --glob '*.mojo'api[fn](a, b)api(a, fn, b)@__parameter@parameter@__copy_capture@__parametermojo build --emit llvm <file> -o /tmp/x.llrg '@__parameter|@parameter' --glob '<touched>.mojo'| Default / symptom | Choice |
|---|---|
| Read-only use of outer state | |
Mutates some outer state; also reads | |
| Mutates several outer names | |
| Needs ownership / move | |
| Named precision only | |
| No free runtime captures | |
| Add |
| That name needs |
| Capture-all |
| Buffer captured |
| |
| |
| Capture list on an |
| Closure struct would hold fields that alias the same origin, one mut and one imm — see Aliasing below |
| |
{mut}Intmutimm{mut tt_in, imm}immmutvar{imm}TileTensor.unsafe_ptr()mut=Trueself._buf.unsafe_ptr()unsafe_mut_cast[True]()CacheBustingBuffer.offset_ptrselflit.call{mut cb_a, mut cb_b, mut cb_c, mut cb_a_scales, mut cb_b_scales, imm}unsafe_mut_cast@__parametermutDeviceBufferas_immut(){mut …}var bufbufbuf: DeviceBuffer[…]enqueue_memsetDeviceBuffer{mut buf, …}origin_of(buf){imm}bufmut buf{mut buf, imm}mut buf: …FuncType{mut buf, imm}buf.as_unsafe_any_origin()@__parameter{mut count}name[i] =with … as namemut@__parameter@parameter