diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-02-17 11:51:22 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-02-18 19:17:20 -0700 |
| commit | faa44e2e5875036b105d8b7d38ccb2e93757a3c5 (patch) | |
| tree | fc384ad77143ae6a5c7df5a19da4c2ccfef364d9 /src/Sema.zig | |
| parent | 6733e43d87d4fe7b9d89948ebb95a72515c44fee (diff) | |
| download | zig-faa44e2e5875036b105d8b7d38ccb2e93757a3c5.tar.gz zig-faa44e2e5875036b105d8b7d38ccb2e93757a3c5.zip | |
AstGen: rework multi-object for loop
* Allow unbounded looping.
* Lower by incrementing raw pointers for each iterable rather than
incrementing a single index variable. This elides safety checks
without any analysis required thanks to the length assertion and
lowers to decent machine code even in debug builds.
- An "end" value is selected, prioritizing a counter if possible,
falling back to a runtime calculation of ptr+len on a slice input.
* Specialize on the pattern `0..`, avoiding an unnecessary subtraction
instruction being emitted.
* Add the `for_check_lens` ZIR instruction.
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index cf6350e35f..b5afe93511 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -1386,6 +1386,11 @@ fn analyzeBodyInner( i += 1; continue; }, + .for_check_lens => { + try sema.zirForCheckLens(block, inst); + i += 1; + continue; + }, // Special case instructions to handle comptime control flow. .@"break" => { @@ -17096,6 +17101,16 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) return sema.popErrorReturnTrace(start_block, src, operand, saved_index); } +fn zirForCheckLens(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { + const inst_data = sema.code.instructions.items(.data)[inst].pl_node; + const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); + const args = sema.code.refSlice(extra.end, extra.data.operands_len); + const src = inst_data.src(); + + _ = args; + return sema.fail(block, src, "TODO implement zirForCheckLens", .{}); +} + fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void { assert(sema.fn_ret_ty.zigTypeTag() == .ErrorUnion); |
