| ... | ... | @@ -1152,12 +1152,12 @@ fn varDecl( |
| 1152 | 1152 | var init_scope: Scope.GenZir = .{ |
| 1153 | 1153 | .parent = scope, |
| 1154 | 1154 | .force_comptime = scope.isComptime(), |
| 1155 | | .zir_code = scope.getGenZir().zir_code, |
| 1155 | .zir_code = gz.zir_code, |
| 1156 | 1156 | }; |
| 1157 | 1157 | defer init_scope.instructions.deinit(mod.gpa); |
| 1158 | 1158 | |
| 1159 | | var resolve_inferred_alloc: ?zir.Inst.Ref = null; |
| 1160 | | var opt_type_inst: ?zir.Inst.Ref = null; |
| 1159 | var resolve_inferred_alloc: zir.Inst.Ref = 0; |
| 1160 | var opt_type_inst: zir.Inst.Ref = 0; |
| 1161 | 1161 | if (var_decl.ast.type_node != 0) { |
| 1162 | 1162 | const type_inst = try typeExpr(mod, &init_scope.base, var_decl.ast.type_node); |
| 1163 | 1163 | opt_type_inst = type_inst; |
| ... | ... | @@ -1169,6 +1169,9 @@ fn varDecl( |
| 1169 | 1169 | } |
| 1170 | 1170 | const init_result_loc: ResultLoc = .{ .block_ptr = &init_scope }; |
| 1171 | 1171 | const init_inst = try expr(mod, &init_scope.base, init_result_loc, var_decl.ast.init_node); |
| 1172 | const zir_tags = gz.zir_code.instructions.items(.tag); |
| 1173 | const zir_datas = gz.zir_code.instructions.items(.data); |
| 1174 | |
| 1172 | 1175 | const parent_zir = &gz.instructions; |
| 1173 | 1176 | if (init_scope.rvalue_rl_count == 1) { |
| 1174 | 1177 | // Result location pointer not used. We don't need an alloc for this |
| ... | ... | @@ -1179,16 +1182,15 @@ fn varDecl( |
| 1179 | 1182 | try parent_zir.ensureCapacity(mod.gpa, expected_len); |
| 1180 | 1183 | for (init_scope.instructions.items) |src_inst| { |
| 1181 | 1184 | if (src_inst == init_scope.rl_ptr) continue; |
| 1182 | | const src_inst_dtag = init_scope.zir_code.instructions.get(src_inst); |
| 1183 | | if (src_inst_dtag.tag == .store_to_block_ptr) { |
| 1184 | | if (src_inst_dtag.data.bin.lhs == init_scope.rl_ptr) continue; |
| 1185 | if (zir_tags[src_inst] == .store_to_block_ptr) { |
| 1186 | if (zir_datas[src_inst].bin.lhs == init_scope.rl_ptr) continue; |
| 1185 | 1187 | } |
| 1186 | 1188 | parent_zir.appendAssumeCapacity(src_inst); |
| 1187 | 1189 | } |
| 1188 | 1190 | assert(parent_zir.items.len == expected_len); |
| 1189 | | const casted_init = if (opt_type_inst) |type_inst| |
| 1191 | const casted_init = if (opt_type_inst != 0) |
| 1190 | 1192 | try gz.addPlNode(.as_node, var_decl.ast.type_node, zir.Inst.As{ |
| 1191 | | .dest_type = type_inst, |
| 1193 | .dest_type = opt_type_inst, |
| 1192 | 1194 | .operand = init_inst, |
| 1193 | 1195 | }) |
| 1194 | 1196 | else |
| ... | ... | @@ -1211,17 +1213,16 @@ fn varDecl( |
| 1211 | 1213 | const expected_len = parent_zir.items.len + init_scope.instructions.items.len; |
| 1212 | 1214 | try parent_zir.ensureCapacity(mod.gpa, expected_len); |
| 1213 | 1215 | for (init_scope.instructions.items) |src_inst| { |
| 1214 | | const src_inst_dtag = init_scope.zir_code.instructions.get(src_inst); |
| 1215 | | if (src_inst_dtag.tag == .store_to_block_ptr) { |
| 1216 | | if (src_inst_dtag.data.bin.lhs == init_scope.rl_ptr) { |
| 1217 | | init_scope.zir_code.instructions.items(.tag)[src_inst] = .store_to_inferred_ptr; |
| 1216 | if (zir_tags[src_inst] == .store_to_block_ptr) { |
| 1217 | if (zir_datas[src_inst].bin.lhs == init_scope.rl_ptr) { |
| 1218 | zir_tags[src_inst] = .store_to_inferred_ptr; |
| 1218 | 1219 | } |
| 1219 | 1220 | } |
| 1220 | 1221 | parent_zir.appendAssumeCapacity(src_inst); |
| 1221 | 1222 | } |
| 1222 | 1223 | assert(parent_zir.items.len == expected_len); |
| 1223 | | if (resolve_inferred_alloc) |inst| { |
| 1224 | | _ = try gz.addUnTok(.resolve_inferred_alloc, inst, tree.firstToken(node)); |
| 1224 | if (resolve_inferred_alloc != 0) { |
| 1225 | _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node); |
| 1225 | 1226 | } |
| 1226 | 1227 | const sub_scope = try block_arena.create(Scope.LocalPtr); |
| 1227 | 1228 | sub_scope.* = .{ |
| ... | ... | @@ -1234,7 +1235,7 @@ fn varDecl( |
| 1234 | 1235 | return &sub_scope.base; |
| 1235 | 1236 | }, |
| 1236 | 1237 | .keyword_var => { |
| 1237 | | var resolve_inferred_alloc: ?zir.Inst.Ref = null; |
| 1238 | var resolve_inferred_alloc: zir.Inst.Ref = 0; |
| 1238 | 1239 | const var_data: struct { |
| 1239 | 1240 | result_loc: ResultLoc, |
| 1240 | 1241 | alloc: zir.Inst.Ref, |
| ... | ... | @@ -1249,8 +1250,8 @@ fn varDecl( |
| 1249 | 1250 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } }; |
| 1250 | 1251 | }; |
| 1251 | 1252 | const init_inst = try expr(mod, scope, var_data.result_loc, var_decl.ast.init_node); |
| 1252 | | if (resolve_inferred_alloc) |inst| { |
| 1253 | | _ = try gz.addUnNode(.resolve_inferred_alloc, inst, node); |
| 1253 | if (resolve_inferred_alloc != 0) { |
| 1254 | _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node); |
| 1254 | 1255 | } |
| 1255 | 1256 | const sub_scope = try block_arena.create(Scope.LocalPtr); |
| 1256 | 1257 | sub_scope.* = .{ |