| author | |
| committer | |
| log | cc39d453c45645296cd771c94d97b8a77469be91 |
| tree | 8d9c857255ac15fe2f8125789f8a42a7a03573eb |
| parent | a0a2ce92ca129d28e22c63f7bace1672c43776b5 |
| parent | 596f7df02e78adf334eed4a1f14eafa31ca611b9 |
| signature |
Stage2: fix comptime unreachable, adjust Zir.Extended8 files changed, 283 insertions(+), 245 deletions(-)
src/AstGen.zig+73-41| ... | ... | @@ -72,6 +72,7 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { |
| 72 | 72 | i32 => @bitCast(u32, @field(extra, field.name)), |
| 73 | 73 | Zir.Inst.Call.Flags => @bitCast(u32, @field(extra, field.name)), |
| 74 | 74 | Zir.Inst.SwitchBlock.Bits => @bitCast(u32, @field(extra, field.name)), |
| 75 | Zir.Inst.ExtendedFunc.Bits => @bitCast(u32, @field(extra, field.name)), | |
| 75 | 76 | else => @compileError("bad field type"), |
| 76 | 77 | }; |
| 77 | 78 | i += 1; |
| ... | ... | @@ -740,7 +741,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr |
| 740 | 741 | _ = try gz.addAsIndex(.{ |
| 741 | 742 | .tag = .@"unreachable", |
| 742 | 743 | .data = .{ .@"unreachable" = .{ |
| 743 | .safety = true, | |
| 744 | .force_comptime = gz.force_comptime, | |
| 744 | 745 | .src_node = gz.nodeIndexToRelative(node), |
| 745 | 746 | } }, |
| 746 | 747 | }); |
| ... | ... | @@ -1078,8 +1079,14 @@ fn awaitExpr( |
| 1078 | 1079 | }); |
| 1079 | 1080 | } |
| 1080 | 1081 | 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); | |
| 1082 | const result = if (gz.nosuspend_node != 0) | |
| 1083 | try gz.addExtendedPayload(.await_nosuspend, Zir.Inst.UnNode{ | |
| 1084 | .node = gz.nodeIndexToRelative(node), | |
| 1085 | .operand = operand, | |
| 1086 | }) | |
| 1087 | else | |
| 1088 | try gz.addUnNode(.@"await", operand, node); | |
| 1089 | ||
| 1083 | 1090 | return rvalue(gz, rl, result, node); |
| 1084 | 1091 | } |
| 1085 | 1092 | |
| ... | ... | @@ -2239,6 +2246,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2239 | 2246 | .field_val_named, |
| 2240 | 2247 | .func, |
| 2241 | 2248 | .func_inferred, |
| 2249 | .func_extended, | |
| 2242 | 2250 | .int, |
| 2243 | 2251 | .int_big, |
| 2244 | 2252 | .float, |
| ... | ... | @@ -2349,7 +2357,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2349 | 2357 | .int_to_ptr, |
| 2350 | 2358 | .float_cast, |
| 2351 | 2359 | .int_cast, |
| 2352 | .err_set_cast, | |
| 2353 | 2360 | .ptr_cast, |
| 2354 | 2361 | .truncate, |
| 2355 | 2362 | .align_cast, |
| ... | ... | @@ -2386,15 +2393,24 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2386 | 2393 | .c_import, |
| 2387 | 2394 | .@"resume", |
| 2388 | 2395 | .@"await", |
| 2389 | .await_nosuspend, | |
| 2390 | 2396 | .ret_err_value_code, |
| 2391 | .extended, | |
| 2392 | 2397 | .closure_get, |
| 2393 | 2398 | .array_base_ptr, |
| 2394 | 2399 | .field_base_ptr, |
| 2395 | 2400 | .param_type, |
| 2401 | .ret_ptr, | |
| 2402 | .ret_type, | |
| 2396 | 2403 | => break :b false, |
| 2397 | 2404 | |
| 2405 | .extended => switch (gz.astgen.instructions.items(.data)[inst].extended.opcode) { | |
| 2406 | .breakpoint, | |
| 2407 | .fence, | |
| 2408 | .set_align_stack, | |
| 2409 | .set_float_mode, | |
| 2410 | => break :b true, | |
| 2411 | else => break :b false, | |
| 2412 | }, | |
| 2413 | ||
| 2398 | 2414 | // ZIR instructions that are always `noreturn`. |
| 2399 | 2415 | .@"break", |
| 2400 | 2416 | .break_inline, |
| ... | ... | @@ -2415,11 +2431,11 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2415 | 2431 | }, |
| 2416 | 2432 | |
| 2417 | 2433 | // ZIR instructions that are always `void`. |
| 2418 | .breakpoint, | |
| 2419 | .fence, | |
| 2420 | 2434 | .dbg_stmt, |
| 2421 | 2435 | .dbg_var_ptr, |
| 2422 | 2436 | .dbg_var_val, |
| 2437 | .dbg_block_begin, | |
| 2438 | .dbg_block_end, | |
| 2423 | 2439 | .ensure_result_used, |
| 2424 | 2440 | .ensure_result_non_error, |
| 2425 | 2441 | .@"export", |
| ... | ... | @@ -2436,9 +2452,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2436 | 2452 | .validate_struct_init_comptime, |
| 2437 | 2453 | .validate_array_init, |
| 2438 | 2454 | .validate_array_init_comptime, |
| 2439 | .set_align_stack, | |
| 2440 | 2455 | .set_cold, |
| 2441 | .set_float_mode, | |
| 2442 | 2456 | .set_runtime_safety, |
| 2443 | 2457 | .closure_capture, |
| 2444 | 2458 | .memcpy, |
| ... | ... | @@ -6310,9 +6324,9 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref |
| 6310 | 6324 | } |
| 6311 | 6325 | |
| 6312 | 6326 | const rl: ResultLoc = if (nodeMayNeedMemoryLocation(tree, operand_node, true)) .{ |
| 6313 | .ptr = try gz.addNodeExtended(.ret_ptr, node), | |
| 6327 | .ptr = try gz.addNode(.ret_ptr, node), | |
| 6314 | 6328 | } else .{ |
| 6315 | .ty = try gz.addNodeExtended(.ret_type, node), | |
| 6329 | .ty = try gz.addNode(.ret_type, node), | |
| 6316 | 6330 | }; |
| 6317 | 6331 | const prev_anon_name_strategy = gz.anon_name_strategy; |
| 6318 | 6332 | gz.anon_name_strategy = .func; |
| ... | ... | @@ -7183,7 +7197,26 @@ fn builtinCall( |
| 7183 | 7197 | }, |
| 7184 | 7198 | .fence => { |
| 7185 | 7199 | const order = try expr(gz, scope, .{ .coerced_ty = .atomic_order_type }, params[0]); |
| 7186 | const result = try gz.addUnNode(.fence, order, node); | |
| 7200 | const result = try gz.addExtendedPayload(.fence, Zir.Inst.UnNode{ | |
| 7201 | .node = gz.nodeIndexToRelative(node), | |
| 7202 | .operand = order, | |
| 7203 | }); | |
| 7204 | return rvalue(gz, rl, result, node); | |
| 7205 | }, | |
| 7206 | .set_float_mode => { | |
| 7207 | const order = try expr(gz, scope, .{ .coerced_ty = .float_mode_type }, params[0]); | |
| 7208 | const result = try gz.addExtendedPayload(.set_float_mode, Zir.Inst.UnNode{ | |
| 7209 | .node = gz.nodeIndexToRelative(node), | |
| 7210 | .operand = order, | |
| 7211 | }); | |
| 7212 | return rvalue(gz, rl, result, node); | |
| 7213 | }, | |
| 7214 | .set_align_stack => { | |
| 7215 | const order = try expr(gz, scope, align_rl, params[0]); | |
| 7216 | const result = try gz.addExtendedPayload(.set_align_stack, Zir.Inst.UnNode{ | |
| 7217 | .node = gz.nodeIndexToRelative(node), | |
| 7218 | .operand = order, | |
| 7219 | }); | |
| 7187 | 7220 | return rvalue(gz, rl, result, node); |
| 7188 | 7221 | }, |
| 7189 | 7222 | |
| ... | ... | @@ -7198,14 +7231,13 @@ fn builtinCall( |
| 7198 | 7231 | return rvalue(gz, rl, result, node); |
| 7199 | 7232 | }, |
| 7200 | 7233 | |
| 7201 | .breakpoint => return simpleNoOpVoid(gz, rl, node, .breakpoint), | |
| 7202 | ||
| 7203 | 7234 | // zig fmt: off |
| 7204 | 7235 | .This => return rvalue(gz, rl, try gz.addNodeExtended(.this, node), node), |
| 7205 | 7236 | .return_address => return rvalue(gz, rl, try gz.addNodeExtended(.ret_addr, node), node), |
| 7206 | 7237 | .error_return_trace => return rvalue(gz, rl, try gz.addNodeExtended(.error_return_trace, node), node), |
| 7207 | 7238 | .frame => return rvalue(gz, rl, try gz.addNodeExtended(.frame, node), node), |
| 7208 | 7239 | .frame_address => return rvalue(gz, rl, try gz.addNodeExtended(.frame_address, node), node), |
| 7240 | .breakpoint => return rvalue(gz, rl, try gz.addNodeExtended(.breakpoint, node), node), | |
| 7209 | 7241 | |
| 7210 | 7242 | .type_info => return simpleUnOpType(gz, scope, rl, node, params[0], .type_info), |
| 7211 | 7243 | .size_of => return simpleUnOpType(gz, scope, rl, node, params[0], .size_of), |
| ... | ... | @@ -7222,9 +7254,7 @@ fn builtinCall( |
| 7222 | 7254 | .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file), |
| 7223 | 7255 | .error_name => return simpleUnOp(gz, scope, rl, node, .{ .ty = .anyerror_type }, params[0], .error_name), |
| 7224 | 7256 | .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 | 7257 | .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 | 7258 | .set_runtime_safety => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_runtime_safety), |
| 7229 | 7259 | .sqrt => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sqrt), |
| 7230 | 7260 | .sin => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sin), |
| ... | ... | @@ -7252,7 +7282,6 @@ fn builtinCall( |
| 7252 | 7282 | .int_to_enum => return typeCast(gz, scope, rl, node, params[0], params[1], .int_to_enum), |
| 7253 | 7283 | .float_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .float_cast), |
| 7254 | 7284 | .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 | 7285 | .ptr_cast => return typeCast(gz, scope, rl, node, params[0], params[1], .ptr_cast), |
| 7257 | 7286 | .truncate => return typeCast(gz, scope, rl, node, params[0], params[1], .truncate), |
| 7258 | 7287 | // zig fmt: on |
| ... | ... | @@ -7266,6 +7295,14 @@ fn builtinCall( |
| 7266 | 7295 | }); |
| 7267 | 7296 | return rvalue(gz, rl, result, node); |
| 7268 | 7297 | }, |
| 7298 | .err_set_cast => { | |
| 7299 | const result = try gz.addExtendedPayload(.err_set_cast, Zir.Inst.BinNode{ | |
| 7300 | .lhs = try typeExpr(gz, scope, params[0]), | |
| 7301 | .rhs = try expr(gz, scope, .none, params[1]), | |
| 7302 | .node = gz.nodeIndexToRelative(node), | |
| 7303 | }); | |
| 7304 | return rvalue(gz, rl, result, node); | |
| 7305 | }, | |
| 7269 | 7306 | |
| 7270 | 7307 | // zig fmt: off |
| 7271 | 7308 | .has_decl => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_decl), |
| ... | ... | @@ -8940,7 +8977,8 @@ fn rvalue( |
| 8940 | 8977 | const result = r: { |
| 8941 | 8978 | if (refToIndex(raw_result)) |result_index| { |
| 8942 | 8979 | const zir_tags = gz.astgen.instructions.items(.tag); |
| 8943 | if (zir_tags[result_index].isAlwaysVoid()) { | |
| 8980 | const data = gz.astgen.instructions.items(.data)[result_index]; | |
| 8981 | if (zir_tags[result_index].isAlwaysVoid(data)) { | |
| 8944 | 8982 | break :r Zir.Inst.Ref.void_value; |
| 8945 | 8983 | } |
| 8946 | 8984 | } |
| ... | ... | @@ -9987,10 +10025,18 @@ const GenZir = struct { |
| 9987 | 10025 | @boolToInt(args.cc != .none), |
| 9988 | 10026 | ); |
| 9989 | 10027 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.ExtendedFunc{ |
| 9990 | .src_node = gz.nodeIndexToRelative(args.src_node), | |
| 9991 | 10028 | .param_block = args.param_block, |
| 9992 | 10029 | .ret_body_len = @intCast(u32, ret_ty.len), |
| 9993 | 10030 | .body_len = @intCast(u32, body.len), |
| 10031 | .bits = .{ | |
| 10032 | .is_var_args = args.is_var_args, | |
| 10033 | .is_inferred_error = args.is_inferred_error, | |
| 10034 | .has_lib_name = args.lib_name != 0, | |
| 10035 | .has_cc = args.cc != .none, | |
| 10036 | .has_align = args.align_inst != .none, | |
| 10037 | .is_test = args.is_test, | |
| 10038 | .is_extern = args.is_extern, | |
| 10039 | }, | |
| 9994 | 10040 | }); |
| 9995 | 10041 | if (args.lib_name != 0) { |
| 9996 | 10042 | astgen.extra.appendAssumeCapacity(args.lib_name); |
| ... | ... | @@ -10014,19 +10060,10 @@ const GenZir = struct { |
| 10014 | 10060 | astgen.instructions.items(.data)[args.ret_br].@"break".block_inst = new_index; |
| 10015 | 10061 | } |
| 10016 | 10062 | astgen.instructions.appendAssumeCapacity(.{ |
| 10017 | .tag = .extended, | |
| 10018 | .data = .{ .extended = .{ | |
| 10019 | .opcode = .func, | |
| 10020 | .small = @bitCast(u16, Zir.Inst.ExtendedFunc.Small{ | |
| 10021 | .is_var_args = args.is_var_args, | |
| 10022 | .is_inferred_error = args.is_inferred_error, | |
| 10023 | .has_lib_name = args.lib_name != 0, | |
| 10024 | .has_cc = args.cc != .none, | |
| 10025 | .has_align = args.align_inst != .none, | |
| 10026 | .is_test = args.is_test, | |
| 10027 | .is_extern = args.is_extern, | |
| 10028 | }), | |
| 10029 | .operand = payload_index, | |
| 10063 | .tag = .func_extended, | |
| 10064 | .data = .{ .pl_node = .{ | |
| 10065 | .src_node = gz.nodeIndexToRelative(args.src_node), | |
| 10066 | .payload_index = payload_index, | |
| 10030 | 10067 | } }, |
| 10031 | 10068 | }); |
| 10032 | 10069 | gz.instructions.appendAssumeCapacity(new_index); |
| ... | ... | @@ -10893,9 +10930,7 @@ const GenZir = struct { |
| 10893 | 10930 | fn addDbgBlockBegin(gz: *GenZir) !void { |
| 10894 | 10931 | if (gz.force_comptime) return; |
| 10895 | 10932 | |
| 10896 | _ = try gz.add(.{ .tag = .extended, .data = .{ | |
| 10897 | .extended = .{ .opcode = .dbg_block_begin, .small = undefined, .operand = undefined }, | |
| 10898 | } }); | |
| 10933 | _ = try gz.add(.{ .tag = .dbg_block_begin, .data = undefined }); | |
| 10899 | 10934 | } |
| 10900 | 10935 | |
| 10901 | 10936 | fn addDbgBlockEnd(gz: *GenZir) !void { |
| ... | ... | @@ -10903,18 +10938,15 @@ const GenZir = struct { |
| 10903 | 10938 | const gpa = gz.astgen.gpa; |
| 10904 | 10939 | |
| 10905 | 10940 | const tags = gz.astgen.instructions.items(.tag); |
| 10906 | const data = gz.astgen.instructions.items(.data); | |
| 10907 | 10941 | const last_inst = gz.instructions.items[gz.instructions.items.len - 1]; |
| 10908 | 10942 | // 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) { | |
| 10943 | if (tags[last_inst] == .dbg_block_begin) { | |
| 10910 | 10944 | _ = gz.instructions.pop(); |
| 10911 | 10945 | return; |
| 10912 | 10946 | } |
| 10913 | 10947 | |
| 10914 | 10948 | 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 | } }); | |
| 10949 | try gz.astgen.instructions.append(gpa, .{ .tag = .dbg_block_end, .data = undefined }); | |
| 10918 | 10950 | try gz.instructions.insert(gpa, gz.instructions.items.len - 1, new_index); |
| 10919 | 10951 | } |
| 10920 | 10952 |
src/Module.zig+4-4| ... | ... | @@ -1532,10 +1532,10 @@ pub const Fn = struct { |
| 1532 | 1532 | switch (zir_tags[func.zir_body_inst]) { |
| 1533 | 1533 | .func => return false, |
| 1534 | 1534 | .func_inferred => return true, |
| 1535 | .extended => { | |
| 1536 | const extended = zir.instructions.items(.data)[func.zir_body_inst].extended; | |
| 1537 | const small = @bitCast(Zir.Inst.ExtendedFunc.Small, extended.small); | |
| 1538 | return small.is_inferred_error; | |
| 1535 | .func_extended => { | |
| 1536 | const inst_data = zir.instructions.items(.data)[func.zir_body_inst].pl_node; | |
| 1537 | const extra = zir.extraData(Zir.Inst.ExtendedFunc, inst_data.payload_index); | |
| 1538 | return extra.data.bits.is_inferred_error; | |
| 1539 | 1539 | }, |
| 1540 | 1540 | else => unreachable, |
| 1541 | 1541 | } |
src/Sema.zig+89-91| ... | ... | @@ -745,6 +745,7 @@ fn analyzeBodyInner( |
| 745 | 745 | .field_call_bind => try sema.zirFieldCallBind(block, inst), |
| 746 | 746 | .func => try sema.zirFunc(block, inst, false), |
| 747 | 747 | .func_inferred => try sema.zirFunc(block, inst, true), |
| 748 | .func_extended => try sema.zirFuncExtended(block, inst), | |
| 748 | 749 | .import => try sema.zirImport(block, inst), |
| 749 | 750 | .indexable_ptr_len => try sema.zirIndexablePtrLen(block, inst), |
| 750 | 751 | .int => try sema.zirInt(block, inst), |
| ... | ... | @@ -819,7 +820,6 @@ fn analyzeBodyInner( |
| 819 | 820 | .int_to_ptr => try sema.zirIntToPtr(block, inst), |
| 820 | 821 | .float_cast => try sema.zirFloatCast(block, inst), |
| 821 | 822 | .int_cast => try sema.zirIntCast(block, inst), |
| 822 | .err_set_cast => try sema.zirErrSetCast(block, inst), | |
| 823 | 823 | .ptr_cast => try sema.zirPtrCast(block, inst), |
| 824 | 824 | .truncate => try sema.zirTruncate(block, inst), |
| 825 | 825 | .align_cast => try sema.zirAlignCast(block, inst), |
| ... | ... | @@ -842,8 +842,7 @@ fn analyzeBodyInner( |
| 842 | 842 | .field_parent_ptr => try sema.zirFieldParentPtr(block, inst), |
| 843 | 843 | .builtin_async_call => try sema.zirBuiltinAsyncCall(block, inst), |
| 844 | 844 | .@"resume" => try sema.zirResume(block, inst), |
| 845 | .@"await" => try sema.zirAwait(block, inst, false), | |
| 846 | .await_nosuspend => try sema.zirAwait(block, inst, true), | |
| 845 | .@"await" => try sema.zirAwait(block, inst), | |
| 847 | 846 | .array_base_ptr => try sema.zirArrayBasePtr(block, inst), |
| 848 | 847 | .field_base_ptr => try sema.zirFieldBasePtr(block, inst), |
| 849 | 848 | |
| ... | ... | @@ -894,6 +893,9 @@ fn analyzeBodyInner( |
| 894 | 893 | .shl_exact => try sema.zirShl(block, inst, .shl_exact), |
| 895 | 894 | .shl_sat => try sema.zirShl(block, inst, .shl_sat), |
| 896 | 895 | |
| 896 | .ret_ptr => try sema.zirRetPtr(block, inst), | |
| 897 | .ret_type => try sema.zirRetType(block, inst), | |
| 898 | ||
| 897 | 899 | // Instructions that we know to *always* be noreturn based solely on their tag. |
| 898 | 900 | // These functions match the return type of analyzeBody so that we can |
| 899 | 901 | // tail call them here. |
| ... | ... | @@ -910,14 +912,11 @@ fn analyzeBodyInner( |
| 910 | 912 | const extended = datas[inst].extended; |
| 911 | 913 | break :ext switch (extended.opcode) { |
| 912 | 914 | // zig fmt: off |
| 913 | .func => try sema.zirFuncExtended( block, extended, inst), | |
| 914 | 915 | .variable => try sema.zirVarExtended( block, extended), |
| 915 | 916 | .struct_decl => try sema.zirStructDecl( block, extended, inst), |
| 916 | 917 | .enum_decl => try sema.zirEnumDecl( block, extended), |
| 917 | 918 | .union_decl => try sema.zirUnionDecl( block, extended, inst), |
| 918 | 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 | 920 | .this => try sema.zirThis( block, extended), |
| 922 | 921 | .ret_addr => try sema.zirRetAddr( block, extended), |
| 923 | 922 | .builtin_src => try sema.zirBuiltinSrc( block, extended), |
| ... | ... | @@ -940,16 +939,28 @@ fn analyzeBodyInner( |
| 940 | 939 | .wasm_memory_grow => try sema.zirWasmMemoryGrow( block, extended), |
| 941 | 940 | .prefetch => try sema.zirPrefetch( block, extended), |
| 942 | 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 | 944 | // 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); | |
| 947 | i += 1; | |
| 948 | continue; | |
| 949 | }, | |
| 950 | .set_float_mode => { | |
| 951 | try sema.zirSetFloatMode(block, extended); | |
| 947 | 952 | i += 1; |
| 948 | 953 | continue; |
| 949 | 954 | }, |
| 950 | .dbg_block_end => { | |
| 951 | dbg_block_begins -= 1; | |
| 952 | try sema.zirDbgBlockEnd(block); | |
| 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 | 964 | i += 1; |
| 954 | 965 | continue; |
| 955 | 966 | }, |
| ... | ... | @@ -961,18 +972,6 @@ fn analyzeBodyInner( |
| 961 | 972 | // continue the loop. |
| 962 | 973 | // We also know that they cannot be referenced later, so we avoid |
| 963 | 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 | 975 | .dbg_stmt => { |
| 977 | 976 | try sema.zirDbgStmt(block, inst); |
| 978 | 977 | i += 1; |
| ... | ... | @@ -988,6 +987,18 @@ fn analyzeBodyInner( |
| 988 | 987 | i += 1; |
| 989 | 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 | 1002 | .ensure_err_payload_void => { |
| 992 | 1003 | try sema.zirEnsureErrPayloadVoid(block, inst); |
| 993 | 1004 | i += 1; |
| ... | ... | @@ -1078,21 +1089,11 @@ fn analyzeBodyInner( |
| 1078 | 1089 | i += 1; |
| 1079 | 1090 | continue; |
| 1080 | 1091 | }, |
| 1081 | .set_align_stack => { | |
| 1082 | try sema.zirSetAlignStack(block, inst); | |
| 1083 | i += 1; | |
| 1084 | continue; | |
| 1085 | }, | |
| 1086 | 1092 | .set_cold => { |
| 1087 | 1093 | try sema.zirSetCold(block, inst); |
| 1088 | 1094 | i += 1; |
| 1089 | 1095 | continue; |
| 1090 | 1096 | }, |
| 1091 | .set_float_mode => { | |
| 1092 | try sema.zirSetFloatMode(block, inst); | |
| 1093 | i += 1; | |
| 1094 | continue; | |
| 1095 | }, | |
| 1096 | 1097 | .set_runtime_safety => { |
| 1097 | 1098 | try sema.zirSetRuntimeSafety(block, inst); |
| 1098 | 1099 | i += 1; |
| ... | ... | @@ -2452,15 +2453,12 @@ fn zirErrorSetDecl( |
| 2452 | 2453 | return sema.analyzeDeclVal(block, src, new_decl_index); |
| 2453 | 2454 | } |
| 2454 | 2455 | |
| 2455 | fn zirRetPtr( | |
| 2456 | sema: *Sema, | |
| 2457 | block: *Block, | |
| 2458 | extended: Zir.Inst.Extended.InstData, | |
| 2459 | ) CompileError!Air.Inst.Ref { | |
| 2456 | fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | |
| 2460 | 2457 | const tracy = trace(@src()); |
| 2461 | 2458 | defer tracy.end(); |
| 2462 | 2459 | |
| 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 | 2462 | try sema.requireFunctionBlock(block, src); |
| 2465 | 2463 | |
| 2466 | 2464 | if (block.is_comptime) { |
| ... | ... | @@ -2493,15 +2491,12 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 2493 | 2491 | return sema.analyzeRef(block, inst_data.src(), operand); |
| 2494 | 2492 | } |
| 2495 | 2493 | |
| 2496 | fn zirRetType( | |
| 2497 | sema: *Sema, | |
| 2498 | block: *Block, | |
| 2499 | extended: Zir.Inst.Extended.InstData, | |
| 2500 | ) CompileError!Air.Inst.Ref { | |
| 2494 | fn zirRetType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | |
| 2501 | 2495 | const tracy = trace(@src()); |
| 2502 | 2496 | defer tracy.end(); |
| 2503 | 2497 | |
| 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 | 2500 | try sema.requireFunctionBlock(block, src); |
| 2506 | 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 | 3741 | sema.fn_ret_ty.zigTypeTag() == .ErrorUnion) |
| 3747 | 3742 | { |
| 3748 | 3743 | 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) { | |
| 3752 | 3745 | try sema.addToInferredErrorSet(operand); |
| 3753 | 3746 | } |
| 3754 | 3747 | } |
| ... | ... | @@ -4392,11 +4385,11 @@ pub fn analyzeExport( |
| 4392 | 4385 | errdefer de_gop.value_ptr.* = gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1); |
| 4393 | 4386 | } |
| 4394 | 4387 | |
| 4395 | fn 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); | |
| 4388 | fn 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); | |
| 4400 | 4393 | if (alignment > 256) { |
| 4401 | 4394 | return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{ |
| 4402 | 4395 | alignment, |
| ... | ... | @@ -4433,10 +4426,10 @@ fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 4433 | 4426 | func.is_cold = is_cold; |
| 4434 | 4427 | } |
| 4435 | 4428 | |
| 4436 | fn 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"); | |
| 4429 | fn 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"); | |
| 4440 | 4433 | switch (float_mode) { |
| 4441 | 4434 | .Strict => return, |
| 4442 | 4435 | .Optimized => { |
| ... | ... | @@ -4451,12 +4444,12 @@ fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile |
| 4451 | 4444 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand); |
| 4452 | 4445 | } |
| 4453 | 4446 | |
| 4454 | fn zirFence(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | |
| 4447 | fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | |
| 4455 | 4448 | if (block.is_comptime) return; |
| 4456 | 4449 | |
| 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); | |
| 4460 | 4453 | |
| 4461 | 4454 | if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) { |
| 4462 | 4455 | return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{}); |
| ... | ... | @@ -12337,14 +12330,15 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi |
| 12337 | 12330 | } |
| 12338 | 12331 | |
| 12339 | 12332 | fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| 12340 | const tracy = trace(@src()); | |
| 12341 | defer tracy.end(); | |
| 12342 | ||
| 12343 | 12333 | const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable"; |
| 12344 | 12334 | const src = inst_data.src(); |
| 12335 | ||
| 12336 | if (block.is_comptime or inst_data.force_comptime) { | |
| 12337 | return sema.fail(block, src, "reached unreachable code", .{}); | |
| 12338 | } | |
| 12345 | 12339 | try sema.requireRuntimeBlock(block, src); |
| 12346 | 12340 | // TODO Add compile error for @optimizeFor occurring too late in a scope. |
| 12347 | try block.addUnreachable(src, inst_data.safety); | |
| 12341 | try block.addUnreachable(src, true); | |
| 12348 | 12342 | return always_noreturn; |
| 12349 | 12343 | } |
| 12350 | 12344 | |
| ... | ... | @@ -14143,12 +14137,11 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14143 | 14137 | return block.addBitCast(type_res, operand_coerced); |
| 14144 | 14138 | } |
| 14145 | 14139 | |
| 14146 | fn zirErrSetCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | |
| 14147 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 14148 | const src = inst_data.src(); | |
| 14149 | const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | |
| 14150 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | |
| 14151 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | |
| 14140 | fn 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 }; | |
| 14152 | 14145 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 14153 | 14146 | const operand = sema.resolveInst(extra.rhs); |
| 14154 | 14147 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -16006,15 +15999,24 @@ fn zirAwait( |
| 16006 | 15999 | sema: *Sema, |
| 16007 | 16000 | block: *Block, |
| 16008 | 16001 | inst: Zir.Inst.Index, |
| 16009 | is_nosuspend: bool, | |
| 16010 | 16002 | ) CompileError!Air.Inst.Ref { |
| 16011 | 16003 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 16012 | 16004 | const src = inst_data.src(); |
| 16013 | 16005 | |
| 16014 | _ = is_nosuspend; | |
| 16015 | 16006 | return sema.fail(block, src, "TODO: Sema.zirAwait", .{}); |
| 16016 | 16007 | } |
| 16017 | 16008 | |
| 16009 | fn 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 | ||
| 16018 | 16020 | fn zirVarExtended( |
| 16019 | 16021 | sema: *Sema, |
| 16020 | 16022 | block: *Block, |
| ... | ... | @@ -16097,37 +16099,33 @@ fn zirVarExtended( |
| 16097 | 16099 | return result; |
| 16098 | 16100 | } |
| 16099 | 16101 | |
| 16100 | fn zirFuncExtended( | |
| 16101 | sema: *Sema, | |
| 16102 | block: *Block, | |
| 16103 | extended: Zir.Inst.Extended.InstData, | |
| 16104 | inst: Zir.Inst.Index, | |
| 16105 | ) CompileError!Air.Inst.Ref { | |
| 16102 | fn zirFuncExtended(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | |
| 16106 | 16103 | const tracy = trace(@src()); |
| 16107 | 16104 | defer tracy.end(); |
| 16108 | 16105 | |
| 16109 | const extra = sema.code.extraData(Zir.Inst.ExtendedFunc, extended.operand); | |
| 16110 | const src: LazySrcLoc = .{ .node_offset = extra.data.src_node }; | |
| 16111 | const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = extra.data.src_node }; | |
| 16106 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 16107 | const src = inst_data.src(); | |
| 16108 | const extra = sema.code.extraData(Zir.Inst.ExtendedFunc, inst_data.payload_index); | |
| 16109 | ||
| 16110 | const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node }; | |
| 16112 | 16111 | const align_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at align |
| 16113 | const small = @bitCast(Zir.Inst.ExtendedFunc.Small, extended.small); | |
| 16114 | 16112 | |
| 16115 | 16113 | var extra_index: usize = extra.end; |
| 16116 | 16114 | |
| 16117 | const lib_name: ?[]const u8 = if (small.has_lib_name) blk: { | |
| 16115 | const lib_name: ?[]const u8 = if (extra.data.bits.has_lib_name) blk: { | |
| 16118 | 16116 | const lib_name = sema.code.nullTerminatedString(sema.code.extra[extra_index]); |
| 16119 | 16117 | extra_index += 1; |
| 16120 | 16118 | break :blk lib_name; |
| 16121 | 16119 | } else null; |
| 16122 | 16120 | |
| 16123 | const cc: std.builtin.CallingConvention = if (small.has_cc) blk: { | |
| 16121 | const cc: std.builtin.CallingConvention = if (extra.data.bits.has_cc) blk: { | |
| 16124 | 16122 | const cc_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 16125 | 16123 | extra_index += 1; |
| 16126 | 16124 | const cc_tv = try sema.resolveInstConst(block, cc_src, cc_ref); |
| 16127 | 16125 | break :blk cc_tv.val.toEnum(std.builtin.CallingConvention); |
| 16128 | 16126 | } else .Unspecified; |
| 16129 | 16127 | |
| 16130 | const align_val: Value = if (small.has_align) blk: { | |
| 16128 | const align_val: Value = if (extra.data.bits.has_align) blk: { | |
| 16131 | 16129 | const align_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 16132 | 16130 | extra_index += 1; |
| 16133 | 16131 | const align_tv = try sema.resolveInstConst(block, align_src, align_ref); |
| ... | ... | @@ -16144,13 +16142,13 @@ fn zirFuncExtended( |
| 16144 | 16142 | src_locs = sema.code.extraData(Zir.Inst.Func.SrcLocs, extra_index).data; |
| 16145 | 16143 | } |
| 16146 | 16144 | |
| 16147 | const is_var_args = small.is_var_args; | |
| 16148 | const is_inferred_error = small.is_inferred_error; | |
| 16149 | const is_extern = small.is_extern; | |
| 16145 | const is_var_args = extra.data.bits.is_var_args; | |
| 16146 | const is_inferred_error = extra.data.bits.is_inferred_error; | |
| 16147 | const is_extern = extra.data.bits.is_extern; | |
| 16150 | 16148 | |
| 16151 | 16149 | return sema.funcCommon( |
| 16152 | 16150 | block, |
| 16153 | extra.data.src_node, | |
| 16151 | inst_data.src_node, | |
| 16154 | 16152 | inst, |
| 16155 | 16153 | ret_ty_body, |
| 16156 | 16154 | cc, |
src/Zir.zig+75-79| ... | ... | @@ -73,6 +73,7 @@ pub fn extraData(code: Zir, comptime T: type, index: usize) struct { data: T, en |
| 73 | 73 | i32 => @bitCast(i32, code.extra[i]), |
| 74 | 74 | Inst.Call.Flags => @bitCast(Inst.Call.Flags, code.extra[i]), |
| 75 | 75 | Inst.SwitchBlock.Bits => @bitCast(Inst.SwitchBlock.Bits, code.extra[i]), |
| 76 | Inst.ExtendedFunc.Bits => @bitCast(Inst.ExtendedFunc.Bits, code.extra[i]), | |
| 76 | 77 | else => @compileError("bad field type"), |
| 77 | 78 | }; |
| 78 | 79 | i += 1; |
| ... | ... | @@ -278,8 +279,6 @@ pub const Inst = struct { |
| 278 | 279 | /// break instruction in a block, and the target block is the parent. |
| 279 | 280 | /// Uses the `break` union field. |
| 280 | 281 | break_inline, |
| 281 | /// Uses the `node` union field. | |
| 282 | breakpoint, | |
| 283 | 282 | /// Function call. |
| 284 | 283 | /// Uses `pl_node`. AST node is the function call. Payload is `Call`. |
| 285 | 284 | call, |
| ... | ... | @@ -331,6 +330,10 @@ pub const Inst = struct { |
| 331 | 330 | /// Same as `dbg_var_ptr` but the local is always a const and the operand |
| 332 | 331 | /// is the local's value. |
| 333 | 332 | dbg_var_val, |
| 333 | /// Marks the beginning of a semantic scope for debug info variables. | |
| 334 | dbg_block_begin, | |
| 335 | /// Marks the end of a semantic scope for debug info variables. | |
| 336 | dbg_block_end, | |
| 334 | 337 | /// Uses a name to identify a Decl and takes a pointer to it. |
| 335 | 338 | /// Uses the `str_tok` union field. |
| 336 | 339 | decl_ref, |
| ... | ... | @@ -413,6 +416,10 @@ pub const Inst = struct { |
| 413 | 416 | func, |
| 414 | 417 | /// Same as `func` but has an inferred error set. |
| 415 | 418 | func_inferred, |
| 419 | /// Represents a function declaration or function prototype, depending on | |
| 420 | /// whether body_len is 0. | |
| 421 | /// Uses the `pl_node` union field. `payload_index` points to a `ExtendedFunc`. | |
| 422 | func_extended, | |
| 416 | 423 | /// Implements the `@import` builtin. |
| 417 | 424 | /// Uses the `str_tok` field. |
| 418 | 425 | import, |
| ... | ... | @@ -499,6 +506,12 @@ pub const Inst = struct { |
| 499 | 506 | /// this instruction; a following 'ret' instruction will do the diversion. |
| 500 | 507 | /// Uses the `str_tok` union field. |
| 501 | 508 | ret_err_value_code, |
| 509 | /// Obtains a pointer to the return value. | |
| 510 | /// Uses the `node` union field. | |
| 511 | ret_ptr, | |
| 512 | /// Obtains the return type of the in-scope function. | |
| 513 | /// Uses the `node` union field. | |
| 514 | ret_type, | |
| 502 | 515 | /// Create a pointer type that does not have a sentinel, alignment, address space, or bit range specified. |
| 503 | 516 | /// Uses the `ptr_type_simple` union field. |
| 504 | 517 | ptr_type_simple, |
| ... | ... | @@ -744,8 +757,6 @@ pub const Inst = struct { |
| 744 | 757 | size_of, |
| 745 | 758 | /// Implements the `@bitSizeOf` builtin. Uses `un_node`. |
| 746 | 759 | bit_size_of, |
| 747 | /// Implements the `@fence` builtin. Uses `un_node`. | |
| 748 | fence, | |
| 749 | 760 | |
| 750 | 761 | /// Implement builtin `@ptrToInt`. Uses `un_node`. |
| 751 | 762 | /// Convert a pointer to a `usize` integer. |
| ... | ... | @@ -774,12 +785,8 @@ pub const Inst = struct { |
| 774 | 785 | error_name, |
| 775 | 786 | /// Implement builtin `@panic`. Uses `un_node`. |
| 776 | 787 | panic, |
| 777 | /// Implement builtin `@setAlignStack`. Uses `un_node`. | |
| 778 | set_align_stack, | |
| 779 | 788 | /// Implement builtin `@setCold`. Uses `un_node`. |
| 780 | 789 | set_cold, |
| 781 | /// Implement builtin `@setFloatMode`. Uses `un_node`. | |
| 782 | set_float_mode, | |
| 783 | 790 | /// Implement builtin `@setRuntimeSafety`. Uses `un_node`. |
| 784 | 791 | set_runtime_safety, |
| 785 | 792 | /// Implement builtin `@sqrt`. Uses `un_node`. |
| ... | ... | @@ -843,9 +850,6 @@ pub const Inst = struct { |
| 843 | 850 | /// Convert an integer value to another integer type, asserting that the destination type |
| 844 | 851 | /// can hold the same mathematical value. |
| 845 | 852 | 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 | 853 | /// Implements the `@ptrCast` builtin. |
| 850 | 854 | /// Uses `pl_node` with payload `Bin`. `lhs` is dest type, `rhs` is operand. |
| 851 | 855 | ptr_cast, |
| ... | ... | @@ -972,7 +976,6 @@ pub const Inst = struct { |
| 972 | 976 | /// Implements `resume` syntax. Uses `un_node` field. |
| 973 | 977 | @"resume", |
| 974 | 978 | @"await", |
| 975 | await_nosuspend, | |
| 976 | 979 | |
| 977 | 980 | /// When a type or function refers to a comptime value from an outer |
| 978 | 981 | /// scope, that forms a closure over comptime value. The outer scope |
| ... | ... | @@ -1028,8 +1031,6 @@ pub const Inst = struct { |
| 1028 | 1031 | .bool_br_and, |
| 1029 | 1032 | .bool_br_or, |
| 1030 | 1033 | .bool_not, |
| 1031 | .breakpoint, | |
| 1032 | .fence, | |
| 1033 | 1034 | .call, |
| 1034 | 1035 | .cmp_lt, |
| 1035 | 1036 | .cmp_lte, |
| ... | ... | @@ -1044,6 +1045,8 @@ pub const Inst = struct { |
| 1044 | 1045 | .dbg_stmt, |
| 1045 | 1046 | .dbg_var_ptr, |
| 1046 | 1047 | .dbg_var_val, |
| 1048 | .dbg_block_begin, | |
| 1049 | .dbg_block_end, | |
| 1047 | 1050 | .decl_ref, |
| 1048 | 1051 | .decl_val, |
| 1049 | 1052 | .load, |
| ... | ... | @@ -1064,6 +1067,7 @@ pub const Inst = struct { |
| 1064 | 1067 | .field_val_named, |
| 1065 | 1068 | .func, |
| 1066 | 1069 | .func_inferred, |
| 1070 | .func_extended, | |
| 1067 | 1071 | .has_decl, |
| 1068 | 1072 | .int, |
| 1069 | 1073 | .int_big, |
| ... | ... | @@ -1164,9 +1168,7 @@ pub const Inst = struct { |
| 1164 | 1168 | .bool_to_int, |
| 1165 | 1169 | .embed_file, |
| 1166 | 1170 | .error_name, |
| 1167 | .set_align_stack, | |
| 1168 | 1171 | .set_cold, |
| 1169 | .set_float_mode, | |
| 1170 | 1172 | .set_runtime_safety, |
| 1171 | 1173 | .sqrt, |
| 1172 | 1174 | .sin, |
| ... | ... | @@ -1192,7 +1194,6 @@ pub const Inst = struct { |
| 1192 | 1194 | .int_to_ptr, |
| 1193 | 1195 | .float_cast, |
| 1194 | 1196 | .int_cast, |
| 1195 | .err_set_cast, | |
| 1196 | 1197 | .ptr_cast, |
| 1197 | 1198 | .truncate, |
| 1198 | 1199 | .align_cast, |
| ... | ... | @@ -1231,11 +1232,12 @@ pub const Inst = struct { |
| 1231 | 1232 | .c_import, |
| 1232 | 1233 | .@"resume", |
| 1233 | 1234 | .@"await", |
| 1234 | .await_nosuspend, | |
| 1235 | 1235 | .ret_err_value_code, |
| 1236 | 1236 | .extended, |
| 1237 | 1237 | .closure_get, |
| 1238 | 1238 | .closure_capture, |
| 1239 | .ret_ptr, | |
| 1240 | .ret_type, | |
| 1239 | 1241 | => false, |
| 1240 | 1242 | |
| 1241 | 1243 | .@"break", |
| ... | ... | @@ -1258,13 +1260,13 @@ pub const Inst = struct { |
| 1258 | 1260 | /// AstGen uses this to find out if `Ref.void_value` should be used in place |
| 1259 | 1261 | /// of the result of a given instruction. This allows Sema to forego adding |
| 1260 | 1262 | /// the instruction to the map after analysis. |
| 1261 | pub fn isAlwaysVoid(tag: Tag) bool { | |
| 1263 | pub fn isAlwaysVoid(tag: Tag, data: Data) bool { | |
| 1262 | 1264 | return switch (tag) { |
| 1263 | .breakpoint, | |
| 1264 | .fence, | |
| 1265 | 1265 | .dbg_stmt, |
| 1266 | 1266 | .dbg_var_ptr, |
| 1267 | 1267 | .dbg_var_val, |
| 1268 | .dbg_block_begin, | |
| 1269 | .dbg_block_end, | |
| 1268 | 1270 | .ensure_result_used, |
| 1269 | 1271 | .ensure_result_non_error, |
| 1270 | 1272 | .ensure_err_payload_void, |
| ... | ... | @@ -1283,9 +1285,7 @@ pub const Inst = struct { |
| 1283 | 1285 | .validate_array_init_comptime, |
| 1284 | 1286 | .@"export", |
| 1285 | 1287 | .export_value, |
| 1286 | .set_align_stack, | |
| 1287 | 1288 | .set_cold, |
| 1288 | .set_float_mode, | |
| 1289 | 1289 | .set_runtime_safety, |
| 1290 | 1290 | .memcpy, |
| 1291 | 1291 | .memset, |
| ... | ... | @@ -1353,6 +1353,7 @@ pub const Inst = struct { |
| 1353 | 1353 | .field_val_named, |
| 1354 | 1354 | .func, |
| 1355 | 1355 | .func_inferred, |
| 1356 | .func_extended, | |
| 1356 | 1357 | .has_decl, |
| 1357 | 1358 | .int, |
| 1358 | 1359 | .int_big, |
| ... | ... | @@ -1464,7 +1465,6 @@ pub const Inst = struct { |
| 1464 | 1465 | .int_to_ptr, |
| 1465 | 1466 | .float_cast, |
| 1466 | 1467 | .int_cast, |
| 1467 | .err_set_cast, | |
| 1468 | 1468 | .ptr_cast, |
| 1469 | 1469 | .truncate, |
| 1470 | 1470 | .align_cast, |
| ... | ... | @@ -1500,9 +1500,7 @@ pub const Inst = struct { |
| 1500 | 1500 | .c_import, |
| 1501 | 1501 | .@"resume", |
| 1502 | 1502 | .@"await", |
| 1503 | .await_nosuspend, | |
| 1504 | 1503 | .ret_err_value_code, |
| 1505 | .extended, | |
| 1506 | 1504 | .closure_get, |
| 1507 | 1505 | .closure_capture, |
| 1508 | 1506 | .@"break", |
| ... | ... | @@ -1514,11 +1512,18 @@ pub const Inst = struct { |
| 1514 | 1512 | .ret_load, |
| 1515 | 1513 | .ret_tok, |
| 1516 | 1514 | .ret_err_value, |
| 1515 | .ret_ptr, | |
| 1516 | .ret_type, | |
| 1517 | 1517 | .@"unreachable", |
| 1518 | 1518 | .repeat, |
| 1519 | 1519 | .repeat_inline, |
| 1520 | 1520 | .panic, |
| 1521 | 1521 | => false, |
| 1522 | ||
| 1523 | .extended => switch (data.extended.opcode) { | |
| 1524 | .breakpoint, .fence => true, | |
| 1525 | else => false, | |
| 1526 | }, | |
| 1522 | 1527 | }; |
| 1523 | 1528 | } |
| 1524 | 1529 | |
| ... | ... | @@ -1563,7 +1568,6 @@ pub const Inst = struct { |
| 1563 | 1568 | .bool_br_or = .bool_br, |
| 1564 | 1569 | .@"break" = .@"break", |
| 1565 | 1570 | .break_inline = .@"break", |
| 1566 | .breakpoint = .node, | |
| 1567 | 1571 | .call = .pl_node, |
| 1568 | 1572 | .cmp_lt = .pl_node, |
| 1569 | 1573 | .cmp_lte = .pl_node, |
| ... | ... | @@ -1580,6 +1584,8 @@ pub const Inst = struct { |
| 1580 | 1584 | .dbg_stmt = .dbg_stmt, |
| 1581 | 1585 | .dbg_var_ptr = .str_op, |
| 1582 | 1586 | .dbg_var_val = .str_op, |
| 1587 | .dbg_block_begin = .tok, | |
| 1588 | .dbg_block_end = .tok, | |
| 1583 | 1589 | .decl_ref = .str_tok, |
| 1584 | 1590 | .decl_val = .str_tok, |
| 1585 | 1591 | .load = .un_node, |
| ... | ... | @@ -1602,6 +1608,7 @@ pub const Inst = struct { |
| 1602 | 1608 | .field_call_bind = .pl_node, |
| 1603 | 1609 | .func = .pl_node, |
| 1604 | 1610 | .func_inferred = .pl_node, |
| 1611 | .func_extended = .pl_node, | |
| 1605 | 1612 | .import = .str_tok, |
| 1606 | 1613 | .int = .int, |
| 1607 | 1614 | .int_big = .str, |
| ... | ... | @@ -1623,6 +1630,8 @@ pub const Inst = struct { |
| 1623 | 1630 | .ret_tok = .un_tok, |
| 1624 | 1631 | .ret_err_value = .str_tok, |
| 1625 | 1632 | .ret_err_value_code = .str_tok, |
| 1633 | .ret_ptr = .node, | |
| 1634 | .ret_type = .node, | |
| 1626 | 1635 | .ptr_type_simple = .ptr_type_simple, |
| 1627 | 1636 | .ptr_type = .ptr_type, |
| 1628 | 1637 | .slice_start = .pl_node, |
| ... | ... | @@ -1685,7 +1694,6 @@ pub const Inst = struct { |
| 1685 | 1694 | .type_info = .un_node, |
| 1686 | 1695 | .size_of = .un_node, |
| 1687 | 1696 | .bit_size_of = .un_node, |
| 1688 | .fence = .un_node, | |
| 1689 | 1697 | |
| 1690 | 1698 | .ptr_to_int = .un_node, |
| 1691 | 1699 | .error_to_int = .un_node, |
| ... | ... | @@ -1698,9 +1706,7 @@ pub const Inst = struct { |
| 1698 | 1706 | .embed_file = .un_node, |
| 1699 | 1707 | .error_name = .un_node, |
| 1700 | 1708 | .panic = .un_node, |
| 1701 | .set_align_stack = .un_node, | |
| 1702 | 1709 | .set_cold = .un_node, |
| 1703 | .set_float_mode = .un_node, | |
| 1704 | 1710 | .set_runtime_safety = .un_node, |
| 1705 | 1711 | .sqrt = .un_node, |
| 1706 | 1712 | .sin = .un_node, |
| ... | ... | @@ -1728,7 +1734,6 @@ pub const Inst = struct { |
| 1728 | 1734 | .int_to_enum = .pl_node, |
| 1729 | 1735 | .float_cast = .pl_node, |
| 1730 | 1736 | .int_cast = .pl_node, |
| 1731 | .err_set_cast = .pl_node, | |
| 1732 | 1737 | .ptr_cast = .pl_node, |
| 1733 | 1738 | .truncate = .pl_node, |
| 1734 | 1739 | .align_cast = .pl_node, |
| ... | ... | @@ -1788,7 +1793,6 @@ pub const Inst = struct { |
| 1788 | 1793 | |
| 1789 | 1794 | .@"resume" = .un_node, |
| 1790 | 1795 | .@"await" = .un_node, |
| 1791 | .await_nosuspend = .un_node, | |
| 1792 | 1796 | |
| 1793 | 1797 | .closure_capture = .un_tok, |
| 1794 | 1798 | .closure_get = .inst_node, |
| ... | ... | @@ -1806,11 +1810,6 @@ pub const Inst = struct { |
| 1806 | 1810 | /// Rarer instructions are here; ones that do not fit in the 8-bit `Tag` enum. |
| 1807 | 1811 | /// `noreturn` instructions may not go here; they must be part of the main `Tag` enum. |
| 1808 | 1812 | pub const Extended = enum(u16) { |
| 1809 | /// Represents a function declaration or function prototype, depending on | |
| 1810 | /// whether body_len is 0. | |
| 1811 | /// `operand` is payload index to `ExtendedFunc`. | |
| 1812 | /// `small` is `ExtendedFunc.Small`. | |
| 1813 | func, | |
| 1814 | 1813 | /// Declares a global variable. |
| 1815 | 1814 | /// `operand` is payload index to `ExtendedVar`. |
| 1816 | 1815 | /// `small` is `ExtendedVar.Small`. |
| ... | ... | @@ -1834,12 +1833,6 @@ pub const Inst = struct { |
| 1834 | 1833 | /// `operand` is payload index to `OpaqueDecl`. |
| 1835 | 1834 | /// `small` is `OpaqueDecl.Small`. |
| 1836 | 1835 | 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 | 1836 | /// Implements the `@This` builtin. |
| 1844 | 1837 | /// `operand` is `src_node: i32`. |
| 1845 | 1838 | this, |
| ... | ... | @@ -1917,10 +1910,6 @@ pub const Inst = struct { |
| 1917 | 1910 | /// The `@prefetch` builtin. |
| 1918 | 1911 | /// `operand` is payload index to `BinNode`. |
| 1919 | 1912 | 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 | 1913 | /// Given a pointer to a struct or object that contains virtual fields, returns the |
| 1925 | 1914 | /// named field. If there is no named field, searches in the type for a decl that |
| 1926 | 1915 | /// matches the field name. The decl is resolved and we ensure that it's a function |
| ... | ... | @@ -1931,6 +1920,22 @@ pub const Inst = struct { |
| 1931 | 1920 | /// `builtin_call` instruction. Any other use is invalid zir and may crash the compiler. |
| 1932 | 1921 | /// Uses `pl_node` field. The AST node is the `@field` builtin. Payload is FieldNamedNode. |
| 1933 | 1922 | field_call_bind_named, |
| 1923 | /// Implements the `@fence` builtin. | |
| 1924 | /// `operand` is payload index to `UnNode`. | |
| 1925 | fence, | |
| 1926 | /// Implement builtin `@setFloatMode`. | |
| 1927 | /// `operand` is payload index to `UnNode`. | |
| 1928 | set_float_mode, | |
| 1929 | /// Implement builtin `@setAlignStack`. | |
| 1930 | /// `operand` is payload index to `UnNode`. | |
| 1931 | set_align_stack, | |
| 1932 | /// Implements the `@errSetCast` builtin. | |
| 1933 | /// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand. | |
| 1934 | err_set_cast, | |
| 1935 | /// `operand` is payload index to `UnNode`. | |
| 1936 | await_nosuspend, | |
| 1937 | /// `operand` is `src_node: i32`. | |
| 1938 | breakpoint, | |
| 1934 | 1939 | |
| 1935 | 1940 | pub const InstData = struct { |
| 1936 | 1941 | opcode: Extended, |
| ... | ... | @@ -2502,11 +2507,7 @@ pub const Inst = struct { |
| 2502 | 2507 | /// Offset from Decl AST node index. |
| 2503 | 2508 | /// `Tag` determines which kind of AST node this points to. |
| 2504 | 2509 | src_node: i32, |
| 2505 | /// `false`: Not safety checked - the compiler will assume the | |
| 2506 | /// correctness of this instruction. | |
| 2507 | /// `true`: In safety-checked modes, this will generate a call | |
| 2508 | /// to the panic function unless it can be proven unreachable by the compiler. | |
| 2509 | safety: bool, | |
| 2510 | force_comptime: bool, | |
| 2510 | 2511 | |
| 2511 | 2512 | pub fn src(self: @This()) LazySrcLoc { |
| 2512 | 2513 | return .{ .node_offset = self.src_node }; |
| ... | ... | @@ -2623,14 +2624,14 @@ pub const Inst = struct { |
| 2623 | 2624 | /// 4. body: Index // for each body_len |
| 2624 | 2625 | /// 5. src_locs: Func.SrcLocs // if body_len != 0 |
| 2625 | 2626 | pub const ExtendedFunc = struct { |
| 2626 | src_node: i32, | |
| 2627 | 2627 | /// If this is 0 it means a void return type. |
| 2628 | 2628 | ret_body_len: u32, |
| 2629 | 2629 | /// Points to the block that contains the param instructions for this function. |
| 2630 | 2630 | param_block: Index, |
| 2631 | 2631 | body_len: u32, |
| 2632 | bits: Bits, | |
| 2632 | 2633 | |
| 2633 | pub const Small = packed struct { | |
| 2634 | pub const Bits = packed struct { | |
| 2634 | 2635 | is_var_args: bool, |
| 2635 | 2636 | is_inferred_error: bool, |
| 2636 | 2637 | has_lib_name: bool, |
| ... | ... | @@ -2638,7 +2639,7 @@ pub const Inst = struct { |
| 2638 | 2639 | has_align: bool, |
| 2639 | 2640 | is_test: bool, |
| 2640 | 2641 | is_extern: bool, |
| 2641 | _: u9 = undefined, | |
| 2642 | _: u25 = undefined, | |
| 2642 | 2643 | }; |
| 2643 | 2644 | }; |
| 2644 | 2645 | |
| ... | ... | @@ -3462,14 +3463,11 @@ pub fn declIterator(zir: Zir, decl_inst: u32) DeclIterator { |
| 3462 | 3463 | switch (tags[decl_inst]) { |
| 3463 | 3464 | // Functions are allowed and yield no iterations. |
| 3464 | 3465 | // There is one case matching this in the extended instruction set below. |
| 3465 | .func, | |
| 3466 | .func_inferred, | |
| 3467 | => return declIteratorInner(zir, 0, 0), | |
| 3466 | .func, .func_inferred, .func_extended => return declIteratorInner(zir, 0, 0), | |
| 3468 | 3467 | |
| 3469 | 3468 | .extended => { |
| 3470 | 3469 | const extended = datas[decl_inst].extended; |
| 3471 | 3470 | switch (extended.opcode) { |
| 3472 | .func => return declIteratorInner(zir, 0, 0), | |
| 3473 | 3471 | .struct_decl => { |
| 3474 | 3472 | const small = @bitCast(Inst.StructDecl.Small, extended.small); |
| 3475 | 3473 | var extra_index: usize = extended.operand; |
| ... | ... | @@ -3574,21 +3572,21 @@ fn findDeclsInner( |
| 3574 | 3572 | const body = zir.extra[extra.end..][0..extra.data.body_len]; |
| 3575 | 3573 | return zir.findDeclsBody(list, body); |
| 3576 | 3574 | }, |
| 3575 | .func_extended => { | |
| 3576 | try list.append(inst); | |
| 3577 | ||
| 3578 | const inst_data = datas[inst].pl_node; | |
| 3579 | const extra = zir.extraData(Inst.ExtendedFunc, inst_data.payload_index); | |
| 3580 | var extra_index: usize = extra.end; | |
| 3581 | extra_index += @boolToInt(extra.data.bits.has_lib_name); | |
| 3582 | extra_index += @boolToInt(extra.data.bits.has_cc); | |
| 3583 | extra_index += @boolToInt(extra.data.bits.has_align); | |
| 3584 | const body = zir.extra[extra_index..][0..extra.data.body_len]; | |
| 3585 | return zir.findDeclsBody(list, body); | |
| 3586 | }, | |
| 3577 | 3587 | .extended => { |
| 3578 | 3588 | const extended = datas[inst].extended; |
| 3579 | 3589 | switch (extended.opcode) { |
| 3580 | .func => { | |
| 3581 | try list.append(inst); | |
| 3582 | ||
| 3583 | const extra = zir.extraData(Inst.ExtendedFunc, extended.operand); | |
| 3584 | const small = @bitCast(Inst.ExtendedFunc.Small, extended.small); | |
| 3585 | var extra_index: usize = extra.end; | |
| 3586 | extra_index += @boolToInt(small.has_lib_name); | |
| 3587 | extra_index += @boolToInt(small.has_cc); | |
| 3588 | extra_index += @boolToInt(small.has_align); | |
| 3589 | const body = zir.extra[extra_index..][0..extra.data.body_len]; | |
| 3590 | return zir.findDeclsBody(list, body); | |
| 3591 | }, | |
| 3592 | 3590 | |
| 3593 | 3591 | // Decl instructions are interesting but have no body. |
| 3594 | 3592 | // TODO yes they do have a body actually. recurse over them just like block instructions. |
| ... | ... | @@ -3735,15 +3733,13 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 3735 | 3733 | .body = body, |
| 3736 | 3734 | }; |
| 3737 | 3735 | }, |
| 3738 | .extended => blk: { | |
| 3739 | const extended = datas[fn_inst].extended; | |
| 3740 | assert(extended.opcode == .func); | |
| 3741 | const extra = zir.extraData(Inst.ExtendedFunc, extended.operand); | |
| 3742 | const small = @bitCast(Inst.ExtendedFunc.Small, extended.small); | |
| 3736 | .func_extended => blk: { | |
| 3737 | const inst_data = datas[fn_inst].pl_node; | |
| 3738 | const extra = zir.extraData(Inst.ExtendedFunc, inst_data.payload_index); | |
| 3743 | 3739 | var extra_index: usize = extra.end; |
| 3744 | extra_index += @boolToInt(small.has_lib_name); | |
| 3745 | extra_index += @boolToInt(small.has_cc); | |
| 3746 | extra_index += @boolToInt(small.has_align); | |
| 3740 | extra_index += @boolToInt(extra.data.bits.has_lib_name); | |
| 3741 | extra_index += @boolToInt(extra.data.bits.has_cc); | |
| 3742 | extra_index += @boolToInt(extra.data.bits.has_align); | |
| 3747 | 3743 | const ret_ty_body = zir.extra[extra_index..][0..extra.data.ret_body_len]; |
| 3748 | 3744 | extra_index += ret_ty_body.len; |
| 3749 | 3745 | const body = zir.extra[extra_index..][0..extra.data.body_len]; |
src/print_zir.zig+33-28| ... | ... | @@ -200,9 +200,7 @@ const Writer = struct { |
| 200 | 200 | .embed_file, |
| 201 | 201 | .error_name, |
| 202 | 202 | .panic, |
| 203 | .set_align_stack, | |
| 204 | 203 | .set_cold, |
| 205 | .set_float_mode, | |
| 206 | 204 | .set_runtime_safety, |
| 207 | 205 | .sqrt, |
| 208 | 206 | .sin, |
| ... | ... | @@ -231,8 +229,6 @@ const Writer = struct { |
| 231 | 229 | .elem_type, |
| 232 | 230 | .@"resume", |
| 233 | 231 | .@"await", |
| 234 | .await_nosuspend, | |
| 235 | .fence, | |
| 236 | 232 | .switch_cond, |
| 237 | 233 | .switch_cond_ref, |
| 238 | 234 | .array_base_ptr, |
| ... | ... | @@ -343,7 +339,6 @@ const Writer = struct { |
| 343 | 339 | .int_to_enum, |
| 344 | 340 | .float_cast, |
| 345 | 341 | .int_cast, |
| 346 | .err_set_cast, | |
| 347 | 342 | .ptr_cast, |
| 348 | 343 | .truncate, |
| 349 | 344 | .align_cast, |
| ... | ... | @@ -405,13 +400,14 @@ const Writer = struct { |
| 405 | 400 | |
| 406 | 401 | .as_node => try self.writeAs(stream, inst), |
| 407 | 402 | |
| 408 | .breakpoint, | |
| 409 | 403 | .repeat, |
| 410 | 404 | .repeat_inline, |
| 411 | 405 | .alloc_inferred, |
| 412 | 406 | .alloc_inferred_mut, |
| 413 | 407 | .alloc_inferred_comptime, |
| 414 | 408 | .alloc_inferred_comptime_mut, |
| 409 | .ret_ptr, | |
| 410 | .ret_type, | |
| 415 | 411 | => try self.writeNode(stream, inst), |
| 416 | 412 | |
| 417 | 413 | .error_value, |
| ... | ... | @@ -433,6 +429,7 @@ const Writer = struct { |
| 433 | 429 | |
| 434 | 430 | .func => try self.writeFunc(stream, inst, false), |
| 435 | 431 | .func_inferred => try self.writeFunc(stream, inst, true), |
| 432 | .func_extended => try self.writeFuncExtended(stream, inst), | |
| 436 | 433 | |
| 437 | 434 | .@"unreachable" => try self.writeUnreachable(stream, inst), |
| 438 | 435 | |
| ... | ... | @@ -444,6 +441,10 @@ const Writer = struct { |
| 444 | 441 | |
| 445 | 442 | .dbg_stmt => try self.writeDbgStmt(stream, inst), |
| 446 | 443 | |
| 444 | .dbg_block_begin, | |
| 445 | .dbg_block_end, | |
| 446 | => try stream.writeAll("))"), | |
| 447 | ||
| 447 | 448 | .closure_get => try self.writeInstNode(stream, inst), |
| 448 | 449 | |
| 449 | 450 | .extended => try self.writeExtended(stream, inst), |
| ... | ... | @@ -454,13 +455,12 @@ const Writer = struct { |
| 454 | 455 | const extended = self.code.instructions.items(.data)[inst].extended; |
| 455 | 456 | try stream.print("{s}(", .{@tagName(extended.opcode)}); |
| 456 | 457 | switch (extended.opcode) { |
| 457 | .ret_ptr, | |
| 458 | .ret_type, | |
| 459 | 458 | .this, |
| 460 | 459 | .ret_addr, |
| 461 | 460 | .error_return_trace, |
| 462 | 461 | .frame, |
| 463 | 462 | .frame_address, |
| 463 | .breakpoint, | |
| 464 | 464 | => try self.writeExtNode(stream, extended), |
| 465 | 465 | |
| 466 | 466 | .builtin_src => { |
| ... | ... | @@ -469,12 +469,7 @@ const Writer = struct { |
| 469 | 469 | try stream.print(":{d}:{d}", .{ inst_data.line + 1, inst_data.column + 1 }); |
| 470 | 470 | }, |
| 471 | 471 | |
| 472 | .dbg_block_begin, | |
| 473 | .dbg_block_end, | |
| 474 | => try stream.writeAll("))"), | |
| 475 | ||
| 476 | 472 | .@"asm" => try self.writeAsm(stream, extended), |
| 477 | .func => try self.writeFuncExtended(stream, extended), | |
| 478 | 473 | .variable => try self.writeVarExtended(stream, extended), |
| 479 | 474 | .alloc => try self.writeAllocExtended(stream, extended), |
| 480 | 475 | |
| ... | ... | @@ -492,7 +487,14 @@ const Writer = struct { |
| 492 | 487 | .enum_decl => try self.writeEnumDecl(stream, extended), |
| 493 | 488 | .opaque_decl => try self.writeOpaqueDecl(stream, extended), |
| 494 | 489 | |
| 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 | 498 | const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 497 | 499 | const src: LazySrcLoc = .{ .node_offset = inst_data.node }; |
| 498 | 500 | try self.writeInstRef(stream, inst_data.operand); |
| ... | ... | @@ -500,7 +502,12 @@ const Writer = struct { |
| 500 | 502 | try self.writeSrc(stream, src); |
| 501 | 503 | }, |
| 502 | 504 | |
| 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 | 511 | const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 505 | 512 | const src: LazySrcLoc = .{ .node_offset = inst_data.node }; |
| 506 | 513 | try self.writeInstRef(stream, inst_data.lhs); |
| ... | ... | @@ -1913,24 +1920,24 @@ const Writer = struct { |
| 1913 | 1920 | ); |
| 1914 | 1921 | } |
| 1915 | 1922 | |
| 1916 | fn writeFuncExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { | |
| 1917 | const extra = self.code.extraData(Zir.Inst.ExtendedFunc, extended.operand); | |
| 1918 | const src: LazySrcLoc = .{ .node_offset = extra.data.src_node }; | |
| 1919 | const small = @bitCast(Zir.Inst.ExtendedFunc.Small, extended.small); | |
| 1923 | fn writeFuncExtended(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | |
| 1924 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; | |
| 1925 | const extra = self.code.extraData(Zir.Inst.ExtendedFunc, inst_data.payload_index); | |
| 1926 | const src = inst_data.src(); | |
| 1920 | 1927 | |
| 1921 | 1928 | var extra_index: usize = extra.end; |
| 1922 | if (small.has_lib_name) { | |
| 1929 | if (extra.data.bits.has_lib_name) { | |
| 1923 | 1930 | const lib_name = self.code.nullTerminatedString(self.code.extra[extra_index]); |
| 1924 | 1931 | extra_index += 1; |
| 1925 | 1932 | try stream.print("lib_name=\"{}\", ", .{std.zig.fmtEscapes(lib_name)}); |
| 1926 | 1933 | } |
| 1927 | try self.writeFlag(stream, "test, ", small.is_test); | |
| 1928 | const cc: Zir.Inst.Ref = if (!small.has_cc) .none else blk: { | |
| 1934 | try self.writeFlag(stream, "test, ", extra.data.bits.is_test); | |
| 1935 | const cc: Zir.Inst.Ref = if (!extra.data.bits.has_cc) .none else blk: { | |
| 1929 | 1936 | const cc = @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index]); |
| 1930 | 1937 | extra_index += 1; |
| 1931 | 1938 | break :blk cc; |
| 1932 | 1939 | }; |
| 1933 | const align_inst: Zir.Inst.Ref = if (!small.has_align) .none else blk: { | |
| 1940 | const align_inst: Zir.Inst.Ref = if (!extra.data.bits.has_align) .none else blk: { | |
| 1934 | 1941 | const align_inst = @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index]); |
| 1935 | 1942 | extra_index += 1; |
| 1936 | 1943 | break :blk align_inst; |
| ... | ... | @@ -1949,9 +1956,9 @@ const Writer = struct { |
| 1949 | 1956 | return self.writeFuncCommon( |
| 1950 | 1957 | stream, |
| 1951 | 1958 | ret_ty_body, |
| 1952 | small.is_inferred_error, | |
| 1953 | small.is_var_args, | |
| 1954 | small.is_extern, | |
| 1959 | extra.data.bits.is_inferred_error, | |
| 1960 | extra.data.bits.is_var_args, | |
| 1961 | extra.data.bits.is_extern, | |
| 1955 | 1962 | cc, |
| 1956 | 1963 | align_inst, |
| 1957 | 1964 | body, |
| ... | ... | @@ -2091,8 +2098,6 @@ const Writer = struct { |
| 2091 | 2098 | |
| 2092 | 2099 | fn writeUnreachable(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| 2093 | 2100 | const inst_data = self.code.instructions.items(.data)[inst].@"unreachable"; |
| 2094 | const safety_str = if (inst_data.safety) "safe" else "unsafe"; | |
| 2095 | try stream.print("{s}) ", .{safety_str}); | |
| 2096 | 2101 | try self.writeSrc(stream, inst_data.src()); |
| 2097 | 2102 | } |
| 2098 | 2103 |
test/compile_errors/stage2/comptime_unreachable.zig created+7| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | pub export fn entry() void { | |
| 2 | comptime unreachable; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // | |
| 7 | // :2:14: error: reached unreachable code |
test/incremental/x86_64-linux/comptime_var.3.zig+1-1| ... | ... | @@ -7,4 +7,4 @@ pub fn main() void {} |
| 7 | 7 | |
| 8 | 8 | // error |
| 9 | 9 | // |
| 10 | // :4:17: error: unable to resolve comptime value | |
| 10 | // :4:17: error: reached unreachable code |
test/incremental/x86_64-macos/comptime_var.3.zig+1-1| ... | ... | @@ -7,4 +7,4 @@ pub fn main() void {} |
| 7 | 7 | |
| 8 | 8 | // error |
| 9 | 9 | // |
| 10 | // :4:17: error: unable to resolve comptime value | |
| 10 | // :4:17: error: reached unreachable code |