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(...@@ -1152,12 +1152,12 @@ fn varDecl(
1152 var init_scope: Scope.GenZir = .{1152 var init_scope: Scope.GenZir = .{
1153 .parent = scope,1153 .parent = scope,
1154 .force_comptime = scope.isComptime(),1154 .force_comptime = scope.isComptime(),
1155 .zir_code = scope.getGenZir().zir_code,1155 .zir_code = gz.zir_code,
1156 };1156 };
1157 defer init_scope.instructions.deinit(mod.gpa);1157 defer init_scope.instructions.deinit(mod.gpa);
11581158
1159 var resolve_inferred_alloc: ?zir.Inst.Ref = null;1159 var resolve_inferred_alloc: zir.Inst.Ref = 0;
1160 var opt_type_inst: ?zir.Inst.Ref = null;1160 var opt_type_inst: zir.Inst.Ref = 0;
1161 if (var_decl.ast.type_node != 0) {1161 if (var_decl.ast.type_node != 0) {
1162 const type_inst = try typeExpr(mod, &init_scope.base, var_decl.ast.type_node);1162 const type_inst = try typeExpr(mod, &init_scope.base, var_decl.ast.type_node);
1163 opt_type_inst = type_inst;1163 opt_type_inst = type_inst;
...@@ -1169,6 +1169,9 @@ fn varDecl(...@@ -1169,6 +1169,9 @@ fn varDecl(
1169 }1169 }
1170 const init_result_loc: ResultLoc = .{ .block_ptr = &init_scope };1170 const init_result_loc: ResultLoc = .{ .block_ptr = &init_scope };
1171 const init_inst = try expr(mod, &init_scope.base, init_result_loc, var_decl.ast.init_node);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 const parent_zir = &gz.instructions;1175 const parent_zir = &gz.instructions;
1173 if (init_scope.rvalue_rl_count == 1) {1176 if (init_scope.rvalue_rl_count == 1) {
1174 // Result location pointer not used. We don't need an alloc for this1177 // Result location pointer not used. We don't need an alloc for this
...@@ -1179,16 +1182,15 @@ fn varDecl(...@@ -1179,16 +1182,15 @@ fn varDecl(
1179 try parent_zir.ensureCapacity(mod.gpa, expected_len);1182 try parent_zir.ensureCapacity(mod.gpa, expected_len);
1180 for (init_scope.instructions.items) |src_inst| {1183 for (init_scope.instructions.items) |src_inst| {
1181 if (src_inst == init_scope.rl_ptr) continue;1184 if (src_inst == init_scope.rl_ptr) continue;
1182 const src_inst_dtag = init_scope.zir_code.instructions.get(src_inst);1185 if (zir_tags[src_inst] == .store_to_block_ptr) {
1183 if (src_inst_dtag.tag == .store_to_block_ptr) {1186 if (zir_datas[src_inst].bin.lhs == init_scope.rl_ptr) continue;
1184 if (src_inst_dtag.data.bin.lhs == init_scope.rl_ptr) continue;
1185 }1187 }
1186 parent_zir.appendAssumeCapacity(src_inst);1188 parent_zir.appendAssumeCapacity(src_inst);
1187 }1189 }
1188 assert(parent_zir.items.len == expected_len);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 try gz.addPlNode(.as_node, var_decl.ast.type_node, zir.Inst.As{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 .operand = init_inst,1194 .operand = init_inst,
1193 })1195 })
1194 else1196 else
...@@ -1211,17 +1213,16 @@ fn varDecl(...@@ -1211,17 +1213,16 @@ fn varDecl(
1211 const expected_len = parent_zir.items.len + init_scope.instructions.items.len;1213 const expected_len = parent_zir.items.len + init_scope.instructions.items.len;
1212 try parent_zir.ensureCapacity(mod.gpa, expected_len);1214 try parent_zir.ensureCapacity(mod.gpa, expected_len);
1213 for (init_scope.instructions.items) |src_inst| {1215 for (init_scope.instructions.items) |src_inst| {
1214 const src_inst_dtag = init_scope.zir_code.instructions.get(src_inst);1216 if (zir_tags[src_inst] == .store_to_block_ptr) {
1215 if (src_inst_dtag.tag == .store_to_block_ptr) {1217 if (zir_datas[src_inst].bin.lhs == init_scope.rl_ptr) {
1216 if (src_inst_dtag.data.bin.lhs == init_scope.rl_ptr) {1218 zir_tags[src_inst] = .store_to_inferred_ptr;
1217 init_scope.zir_code.instructions.items(.tag)[src_inst] = .store_to_inferred_ptr;
1218 }1219 }
1219 }1220 }
1220 parent_zir.appendAssumeCapacity(src_inst);1221 parent_zir.appendAssumeCapacity(src_inst);
1221 }1222 }
1222 assert(parent_zir.items.len == expected_len);1223 assert(parent_zir.items.len == expected_len);
1223 if (resolve_inferred_alloc) |inst| {1224 if (resolve_inferred_alloc != 0) {
1224 _ = try gz.addUnTok(.resolve_inferred_alloc, inst, tree.firstToken(node));1225 _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node);
1225 }1226 }
1226 const sub_scope = try block_arena.create(Scope.LocalPtr);1227 const sub_scope = try block_arena.create(Scope.LocalPtr);
1227 sub_scope.* = .{1228 sub_scope.* = .{
...@@ -1234,7 +1235,7 @@ fn varDecl(...@@ -1234,7 +1235,7 @@ fn varDecl(
1234 return &sub_scope.base;1235 return &sub_scope.base;
1235 },1236 },
1236 .keyword_var => {1237 .keyword_var => {
1237 var resolve_inferred_alloc: ?zir.Inst.Ref = null;1238 var resolve_inferred_alloc: zir.Inst.Ref = 0;
1238 const var_data: struct {1239 const var_data: struct {
1239 result_loc: ResultLoc,1240 result_loc: ResultLoc,
1240 alloc: zir.Inst.Ref,1241 alloc: zir.Inst.Ref,
...@@ -1249,8 +1250,8 @@ fn varDecl(...@@ -1249,8 +1250,8 @@ fn varDecl(
1249 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };1250 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };
1250 };1251 };
1251 const init_inst = try expr(mod, scope, var_data.result_loc, var_decl.ast.init_node);1252 const init_inst = try expr(mod, scope, var_data.result_loc, var_decl.ast.init_node);
1252 if (resolve_inferred_alloc) |inst| {1253 if (resolve_inferred_alloc != 0) {
1253 _ = try gz.addUnNode(.resolve_inferred_alloc, inst, node);1254 _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node);
1254 }1255 }
1255 const sub_scope = try block_arena.create(Scope.LocalPtr);1256 const sub_scope = try block_arena.create(Scope.LocalPtr);
1256 sub_scope.* = .{1257 sub_scope.* = .{
src/zir.zig+3
...@@ -746,6 +746,9 @@ pub const Inst = struct {...@@ -746,6 +746,9 @@ pub const Inst = struct {
746 store_to_block_ptr,746 store_to_block_ptr,
747 /// Same as `store` but the type of the value being stored will be used to infer747 /// Same as `store` but the type of the value being stored will be used to infer
748 /// the pointer type.748 /// 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.
749 store_to_inferred_ptr,752 store_to_inferred_ptr,
750 /// String Literal. Makes an anonymous Decl and then takes a pointer to it.753 /// String Literal. Makes an anonymous Decl and then takes a pointer to it.
751 /// Uses the `str` union field.754 /// Uses the `str` union field.