You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
break / continue in a for await body, and nested for await, crash the compiler #502
break or continue in the body of a for await loop, and a for await nested in another, crash the compiler (0xC0000005, no message), under every memory model.
letlog="";asyncfunction*numbers(){yield1;yield2;yield3;yield4;}asyncfunction*letters(){yield"a";yield"b";}asyncfunctionmain(){forawait(constxofnumbers()){if(x==3)break;// or: if (x == 2) continue;log+=x;}print(log);}
Expected: 12 (break), 134 (continue), and 1a1b2a2b3a3b4a4b (nested).
Same on main a2a3258, and with #498's fix (PR for #498): an await in the body works, break, continue and the nested loop do not.
Where
break / continue: --emit=mlir succeeds, and the crash is in lowering (--emit=mlir-affine crashes). The body of a for await is generated inside an async.execute region (MLIRGenImpl::mlirGen(ForStatement), MLIRGenStatements.cpp), and the ts.Break / ts.Continue is inside that region, so the loop it refers to is outside it:
A branch cannot leave the region, and the lowering that looks for the enclosing loop finds none.
Nested for await: --emit=mlir itself crashes, during MLIR generation.
Possible fix
The body is an async.execute only so that an await in it has an async region. One option is to generate the body directly in the loop (like a plain for...of in an async function, where await already works), dropping the extra region. Then break and continue reach the loop, and nesting needs nothing special. Failing that, report break / continue in a for await body as an error rather than crashing.
Activity
break and continue in a for await body, and nested for await (#502) (#…