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(...@@ -1078,8 +1078,14 @@ fn awaitExpr(
1078 });1078 });
1079 }1079 }
1080 const operand = try expr(gz, scope, .none, rhs_node);1080 const operand = try expr(gz, scope, .none, rhs_node);
1081 const tag: Zir.Inst.Tag = if (gz.nosuspend_node != 0) .await_nosuspend else .@"await";1081 const result = if (gz.nosuspend_node != 0)
1082 const result = try gz.addUnNode(tag, operand, node);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
1083 return rvalue(gz, rl, result, node);1089 return rvalue(gz, rl, result, node);
1084}1090}
10851091
...@@ -2349,7 +2355,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner...@@ -2349,7 +2355,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2349 .int_to_ptr,2355 .int_to_ptr,
2350 .float_cast,2356 .float_cast,
2351 .int_cast,2357 .int_cast,
2352 .err_set_cast,
2353 .ptr_cast,2358 .ptr_cast,
2354 .truncate,2359 .truncate,
2355 .align_cast,2360 .align_cast,
...@@ -2386,15 +2391,24 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner...@@ -2386,15 +2391,24 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2386 .c_import,2391 .c_import,
2387 .@"resume",2392 .@"resume",
2388 .@"await",2393 .@"await",
2389 .await_nosuspend,
2390 .ret_err_value_code,2394 .ret_err_value_code,
2391 .extended,
2392 .closure_get,2395 .closure_get,
2393 .array_base_ptr,2396 .array_base_ptr,
2394 .field_base_ptr,2397 .field_base_ptr,
2395 .param_type,2398 .param_type,
2399 .ret_ptr,
2400 .ret_type,
2396 => break :b false,2401 => 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
2398 // ZIR instructions that are always `noreturn`.2412 // ZIR instructions that are always `noreturn`.
2399 .@"break",2413 .@"break",
2400 .break_inline,2414 .break_inline,
...@@ -2415,11 +2429,11 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner...@@ -2415,11 +2429,11 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2415 },2429 },
24162430
2417 // ZIR instructions that are always `void`.2431 // ZIR instructions that are always `void`.
2418 .breakpoint,
2419 .fence,
2420 .dbg_stmt,2432 .dbg_stmt,
2421 .dbg_var_ptr,2433 .dbg_var_ptr,
2422 .dbg_var_val,2434 .dbg_var_val,
2435 .dbg_block_begin,
2436 .dbg_block_end,
2423 .ensure_result_used,2437 .ensure_result_used,
2424 .ensure_result_non_error,2438 .ensure_result_non_error,
2425 .@"export",2439 .@"export",
...@@ -2436,9 +2450,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner...@@ -2436,9 +2450,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2436 .validate_struct_init_comptime,2450 .validate_struct_init_comptime,
2437 .validate_array_init,2451 .validate_array_init,
2438 .validate_array_init_comptime,2452 .validate_array_init_comptime,
2439 .set_align_stack,
2440 .set_cold,2453 .set_cold,
2441 .set_float_mode,
2442 .set_runtime_safety,2454 .set_runtime_safety,
2443 .closure_capture,2455 .closure_capture,
2444 .memcpy,2456 .memcpy,
...@@ -6310,9 +6322,9 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref...@@ -6310,9 +6322,9 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
6310 }6322 }
63116323
6312 const rl: ResultLoc = if (nodeMayNeedMemoryLocation(tree, operand_node, true)) .{6324 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),
6314 } else .{6326 } else .{
6315 .ty = try gz.addNodeExtended(.ret_type, node),6327 .ty = try gz.addNode(.ret_type, node),
6316 };6328 };
6317 const prev_anon_name_strategy = gz.anon_name_strategy;6329 const prev_anon_name_strategy = gz.anon_name_strategy;
6318 gz.anon_name_strategy = .func;6330 gz.anon_name_strategy = .func;
...@@ -7183,7 +7195,26 @@ fn builtinCall(...@@ -7183,7 +7195,26 @@ fn builtinCall(
7183 },7195 },
7184 .fence => {7196 .fence => {
7185 const order = try expr(gz, scope, .{ .coerced_ty = .atomic_order_type }, params[0]);7197 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 });
7187 return rvalue(gz, rl, result, node);7218 return rvalue(gz, rl, result, node);
7188 },7219 },
71897220
...@@ -7198,14 +7229,13 @@ fn builtinCall(...@@ -7198,14 +7229,13 @@ fn builtinCall(
7198 return rvalue(gz, rl, result, node);7229 return rvalue(gz, rl, result, node);
7199 },7230 },
72007231
7201 .breakpoint => return simpleNoOpVoid(gz, rl, node, .breakpoint),
7202
7203 // zig fmt: off7232 // zig fmt: off
7204 .This => return rvalue(gz, rl, try gz.addNodeExtended(.this, node), node),7233 .This => return rvalue(gz, rl, try gz.addNodeExtended(.this, node), node),
7205 .return_address => return rvalue(gz, rl, try gz.addNodeExtended(.ret_addr, node), node),7234 .return_address => return rvalue(gz, rl, try gz.addNodeExtended(.ret_addr, node), node),
7206 .error_return_trace => return rvalue(gz, rl, try gz.addNodeExtended(.error_return_trace, node), node),7235 .error_return_trace => return rvalue(gz, rl, try gz.addNodeExtended(.error_return_trace, node), node),
7207 .frame => return rvalue(gz, rl, try gz.addNodeExtended(.frame, node), node),7236 .frame => return rvalue(gz, rl, try gz.addNodeExtended(.frame, node), node),
7208 .frame_address => return rvalue(gz, rl, try gz.addNodeExtended(.frame_address, node), node),7237 .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
7210 .type_info => return simpleUnOpType(gz, scope, rl, node, params[0], .type_info),7240 .type_info => return simpleUnOpType(gz, scope, rl, node, params[0], .type_info),
7211 .size_of => return simpleUnOpType(gz, scope, rl, node, params[0], .size_of),7241 .size_of => return simpleUnOpType(gz, scope, rl, node, params[0], .size_of),
...@@ -7222,9 +7252,7 @@ fn builtinCall(...@@ -7222,9 +7252,7 @@ fn builtinCall(
7222 .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file),7252 .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file),
7223 .error_name => return simpleUnOp(gz, scope, rl, node, .{ .ty = .anyerror_type }, params[0], .error_name),7253 .error_name => return simpleUnOp(gz, scope, rl, node, .{ .ty = .anyerror_type }, params[0], .error_name),
7224 .panic => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .panic),7254 .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),
7226 .set_cold => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_cold),7255 .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),
7228 .set_runtime_safety => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_runtime_safety),7256 .set_runtime_safety => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_runtime_safety),
7229 .sqrt => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sqrt),7257 .sqrt => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sqrt),
7230 .sin => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sin),7258 .sin => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sin),
...@@ -7252,7 +7280,6 @@ fn builtinCall(...@@ -7252,7 +7280,6 @@ fn builtinCall(
7252 .int_to_enum => return typeCast(gz, scope, rl, node, params[0], params[1], .int_to_enum),7280 .int_to_enum => return typeCast(gz, scope, rl, node, params[0], params[1], .int_to_enum),
7253 .float_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .float_cast),7281 .float_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .float_cast),
7254 .int_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .int_cast),7282 .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),
7256 .ptr_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .ptr_cast),7283 .ptr_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .ptr_cast),
7257 .truncate => return typeCast(gz, scope, rl, node, params[0], params[1], .truncate),7284 .truncate => return typeCast(gz, scope, rl, node, params[0], params[1], .truncate),
7258 // zig fmt: on7285 // zig fmt: on
...@@ -7266,6 +7293,14 @@ fn builtinCall(...@@ -7266,6 +7293,14 @@ fn builtinCall(
7266 });7293 });
7267 return rvalue(gz, rl, result, node);7294 return rvalue(gz, rl, result, node);
7268 },7295 },
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
7270 // zig fmt: off7305 // zig fmt: off
7271 .has_decl => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_decl),7306 .has_decl => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_decl),
...@@ -8940,7 +8975,8 @@ fn rvalue(...@@ -8940,7 +8975,8 @@ fn rvalue(
8940 const result = r: {8975 const result = r: {
8941 if (refToIndex(raw_result)) |result_index| {8976 if (refToIndex(raw_result)) |result_index| {
8942 const zir_tags = gz.astgen.instructions.items(.tag);8977 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)) {
8944 break :r Zir.Inst.Ref.void_value;8980 break :r Zir.Inst.Ref.void_value;
8945 }8981 }
8946 }8982 }
...@@ -10893,9 +10929,7 @@ const GenZir = struct {...@@ -10893,9 +10929,7 @@ const GenZir = struct {
10893 fn addDbgBlockBegin(gz: *GenZir) !void {10929 fn addDbgBlockBegin(gz: *GenZir) !void {
10894 if (gz.force_comptime) return;10930 if (gz.force_comptime) return;
1089510931
10896 _ = try gz.add(.{ .tag = .extended, .data = .{10932 _ = try gz.add(.{ .tag = .dbg_block_begin, .data = undefined });
10897 .extended = .{ .opcode = .dbg_block_begin, .small = undefined, .operand = undefined },
10898 } });
10899 }10933 }
1090010934
10901 fn addDbgBlockEnd(gz: *GenZir) !void {10935 fn addDbgBlockEnd(gz: *GenZir) !void {
...@@ -10903,18 +10937,15 @@ const GenZir = struct {...@@ -10903,18 +10937,15 @@ const GenZir = struct {
10903 const gpa = gz.astgen.gpa;10937 const gpa = gz.astgen.gpa;
1090410938
10905 const tags = gz.astgen.instructions.items(.tag);10939 const tags = gz.astgen.instructions.items(.tag);
10906 const data = gz.astgen.instructions.items(.data);
10907 const last_inst = gz.instructions.items[gz.instructions.items.len - 1];10940 const last_inst = gz.instructions.items[gz.instructions.items.len - 1];
10908 // remove dbg_block_begin immediately followed by dbg_block_end10941 // 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) {
10910 _ = gz.instructions.pop();10943 _ = gz.instructions.pop();
10911 return;10944 return;
10912 }10945 }
1091310946
10914 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);10947 const new_index = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
10915 try gz.astgen.instructions.append(gpa, .{ .tag = .extended, .data = .{10948 try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined });
10916 .extended = .{ .opcode = .dbg_block_end, .small = undefined, .operand = undefined },
10917 } });
10918 try gz.instructions.insert(gpa, gz.instructions.items.len - 1, new_index);10949 try gz.instructions.insert(gpa, gz.instructions.items.len - 1, new_index);
10919 }10950 }
1092010951
src/Sema.zig+70-69
...@@ -819,7 +819,6 @@ fn analyzeBodyInner(...@@ -819,7 +819,6 @@ fn analyzeBodyInner(
819 .int_to_ptr => try sema.zirIntToPtr(block, inst),819 .int_to_ptr => try sema.zirIntToPtr(block, inst),
820 .float_cast => try sema.zirFloatCast(block, inst),820 .float_cast => try sema.zirFloatCast(block, inst),
821 .int_cast => try sema.zirIntCast(block, inst),821 .int_cast => try sema.zirIntCast(block, inst),
822 .err_set_cast => try sema.zirErrSetCast(block, inst),
823 .ptr_cast => try sema.zirPtrCast(block, inst),822 .ptr_cast => try sema.zirPtrCast(block, inst),
824 .truncate => try sema.zirTruncate(block, inst),823 .truncate => try sema.zirTruncate(block, inst),
825 .align_cast => try sema.zirAlignCast(block, inst),824 .align_cast => try sema.zirAlignCast(block, inst),
...@@ -842,8 +841,7 @@ fn analyzeBodyInner(...@@ -842,8 +841,7 @@ fn analyzeBodyInner(
842 .field_parent_ptr => try sema.zirFieldParentPtr(block, inst),841 .field_parent_ptr => try sema.zirFieldParentPtr(block, inst),
843 .builtin_async_call => try sema.zirBuiltinAsyncCall(block, inst),842 .builtin_async_call => try sema.zirBuiltinAsyncCall(block, inst),
844 .@"resume" => try sema.zirResume(block, inst),843 .@"resume" => try sema.zirResume(block, inst),
845 .@"await" => try sema.zirAwait(block, inst, false),844 .@"await" => try sema.zirAwait(block, inst),
846 .await_nosuspend => try sema.zirAwait(block, inst, true),
847 .array_base_ptr => try sema.zirArrayBasePtr(block, inst),845 .array_base_ptr => try sema.zirArrayBasePtr(block, inst),
848 .field_base_ptr => try sema.zirFieldBasePtr(block, inst),846 .field_base_ptr => try sema.zirFieldBasePtr(block, inst),
849847
...@@ -894,6 +892,9 @@ fn analyzeBodyInner(...@@ -894,6 +892,9 @@ fn analyzeBodyInner(
894 .shl_exact => try sema.zirShl(block, inst, .shl_exact),892 .shl_exact => try sema.zirShl(block, inst, .shl_exact),
895 .shl_sat => try sema.zirShl(block, inst, .shl_sat),893 .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
897 // Instructions that we know to *always* be noreturn based solely on their tag.898 // Instructions that we know to *always* be noreturn based solely on their tag.
898 // These functions match the return type of analyzeBody so that we can899 // These functions match the return type of analyzeBody so that we can
899 // tail call them here.900 // tail call them here.
...@@ -916,8 +917,6 @@ fn analyzeBodyInner(...@@ -916,8 +917,6 @@ fn analyzeBodyInner(
916 .enum_decl => try sema.zirEnumDecl( block, extended),917 .enum_decl => try sema.zirEnumDecl( block, extended),
917 .union_decl => try sema.zirUnionDecl( block, extended, inst),918 .union_decl => try sema.zirUnionDecl( block, extended, inst),
918 .opaque_decl => try sema.zirOpaqueDecl( block, extended),919 .opaque_decl => try sema.zirOpaqueDecl( block, extended),
919 .ret_ptr => try sema.zirRetPtr( block, extended),
920 .ret_type => try sema.zirRetType( block, extended),
921 .this => try sema.zirThis( block, extended),920 .this => try sema.zirThis( block, extended),
922 .ret_addr => try sema.zirRetAddr( block, extended),921 .ret_addr => try sema.zirRetAddr( block, extended),
923 .builtin_src => try sema.zirBuiltinSrc( block, extended),922 .builtin_src => try sema.zirBuiltinSrc( block, extended),
...@@ -940,16 +939,28 @@ fn analyzeBodyInner(...@@ -940,16 +939,28 @@ fn analyzeBodyInner(
940 .wasm_memory_grow => try sema.zirWasmMemoryGrow( block, extended),939 .wasm_memory_grow => try sema.zirWasmMemoryGrow( block, extended),
941 .prefetch => try sema.zirPrefetch( block, extended),940 .prefetch => try sema.zirPrefetch( block, extended),
942 .field_call_bind_named => try sema.zirFieldCallBindNamed(block, extended),941 .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),
943 // zig fmt: on944 // zig fmt: on
944 .dbg_block_begin => {945 .fence => {
945 dbg_block_begins += 1;946 try sema.zirFence(block, extended);
946 try sema.zirDbgBlockBegin(block);
947 i += 1;947 i += 1;
948 continue;948 continue;
949 },949 },
950 .dbg_block_end => {950 .set_float_mode => {
951 dbg_block_begins -= 1;951 try sema.zirSetFloatMode(block, extended);
952 try sema.zirDbgBlockEnd(block);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 }
953 i += 1;964 i += 1;
954 continue;965 continue;
955 },966 },
...@@ -961,18 +972,6 @@ fn analyzeBodyInner(...@@ -961,18 +972,6 @@ fn analyzeBodyInner(
961 // continue the loop.972 // continue the loop.
962 // We also know that they cannot be referenced later, so we avoid973 // We also know that they cannot be referenced later, so we avoid
963 // putting them into the map.974 // 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 },
976 .dbg_stmt => {975 .dbg_stmt => {
977 try sema.zirDbgStmt(block, inst);976 try sema.zirDbgStmt(block, inst);
978 i += 1;977 i += 1;
...@@ -988,6 +987,18 @@ fn analyzeBodyInner(...@@ -988,6 +987,18 @@ fn analyzeBodyInner(
988 i += 1;987 i += 1;
989 continue;988 continue;
990 },989 },
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 },
991 .ensure_err_payload_void => {1002 .ensure_err_payload_void => {
992 try sema.zirEnsureErrPayloadVoid(block, inst);1003 try sema.zirEnsureErrPayloadVoid(block, inst);
993 i += 1;1004 i += 1;
...@@ -1078,21 +1089,11 @@ fn analyzeBodyInner(...@@ -1078,21 +1089,11 @@ fn analyzeBodyInner(
1078 i += 1;1089 i += 1;
1079 continue;1090 continue;
1080 },1091 },
1081 .set_align_stack => {
1082 try sema.zirSetAlignStack(block, inst);
1083 i += 1;
1084 continue;
1085 },
1086 .set_cold => {1092 .set_cold => {
1087 try sema.zirSetCold(block, inst);1093 try sema.zirSetCold(block, inst);
1088 i += 1;1094 i += 1;
1089 continue;1095 continue;
1090 },1096 },
1091 .set_float_mode => {
1092 try sema.zirSetFloatMode(block, inst);
1093 i += 1;
1094 continue;
1095 },
1096 .set_runtime_safety => {1097 .set_runtime_safety => {
1097 try sema.zirSetRuntimeSafety(block, inst);1098 try sema.zirSetRuntimeSafety(block, inst);
1098 i += 1;1099 i += 1;
...@@ -2452,15 +2453,12 @@ fn zirErrorSetDecl(...@@ -2452,15 +2453,12 @@ fn zirErrorSetDecl(
2452 return sema.analyzeDeclVal(block, src, new_decl_index);2453 return sema.analyzeDeclVal(block, src, new_decl_index);
2453}2454}
24542455
2455fn zirRetPtr(2456fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2456 sema: *Sema,
2457 block: *Block,
2458 extended: Zir.Inst.Extended.InstData,
2459) CompileError!Air.Inst.Ref {
2460 const tracy = trace(@src());2457 const tracy = trace(@src());
2461 defer tracy.end();2458 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 };
2464 try sema.requireFunctionBlock(block, src);2462 try sema.requireFunctionBlock(block, src);
24652463
2466 if (block.is_comptime) {2464 if (block.is_comptime) {
...@@ -2493,15 +2491,12 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -2493,15 +2491,12 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
2493 return sema.analyzeRef(block, inst_data.src(), operand);2491 return sema.analyzeRef(block, inst_data.src(), operand);
2494}2492}
24952493
2496fn zirRetType(2494fn zirRetType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2497 sema: *Sema,
2498 block: *Block,
2499 extended: Zir.Inst.Extended.InstData,
2500) CompileError!Air.Inst.Ref {
2501 const tracy = trace(@src());2495 const tracy = trace(@src());
2502 defer tracy.end();2496 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 };
2505 try sema.requireFunctionBlock(block, src);2500 try sema.requireFunctionBlock(block, src);
2506 return sema.addType(sema.fn_ret_ty);2501 return sema.addType(sema.fn_ret_ty);
2507}2502}
...@@ -3746,9 +3741,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v...@@ -3746,9 +3741,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
3746 sema.fn_ret_ty.zigTypeTag() == .ErrorUnion)3741 sema.fn_ret_ty.zigTypeTag() == .ErrorUnion)
3747 {3742 {
3748 if (Zir.refToIndex(extra.lhs)) |ptr_index| {3743 if (Zir.refToIndex(extra.lhs)) |ptr_index| {
3749 if (zir_tags[ptr_index] == .extended and3744 if (zir_tags[ptr_index] == .ret_ptr) {
3750 zir_datas[ptr_index].extended.opcode == .ret_ptr)
3751 {
3752 try sema.addToInferredErrorSet(operand);3745 try sema.addToInferredErrorSet(operand);
3753 }3746 }
3754 }3747 }
...@@ -4392,11 +4385,11 @@ pub fn analyzeExport(...@@ -4392,11 +4385,11 @@ pub fn analyzeExport(
4392 errdefer de_gop.value_ptr.* = gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1);4385 errdefer de_gop.value_ptr.* = gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1);
4393}4386}
43944387
4395fn zirSetAlignStack(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {4388fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
4396 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4389 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
4397 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };4390 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
4398 const src: LazySrcLoc = inst_data.src();4391 const src: LazySrcLoc = .{ .node_offset = extra.node };
4399 const alignment = try sema.resolveAlign(block, operand_src, inst_data.operand);4392 const alignment = try sema.resolveAlign(block, operand_src, extra.operand);
4400 if (alignment > 256) {4393 if (alignment > 256) {
4401 return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{4394 return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{
4402 alignment,4395 alignment,
...@@ -4433,10 +4426,10 @@ fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi...@@ -4433,10 +4426,10 @@ fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
4433 func.is_cold = is_cold;4426 func.is_cold = is_cold;
4434}4427}
44354428
4436fn zirSetFloatMode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {4429fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
4437 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4430 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
4438 const src: LazySrcLoc = inst_data.src();4431 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
4439 const float_mode = try sema.resolveBuiltinEnum(block, src, inst_data.operand, "FloatMode");4432 const float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode");
4440 switch (float_mode) {4433 switch (float_mode) {
4441 .Strict => return,4434 .Strict => return,
4442 .Optimized => {4435 .Optimized => {
...@@ -4451,12 +4444,12 @@ fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile...@@ -4451,12 +4444,12 @@ fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
4451 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand);4444 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand);
4452}4445}
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 {
4455 if (block.is_comptime) return;4448 if (block.is_comptime) return;
44564449
4457 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4450 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
4458 const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };4451 const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
4459 const order = try sema.resolveAtomicOrder(block, order_src, inst_data.operand);4452 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand);
44604453
4461 if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) {4454 if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) {
4462 return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{});4455 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...@@ -14144,12 +14137,11 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14144 return block.addBitCast(type_res, operand_coerced);14137 return block.addBitCast(type_res, operand_coerced);
14145}14138}
1414614139
14147fn zirErrSetCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {14140fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
14148 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;14141 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
14149 const src = inst_data.src();14142 const src: LazySrcLoc = .{ .node_offset = extra.node };
14150 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };14143 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
14151 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };14144 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
14152 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14153 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);14145 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
14154 const operand = sema.resolveInst(extra.rhs);14146 const operand = sema.resolveInst(extra.rhs);
14155 const operand_ty = sema.typeOf(operand);14147 const operand_ty = sema.typeOf(operand);
...@@ -16007,15 +15999,24 @@ fn zirAwait(...@@ -16007,15 +15999,24 @@ fn zirAwait(
16007 sema: *Sema,15999 sema: *Sema,
16008 block: *Block,16000 block: *Block,
16009 inst: Zir.Inst.Index,16001 inst: Zir.Inst.Index,
16010 is_nosuspend: bool,
16011) CompileError!Air.Inst.Ref {16002) CompileError!Air.Inst.Ref {
16012 const inst_data = sema.code.instructions.items(.data)[inst].un_node;16003 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
16013 const src = inst_data.src();16004 const src = inst_data.src();
1601416005
16015 _ = is_nosuspend;
16016 return sema.fail(block, src, "TODO: Sema.zirAwait", .{});16006 return sema.fail(block, src, "TODO: Sema.zirAwait", .{});
16017}16007}
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
16019fn zirVarExtended(16020fn zirVarExtended(
16020 sema: *Sema,16021 sema: *Sema,
16021 block: *Block,16022 block: *Block,
src/Zir.zig+44-42
...@@ -278,8 +278,6 @@ pub const Inst = struct {...@@ -278,8 +278,6 @@ pub const Inst = struct {
278 /// break instruction in a block, and the target block is the parent.278 /// break instruction in a block, and the target block is the parent.
279 /// Uses the `break` union field.279 /// Uses the `break` union field.
280 break_inline,280 break_inline,
281 /// Uses the `node` union field.
282 breakpoint,
283 /// Function call.281 /// Function call.
284 /// Uses `pl_node`. AST node is the function call. Payload is `Call`.282 /// Uses `pl_node`. AST node is the function call. Payload is `Call`.
285 call,283 call,
...@@ -331,6 +329,10 @@ pub const Inst = struct {...@@ -331,6 +329,10 @@ pub const Inst = struct {
331 /// Same as `dbg_var_ptr` but the local is always a const and the operand329 /// Same as `dbg_var_ptr` but the local is always a const and the operand
332 /// is the local's value.330 /// is the local's value.
333 dbg_var_val,331 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,
334 /// Uses a name to identify a Decl and takes a pointer to it.336 /// Uses a name to identify a Decl and takes a pointer to it.
335 /// Uses the `str_tok` union field.337 /// Uses the `str_tok` union field.
336 decl_ref,338 decl_ref,
...@@ -499,6 +501,12 @@ pub const Inst = struct {...@@ -499,6 +501,12 @@ pub const Inst = struct {
499 /// this instruction; a following 'ret' instruction will do the diversion.501 /// this instruction; a following 'ret' instruction will do the diversion.
500 /// Uses the `str_tok` union field.502 /// Uses the `str_tok` union field.
501 ret_err_value_code,503 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,
502 /// Create a pointer type that does not have a sentinel, alignment, address space, or bit range specified.510 /// Create a pointer type that does not have a sentinel, alignment, address space, or bit range specified.
503 /// Uses the `ptr_type_simple` union field.511 /// Uses the `ptr_type_simple` union field.
504 ptr_type_simple,512 ptr_type_simple,
...@@ -744,8 +752,6 @@ pub const Inst = struct {...@@ -744,8 +752,6 @@ pub const Inst = struct {
744 size_of,752 size_of,
745 /// Implements the `@bitSizeOf` builtin. Uses `un_node`.753 /// Implements the `@bitSizeOf` builtin. Uses `un_node`.
746 bit_size_of,754 bit_size_of,
747 /// Implements the `@fence` builtin. Uses `un_node`.
748 fence,
749755
750 /// Implement builtin `@ptrToInt`. Uses `un_node`.756 /// Implement builtin `@ptrToInt`. Uses `un_node`.
751 /// Convert a pointer to a `usize` integer.757 /// Convert a pointer to a `usize` integer.
...@@ -774,12 +780,8 @@ pub const Inst = struct {...@@ -774,12 +780,8 @@ pub const Inst = struct {
774 error_name,780 error_name,
775 /// Implement builtin `@panic`. Uses `un_node`.781 /// Implement builtin `@panic`. Uses `un_node`.
776 panic,782 panic,
777 /// Implement builtin `@setAlignStack`. Uses `un_node`.
778 set_align_stack,
779 /// Implement builtin `@setCold`. Uses `un_node`.783 /// Implement builtin `@setCold`. Uses `un_node`.
780 set_cold,784 set_cold,
781 /// Implement builtin `@setFloatMode`. Uses `un_node`.
782 set_float_mode,
783 /// Implement builtin `@setRuntimeSafety`. Uses `un_node`.785 /// Implement builtin `@setRuntimeSafety`. Uses `un_node`.
784 set_runtime_safety,786 set_runtime_safety,
785 /// Implement builtin `@sqrt`. Uses `un_node`.787 /// Implement builtin `@sqrt`. Uses `un_node`.
...@@ -843,9 +845,6 @@ pub const Inst = struct {...@@ -843,9 +845,6 @@ pub const Inst = struct {
843 /// Convert an integer value to another integer type, asserting that the destination type845 /// Convert an integer value to another integer type, asserting that the destination type
844 /// can hold the same mathematical value.846 /// can hold the same mathematical value.
845 int_cast,847 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,
849 /// Implements the `@ptrCast` builtin.848 /// Implements the `@ptrCast` builtin.
850 /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.849 /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand.
851 ptr_cast,850 ptr_cast,
...@@ -972,7 +971,6 @@ pub const Inst = struct {...@@ -972,7 +971,6 @@ pub const Inst = struct {
972 /// Implements `resume` syntax. Uses `un_node` field.971 /// Implements `resume` syntax. Uses `un_node` field.
973 @"resume",972 @"resume",
974 @"await",973 @"await",
975 await_nosuspend,
976974
977 /// When a type or function refers to a comptime value from an outer975 /// When a type or function refers to a comptime value from an outer
978 /// scope, that forms a closure over comptime value. The outer scope976 /// scope, that forms a closure over comptime value. The outer scope
...@@ -1028,8 +1026,6 @@ pub const Inst = struct {...@@ -1028,8 +1026,6 @@ pub const Inst = struct {
1028 .bool_br_and,1026 .bool_br_and,
1029 .bool_br_or,1027 .bool_br_or,
1030 .bool_not,1028 .bool_not,
1031 .breakpoint,
1032 .fence,
1033 .call,1029 .call,
1034 .cmp_lt,1030 .cmp_lt,
1035 .cmp_lte,1031 .cmp_lte,
...@@ -1044,6 +1040,8 @@ pub const Inst = struct {...@@ -1044,6 +1040,8 @@ pub const Inst = struct {
1044 .dbg_stmt,1040 .dbg_stmt,
1045 .dbg_var_ptr,1041 .dbg_var_ptr,
1046 .dbg_var_val,1042 .dbg_var_val,
1043 .dbg_block_begin,
1044 .dbg_block_end,
1047 .decl_ref,1045 .decl_ref,
1048 .decl_val,1046 .decl_val,
1049 .load,1047 .load,
...@@ -1164,9 +1162,7 @@ pub const Inst = struct {...@@ -1164,9 +1162,7 @@ pub const Inst = struct {
1164 .bool_to_int,1162 .bool_to_int,
1165 .embed_file,1163 .embed_file,
1166 .error_name,1164 .error_name,
1167 .set_align_stack,
1168 .set_cold,1165 .set_cold,
1169 .set_float_mode,
1170 .set_runtime_safety,1166 .set_runtime_safety,
1171 .sqrt,1167 .sqrt,
1172 .sin,1168 .sin,
...@@ -1192,7 +1188,6 @@ pub const Inst = struct {...@@ -1192,7 +1188,6 @@ pub const Inst = struct {
1192 .int_to_ptr,1188 .int_to_ptr,
1193 .float_cast,1189 .float_cast,
1194 .int_cast,1190 .int_cast,
1195 .err_set_cast,
1196 .ptr_cast,1191 .ptr_cast,
1197 .truncate,1192 .truncate,
1198 .align_cast,1193 .align_cast,
...@@ -1231,11 +1226,12 @@ pub const Inst = struct {...@@ -1231,11 +1226,12 @@ pub const Inst = struct {
1231 .c_import,1226 .c_import,
1232 .@"resume",1227 .@"resume",
1233 .@"await",1228 .@"await",
1234 .await_nosuspend,
1235 .ret_err_value_code,1229 .ret_err_value_code,
1236 .extended,1230 .extended,
1237 .closure_get,1231 .closure_get,
1238 .closure_capture,1232 .closure_capture,
1233 .ret_ptr,
1234 .ret_type,
1239 => false,1235 => false,
12401236
1241 .@"break",1237 .@"break",
...@@ -1258,13 +1254,13 @@ pub const Inst = struct {...@@ -1258,13 +1254,13 @@ pub const Inst = struct {
1258 /// AstGen uses this to find out if `Ref.void_value` should be used in place1254 /// AstGen uses this to find out if `Ref.void_value` should be used in place
1259 /// of the result of a given instruction. This allows Sema to forego adding1255 /// of the result of a given instruction. This allows Sema to forego adding
1260 /// the instruction to the map after analysis.1256 /// the instruction to the map after analysis.
1261 pub fn isAlwaysVoid(tag: Tag) bool {1257 pub fn isAlwaysVoid(tag: Tag, data: Data) bool {
1262 return switch (tag) {1258 return switch (tag) {
1263 .breakpoint,
1264 .fence,
1265 .dbg_stmt,1259 .dbg_stmt,
1266 .dbg_var_ptr,1260 .dbg_var_ptr,
1267 .dbg_var_val,1261 .dbg_var_val,
1262 .dbg_block_begin,
1263 .dbg_block_end,
1268 .ensure_result_used,1264 .ensure_result_used,
1269 .ensure_result_non_error,1265 .ensure_result_non_error,
1270 .ensure_err_payload_void,1266 .ensure_err_payload_void,
...@@ -1283,9 +1279,7 @@ pub const Inst = struct {...@@ -1283,9 +1279,7 @@ pub const Inst = struct {
1283 .validate_array_init_comptime,1279 .validate_array_init_comptime,
1284 .@"export",1280 .@"export",
1285 .export_value,1281 .export_value,
1286 .set_align_stack,
1287 .set_cold,1282 .set_cold,
1288 .set_float_mode,
1289 .set_runtime_safety,1283 .set_runtime_safety,
1290 .memcpy,1284 .memcpy,
1291 .memset,1285 .memset,
...@@ -1464,7 +1458,6 @@ pub const Inst = struct {...@@ -1464,7 +1458,6 @@ pub const Inst = struct {
1464 .int_to_ptr,1458 .int_to_ptr,
1465 .float_cast,1459 .float_cast,
1466 .int_cast,1460 .int_cast,
1467 .err_set_cast,
1468 .ptr_cast,1461 .ptr_cast,
1469 .truncate,1462 .truncate,
1470 .align_cast,1463 .align_cast,
...@@ -1500,9 +1493,7 @@ pub const Inst = struct {...@@ -1500,9 +1493,7 @@ pub const Inst = struct {
1500 .c_import,1493 .c_import,
1501 .@"resume",1494 .@"resume",
1502 .@"await",1495 .@"await",
1503 .await_nosuspend,
1504 .ret_err_value_code,1496 .ret_err_value_code,
1505 .extended,
1506 .closure_get,1497 .closure_get,
1507 .closure_capture,1498 .closure_capture,
1508 .@"break",1499 .@"break",
...@@ -1514,11 +1505,18 @@ pub const Inst = struct {...@@ -1514,11 +1505,18 @@ pub const Inst = struct {
1514 .ret_load,1505 .ret_load,
1515 .ret_tok,1506 .ret_tok,
1516 .ret_err_value,1507 .ret_err_value,
1508 .ret_ptr,
1509 .ret_type,
1517 .@"unreachable",1510 .@"unreachable",
1518 .repeat,1511 .repeat,
1519 .repeat_inline,1512 .repeat_inline,
1520 .panic,1513 .panic,
1521 => false,1514 => false,
1515
1516 .extended => switch (data.extended.opcode) {
1517 .breakpoint, .fence => true,
1518 else => false,
1519 },
1522 };1520 };
1523 }1521 }
15241522
...@@ -1563,7 +1561,6 @@ pub const Inst = struct {...@@ -1563,7 +1561,6 @@ pub const Inst = struct {
1563 .bool_br_or = .bool_br,1561 .bool_br_or = .bool_br,
1564 .@"break" = .@"break",1562 .@"break" = .@"break",
1565 .break_inline = .@"break",1563 .break_inline = .@"break",
1566 .breakpoint = .node,
1567 .call = .pl_node,1564 .call = .pl_node,
1568 .cmp_lt = .pl_node,1565 .cmp_lt = .pl_node,
1569 .cmp_lte = .pl_node,1566 .cmp_lte = .pl_node,
...@@ -1580,6 +1577,8 @@ pub const Inst = struct {...@@ -1580,6 +1577,8 @@ pub const Inst = struct {
1580 .dbg_stmt = .dbg_stmt,1577 .dbg_stmt = .dbg_stmt,
1581 .dbg_var_ptr = .str_op,1578 .dbg_var_ptr = .str_op,
1582 .dbg_var_val = .str_op,1579 .dbg_var_val = .str_op,
1580 .dbg_block_begin = .tok,
1581 .dbg_block_end = .tok,
1583 .decl_ref = .str_tok,1582 .decl_ref = .str_tok,
1584 .decl_val = .str_tok,1583 .decl_val = .str_tok,
1585 .load = .un_node,1584 .load = .un_node,
...@@ -1623,6 +1622,8 @@ pub const Inst = struct {...@@ -1623,6 +1622,8 @@ pub const Inst = struct {
1623 .ret_tok = .un_tok,1622 .ret_tok = .un_tok,
1624 .ret_err_value = .str_tok,1623 .ret_err_value = .str_tok,
1625 .ret_err_value_code = .str_tok,1624 .ret_err_value_code = .str_tok,
1625 .ret_ptr = .node,
1626 .ret_type = .node,
1626 .ptr_type_simple = .ptr_type_simple,1627 .ptr_type_simple = .ptr_type_simple,
1627 .ptr_type = .ptr_type,1628 .ptr_type = .ptr_type,
1628 .slice_start = .pl_node,1629 .slice_start = .pl_node,
...@@ -1685,7 +1686,6 @@ pub const Inst = struct {...@@ -1685,7 +1686,6 @@ pub const Inst = struct {
1685 .type_info = .un_node,1686 .type_info = .un_node,
1686 .size_of = .un_node,1687 .size_of = .un_node,
1687 .bit_size_of = .un_node,1688 .bit_size_of = .un_node,
1688 .fence = .un_node,
16891689
1690 .ptr_to_int = .un_node,1690 .ptr_to_int = .un_node,
1691 .error_to_int = .un_node,1691 .error_to_int = .un_node,
...@@ -1698,9 +1698,7 @@ pub const Inst = struct {...@@ -1698,9 +1698,7 @@ pub const Inst = struct {
1698 .embed_file = .un_node,1698 .embed_file = .un_node,
1699 .error_name = .un_node,1699 .error_name = .un_node,
1700 .panic = .un_node,1700 .panic = .un_node,
1701 .set_align_stack = .un_node,
1702 .set_cold = .un_node,1701 .set_cold = .un_node,
1703 .set_float_mode = .un_node,
1704 .set_runtime_safety = .un_node,1702 .set_runtime_safety = .un_node,
1705 .sqrt = .un_node,1703 .sqrt = .un_node,
1706 .sin = .un_node,1704 .sin = .un_node,
...@@ -1728,7 +1726,6 @@ pub const Inst = struct {...@@ -1728,7 +1726,6 @@ pub const Inst = struct {
1728 .int_to_enum = .pl_node,1726 .int_to_enum = .pl_node,
1729 .float_cast = .pl_node,1727 .float_cast = .pl_node,
1730 .int_cast = .pl_node,1728 .int_cast = .pl_node,
1731 .err_set_cast = .pl_node,
1732 .ptr_cast = .pl_node,1729 .ptr_cast = .pl_node,
1733 .truncate = .pl_node,1730 .truncate = .pl_node,
1734 .align_cast = .pl_node,1731 .align_cast = .pl_node,
...@@ -1788,7 +1785,6 @@ pub const Inst = struct {...@@ -1788,7 +1785,6 @@ pub const Inst = struct {
17881785
1789 .@"resume" = .un_node,1786 .@"resume" = .un_node,
1790 .@"await" = .un_node,1787 .@"await" = .un_node,
1791 .await_nosuspend = .un_node,
17921788
1793 .closure_capture = .un_tok,1789 .closure_capture = .un_tok,
1794 .closure_get = .inst_node,1790 .closure_get = .inst_node,
...@@ -1834,12 +1830,6 @@ pub const Inst = struct {...@@ -1834,12 +1830,6 @@ pub const Inst = struct {
1834 /// `operand` is payload index to `OpaqueDecl`.1830 /// `operand` is payload index to `OpaqueDecl`.
1835 /// `small` is `OpaqueDecl.Small`.1831 /// `small` is `OpaqueDecl.Small`.
1836 opaque_decl,1832 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,
1843 /// Implements the `@This` builtin.1833 /// Implements the `@This` builtin.
1844 /// `operand` is `src_node: i32`.1834 /// `operand` is `src_node: i32`.
1845 this,1835 this,
...@@ -1917,10 +1907,6 @@ pub const Inst = struct {...@@ -1917,10 +1907,6 @@ pub const Inst = struct {
1917 /// The `@prefetch` builtin.1907 /// The `@prefetch` builtin.
1918 /// `operand` is payload index to `BinNode`.1908 /// `operand` is payload index to `BinNode`.
1919 prefetch,1909 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,
1924 /// Given a pointer to a struct or object that contains virtual fields, returns the1910 /// Given a pointer to a struct or object that contains virtual fields, returns the
1925 /// named field. If there is no named field, searches in the type for a decl that1911 /// named field. If there is no named field, searches in the type for a decl that
1926 /// matches the field name. The decl is resolved and we ensure that it's a function1912 /// matches the field name. The decl is resolved and we ensure that it's a function
...@@ -1931,6 +1917,22 @@ pub const Inst = struct {...@@ -1931,6 +1917,22 @@ pub const Inst = struct {
1931 /// `builtin_call` instruction. Any other use is invalid zir and may crash the compiler.1917 /// `builtin_call` instruction. Any other use is invalid zir and may crash the compiler.
1932 /// Uses `pl_node` field. The AST node is the `@field` builtin. Payload is FieldNamedNode.1918 /// Uses `pl_node` field. The AST node is the `@field` builtin. Payload is FieldNamedNode.
1933 field_call_bind_named,1919 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
1935 pub const InstData = struct {1937 pub const InstData = struct {
1936 opcode: Extended,1938 opcode: Extended,
src/print_zir.zig+21-14
...@@ -200,9 +200,7 @@ const Writer = struct {...@@ -200,9 +200,7 @@ const Writer = struct {
200 .embed_file,200 .embed_file,
201 .error_name,201 .error_name,
202 .panic,202 .panic,
203 .set_align_stack,
204 .set_cold,203 .set_cold,
205 .set_float_mode,
206 .set_runtime_safety,204 .set_runtime_safety,
207 .sqrt,205 .sqrt,
208 .sin,206 .sin,
...@@ -231,8 +229,6 @@ const Writer = struct {...@@ -231,8 +229,6 @@ const Writer = struct {
231 .elem_type,229 .elem_type,
232 .@"resume",230 .@"resume",
233 .@"await",231 .@"await",
234 .await_nosuspend,
235 .fence,
236 .switch_cond,232 .switch_cond,
237 .switch_cond_ref,233 .switch_cond_ref,
238 .array_base_ptr,234 .array_base_ptr,
...@@ -343,7 +339,6 @@ const Writer = struct {...@@ -343,7 +339,6 @@ const Writer = struct {
343 .int_to_enum,339 .int_to_enum,
344 .float_cast,340 .float_cast,
345 .int_cast,341 .int_cast,
346 .err_set_cast,
347 .ptr_cast,342 .ptr_cast,
348 .truncate,343 .truncate,
349 .align_cast,344 .align_cast,
...@@ -405,13 +400,14 @@ const Writer = struct {...@@ -405,13 +400,14 @@ const Writer = struct {
405400
406 .as_node => try self.writeAs(stream, inst),401 .as_node => try self.writeAs(stream, inst),
407402
408 .breakpoint,
409 .repeat,403 .repeat,
410 .repeat_inline,404 .repeat_inline,
411 .alloc_inferred,405 .alloc_inferred,
412 .alloc_inferred_mut,406 .alloc_inferred_mut,
413 .alloc_inferred_comptime,407 .alloc_inferred_comptime,
414 .alloc_inferred_comptime_mut,408 .alloc_inferred_comptime_mut,
409 .ret_ptr,
410 .ret_type,
415 => try self.writeNode(stream, inst),411 => try self.writeNode(stream, inst),
416412
417 .error_value,413 .error_value,
...@@ -444,6 +440,10 @@ const Writer = struct {...@@ -444,6 +440,10 @@ const Writer = struct {
444440
445 .dbg_stmt => try self.writeDbgStmt(stream, inst),441 .dbg_stmt => try self.writeDbgStmt(stream, inst),
446442
443 .dbg_block_begin,
444 .dbg_block_end,
445 => try stream.writeAll("))"),
446
447 .closure_get => try self.writeInstNode(stream, inst),447 .closure_get => try self.writeInstNode(stream, inst),
448448
449 .extended => try self.writeExtended(stream, inst),449 .extended => try self.writeExtended(stream, inst),
...@@ -454,13 +454,12 @@ const Writer = struct {...@@ -454,13 +454,12 @@ const Writer = struct {
454 const extended = self.code.instructions.items(.data)[inst].extended;454 const extended = self.code.instructions.items(.data)[inst].extended;
455 try stream.print("{s}(", .{@tagName(extended.opcode)});455 try stream.print("{s}(", .{@tagName(extended.opcode)});
456 switch (extended.opcode) {456 switch (extended.opcode) {
457 .ret_ptr,
458 .ret_type,
459 .this,457 .this,
460 .ret_addr,458 .ret_addr,
461 .error_return_trace,459 .error_return_trace,
462 .frame,460 .frame,
463 .frame_address,461 .frame_address,
462 .breakpoint,
464 => try self.writeExtNode(stream, extended),463 => try self.writeExtNode(stream, extended),
465464
466 .builtin_src => {465 .builtin_src => {
...@@ -469,10 +468,6 @@ const Writer = struct {...@@ -469,10 +468,6 @@ const Writer = struct {
469 try stream.print(":{d}:{d}", .{ inst_data.line + 1, inst_data.column + 1 });468 try stream.print(":{d}:{d}", .{ inst_data.line + 1, inst_data.column + 1 });
470 },469 },
471470
472 .dbg_block_begin,
473 .dbg_block_end,
474 => try stream.writeAll("))"),
475
476 .@"asm" => try self.writeAsm(stream, extended),471 .@"asm" => try self.writeAsm(stream, extended),
477 .func => try self.writeFuncExtended(stream, extended),472 .func => try self.writeFuncExtended(stream, extended),
478 .variable => try self.writeVarExtended(stream, extended),473 .variable => try self.writeVarExtended(stream, extended),
...@@ -492,7 +487,14 @@ const Writer = struct {...@@ -492,7 +487,14 @@ const Writer = struct {
492 .enum_decl => try self.writeEnumDecl(stream, extended),487 .enum_decl => try self.writeEnumDecl(stream, extended),
493 .opaque_decl => try self.writeOpaqueDecl(stream, extended),488 .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 => {
496 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;498 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
497 const src: LazySrcLoc = .{ .node_offset = inst_data.node };499 const src: LazySrcLoc = .{ .node_offset = inst_data.node };
498 try self.writeInstRef(stream, inst_data.operand);500 try self.writeInstRef(stream, inst_data.operand);
...@@ -500,7 +502,12 @@ const Writer = struct {...@@ -500,7 +502,12 @@ const Writer = struct {
500 try self.writeSrc(stream, src);502 try self.writeSrc(stream, src);
501 },503 },
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 => {
504 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;511 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
505 const src: LazySrcLoc = .{ .node_offset = inst_data.node };512 const src: LazySrcLoc = .{ .node_offset = inst_data.node };
506 try self.writeInstRef(stream, inst_data.lhs);513 try self.writeInstRef(stream, inst_data.lhs);