Commit 4f3071a817
Changed files (2)
src/astgen.zig
@@ -1152,12 +1152,12 @@ fn varDecl(
var init_scope: Scope.GenZir = .{
.parent = scope,
.force_comptime = scope.isComptime(),
- .zir_code = scope.getGenZir().zir_code,
+ .zir_code = gz.zir_code,
};
defer init_scope.instructions.deinit(mod.gpa);
- var resolve_inferred_alloc: ?zir.Inst.Ref = null;
- var opt_type_inst: ?zir.Inst.Ref = null;
+ var resolve_inferred_alloc: zir.Inst.Ref = 0;
+ var opt_type_inst: zir.Inst.Ref = 0;
if (var_decl.ast.type_node != 0) {
const type_inst = try typeExpr(mod, &init_scope.base, var_decl.ast.type_node);
opt_type_inst = type_inst;
@@ -1169,6 +1169,9 @@ fn varDecl(
}
const init_result_loc: ResultLoc = .{ .block_ptr = &init_scope };
const init_inst = try expr(mod, &init_scope.base, init_result_loc, var_decl.ast.init_node);
+ const zir_tags = gz.zir_code.instructions.items(.tag);
+ const zir_datas = gz.zir_code.instructions.items(.data);
+
const parent_zir = &gz.instructions;
if (init_scope.rvalue_rl_count == 1) {
// Result location pointer not used. We don't need an alloc for this
@@ -1179,16 +1182,15 @@ fn varDecl(
try parent_zir.ensureCapacity(mod.gpa, expected_len);
for (init_scope.instructions.items) |src_inst| {
if (src_inst == init_scope.rl_ptr) continue;
- const src_inst_dtag = init_scope.zir_code.instructions.get(src_inst);
- if (src_inst_dtag.tag == .store_to_block_ptr) {
- if (src_inst_dtag.data.bin.lhs == init_scope.rl_ptr) continue;
+ if (zir_tags[src_inst] == .store_to_block_ptr) {
+ if (zir_datas[src_inst].bin.lhs == init_scope.rl_ptr) continue;
}
parent_zir.appendAssumeCapacity(src_inst);
}
assert(parent_zir.items.len == expected_len);
- const casted_init = if (opt_type_inst) |type_inst|
+ const casted_init = if (opt_type_inst != 0)
try gz.addPlNode(.as_node, var_decl.ast.type_node, zir.Inst.As{
- .dest_type = type_inst,
+ .dest_type = opt_type_inst,
.operand = init_inst,
})
else
@@ -1211,17 +1213,16 @@ fn varDecl(
const expected_len = parent_zir.items.len + init_scope.instructions.items.len;
try parent_zir.ensureCapacity(mod.gpa, expected_len);
for (init_scope.instructions.items) |src_inst| {
- const src_inst_dtag = init_scope.zir_code.instructions.get(src_inst);
- if (src_inst_dtag.tag == .store_to_block_ptr) {
- if (src_inst_dtag.data.bin.lhs == init_scope.rl_ptr) {
- init_scope.zir_code.instructions.items(.tag)[src_inst] = .store_to_inferred_ptr;
+ if (zir_tags[src_inst] == .store_to_block_ptr) {
+ if (zir_datas[src_inst].bin.lhs == init_scope.rl_ptr) {
+ zir_tags[src_inst] = .store_to_inferred_ptr;
}
}
parent_zir.appendAssumeCapacity(src_inst);
}
assert(parent_zir.items.len == expected_len);
- if (resolve_inferred_alloc) |inst| {
- _ = try gz.addUnTok(.resolve_inferred_alloc, inst, tree.firstToken(node));
+ if (resolve_inferred_alloc != 0) {
+ _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node);
}
const sub_scope = try block_arena.create(Scope.LocalPtr);
sub_scope.* = .{
@@ -1234,7 +1235,7 @@ fn varDecl(
return &sub_scope.base;
},
.keyword_var => {
- var resolve_inferred_alloc: ?zir.Inst.Ref = null;
+ var resolve_inferred_alloc: zir.Inst.Ref = 0;
const var_data: struct {
result_loc: ResultLoc,
alloc: zir.Inst.Ref,
@@ -1249,8 +1250,8 @@ fn varDecl(
break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };
};
const init_inst = try expr(mod, scope, var_data.result_loc, var_decl.ast.init_node);
- if (resolve_inferred_alloc) |inst| {
- _ = try gz.addUnNode(.resolve_inferred_alloc, inst, node);
+ if (resolve_inferred_alloc != 0) {
+ _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node);
}
const sub_scope = try block_arena.create(Scope.LocalPtr);
sub_scope.* = .{
src/zir.zig
@@ -746,6 +746,9 @@ pub const Inst = struct {
store_to_block_ptr,
/// Same as `store` but the type of the value being stored will be used to infer
/// the pointer type.
+ /// Uses the `bin` union field - astgen.zig depends on the ability to change
+ /// the tag of an instruction from `store_to_block_ptr` to `store_to_inferred_ptr`
+ /// without changing the data.
store_to_inferred_ptr,
/// String Literal. Makes an anonymous Decl and then takes a pointer to it.
/// Uses the `str` union field.