authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-17 16:39:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-18 19:17:20-07:00
log293d6bdc73c5fe01b07ebe3d09c9a78613fed093
treeff2ab85b168aa731fcdf1ddb530ed70d1c285245
parent841add6890d001d315591dc20f7d464c264d88bb

AstGen: back to index-based for loops


4 files changed, 106 insertions(+), 143 deletions(-)

src/AstGen.zig+71-88
......@@ -88,7 +88,6 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
8888 Zir.Inst.BuiltinCall.Flags => @bitCast(u32, @field(extra, field.name)),
8989 Zir.Inst.SwitchBlock.Bits => @bitCast(u32, @field(extra, field.name)),
9090 Zir.Inst.FuncFancy.Bits => @bitCast(u32, @field(extra, field.name)),
91 Zir.Inst.ElemPtrImm.Bits => @bitCast(u32, @field(extra, field.name)),
9291 else => @compileError("bad field type"),
9392 };
9493 i += 1;
......@@ -1566,9 +1565,7 @@ fn arrayInitExprRlPtrInner(
15661565 for (elements) |elem_init, i| {
15671566 const elem_ptr = try gz.addPlNode(.elem_ptr_imm, elem_init, Zir.Inst.ElemPtrImm{
15681567 .ptr = result_ptr,
1569 .bits = .{
1570 .index = @intCast(u31, i),
1571 },
1568 .index = @intCast(u32, i),
15721569 });
15731570 astgen.extra.items[extra_index] = refToIndex(elem_ptr).?;
15741571 extra_index += 1;
......@@ -2601,6 +2598,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
26012598 .field_base_ptr,
26022599 .ret_ptr,
26032600 .ret_type,
2601 .for_len,
26042602 .@"try",
26052603 .try_ptr,
26062604 //.try_inline,
......@@ -2669,7 +2667,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
26692667 .validate_deref,
26702668 .save_err_ret_index,
26712669 .restore_err_ret_index,
2672 .for_check_lens,
26732670 => break :b true,
26742671
26752672 .@"defer" => unreachable,
......@@ -6305,23 +6302,26 @@ fn forExpr(
63056302 const node_data = tree.nodes.items(.data);
63066303 const gpa = astgen.gpa;
63076304
6308 const allocs = try gpa.alloc(Zir.Inst.Ref, for_full.ast.inputs.len);
6309 defer gpa.free(allocs);
6305 // For counters, this is the start value; for indexables, this is the base
6306 // pointer that can be used with elem_ptr and similar instructions.
6307 // Special value `none` means that this is a counter and its start value is
6308 // zero, indicating that the main index counter can be used directly.
6309 const indexables = try gpa.alloc(Zir.Inst.Ref, for_full.ast.inputs.len);
6310 defer gpa.free(indexables);
63106311 // elements of this array can be `none`, indicating no length check.
63116312 const lens = try gpa.alloc(Zir.Inst.Ref, for_full.ast.inputs.len);
63126313 defer gpa.free(lens);
63136314
6314 const alloc_tag: Zir.Inst.Tag = if (is_inline) .alloc_comptime_mut else .alloc_mut;
6315 // We will use a single zero-based counter no matter how many indexables there are.
6316 const index_ptr = blk: {
6317 const alloc_tag: Zir.Inst.Tag = if (is_inline) .alloc_comptime_mut else .alloc;
6318 const index_ptr = try parent_gz.addUnNode(alloc_tag, .usize_type, node);
6319 // initialize to zero
6320 _ = try parent_gz.addBin(.store, index_ptr, .zero_usize);
6321 break :blk index_ptr;
6322 };
63156323
6316 // Tracks the index of allocs/lens that has a length to be checked and is
6317 // used for the end value.
6318 // If this is null, there are no len checks.
6319 var end_input_index: ?u32 = null;
6320 // This is a value to use to find out if the for loop has reached the end
6321 // yet. It prefers to use a counter since the end value is provided directly,
6322 // and otherwise falls back to adding ptr+len of a slice to compute end.
6323 // Corresponds to end_input_index and will be .none in case that value is null.
6324 var cond_end_val: Zir.Inst.Ref = .none;
6324 var any_len_checks = false;
63256325
63266326 {
63276327 var capture_token = for_full.payload_token;
......@@ -6341,10 +6341,8 @@ fn forExpr(
63416341 if (capture_is_ref) {
63426342 return astgen.failTok(ident_tok, "cannot capture reference to range", .{});
63436343 }
6344 const counter_ptr = try parent_gz.addUnNode(alloc_tag, .usize_type, node);
63456344 const start_node = node_data[input].lhs;
63466345 const start_val = try expr(parent_gz, scope, .{ .rl = .none }, start_node);
6347 _ = try parent_gz.addBin(.store, counter_ptr, start_val);
63486346
63496347 const end_node = node_data[input].rhs;
63506348 const end_val = if (end_node != 0)
......@@ -6352,7 +6350,8 @@ fn forExpr(
63526350 else
63536351 .none;
63546352
6355 const range_len = if (end_val == .none or nodeIsTriviallyZero(tree, start_node))
6353 const start_is_zero = nodeIsTriviallyZero(tree, start_node);
6354 const range_len = if (end_val == .none or start_is_zero)
63566355 end_val
63576356 else
63586357 try parent_gz.addPlNode(.sub, input, Zir.Inst.Bin{
......@@ -6360,61 +6359,33 @@ fn forExpr(
63606359 .rhs = start_val,
63616360 });
63626361
6363 if (range_len != .none and cond_end_val == .none) {
6364 end_input_index = i;
6365 cond_end_val = end_val;
6366 }
6367
6368 allocs[i] = counter_ptr;
6362 any_len_checks = any_len_checks or range_len != .none;
6363 indexables[i] = if (start_is_zero) .none else start_val;
63696364 lens[i] = range_len;
63706365 } else {
63716366 const indexable = try expr(parent_gz, scope, .{ .rl = .none }, input);
6372 // This instruction has nice compile errors so we put it before the other ones
6373 // even though it is not needed until later in the block.
6374 const ptr_len = try parent_gz.addUnNode(.indexable_ptr_len, indexable, input);
6375 const base_ptr = try parent_gz.addPlNode(.elem_ptr_imm, input, Zir.Inst.ElemPtrImm{
6376 .ptr = indexable,
6377 .bits = .{
6378 .index = 0,
6379 .manyptr = true,
6380 },
6381 });
6382 const alloc_ty_inst = try parent_gz.addUnNode(.typeof, base_ptr, node);
6383 const alloc = try parent_gz.addUnNode(alloc_tag, alloc_ty_inst, node);
6384 _ = try parent_gz.addBin(.store, alloc, base_ptr);
6385
6386 if (end_input_index == null) {
6387 end_input_index = i;
6388 assert(cond_end_val == .none);
6389 }
6367 const indexable_len = try parent_gz.addUnNode(.indexable_ptr_len, indexable, input);
63906368
6391 allocs[i] = alloc;
6392 lens[i] = ptr_len;
6369 any_len_checks = true;
6370 indexables[i] = indexable;
6371 lens[i] = indexable_len;
63936372 }
63946373 }
63956374 }
63966375
6397 // In case there are no counters which already have an end computed, we
6398 // compute an end from base pointer plus length.
6399 if (end_input_index) |i| {
6400 if (cond_end_val == .none) {
6401 cond_end_val = try parent_gz.addPlNode(.add, for_full.ast.inputs[i], Zir.Inst.Bin{
6402 .lhs = allocs[i],
6403 .rhs = lens[i],
6404 });
6405 }
6406 }
6407
64086376 // We use a dedicated ZIR instruction to assert the lengths to assist with
64096377 // nicer error reporting as well as fewer ZIR bytes emitted.
6410 if (end_input_index != null) {
6378 const len: Zir.Inst.Ref = len: {
6379 if (!any_len_checks) break :len .none;
6380
64116381 const lens_len = @intCast(u32, lens.len);
64126382 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.MultiOp).Struct.fields.len + lens_len);
6413 _ = try parent_gz.addPlNode(.for_check_lens, node, Zir.Inst.MultiOp{
6383 const len = try parent_gz.addPlNode(.for_len, node, Zir.Inst.MultiOp{
64146384 .operands_len = lens_len,
64156385 });
64166386 appendRefsAssumeCapacity(astgen, lens);
6417 }
6387 break :len len;
6388 };
64186389
64196390 const loop_tag: Zir.Inst.Tag = if (is_inline) .block_inline else .loop;
64206391 const loop_block = try parent_gz.makeBlockInst(loop_tag, node);
......@@ -6429,22 +6400,14 @@ fn forExpr(
64296400 var cond_scope = parent_gz.makeSubBlock(&loop_scope.base);
64306401 defer cond_scope.unstack();
64316402
6432 // Load all the iterables.
6433 const loaded_ptrs = try gpa.alloc(Zir.Inst.Ref, allocs.len);
6434 defer gpa.free(loaded_ptrs);
6435 for (allocs) |alloc, i| {
6436 loaded_ptrs[i] = try cond_scope.addUnNode(.load, alloc, for_full.ast.inputs[i]);
6437 }
6438
64396403 // Check the condition.
6440 const input_index = end_input_index orelse {
6404 if (!any_len_checks) {
64416405 return astgen.failNode(node, "TODO: handle infinite for loop", .{});
6442 };
6443 assert(cond_end_val != .none);
6444
6445 const cond = try cond_scope.addPlNode(.cmp_neq, for_full.ast.inputs[input_index], Zir.Inst.Bin{
6446 .lhs = loaded_ptrs[input_index],
6447 .rhs = cond_end_val,
6406 }
6407 const index = try cond_scope.addUnNode(.load, index_ptr, node);
6408 const cond = try cond_scope.addPlNode(.cmp_lt, node, Zir.Inst.Bin{
6409 .lhs = index,
6410 .rhs = len,
64486411 });
64496412
64506413 const condbr_tag: Zir.Inst.Tag = if (is_inline) .condbr_inline else .condbr;
......@@ -6455,14 +6418,12 @@ fn forExpr(
64556418 // cond_block unstacked now, can add new instructions to loop_scope
64566419 try loop_scope.instructions.append(gpa, cond_block);
64576420
6458 // Increment the loop variables.
6459 for (allocs) |alloc, i| {
6460 const incremented = try loop_scope.addPlNode(.add, node, Zir.Inst.Bin{
6461 .lhs = loaded_ptrs[i],
6462 .rhs = .one_usize,
6463 });
6464 _ = try loop_scope.addBin(.store, alloc, incremented);
6465 }
6421 // Increment the index variable.
6422 const index_plus_one = try loop_scope.addPlNode(.add, node, Zir.Inst.Bin{
6423 .lhs = index,
6424 .rhs = .one_usize,
6425 });
6426 _ = try loop_scope.addBin(.store, index_ptr, index_plus_one);
64666427 const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat;
64676428 _ = try loop_scope.addNode(repeat_tag, node);
64686429
......@@ -6500,21 +6461,43 @@ fn forExpr(
65006461 const name_str_index = try astgen.identAsString(ident_tok);
65016462 try astgen.detectLocalShadowing(capture_sub_scope, name_str_index, ident_tok, capture_name, .capture);
65026463
6503 const loaded = if (capture_is_ref)
6504 loaded_ptrs[i]
6505 else
6506 try then_scope.addUnNode(.load, loaded_ptrs[i], input);
6464 const capture_inst = inst: {
6465 const is_counter = node_tags[input] == .for_range;
6466
6467 if (indexables[i] == .none) {
6468 // Special case: the main index can be used directly.
6469 assert(is_counter);
6470 assert(!capture_is_ref);
6471 break :inst index;
6472 }
6473
6474 // For counters, we add the index variable to the start value; for
6475 // indexables, we use it as an element index. This is so similar
6476 // that they can share the same code paths, branching only on the
6477 // ZIR tag.
6478 const switch_cond = (@as(u2, @boolToInt(capture_is_ref)) << 1) | @boolToInt(is_counter);
6479 const tag: Zir.Inst.Tag = switch (switch_cond) {
6480 0b00 => .elem_val,
6481 0b01 => .add,
6482 0b10 => .elem_ptr,
6483 0b11 => unreachable, // compile error emitted already
6484 };
6485 break :inst try then_scope.addPlNode(tag, input, Zir.Inst.Bin{
6486 .lhs = indexables[i],
6487 .rhs = index,
6488 });
6489 };
65076490
65086491 capture_scopes[i] = .{
65096492 .parent = capture_sub_scope,
65106493 .gen_zir = &then_scope,
65116494 .name = name_str_index,
6512 .inst = loaded,
6495 .inst = capture_inst,
65136496 .token_src = ident_tok,
65146497 .id_cat = .capture,
65156498 };
65166499
6517 try then_scope.addDbgVar(.dbg_var_val, name_str_index, loaded);
6500 try then_scope.addDbgVar(.dbg_var_val, name_str_index, capture_inst);
65186501 capture_sub_scope = &capture_scopes[i].base;
65196502 }
65206503
src/Sema.zig+26-37
......@@ -1035,6 +1035,7 @@ fn analyzeBodyInner(
10351035 .@"await" => try sema.zirAwait(block, inst),
10361036 .array_base_ptr => try sema.zirArrayBasePtr(block, inst),
10371037 .field_base_ptr => try sema.zirFieldBasePtr(block, inst),
1038 .for_len => try sema.zirForLen(block, inst),
10381039
10391040 .clz => try sema.zirBitCount(block, inst, .clz, Value.clz),
10401041 .ctz => try sema.zirBitCount(block, inst, .ctz, Value.ctz),
......@@ -1386,11 +1387,6 @@ fn analyzeBodyInner(
13861387 i += 1;
13871388 continue;
13881389 },
1389 .for_check_lens => {
1390 try sema.zirForCheckLens(block, inst);
1391 i += 1;
1392 continue;
1393 },
13941390
13951391 // Special case instructions to handle comptime control flow.
13961392 .@"break" => {
......@@ -3924,6 +3920,16 @@ fn zirFieldBasePtr(
39243920 return sema.failWithStructInitNotSupported(block, src, sema.typeOf(start_ptr).childType());
39253921}
39263922
3923fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3924 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3925 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
3926 const args = sema.code.refSlice(extra.end, extra.data.operands_len);
3927 const src = inst_data.src();
3928
3929 _ = args;
3930 return sema.fail(block, src, "TODO implement zirForCheckLens", .{});
3931}
3932
39273933fn validateArrayInitTy(
39283934 sema: *Sema,
39293935 block: *Block,
......@@ -9649,7 +9655,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
96499655 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
96509656 const array_ptr = try sema.resolveInst(extra.lhs);
96519657 const elem_index = try sema.resolveInst(extra.rhs);
9652 return sema.elemPtr(block, src, array_ptr, elem_index, src, false, .One);
9658 return sema.elemPtr(block, src, array_ptr, elem_index, src, false);
96539659}
96549660
96559661fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -9662,7 +9668,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
96629668 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
96639669 const array_ptr = try sema.resolveInst(extra.lhs);
96649670 const elem_index = try sema.resolveInst(extra.rhs);
9665 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src, false, .One);
9671 return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src, false);
96669672}
96679673
96689674fn zirElemPtrImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -9673,9 +9679,8 @@ fn zirElemPtrImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
96739679 const src = inst_data.src();
96749680 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
96759681 const array_ptr = try sema.resolveInst(extra.ptr);
9676 const elem_index = try sema.addIntUnsigned(Type.usize, extra.bits.index);
9677 const size: std.builtin.Type.Pointer.Size = if (extra.bits.manyptr) .Many else .One;
9678 return sema.elemPtr(block, src, array_ptr, elem_index, src, true, size);
9682 const elem_index = try sema.addIntUnsigned(Type.usize, extra.index);
9683 return sema.elemPtr(block, src, array_ptr, elem_index, src, true);
96799684}
96809685
96819686fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -17102,16 +17107,6 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index)
1710217107 return sema.popErrorReturnTrace(start_block, src, operand, saved_index);
1710317108}
1710417109
17105fn zirForCheckLens(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
17106 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
17107 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
17108 const args = sema.code.refSlice(extra.end, extra.data.operands_len);
17109 const src = inst_data.src();
17110
17111 _ = args;
17112 return sema.fail(block, src, "TODO implement zirForCheckLens", .{});
17113}
17114
1711517110fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {
1711617111 assert(sema.fn_ret_ty.zigTypeTag() == .ErrorUnion);
1711717112
......@@ -22906,7 +22901,7 @@ fn panicSentinelMismatch(
2290622901 const actual_sentinel = if (ptr_ty.isSlice())
2290722902 try parent_block.addBinOp(.slice_elem_val, ptr, sentinel_index)
2290822903 else blk: {
22909 const elem_ptr_ty = try sema.elemPtrType(ptr_ty, null, .One);
22904 const elem_ptr_ty = try sema.elemPtrType(ptr_ty, null);
2291022905 const sentinel_ptr = try parent_block.addPtrElemPtr(ptr, sentinel_index, elem_ptr_ty);
2291122906 break :blk try parent_block.addTyOp(.load, sentinel_ty, sentinel_ptr);
2291222907 };
......@@ -24073,7 +24068,6 @@ fn elemPtr(
2407324068 elem_index: Air.Inst.Ref,
2407424069 elem_index_src: LazySrcLoc,
2407524070 init: bool,
24076 size: std.builtin.Type.Pointer.Size,
2407724071) CompileError!Air.Inst.Ref {
2407824072 const indexable_ptr_src = src; // TODO better source location
2407924073 const indexable_ptr_ty = sema.typeOf(indexable_ptr);
......@@ -24100,12 +24094,13 @@ fn elemPtr(
2410024094 const index_val = maybe_index_val orelse break :rs elem_index_src;
2410124095 const index = @intCast(usize, index_val.toUnsignedInt(target));
2410224096 const elem_ptr = try ptr_val.elemPtr(indexable_ty, sema.arena, index, sema.mod);
24103 const elem_ptr_ty = try sema.elemPtrType(indexable_ty, index, size);
24104 return sema.addConstant(elem_ptr_ty, elem_ptr);
24097 const result_ty = try sema.elemPtrType(indexable_ty, index);
24098 return sema.addConstant(result_ty, elem_ptr);
2410524099 };
24106 const elem_ptr_ty = try sema.elemPtrType(indexable_ty, null, size);
24100 const result_ty = try sema.elemPtrType(indexable_ty, null);
24101
2410724102 try sema.requireRuntimeBlock(block, src, runtime_src);
24108 return block.addPtrElemPtr(indexable, elem_index, elem_ptr_ty);
24103 return block.addPtrElemPtr(indexable, elem_index, result_ty);
2410924104 },
2411024105 .One => {
2411124106 assert(indexable_ty.childType().zigTypeTag() == .Array); // Guaranteed by isIndexable
......@@ -24167,7 +24162,7 @@ fn elemVal(
2416724162 },
2416824163 .One => {
2416924164 assert(indexable_ty.childType().zigTypeTag() == .Array); // Guaranteed by isIndexable
24170 const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false, .One);
24165 const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false);
2417124166 return sema.analyzeLoad(block, indexable_src, elem_ptr, elem_index_src);
2417224167 },
2417324168 },
......@@ -24405,7 +24400,7 @@ fn elemPtrArray(
2440524400 break :o index;
2440624401 } else null;
2440724402
24408 const elem_ptr_ty = try sema.elemPtrType(array_ptr_ty, offset, .One);
24403 const elem_ptr_ty = try sema.elemPtrType(array_ptr_ty, offset);
2440924404
2441024405 if (maybe_undef_array_ptr_val) |array_ptr_val| {
2441124406 if (array_ptr_val.isUndef()) {
......@@ -24510,7 +24505,7 @@ fn elemPtrSlice(
2451024505 break :o index;
2451124506 } else null;
2451224507
24513 const elem_ptr_ty = try sema.elemPtrType(slice_ty, offset, .One);
24508 const elem_ptr_ty = try sema.elemPtrType(slice_ty, offset);
2451424509
2451524510 if (maybe_undef_slice_val) |slice_val| {
2451624511 if (slice_val.isUndef()) {
......@@ -26240,7 +26235,7 @@ fn storePtr2(
2624026235 const elem_src = operand_src; // TODO better source location
2624126236 const elem = try sema.tupleField(block, operand_src, uncasted_operand, elem_src, i);
2624226237 const elem_index = try sema.addIntUnsigned(Type.usize, i);
26243 const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false, .One);
26238 const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false);
2624426239 try sema.storePtr2(block, src, elem_ptr, elem_src, elem, elem_src, .store);
2624526240 }
2624626241 return;
......@@ -33277,12 +33272,7 @@ fn compareVector(
3327733272/// For []T, returns *T
3327833273/// Handles const-ness and address spaces in particular.
3327933274/// This code is duplicated in `analyzePtrArithmetic`.
33280fn elemPtrType(
33281 sema: *Sema,
33282 ptr_ty: Type,
33283 offset: ?usize,
33284 size: std.builtin.Type.Pointer.Size,
33285) !Type {
33275fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3328633276 const ptr_info = ptr_ty.ptrInfo().data;
3328733277 const elem_ty = ptr_ty.elemType2();
3328833278 const allow_zero = ptr_info.@"allowzero" and (offset orelse 0) == 0;
......@@ -33327,7 +33317,6 @@ fn elemPtrType(
3332733317 break :a new_align;
3332833318 };
3332933319 return try Type.ptr(sema.arena, sema.mod, .{
33330 .size = size,
3333133320 .pointee_type = elem_ty,
3333233321 .mutable = ptr_info.mutable,
3333333322 .@"addrspace" = ptr_info.@"addrspace",
src/Zir.zig+7-14
......@@ -79,7 +79,6 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) struct { data: T, en
7979 Inst.BuiltinCall.Flags => @bitCast(Inst.BuiltinCall.Flags, code.extra[i]),
8080 Inst.SwitchBlock.Bits => @bitCast(Inst.SwitchBlock.Bits, code.extra[i]),
8181 Inst.FuncFancy.Bits => @bitCast(Inst.FuncFancy.Bits, code.extra[i]),
82 Inst.ElemPtrImm.Bits => @bitCast(Inst.ElemPtrImm.Bits, code.extra[i]),
8382 else => @compileError("bad field type"),
8483 };
8584 i += 1;
......@@ -501,14 +500,14 @@ pub const Inst = struct {
501500 /// Uses the `node` field.
502501 repeat_inline,
503502 /// Asserts that all the lengths provided match. Used to build a for loop.
504 /// Return value is always void.
503 /// Return value is the length as a usize.
505504 /// Uses the `pl_node` field with payload `MultiOp`.
506505 /// There is exactly one item corresponding to each AST node inside the for
507 /// loop condition. Each item may be `none`, indicating an unbounded range.
506 /// loop condition. Any item may be `none`, indicating an unbounded range.
508507 /// Illegal behaviors:
509508 /// * If all lengths are unbounded ranges (always a compile error).
510509 /// * If any two lengths do not match each other.
511 for_check_lens,
510 for_len,
512511 /// Merge two error sets into one, `E1 || E2`.
513512 /// Uses the `pl_node` field with payload `Bin`.
514513 merge_error_sets,
......@@ -1254,7 +1253,7 @@ pub const Inst = struct {
12541253 .defer_err_code,
12551254 .save_err_ret_index,
12561255 .restore_err_ret_index,
1257 .for_check_lens,
1256 .for_len,
12581257 => false,
12591258
12601259 .@"break",
......@@ -1322,7 +1321,6 @@ pub const Inst = struct {
13221321 .memcpy,
13231322 .memset,
13241323 .check_comptime_control_flow,
1325 .for_check_lens,
13261324 .@"defer",
13271325 .defer_err_code,
13281326 .restore_err_ret_index,
......@@ -1547,6 +1545,7 @@ pub const Inst = struct {
15471545 .repeat_inline,
15481546 .panic,
15491547 .panic_comptime,
1548 .for_len,
15501549 .@"try",
15511550 .try_ptr,
15521551 //.try_inline,
......@@ -1602,7 +1601,7 @@ pub const Inst = struct {
16021601 .@"break" = .@"break",
16031602 .break_inline = .@"break",
16041603 .check_comptime_control_flow = .un_node,
1605 .for_check_lens = .pl_node,
1604 .for_len = .pl_node,
16061605 .call = .pl_node,
16071606 .cmp_lt = .pl_node,
16081607 .cmp_lte = .pl_node,
......@@ -2975,13 +2974,7 @@ pub const Inst = struct {
29752974
29762975 pub const ElemPtrImm = struct {
29772976 ptr: Ref,
2978 bits: Bits,
2979
2980 pub const Bits = packed struct(u32) {
2981 index: u31,
2982 /// Controls whether the type returned is `*T` or `[*]T`.
2983 manyptr: bool = false,
2984 };
2977 index: u32,
29852978 };
29862979
29872980 /// 0. multi_cases_len: u32 // If has_multi_cases is set.
src/print_zir.zig+2-4
......@@ -355,7 +355,7 @@ const Writer = struct {
355355 .array_type,
356356 => try self.writePlNodeBin(stream, inst),
357357
358 .for_check_lens => try self.writePlNodeMultiOp(stream, inst),
358 .for_len => try self.writePlNodeMultiOp(stream, inst),
359359
360360 .elem_ptr_imm => try self.writeElemPtrImm(stream, inst),
361361
......@@ -888,9 +888,7 @@ const Writer = struct {
888888 const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
889889
890890 try self.writeInstRef(stream, extra.ptr);
891 try stream.print(", {d}", .{extra.bits.index});
892 try self.writeFlag(stream, ", manyptr", extra.bits.manyptr);
893 try stream.writeAll(") ");
891 try stream.print(", {d}) ", .{extra.index});
894892 try self.writeSrc(stream, inst_data.src());
895893 }
896894