authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-21 20:18:13-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-21 20:18:13-07:00
log4f3071a8172b1e5d0aa22c07471de2056df1608a
tree988fcb6aadb89802441cb58d87314b2a9d0b8df0
parent7a55671b89c85d412aa37dfa18fc6faaed1eba22

cleanups from previous commit


2 files changed, 21 insertions(+), 17 deletions(-)

src/astgen.zig+18-17
......@@ -1152,12 +1152,12 @@ fn varDecl(
11521152 var init_scope: Scope.GenZir = .{
11531153 .parent = scope,
11541154 .force_comptime = scope.isComptime(),
1155 .zir_code = scope.getGenZir().zir_code,
1155 .zir_code = gz.zir_code,
11561156 };
11571157 defer init_scope.instructions.deinit(mod.gpa);
11581158
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;
11611161 if (var_decl.ast.type_node != 0) {
11621162 const type_inst = try typeExpr(mod, &init_scope.base, var_decl.ast.type_node);
11631163 opt_type_inst = type_inst;
......@@ -1169,6 +1169,9 @@ fn varDecl(
11691169 }
11701170 const init_result_loc: ResultLoc = .{ .block_ptr = &init_scope };
11711171 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
11721175 const parent_zir = &gz.instructions;
11731176 if (init_scope.rvalue_rl_count == 1) {
11741177 // Result location pointer not used. We don't need an alloc for this
......@@ -1179,16 +1182,15 @@ fn varDecl(
11791182 try parent_zir.ensureCapacity(mod.gpa, expected_len);
11801183 for (init_scope.instructions.items) |src_inst| {
11811184 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;
11851187 }
11861188 parent_zir.appendAssumeCapacity(src_inst);
11871189 }
11881190 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)
11901192 try gz.addPlNode(.as_node, var_decl.ast.type_node, zir.Inst.As{
1191 .dest_type = type_inst,
1193 .dest_type = opt_type_inst,
11921194 .operand = init_inst,
11931195 })
11941196 else
......@@ -1211,17 +1213,16 @@ fn varDecl(
12111213 const expected_len = parent_zir.items.len + init_scope.instructions.items.len;
12121214 try parent_zir.ensureCapacity(mod.gpa, expected_len);
12131215 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;
12181219 }
12191220 }
12201221 parent_zir.appendAssumeCapacity(src_inst);
12211222 }
12221223 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);
12251226 }
12261227 const sub_scope = try block_arena.create(Scope.LocalPtr);
12271228 sub_scope.* = .{
......@@ -1234,7 +1235,7 @@ fn varDecl(
12341235 return &sub_scope.base;
12351236 },
12361237 .keyword_var => {
1237 var resolve_inferred_alloc: ?zir.Inst.Ref = null;
1238 var resolve_inferred_alloc: zir.Inst.Ref = 0;
12381239 const var_data: struct {
12391240 result_loc: ResultLoc,
12401241 alloc: zir.Inst.Ref,
......@@ -1249,8 +1250,8 @@ fn varDecl(
12491250 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };
12501251 };
12511252 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);
12541255 }
12551256 const sub_scope = try block_arena.create(Scope.LocalPtr);
12561257 sub_scope.* = .{
src/zir.zig+3
......@@ -746,6 +746,9 @@ pub const Inst = struct {
746746 store_to_block_ptr,
747747 /// Same as `store` but the type of the value being stored will be used to infer
748748 /// the pointer type.
749 /// Uses the `bin` union field - astgen.zig depends on the ability to change
750 /// the tag of an instruction from `store_to_block_ptr` to `store_to_inferred_ptr`
751 /// without changing the data.
749752 store_to_inferred_ptr,
750753 /// String Literal. Makes an anonymous Decl and then takes a pointer to it.
751754 /// Uses the `str` union field.