AstGen: fix loop result locations
The main problem was that the loop body was treated as an expression that was one of the peer result values of a loop, when in reality the loop body is noreturn and only the `break` operands are the result values of loops. This was solved by introducing an override that prevents rvalue() from emitting a store to result location instruction for loop bodies. An orthogonal change also included in this commit is switching `elem_val` index expressions to using `coerced_ty` and doing the coercion to `usize` inside `Sema`, resulting in smaller ZIR (since the cast becomes implied). I also changed the break operand expression to use `reachableExpr`, introducing a new compile error for double break. This makes a few more behavior tests pass for `while` and `for` loops.
This commit is contained in:
@@ -12528,7 +12528,7 @@ fn elemVal(
|
||||
block: *Block,
|
||||
src: LazySrcLoc,
|
||||
array: Air.Inst.Ref,
|
||||
elem_index: Air.Inst.Ref,
|
||||
elem_index_uncasted: Air.Inst.Ref,
|
||||
elem_index_src: LazySrcLoc,
|
||||
) CompileError!Air.Inst.Ref {
|
||||
const array_src = src; // TODO better source location
|
||||
@@ -12538,6 +12538,8 @@ fn elemVal(
|
||||
return sema.fail(block, src, "array access of non-indexable type '{}'", .{array_ty});
|
||||
}
|
||||
|
||||
const elem_index = try sema.coerce(block, Type.usize, elem_index_uncasted, elem_index_src);
|
||||
|
||||
switch (array_ty.zigTypeTag()) {
|
||||
.Pointer => switch (array_ty.ptrSize()) {
|
||||
.Slice => {
|
||||
|
||||
Reference in New Issue
Block a user