authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-04-29 12:23:14+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-04-30 01:06:01+03:00
log1d455896cb24165c5a3e0b3e10934c60a285589d
treec1897fc1304802ae8dbaa0bdeed9637f727efd4e
parenta6f254ec3e106e6496a84c89375427e6adc9065f

Zir: move more common instructions out of extended


4 files changed, 192 insertions(+), 151 deletions(-)

src/AstGen.zig+57-26
......@@ -1078,8 +1078,14 @@ fn awaitExpr(
10781078 });
10791079 }
10801080 const operand = try expr(gz, scope, .none, rhs_node);
1081 const tag: Zir.Inst.Tag = if (gz.nosuspend_node != 0) .await_nosuspend else .@"await";
1082 const result = try gz.addUnNode(tag, operand, node);
1081 const result = if (gz.nosuspend_node != 0)
1082 try gz.addExtendedPayload(.await_nosuspend, Zir.Inst.UnNode{
1083 .node = gz.nodeIndexToRelative(node),
1084 .operand = operand,
1085 })
1086 else
1087 try gz.addUnNode(.@"await", operand, node);
1088
10831089 return rvalue(gz, rl, result, node);
10841090}
10851091
......@@ -2349,7 +2355,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
23492355 .int_to_ptr,
23502356 .float_cast,
23512357 .int_cast,
2352 .err_set_cast,
23532358 .ptr_cast,
23542359 .truncate,
23552360 .align_cast,
......@@ -2386,15 +2391,24 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
23862391 .c_import,
23872392 .@"resume",
23882393 .@"await",
2389 .await_nosuspend,
23902394 .ret_err_value_code,
2391 .extended,
23922395 .closure_get,
23932396 .array_base_ptr,
23942397 .field_base_ptr,
23952398 .param_type,
2399 .ret_ptr,
2400 .ret_type,
23962401 => break :b false,
23972402
2403 .extended => switch (gz.astgen.instructions.items(.data)[inst].extended.opcode) {
2404 .breakpoint,
2405 .fence,
2406 .set_align_stack,
2407 .set_float_mode,
2408 => break :b true,
2409 else => break :b false,
2410 },
2411
23982412 // ZIR instructions that are always `noreturn`.
23992413 .@"break",
24002414 .break_inline,
......@@ -2415,11 +2429,11 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
24152429 },
24162430
24172431 // ZIR instructions that are always `void`.
2418 .breakpoint,
2419 .fence,
24202432 .dbg_stmt,
24212433 .dbg_var_ptr,
24222434 .dbg_var_val,
2435 .dbg_block_begin,
2436 .dbg_block_end,
24232437 .ensure_result_used,
24242438 .ensure_result_non_error,
24252439 .@"export",
......@@ -2436,9 +2450,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
24362450 .validate_struct_init_comptime,
24372451 .validate_array_init,
24382452 .validate_array_init_comptime,
2439 .set_align_stack,
24402453 .set_cold,
2441 .set_float_mode,
24422454 .set_runtime_safety,
24432455 .closure_capture,
24442456 .memcpy,
......@@ -6310,9 +6322,9 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
63106322 }
63116323
63126324 const rl: ResultLoc = if (nodeMayNeedMemoryLocation(tree, operand_node, true)) .{
6313 .ptr = try gz.addNodeExtended(.ret_ptr, node),
6325 .ptr = try gz.addNode(.ret_ptr, node),
63146326 } else .{
6315 .ty = try gz.addNodeExtended(.ret_type, node),
6327 .ty = try gz.addNode(.ret_type, node),
63166328 };
63176329 const prev_anon_name_strategy = gz.anon_name_strategy;
63186330 gz.anon_name_strategy = .func;
......@@ -7183,7 +7195,26 @@ fn builtinCall(
71837195 },
71847196 .fence => {
71857197 const order = try expr(gz, scope, .{ .coerced_ty = .atomic_order_type }, params[0]);
7186 const result = try gz.addUnNode(.fence, order, node);
7198 const result = try gz.addExtendedPayload(.fence, Zir.Inst.UnNode{
7199 .node = gz.nodeIndexToRelative(node),
7200 .operand = order,
7201 });
7202 return rvalue(gz, rl, result, node);
7203 },
7204 .set_float_mode => {
7205 const order = try expr(gz, scope, .{ .coerced_ty = .float_mode_type }, params[0]);
7206 const result = try gz.addExtendedPayload(.set_float_mode, Zir.Inst.UnNode{
7207 .node = gz.nodeIndexToRelative(node),
7208 .operand = order,
7209 });
7210 return rvalue(gz, rl, result, node);
7211 },
7212 .set_align_stack => {
7213 const order = try expr(gz, scope, align_rl, params[0]);
7214 const result = try gz.addExtendedPayload(.set_align_stack, Zir.Inst.UnNode{
7215 .node = gz.nodeIndexToRelative(node),
7216 .operand = order,
7217 });
71877218 return rvalue(gz, rl, result, node);
71887219 },
71897220
......@@ -7198,14 +7229,13 @@ fn builtinCall(
71987229 return rvalue(gz, rl, result, node);
71997230 },
72007231
7201 .breakpoint => return simpleNoOpVoid(gz, rl, node, .breakpoint),
7202
72037232 // zig fmt: off
72047233 .This => return rvalue(gz, rl, try gz.addNodeExtended(.this, node), node),
72057234 .return_address => return rvalue(gz, rl, try gz.addNodeExtended(.ret_addr, node), node),
72067235 .error_return_trace => return rvalue(gz, rl, try gz.addNodeExtended(.error_return_trace, node), node),
72077236 .frame => return rvalue(gz, rl, try gz.addNodeExtended(.frame, node), node),
72087237 .frame_address => return rvalue(gz, rl, try gz.addNodeExtended(.frame_address, node), node),
7238 .breakpoint => return rvalue(gz, rl, try gz.addNodeExtended(.breakpoint, node), node),
72097239
72107240 .type_info => return simpleUnOpType(gz, scope, rl, node, params[0], .type_info),
72117241 .size_of => return simpleUnOpType(gz, scope, rl, node, params[0], .size_of),
......@@ -7222,9 +7252,7 @@ fn builtinCall(
72227252 .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file),
72237253 .error_name => return simpleUnOp(gz, scope, rl, node, .{ .ty = .anyerror_type }, params[0], .error_name),
72247254 .panic => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .panic),
7225 .set_align_stack => return simpleUnOp(gz, scope, rl, node, align_rl, params[0], .set_align_stack),
72267255 .set_cold => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_cold),
7227 .set_float_mode => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .float_mode_type }, params[0], .set_float_mode),
72287256 .set_runtime_safety => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_runtime_safety),
72297257 .sqrt => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sqrt),
72307258 .sin => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sin),
......@@ -7252,7 +7280,6 @@ fn builtinCall(
72527280 .int_to_enum => return typeCast(gz, scope, rl, node, params[0], params[1], .int_to_enum),
72537281 .float_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .float_cast),
72547282 .int_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .int_cast),
7255 .err_set_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .err_set_cast),
72567283 .ptr_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .ptr_cast),
72577284 .truncate => return typeCast(gz, scope, rl, node, params[0], params[1], .truncate),
72587285 // zig fmt: on
......@@ -7266,6 +7293,14 @@ fn builtinCall(
72667293 });
72677294 return rvalue(gz, rl, result, node);
72687295 },
7296 .err_set_cast => {
7297 const result = try gz.addExtendedPayload(.err_set_cast, Zir.Inst.BinNode{
7298 .lhs = try typeExpr(gz, scope, params[0]),
7299 .rhs = try expr(gz, scope, .none, params[1]),
7300 .node = gz.nodeIndexToRelative(node),
7301 });
7302 return rvalue(gz, rl, result, node);
7303 },
72697304
72707305 // zig fmt: off
72717306 .has_decl => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_decl),
......@@ -8940,7 +8975,8 @@ fn rvalue(
89408975 const result = r: {
89418976 if (refToIndex(raw_result)) |result_index| {
89428977 const zir_tags = gz.astgen.instructions.items(.tag);
8943 if (zir_tags[result_index].isAlwaysVoid()) {
8978 const data = gz.astgen.instructions.items(.data)[result_index];
8979 if (zir_tags[result_index].isAlwaysVoid(data)) {
89448980 break :r Zir.Inst.Ref.void_value;
89458981 }
89468982 }
......@@ -10893,9 +10929,7 @@ const GenZir = struct {
1089310929 fn addDbgBlockBegin(gz: *GenZir) !void {
1089410930 if (gz.force_comptime) return;
1089510931
10896 _ = try gz.add(.{ .tag = .extended, .data = .{
10897 .extended = .{ .opcode = .dbg_block_begin, .small = undefined, .operand = undefined },
10898 } });
10932 _ = try gz.add(.{ .tag = .dbg_block_begin, .data = undefined });
1089910933 }
1090010934
1090110935 fn addDbgBlockEnd(gz: *GenZir) !void {
......@@ -10903,18 +10937,15 @@ const GenZir = struct {
1090310937 const gpa = gz.astgen.gpa;
1090410938
1090510939 const tags = gz.astgen.instructions.items(.tag);
10906 const data = gz.astgen.instructions.items(.data);
1090710940 const last_inst = gz.instructions.items[gz.instructions.items.len - 1];
1090810941 // remove dbg_block_begin immediately followed by dbg_block_end
10909 if (tags[last_inst] == .extended and data[last_inst].extended.opcode == .dbg_block_begin) {
10942 if (tags[last_inst] == .dbg_block_begin) {
1091010943 _ = gz.instructions.pop();
1091110944 return;
1091210945 }
1091310946
1091410947 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
10915 try gz.astgen.instructions.append(gpa, .{ .tag = .extended, .data = .{
10916 .extended = .{ .opcode = .dbg_block_end, .small = undefined, .operand = undefined },
10917 } });
10948 try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined });
1091810949 try gz.instructions.insert(gpa, gz.instructions.items.len - 1, new_index);
1091910950 }
1092010951
src/Sema.zig+70-69
......@@ -819,7 +819,6 @@ fn analyzeBodyInner(
819819 .int_to_ptr => try sema.zirIntToPtr(block, inst),
820820 .float_cast => try sema.zirFloatCast(block, inst),
821821 .int_cast => try sema.zirIntCast(block, inst),
822 .err_set_cast => try sema.zirErrSetCast(block, inst),
823822 .ptr_cast => try sema.zirPtrCast(block, inst),
824823 .truncate => try sema.zirTruncate(block, inst),
825824 .align_cast => try sema.zirAlignCast(block, inst),
......@@ -842,8 +841,7 @@ fn analyzeBodyInner(
842841 .field_parent_ptr => try sema.zirFieldParentPtr(block, inst),
843842 .builtin_async_call => try sema.zirBuiltinAsyncCall(block, inst),
844843 .@"resume" => try sema.zirResume(block, inst),
845 .@"await" => try sema.zirAwait(block, inst, false),
846 .await_nosuspend => try sema.zirAwait(block, inst, true),
844 .@"await" => try sema.zirAwait(block, inst),
847845 .array_base_ptr => try sema.zirArrayBasePtr(block, inst),
848846 .field_base_ptr => try sema.zirFieldBasePtr(block, inst),
849847
......@@ -894,6 +892,9 @@ fn analyzeBodyInner(
894892 .shl_exact => try sema.zirShl(block, inst, .shl_exact),
895893 .shl_sat => try sema.zirShl(block, inst, .shl_sat),
896894
895 .ret_ptr => try sema.zirRetPtr(block, inst),
896 .ret_type => try sema.zirRetType(block, inst),
897
897898 // Instructions that we know to *always* be noreturn based solely on their tag.
898899 // These functions match the return type of analyzeBody so that we can
899900 // tail call them here.
......@@ -916,8 +917,6 @@ fn analyzeBodyInner(
916917 .enum_decl => try sema.zirEnumDecl( block, extended),
917918 .union_decl => try sema.zirUnionDecl( block, extended, inst),
918919 .opaque_decl => try sema.zirOpaqueDecl( block, extended),
919 .ret_ptr => try sema.zirRetPtr( block, extended),
920 .ret_type => try sema.zirRetType( block, extended),
921920 .this => try sema.zirThis( block, extended),
922921 .ret_addr => try sema.zirRetAddr( block, extended),
923922 .builtin_src => try sema.zirBuiltinSrc( block, extended),
......@@ -940,16 +939,28 @@ fn analyzeBodyInner(
940939 .wasm_memory_grow => try sema.zirWasmMemoryGrow( block, extended),
941940 .prefetch => try sema.zirPrefetch( block, extended),
942941 .field_call_bind_named => try sema.zirFieldCallBindNamed(block, extended),
942 .err_set_cast => try sema.zirErrSetCast( block, extended),
943 .await_nosuspend => try sema.zirAwaitNosuspend( block, extended),
943944 // zig fmt: on
944 .dbg_block_begin => {
945 dbg_block_begins += 1;
946 try sema.zirDbgBlockBegin(block);
945 .fence => {
946 try sema.zirFence(block, extended);
947947 i += 1;
948948 continue;
949949 },
950 .dbg_block_end => {
951 dbg_block_begins -= 1;
952 try sema.zirDbgBlockEnd(block);
950 .set_float_mode => {
951 try sema.zirSetFloatMode(block, extended);
952 i += 1;
953 continue;
954 },
955 .set_align_stack => {
956 try sema.zirSetAlignStack(block, extended);
957 i += 1;
958 continue;
959 },
960 .breakpoint => {
961 if (!block.is_comptime) {
962 _ = try block.addNoOp(.breakpoint);
963 }
953964 i += 1;
954965 continue;
955966 },
......@@ -961,18 +972,6 @@ fn analyzeBodyInner(
961972 // continue the loop.
962973 // We also know that they cannot be referenced later, so we avoid
963974 // putting them into the map.
964 .breakpoint => {
965 if (!block.is_comptime) {
966 _ = try block.addNoOp(.breakpoint);
967 }
968 i += 1;
969 continue;
970 },
971 .fence => {
972 try sema.zirFence(block, inst);
973 i += 1;
974 continue;
975 },
976975 .dbg_stmt => {
977976 try sema.zirDbgStmt(block, inst);
978977 i += 1;
......@@ -988,6 +987,18 @@ fn analyzeBodyInner(
988987 i += 1;
989988 continue;
990989 },
990 .dbg_block_begin => {
991 dbg_block_begins += 1;
992 try sema.zirDbgBlockBegin(block);
993 i += 1;
994 continue;
995 },
996 .dbg_block_end => {
997 dbg_block_begins -= 1;
998 try sema.zirDbgBlockEnd(block);
999 i += 1;
1000 continue;
1001 },
9911002 .ensure_err_payload_void => {
9921003 try sema.zirEnsureErrPayloadVoid(block, inst);
9931004 i += 1;
......@@ -1078,21 +1089,11 @@ fn analyzeBodyInner(
10781089 i += 1;
10791090 continue;
10801091 },
1081 .set_align_stack => {
1082 try sema.zirSetAlignStack(block, inst);
1083 i += 1;
1084 continue;
1085 },
10861092 .set_cold => {
10871093 try sema.zirSetCold(block, inst);
10881094 i += 1;
10891095 continue;
10901096 },
1091 .set_float_mode => {
1092 try sema.zirSetFloatMode(block, inst);
1093 i += 1;
1094 continue;
1095 },
10961097 .set_runtime_safety => {
10971098 try sema.zirSetRuntimeSafety(block, inst);
10981099 i += 1;
......@@ -2452,15 +2453,12 @@ fn zirErrorSetDecl(
24522453 return sema.analyzeDeclVal(block, src, new_decl_index);
24532454}
24542455
2455fn zirRetPtr(
2456 sema: *Sema,
2457 block: *Block,
2458 extended: Zir.Inst.Extended.InstData,
2459) CompileError!Air.Inst.Ref {
2456fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
24602457 const tracy = trace(@src());
24612458 defer tracy.end();
24622459
2463 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
2460 const inst_data = sema.code.instructions.items(.data)[inst].node;
2461 const src: LazySrcLoc = .{ .node_offset = inst_data };
24642462 try sema.requireFunctionBlock(block, src);
24652463
24662464 if (block.is_comptime) {
......@@ -2493,15 +2491,12 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
24932491 return sema.analyzeRef(block, inst_data.src(), operand);
24942492}
24952493
2496fn zirRetType(
2497 sema: *Sema,
2498 block: *Block,
2499 extended: Zir.Inst.Extended.InstData,
2500) CompileError!Air.Inst.Ref {
2494fn zirRetType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
25012495 const tracy = trace(@src());
25022496 defer tracy.end();
25032497
2504 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
2498 const inst_data = sema.code.instructions.items(.data)[inst].node;
2499 const src: LazySrcLoc = .{ .node_offset = inst_data };
25052500 try sema.requireFunctionBlock(block, src);
25062501 return sema.addType(sema.fn_ret_ty);
25072502}
......@@ -3746,9 +3741,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
37463741 sema.fn_ret_ty.zigTypeTag() == .ErrorUnion)
37473742 {
37483743 if (Zir.refToIndex(extra.lhs)) |ptr_index| {
3749 if (zir_tags[ptr_index] == .extended and
3750 zir_datas[ptr_index].extended.opcode == .ret_ptr)
3751 {
3744 if (zir_tags[ptr_index] == .ret_ptr) {
37523745 try sema.addToInferredErrorSet(operand);
37533746 }
37543747 }
......@@ -4392,11 +4385,11 @@ pub fn analyzeExport(
43924385 errdefer de_gop.value_ptr.* = gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1);
43934386}
43944387
4395fn zirSetAlignStack(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
4396 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4397 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
4398 const src: LazySrcLoc = inst_data.src();
4399 const alignment = try sema.resolveAlign(block, operand_src, inst_data.operand);
4388fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
4389 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
4390 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
4391 const src: LazySrcLoc = .{ .node_offset = extra.node };
4392 const alignment = try sema.resolveAlign(block, operand_src, extra.operand);
44004393 if (alignment > 256) {
44014394 return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{
44024395 alignment,
......@@ -4433,10 +4426,10 @@ fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
44334426 func.is_cold = is_cold;
44344427}
44354428
4436fn zirSetFloatMode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
4437 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4438 const src: LazySrcLoc = inst_data.src();
4439 const float_mode = try sema.resolveBuiltinEnum(block, src, inst_data.operand, "FloatMode");
4429fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
4430 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
4431 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
4432 const float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode");
44404433 switch (float_mode) {
44414434 .Strict => return,
44424435 .Optimized => {
......@@ -4451,12 +4444,12 @@ fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
44514444 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand);
44524445}
44534446
4454fn zirFence(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
4447fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
44554448 if (block.is_comptime) return;
44564449
4457 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4458 const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
4459 const order = try sema.resolveAtomicOrder(block, order_src, inst_data.operand);
4450 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
4451 const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
4452 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand);
44604453
44614454 if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) {
44624455 return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{});
......@@ -14144,12 +14137,11 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1414414137 return block.addBitCast(type_res, operand_coerced);
1414514138}
1414614139
14147fn zirErrSetCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
14148 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
14149 const src = inst_data.src();
14150 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
14151 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
14152 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14140fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
14141 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
14142 const src: LazySrcLoc = .{ .node_offset = extra.node };
14143 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
14144 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
1415314145 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
1415414146 const operand = sema.resolveInst(extra.rhs);
1415514147 const operand_ty = sema.typeOf(operand);
......@@ -16007,15 +15999,24 @@ fn zirAwait(
1600715999 sema: *Sema,
1600816000 block: *Block,
1600916001 inst: Zir.Inst.Index,
16010 is_nosuspend: bool,
1601116002) CompileError!Air.Inst.Ref {
1601216003 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1601316004 const src = inst_data.src();
1601416005
16015 _ = is_nosuspend;
1601616006 return sema.fail(block, src, "TODO: Sema.zirAwait", .{});
1601716007}
1601816008
16009fn zirAwaitNosuspend(
16010 sema: *Sema,
16011 block: *Block,
16012 extended: Zir.Inst.Extended.InstData,
16013) CompileError!Air.Inst.Ref {
16014 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
16015 const src: LazySrcLoc = .{ .node_offset = extra.node };
16016
16017 return sema.fail(block, src, "TODO: Sema.zirAwaitNosuspend", .{});
16018}
16019
1601916020fn zirVarExtended(
1602016021 sema: *Sema,
1602116022 block: *Block,
src/Zir.zig+44-42
......@@ -278,8 +278,6 @@ pub const Inst = struct {
278278 /// break instruction in a block, and the target block is the parent.
279279 /// Uses the `break` union field.
280280 break_inline,
281 /// Uses the `node` union field.
282 breakpoint,
283281 /// Function call.
284282 /// Uses `pl_node`. AST node is the function call. Payload is `Call`.
285283 call,
......@@ -331,6 +329,10 @@ pub const Inst = struct {
331329 /// Same as `dbg_var_ptr` but the local is always a const and the operand
332330 /// is the local's value.
333331 dbg_var_val,
332 /// Marks the beginning of a semantic scope for debug info variables.
333 dbg_block_begin,
334 /// Marks the end of a semantic scope for debug info variables.
335 dbg_block_end,
334336 /// Uses a name to identify a Decl and takes a pointer to it.
335337 /// Uses the `str_tok` union field.
336338 decl_ref,
......@@ -499,6 +501,12 @@ pub const Inst = struct {
499501 /// this instruction; a following 'ret' instruction will do the diversion.
500502 /// Uses the `str_tok` union field.
501503 ret_err_value_code,
504 /// Obtains a pointer to the return value.
505 /// Uses the `node` union field.
506 ret_ptr,
507 /// Obtains the return type of the in-scope function.
508 /// Uses the `node` union field.
509 ret_type,
502510 /// Create a pointer type that does not have a sentinel, alignment, address space, or bit range specified.
503511 /// Uses the `ptr_type_simple` union field.
504512 ptr_type_simple,
......@@ -744,8 +752,6 @@ pub const Inst = struct {
744752 size_of,
745753 /// Implements the `@bitSizeOf` builtin. Uses `un_node`.
746754 bit_size_of,
747 /// Implements the `@fence` builtin. Uses `un_node`.
748 fence,
749755
750756 /// Implement builtin `@ptrToInt`. Uses `un_node`.
751757 /// Convert a pointer to a `usize` integer.
......@@ -774,12 +780,8 @@ pub const Inst = struct {
774780 error_name,
775781 /// Implement builtin `@panic`. Uses `un_node`.
776782 panic,
777 /// Implement builtin `@setAlignStack`. Uses `un_node`.
778 set_align_stack,
779783 /// Implement builtin `@setCold`. Uses `un_node`.
780784 set_cold,
781 /// Implement builtin `@setFloatMode`. Uses `un_node`.
782 set_float_mode,
783785 /// Implement builtin `@setRuntimeSafety`. Uses `un_node`.
784786 set_runtime_safety,
785787 /// Implement builtin `@sqrt`. Uses `un_node`.
......@@ -843,9 +845,6 @@ pub const Inst = struct {
843845 /// Convert an integer value to another integer type, asserting that the destination type
844846 /// can hold the same mathematical value.
845847 int_cast,
846 /// Implements the `@errSetCast` builtin.
847 /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
848 err_set_cast,
849848 /// Implements the `@ptrCast` builtin.
850849 /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
851850 ptr_cast,
......@@ -972,7 +971,6 @@ pub const Inst = struct {
972971 /// Implements `resume` syntax. Uses `un_node` field.
973972 @"resume",
974973 @"await",
975 await_nosuspend,
976974
977975 /// When a type or function refers to a comptime value from an outer
978976 /// scope, that forms a closure over comptime value. The outer scope
......@@ -1028,8 +1026,6 @@ pub const Inst = struct {
10281026 .bool_br_and,
10291027 .bool_br_or,
10301028 .bool_not,
1031 .breakpoint,
1032 .fence,
10331029 .call,
10341030 .cmp_lt,
10351031 .cmp_lte,
......@@ -1044,6 +1040,8 @@ pub const Inst = struct {
10441040 .dbg_stmt,
10451041 .dbg_var_ptr,
10461042 .dbg_var_val,
1043 .dbg_block_begin,
1044 .dbg_block_end,
10471045 .decl_ref,
10481046 .decl_val,
10491047 .load,
......@@ -1164,9 +1162,7 @@ pub const Inst = struct {
11641162 .bool_to_int,
11651163 .embed_file,
11661164 .error_name,
1167 .set_align_stack,
11681165 .set_cold,
1169 .set_float_mode,
11701166 .set_runtime_safety,
11711167 .sqrt,
11721168 .sin,
......@@ -1192,7 +1188,6 @@ pub const Inst = struct {
11921188 .int_to_ptr,
11931189 .float_cast,
11941190 .int_cast,
1195 .err_set_cast,
11961191 .ptr_cast,
11971192 .truncate,
11981193 .align_cast,
......@@ -1231,11 +1226,12 @@ pub const Inst = struct {
12311226 .c_import,
12321227 .@"resume",
12331228 .@"await",
1234 .await_nosuspend,
12351229 .ret_err_value_code,
12361230 .extended,
12371231 .closure_get,
12381232 .closure_capture,
1233 .ret_ptr,
1234 .ret_type,
12391235 => false,
12401236
12411237 .@"break",
......@@ -1258,13 +1254,13 @@ pub const Inst = struct {
12581254 /// AstGen uses this to find out if `Ref.void_value` should be used in place
12591255 /// of the result of a given instruction. This allows Sema to forego adding
12601256 /// the instruction to the map after analysis.
1261 pub fn isAlwaysVoid(tag: Tag) bool {
1257 pub fn isAlwaysVoid(tag: Tag, data: Data) bool {
12621258 return switch (tag) {
1263 .breakpoint,
1264 .fence,
12651259 .dbg_stmt,
12661260 .dbg_var_ptr,
12671261 .dbg_var_val,
1262 .dbg_block_begin,
1263 .dbg_block_end,
12681264 .ensure_result_used,
12691265 .ensure_result_non_error,
12701266 .ensure_err_payload_void,
......@@ -1283,9 +1279,7 @@ pub const Inst = struct {
12831279 .validate_array_init_comptime,
12841280 .@"export",
12851281 .export_value,
1286 .set_align_stack,
12871282 .set_cold,
1288 .set_float_mode,
12891283 .set_runtime_safety,
12901284 .memcpy,
12911285 .memset,
......@@ -1464,7 +1458,6 @@ pub const Inst = struct {
14641458 .int_to_ptr,
14651459 .float_cast,
14661460 .int_cast,
1467 .err_set_cast,
14681461 .ptr_cast,
14691462 .truncate,
14701463 .align_cast,
......@@ -1500,9 +1493,7 @@ pub const Inst = struct {
15001493 .c_import,
15011494 .@"resume",
15021495 .@"await",
1503 .await_nosuspend,
15041496 .ret_err_value_code,
1505 .extended,
15061497 .closure_get,
15071498 .closure_capture,
15081499 .@"break",
......@@ -1514,11 +1505,18 @@ pub const Inst = struct {
15141505 .ret_load,
15151506 .ret_tok,
15161507 .ret_err_value,
1508 .ret_ptr,
1509 .ret_type,
15171510 .@"unreachable",
15181511 .repeat,
15191512 .repeat_inline,
15201513 .panic,
15211514 => false,
1515
1516 .extended => switch (data.extended.opcode) {
1517 .breakpoint, .fence => true,
1518 else => false,
1519 },
15221520 };
15231521 }
15241522
......@@ -1563,7 +1561,6 @@ pub const Inst = struct {
15631561 .bool_br_or = .bool_br,
15641562 .@"break" = .@"break",
15651563 .break_inline = .@"break",
1566 .breakpoint = .node,
15671564 .call = .pl_node,
15681565 .cmp_lt = .pl_node,
15691566 .cmp_lte = .pl_node,
......@@ -1580,6 +1577,8 @@ pub const Inst = struct {
15801577 .dbg_stmt = .dbg_stmt,
15811578 .dbg_var_ptr = .str_op,
15821579 .dbg_var_val = .str_op,
1580 .dbg_block_begin = .tok,
1581 .dbg_block_end = .tok,
15831582 .decl_ref = .str_tok,
15841583 .decl_val = .str_tok,
15851584 .load = .un_node,
......@@ -1623,6 +1622,8 @@ pub const Inst = struct {
16231622 .ret_tok = .un_tok,
16241623 .ret_err_value = .str_tok,
16251624 .ret_err_value_code = .str_tok,
1625 .ret_ptr = .node,
1626 .ret_type = .node,
16261627 .ptr_type_simple = .ptr_type_simple,
16271628 .ptr_type = .ptr_type,
16281629 .slice_start = .pl_node,
......@@ -1685,7 +1686,6 @@ pub const Inst = struct {
16851686 .type_info = .un_node,
16861687 .size_of = .un_node,
16871688 .bit_size_of = .un_node,
1688 .fence = .un_node,
16891689
16901690 .ptr_to_int = .un_node,
16911691 .error_to_int = .un_node,
......@@ -1698,9 +1698,7 @@ pub const Inst = struct {
16981698 .embed_file = .un_node,
16991699 .error_name = .un_node,
17001700 .panic = .un_node,
1701 .set_align_stack = .un_node,
17021701 .set_cold = .un_node,
1703 .set_float_mode = .un_node,
17041702 .set_runtime_safety = .un_node,
17051703 .sqrt = .un_node,
17061704 .sin = .un_node,
......@@ -1728,7 +1726,6 @@ pub const Inst = struct {
17281726 .int_to_enum = .pl_node,
17291727 .float_cast = .pl_node,
17301728 .int_cast = .pl_node,
1731 .err_set_cast = .pl_node,
17321729 .ptr_cast = .pl_node,
17331730 .truncate = .pl_node,
17341731 .align_cast = .pl_node,
......@@ -1788,7 +1785,6 @@ pub const Inst = struct {
17881785
17891786 .@"resume" = .un_node,
17901787 .@"await" = .un_node,
1791 .await_nosuspend = .un_node,
17921788
17931789 .closure_capture = .un_tok,
17941790 .closure_get = .inst_node,
......@@ -1834,12 +1830,6 @@ pub const Inst = struct {
18341830 /// `operand` is payload index to `OpaqueDecl`.
18351831 /// `small` is `OpaqueDecl.Small`.
18361832 opaque_decl,
1837 /// Obtains a pointer to the return value.
1838 /// `operand` is `src_node: i32`.
1839 ret_ptr,
1840 /// Obtains the return type of the in-scope function.
1841 /// `operand` is `src_node: i32`.
1842 ret_type,
18431833 /// Implements the `@This` builtin.
18441834 /// `operand` is `src_node: i32`.
18451835 this,
......@@ -1917,10 +1907,6 @@ pub const Inst = struct {
19171907 /// The `@prefetch` builtin.
19181908 /// `operand` is payload index to `BinNode`.
19191909 prefetch,
1920 /// Marks the beginning of a semantic scope for debug info variables.
1921 dbg_block_begin,
1922 /// Marks the end of a semantic scope for debug info variables.
1923 dbg_block_end,
19241910 /// Given a pointer to a struct or object that contains virtual fields, returns the
19251911 /// named field. If there is no named field, searches in the type for a decl that
19261912 /// matches the field name. The decl is resolved and we ensure that it's a function
......@@ -1931,6 +1917,22 @@ pub const Inst = struct {
19311917 /// `builtin_call` instruction. Any other use is invalid zir and may crash the compiler.
19321918 /// Uses `pl_node` field. The AST node is the `@field` builtin. Payload is FieldNamedNode.
19331919 field_call_bind_named,
1920 /// Implements the `@fence` builtin.
1921 /// `operand` is payload index to `UnNode`.
1922 fence,
1923 /// Implement builtin `@setFloatMode`.
1924 /// `operand` is payload index to `UnNode`.
1925 set_float_mode,
1926 /// Implement builtin `@setAlignStack`.
1927 /// `operand` is payload index to `UnNode`.
1928 set_align_stack,
1929 /// Implements the `@errSetCast` builtin.
1930 /// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand.
1931 err_set_cast,
1932 /// `operand` is payload index to `UnNode`.
1933 await_nosuspend,
1934 /// `operand` is `src_node: i32`.
1935 breakpoint,
19341936
19351937 pub const InstData = struct {
19361938 opcode: Extended,
src/print_zir.zig+21-14
......@@ -200,9 +200,7 @@ const Writer = struct {
200200 .embed_file,
201201 .error_name,
202202 .panic,
203 .set_align_stack,
204203 .set_cold,
205 .set_float_mode,
206204 .set_runtime_safety,
207205 .sqrt,
208206 .sin,
......@@ -231,8 +229,6 @@ const Writer = struct {
231229 .elem_type,
232230 .@"resume",
233231 .@"await",
234 .await_nosuspend,
235 .fence,
236232 .switch_cond,
237233 .switch_cond_ref,
238234 .array_base_ptr,
......@@ -343,7 +339,6 @@ const Writer = struct {
343339 .int_to_enum,
344340 .float_cast,
345341 .int_cast,
346 .err_set_cast,
347342 .ptr_cast,
348343 .truncate,
349344 .align_cast,
......@@ -405,13 +400,14 @@ const Writer = struct {
405400
406401 .as_node => try self.writeAs(stream, inst),
407402
408 .breakpoint,
409403 .repeat,
410404 .repeat_inline,
411405 .alloc_inferred,
412406 .alloc_inferred_mut,
413407 .alloc_inferred_comptime,
414408 .alloc_inferred_comptime_mut,
409 .ret_ptr,
410 .ret_type,
415411 => try self.writeNode(stream, inst),
416412
417413 .error_value,
......@@ -444,6 +440,10 @@ const Writer = struct {
444440
445441 .dbg_stmt => try self.writeDbgStmt(stream, inst),
446442
443 .dbg_block_begin,
444 .dbg_block_end,
445 => try stream.writeAll("))"),
446
447447 .closure_get => try self.writeInstNode(stream, inst),
448448
449449 .extended => try self.writeExtended(stream, inst),
......@@ -454,13 +454,12 @@ const Writer = struct {
454454 const extended = self.code.instructions.items(.data)[inst].extended;
455455 try stream.print("{s}(", .{@tagName(extended.opcode)});
456456 switch (extended.opcode) {
457 .ret_ptr,
458 .ret_type,
459457 .this,
460458 .ret_addr,
461459 .error_return_trace,
462460 .frame,
463461 .frame_address,
462 .breakpoint,
464463 => try self.writeExtNode(stream, extended),
465464
466465 .builtin_src => {
......@@ -469,10 +468,6 @@ const Writer = struct {
469468 try stream.print(":{d}:{d}", .{ inst_data.line + 1, inst_data.column + 1 });
470469 },
471470
472 .dbg_block_begin,
473 .dbg_block_end,
474 => try stream.writeAll("))"),
475
476471 .@"asm" => try self.writeAsm(stream, extended),
477472 .func => try self.writeFuncExtended(stream, extended),
478473 .variable => try self.writeVarExtended(stream, extended),
......@@ -492,7 +487,14 @@ const Writer = struct {
492487 .enum_decl => try self.writeEnumDecl(stream, extended),
493488 .opaque_decl => try self.writeOpaqueDecl(stream, extended),
494489
495 .c_undef, .c_include, .wasm_memory_size => {
490 .await_nosuspend,
491 .c_undef,
492 .c_include,
493 .fence,
494 .set_float_mode,
495 .set_align_stack,
496 .wasm_memory_size,
497 => {
496498 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
497499 const src: LazySrcLoc = .{ .node_offset = inst_data.node };
498500 try self.writeInstRef(stream, inst_data.operand);
......@@ -500,7 +502,12 @@ const Writer = struct {
500502 try self.writeSrc(stream, src);
501503 },
502504
503 .builtin_extern, .c_define, .wasm_memory_grow, .prefetch => {
505 .builtin_extern,
506 .c_define,
507 .err_set_cast,
508 .wasm_memory_grow,
509 .prefetch,
510 => {
504511 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
505512 const src: LazySrcLoc = .{ .node_offset = inst_data.node };
506513 try self.writeInstRef(stream, inst_data.lhs);