authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-05-28 18:38:35+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-05-29 13:19:03+03:00
logc7b778992ec539e237d8afa7c105dcbad7ee280c
treed8e9e03fd9f84ad3a8a6439a82972806ed8bc914
parentee651c3cd358f40f60db0bbcd82ffde99aed9b88

AstGen: improve generated Zir for array init exprs


6 files changed, 57 insertions(+), 141 deletions(-)

src/AstGen.zig+30-84
...@@ -1273,16 +1273,8 @@ fn arrayInitExpr(...@@ -1273,16 +1273,8 @@ fn arrayInitExpr(
12731273
1274 assert(array_init.ast.elements.len != 0); // Otherwise it would be struct init.1274 assert(array_init.ast.elements.len != 0); // Otherwise it would be struct init.
12751275
1276 const types: struct {1276 const array_ty: Zir.Inst.Ref = inst: {
1277 array: Zir.Inst.Ref,1277 if (array_init.ast.type_expr == 0) break :inst .none;
1278 elem: Zir.Inst.Ref,
1279 sentinel: Zir.Inst.Ref,
1280 } = inst: {
1281 if (array_init.ast.type_expr == 0) break :inst .{
1282 .array = .none,
1283 .elem = .none,
1284 .sentinel = .none,
1285 };
12861278
1287 infer: {1279 infer: {
1288 const array_type: Ast.full.ArrayType = switch (node_tags[array_init.ast.type_expr]) {1280 const array_type: Ast.full.ArrayType = switch (node_tags[array_init.ast.type_expr]) {
...@@ -1297,15 +1289,10 @@ fn arrayInitExpr(...@@ -1297,15 +1289,10 @@ fn arrayInitExpr(
1297 const len_inst = try gz.addInt(array_init.ast.elements.len);1289 const len_inst = try gz.addInt(array_init.ast.elements.len);
1298 const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type);1290 const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type);
1299 if (array_type.ast.sentinel == 0) {1291 if (array_type.ast.sentinel == 0) {
1300 const array_type_inst = try gz.addBin(.array_type, len_inst, elem_type);1292 break :inst try gz.addBin(.array_type, len_inst, elem_type);
1301 break :inst .{
1302 .array = array_type_inst,
1303 .elem = elem_type,
1304 .sentinel = .none,
1305 };
1306 } else {1293 } else {
1307 const sentinel = try comptimeExpr(gz, scope, .{ .ty = elem_type }, array_type.ast.sentinel);1294 const sentinel = try comptimeExpr(gz, scope, .{ .ty = elem_type }, array_type.ast.sentinel);
1308 const array_type_inst = try gz.addPlNode(1295 break :inst try gz.addPlNode(
1309 .array_type_sentinel,1296 .array_type_sentinel,
1310 array_init.ast.type_expr,1297 array_init.ast.type_expr,
1311 Zir.Inst.ArrayTypeSentinel{1298 Zir.Inst.ArrayTypeSentinel{
...@@ -1314,76 +1301,57 @@ fn arrayInitExpr(...@@ -1314,76 +1301,57 @@ fn arrayInitExpr(
1314 .sentinel = sentinel,1301 .sentinel = sentinel,
1315 },1302 },
1316 );1303 );
1317 break :inst .{
1318 .array = array_type_inst,
1319 .elem = elem_type,
1320 .sentinel = sentinel,
1321 };
1322 }1304 }
1323 }1305 }
1324 }1306 }
1325 const array_type_inst = try typeExpr(gz, scope, array_init.ast.type_expr);1307 const array_type_inst = try typeExpr(gz, scope, array_init.ast.type_expr);
1326 _ = try gz.addUnNode(.validate_array_init_ty, array_type_inst, node);1308 _ = try gz.addUnNode(.validate_array_init_ty, array_type_inst, node);
1327 const elem_type = try gz.addUnNode(.elem_type, array_type_inst, array_init.ast.type_expr);1309 break :inst array_type_inst;
1328 break :inst .{
1329 .array = array_type_inst,
1330 .elem = elem_type,
1331 .sentinel = .none,
1332 };
1333 };1310 };
13341311
1335 switch (rl) {1312 switch (rl) {
1336 .discard => {1313 .discard => {
1314 // TODO elements should still be coerced if type is provided
1337 for (array_init.ast.elements) |elem_init| {1315 for (array_init.ast.elements) |elem_init| {
1338 _ = try expr(gz, scope, .discard, elem_init);1316 _ = try expr(gz, scope, .discard, elem_init);
1339 }1317 }
1340 return Zir.Inst.Ref.void_value;1318 return Zir.Inst.Ref.void_value;
1341 },1319 },
1342 .ref => {1320 .ref => {
1343 if (types.array != .none) {1321 const tag: Zir.Inst.Tag = if (array_ty != .none) .array_init_ref else .array_init_anon_ref;
1344 return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, types.sentinel, true);1322 return arrayInitExprInner(gz, scope, node, array_init.ast.elements, array_ty, tag);
1345 } else {
1346 return arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon_ref);
1347 }
1348 },1323 },
1349 .none => {1324 .none => {
1350 if (types.array != .none) {1325 const tag: Zir.Inst.Tag = if (array_ty != .none) .array_init else .array_init_anon;
1351 return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, types.sentinel, false);1326 return arrayInitExprInner(gz, scope, node, array_init.ast.elements, array_ty, tag);
1352 } else {
1353 return arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);
1354 }
1355 },1327 },
1356 .ty, .coerced_ty => {1328 .ty, .coerced_ty => {
1357 if (types.array != .none) {1329 const tag: Zir.Inst.Tag = if (array_ty != .none) .array_init else .array_init_anon;
1358 const result = try arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, types.sentinel, false);1330 const result = try arrayInitExprInner(gz, scope, node, array_init.ast.elements, array_ty, tag);
1359 return rvalue(gz, rl, result, node);1331 return rvalue(gz, rl, result, node);
1360 } else {
1361 const result = try arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);
1362 return rvalue(gz, rl, result, node);
1363 }
1364 },1332 },
1365 .ptr => |ptr_inst| {1333 .ptr => |ptr_inst| {
1366 return arrayInitExprRlPtr(gz, scope, rl, node, ptr_inst, array_init.ast.elements, types.array);1334 return arrayInitExprRlPtr(gz, scope, rl, node, ptr_inst, array_init.ast.elements, array_ty);
1367 },1335 },
1368 .inferred_ptr => |ptr_inst| {1336 .inferred_ptr => |ptr_inst| {
1369 if (types.array == .none) {1337 if (array_ty == .none) {
1370 // We treat this case differently so that we don't get a crash when1338 // We treat this case differently so that we don't get a crash when
1371 // analyzing array_base_ptr against an alloc_inferred_mut.1339 // analyzing array_base_ptr against an alloc_inferred_mut.
1372 // See corresponding logic in structInitExpr.1340 // See corresponding logic in structInitExpr.
1373 const result = try arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);1341 const result = try arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);
1374 return rvalue(gz, rl, result, node);1342 return rvalue(gz, rl, result, node);
1375 } else {1343 } else {
1376 return arrayInitExprRlPtr(gz, scope, rl, node, ptr_inst, array_init.ast.elements, types.array);1344 return arrayInitExprRlPtr(gz, scope, rl, node, ptr_inst, array_init.ast.elements, array_ty);
1377 }1345 }
1378 },1346 },
1379 .block_ptr => |block_gz| {1347 .block_ptr => |block_gz| {
1380 // This condition is here for the same reason as the above condition in `inferred_ptr`.1348 // This condition is here for the same reason as the above condition in `inferred_ptr`.
1381 // See corresponding logic in structInitExpr.1349 // See corresponding logic in structInitExpr.
1382 if (types.array == .none and astgen.isInferred(block_gz.rl_ptr)) {1350 if (array_ty == .none and astgen.isInferred(block_gz.rl_ptr)) {
1383 const result = try arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);1351 const result = try arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);
1384 return rvalue(gz, rl, result, node);1352 return rvalue(gz, rl, result, node);
1385 }1353 }
1386 return arrayInitExprRlPtr(gz, scope, rl, node, block_gz.rl_ptr, array_init.ast.elements, types.array);1354 return arrayInitExprRlPtr(gz, scope, rl, node, block_gz.rl_ptr, array_init.ast.elements, array_ty);
1387 },1355 },
1388 }1356 }
1389}1357}
...@@ -1410,52 +1378,33 @@ fn arrayInitExprRlNone(...@@ -1410,52 +1378,33 @@ fn arrayInitExprRlNone(
1410 return try gz.addPlNodePayloadIndex(tag, node, payload_index);1378 return try gz.addPlNodePayloadIndex(tag, node, payload_index);
1411}1379}
14121380
1413fn arrayInitExprRlTy(1381fn arrayInitExprInner(
1414 gz: *GenZir,1382 gz: *GenZir,
1415 scope: *Scope,1383 scope: *Scope,
1416 node: Ast.Node.Index,1384 node: Ast.Node.Index,
1417 elements: []const Ast.Node.Index,1385 elements: []const Ast.Node.Index,
1418 elem_ty_inst: Zir.Inst.Ref,1386 array_ty_inst: Zir.Inst.Ref,
1419 sentinel: Zir.Inst.Ref,1387 tag: Zir.Inst.Tag,
1420 ref: bool,
1421) InnerError!Zir.Inst.Ref {1388) InnerError!Zir.Inst.Ref {
1422 const astgen = gz.astgen;1389 const astgen = gz.astgen;
14231390
1424 const info: struct {1391 const len = elements.len + @boolToInt(array_ty_inst != .none);
1425 len: usize,
1426 tag: Zir.Inst.Tag,
1427 } = blk: {
1428 if (sentinel != .none) {
1429 break :blk .{
1430 .len = elements.len + 1,
1431 .tag = if (ref) .array_init_sent_ref else .array_init_sent,
1432 };
1433 } else {
1434 break :blk .{
1435 .len = elements.len,
1436 .tag = if (ref) .array_init_ref else .array_init,
1437 };
1438 }
1439 };
1440
1441 const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{1392 const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{
1442 .operands_len = @intCast(u32, info.len),1393 .operands_len = @intCast(u32, len),
1443 });1394 });
1444 var extra_index = try reserveExtra(astgen, info.len);1395 var extra_index = try reserveExtra(astgen, len);
14451396 if (array_ty_inst != .none) {
1446 const elem_rl: ResultLoc = .{ .ty = elem_ty_inst };1397 astgen.extra.items[extra_index] = @enumToInt(array_ty_inst);
1447 for (elements) |elem_init| {
1448 const elem_ref = try expr(gz, scope, elem_rl, elem_init);
1449 astgen.extra.items[extra_index] = @enumToInt(elem_ref);
1450 extra_index += 1;1398 extra_index += 1;
1451 }1399 }
14521400
1453 if (sentinel != .none) {1401 for (elements) |elem_init| {
1454 astgen.extra.items[extra_index] = @enumToInt(sentinel);1402 const elem_ref = try expr(gz, scope, .none, elem_init);
1403 astgen.extra.items[extra_index] = @enumToInt(elem_ref);
1455 extra_index += 1;1404 extra_index += 1;
1456 }1405 }
14571406
1458 return try gz.addPlNodePayloadIndex(info.tag, node, payload_index);1407 return try gz.addPlNodePayloadIndex(tag, node, payload_index);
1459}1408}
14601409
1461fn arrayInitExprRlPtr(1410fn arrayInitExprRlPtr(
...@@ -2244,7 +2193,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner...@@ -2244,7 +2193,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2244 .array_type,2193 .array_type,
2245 .array_type_sentinel,2194 .array_type_sentinel,
2246 .vector_type,2195 .vector_type,
2247 .elem_type,
2248 .indexable_ptr_len,2196 .indexable_ptr_len,
2249 .anyframe_type,2197 .anyframe_type,
2250 .as,2198 .as,
...@@ -2347,10 +2295,8 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner...@@ -2347,10 +2295,8 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2347 .struct_init_anon_ref,2295 .struct_init_anon_ref,
2348 .array_init,2296 .array_init,
2349 .array_init_anon,2297 .array_init_anon,
2350 .array_init_sent,
2351 .array_init_ref,2298 .array_init_ref,
2352 .array_init_anon_ref,2299 .array_init_anon_ref,
2353 .array_init_sent_ref,
2354 .union_init,2300 .union_init,
2355 .field_type,2301 .field_type,
2356 .field_type_ref,2302 .field_type_ref,
src/Sema.zig+17-28
...@@ -726,7 +726,6 @@ fn analyzeBodyInner(...@@ -726,7 +726,6 @@ fn analyzeBodyInner(
726 .elem_ptr_imm => try sema.zirElemPtrImm(block, inst),726 .elem_ptr_imm => try sema.zirElemPtrImm(block, inst),
727 .elem_val => try sema.zirElemVal(block, inst),727 .elem_val => try sema.zirElemVal(block, inst),
728 .elem_val_node => try sema.zirElemValNode(block, inst),728 .elem_val_node => try sema.zirElemValNode(block, inst),
729 .elem_type => try sema.zirElemType(block, inst),
730 .enum_literal => try sema.zirEnumLiteral(block, inst),729 .enum_literal => try sema.zirEnumLiteral(block, inst),
731 .enum_to_int => try sema.zirEnumToInt(block, inst),730 .enum_to_int => try sema.zirEnumToInt(block, inst),
732 .int_to_enum => try sema.zirIntToEnum(block, inst),731 .int_to_enum => try sema.zirIntToEnum(block, inst),
...@@ -798,10 +797,8 @@ fn analyzeBodyInner(...@@ -798,10 +797,8 @@ fn analyzeBodyInner(
798 .struct_init_ref => try sema.zirStructInit(block, inst, true),797 .struct_init_ref => try sema.zirStructInit(block, inst, true),
799 .struct_init_anon => try sema.zirStructInitAnon(block, inst, false),798 .struct_init_anon => try sema.zirStructInitAnon(block, inst, false),
800 .struct_init_anon_ref => try sema.zirStructInitAnon(block, inst, true),799 .struct_init_anon_ref => try sema.zirStructInitAnon(block, inst, true),
801 .array_init => try sema.zirArrayInit(block, inst, false, false),800 .array_init => try sema.zirArrayInit(block, inst, false),
802 .array_init_sent => try sema.zirArrayInit(block, inst, false, true),801 .array_init_ref => try sema.zirArrayInit(block, inst, true),
803 .array_init_ref => try sema.zirArrayInit(block, inst, true, false),
804 .array_init_sent_ref => try sema.zirArrayInit(block, inst, true, true),
805 .array_init_anon => try sema.zirArrayInitAnon(block, inst, false),802 .array_init_anon => try sema.zirArrayInitAnon(block, inst, false),
806 .array_init_anon_ref => try sema.zirArrayInitAnon(block, inst, true),803 .array_init_anon_ref => try sema.zirArrayInitAnon(block, inst, true),
807 .union_init => try sema.zirUnionInit(block, inst),804 .union_init => try sema.zirUnionInit(block, inst),
...@@ -13436,7 +13433,6 @@ fn zirArrayInit(...@@ -13436,7 +13433,6 @@ fn zirArrayInit(
13436 block: *Block,13433 block: *Block,
13437 inst: Zir.Inst.Index,13434 inst: Zir.Inst.Index,
13438 is_ref: bool,13435 is_ref: bool,
13439 is_sent: bool,
13440) CompileError!Air.Inst.Ref {13436) CompileError!Air.Inst.Ref {
13441 const gpa = sema.gpa;13437 const gpa = sema.gpa;
13442 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;13438 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
...@@ -13444,30 +13440,23 @@ fn zirArrayInit(...@@ -13444,30 +13440,23 @@ fn zirArrayInit(
1344413440
13445 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);13441 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
13446 const args = sema.code.refSlice(extra.end, extra.data.operands_len);13442 const args = sema.code.refSlice(extra.end, extra.data.operands_len);
13447 assert(args.len != 0);13443 assert(args.len >= 2); // array_ty + at least one element
1344813444
13449 const resolved_args = try gpa.alloc(Air.Inst.Ref, args.len);13445 const array_ty = try sema.resolveType(block, src, args[0]);
13450 defer gpa.free(resolved_args);13446 const sentinel_val = array_ty.sentinel();
13451
13452 for (args) |arg, i| resolved_args[i] = try sema.resolveInst(arg);
1345313447
13454 const elem_ty = sema.typeOf(resolved_args[0]);13448 const resolved_args = try gpa.alloc(Air.Inst.Ref, args.len - 1 + @boolToInt(sentinel_val != null));
13455 const array_ty = blk: {13449 defer gpa.free(resolved_args);
13456 if (!is_sent) {13450 const elem_ty = array_ty.elemType2();
13457 break :blk try Type.Tag.array.create(sema.arena, .{13451 for (args[1..]) |arg, i| {
13458 .len = resolved_args.len,13452 const resolved_arg = try sema.resolveInst(arg);
13459 .elem_type = elem_ty,13453 const arg_src = src; // TODO better source location
13460 });13454 resolved_args[i] = try sema.coerce(block, elem_ty, resolved_arg, arg_src);
13461 }13455 }
1346213456
13463 const sentinel_ref = resolved_args[resolved_args.len - 1];13457 if (sentinel_val) |some| {
13464 const val = try sema.resolveConstValue(block, src, sentinel_ref);13458 resolved_args[resolved_args.len - 1] = try sema.addConstant(elem_ty, some);
13465 break :blk try Type.Tag.array_sentinel.create(sema.arena, .{13459 }
13466 .len = resolved_args.len - 1,
13467 .sentinel = val,
13468 .elem_type = elem_ty,
13469 });
13470 };
1347113460
13472 const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| {13461 const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| {
13473 const arg_src = src; // TODO better source location13462 const arg_src = src; // TODO better source location
...@@ -13488,7 +13477,7 @@ fn zirArrayInit(...@@ -13488,7 +13477,7 @@ fn zirArrayInit(
13488 };13477 };
1348913478
13490 try sema.requireRuntimeBlock(block, runtime_src);13479 try sema.requireRuntimeBlock(block, runtime_src);
13491 try sema.queueFullTypeResolution(elem_ty);13480 try sema.queueFullTypeResolution(array_ty);
1349213481
13493 if (is_ref) {13482 if (is_ref) {
13494 const target = sema.mod.getTarget();13483 const target = sema.mod.getTarget();
src/Zir.zig-20
...@@ -221,9 +221,6 @@ pub const Inst = struct {...@@ -221,9 +221,6 @@ pub const Inst = struct {
221 /// Uses the `pl_node` union field with `Bin` payload.221 /// Uses the `pl_node` union field with `Bin` payload.
222 /// lhs is length, rhs is element type.222 /// lhs is length, rhs is element type.
223 vector_type,223 vector_type,
224 /// Given an array type, returns the element type.
225 /// Uses the `un_node` union field.
226 elem_type,
227 /// Given a pointer to an indexable object, returns the len property. This is224 /// Given a pointer to an indexable object, returns the len property. This is
228 /// used by for loops. This instruction also emits a for-loop specific compile225 /// used by for loops. This instruction also emits a for-loop specific compile
229 /// error if the indexable object is not indexable.226 /// error if the indexable object is not indexable.
...@@ -737,20 +734,12 @@ pub const Inst = struct {...@@ -737,20 +734,12 @@ pub const Inst = struct {
737 /// Array initialization syntax.734 /// Array initialization syntax.
738 /// Uses the `pl_node` field. Payload is `MultiOp`.735 /// Uses the `pl_node` field. Payload is `MultiOp`.
739 array_init,736 array_init,
740 /// Array initialization with sentinel.
741 /// Uses the `pl_node` field. Payload is `MultiOp`.
742 /// Final op in MultiOp is the sentinel.
743 array_init_sent,
744 /// Anonymous array initialization syntax.737 /// Anonymous array initialization syntax.
745 /// Uses the `pl_node` field. Payload is `MultiOp`.738 /// Uses the `pl_node` field. Payload is `MultiOp`.
746 array_init_anon,739 array_init_anon,
747 /// Array initialization syntax, make the result a pointer.740 /// Array initialization syntax, make the result a pointer.
748 /// Uses the `pl_node` field. Payload is `MultiOp`.741 /// Uses the `pl_node` field. Payload is `MultiOp`.
749 array_init_ref,742 array_init_ref,
750 /// Array initialization with sentinel.
751 /// Uses the `pl_node` field. Payload is `MultiOp`.
752 /// Final op in MultiOp is the sentinel.
753 array_init_sent_ref,
754 /// Anonymous array initialization syntax, make the result a pointer.743 /// Anonymous array initialization syntax, make the result a pointer.
755 /// Uses the `pl_node` field. Payload is `MultiOp`.744 /// Uses the `pl_node` field. Payload is `MultiOp`.
756 array_init_anon_ref,745 array_init_anon_ref,
...@@ -1019,7 +1008,6 @@ pub const Inst = struct {...@@ -1019,7 +1008,6 @@ pub const Inst = struct {
1019 .array_type,1008 .array_type,
1020 .array_type_sentinel,1009 .array_type_sentinel,
1021 .vector_type,1010 .vector_type,
1022 .elem_type,
1023 .indexable_ptr_len,1011 .indexable_ptr_len,
1024 .anyframe_type,1012 .anyframe_type,
1025 .as,1013 .as,
...@@ -1153,10 +1141,8 @@ pub const Inst = struct {...@@ -1153,10 +1141,8 @@ pub const Inst = struct {
1153 .struct_init_anon,1141 .struct_init_anon,
1154 .struct_init_anon_ref,1142 .struct_init_anon_ref,
1155 .array_init,1143 .array_init,
1156 .array_init_sent,
1157 .array_init_anon,1144 .array_init_anon,
1158 .array_init_ref,1145 .array_init_ref,
1159 .array_init_sent_ref,
1160 .array_init_anon_ref,1146 .array_init_anon_ref,
1161 .union_init,1147 .union_init,
1162 .field_type,1148 .field_type,
...@@ -1314,7 +1300,6 @@ pub const Inst = struct {...@@ -1314,7 +1300,6 @@ pub const Inst = struct {
1314 .array_type,1300 .array_type,
1315 .array_type_sentinel,1301 .array_type_sentinel,
1316 .vector_type,1302 .vector_type,
1317 .elem_type,
1318 .indexable_ptr_len,1303 .indexable_ptr_len,
1319 .anyframe_type,1304 .anyframe_type,
1320 .as,1305 .as,
...@@ -1426,10 +1411,8 @@ pub const Inst = struct {...@@ -1426,10 +1411,8 @@ pub const Inst = struct {
1426 .struct_init_anon,1411 .struct_init_anon,
1427 .struct_init_anon_ref,1412 .struct_init_anon_ref,
1428 .array_init,1413 .array_init,
1429 .array_init_sent,
1430 .array_init_anon,1414 .array_init_anon,
1431 .array_init_ref,1415 .array_init_ref,
1432 .array_init_sent_ref,
1433 .array_init_anon_ref,1416 .array_init_anon_ref,
1434 .union_init,1417 .union_init,
1435 .field_type,1418 .field_type,
...@@ -1554,7 +1537,6 @@ pub const Inst = struct {...@@ -1554,7 +1537,6 @@ pub const Inst = struct {
1554 .array_type = .bin,1537 .array_type = .bin,
1555 .array_type_sentinel = .pl_node,1538 .array_type_sentinel = .pl_node,
1556 .vector_type = .pl_node,1539 .vector_type = .pl_node,
1557 .elem_type = .un_node,
1558 .indexable_ptr_len = .un_node,1540 .indexable_ptr_len = .un_node,
1559 .anyframe_type = .un_node,1541 .anyframe_type = .un_node,
1560 .as = .bin,1542 .as = .bin,
...@@ -1688,10 +1670,8 @@ pub const Inst = struct {...@@ -1688,10 +1670,8 @@ pub const Inst = struct {
1688 .struct_init_anon = .pl_node,1670 .struct_init_anon = .pl_node,
1689 .struct_init_anon_ref = .pl_node,1671 .struct_init_anon_ref = .pl_node,
1690 .array_init = .pl_node,1672 .array_init = .pl_node,
1691 .array_init_sent = .pl_node,
1692 .array_init_anon = .pl_node,1673 .array_init_anon = .pl_node,
1693 .array_init_ref = .pl_node,1674 .array_init_ref = .pl_node,
1694 .array_init_sent_ref = .pl_node,
1695 .array_init_anon_ref = .pl_node,1675 .array_init_anon_ref = .pl_node,
1696 .union_init = .pl_node,1676 .union_init = .pl_node,
1697 .type_info = .un_node,1677 .type_info = .un_node,
src/print_zir.zig+3-7
...@@ -226,7 +226,6 @@ const Writer = struct {...@@ -226,7 +226,6 @@ const Writer = struct {
226 .pop_count,226 .pop_count,
227 .byte_swap,227 .byte_swap,
228 .bit_reverse,228 .bit_reverse,
229 .elem_type,
230 .@"resume",229 .@"resume",
231 .@"await",230 .@"await",
232 .switch_cond,231 .switch_cond,
...@@ -268,10 +267,6 @@ const Writer = struct {...@@ -268,10 +267,6 @@ const Writer = struct {
268 .array_init_anon_ref,267 .array_init_anon_ref,
269 => try self.writeArrayInit(stream, inst),268 => try self.writeArrayInit(stream, inst),
270269
271 .array_init_sent,
272 .array_init_sent_ref,
273 => try self.writeArrayInitSent(stream, inst),
274
275 .slice_start => try self.writeSliceStart(stream, inst),270 .slice_start => try self.writeSliceStart(stream, inst),
276 .slice_end => try self.writeSliceEnd(stream, inst),271 .slice_end => try self.writeSliceEnd(stream, inst),
277 .slice_sentinel => try self.writeSliceSentinel(stream, inst),272 .slice_sentinel => try self.writeSliceSentinel(stream, inst),
...@@ -2085,8 +2080,9 @@ const Writer = struct {...@@ -2085,8 +2080,9 @@ const Writer = struct {
2085 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);2080 const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
2086 const args = self.code.refSlice(extra.end, extra.data.operands_len);2081 const args = self.code.refSlice(extra.end, extra.data.operands_len);
20872082
2088 try stream.writeAll(".{");2083 try self.writeInstRef(stream, args[0]);
2089 for (args) |arg, i| {2084 try stream.writeAll("{");
2085 for (args[1..]) |arg, i| {
2090 if (i != 0) try stream.writeAll(", ");2086 if (i != 0) try stream.writeAll(", ");
2091 try self.writeInstRef(stream, arg);2087 try self.writeInstRef(stream, arg);
2092 }2088 }
test/behavior/basic.zig+7
...@@ -942,3 +942,10 @@ test "comptime int in switch in catch is casted to correct inferred type" {...@@ -942,3 +942,10 @@ test "comptime int in switch in catch is casted to correct inferred type" {
942 };942 };
943 _ = b;943 _ = b;
944}944}
945
946test "vector initialized with array init syntax has proper type" {
947 comptime {
948 const actual = -@Vector(4, i32){ 1, 2, 3, 4 };
949 try std.testing.expectEqual(@Vector(4, i32){ -1, -2, -3, -4 }, actual);
950 }
951}
test/behavior/tuple.zig-2
...@@ -194,8 +194,6 @@ test "tuple as the result from a labeled block" {...@@ -194,8 +194,6 @@ test "tuple as the result from a labeled block" {
194}194}
195195
196test "initializing tuple with explicit type" {196test "initializing tuple with explicit type" {
197 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
198
199 const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });197 const T = @TypeOf(.{ @as(i32, 0), @as(u32, 0) });
200 var a = T{ 0, 0 };198 var a = T{ 0, 0 };
201 _ = a;199 _ = a;