| ... | ... | @@ -1195,6 +1195,7 @@ fn varDecl( |
| 1195 | 1195 | return mod.failNode(scope, var_decl.ast.align_node, "TODO implement alignment on locals", .{}); |
| 1196 | 1196 | } |
| 1197 | 1197 | const gz = scope.getGenZir(); |
| 1198 | const wzc = gz.zir_code; |
| 1198 | 1199 | const tree = scope.tree(); |
| 1199 | 1200 | const token_tags = tree.tokens.items(.tag); |
| 1200 | 1201 | |
| ... | ... | @@ -1276,7 +1277,7 @@ fn varDecl( |
| 1276 | 1277 | var init_scope: Scope.GenZir = .{ |
| 1277 | 1278 | .parent = scope, |
| 1278 | 1279 | .force_comptime = gz.force_comptime, |
| 1279 | | .zir_code = gz.zir_code, |
| 1280 | .zir_code = wzc, |
| 1280 | 1281 | }; |
| 1281 | 1282 | defer init_scope.instructions.deinit(mod.gpa); |
| 1282 | 1283 | |
| ... | ... | @@ -1285,16 +1286,16 @@ fn varDecl( |
| 1285 | 1286 | if (var_decl.ast.type_node != 0) { |
| 1286 | 1287 | const type_inst = try typeExpr(mod, &init_scope.base, var_decl.ast.type_node); |
| 1287 | 1288 | opt_type_inst = type_inst; |
| 1288 | | init_scope.rl_ptr = try init_scope.addUnNodeAsIndex(.alloc, type_inst, node); |
| 1289 | init_scope.rl_ptr = try init_scope.addUnNode(.alloc, type_inst, node); |
| 1289 | 1290 | } else { |
| 1290 | | const alloc = try init_scope.addUnNodeAsIndex(.alloc_inferred, undefined, node); |
| 1291 | | resolve_inferred_alloc = init_scope.zir_code.ref_start_index + alloc; |
| 1291 | const alloc = try init_scope.addUnNode(.alloc_inferred, undefined, node); |
| 1292 | resolve_inferred_alloc = alloc; |
| 1292 | 1293 | init_scope.rl_ptr = alloc; |
| 1293 | 1294 | } |
| 1294 | 1295 | const init_result_loc: ResultLoc = .{ .block_ptr = &init_scope }; |
| 1295 | 1296 | const init_inst = try expr(mod, &init_scope.base, init_result_loc, var_decl.ast.init_node); |
| 1296 | | const zir_tags = gz.zir_code.instructions.items(.tag); |
| 1297 | | const zir_datas = gz.zir_code.instructions.items(.data); |
| 1297 | const zir_tags = wzc.instructions.items(.tag); |
| 1298 | const zir_datas = wzc.instructions.items(.data); |
| 1298 | 1299 | |
| 1299 | 1300 | const parent_zir = &gz.instructions; |
| 1300 | 1301 | if (init_scope.rvalue_rl_count == 1) { |
| ... | ... | @@ -1305,7 +1306,7 @@ fn varDecl( |
| 1305 | 1306 | const expected_len = parent_zir.items.len + init_scope.instructions.items.len - 2; |
| 1306 | 1307 | try parent_zir.ensureCapacity(mod.gpa, expected_len); |
| 1307 | 1308 | for (init_scope.instructions.items) |src_inst| { |
| 1308 | | if (src_inst == init_scope.rl_ptr) continue; |
| 1309 | if (wzc.ref_start_index + src_inst == init_scope.rl_ptr) continue; |
| 1309 | 1310 | if (zir_tags[src_inst] == .store_to_block_ptr) { |
| 1310 | 1311 | if (zir_datas[src_inst].bin.lhs == init_scope.rl_ptr) continue; |
| 1311 | 1312 | } |
| ... | ... | @@ -3192,26 +3193,27 @@ fn asRlPtr( |
| 3192 | 3193 | // result location. If it does, elide the coerce_result_ptr instruction |
| 3193 | 3194 | // as well as the store instruction, instead passing the result as an rvalue. |
| 3194 | 3195 | const parent_gz = scope.getGenZir(); |
| 3196 | const wzc = parent_gz.zir_code; |
| 3195 | 3197 | |
| 3196 | 3198 | var as_scope: Scope.GenZir = .{ |
| 3197 | 3199 | .parent = scope, |
| 3198 | | .zir_code = parent_gz.zir_code, |
| 3200 | .zir_code = wzc, |
| 3199 | 3201 | .force_comptime = parent_gz.force_comptime, |
| 3200 | 3202 | .instructions = .{}, |
| 3201 | 3203 | }; |
| 3202 | 3204 | defer as_scope.instructions.deinit(mod.gpa); |
| 3203 | 3205 | |
| 3204 | | as_scope.rl_ptr = try as_scope.addBinAsIndex(.coerce_result_ptr, dest_type, result_ptr); |
| 3206 | as_scope.rl_ptr = try as_scope.addBin(.coerce_result_ptr, dest_type, result_ptr); |
| 3205 | 3207 | const result = try expr(mod, &as_scope.base, .{ .block_ptr = &as_scope }, operand_node); |
| 3206 | 3208 | const parent_zir = &parent_gz.instructions; |
| 3207 | 3209 | if (as_scope.rvalue_rl_count == 1) { |
| 3208 | 3210 | // Busted! This expression didn't actually need a pointer. |
| 3209 | | const zir_tags = parent_gz.zir_code.instructions.items(.tag); |
| 3210 | | const zir_datas = parent_gz.zir_code.instructions.items(.data); |
| 3211 | const zir_tags = wzc.instructions.items(.tag); |
| 3212 | const zir_datas = wzc.instructions.items(.data); |
| 3211 | 3213 | const expected_len = parent_zir.items.len + as_scope.instructions.items.len - 2; |
| 3212 | 3214 | try parent_zir.ensureCapacity(mod.gpa, expected_len); |
| 3213 | 3215 | for (as_scope.instructions.items) |src_inst| { |
| 3214 | | if (src_inst == as_scope.rl_ptr) continue; |
| 3216 | if (wzc.ref_start_index + src_inst == as_scope.rl_ptr) continue; |
| 3215 | 3217 | if (zir_tags[src_inst] == .store_to_block_ptr) { |
| 3216 | 3218 | if (zir_datas[src_inst].bin.lhs == as_scope.rl_ptr) continue; |
| 3217 | 3219 | } |