| ... | @@ -989,7 +989,7 @@ fn suspendExpr( | ... | @@ -989,7 +989,7 @@ fn suspendExpr( |
| 989 | } | 989 | } |
| 990 | try suspend_scope.setBlockBody(suspend_inst); | 990 | try suspend_scope.setBlockBody(suspend_inst); |
| 991 | | 991 | |
| 992 | return gz.indexToRef(suspend_inst); | 992 | return indexToRef(suspend_inst); |
| 993 | } | 993 | } |
| 994 | | 994 | |
| 995 | fn awaitExpr( | 995 | fn awaitExpr( |
| ... | @@ -1300,7 +1300,7 @@ fn arrayInitExprRlPtr( | ... | @@ -1300,7 +1300,7 @@ fn arrayInitExprRlPtr( |
| 1300 | .lhs = result_ptr, | 1300 | .lhs = result_ptr, |
| 1301 | .rhs = index_inst, | 1301 | .rhs = index_inst, |
| 1302 | }); | 1302 | }); |
| 1303 | elem_ptr_list[i] = gz.refToIndex(elem_ptr).?; | 1303 | elem_ptr_list[i] = refToIndex(elem_ptr).?; |
| 1304 | _ = try expr(gz, scope, .{ .ptr = elem_ptr }, elem_init); | 1304 | _ = try expr(gz, scope, .{ .ptr = elem_ptr }, elem_init); |
| 1305 | } | 1305 | } |
| 1306 | _ = try gz.addPlNode(.validate_array_init_ptr, node, Zir.Inst.Block{ | 1306 | _ = try gz.addPlNode(.validate_array_init_ptr, node, Zir.Inst.Block{ |
| ... | @@ -1455,7 +1455,7 @@ fn structInitExprRlPtr( | ... | @@ -1455,7 +1455,7 @@ fn structInitExprRlPtr( |
| 1455 | .lhs = result_ptr, | 1455 | .lhs = result_ptr, |
| 1456 | .field_name_start = str_index, | 1456 | .field_name_start = str_index, |
| 1457 | }); | 1457 | }); |
| 1458 | field_ptr_list[i] = gz.refToIndex(field_ptr).?; | 1458 | field_ptr_list[i] = refToIndex(field_ptr).?; |
| 1459 | _ = try expr(gz, scope, .{ .ptr = field_ptr }, field_init); | 1459 | _ = try expr(gz, scope, .{ .ptr = field_ptr }, field_init); |
| 1460 | } | 1460 | } |
| 1461 | _ = try gz.addPlNode(.validate_struct_init_ptr, node, Zir.Inst.Block{ | 1461 | _ = try gz.addPlNode(.validate_struct_init_ptr, node, Zir.Inst.Block{ |
| ... | @@ -1489,7 +1489,7 @@ fn structInitExprRlTy( | ... | @@ -1489,7 +1489,7 @@ fn structInitExprRlTy( |
| 1489 | .name_start = str_index, | 1489 | .name_start = str_index, |
| 1490 | }); | 1490 | }); |
| 1491 | fields_list[i] = .{ | 1491 | fields_list[i] = .{ |
| 1492 | .field_type = gz.refToIndex(field_ty_inst).?, | 1492 | .field_type = refToIndex(field_ty_inst).?, |
| 1493 | .init = try expr(gz, scope, .{ .ty = field_ty_inst }, field_init), | 1493 | .init = try expr(gz, scope, .{ .ty = field_ty_inst }, field_init), |
| 1494 | }; | 1494 | }; |
| 1495 | } | 1495 | } |
| ... | @@ -1786,7 +1786,7 @@ fn labeledBlockExpr( | ... | @@ -1786,7 +1786,7 @@ fn labeledBlockExpr( |
| 1786 | } | 1786 | } |
| 1787 | try block_scope.setBlockBody(block_inst); | 1787 | try block_scope.setBlockBody(block_inst); |
| 1788 | | 1788 | |
| 1789 | return gz.indexToRef(block_inst); | 1789 | return indexToRef(block_inst); |
| 1790 | }, | 1790 | }, |
| 1791 | .break_operand => { | 1791 | .break_operand => { |
| 1792 | // All break operands are values that did not use the result location pointer. | 1792 | // All break operands are values that did not use the result location pointer. |
| ... | @@ -1800,7 +1800,7 @@ fn labeledBlockExpr( | ... | @@ -1800,7 +1800,7 @@ fn labeledBlockExpr( |
| 1800 | } else { | 1800 | } else { |
| 1801 | try block_scope.setBlockBody(block_inst); | 1801 | try block_scope.setBlockBody(block_inst); |
| 1802 | } | 1802 | } |
| 1803 | const block_ref = gz.indexToRef(block_inst); | 1803 | const block_ref = indexToRef(block_inst); |
| 1804 | switch (rl) { | 1804 | switch (rl) { |
| 1805 | .ref => return block_ref, | 1805 | .ref => return block_ref, |
| 1806 | else => return rvalue(gz, rl, block_ref, block_node), | 1806 | else => return rvalue(gz, rl, block_ref, block_node), |
| ... | @@ -1878,7 +1878,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: ast.Node.Index) Inner | ... | @@ -1878,7 +1878,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: ast.Node.Index) Inner |
| 1878 | // we want to avoid adding the ZIR instruction if possible for performance. | 1878 | // we want to avoid adding the ZIR instruction if possible for performance. |
| 1879 | const maybe_unused_result = try expr(gz, scope, .none, statement); | 1879 | const maybe_unused_result = try expr(gz, scope, .none, statement); |
| 1880 | var noreturn_src_node: ast.Node.Index = 0; | 1880 | var noreturn_src_node: ast.Node.Index = 0; |
| 1881 | const elide_check = if (gz.refToIndex(maybe_unused_result)) |inst| b: { | 1881 | const elide_check = if (refToIndex(maybe_unused_result)) |inst| b: { |
| 1882 | // Note that this array becomes invalid after appending more items to it | 1882 | // Note that this array becomes invalid after appending more items to it |
| 1883 | // in the above while loop. | 1883 | // in the above while loop. |
| 1884 | const zir_tags = gz.astgen.instructions.items(.tag); | 1884 | const zir_tags = gz.astgen.instructions.items(.tag); |
| ... | @@ -2440,7 +2440,7 @@ fn varDecl( | ... | @@ -2440,7 +2440,7 @@ fn varDecl( |
| 2440 | // the alloc instruction and the store_to_block_ptr instruction. | 2440 | // the alloc instruction and the store_to_block_ptr instruction. |
| 2441 | try parent_zir.ensureUnusedCapacity(gpa, init_scope.instructions.items.len); | 2441 | try parent_zir.ensureUnusedCapacity(gpa, init_scope.instructions.items.len); |
| 2442 | for (init_scope.instructions.items) |src_inst| { | 2442 | for (init_scope.instructions.items) |src_inst| { |
| 2443 | if (gz.indexToRef(src_inst) == init_scope.rl_ptr) continue; | 2443 | if (indexToRef(src_inst) == init_scope.rl_ptr) continue; |
| 2444 | if (zir_tags[src_inst] == .store_to_block_ptr) { | 2444 | if (zir_tags[src_inst] == .store_to_block_ptr) { |
| 2445 | if (zir_datas[src_inst].bin.lhs == init_scope.rl_ptr) continue; | 2445 | if (zir_datas[src_inst].bin.lhs == init_scope.rl_ptr) continue; |
| 2446 | } | 2446 | } |
| ... | @@ -2743,7 +2743,7 @@ fn ptrType( | ... | @@ -2743,7 +2743,7 @@ fn ptrType( |
| 2743 | } | 2743 | } |
| 2744 | | 2744 | |
| 2745 | const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len); | 2745 | const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len); |
| 2746 | const result = gz.indexToRef(new_index); | 2746 | const result = indexToRef(new_index); |
| 2747 | gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{ | 2747 | gz.astgen.instructions.appendAssumeCapacity(.{ .tag = .ptr_type, .data = .{ |
| 2748 | .ptr_type = .{ | 2748 | .ptr_type = .{ |
| 2749 | .flags = .{ | 2749 | .flags = .{ |
| ... | @@ -3473,7 +3473,7 @@ fn structDeclInner( | ... | @@ -3473,7 +3473,7 @@ fn structDeclInner( |
| 3473 | .body_len = 0, | 3473 | .body_len = 0, |
| 3474 | .decls_len = 0, | 3474 | .decls_len = 0, |
| 3475 | }); | 3475 | }); |
| 3476 | return gz.indexToRef(decl_inst); | 3476 | return indexToRef(decl_inst); |
| 3477 | } | 3477 | } |
| 3478 | | 3478 | |
| 3479 | const astgen = gz.astgen; | 3479 | const astgen = gz.astgen; |
| ... | @@ -3492,7 +3492,6 @@ fn structDeclInner( | ... | @@ -3492,7 +3492,6 @@ fn structDeclInner( |
| 3492 | .astgen = astgen, | 3492 | .astgen = astgen, |
| 3493 | .force_comptime = true, | 3493 | .force_comptime = true, |
| 3494 | .in_defer = false, | 3494 | .in_defer = false, |
| 3495 | .ref_start_index = gz.ref_start_index, | | |
| 3496 | }; | 3495 | }; |
| 3497 | defer block_scope.instructions.deinit(gpa); | 3496 | defer block_scope.instructions.deinit(gpa); |
| 3498 | | 3497 | |
| ... | @@ -3730,7 +3729,7 @@ fn structDeclInner( | ... | @@ -3730,7 +3729,7 @@ fn structDeclInner( |
| 3730 | } | 3729 | } |
| 3731 | astgen.extra.appendSliceAssumeCapacity(fields_data.items); | 3730 | astgen.extra.appendSliceAssumeCapacity(fields_data.items); |
| 3732 | | 3731 | |
| 3733 | return gz.indexToRef(decl_inst); | 3732 | return indexToRef(decl_inst); |
| 3734 | } | 3733 | } |
| 3735 | | 3734 | |
| 3736 | fn unionDeclInner( | 3735 | fn unionDeclInner( |
| ... | @@ -3758,7 +3757,6 @@ fn unionDeclInner( | ... | @@ -3758,7 +3757,6 @@ fn unionDeclInner( |
| 3758 | .astgen = astgen, | 3757 | .astgen = astgen, |
| 3759 | .force_comptime = true, | 3758 | .force_comptime = true, |
| 3760 | .in_defer = false, | 3759 | .in_defer = false, |
| 3761 | .ref_start_index = gz.ref_start_index, | | |
| 3762 | }; | 3760 | }; |
| 3763 | defer block_scope.instructions.deinit(gpa); | 3761 | defer block_scope.instructions.deinit(gpa); |
| 3764 | | 3762 | |
| ... | @@ -4006,7 +4004,7 @@ fn unionDeclInner( | ... | @@ -4006,7 +4004,7 @@ fn unionDeclInner( |
| 4006 | astgen.extra.appendAssumeCapacity(cur_bit_bag); | 4004 | astgen.extra.appendAssumeCapacity(cur_bit_bag); |
| 4007 | astgen.extra.appendSliceAssumeCapacity(fields_data.items); | 4005 | astgen.extra.appendSliceAssumeCapacity(fields_data.items); |
| 4008 | | 4006 | |
| 4009 | return gz.indexToRef(decl_inst); | 4007 | return indexToRef(decl_inst); |
| 4010 | } | 4008 | } |
| 4011 | | 4009 | |
| 4012 | fn containerDecl( | 4010 | fn containerDecl( |
| ... | @@ -4170,7 +4168,6 @@ fn containerDecl( | ... | @@ -4170,7 +4168,6 @@ fn containerDecl( |
| 4170 | .astgen = astgen, | 4168 | .astgen = astgen, |
| 4171 | .force_comptime = true, | 4169 | .force_comptime = true, |
| 4172 | .in_defer = false, | 4170 | .in_defer = false, |
| 4173 | .ref_start_index = gz.ref_start_index, | | |
| 4174 | }; | 4171 | }; |
| 4175 | defer block_scope.instructions.deinit(gpa); | 4172 | defer block_scope.instructions.deinit(gpa); |
| 4176 | | 4173 | |
| ... | @@ -4398,7 +4395,7 @@ fn containerDecl( | ... | @@ -4398,7 +4395,7 @@ fn containerDecl( |
| 4398 | astgen.extra.appendAssumeCapacity(cur_bit_bag); | 4395 | astgen.extra.appendAssumeCapacity(cur_bit_bag); |
| 4399 | astgen.extra.appendSliceAssumeCapacity(fields_data.items); | 4396 | astgen.extra.appendSliceAssumeCapacity(fields_data.items); |
| 4400 | | 4397 | |
| 4401 | return rvalue(gz, rl, gz.indexToRef(decl_inst), node); | 4398 | return rvalue(gz, rl, indexToRef(decl_inst), node); |
| 4402 | }, | 4399 | }, |
| 4403 | .keyword_opaque => { | 4400 | .keyword_opaque => { |
| 4404 | var namespace: Scope.Namespace = .{ .parent = scope }; | 4401 | var namespace: Scope.Namespace = .{ .parent = scope }; |
| ... | @@ -4559,7 +4556,7 @@ fn containerDecl( | ... | @@ -4559,7 +4556,7 @@ fn containerDecl( |
| 4559 | } | 4556 | } |
| 4560 | astgen.extra.appendSliceAssumeCapacity(wip_decls.payload.items); | 4557 | astgen.extra.appendSliceAssumeCapacity(wip_decls.payload.items); |
| 4561 | | 4558 | |
| 4562 | return rvalue(gz, rl, gz.indexToRef(decl_inst), node); | 4559 | return rvalue(gz, rl, indexToRef(decl_inst), node); |
| 4563 | }, | 4560 | }, |
| 4564 | else => unreachable, | 4561 | else => unreachable, |
| 4565 | } | 4562 | } |
| ... | @@ -4797,7 +4794,7 @@ fn finishThenElseBlock( | ... | @@ -4797,7 +4794,7 @@ fn finishThenElseBlock( |
| 4797 | } | 4794 | } |
| 4798 | assert(!strat.elide_store_to_block_ptr_instructions); | 4795 | assert(!strat.elide_store_to_block_ptr_instructions); |
| 4799 | try setCondBrPayload(condbr, cond, then_scope, else_scope); | 4796 | try setCondBrPayload(condbr, cond, then_scope, else_scope); |
| 4800 | return parent_gz.indexToRef(main_block); | 4797 | return indexToRef(main_block); |
| 4801 | }, | 4798 | }, |
| 4802 | .break_operand => { | 4799 | .break_operand => { |
| 4803 | if (!parent_gz.refIsNoReturn(then_result)) { | 4800 | if (!parent_gz.refIsNoReturn(then_result)) { |
| ... | @@ -4815,7 +4812,7 @@ fn finishThenElseBlock( | ... | @@ -4815,7 +4812,7 @@ fn finishThenElseBlock( |
| 4815 | } else { | 4812 | } else { |
| 4816 | try setCondBrPayload(condbr, cond, then_scope, else_scope); | 4813 | try setCondBrPayload(condbr, cond, then_scope, else_scope); |
| 4817 | } | 4814 | } |
| 4818 | const block_ref = parent_gz.indexToRef(main_block); | 4815 | const block_ref = indexToRef(main_block); |
| 4819 | switch (rl) { | 4816 | switch (rl) { |
| 4820 | .ref => return block_ref, | 4817 | .ref => return block_ref, |
| 4821 | else => return rvalue(parent_gz, rl, block_ref, node), | 4818 | else => return rvalue(parent_gz, rl, block_ref, node), |
| ... | @@ -4937,7 +4934,7 @@ fn boolBinOp( | ... | @@ -4937,7 +4934,7 @@ fn boolBinOp( |
| 4937 | } | 4934 | } |
| 4938 | try rhs_scope.setBoolBrBody(bool_br); | 4935 | try rhs_scope.setBoolBrBody(bool_br); |
| 4939 | | 4936 | |
| 4940 | const block_ref = gz.indexToRef(bool_br); | 4937 | const block_ref = indexToRef(bool_br); |
| 4941 | return rvalue(gz, rl, block_ref, node); | 4938 | return rvalue(gz, rl, block_ref, node); |
| 4942 | } | 4939 | } |
| 4943 | | 4940 | |
| ... | @@ -5959,7 +5956,7 @@ fn switchExpr( | ... | @@ -5959,7 +5956,7 @@ fn switchExpr( |
| 5959 | if (!strat.elide_store_to_block_ptr_instructions) { | 5956 | if (!strat.elide_store_to_block_ptr_instructions) { |
| 5960 | astgen.extra.appendSliceAssumeCapacity(scalar_cases_payload.items); | 5957 | astgen.extra.appendSliceAssumeCapacity(scalar_cases_payload.items); |
| 5961 | astgen.extra.appendSliceAssumeCapacity(multi_cases_payload.items); | 5958 | astgen.extra.appendSliceAssumeCapacity(multi_cases_payload.items); |
| 5962 | return parent_gz.indexToRef(switch_block); | 5959 | return indexToRef(switch_block); |
| 5963 | } | 5960 | } |
| 5964 | | 5961 | |
| 5965 | // There will necessarily be a store_to_block_ptr for | 5962 | // There will necessarily be a store_to_block_ptr for |
| ... | @@ -6003,7 +6000,7 @@ fn switchExpr( | ... | @@ -6003,7 +6000,7 @@ fn switchExpr( |
| 6003 | .lhs = block_scope.rl_ty_inst, | 6000 | .lhs = block_scope.rl_ty_inst, |
| 6004 | .rhs = zir_datas[break_inst].@"break".operand, | 6001 | .rhs = zir_datas[break_inst].@"break".operand, |
| 6005 | }; | 6002 | }; |
| 6006 | zir_datas[break_inst].@"break".operand = parent_gz.indexToRef(store_inst); | 6003 | zir_datas[break_inst].@"break".operand = indexToRef(store_inst); |
| 6007 | } else { | 6004 | } else { |
| 6008 | scalar_cases_payload.items[body_len_index] -= 1; | 6005 | scalar_cases_payload.items[body_len_index] -= 1; |
| 6009 | astgen.extra.appendSliceAssumeCapacity(scalar_cases_payload.items[0..extra_index]); | 6006 | astgen.extra.appendSliceAssumeCapacity(scalar_cases_payload.items[0..extra_index]); |
| ... | @@ -6045,7 +6042,7 @@ fn switchExpr( | ... | @@ -6045,7 +6042,7 @@ fn switchExpr( |
| 6045 | .lhs = block_scope.rl_ty_inst, | 6042 | .lhs = block_scope.rl_ty_inst, |
| 6046 | .rhs = zir_datas[break_inst].@"break".operand, | 6043 | .rhs = zir_datas[break_inst].@"break".operand, |
| 6047 | }; | 6044 | }; |
| 6048 | zir_datas[break_inst].@"break".operand = parent_gz.indexToRef(store_inst); | 6045 | zir_datas[break_inst].@"break".operand = indexToRef(store_inst); |
| 6049 | } else { | 6046 | } else { |
| 6050 | scalar_cases_payload.items[body_len_index] -= 1; | 6047 | scalar_cases_payload.items[body_len_index] -= 1; |
| 6051 | astgen.extra.appendSliceAssumeCapacity(scalar_cases_payload.items[start_index..extra_index]); | 6048 | astgen.extra.appendSliceAssumeCapacity(scalar_cases_payload.items[start_index..extra_index]); |
| ... | @@ -6091,7 +6088,7 @@ fn switchExpr( | ... | @@ -6091,7 +6088,7 @@ fn switchExpr( |
| 6091 | .lhs = block_scope.rl_ty_inst, | 6088 | .lhs = block_scope.rl_ty_inst, |
| 6092 | .rhs = zir_datas[break_inst].@"break".operand, | 6089 | .rhs = zir_datas[break_inst].@"break".operand, |
| 6093 | }; | 6090 | }; |
| 6094 | zir_datas[break_inst].@"break".operand = parent_gz.indexToRef(store_inst); | 6091 | zir_datas[break_inst].@"break".operand = indexToRef(store_inst); |
| 6095 | } else { | 6092 | } else { |
| 6096 | assert(zir_datas[store_inst].bin.lhs == block_scope.rl_ptr); | 6093 | assert(zir_datas[store_inst].bin.lhs == block_scope.rl_ptr); |
| 6097 | multi_cases_payload.items[body_len_index] -= 1; | 6094 | multi_cases_payload.items[body_len_index] -= 1; |
| ... | @@ -6102,7 +6099,7 @@ fn switchExpr( | ... | @@ -6102,7 +6099,7 @@ fn switchExpr( |
| 6102 | } | 6099 | } |
| 6103 | } | 6100 | } |
| 6104 | | 6101 | |
| 6105 | const block_ref = parent_gz.indexToRef(switch_block); | 6102 | const block_ref = indexToRef(switch_block); |
| 6106 | switch (rl) { | 6103 | switch (rl) { |
| 6107 | .ref => return block_ref, | 6104 | .ref => return block_ref, |
| 6108 | else => return rvalue(parent_gz, rl, block_ref, switch_node), | 6105 | else => return rvalue(parent_gz, rl, block_ref, switch_node), |
| ... | @@ -6162,7 +6159,7 @@ fn switchExpr( | ... | @@ -6162,7 +6159,7 @@ fn switchExpr( |
| 6162 | } | 6159 | } |
| 6163 | } | 6160 | } |
| 6164 | | 6161 | |
| 6165 | return parent_gz.indexToRef(switch_block); | 6162 | return indexToRef(switch_block); |
| 6166 | }, | 6163 | }, |
| 6167 | } | 6164 | } |
| 6168 | } | 6165 | } |
| ... | @@ -6861,7 +6858,7 @@ fn asRlPtr( | ... | @@ -6861,7 +6858,7 @@ fn asRlPtr( |
| 6861 | const zir_datas = astgen.instructions.items(.data); | 6858 | const zir_datas = astgen.instructions.items(.data); |
| 6862 | try parent_zir.ensureUnusedCapacity(astgen.gpa, as_scope.instructions.items.len); | 6859 | try parent_zir.ensureUnusedCapacity(astgen.gpa, as_scope.instructions.items.len); |
| 6863 | for (as_scope.instructions.items) |src_inst| { | 6860 | for (as_scope.instructions.items) |src_inst| { |
| 6864 | if (parent_gz.indexToRef(src_inst) == as_scope.rl_ptr) continue; | 6861 | if (indexToRef(src_inst) == as_scope.rl_ptr) continue; |
| 6865 | if (zir_tags[src_inst] == .store_to_block_ptr) { | 6862 | if (zir_tags[src_inst] == .store_to_block_ptr) { |
| 6866 | if (zir_datas[src_inst].bin.lhs == as_scope.rl_ptr) continue; | 6863 | if (zir_datas[src_inst].bin.lhs == as_scope.rl_ptr) continue; |
| 6867 | } | 6864 | } |
| ... | @@ -6992,10 +6989,10 @@ fn builtinCall( | ... | @@ -6992,10 +6989,10 @@ fn builtinCall( |
| 6992 | const str_lit_token = main_tokens[operand_node]; | 6989 | const str_lit_token = main_tokens[operand_node]; |
| 6993 | const str = try astgen.strLitAsString(str_lit_token); | 6990 | const str = try astgen.strLitAsString(str_lit_token); |
| 6994 | const result = try gz.addStrTok(.import, str.index, str_lit_token); | 6991 | const result = try gz.addStrTok(.import, str.index, str_lit_token); |
| 6995 | const gop = try astgen.imports.getOrPut(astgen.gpa, str.index); | 6992 | const gop = try astgen.imports.getOrPut(astgen.gpa, str.index); |
| 6996 | if (!gop.found_existing) { | 6993 | if (!gop.found_existing) { |
| 6997 | gop.value_ptr.* = str_lit_token; | 6994 | gop.value_ptr.* = str_lit_token; |
| 6998 | } | 6995 | } |
| 6999 | return rvalue(gz, rl, result, node); | 6996 | return rvalue(gz, rl, result, node); |
| 7000 | }, | 6997 | }, |
| 7001 | .compile_log => { | 6998 | .compile_log => { |
| ... | @@ -8705,9 +8702,6 @@ const GenZir = struct { | ... | @@ -8705,9 +8702,6 @@ const GenZir = struct { |
| 8705 | in_defer: bool, | 8702 | in_defer: bool, |
| 8706 | /// How decls created in this scope should be named. | 8703 | /// How decls created in this scope should be named. |
| 8707 | anon_name_strategy: Zir.Inst.NameStrategy = .anon, | 8704 | anon_name_strategy: Zir.Inst.NameStrategy = .anon, |
| 8708 | /// The end of special indexes. `Zir.Inst.Ref` subtracts against this number to convert | | |
| 8709 | /// to `Zir.Inst.Index`. The default here is correct if there are 0 parameters. | | |
| 8710 | ref_start_index: u32 = Zir.Inst.Ref.typed_value_map.len, | | |
| 8711 | /// The containing decl AST node. | 8705 | /// The containing decl AST node. |
| 8712 | decl_node_index: ast.Node.Index, | 8706 | decl_node_index: ast.Node.Index, |
| 8713 | /// The containing decl line index, absolute. | 8707 | /// The containing decl line index, absolute. |
| ... | @@ -8751,7 +8745,6 @@ const GenZir = struct { | ... | @@ -8751,7 +8745,6 @@ const GenZir = struct { |
| 8751 | return .{ | 8745 | return .{ |
| 8752 | .force_comptime = gz.force_comptime, | 8746 | .force_comptime = gz.force_comptime, |
| 8753 | .in_defer = gz.in_defer, | 8747 | .in_defer = gz.in_defer, |
| 8754 | .ref_start_index = gz.ref_start_index, | | |
| 8755 | .decl_node_index = gz.decl_node_index, | 8748 | .decl_node_index = gz.decl_node_index, |
| 8756 | .decl_line = gz.decl_line, | 8749 | .decl_line = gz.decl_line, |
| 8757 | .parent = scope, | 8750 | .parent = scope, |
| ... | @@ -8769,7 +8762,7 @@ const GenZir = struct { | ... | @@ -8769,7 +8762,7 @@ const GenZir = struct { |
| 8769 | | 8762 | |
| 8770 | fn refIsNoReturn(gz: GenZir, inst_ref: Zir.Inst.Ref) bool { | 8763 | fn refIsNoReturn(gz: GenZir, inst_ref: Zir.Inst.Ref) bool { |
| 8771 | if (inst_ref == .unreachable_value) return true; | 8764 | if (inst_ref == .unreachable_value) return true; |
| 8772 | if (gz.refToIndex(inst_ref)) |inst_index| { | 8765 | if (refToIndex(inst_ref)) |inst_index| { |
| 8773 | return gz.astgen.instructions.items(.tag)[inst_index].isNoReturn(); | 8766 | return gz.astgen.instructions.items(.tag)[inst_index].isNoReturn(); |
| 8774 | } | 8767 | } |
| 8775 | return false; | 8768 | return false; |
| ... | @@ -8807,19 +8800,6 @@ const GenZir = struct { | ... | @@ -8807,19 +8800,6 @@ const GenZir = struct { |
| 8807 | return gz.astgen.tree.firstToken(gz.decl_node_index); | 8800 | return gz.astgen.tree.firstToken(gz.decl_node_index); |
| 8808 | } | 8801 | } |
| 8809 | | 8802 | |
| 8810 | fn indexToRef(gz: GenZir, inst: Zir.Inst.Index) Zir.Inst.Ref { | | |
| 8811 | return @intToEnum(Zir.Inst.Ref, gz.ref_start_index + inst); | | |
| 8812 | } | | |
| 8813 | | | |
| 8814 | fn refToIndex(gz: GenZir, inst: Zir.Inst.Ref) ?Zir.Inst.Index { | | |
| 8815 | const ref_int = @enumToInt(inst); | | |
| 8816 | if (ref_int >= gz.ref_start_index) { | | |
| 8817 | return ref_int - gz.ref_start_index; | | |
| 8818 | } else { | | |
| 8819 | return null; | | |
| 8820 | } | | |
| 8821 | } | | |
| 8822 | | | |
| 8823 | fn setBreakResultLoc(gz: *GenZir, parent_rl: AstGen.ResultLoc) void { | 8803 | fn setBreakResultLoc(gz: *GenZir, parent_rl: AstGen.ResultLoc) void { |
| 8824 | // Depending on whether the result location is a pointer or value, different | 8804 | // Depending on whether the result location is a pointer or value, different |
| 8825 | // ZIR needs to be generated. In the former case we rely on storing to the | 8805 | // ZIR needs to be generated. In the former case we rely on storing to the |
| ... | @@ -8998,7 +8978,7 @@ const GenZir = struct { | ... | @@ -8998,7 +8978,7 @@ const GenZir = struct { |
| 8998 | } }, | 8978 | } }, |
| 8999 | }); | 8979 | }); |
| 9000 | gz.instructions.appendAssumeCapacity(new_index); | 8980 | gz.instructions.appendAssumeCapacity(new_index); |
| 9001 | return gz.indexToRef(new_index); | 8981 | return indexToRef(new_index); |
| 9002 | } else { | 8982 | } else { |
| 9003 | try gz.astgen.extra.ensureUnusedCapacity( | 8983 | try gz.astgen.extra.ensureUnusedCapacity( |
| 9004 | gpa, | 8984 | gpa, |
| ... | @@ -9025,7 +9005,7 @@ const GenZir = struct { | ... | @@ -9025,7 +9005,7 @@ const GenZir = struct { |
| 9025 | } }, | 9005 | } }, |
| 9026 | }); | 9006 | }); |
| 9027 | gz.instructions.appendAssumeCapacity(new_index); | 9007 | gz.instructions.appendAssumeCapacity(new_index); |
| 9028 | return gz.indexToRef(new_index); | 9008 | return indexToRef(new_index); |
| 9029 | } | 9009 | } |
| 9030 | } | 9010 | } |
| 9031 | | 9011 | |
| ... | @@ -9079,7 +9059,7 @@ const GenZir = struct { | ... | @@ -9079,7 +9059,7 @@ const GenZir = struct { |
| 9079 | } }, | 9059 | } }, |
| 9080 | }); | 9060 | }); |
| 9081 | gz.instructions.appendAssumeCapacity(new_index); | 9061 | gz.instructions.appendAssumeCapacity(new_index); |
| 9082 | return gz.indexToRef(new_index); | 9062 | return indexToRef(new_index); |
| 9083 | } | 9063 | } |
| 9084 | | 9064 | |
| 9085 | fn addCall( | 9065 | fn addCall( |
| ... | @@ -9113,7 +9093,7 @@ const GenZir = struct { | ... | @@ -9113,7 +9093,7 @@ const GenZir = struct { |
| 9113 | } }, | 9093 | } }, |
| 9114 | }); | 9094 | }); |
| 9115 | gz.instructions.appendAssumeCapacity(new_index); | 9095 | gz.instructions.appendAssumeCapacity(new_index); |
| 9116 | return gz.indexToRef(new_index); | 9096 | return indexToRef(new_index); |
| 9117 | } | 9097 | } |
| 9118 | | 9098 | |
| 9119 | /// Note that this returns a `Zir.Inst.Index` not a ref. | 9099 | /// Note that this returns a `Zir.Inst.Index` not a ref. |
| ... | @@ -9164,7 +9144,7 @@ const GenZir = struct { | ... | @@ -9164,7 +9144,7 @@ const GenZir = struct { |
| 9164 | }); | 9144 | }); |
| 9165 | gz.instructions.appendAssumeCapacity(new_index); | 9145 | gz.instructions.appendAssumeCapacity(new_index); |
| 9166 | astgen.string_bytes.appendSliceAssumeCapacity(mem.sliceAsBytes(limbs)); | 9146 | astgen.string_bytes.appendSliceAssumeCapacity(mem.sliceAsBytes(limbs)); |
| 9167 | return gz.indexToRef(new_index); | 9147 | return indexToRef(new_index); |
| 9168 | } | 9148 | } |
| 9169 | | 9149 | |
| 9170 | fn addFloat(gz: *GenZir, number: f32, src_node: ast.Node.Index) !Zir.Inst.Ref { | 9150 | fn addFloat(gz: *GenZir, number: f32, src_node: ast.Node.Index) !Zir.Inst.Ref { |
| ... | @@ -9215,7 +9195,7 @@ const GenZir = struct { | ... | @@ -9215,7 +9195,7 @@ const GenZir = struct { |
| 9215 | } }, | 9195 | } }, |
| 9216 | }); | 9196 | }); |
| 9217 | gz.instructions.appendAssumeCapacity(new_index); | 9197 | gz.instructions.appendAssumeCapacity(new_index); |
| 9218 | return gz.indexToRef(new_index); | 9198 | return indexToRef(new_index); |
| 9219 | } | 9199 | } |
| 9220 | | 9200 | |
| 9221 | fn addExtendedPayload( | 9201 | fn addExtendedPayload( |
| ... | @@ -9239,7 +9219,7 @@ const GenZir = struct { | ... | @@ -9239,7 +9219,7 @@ const GenZir = struct { |
| 9239 | } }, | 9219 | } }, |
| 9240 | }); | 9220 | }); |
| 9241 | gz.instructions.appendAssumeCapacity(new_index); | 9221 | gz.instructions.appendAssumeCapacity(new_index); |
| 9242 | return gz.indexToRef(new_index); | 9222 | return indexToRef(new_index); |
| 9243 | } | 9223 | } |
| 9244 | | 9224 | |
| 9245 | fn addExtendedMultiOp( | 9225 | fn addExtendedMultiOp( |
| ... | @@ -9272,7 +9252,7 @@ const GenZir = struct { | ... | @@ -9272,7 +9252,7 @@ const GenZir = struct { |
| 9272 | }); | 9252 | }); |
| 9273 | gz.instructions.appendAssumeCapacity(new_index); | 9253 | gz.instructions.appendAssumeCapacity(new_index); |
| 9274 | astgen.appendRefsAssumeCapacity(operands); | 9254 | astgen.appendRefsAssumeCapacity(operands); |
| 9275 | return gz.indexToRef(new_index); | 9255 | return indexToRef(new_index); |
| 9276 | } | 9256 | } |
| 9277 | | 9257 | |
| 9278 | fn addArrayTypeSentinel( | 9258 | fn addArrayTypeSentinel( |
| ... | @@ -9298,7 +9278,7 @@ const GenZir = struct { | ... | @@ -9298,7 +9278,7 @@ const GenZir = struct { |
| 9298 | } }, | 9278 | } }, |
| 9299 | }); | 9279 | }); |
| 9300 | gz.instructions.appendAssumeCapacity(new_index); | 9280 | gz.instructions.appendAssumeCapacity(new_index); |
| 9301 | return gz.indexToRef(new_index); | 9281 | return indexToRef(new_index); |
| 9302 | } | 9282 | } |
| 9303 | | 9283 | |
| 9304 | fn addUnTok( | 9284 | fn addUnTok( |
| ... | @@ -9457,7 +9437,7 @@ const GenZir = struct { | ... | @@ -9457,7 +9437,7 @@ const GenZir = struct { |
| 9457 | } }, | 9437 | } }, |
| 9458 | }); | 9438 | }); |
| 9459 | gz.instructions.appendAssumeCapacity(new_index); | 9439 | gz.instructions.appendAssumeCapacity(new_index); |
| 9460 | return gz.indexToRef(new_index); | 9440 | return indexToRef(new_index); |
| 9461 | } | 9441 | } |
| 9462 | | 9442 | |
| 9463 | fn addAsm( | 9443 | fn addAsm( |
| ... | @@ -9515,7 +9495,7 @@ const GenZir = struct { | ... | @@ -9515,7 +9495,7 @@ const GenZir = struct { |
| 9515 | } }, | 9495 | } }, |
| 9516 | }); | 9496 | }); |
| 9517 | gz.instructions.appendAssumeCapacity(new_index); | 9497 | gz.instructions.appendAssumeCapacity(new_index); |
| 9518 | return gz.indexToRef(new_index); | 9498 | return indexToRef(new_index); |
| 9519 | } | 9499 | } |
| 9520 | | 9500 | |
| 9521 | /// Note that this returns a `Zir.Inst.Index` not a ref. | 9501 | /// Note that this returns a `Zir.Inst.Index` not a ref. |
| ... | @@ -9693,7 +9673,7 @@ const GenZir = struct { | ... | @@ -9693,7 +9673,7 @@ const GenZir = struct { |
| 9693 | } | 9673 | } |
| 9694 | | 9674 | |
| 9695 | fn add(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Ref { | 9675 | fn add(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Ref { |
| 9696 | return gz.indexToRef(try gz.addAsIndex(inst)); | 9676 | return indexToRef(try gz.addAsIndex(inst)); |
| 9697 | } | 9677 | } |
| 9698 | | 9678 | |
| 9699 | fn addAsIndex(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Index { | 9679 | fn addAsIndex(gz: *GenZir, inst: Zir.Inst) !Zir.Inst.Index { |
| ... | @@ -9840,3 +9820,18 @@ fn advanceSourceCursor(astgen: *AstGen, source: []const u8, end: usize) void { | ... | @@ -9840,3 +9820,18 @@ fn advanceSourceCursor(astgen: *AstGen, source: []const u8, end: usize) void { |
| 9840 | astgen.source_line = line; | 9820 | astgen.source_line = line; |
| 9841 | astgen.source_column = column; | 9821 | astgen.source_column = column; |
| 9842 | } | 9822 | } |
| | 9823 | |
| | 9824 | const ref_start_index = Zir.Inst.Ref.typed_value_map.len; |
| | 9825 | |
| | 9826 | fn indexToRef(inst: Zir.Inst.Index) Zir.Inst.Ref { |
| | 9827 | return @intToEnum(Zir.Inst.Ref, ref_start_index + inst); |
| | 9828 | } |
| | 9829 | |
| | 9830 | fn refToIndex(inst: Zir.Inst.Ref) ?Zir.Inst.Index { |
| | 9831 | const ref_int = @enumToInt(inst); |
| | 9832 | if (ref_int >= ref_start_index) { |
| | 9833 | return ref_int - ref_start_index; |
| | 9834 | } else { |
| | 9835 | return null; |
| | 9836 | } |
| | 9837 | } |