authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-07 14:52:28-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-07-07 14:52:28-04:00
log0c78ece1c95164f4a321f5705b20896415336d02
treedff294a61dc2c004b358f49062c551892a426770
parent6f17be063d37f5ecd9552479e65428a5c60d9152
parent5007f727e5a2631ce55e9b44f93e69a9cb82cde8
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #12016 from Vexu/stage2-compile-errors

Stage2 compile error improvements

92 files changed, 930 insertions(+), 744 deletions(-)

src/AstGen.zig+37-11
...@@ -812,7 +812,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr...@@ -812,7 +812,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr
812812
813 .deref => {813 .deref => {
814 const lhs = try expr(gz, scope, .none, node_datas[node].lhs);814 const lhs = try expr(gz, scope, .none, node_datas[node].lhs);
815 _ = try gz.addUnTok(.validate_deref, lhs, main_tokens[node]);815 _ = try gz.addUnNode(.validate_deref, lhs, node);
816 switch (rl) {816 switch (rl) {
817 .ref => return lhs,817 .ref => return lhs,
818 else => {818 else => {
...@@ -1320,7 +1320,10 @@ fn arrayInitExpr(...@@ -1320,7 +1320,10 @@ fn arrayInitExpr(
1320 const len_inst = try gz.addInt(array_init.ast.elements.len);1320 const len_inst = try gz.addInt(array_init.ast.elements.len);
1321 const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type);1321 const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type);
1322 if (array_type.ast.sentinel == 0) {1322 if (array_type.ast.sentinel == 0) {
1323 const array_type_inst = try gz.addBin(.array_type, len_inst, elem_type);1323 const array_type_inst = try gz.addPlNode(.array_type, array_init.ast.type_expr, Zir.Inst.Bin{
1324 .lhs = len_inst,
1325 .rhs = elem_type,
1326 });
1324 break :inst .{1327 break :inst .{
1325 .array = array_type_inst,1328 .array = array_type_inst,
1326 .elem = elem_type,1329 .elem = elem_type,
...@@ -1553,7 +1556,10 @@ fn structInitExpr(...@@ -1553,7 +1556,10 @@ fn structInitExpr(
1553 if (is_inferred_array_len) {1556 if (is_inferred_array_len) {
1554 const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type);1557 const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type);
1555 const array_type_inst = if (array_type.ast.sentinel == 0) blk: {1558 const array_type_inst = if (array_type.ast.sentinel == 0) blk: {
1556 break :blk try gz.addBin(.array_type, .zero_usize, elem_type);1559 break :blk try gz.addPlNode(.array_type, struct_init.ast.type_expr, Zir.Inst.Bin{
1560 .lhs = .zero_usize,
1561 .rhs = elem_type,
1562 });
1557 } else blk: {1563 } else blk: {
1558 const sentinel = try comptimeExpr(gz, scope, .{ .ty = elem_type }, array_type.ast.sentinel);1564 const sentinel = try comptimeExpr(gz, scope, .{ .ty = elem_type }, array_type.ast.sentinel);
1559 break :blk try gz.addPlNode(1565 break :blk try gz.addPlNode(
...@@ -2332,8 +2338,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner...@@ -2332,8 +2338,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2332 .error_union_type,2338 .error_union_type,
2333 .bit_not,2339 .bit_not,
2334 .error_value,2340 .error_value,
2335 .error_to_int,
2336 .int_to_error,
2337 .slice_start,2341 .slice_start,
2338 .slice_end,2342 .slice_end,
2339 .slice_sentinel,2343 .slice_sentinel,
...@@ -2420,7 +2424,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner...@@ -2420,7 +2424,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2420 .splat,2424 .splat,
2421 .reduce,2425 .reduce,
2422 .shuffle,2426 .shuffle,
2423 .select,
2424 .atomic_load,2427 .atomic_load,
2425 .atomic_rmw,2428 .atomic_rmw,
2426 .mul_add,2429 .mul_add,
...@@ -2467,6 +2470,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner...@@ -2467,6 +2470,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
2467 .repeat,2470 .repeat,
2468 .repeat_inline,2471 .repeat_inline,
2469 .panic,2472 .panic,
2473 .panic_comptime,
2470 => {2474 => {
2471 noreturn_src_node = statement;2475 noreturn_src_node = statement;
2472 break :b true;2476 break :b true;
...@@ -3100,6 +3104,10 @@ fn ptrType(...@@ -3100,6 +3104,10 @@ fn ptrType(
3100 node: Ast.Node.Index,3104 node: Ast.Node.Index,
3101 ptr_info: Ast.full.PtrType,3105 ptr_info: Ast.full.PtrType,
3102) InnerError!Zir.Inst.Ref {3106) InnerError!Zir.Inst.Ref {
3107 if (ptr_info.size == .C and ptr_info.allowzero_token != null) {
3108 return gz.astgen.failTok(ptr_info.allowzero_token.?, "C pointers always allow address zero", .{});
3109 }
3110
3103 const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type);3111 const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type);
31043112
3105 const simple = ptr_info.ast.align_node == 0 and3113 const simple = ptr_info.ast.align_node == 0 and
...@@ -3205,7 +3213,10 @@ fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) !Z...@@ -3205,7 +3213,10 @@ fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) !Z
3205 const len = try expr(gz, scope, .{ .coerced_ty = .usize_type }, len_node);3213 const len = try expr(gz, scope, .{ .coerced_ty = .usize_type }, len_node);
3206 const elem_type = try typeExpr(gz, scope, node_datas[node].rhs);3214 const elem_type = try typeExpr(gz, scope, node_datas[node].rhs);
32073215
3208 const result = try gz.addBin(.array_type, len, elem_type);3216 const result = try gz.addPlNode(.array_type, node, Zir.Inst.Bin{
3217 .lhs = len,
3218 .rhs = elem_type,
3219 });
3209 return rvalue(gz, rl, result, node);3220 return rvalue(gz, rl, result, node);
3210}3221}
32113222
...@@ -7359,15 +7370,13 @@ fn builtinCall(...@@ -7359,15 +7370,13 @@ fn builtinCall(
7359 .align_of => return simpleUnOpType(gz, scope, rl, node, params[0], .align_of),7370 .align_of => return simpleUnOpType(gz, scope, rl, node, params[0], .align_of),
73607371
7361 .ptr_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .ptr_to_int),7372 .ptr_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .ptr_to_int),
7362 .error_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .error_to_int),
7363 .int_to_error => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .u16_type }, params[0], .int_to_error),
7364 .compile_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .compile_error),7373 .compile_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .compile_error),
7365 .set_eval_branch_quota => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .u32_type }, params[0], .set_eval_branch_quota),7374 .set_eval_branch_quota => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .u32_type }, params[0], .set_eval_branch_quota),
7366 .enum_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .enum_to_int),7375 .enum_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .enum_to_int),
7367 .bool_to_int => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .bool_to_int),7376 .bool_to_int => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .bool_to_int),
7368 .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file),7377 .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file),
7369 .error_name => return simpleUnOp(gz, scope, rl, node, .{ .ty = .anyerror_type }, params[0], .error_name),7378 .error_name => return simpleUnOp(gz, scope, rl, node, .{ .ty = .anyerror_type }, params[0], .error_name),
7370 .panic => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .panic),7379 .panic => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], if (gz.force_comptime) .panic_comptime else .panic),
7371 .set_cold => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_cold),7380 .set_cold => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_cold),
7372 .set_runtime_safety => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_runtime_safety),7381 .set_runtime_safety => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_runtime_safety),
7373 .sqrt => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sqrt),7382 .sqrt => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sqrt),
...@@ -7400,6 +7409,22 @@ fn builtinCall(...@@ -7400,6 +7409,22 @@ fn builtinCall(
7400 .truncate => return typeCast(gz, scope, rl, node, params[0], params[1], .truncate),7409 .truncate => return typeCast(gz, scope, rl, node, params[0], params[1], .truncate),
7401 // zig fmt: on7410 // zig fmt: on
74027411
7412 .error_to_int => {
7413 const operand = try expr(gz, scope, .none, params[0]);
7414 const result = try gz.addExtendedPayload(.error_to_int, Zir.Inst.UnNode{
7415 .node = gz.nodeIndexToRelative(node),
7416 .operand = operand,
7417 });
7418 return rvalue(gz, rl, result, node);
7419 },
7420 .int_to_error => {
7421 const operand = try expr(gz, scope, .{ .coerced_ty = .u16_type }, params[0]);
7422 const result = try gz.addExtendedPayload(.int_to_error, Zir.Inst.UnNode{
7423 .node = gz.nodeIndexToRelative(node),
7424 .operand = operand,
7425 });
7426 return rvalue(gz, rl, result, node);
7427 },
7403 .align_cast => {7428 .align_cast => {
7404 const dest_align = try comptimeExpr(gz, scope, align_rl, params[0]);7429 const dest_align = try comptimeExpr(gz, scope, align_rl, params[0]);
7405 const rhs = try expr(gz, scope, .none, params[1]);7430 const rhs = try expr(gz, scope, .none, params[1]);
...@@ -7639,7 +7664,8 @@ fn builtinCall(...@@ -7639,7 +7664,8 @@ fn builtinCall(
7639 return rvalue(gz, rl, result, node);7664 return rvalue(gz, rl, result, node);
7640 },7665 },
7641 .select => {7666 .select => {
7642 const result = try gz.addPlNode(.select, node, Zir.Inst.Select{7667 const result = try gz.addExtendedPayload(.select, Zir.Inst.Select{
7668 .node = gz.nodeIndexToRelative(node),
7643 .elem_type = try typeExpr(gz, scope, params[0]),7669 .elem_type = try typeExpr(gz, scope, params[0]),
7644 .pred = try expr(gz, scope, .none, params[1]),7670 .pred = try expr(gz, scope, .none, params[1]),
7645 .a = try expr(gz, scope, .none, params[2]),7671 .a = try expr(gz, scope, .none, params[2]),
src/Module.zig+49-2
...@@ -2171,7 +2171,11 @@ pub const SrcLoc = struct {...@@ -2171,7 +2171,11 @@ pub const SrcLoc = struct {
2171 const token_starts = tree.tokens.items(.start);2171 const token_starts = tree.tokens.items(.start);
2172 return token_starts[tok_index];2172 return token_starts[tok_index];
2173 },2173 },
2174 .node_offset_slice_sentinel => |node_off| {2174 .node_offset_slice_ptr,
2175 .node_offset_slice_start,
2176 .node_offset_slice_end,
2177 .node_offset_slice_sentinel,
2178 => |node_off| {
2175 const tree = try src_loc.file_scope.getTree(gpa);2179 const tree = try src_loc.file_scope.getTree(gpa);
2176 const node_tags = tree.nodes.items(.tag);2180 const node_tags = tree.nodes.items(.tag);
2177 const node = src_loc.declRelativeToNodeIndex(node_off);2181 const node = src_loc.declRelativeToNodeIndex(node_off);
...@@ -2182,7 +2186,15 @@ pub const SrcLoc = struct {...@@ -2182,7 +2186,15 @@ pub const SrcLoc = struct {
2182 else => unreachable,2186 else => unreachable,
2183 };2187 };
2184 const main_tokens = tree.nodes.items(.main_token);2188 const main_tokens = tree.nodes.items(.main_token);
2185 const tok_index = main_tokens[full.ast.sentinel];2189 const tok_index = main_tokens[
2190 switch (src_loc.lazy) {
2191 .node_offset_slice_ptr => full.ast.sliced,
2192 .node_offset_slice_start => full.ast.start,
2193 .node_offset_slice_end => full.ast.end,
2194 .node_offset_slice_sentinel => full.ast.sentinel,
2195 else => unreachable,
2196 }
2197 ];
2186 const token_starts = tree.tokens.items(.start);2198 const token_starts = tree.tokens.items(.start);
2187 return token_starts[tok_index];2199 return token_starts[tok_index];
2188 },2200 },
...@@ -2501,6 +2513,16 @@ pub const SrcLoc = struct {...@@ -2501,6 +2513,16 @@ pub const SrcLoc = struct {
2501 const token_starts = tree.tokens.items(.start);2513 const token_starts = tree.tokens.items(.start);
2502 return token_starts[tok_index];2514 return token_starts[tok_index];
2503 },2515 },
2516 .node_offset_un_op => |node_off| {
2517 const tree = try src_loc.file_scope.getTree(gpa);
2518 const node_datas = tree.nodes.items(.data);
2519 const node = src_loc.declRelativeToNodeIndex(node_off);
2520
2521 const main_tokens = tree.nodes.items(.main_token);
2522 const tok_index = main_tokens[node_datas[node].lhs];
2523 const token_starts = tree.tokens.items(.start);
2524 return token_starts[tok_index];
2525 },
2504 }2526 }
2505 }2527 }
25062528
...@@ -2614,6 +2636,24 @@ pub const LazySrcLoc = union(enum) {...@@ -2614,6 +2636,24 @@ pub const LazySrcLoc = union(enum) {
2614 /// to the index expression.2636 /// to the index expression.
2615 /// The Decl is determined contextually.2637 /// The Decl is determined contextually.
2616 node_offset_array_access_index: i32,2638 node_offset_array_access_index: i32,
2639 /// The source location points to the LHS of a slice expression
2640 /// expression, found by taking this AST node index offset from the containing
2641 /// Decl AST node, which points to a slice AST node. Next, navigate
2642 /// to the sentinel expression.
2643 /// The Decl is determined contextually.
2644 node_offset_slice_ptr: i32,
2645 /// The source location points to start expression of a slice expression
2646 /// expression, found by taking this AST node index offset from the containing
2647 /// Decl AST node, which points to a slice AST node. Next, navigate
2648 /// to the sentinel expression.
2649 /// The Decl is determined contextually.
2650 node_offset_slice_start: i32,
2651 /// The source location points to the end expression of a slice
2652 /// expression, found by taking this AST node index offset from the containing
2653 /// Decl AST node, which points to a slice AST node. Next, navigate
2654 /// to the sentinel expression.
2655 /// The Decl is determined contextually.
2656 node_offset_slice_end: i32,
2617 /// The source location points to the sentinel expression of a slice2657 /// The source location points to the sentinel expression of a slice
2618 /// expression, found by taking this AST node index offset from the containing2658 /// expression, found by taking this AST node index offset from the containing
2619 /// Decl AST node, which points to a slice AST node. Next, navigate2659 /// Decl AST node, which points to a slice AST node. Next, navigate
...@@ -2728,6 +2768,9 @@ pub const LazySrcLoc = union(enum) {...@@ -2728,6 +2768,9 @@ pub const LazySrcLoc = union(enum) {
2728 /// to the elem expression.2768 /// to the elem expression.
2729 /// The Decl is determined contextually.2769 /// The Decl is determined contextually.
2730 node_offset_array_type_elem: i32,2770 node_offset_array_type_elem: i32,
2771 /// The source location points to the operand of an unary expression.
2772 /// The Decl is determined contextually.
2773 node_offset_un_op: i32,
27312774
2732 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;2775 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;
27332776
...@@ -2768,6 +2811,9 @@ pub const LazySrcLoc = union(enum) {...@@ -2768,6 +2811,9 @@ pub const LazySrcLoc = union(enum) {
2768 .node_offset_builtin_call_arg4,2811 .node_offset_builtin_call_arg4,
2769 .node_offset_builtin_call_arg5,2812 .node_offset_builtin_call_arg5,
2770 .node_offset_array_access_index,2813 .node_offset_array_access_index,
2814 .node_offset_slice_ptr,
2815 .node_offset_slice_start,
2816 .node_offset_slice_end,
2771 .node_offset_slice_sentinel,2817 .node_offset_slice_sentinel,
2772 .node_offset_call_func,2818 .node_offset_call_func,
2773 .node_offset_field_name,2819 .node_offset_field_name,
...@@ -2788,6 +2834,7 @@ pub const LazySrcLoc = union(enum) {...@@ -2788,6 +2834,7 @@ pub const LazySrcLoc = union(enum) {
2788 .node_offset_array_type_len,2834 .node_offset_array_type_len,
2789 .node_offset_array_type_sentinel,2835 .node_offset_array_type_sentinel,
2790 .node_offset_array_type_elem,2836 .node_offset_array_type_elem,
2837 .node_offset_un_op,
2791 => .{2838 => .{
2792 .file_scope = decl.getFileScope(),2839 .file_scope = decl.getFileScope(),
2793 .parent_decl_node = decl.src_node,2840 .parent_decl_node = decl.src_node,
src/Sema.zig+189-115
...@@ -739,8 +739,6 @@ fn analyzeBodyInner(...@@ -739,8 +739,6 @@ fn analyzeBodyInner(
739 .err_union_payload_unsafe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, false),739 .err_union_payload_unsafe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, false),
740 .error_union_type => try sema.zirErrorUnionType(block, inst),740 .error_union_type => try sema.zirErrorUnionType(block, inst),
741 .error_value => try sema.zirErrorValue(block, inst),741 .error_value => try sema.zirErrorValue(block, inst),
742 .error_to_int => try sema.zirErrorToInt(block, inst),
743 .int_to_error => try sema.zirIntToError(block, inst),
744 .field_ptr => try sema.zirFieldPtr(block, inst),742 .field_ptr => try sema.zirFieldPtr(block, inst),
745 .field_ptr_named => try sema.zirFieldPtrNamed(block, inst),743 .field_ptr_named => try sema.zirFieldPtrNamed(block, inst),
746 .field_val => try sema.zirFieldVal(block, inst),744 .field_val => try sema.zirFieldVal(block, inst),
...@@ -835,7 +833,6 @@ fn analyzeBodyInner(...@@ -835,7 +833,6 @@ fn analyzeBodyInner(
835 .splat => try sema.zirSplat(block, inst),833 .splat => try sema.zirSplat(block, inst),
836 .reduce => try sema.zirReduce(block, inst),834 .reduce => try sema.zirReduce(block, inst),
837 .shuffle => try sema.zirShuffle(block, inst),835 .shuffle => try sema.zirShuffle(block, inst),
838 .select => try sema.zirSelect(block, inst),
839 .atomic_load => try sema.zirAtomicLoad(block, inst),836 .atomic_load => try sema.zirAtomicLoad(block, inst),
840 .atomic_rmw => try sema.zirAtomicRmw(block, inst),837 .atomic_rmw => try sema.zirAtomicRmw(block, inst),
841 .mul_add => try sema.zirMulAdd(block, inst),838 .mul_add => try sema.zirMulAdd(block, inst),
...@@ -906,7 +903,8 @@ fn analyzeBodyInner(...@@ -906,7 +903,8 @@ fn analyzeBodyInner(
906 .ret_load => break sema.zirRetLoad(block, inst),903 .ret_load => break sema.zirRetLoad(block, inst),
907 .ret_err_value => break sema.zirRetErrValue(block, inst),904 .ret_err_value => break sema.zirRetErrValue(block, inst),
908 .@"unreachable" => break sema.zirUnreachable(block, inst),905 .@"unreachable" => break sema.zirUnreachable(block, inst),
909 .panic => break sema.zirPanic(block, inst),906 .panic => break sema.zirPanic(block, inst, false),
907 .panic_comptime => break sema.zirPanic(block, inst, true),
910 // zig fmt: on908 // zig fmt: on
911909
912 .extended => ext: {910 .extended => ext: {
...@@ -942,6 +940,9 @@ fn analyzeBodyInner(...@@ -942,6 +940,9 @@ fn analyzeBodyInner(
942 .field_call_bind_named => try sema.zirFieldCallBindNamed(block, extended),940 .field_call_bind_named => try sema.zirFieldCallBindNamed(block, extended),
943 .err_set_cast => try sema.zirErrSetCast( block, extended),941 .err_set_cast => try sema.zirErrSetCast( block, extended),
944 .await_nosuspend => try sema.zirAwaitNosuspend( block, extended),942 .await_nosuspend => try sema.zirAwaitNosuspend( block, extended),
943 .select => try sema.zirSelect( block, extended),
944 .error_to_int => try sema.zirErrorToInt( block, extended),
945 .int_to_error => try sema.zirIntToError( block, extended),
945 // zig fmt: on946 // zig fmt: on
946 .fence => {947 .fence => {
947 try sema.zirFence(block, extended);948 try sema.zirFence(block, extended);
...@@ -1685,7 +1686,9 @@ fn resolveMaybeUndefValAllowVariables(...@@ -1685,7 +1686,9 @@ fn resolveMaybeUndefValAllowVariables(
1685 switch (air_tags[i]) {1686 switch (air_tags[i]) {
1686 .constant => {1687 .constant => {
1687 const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;1688 const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
1688 return sema.air_values.items[ty_pl.payload];1689 const val = sema.air_values.items[ty_pl.payload];
1690 if (val.tag() == .runtime_int) return null;
1691 return val;
1689 },1692 },
1690 .const_ty => {1693 .const_ty => {
1691 return try sema.air_instructions.items(.data)[i].ty.toValue(sema.arena);1694 return try sema.air_instructions.items(.data)[i].ty.toValue(sema.arena);
...@@ -1717,9 +1720,17 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, opt...@@ -1717,9 +1720,17 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, opt
1717}1720}
17181721
1719fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {1722fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
1720 return sema.fail(block, src, "type '{}' does not support array initialization syntax", .{1723 const msg = msg: {
1721 ty.fmt(sema.mod),1724 const msg = try sema.errMsg(block, src, "type '{}' does not support array initialization syntax", .{
1722 });1725 ty.fmt(sema.mod),
1726 });
1727 errdefer msg.destroy(sema.gpa);
1728 if (ty.isSlice()) {
1729 try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2().fmt(sema.mod)});
1730 }
1731 break :msg msg;
1732 };
1733 return sema.failWithOwnedErrorMsg(block, msg);
1723}1734}
17241735
1725fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {1736fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
...@@ -2804,7 +2815,7 @@ fn zirAllocExtended(...@@ -2804,7 +2815,7 @@ fn zirAllocExtended(
2804) CompileError!Air.Inst.Ref {2815) CompileError!Air.Inst.Ref {
2805 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);2816 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
2806 const src = LazySrcLoc.nodeOffset(extra.data.src_node);2817 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
2807 const ty_src = src; // TODO better source location2818 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };
2808 const align_src = src; // TODO better source location2819 const align_src = src; // TODO better source location
2809 const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small);2820 const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small);
28102821
...@@ -3856,9 +3867,9 @@ fn zirValidateArrayInit(...@@ -3856,9 +3867,9 @@ fn zirValidateArrayInit(
3856}3867}
38573868
3858fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {3869fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
3859 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;3870 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3860 const src = inst_data.src();3871 const src = inst_data.src();
3861 const operand_src: LazySrcLoc = .{ .token_offset = inst_data.src_tok + 1 };3872 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
3862 const operand = try sema.resolveInst(inst_data.operand);3873 const operand = try sema.resolveInst(inst_data.operand);
3863 const operand_ty = sema.typeOf(operand);3874 const operand_ty = sema.typeOf(operand);
38643875
...@@ -3870,10 +3881,26 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -3870,10 +3881,26 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
3870 .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(sema.mod)}),3881 .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(sema.mod)}),
3871 }3882 }
38723883
3884 const elem_ty = operand_ty.elemType2();
3873 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {3885 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
3874 if (val.isUndef()) {3886 if (val.isUndef()) {
3875 return sema.fail(block, src, "cannot dereference undefined value", .{});3887 return sema.fail(block, src, "cannot dereference undefined value", .{});
3876 }3888 }
3889 } else if (!(try sema.validateRunTimeType(block, src, elem_ty, false))) {
3890 const msg = msg: {
3891 const msg = try sema.errMsg(
3892 block,
3893 src,
3894 "values of type '{}' must be comptime known, but operand value is runtime known",
3895 .{elem_ty.fmt(sema.mod)},
3896 );
3897 errdefer msg.destroy(sema.gpa);
3898
3899 const src_decl = sema.mod.declPtr(block.src_decl);
3900 try sema.explainWhyTypeIsComptime(block, src, msg, src.toSrcLoc(src_decl), elem_ty);
3901 break :msg msg;
3902 };
3903 return sema.failWithOwnedErrorMsg(block, msg);
3877 }3904 }
3878}3905}
38793906
...@@ -4308,11 +4335,15 @@ fn zirCompileLog(...@@ -4308,11 +4335,15 @@ fn zirCompileLog(
4308 return Air.Inst.Ref.void_value;4335 return Air.Inst.Ref.void_value;
4309}4336}
43104337
4311fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {4338fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index, force_comptime: bool) CompileError!Zir.Inst.Index {
4312 const inst_data = sema.code.instructions.items(.data)[inst].un_node;4339 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
4313 const src: LazySrcLoc = inst_data.src();4340 const src = inst_data.src();
4314 const msg_inst = try sema.resolveInst(inst_data.operand);4341 const msg_inst = try sema.resolveInst(inst_data.operand);
43154342
4343 if (block.is_comptime or force_comptime) {
4344 return sema.fail(block, src, "encountered @panic at comptime", .{});
4345 }
4346 try sema.requireRuntimeBlock(block, src);
4316 return sema.panicWithMsg(block, src, msg_inst);4347 return sema.panicWithMsg(block, src, msg_inst);
4317}4348}
43184349
...@@ -4796,14 +4827,16 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst...@@ -4796,14 +4827,16 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
4796 alignment,4827 alignment,
4797 });4828 });
4798 }4829 }
4799 const func = sema.owner_func orelse4830 const func = sema.func orelse
4800 return sema.fail(block, src, "@setAlignStack outside function body", .{});4831 return sema.fail(block, src, "@setAlignStack outside function body", .{});
48014832
4802 const fn_owner_decl = sema.mod.declPtr(func.owner_decl);4833 const fn_owner_decl = sema.mod.declPtr(func.owner_decl);
4803 switch (fn_owner_decl.ty.fnCallingConvention()) {4834 switch (fn_owner_decl.ty.fnCallingConvention()) {
4804 .Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}),4835 .Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}),
4805 .Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}),4836 .Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}),
4806 else => {},4837 else => if (block.inlining != null) {
4838 return sema.fail(block, src, "@setAlignStack in inline call", .{});
4839 },
4807 }4840 }
48084841
4809 const gop = try sema.mod.align_stack_fns.getOrPut(sema.mod.gpa, func);4842 const gop = try sema.mod.align_stack_fns.getOrPut(sema.mod.gpa, func);
...@@ -6161,11 +6194,12 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -6161,11 +6194,12 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
6161 const tracy = trace(@src());6194 const tracy = trace(@src());
6162 defer tracy.end();6195 defer tracy.end();
61636196
6164 const bin_inst = sema.code.instructions.items(.data)[inst].bin;6197 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
6165 const len_src = sema.src; // TODO better source location6198 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
6166 const elem_src = sema.src; // TODO better source location6199 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
6167 const len = try sema.resolveInt(block, len_src, bin_inst.lhs, Type.usize);6200 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };
6168 const elem_type = try sema.resolveType(block, elem_src, bin_inst.rhs);6201 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize);
6202 const elem_type = try sema.resolveType(block, elem_src, extra.rhs);
6169 const array_ty = try Type.array(sema.arena, len, null, elem_type, sema.mod);6203 const array_ty = try Type.array(sema.arena, len, null, elem_type, sema.mod);
61706204
6171 return sema.addType(array_ty);6205 return sema.addType(array_ty);
...@@ -6240,18 +6274,18 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -6240,18 +6274,18 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
6240 );6274 );
6241}6275}
62426276
6243fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6277fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
6244 const tracy = trace(@src());6278 const tracy = trace(@src());
6245 defer tracy.end();6279 defer tracy.end();
62466280
6247 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6281 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6248 const src = inst_data.src();6282 const src = LazySrcLoc.nodeOffset(extra.node);
6249 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6283 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6250 const op = try sema.resolveInst(inst_data.operand);6284 const uncasted_operand = try sema.resolveInst(extra.operand);
6251 const op_coerced = try sema.coerce(block, Type.anyerror, op, operand_src);6285 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);
6252 const result_ty = Type.u16;6286 const result_ty = Type.u16;
62536287
6254 if (try sema.resolveMaybeUndefVal(block, src, op_coerced)) |val| {6288 if (try sema.resolveMaybeUndefVal(block, src, operand)) |val| {
6255 if (val.isUndef()) {6289 if (val.isUndef()) {
6256 return sema.addConstUndef(result_ty);6290 return sema.addConstUndef(result_ty);
6257 }6291 }
...@@ -6273,7 +6307,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -6273,7 +6307,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
6273 }6307 }
6274 }6308 }
62756309
6276 const op_ty = sema.typeOf(op);6310 const op_ty = sema.typeOf(uncasted_operand);
6277 try sema.resolveInferredErrorSetTy(block, src, op_ty);6311 try sema.resolveInferredErrorSetTy(block, src, op_ty);
6278 if (!op_ty.isAnyError()) {6312 if (!op_ty.isAnyError()) {
6279 const names = op_ty.errorSetNames();6313 const names = op_ty.errorSetNames();
...@@ -6285,17 +6319,17 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -6285,17 +6319,17 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
6285 }6319 }
62866320
6287 try sema.requireRuntimeBlock(block, src);6321 try sema.requireRuntimeBlock(block, src);
6288 return block.addBitCast(result_ty, op_coerced);6322 return block.addBitCast(result_ty, operand);
6289}6323}
62906324
6291fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6325fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
6292 const tracy = trace(@src());6326 const tracy = trace(@src());
6293 defer tracy.end();6327 defer tracy.end();
62946328
6295 const inst_data = sema.code.instructions.items(.data)[inst].un_node;6329 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6296 const src = inst_data.src();6330 const src = LazySrcLoc.nodeOffset(extra.node);
6297 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6331 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6298 const uncasted_operand = try sema.resolveInst(inst_data.operand);6332 const uncasted_operand = try sema.resolveInst(extra.operand);
6299 const operand = try sema.coerce(block, Type.u16, uncasted_operand, operand_src);6333 const operand = try sema.coerce(block, Type.u16, uncasted_operand, operand_src);
6300 const target = sema.mod.getTarget();6334 const target = sema.mod.getTarget();
63016335
...@@ -7432,6 +7466,9 @@ fn analyzeAs(...@@ -7432,6 +7466,9 @@ fn analyzeAs(
7432 const dest_ty = try sema.resolveType(block, src, zir_dest_type);7466 const dest_ty = try sema.resolveType(block, src, zir_dest_type);
7433 const operand = try sema.resolveInst(zir_operand);7467 const operand = try sema.resolveInst(zir_operand);
7434 if (dest_ty.tag() == .var_args_param) return operand;7468 if (dest_ty.tag() == .var_args_param) return operand;
7469 if (dest_ty.zigTypeTag() == .NoReturn) {
7470 return sema.fail(block, src, "cannot cast to noreturn", .{});
7471 }
7435 return sema.coerce(block, dest_ty, operand, src);7472 return sema.coerce(block, dest_ty, operand, src);
7436}7473}
74377474
...@@ -8099,9 +8136,11 @@ fn zirSwitchCond(...@@ -8099,9 +8136,11 @@ fn zirSwitchCond(
8099 const union_ty = try sema.resolveTypeFields(block, operand_src, operand_ty);8136 const union_ty = try sema.resolveTypeFields(block, operand_src, operand_ty);
8100 const enum_ty = union_ty.unionTagType() orelse {8137 const enum_ty = union_ty.unionTagType() orelse {
8101 const msg = msg: {8138 const msg = msg: {
8102 const msg = try sema.errMsg(block, src, "switch on untagged union", .{});8139 const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{});
8103 errdefer msg.destroy(sema.gpa);8140 errdefer msg.destroy(sema.gpa);
8104 try sema.addDeclaredHereNote(msg, union_ty);8141 if (union_ty.declSrcLocOrNull(sema.mod)) |union_src| {
8142 try sema.mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{});
8143 }
8105 break :msg msg;8144 break :msg msg;
8106 };8145 };
8107 return sema.failWithOwnedErrorMsg(block, msg);8146 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -8357,7 +8396,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8357,7 +8396,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8357 return sema.fail(8396 return sema.fail(
8358 block,8397 block,
8359 src,8398 src,
8360 "switch must handle all possibilities",8399 "else prong required when switching on type 'anyerror'",
8361 .{},8400 .{},
8362 );8401 );
8363 }8402 }
...@@ -8592,7 +8631,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8592,7 +8631,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8592 if (true_count + false_count == 2) {8631 if (true_count + false_count == 2) {
8593 return sema.fail(8632 return sema.fail(
8594 block,8633 block,
8595 src,8634 special_prong_src,
8596 "unreachable else prong; all cases already handled",8635 "unreachable else prong; all cases already handled",
8597 .{},8636 .{},
8598 );8637 );
...@@ -9720,7 +9759,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -9720,7 +9759,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
97209759
9721 const inst_data = sema.code.instructions.items(.data)[inst].un_node;9760 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
9722 const src = inst_data.src();9761 const src = inst_data.src();
9723 const operand_src = src; // TODO put this on the operand, not the '~'9762 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
97249763
9725 const operand = try sema.resolveInst(inst_data.operand);9764 const operand = try sema.resolveInst(inst_data.operand);
9726 const operand_type = sema.typeOf(operand);9765 const operand_type = sema.typeOf(operand);
...@@ -10219,7 +10258,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -10219,7 +10258,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
10219 const inst_data = sema.code.instructions.items(.data)[inst].un_node;10258 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
10220 const src = inst_data.src();10259 const src = inst_data.src();
10221 const lhs_src = src;10260 const lhs_src = src;
10222 const rhs_src = src; // TODO better source location10261 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
1022310262
10224 const rhs = try sema.resolveInst(inst_data.operand);10263 const rhs = try sema.resolveInst(inst_data.operand);
10225 const rhs_ty = sema.typeOf(rhs);10264 const rhs_ty = sema.typeOf(rhs);
...@@ -10255,7 +10294,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10255,7 +10294,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10255 const inst_data = sema.code.instructions.items(.data)[inst].un_node;10294 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
10256 const src = inst_data.src();10295 const src = inst_data.src();
10257 const lhs_src = src;10296 const lhs_src = src;
10258 const rhs_src = src; // TODO better source location10297 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
1025910298
10260 const rhs = try sema.resolveInst(inst_data.operand);10299 const rhs = try sema.resolveInst(inst_data.operand);
10261 const rhs_ty = sema.typeOf(rhs);10300 const rhs_ty = sema.typeOf(rhs);
...@@ -10532,18 +10571,17 @@ fn analyzeArithmetic(...@@ -10532,18 +10571,17 @@ fn analyzeArithmetic(
10532 if (lhs_zig_ty_tag == .Pointer) switch (lhs_ty.ptrSize()) {10571 if (lhs_zig_ty_tag == .Pointer) switch (lhs_ty.ptrSize()) {
10533 .One, .Slice => {},10572 .One, .Slice => {},
10534 .Many, .C => {10573 .Many, .C => {
10535 const op_src = src; // TODO better source location
10536 const air_tag: Air.Inst.Tag = switch (zir_tag) {10574 const air_tag: Air.Inst.Tag = switch (zir_tag) {
10537 .add => .ptr_add,10575 .add => .ptr_add,
10538 .sub => .ptr_sub,10576 .sub => .ptr_sub,
10539 else => return sema.fail(10577 else => return sema.fail(
10540 block,10578 block,
10541 op_src,10579 src,
10542 "invalid pointer arithmetic operand: '{s}''",10580 "invalid pointer arithmetic operand: '{s}''",
10543 .{@tagName(zir_tag)},10581 .{@tagName(zir_tag)},
10544 ),10582 ),
10545 };10583 };
10546 return analyzePtrArithmetic(sema, block, op_src, lhs, rhs, air_tag, lhs_src, rhs_src);10584 return analyzePtrArithmetic(sema, block, src, lhs, rhs, air_tag, lhs_src, rhs_src);
10547 },10585 },
10548 };10586 };
1054910587
...@@ -11941,7 +11979,6 @@ fn runtimeBoolCmp(...@@ -11941,7 +11979,6 @@ fn runtimeBoolCmp(
1194111979
11942fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {11980fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
11943 const inst_data = sema.code.instructions.items(.data)[inst].un_node;11981 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
11944 const src = inst_data.src();
11945 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };11982 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
11946 const ty = try sema.resolveType(block, operand_src, inst_data.operand);11983 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
11947 switch (ty.zigTypeTag()) {11984 switch (ty.zigTypeTag()) {
...@@ -11951,7 +11988,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -11951,7 +11988,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
11951 .Null,11988 .Null,
11952 .BoundFn,11989 .BoundFn,
11953 .Opaque,11990 .Opaque,
11954 => return sema.fail(block, src, "no size available for type '{}'", .{ty.fmt(sema.mod)}),11991 => return sema.fail(block, operand_src, "no size available for type '{}'", .{ty.fmt(sema.mod)}),
1195511992
11956 .Type,11993 .Type,
11957 .EnumLiteral,11994 .EnumLiteral,
...@@ -12077,7 +12114,7 @@ fn zirBuiltinSrc(...@@ -12077,7 +12114,7 @@ fn zirBuiltinSrc(
12077 const tracy = trace(@src());12114 const tracy = trace(@src());
12078 defer tracy.end();12115 defer tracy.end();
1207912116
12080 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));12117 const src = sema.src; // TODO better source location
12081 const extra = sema.code.extraData(Zir.Inst.LineColumn, extended.operand).data;12118 const extra = sema.code.extraData(Zir.Inst.LineColumn, extended.operand).data;
12082 const func = sema.func orelse return sema.fail(block, src, "@src outside function", .{});12119 const func = sema.func orelse return sema.fail(block, src, "@src outside function", .{});
12083 const fn_owner_decl = sema.mod.declPtr(func.owner_decl);12120 const fn_owner_decl = sema.mod.declPtr(func.owner_decl);
...@@ -12116,9 +12153,8 @@ fn zirBuiltinSrc(...@@ -12116,9 +12153,8 @@ fn zirBuiltinSrc(
12116 field_values[0] = file_name_val;12153 field_values[0] = file_name_val;
12117 // fn_name: [:0]const u8,12154 // fn_name: [:0]const u8,
12118 field_values[1] = func_name_val;12155 field_values[1] = func_name_val;
12119 // TODO these should be runtime only!
12120 // line: u3212156 // line: u32
12121 field_values[2] = try Value.Tag.int_u64.create(sema.arena, extra.line + 1);12157 field_values[2] = try Value.Tag.runtime_int.create(sema.arena, extra.line + 1);
12122 // column: u32,12158 // column: u32,
12123 field_values[3] = try Value.Tag.int_u64.create(sema.arena, extra.column + 1);12159 field_values[3] = try Value.Tag.int_u64.create(sema.arena, extra.column + 1);
1212412160
...@@ -13123,7 +13159,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13123,7 +13159,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1312313159
13124 const inst_data = sema.code.instructions.items(.data)[inst].un_node;13160 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
13125 const src = inst_data.src();13161 const src = inst_data.src();
13126 const operand_src = src; // TODO put this on the operand, not the `!`13162 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
13127 const uncasted_operand = try sema.resolveInst(inst_data.operand);13163 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1312813164
13129 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);13165 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
...@@ -13667,7 +13703,8 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -13667,7 +13703,8 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
13667 defer tracy.end();13703 defer tracy.end();
1366813704
13669 const inst_data = sema.code.instructions.items(.data)[inst].ptr_type_simple;13705 const inst_data = sema.code.instructions.items(.data)[inst].ptr_type_simple;
13670 const elem_type = try sema.resolveType(block, .unneeded, inst_data.elem_type);13706 const elem_ty_src = sema.src; // TODO better source location
13707 const elem_type = try sema.resolveType(block, elem_ty_src, inst_data.elem_type);
13671 const ty = try Type.ptr(sema.arena, sema.mod, .{13708 const ty = try Type.ptr(sema.arena, sema.mod, .{
13672 .pointee_type = elem_type,13709 .pointee_type = elem_type,
13673 .@"addrspace" = .generic,13710 .@"addrspace" = .generic,
...@@ -13676,6 +13713,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -13676,6 +13713,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
13676 .@"volatile" = inst_data.is_volatile,13713 .@"volatile" = inst_data.is_volatile,
13677 .size = inst_data.size,13714 .size = inst_data.size,
13678 });13715 });
13716 try sema.validatePtrTy(block, elem_ty_src, ty);
13679 return sema.addType(ty);13717 return sema.addType(ty);
13680}13718}
1368113719
...@@ -13683,9 +13721,12 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13683,9 +13721,12 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13683 const tracy = trace(@src());13721 const tracy = trace(@src());
13684 defer tracy.end();13722 defer tracy.end();
1368513723
13686 // TODO better source location13724 const src: LazySrcLoc = sema.src; // TODO better source location
13687 const src: LazySrcLoc = sema.src;13725 const elem_ty_src: LazySrcLoc = sema.src; // TODO better source location
13688 const elem_ty_src: LazySrcLoc = .unneeded;13726 const sentinel_src: LazySrcLoc = sema.src; // TODO better source location
13727 const addrspace_src: LazySrcLoc = sema.src; // TODO better source location
13728 const bitoffset_src: LazySrcLoc = sema.src; // TODO better source location
13729 const hostsize_src: LazySrcLoc = sema.src; // TODO better source location
13689 const inst_data = sema.code.instructions.items(.data)[inst].ptr_type;13730 const inst_data = sema.code.instructions.items(.data)[inst].ptr_type;
13690 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);13731 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);
13691 const unresolved_elem_ty = try sema.resolveType(block, elem_ty_src, extra.data.elem_type);13732 const unresolved_elem_ty = try sema.resolveType(block, elem_ty_src, extra.data.elem_type);
...@@ -13696,7 +13737,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13696,7 +13737,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13696 const sentinel = if (inst_data.flags.has_sentinel) blk: {13737 const sentinel = if (inst_data.flags.has_sentinel) blk: {
13697 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);13738 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
13698 extra_i += 1;13739 extra_i += 1;
13699 break :blk (try sema.resolveInstConst(block, .unneeded, ref)).val;13740 break :blk (try sema.resolveInstConst(block, sentinel_src, ref)).val;
13700 } else null;13741 } else null;
1370113742
13702 const abi_align: u32 = if (inst_data.flags.has_align) blk: {13743 const abi_align: u32 = if (inst_data.flags.has_align) blk: {
...@@ -13718,20 +13759,20 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13718,20 +13759,20 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13718 const address_space = if (inst_data.flags.has_addrspace) blk: {13759 const address_space = if (inst_data.flags.has_addrspace) blk: {
13719 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);13760 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
13720 extra_i += 1;13761 extra_i += 1;
13721 break :blk try sema.analyzeAddrspace(block, .unneeded, ref, .pointer);13762 break :blk try sema.analyzeAddrspace(block, addrspace_src, ref, .pointer);
13722 } else .generic;13763 } else .generic;
1372313764
13724 const bit_offset = if (inst_data.flags.has_bit_range) blk: {13765 const bit_offset = if (inst_data.flags.has_bit_range) blk: {
13725 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);13766 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
13726 extra_i += 1;13767 extra_i += 1;
13727 const bit_offset = try sema.resolveInt(block, .unneeded, ref, Type.u16);13768 const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16);
13728 break :blk @intCast(u16, bit_offset);13769 break :blk @intCast(u16, bit_offset);
13729 } else 0;13770 } else 0;
1373013771
13731 const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {13772 const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {
13732 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);13773 const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]);
13733 extra_i += 1;13774 extra_i += 1;
13734 const host_size = try sema.resolveInt(block, .unneeded, ref, Type.u16);13775 const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16);
13735 break :blk @intCast(u16, host_size);13776 break :blk @intCast(u16, host_size);
13736 } else 0;13777 } else 0;
1373713778
...@@ -13758,9 +13799,25 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13758,9 +13799,25 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13758 .@"volatile" = inst_data.flags.is_volatile,13799 .@"volatile" = inst_data.flags.is_volatile,
13759 .size = inst_data.size,13800 .size = inst_data.size,
13760 });13801 });
13802 try sema.validatePtrTy(block, elem_ty_src, ty);
13761 return sema.addType(ty);13803 return sema.addType(ty);
13762}13804}
1376313805
13806fn validatePtrTy(sema: *Sema, block: *Block, elem_src: LazySrcLoc, ty: Type) CompileError!void {
13807 const ptr_info = ty.ptrInfo().data;
13808 const pointee_tag = ptr_info.pointee_type.zigTypeTag();
13809 if (pointee_tag == .NoReturn) {
13810 return sema.fail(block, elem_src, "pointer to noreturn not allowed", .{});
13811 } else if (ptr_info.size == .Many and pointee_tag == .Opaque) {
13812 return sema.fail(block, elem_src, "unknown-length pointer to opaque not allowed", .{});
13813 } else if (ptr_info.size == .C) {
13814 // TODO check extern type
13815 if (pointee_tag == .Opaque) {
13816 return sema.fail(block, elem_src, "C pointers cannot point to opaque types", .{});
13817 }
13818 }
13819}
13820
13764fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {13821fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
13765 const tracy = trace(@src());13822 const tracy = trace(@src());
13766 defer tracy.end();13823 defer tracy.end();
...@@ -14559,14 +14616,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -14559,14 +14616,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
14559 },14616 },
14560 .Enum => operand_ty,14617 .Enum => operand_ty,
14561 .Union => operand_ty.unionTagType() orelse {14618 .Union => operand_ty.unionTagType() orelse {
14562 const decl_index = operand_ty.getOwnerDecl();
14563 const decl = mod.declPtr(decl_index);
14564 const msg = msg: {14619 const msg = msg: {
14565 const msg = try sema.errMsg(block, src, "union '{s}' is untagged", .{14620 const msg = try sema.errMsg(block, src, "union '{}' is untagged", .{
14566 decl.name,14621 operand_ty.fmt(sema.mod),
14567 });14622 });
14568 errdefer msg.destroy(sema.gpa);14623 errdefer msg.destroy(sema.gpa);
14569 try mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{});14624 try sema.addDeclaredHereNote(msg, operand_ty);
14570 break :msg msg;14625 break :msg msg;
14571 };14626 };
14572 return sema.failWithOwnedErrorMsg(block, msg);14627 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -16703,14 +16758,13 @@ fn analyzeShuffle(...@@ -16703,14 +16758,13 @@ fn analyzeShuffle(
16703 });16758 });
16704}16759}
1670516760
16706fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {16761fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
16707 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;16762 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;
16708 const extra = sema.code.extraData(Zir.Inst.Select, inst_data.payload_index).data;
1670916763
16710 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };16764 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
16711 const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };16765 const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
16712 const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };16766 const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };
16713 const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };16767 const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node };
1671416768
16715 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);16769 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
16716 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);16770 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
...@@ -17417,7 +17471,7 @@ fn zirVarExtended(...@@ -17417,7 +17471,7 @@ fn zirVarExtended(
17417 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);17471 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
17418 const src = sema.src;17472 const src = sema.src;
17419 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type17473 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type
17420 const mut_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at mut token17474 const name_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at the name token
17421 const init_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at init expr17475 const init_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at init expr
17422 const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small);17476 const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small);
1742317477
...@@ -17461,7 +17515,7 @@ fn zirVarExtended(...@@ -17461,7 +17515,7 @@ fn zirVarExtended(
17461 return sema.failWithNeededComptime(block, init_src);17515 return sema.failWithNeededComptime(block, init_src);
17462 } else Value.initTag(.unreachable_value);17516 } else Value.initTag(.unreachable_value);
1746317517
17464 try sema.validateVarType(block, mut_src, var_ty, small.is_extern);17518 try sema.validateVarType(block, name_src, var_ty, small.is_extern);
1746517519
17466 const new_var = try sema.gpa.create(Module.Var);17520 const new_var = try sema.gpa.create(Module.Var);
17467 errdefer sema.gpa.destroy(new_var);17521 errdefer sema.gpa.destroy(new_var);
...@@ -17958,6 +18012,9 @@ fn validateVarType(...@@ -17958,6 +18012,9 @@ fn validateVarType(
1795818012
17959 const src_decl = mod.declPtr(block.src_decl);18013 const src_decl = mod.declPtr(block.src_decl);
17960 try sema.explainWhyTypeIsComptime(block, src, msg, src.toSrcLoc(src_decl), var_ty);18014 try sema.explainWhyTypeIsComptime(block, src, msg, src.toSrcLoc(src_decl), var_ty);
18015 if (var_ty.zigTypeTag() == .ComptimeInt or var_ty.zigTypeTag() == .ComptimeFloat) {
18016 try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
18017 }
1796118018
17962 break :msg msg;18019 break :msg msg;
17963 };18020 };
...@@ -19445,6 +19502,34 @@ fn elemVal(...@@ -19445,6 +19502,34 @@ fn elemVal(
19445 }19502 }
19446}19503}
1944719504
19505fn validateRuntimeElemAccess(
19506 sema: *Sema,
19507 block: *Block,
19508 elem_index_src: LazySrcLoc,
19509 elem_ty: Type,
19510 parent_ty: Type,
19511 parent_src: LazySrcLoc,
19512) CompileError!void {
19513 const valid_rt = try sema.validateRunTimeType(block, elem_index_src, elem_ty, false);
19514 if (!valid_rt) {
19515 const msg = msg: {
19516 const msg = try sema.errMsg(
19517 block,
19518 elem_index_src,
19519 "values of type '{}' must be comptime known, but index value is runtime known",
19520 .{parent_ty.fmt(sema.mod)},
19521 );
19522 errdefer msg.destroy(sema.gpa);
19523
19524 const src_decl = sema.mod.declPtr(block.src_decl);
19525 try sema.explainWhyTypeIsComptime(block, elem_index_src, msg, parent_src.toSrcLoc(src_decl), parent_ty);
19526
19527 break :msg msg;
19528 };
19529 return sema.failWithOwnedErrorMsg(block, msg);
19530 }
19531}
19532
19448fn tupleFieldPtr(19533fn tupleFieldPtr(
19449 sema: *Sema,19534 sema: *Sema,
19450 block: *Block,19535 block: *Block,
...@@ -19485,6 +19570,8 @@ fn tupleFieldPtr(...@@ -19485,6 +19570,8 @@ fn tupleFieldPtr(
19485 );19570 );
19486 }19571 }
1948719572
19573 try sema.validateRuntimeElemAccess(block, field_index_src, field_ty, tuple_ty, tuple_ptr_src);
19574
19488 try sema.requireRuntimeBlock(block, tuple_ptr_src);19575 try sema.requireRuntimeBlock(block, tuple_ptr_src);
19489 return block.addStructFieldPtr(tuple_ptr, field_index, ptr_field_ty);19576 return block.addStructFieldPtr(tuple_ptr, field_index, ptr_field_ty);
19490}19577}
...@@ -19523,6 +19610,8 @@ fn tupleField(...@@ -19523,6 +19610,8 @@ fn tupleField(
19523 return sema.addConstant(field_ty, field_values[field_index]);19610 return sema.addConstant(field_ty, field_values[field_index]);
19524 }19611 }
1952519612
19613 try sema.validateRuntimeElemAccess(block, field_index_src, field_ty, tuple_ty, tuple_src);
19614
19526 try sema.requireRuntimeBlock(block, tuple_src);19615 try sema.requireRuntimeBlock(block, tuple_src);
19527 return block.addStructFieldVal(tuple, field_index, field_ty);19616 return block.addStructFieldVal(tuple, field_index, field_ty);
19528}19617}
...@@ -19573,24 +19662,7 @@ fn elemValArray(...@@ -19573,24 +19662,7 @@ fn elemValArray(
19573 }19662 }
19574 }19663 }
1957519664
19576 const valid_rt = try sema.validateRunTimeType(block, elem_index_src, elem_ty, false);19665 try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ty, array_ty, array_src);
19577 if (!valid_rt) {
19578 const msg = msg: {
19579 const msg = try sema.errMsg(
19580 block,
19581 elem_index_src,
19582 "values of type '{}' must be comptime known, but index value is runtime known",
19583 .{array_ty.fmt(sema.mod)},
19584 );
19585 errdefer msg.destroy(sema.gpa);
19586
19587 const src_decl = sema.mod.declPtr(block.src_decl);
19588 try sema.explainWhyTypeIsComptime(block, elem_index_src, msg, array_src.toSrcLoc(src_decl), array_ty);
19589
19590 break :msg msg;
19591 };
19592 return sema.failWithOwnedErrorMsg(block, msg);
19593 }
1959419666
19595 const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src;19667 const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src;
19596 try sema.requireRuntimeBlock(block, runtime_src);19668 try sema.requireRuntimeBlock(block, runtime_src);
...@@ -19648,23 +19720,8 @@ fn elemPtrArray(...@@ -19648,23 +19720,8 @@ fn elemPtrArray(
19648 }19720 }
19649 }19721 }
1965019722
19651 const valid_rt = try sema.validateRunTimeType(block, elem_index_src, array_ty.elemType2(), false);19723 if (!init) {
19652 if (!valid_rt and !init) {19724 try sema.validateRuntimeElemAccess(block, elem_index_src, array_ty.elemType2(), array_ty, array_ptr_src);
19653 const msg = msg: {
19654 const msg = try sema.errMsg(
19655 block,
19656 elem_index_src,
19657 "values of type '{}' must be comptime known, but index value is runtime known",
19658 .{array_ty.fmt(sema.mod)},
19659 );
19660 errdefer msg.destroy(sema.gpa);
19661
19662 const src_decl = sema.mod.declPtr(block.src_decl);
19663 try sema.explainWhyTypeIsComptime(block, elem_index_src, msg, array_ptr_src.toSrcLoc(src_decl), array_ty);
19664
19665 break :msg msg;
19666 };
19667 return sema.failWithOwnedErrorMsg(block, msg);
19668 }19725 }
1966919726
19670 const runtime_src = if (maybe_undef_array_ptr_val != null) elem_index_src else array_ptr_src;19727 const runtime_src = if (maybe_undef_array_ptr_val != null) elem_index_src else array_ptr_src;
...@@ -19720,6 +19777,8 @@ fn elemValSlice(...@@ -19720,6 +19777,8 @@ fn elemValSlice(
19720 }19777 }
19721 }19778 }
1972219779
19780 try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ty, slice_ty, slice_src);
19781
19723 try sema.requireRuntimeBlock(block, runtime_src);19782 try sema.requireRuntimeBlock(block, runtime_src);
19724 if (block.wantSafety()) {19783 if (block.wantSafety()) {
19725 const len_inst = if (maybe_slice_val) |slice_val|19784 const len_inst = if (maybe_slice_val) |slice_val|
...@@ -19773,6 +19832,8 @@ fn elemPtrSlice(...@@ -19773,6 +19832,8 @@ fn elemPtrSlice(
19773 }19832 }
19774 }19833 }
1977519834
19835 try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ptr_ty, slice_ty, slice_src);
19836
19776 const runtime_src = if (maybe_undef_slice_val != null) elem_index_src else slice_src;19837 const runtime_src = if (maybe_undef_slice_val != null) elem_index_src else slice_src;
19777 try sema.requireRuntimeBlock(block, runtime_src);19838 try sema.requireRuntimeBlock(block, runtime_src);
19778 if (block.wantSafety()) {19839 if (block.wantSafety()) {
...@@ -20042,6 +20103,15 @@ fn coerce(...@@ -20042,6 +20103,15 @@ fn coerce(
20042 });20103 });
20043 return sema.addConstant(dest_ty, slice_val);20104 return sema.addConstant(dest_ty, slice_val);
20044 }20105 }
20106
20107 if (inst_ty.zigTypeTag() == .Array) {
20108 return sema.fail(
20109 block,
20110 inst_src,
20111 "array literal requires address-of operator (&) to coerce to slice type '{}'",
20112 .{dest_ty.fmt(sema.mod)},
20113 );
20114 }
20045 },20115 },
20046 .Many => p: {20116 .Many => p: {
20047 if (!inst_ty.isSlice()) break :p;20117 if (!inst_ty.isSlice()) break :p;
...@@ -22368,7 +22438,7 @@ fn analyzeLoad(...@@ -22368,7 +22438,7 @@ fn analyzeLoad(
22368 }22438 }
2236922439
22370 if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| {22440 if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| {
22371 if (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) |elem_val| {22441 if (try sema.pointerDeref(block, src, ptr_val, ptr_ty)) |elem_val| {
22372 return sema.addConstant(elem_ty, elem_val);22442 return sema.addConstant(elem_ty, elem_val);
22373 }22443 }
22374 if (block.is_typeof) {22444 if (block.is_typeof) {
...@@ -22543,9 +22613,9 @@ fn analyzeSlice(...@@ -22543,9 +22613,9 @@ fn analyzeSlice(
22543 sentinel_opt: Air.Inst.Ref,22613 sentinel_opt: Air.Inst.Ref,
22544 sentinel_src: LazySrcLoc,22614 sentinel_src: LazySrcLoc,
22545) CompileError!Air.Inst.Ref {22615) CompileError!Air.Inst.Ref {
22546 const ptr_src = src; // TODO better source location22616 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = src.node_offset.x };
22547 const start_src = src; // TODO better source location22617 const start_src: LazySrcLoc = .{ .node_offset_slice_start = src.node_offset.x };
22548 const end_src = src; // TODO better source location22618 const end_src: LazySrcLoc = .{ .node_offset_slice_end = src.node_offset.x };
22549 // Slice expressions can operate on a variable whose type is an array. This requires22619 // Slice expressions can operate on a variable whose type is an array. This requires
22550 // the slice operand to be a pointer. In the case of a non-array, it will be a double pointer.22620 // the slice operand to be a pointer. In the case of a non-array, it will be a double pointer.
22551 const ptr_ptr_ty = sema.typeOf(ptr_ptr);22621 const ptr_ptr_ty = sema.typeOf(ptr_ptr);
...@@ -22575,7 +22645,7 @@ fn analyzeSlice(...@@ -22575,7 +22645,7 @@ fn analyzeSlice(
22575 array_ty = double_child_ty;22645 array_ty = double_child_ty;
22576 elem_ty = double_child_ty.childType();22646 elem_ty = double_child_ty.childType();
22577 } else {22647 } else {
22578 return sema.fail(block, ptr_src, "slice of single-item pointer", .{});22648 return sema.fail(block, src, "slice of single-item pointer", .{});
22579 }22649 }
22580 },22650 },
22581 .Many, .C => {22651 .Many, .C => {
...@@ -22588,7 +22658,7 @@ fn analyzeSlice(...@@ -22588,7 +22658,7 @@ fn analyzeSlice(
22588 if (ptr_ptr_child_ty.ptrSize() == .C) {22658 if (ptr_ptr_child_ty.ptrSize() == .C) {
22589 if (try sema.resolveDefinedValue(block, ptr_src, ptr_or_slice)) |ptr_val| {22659 if (try sema.resolveDefinedValue(block, ptr_src, ptr_or_slice)) |ptr_val| {
22590 if (ptr_val.isNull()) {22660 if (ptr_val.isNull()) {
22591 return sema.fail(block, ptr_src, "slice of null pointer", .{});22661 return sema.fail(block, src, "slice of null pointer", .{});
22592 }22662 }
22593 }22663 }
22594 }22664 }
...@@ -22601,7 +22671,7 @@ fn analyzeSlice(...@@ -22601,7 +22671,7 @@ fn analyzeSlice(
22601 elem_ty = ptr_ptr_child_ty.childType();22671 elem_ty = ptr_ptr_child_ty.childType();
22602 },22672 },
22603 },22673 },
22604 else => return sema.fail(block, ptr_src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(mod)}),22674 else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(mod)}),
22605 }22675 }
2260622676
22607 const ptr = if (slice_ty.isSlice())22677 const ptr = if (slice_ty.isSlice())
...@@ -22774,7 +22844,7 @@ fn analyzeSlice(...@@ -22774,7 +22844,7 @@ fn analyzeSlice(
22774 return sema.addConstUndef(return_ty);22844 return sema.addConstUndef(return_ty);
22775 }22845 }
2277622846
22777 return sema.fail(block, ptr_src, "non-zero length slice of undefined pointer", .{});22847 return sema.fail(block, src, "non-zero length slice of undefined pointer", .{});
22778 }22848 }
2277922849
22780 const return_ty = try Type.ptr(sema.arena, mod, .{22850 const return_ty = try Type.ptr(sema.arena, mod, .{
...@@ -24434,6 +24504,10 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil...@@ -24434,6 +24504,10 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil
24434 } else {24504 } else {
24435 // The provided type is the enum tag type.24505 // The provided type is the enum tag type.
24436 union_obj.tag_ty = try provided_ty.copy(decl_arena_allocator);24506 union_obj.tag_ty = try provided_ty.copy(decl_arena_allocator);
24507 if (union_obj.tag_ty.zigTypeTag() != .Enum) {
24508 const tag_ty_src = src; // TODO better source location
24509 return sema.fail(block, tag_ty_src, "expected enum tag type, found '{}'", .{union_obj.tag_ty.fmt(sema.mod)});
24510 }
24437 // The fields of the union must match the enum exactly.24511 // The fields of the union must match the enum exactly.
24438 // Store a copy of the enum field names so we can check for24512 // Store a copy of the enum field names so we can check for
24439 // missing or extraneous fields later.24513 // missing or extraneous fields later.
src/TypedValue.zig+1
...@@ -495,5 +495,6 @@ pub fn print(...@@ -495,5 +495,6 @@ pub fn print(
495 },495 },
496 .generic_poison_type => return writer.writeAll("(generic poison type)"),496 .generic_poison_type => return writer.writeAll("(generic poison type)"),
497 .generic_poison => return writer.writeAll("(generic poison)"),497 .generic_poison => return writer.writeAll("(generic poison)"),
498 .runtime_int => return writer.writeAll("[runtime value]"),
498 };499 };
499}500}
src/Zir.zig+21-22
...@@ -212,7 +212,7 @@ pub const Inst = struct {...@@ -212,7 +212,7 @@ pub const Inst = struct {
212 /// Uses the `pl_node` union field. Payload is `Bin`.212 /// Uses the `pl_node` union field. Payload is `Bin`.
213 array_mul,213 array_mul,
214 /// `[N]T` syntax. No source location provided.214 /// `[N]T` syntax. No source location provided.
215 /// Uses the `bin` union field. lhs is length, rhs is element type.215 /// Uses the `pl_node` union field. Payload is `Bin`. lhs is length, rhs is element type.
216 array_type,216 array_type,
217 /// `[N:S]T` syntax. Source location is the array type expression node.217 /// `[N:S]T` syntax. Source location is the array type expression node.
218 /// Uses the `pl_node` union field. Payload is `ArrayTypeSentinel`.218 /// Uses the `pl_node` union field. Payload is `ArrayTypeSentinel`.
...@@ -244,7 +244,7 @@ pub const Inst = struct {...@@ -244,7 +244,7 @@ pub const Inst = struct {
244 /// Uses the pl_node field with payload `Bin`.244 /// Uses the pl_node field with payload `Bin`.
245 bitcast,245 bitcast,
246 /// Bitwise NOT. `~`246 /// Bitwise NOT. `~`
247 /// Uses `un_node`.247 /// Uses `un_tok`.
248 bit_not,248 bit_not,
249 /// Bitwise OR. `|`249 /// Bitwise OR. `|`
250 bit_or,250 bit_or,
...@@ -260,7 +260,7 @@ pub const Inst = struct {...@@ -260,7 +260,7 @@ pub const Inst = struct {
260 /// Uses the `pl_node` union field. Payload is `Block`.260 /// Uses the `pl_node` union field. Payload is `Block`.
261 suspend_block,261 suspend_block,
262 /// Boolean NOT. See also `bit_not`.262 /// Boolean NOT. See also `bit_not`.
263 /// Uses the `un_node` field.263 /// Uses the `un_tok` field.
264 bool_not,264 bool_not,
265 /// Short-circuiting boolean `and`. `lhs` is a boolean `Ref` and the other operand265 /// Short-circuiting boolean `and`. `lhs` is a boolean `Ref` and the other operand
266 /// is a block, which is evaluated if `lhs` is `true`.266 /// is a block, which is evaluated if `lhs` is `true`.
...@@ -729,7 +729,7 @@ pub const Inst = struct {...@@ -729,7 +729,7 @@ pub const Inst = struct {
729 /// resulting array initialization value is within a comptime scope.729 /// resulting array initialization value is within a comptime scope.
730 validate_array_init_comptime,730 validate_array_init_comptime,
731 /// Check that operand type supports the dereference operand (.*).731 /// Check that operand type supports the dereference operand (.*).
732 /// Uses the `un_tok` field.732 /// Uses the `un_node` field.
733 validate_deref,733 validate_deref,
734 /// A struct literal with a specified type, with no fields.734 /// A struct literal with a specified type, with no fields.
735 /// Uses the `un_node` field.735 /// Uses the `un_node` field.
...@@ -778,10 +778,6 @@ pub const Inst = struct {...@@ -778,10 +778,6 @@ pub const Inst = struct {
778 /// Implement builtin `@ptrToInt`. Uses `un_node`.778 /// Implement builtin `@ptrToInt`. Uses `un_node`.
779 /// Convert a pointer to a `usize` integer.779 /// Convert a pointer to a `usize` integer.
780 ptr_to_int,780 ptr_to_int,
781 /// Implement builtin `@errToInt`. Uses `un_node`.
782 error_to_int,
783 /// Implement builtin `@intToError`. Uses `un_node`.
784 int_to_error,
785 /// Emit an error message and fail compilation.781 /// Emit an error message and fail compilation.
786 /// Uses the `un_node` field.782 /// Uses the `un_node` field.
787 compile_error,783 compile_error,
...@@ -802,6 +798,8 @@ pub const Inst = struct {...@@ -802,6 +798,8 @@ pub const Inst = struct {
802 error_name,798 error_name,
803 /// Implement builtin `@panic`. Uses `un_node`.799 /// Implement builtin `@panic`. Uses `un_node`.
804 panic,800 panic,
801 /// Same as `panic` but forces comptime.
802 panic_comptime,
805 /// Implement builtin `@setCold`. Uses `un_node`.803 /// Implement builtin `@setCold`. Uses `un_node`.
806 set_cold,804 set_cold,
807 /// Implement builtin `@setRuntimeSafety`. Uses `un_node`.805 /// Implement builtin `@setRuntimeSafety`. Uses `un_node`.
...@@ -916,9 +914,6 @@ pub const Inst = struct {...@@ -916,9 +914,6 @@ pub const Inst = struct {
916 /// Implements the `@shuffle` builtin.914 /// Implements the `@shuffle` builtin.
917 /// Uses the `pl_node` union field with payload `Shuffle`.915 /// Uses the `pl_node` union field with payload `Shuffle`.
918 shuffle,916 shuffle,
919 /// Implements the `@select` builtin.
920 /// Uses the `pl_node` union field with payload `Select`.
921 select,
922 /// Implements the `@atomicLoad` builtin.917 /// Implements the `@atomicLoad` builtin.
923 /// Uses the `pl_node` union field with payload `AtomicLoad`.918 /// Uses the `pl_node` union field with payload `AtomicLoad`.
924 atomic_load,919 atomic_load,
...@@ -1125,8 +1120,6 @@ pub const Inst = struct {...@@ -1125,8 +1120,6 @@ pub const Inst = struct {
1125 .err_union_payload_unsafe_ptr,1120 .err_union_payload_unsafe_ptr,
1126 .err_union_code,1121 .err_union_code,
1127 .err_union_code_ptr,1122 .err_union_code_ptr,
1128 .error_to_int,
1129 .int_to_error,
1130 .ptr_type,1123 .ptr_type,
1131 .ptr_type_simple,1124 .ptr_type_simple,
1132 .ensure_err_payload_void,1125 .ensure_err_payload_void,
...@@ -1230,7 +1223,6 @@ pub const Inst = struct {...@@ -1230,7 +1223,6 @@ pub const Inst = struct {
1230 .splat,1223 .splat,
1231 .reduce,1224 .reduce,
1232 .shuffle,1225 .shuffle,
1233 .select,
1234 .atomic_load,1226 .atomic_load,
1235 .atomic_rmw,1227 .atomic_rmw,
1236 .atomic_store,1228 .atomic_store,
...@@ -1270,6 +1262,7 @@ pub const Inst = struct {...@@ -1270,6 +1262,7 @@ pub const Inst = struct {
1270 .repeat,1262 .repeat,
1271 .repeat_inline,1263 .repeat_inline,
1272 .panic,1264 .panic,
1265 .panic_comptime,
1273 => true,1266 => true,
1274 };1267 };
1275 }1268 }
...@@ -1423,8 +1416,6 @@ pub const Inst = struct {...@@ -1423,8 +1416,6 @@ pub const Inst = struct {
1423 .err_union_payload_unsafe_ptr,1416 .err_union_payload_unsafe_ptr,
1424 .err_union_code,1417 .err_union_code,
1425 .err_union_code_ptr,1418 .err_union_code_ptr,
1426 .error_to_int,
1427 .int_to_error,
1428 .ptr_type,1419 .ptr_type,
1429 .ptr_type_simple,1420 .ptr_type_simple,
1430 .enum_literal,1421 .enum_literal,
...@@ -1516,7 +1507,6 @@ pub const Inst = struct {...@@ -1516,7 +1507,6 @@ pub const Inst = struct {
1516 .splat,1507 .splat,
1517 .reduce,1508 .reduce,
1518 .shuffle,1509 .shuffle,
1519 .select,
1520 .atomic_load,1510 .atomic_load,
1521 .atomic_rmw,1511 .atomic_rmw,
1522 .mul_add,1512 .mul_add,
...@@ -1546,6 +1536,7 @@ pub const Inst = struct {...@@ -1546,6 +1536,7 @@ pub const Inst = struct {
1546 .repeat,1536 .repeat,
1547 .repeat_inline,1537 .repeat_inline,
1548 .panic,1538 .panic,
1539 .panic_comptime,
1549 .@"try",1540 .@"try",
1550 .try_ptr,1541 .try_ptr,
1551 //.try_inline,1542 //.try_inline,
...@@ -1580,7 +1571,7 @@ pub const Inst = struct {...@@ -1580,7 +1571,7 @@ pub const Inst = struct {
1580 .param_anytype_comptime = .str_tok,1571 .param_anytype_comptime = .str_tok,
1581 .array_cat = .pl_node,1572 .array_cat = .pl_node,
1582 .array_mul = .pl_node,1573 .array_mul = .pl_node,
1583 .array_type = .bin,1574 .array_type = .pl_node,
1584 .array_type_sentinel = .pl_node,1575 .array_type_sentinel = .pl_node,
1585 .vector_type = .pl_node,1576 .vector_type = .pl_node,
1586 .elem_type_index = .bin,1577 .elem_type_index = .bin,
...@@ -1713,7 +1704,7 @@ pub const Inst = struct {...@@ -1713,7 +1704,7 @@ pub const Inst = struct {
1713 .validate_struct_init_comptime = .pl_node,1704 .validate_struct_init_comptime = .pl_node,
1714 .validate_array_init = .pl_node,1705 .validate_array_init = .pl_node,
1715 .validate_array_init_comptime = .pl_node,1706 .validate_array_init_comptime = .pl_node,
1716 .validate_deref = .un_tok,1707 .validate_deref = .un_node,
1717 .struct_init_empty = .un_node,1708 .struct_init_empty = .un_node,
1718 .field_type = .pl_node,1709 .field_type = .pl_node,
1719 .field_type_ref = .pl_node,1710 .field_type_ref = .pl_node,
...@@ -1731,8 +1722,6 @@ pub const Inst = struct {...@@ -1731,8 +1722,6 @@ pub const Inst = struct {
1731 .bit_size_of = .un_node,1722 .bit_size_of = .un_node,
17321723
1733 .ptr_to_int = .un_node,1724 .ptr_to_int = .un_node,
1734 .error_to_int = .un_node,
1735 .int_to_error = .un_node,
1736 .compile_error = .un_node,1725 .compile_error = .un_node,
1737 .set_eval_branch_quota = .un_node,1726 .set_eval_branch_quota = .un_node,
1738 .enum_to_int = .un_node,1727 .enum_to_int = .un_node,
...@@ -1741,6 +1730,7 @@ pub const Inst = struct {...@@ -1741,6 +1730,7 @@ pub const Inst = struct {
1741 .embed_file = .un_node,1730 .embed_file = .un_node,
1742 .error_name = .un_node,1731 .error_name = .un_node,
1743 .panic = .un_node,1732 .panic = .un_node,
1733 .panic_comptime = .un_node,
1744 .set_cold = .un_node,1734 .set_cold = .un_node,
1745 .set_runtime_safety = .un_node,1735 .set_runtime_safety = .un_node,
1746 .sqrt = .un_node,1736 .sqrt = .un_node,
...@@ -1802,7 +1792,6 @@ pub const Inst = struct {...@@ -1802,7 +1792,6 @@ pub const Inst = struct {
1802 .splat = .pl_node,1792 .splat = .pl_node,
1803 .reduce = .pl_node,1793 .reduce = .pl_node,
1804 .shuffle = .pl_node,1794 .shuffle = .pl_node,
1805 .select = .pl_node,
1806 .atomic_load = .pl_node,1795 .atomic_load = .pl_node,
1807 .atomic_rmw = .pl_node,1796 .atomic_rmw = .pl_node,
1808 .atomic_store = .pl_node,1797 .atomic_store = .pl_node,
...@@ -1971,6 +1960,15 @@ pub const Inst = struct {...@@ -1971,6 +1960,15 @@ pub const Inst = struct {
1971 await_nosuspend,1960 await_nosuspend,
1972 /// `operand` is `src_node: i32`.1961 /// `operand` is `src_node: i32`.
1973 breakpoint,1962 breakpoint,
1963 /// Implements the `@select` builtin.
1964 /// operand` is payload index to `Select`.
1965 select,
1966 /// Implement builtin `@errToInt`.
1967 /// `operand` is payload index to `UnNode`.
1968 error_to_int,
1969 /// Implement builtin `@intToError`.
1970 /// `operand` is payload index to `UnNode`.
1971 int_to_error,
19741972
1975 pub const InstData = struct {1973 pub const InstData = struct {
1976 opcode: Extended,1974 opcode: Extended,
...@@ -3448,6 +3446,7 @@ pub const Inst = struct {...@@ -3448,6 +3446,7 @@ pub const Inst = struct {
3448 };3446 };
34493447
3450 pub const Select = struct {3448 pub const Select = struct {
3449 node: i32,
3451 elem_type: Ref,3450 elem_type: Ref,
3452 pred: Ref,3451 pred: Ref,
3453 a: Ref,3452 a: Ref,
src/print_zir.zig+9-8
...@@ -142,7 +142,6 @@ const Writer = struct {...@@ -142,7 +142,6 @@ const Writer = struct {
142 const tag = tags[inst];142 const tag = tags[inst];
143 try stream.print("= {s}(", .{@tagName(tags[inst])});143 try stream.print("= {s}(", .{@tagName(tags[inst])});
144 switch (tag) {144 switch (tag) {
145 .array_type,
146 .as,145 .as,
147 .store,146 .store,
148 .store_to_block_ptr,147 .store_to_block_ptr,
...@@ -189,8 +188,6 @@ const Writer = struct {...@@ -189,8 +188,6 @@ const Writer = struct {
189 .typeof_log2_int_type,188 .typeof_log2_int_type,
190 .log2_int_type,189 .log2_int_type,
191 .ptr_to_int,190 .ptr_to_int,
192 .error_to_int,
193 .int_to_error,
194 .compile_error,191 .compile_error,
195 .set_eval_branch_quota,192 .set_eval_branch_quota,
196 .enum_to_int,193 .enum_to_int,
...@@ -199,6 +196,7 @@ const Writer = struct {...@@ -199,6 +196,7 @@ const Writer = struct {
199 .embed_file,196 .embed_file,
200 .error_name,197 .error_name,
201 .panic,198 .panic,
199 .panic_comptime,
202 .set_cold,200 .set_cold,
203 .set_runtime_safety,201 .set_runtime_safety,
204 .sqrt,202 .sqrt,
...@@ -284,7 +282,6 @@ const Writer = struct {...@@ -284,7 +282,6 @@ const Writer = struct {
284 .memcpy => try self.writeMemcpy(stream, inst),282 .memcpy => try self.writeMemcpy(stream, inst),
285 .memset => try self.writeMemset(stream, inst),283 .memset => try self.writeMemset(stream, inst),
286 .shuffle => try self.writeShuffle(stream, inst),284 .shuffle => try self.writeShuffle(stream, inst),
287 .select => try self.writeSelect(stream, inst),
288 .mul_add => try self.writeMulAdd(stream, inst),285 .mul_add => try self.writeMulAdd(stream, inst),
289 .field_parent_ptr => try self.writeFieldParentPtr(stream, inst),286 .field_parent_ptr => try self.writeFieldParentPtr(stream, inst),
290 .builtin_call => try self.writeBuiltinCall(stream, inst),287 .builtin_call => try self.writeBuiltinCall(stream, inst),
...@@ -356,6 +353,7 @@ const Writer = struct {...@@ -356,6 +353,7 @@ const Writer = struct {
356 .elem_ptr,353 .elem_ptr,
357 .elem_val,354 .elem_val,
358 .coerce_result_ptr,355 .coerce_result_ptr,
356 .array_type,
359 => try self.writePlNodeBin(stream, inst),357 => try self.writePlNodeBin(stream, inst),
360358
361 .elem_ptr_imm => try self.writeElemPtrImm(stream, inst),359 .elem_ptr_imm => try self.writeElemPtrImm(stream, inst),
...@@ -478,6 +476,8 @@ const Writer = struct {...@@ -478,6 +476,8 @@ const Writer = struct {
478 .compile_log => try self.writeNodeMultiOp(stream, extended),476 .compile_log => try self.writeNodeMultiOp(stream, extended),
479 .typeof_peer => try self.writeTypeofPeer(stream, extended),477 .typeof_peer => try self.writeTypeofPeer(stream, extended),
480478
479 .select => try self.writeSelect(stream, extended),
480
481 .add_with_overflow,481 .add_with_overflow,
482 .sub_with_overflow,482 .sub_with_overflow,
483 .mul_with_overflow,483 .mul_with_overflow,
...@@ -496,6 +496,8 @@ const Writer = struct {...@@ -496,6 +496,8 @@ const Writer = struct {
496 .set_float_mode,496 .set_float_mode,
497 .set_align_stack,497 .set_align_stack,
498 .wasm_memory_size,498 .wasm_memory_size,
499 .error_to_int,
500 .int_to_error,
499 => {501 => {
500 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;502 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
501 const src = LazySrcLoc.nodeOffset(inst_data.node);503 const src = LazySrcLoc.nodeOffset(inst_data.node);
...@@ -772,9 +774,8 @@ const Writer = struct {...@@ -772,9 +774,8 @@ const Writer = struct {
772 try self.writeSrc(stream, inst_data.src());774 try self.writeSrc(stream, inst_data.src());
773 }775 }
774776
775 fn writeSelect(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {777 fn writeSelect(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
776 const inst_data = self.code.instructions.items(.data)[inst].pl_node;778 const extra = self.code.extraData(Zir.Inst.Select, extended.operand).data;
777 const extra = self.code.extraData(Zir.Inst.Select, inst_data.payload_index).data;
778 try self.writeInstRef(stream, extra.elem_type);779 try self.writeInstRef(stream, extra.elem_type);
779 try stream.writeAll(", ");780 try stream.writeAll(", ");
780 try self.writeInstRef(stream, extra.pred);781 try self.writeInstRef(stream, extra.pred);
...@@ -783,7 +784,7 @@ const Writer = struct {...@@ -783,7 +784,7 @@ const Writer = struct {
783 try stream.writeAll(", ");784 try stream.writeAll(", ");
784 try self.writeInstRef(stream, extra.b);785 try self.writeInstRef(stream, extra.b);
785 try stream.writeAll(") ");786 try stream.writeAll(") ");
786 try self.writeSrc(stream, inst_data.src());787 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node));
787 }788 }
788789
789 fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {790 fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
src/value.zig+8
...@@ -111,6 +111,7 @@ pub const Value = extern union {...@@ -111,6 +111,7 @@ pub const Value = extern union {
111 int_i64,111 int_i64,
112 int_big_positive,112 int_big_positive,
113 int_big_negative,113 int_big_negative,
114 runtime_int,
114 function,115 function,
115 extern_fn,116 extern_fn,
116 variable,117 variable,
...@@ -304,6 +305,7 @@ pub const Value = extern union {...@@ -304,6 +305,7 @@ pub const Value = extern union {
304 .int_type => Payload.IntType,305 .int_type => Payload.IntType,
305 .int_u64 => Payload.U64,306 .int_u64 => Payload.U64,
306 .int_i64 => Payload.I64,307 .int_i64 => Payload.I64,
308 .runtime_int => Payload.U64,
307 .function => Payload.Function,309 .function => Payload.Function,
308 .variable => Payload.Variable,310 .variable => Payload.Variable,
309 .decl_ref_mut => Payload.DeclRefMut,311 .decl_ref_mut => Payload.DeclRefMut,
...@@ -483,6 +485,7 @@ pub const Value = extern union {...@@ -483,6 +485,7 @@ pub const Value = extern union {
483 },485 },
484 .int_type => return self.copyPayloadShallow(arena, Payload.IntType),486 .int_type => return self.copyPayloadShallow(arena, Payload.IntType),
485 .int_u64 => return self.copyPayloadShallow(arena, Payload.U64),487 .int_u64 => return self.copyPayloadShallow(arena, Payload.U64),
488 .runtime_int => return self.copyPayloadShallow(arena, Payload.U64),
486 .int_i64 => return self.copyPayloadShallow(arena, Payload.I64),489 .int_i64 => return self.copyPayloadShallow(arena, Payload.I64),
487 .int_big_positive, .int_big_negative => {490 .int_big_positive, .int_big_negative => {
488 const old_payload = self.cast(Payload.BigInt).?;491 const old_payload = self.cast(Payload.BigInt).?;
...@@ -762,6 +765,7 @@ pub const Value = extern union {...@@ -762,6 +765,7 @@ pub const Value = extern union {
762 .int_i64 => return std.fmt.formatIntValue(val.castTag(.int_i64).?.data, "", options, out_stream),765 .int_i64 => return std.fmt.formatIntValue(val.castTag(.int_i64).?.data, "", options, out_stream),
763 .int_big_positive => return out_stream.print("{}", .{val.castTag(.int_big_positive).?.asBigInt()}),766 .int_big_positive => return out_stream.print("{}", .{val.castTag(.int_big_positive).?.asBigInt()}),
764 .int_big_negative => return out_stream.print("{}", .{val.castTag(.int_big_negative).?.asBigInt()}),767 .int_big_negative => return out_stream.print("{}", .{val.castTag(.int_big_negative).?.asBigInt()}),
768 .runtime_int => return out_stream.writeAll("[runtime value]"),
765 .function => return out_stream.print("(function decl={d})", .{val.castTag(.function).?.data.owner_decl}),769 .function => return out_stream.print("(function decl={d})", .{val.castTag(.function).?.data.owner_decl}),
766 .extern_fn => return out_stream.writeAll("(extern function)"),770 .extern_fn => return out_stream.writeAll("(extern function)"),
767 .variable => return out_stream.writeAll("(variable)"),771 .variable => return out_stream.writeAll("(variable)"),
...@@ -1077,6 +1081,8 @@ pub const Value = extern union {...@@ -1077,6 +1081,8 @@ pub const Value = extern union {
1077 .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt(),1081 .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt(),
1078 .int_big_negative => return val.castTag(.int_big_negative).?.asBigInt(),1082 .int_big_negative => return val.castTag(.int_big_negative).?.asBigInt(),
10791083
1084 .runtime_int => return BigIntMutable.init(&space.limbs, val.castTag(.runtime_int).?.data).toConst(),
1085
1080 .undef => unreachable,1086 .undef => unreachable,
10811087
1082 .lazy_align => {1088 .lazy_align => {
...@@ -1132,6 +1138,8 @@ pub const Value = extern union {...@@ -1132,6 +1138,8 @@ pub const Value = extern union {
1132 .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt().to(u64) catch null,1138 .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt().to(u64) catch null,
1133 .int_big_negative => return val.castTag(.int_big_negative).?.asBigInt().to(u64) catch null,1139 .int_big_negative => return val.castTag(.int_big_negative).?.asBigInt().to(u64) catch null,
11341140
1141 .runtime_int => return val.castTag(.runtime_int).?.data,
1142
1135 .undef => unreachable,1143 .undef => unreachable,
11361144
1137 .lazy_align => {1145 .lazy_align => {
test/cases/compile_errors/array_access_of_type.zig created+10
...@@ -0,0 +1,10 @@
1export fn foo() void {
2 var b: u8[40] = undefined;
3 _ = b;
4}
5
6// error
7// backend=stage2
8// target=native
9//
10// :2:14: error: element access of non-indexable type 'type'
test/cases/compile_errors/invalid_array_elem_ty.zig+1-1
...@@ -9,4 +9,4 @@ pub export fn entry() void {...@@ -9,4 +9,4 @@ pub export fn entry() void {
9// target=native9// target=native
10// backend=stage210// backend=stage2
11//11//
12// :4:1: error: expected type 'type', found 'fn() type'12// :5:12: error: expected type 'type', found 'fn() type'
test/cases/compile_errors/method_call_with_first_arg_type_primitive.zig created+21
...@@ -0,0 +1,21 @@
1const Foo = struct {
2 x: i32,
3
4 fn init(x: i32) Foo {
5 return Foo {
6 .x = x,
7 };
8 }
9};
10
11export fn f() void {
12 const derp = Foo.init(3);
13
14 derp.init();
15}
16
17// error
18// backend=stage2
19// target=native
20//
21// :14:9: error: type 'tmp.Foo' has no field or member function named 'init'
test/cases/compile_errors/method_call_with_first_arg_type_wrong_container.zig created+30
...@@ -0,0 +1,30 @@
1pub const List = struct {
2 len: usize,
3 allocator: *Allocator,
4
5 pub fn init(allocator: *Allocator) List {
6 return List {
7 .len = 0,
8 .allocator = allocator,
9 };
10 }
11};
12
13pub var global_allocator = Allocator {
14 .field = 1234,
15};
16
17pub const Allocator = struct {
18 field: i32,
19};
20
21export fn foo() void {
22 var x = List.init(&global_allocator);
23 x.init();
24}
25
26// error
27// backend=llvm
28// target=native
29//
30// :23:6: error: type 'tmp.List' has no field or member function named 'init'
test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig created+18
...@@ -0,0 +1,18 @@
1const Geo3DTex2D = struct { vertices: [][2]f32 };
2pub fn getGeo3DTex2D() Geo3DTex2D {
3 return Geo3DTex2D{
4 .vertices = [_][2]f32{
5 [_]f32{ -0.5, -0.5},
6 },
7 };
8}
9export fn entry() void {
10 var geo_data = getGeo3DTex2D();
11 _ = geo_data;
12}
13
14// error
15// backend=llvm
16// target=native
17//
18// :4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32'
test/cases/compile_errors/mul_overflow_in_function_evaluation.zig created+14
...@@ -0,0 +1,14 @@
1const y = mul(300, 6000);
2fn mul(a: u16, b: u16) u16 {
3 return a * b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(&y)); }
7
8// error
9// backend=stage2
10// target=native
11//
12// :3:14: error: overflow of integer type 'u16' with value '1800000'
13// :1:14: note: called from here
14
test/cases/compile_errors/negation_overflow_in_function_evaluation.zig created+13
...@@ -0,0 +1,13 @@
1const y = neg(-128);
2fn neg(x: i8) i8 {
3 return -x;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(&y)); }
7
8// error
9// backend=stage2
10// target=native
11//
12// :3:12: error: overflow of integer type 'i8' with value '128'
13// :1:14: note: called from here
test/cases/compile_errors/no_else_prong_on_switch_on_global_error_set.zig created+14
...@@ -0,0 +1,14 @@
1export fn entry() void {
2 foo(error.A);
3}
4fn foo(a: anyerror) void {
5 switch (a) {
6 error.A => {},
7 }
8}
9
10// error
11// backend=stage2
12// target=native
13//
14// :5:5: error: else prong required when switching on type 'anyerror'
test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig created+44
...@@ -0,0 +1,44 @@
1export fn entry1() void {
2 var m2 = &2;
3 _ = m2;
4}
5export fn entry2() void {
6 var a = undefined;
7 _ = a;
8}
9export fn entry3() void {
10 var b = 1;
11 _ = b;
12}
13export fn entry4() void {
14 var c = 1.0;
15 _ = c;
16}
17export fn entry5() void {
18 var d = null;
19 _ = d;
20}
21export fn entry6(opaque_: *Opaque) void {
22 var e = opaque_.*;
23 _ = e;
24}
25export fn entry7() void {
26 var f = i32;
27 _ = f;
28}
29const Opaque = opaque {};
30
31// error
32// backend=stage2
33// target=native
34//
35// :2:8: error: variable of type '*const comptime_int' must be const or comptime
36// :6:8: error: variable of type '@TypeOf(undefined)' must be const or comptime
37// :10:8: error: variable of type 'comptime_int' must be const or comptime
38// :10:8: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
39// :14:8: error: variable of type 'comptime_float' must be const or comptime
40// :14:8: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
41// :18:8: error: variable of type '@TypeOf(null)' must be const or comptime
42// :22:19: error: values of type 'tmp.Opaque' must be comptime known, but operand value is runtime known
43// :26:8: error: variable of type 'type' must be const or comptime
44// :26:8: note: types are not available at runtime
test/cases/compile_errors/non-inline_for_loop_on_a_type_that_requires_comptime.zig created+16
...@@ -0,0 +1,16 @@
1const Foo = struct {
2 name: []const u8,
3 T: type,
4};
5export fn entry() void {
6 const xx: [2]Foo = .{ .{ .name = "", .T = u8 }, .{ .name = "", .T = u8 } };
7 for (xx) |f| { _ = f;}
8}
9
10// error
11// backend=stage2
12// target=native
13//
14// :7:10: error: values of type '[2]tmp.Foo' must be comptime known, but index value is runtime known
15// :3:8: note: struct requires comptime because of this field
16// :3:8: note: types are not available at runtime
test/cases/compile_errors/non_constant_expression_in_array_size.zig created+14
...@@ -0,0 +1,14 @@
1const Foo = struct {
2 y: [get()]u8,
3};
4var global_var: usize = 1;
5fn get() usize { return global_var; }
6
7export fn entry() usize { return @offsetOf(Foo, "y"); }
8
9// error
10// backend=stage2
11// target=native
12//
13// :5:25: error: unable to resolve comptime value
14// :2:15: note: called from here
test/cases/compile_errors/non_error_sets_used_in_merge_error_sets_operator.zig created+15
...@@ -0,0 +1,15 @@
1export fn foo() void {
2 const Errors = u8 || u16;
3 _ = Errors;
4}
5export fn bar() void {
6 const Errors = error{} || u16;
7 _ = Errors;
8}
9
10// error
11// backend=stage2
12// target=native
13//
14// :2:20: error: expected error set type, found 'u8'
15// :6:31: error: expected error set type, found 'u16'
test/cases/compile_errors/panic_called_at_compile_time.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 comptime {
3 @panic("aoeu",);
4 }
5}
6
7// error
8// backend=stage2
9// target=native
10//
11// :3:9: error: encountered @panic at comptime
test/cases/compile_errors/range_operator_in_switch_used_on_error_set.zig created+20
...@@ -0,0 +1,20 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo ... error.Bar => {},
4 else => {},
5 };
6}
7fn foo(x: i32) !void {
8 switch (x) {
9 0 ... 10 => return error.Foo,
10 11 ... 20 => return error.Bar,
11 else => {},
12 }
13}
14
15// error
16// backend=llvm
17// target=native
18//
19// :2:34: error: ranges not allowed when switching on type '@typeInfo(@typeInfo(@TypeOf(tmp.foo)).Fn.return_type.?).ErrorUnion.error_set'
20// :3:19: note: range here
test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig created+13
...@@ -0,0 +1,13 @@
1comptime {
2 const array: [4]u8 = "aoeu".*;
3 const sub_array = array[1..];
4 const int_ptr = @ptrCast(*const u24, sub_array);
5 const deref = int_ptr.*;
6 _ = deref;
7}
8
9// error
10// backend=stage2
11// target=native
12//
13// :5:26: error: dereference of '*const u24' exceeds bounds of containing decl of type '[4]u8'
test/cases/compile_errors/runtime_index_into_comptime_type_slice.zig created+19
...@@ -0,0 +1,19 @@
1const Struct = struct {
2 a: u32,
3};
4fn getIndex() usize {
5 return 2;
6}
7export fn entry() void {
8 const index = getIndex();
9 const field = @typeInfo(Struct).Struct.fields[index];
10 _ = field;
11}
12
13// error
14// backend=stage2
15// target=native
16//
17// :9:51: error: values of type '[]const builtin.Type.StructField' must be comptime known, but index value is runtime known
18// :?:21: note: struct requires comptime because of this field
19// :?:21: note: types are not available at runtime
test/cases/compile_errors/setAlignStack_in_inline_function.zig created+23
...@@ -0,0 +1,23 @@
1export fn entry() void {
2 foo();
3}
4fn foo() callconv(.Inline) void {
5 @setAlignStack(16);
6}
7
8export fn entry1() void {
9 comptime bar();
10}
11fn bar() void {
12 @setAlignStack(16);
13}
14
15
16// error
17// backend=stage2
18// target=native
19//
20// :5:5: error: @setAlignStack in inline function
21// :2:8: note: called from here
22// :12:5: error: @setAlignStack in inline call
23// :9:17: note: called from here
test/cases/compile_errors/signed_integer_remainder_division.zig created+9
...@@ -0,0 +1,9 @@
1export fn foo(a: i32, b: i32) i32 {
2 return a % b;
3}
4
5// error
6// backend=stage2
7// target=native
8//
9// :2:12: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod
test/cases/compile_errors/sizeOf_bad_type.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() usize {
2 return @sizeOf(@TypeOf(null));
3}
4
5// error
6// backend=stage2
7// target=native
8//
9// :2:20: error: no size available for type '@TypeOf(null)'
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig created+11
...@@ -0,0 +1,11 @@
1export fn foo() void {
2 const bytes = [1]u8{ 0xfa } ** 16;
3 var value = @ptrCast(*const []const u8, &bytes).*;
4 _ = value;
5}
6
7// error
8// backend=stage2
9// target=native
10//
11// :3:52: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not.
test/cases/compile_errors/slice_passed_as_array_init_type.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 const x = []u8{};
3 _ = x;
4}
5
6// error
7// backend=stage2
8// target=native
9//
10// :2:19: error: type '[]u8' does not support array initialization syntax
11// :2:19: note: inferred array length is specified with an underscore: '[_]u8'
test/cases/compile_errors/slice_passed_as_array_init_type_with_elems.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry() void {
2 const x = []u8{1, 2};
3 _ = x;
4}
5
6// error
7// backend=stage2
8// target=native
9//
10// :2:19: error: type '[]u8' does not support array initialization syntax
11// :2:19: note: inferred array length is specified with an underscore: '[_]u8'
test/cases/compile_errors/src_fields_runtime.zig created+14
...@@ -0,0 +1,14 @@
1pub export fn entry1() void {
2 const s = @src();
3 comptime var a: []const u8 = s.file;
4 comptime var b: []const u8 = s.fn_name;
5 comptime var c: u32 = s.column;
6 comptime var d: u32 = s.line;
7 _ = a; _ = b; _ = c; _ = d;
8}
9
10// error
11// backend=stage2
12// target=native
13//
14// :6:28: error: cannot store runtime value in compile time variable
test/cases/compile_errors/stage1/non_compile_time_array_concatenation.zig created+11
...@@ -0,0 +1,11 @@
1fn f() []u8 {
2 return s ++ "foo";
3}
4var s: [10]u8 = undefined;
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:12: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/array_access_of_type.zig deleted-10
...@@ -1,10 +0,0 @@
1export fn foo() void {
2 var b: u8[40] = undefined;
3 _ = b;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:14: error: array access of non-array type 'type'
test/cases/compile_errors/stage1/obj/method_call_with_first_arg_type_primitive.zig deleted-21
...@@ -1,21 +0,0 @@
1const Foo = struct {
2 x: i32,
3
4 fn init(x: i32) Foo {
5 return Foo {
6 .x = x,
7 };
8 }
9};
10
11export fn f() void {
12 const derp = Foo.init(3);
13
14 derp.init();
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:14:5: error: expected type 'i32', found 'Foo'
test/cases/compile_errors/stage1/obj/method_call_with_first_arg_type_wrong_container.zig deleted-30
...@@ -1,30 +0,0 @@
1pub const List = struct {
2 len: usize,
3 allocator: *Allocator,
4
5 pub fn init(allocator: *Allocator) List {
6 return List {
7 .len = 0,
8 .allocator = allocator,
9 };
10 }
11};
12
13pub var global_allocator = Allocator {
14 .field = 1234,
15};
16
17pub const Allocator = struct {
18 field: i32,
19};
20
21export fn foo() void {
22 var x = List.init(&global_allocator);
23 x.init();
24}
25
26// error
27// backend=stage1
28// target=native
29//
30// tmp.zig:23:5: error: expected type '*Allocator', found '*List'
test/cases/compile_errors/stage1/obj/missing_const_in_slice_with_nested_array_type.zig deleted-18
...@@ -1,18 +0,0 @@
1const Geo3DTex2D = struct { vertices: [][2]f32 };
2pub fn getGeo3DTex2D() Geo3DTex2D {
3 return Geo3DTex2D{
4 .vertices = [_][2]f32{
5 [_]f32{ -0.5, -0.5},
6 },
7 };
8}
9export fn entry() void {
10 var geo_data = getGeo3DTex2D();
11 _ = geo_data;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32'
test/cases/compile_errors/stage1/obj/mul_overflow_in_function_evaluation.zig deleted-12
...@@ -1,12 +0,0 @@
1const y = mul(300, 6000);
2fn mul(a: u16, b: u16) u16 {
3 return a * b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:14: error: operation caused overflow
test/cases/compile_errors/stage1/obj/negation_overflow_in_function_evaluation.zig deleted-12
...@@ -1,12 +0,0 @@
1const y = neg(-128);
2fn neg(x: i8) i8 {
3 return -x;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:12: error: negation caused overflow
test/cases/compile_errors/stage1/obj/no_else_prong_on_switch_on_global_error_set.zig deleted-14
...@@ -1,14 +0,0 @@
1export fn entry() void {
2 foo(error.A);
3}
4fn foo(a: anyerror) void {
5 switch (a) {
6 error.A => {},
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:5: error: else prong required when switching on type 'anyerror'
test/cases/compile_errors/stage1/obj/non-const_variables_of_things_that_require_const_variables.zig deleted-51
...@@ -1,51 +0,0 @@
1export fn entry1() void {
2 var m2 = &2;
3 _ = m2;
4}
5export fn entry2() void {
6 var a = undefined;
7 _ = a;
8}
9export fn entry3() void {
10 var b = 1;
11 _ = b;
12}
13export fn entry4() void {
14 var c = 1.0;
15 _ = c;
16}
17export fn entry5() void {
18 var d = null;
19 _ = d;
20}
21export fn entry6(opaque_: *Opaque) void {
22 var e = opaque_.*;
23 _ = e;
24}
25export fn entry7() void {
26 var f = i32;
27 _ = f;
28}
29export fn entry8() void {
30 var h = (Foo {}).bar;
31 _ = h;
32}
33const Opaque = opaque {};
34const Foo = struct {
35 fn bar(self: *const Foo) void {_ = self;}
36};
37
38// error
39// backend=stage1
40// target=native
41//
42// tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime
43// tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime
44// tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime
45// tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
46// tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime
47// tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
48// tmp.zig:18:4: error: variable of type '@Type(.Null)' must be const or comptime
49// tmp.zig:22:4: error: variable of type 'Opaque' not allowed
50// tmp.zig:26:4: error: variable of type 'type' must be const or comptime
51// tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime
test/cases/compile_errors/stage1/obj/non-inline_for_loop_on_a_type_that_requires_comptime.zig deleted-14
...@@ -1,14 +0,0 @@
1const Foo = struct {
2 name: []const u8,
3 T: type,
4};
5export fn entry() void {
6 const xx: [2]Foo = undefined;
7 for (xx) |f| { _ = f;}
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known
test/cases/compile_errors/stage1/obj/non_compile_time_array_concatenation.zig deleted-11
...@@ -1,11 +0,0 @@
1fn f() []u8 {
2 return s ++ "foo";
3}
4var s: [10]u8 = undefined;
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:12: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/non_constant_expression_in_array_size.zig deleted-14
...@@ -1,14 +0,0 @@
1const Foo = struct {
2 y: [get()]u8,
3};
4var global_var: usize = 1;
5fn get() usize { return global_var; }
6
7export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:25: error: cannot store runtime value in compile time variable
14// tmp.zig:2:12: note: called from here
test/cases/compile_errors/stage1/obj/non_error_sets_used_in_merge_error_sets_operator.zig deleted-17
...@@ -1,17 +0,0 @@
1export fn foo() void {
2 const Errors = u8 || u16;
3 _ = Errors;
4}
5export fn bar() void {
6 const Errors = error{} || u16;
7 _ = Errors;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:20: error: expected error set type, found type 'u8'
15// tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR
16// tmp.zig:6:31: error: expected error set type, found type 'u16'
17// tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR
test/cases/compile_errors/stage1/obj/panic_called_at_compile_time.zig deleted-11
...@@ -1,11 +0,0 @@
1export fn entry() void {
2 comptime {
3 @panic("aoeu",);
4 }
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: encountered @panic at compile-time
test/cases/compile_errors/stage1/obj/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig deleted-13
...@@ -1,13 +0,0 @@
1export fn entry() bool {
2 var x: u0 = 0;
3 const p = @ptrCast(?*u0, &x);
4 return p == null;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation
12// tmp.zig:3:31: note: '*u0' has no in-memory bits
13// tmp.zig:3:24: note: '?*u0' has in-memory bits
test/cases/compile_errors/stage1/obj/ptrToInt_on_void.zig deleted-9
...@@ -1,9 +0,0 @@
1export fn entry() bool {
2 return @ptrToInt(&{}) == @ptrToInt(&{});
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:23: error: pointer to size 0 type has no address
test/cases/compile_errors/stage1/obj/range_operator_in_switch_used_on_error_set.zig deleted-19
...@@ -1,19 +0,0 @@
1export fn entry() void {
2 try foo(452) catch |err| switch (err) {
3 error.A ... error.B => {},
4 else => {},
5 };
6}
7fn foo(x: i32) !void {
8 switch (x) {
9 0 ... 10 => return error.Foo,
10 11 ... 20 => return error.Bar,
11 else => {},
12 }
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:3:17: error: operator not allowed for errors
test/cases/compile_errors/stage1/obj/reading_past_end_of_pointer_casted_array.zig deleted-13
...@@ -1,13 +0,0 @@
1comptime {
2 const array: [4]u8 = "aoeu".*;
3 const sub_array = array[1..];
4 const int_ptr = @ptrCast(*const u24, sub_array);
5 const deref = int_ptr.*;
6 _ = deref;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes
test/cases/compile_errors/stage1/obj/recursive_inferred_error_set.zig deleted-12
...@@ -1,12 +0,0 @@
1export fn entry() void {
2 foo() catch unreachable;
3}
4fn foo() !void {
5 try foo();
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet
test/cases/compile_errors/stage1/obj/runtime_index_into_comptime_type_slice.zig deleted-17
...@@ -1,17 +0,0 @@
1const Struct = struct {
2 a: u32,
3};
4fn getIndex() usize {
5 return 2;
6}
7export fn entry() void {
8 const index = getIndex();
9 const field = @typeInfo(Struct).Struct.fields[index];
10 _ = field;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known
test/cases/compile_errors/stage1/obj/setAlignStack_in_inline_function.zig deleted-12
...@@ -1,12 +0,0 @@
1export fn entry() void {
2 foo();
3}
4fn foo() callconv(.Inline) void {
5 @setAlignStack(16);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: @setAlignStack in inline function
test/cases/compile_errors/stage1/obj/signed_integer_remainder_division.zig deleted-9
...@@ -1,9 +0,0 @@
1export fn foo(a: i32, b: i32) i32 {
2 return a % b;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod
test/cases/compile_errors/stage1/obj/sizeOf_bad_type.zig deleted-9
...@@ -1,9 +0,0 @@
1export fn entry() usize {
2 return @sizeOf(@TypeOf(null));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:20: error: no size available for type '@Type(.Null)'
test/cases/compile_errors/stage1/obj/slice_cannot_have_its_bytes_reinterpreted.zig deleted-11
...@@ -1,11 +0,0 @@
1export fn foo() void {
2 const bytes = [1]u8{ 0xfa } ** 16;
3 var value = @ptrCast(*const []const u8, &bytes).*;
4 _ = value;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// :3:52: error: slice '[]const u8' cannot have its bytes reinterpreted
test/cases/compile_errors/stage1/obj/slice_passed_as_array_init_type.zig deleted-10
...@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = []u8{};
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
test/cases/compile_errors/stage1/obj/slice_passed_as_array_init_type_with_elems.zig deleted-10
...@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = []u8{1, 2};
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
test/cases/compile_errors/stage1/obj/slicing_of_global_undefined_pointer.zig deleted-10
...@@ -1,10 +0,0 @@
1var buf: *[1]u8 = undefined;
2export fn entry() void {
3 _ = buf[0..1];
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:12: error: non-zero length slice of undefined pointer
test/cases/compile_errors/stage1/obj/sub_overflow_in_function_evaluation.zig deleted-12
...@@ -1,12 +0,0 @@
1const y = sub(10, 20);
2fn sub(a: u16, b: u16) u16 {
3 return a - b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:14: error: operation caused overflow
test/cases/compile_errors/stage1/obj/switch_expression-duplicate_or_overlapping_integer_value.zig deleted-16
...@@ -1,16 +0,0 @@
1fn foo(x: u8) u8 {
2 return switch (x) {
3 0 ... 100 => @as(u8, 0),
4 101 ... 200 => 1,
5 201, 203 ... 207 => 2,
6 206 ... 255 => 3,
7 };
8}
9export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:6:9: error: duplicate switch value
16// tmp.zig:5:14: note: previous value here
test/cases/compile_errors/stage1/obj/switch_expression-switch_on_pointer_type_with_no_else.zig deleted-13
...@@ -1,13 +0,0 @@
1fn foo(x: *u8) void {
2 switch (x) {
3 &y => {},
4 }
5}
6const y: u8 = 100;
7export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:5: error: else prong required when switching on type '*u8'
test/cases/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_bool.zig deleted-14
...@@ -1,14 +0,0 @@
1fn foo(x: bool) void {
2 switch (x) {
3 true => {},
4 false => {},
5 else => {},
6 }
7}
8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:9: error: unreachable else prong, all cases already handled
test/cases/compile_errors/stage1/obj/switch_on_union_with_no_attached_enum.zig deleted-22
...@@ -1,22 +0,0 @@
1const Payload = union {
2 A: i32,
3 B: f64,
4 C: bool,
5};
6export fn entry() void {
7 const a = Payload { .A = 1234 };
8 foo(a);
9}
10fn foo(a: *const Payload) void {
11 switch (a.*) {
12 Payload.A => {},
13 else => unreachable,
14 }
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:11:14: error: switch on union which has no attached enum
22// tmp.zig:1:17: note: consider 'union(enum)' here
test/cases/compile_errors/stage1/obj/switch_with_invalid_expression_parameter.zig deleted-17
...@@ -1,17 +0,0 @@
1export fn entry() void {
2 Test(i32);
3}
4fn Test(comptime T: type) void {
5 const x = switch (T) {
6 []u8 => |x| x,
7 i32 => |x| x,
8 else => unreachable,
9 };
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:7:17: error: switch on type 'type' provides no expression parameter
test/cases/compile_errors/stage1/obj/switch_with_overlapping_case_ranges.zig deleted-13
...@@ -1,13 +0,0 @@
1export fn entry() void {
2 var q: u8 = 0;
3 switch (q) {
4 1...2 => {},
5 0...255 => {},
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:9: error: duplicate switch value
test/cases/compile_errors/stage1/obj/tagName_used_on_union_with_no_associated_enum_tag.zig deleted-16
...@@ -1,16 +0,0 @@
1const FloatInt = extern union {
2 Float: f32,
3 Int: i32,
4};
5export fn entry() void {
6 var fi = FloatInt{.Float = 123.45};
7 var tagName = @tagName(fi);
8 _ = tagName;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:19: error: union has no associated enum
16// tmp.zig:1:18: note: declared here
test/cases/compile_errors/stage1/obj/type_variables_must_be_constant.zig deleted-10
...@@ -1,10 +0,0 @@
1var foo = u8;
2export fn entry() foo {
3 return 1;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// :1:1: error: variable of type 'type' must be constant
test/cases/compile_errors/stage1/obj/unreachable_executed_at_comptime.zig deleted-16
...@@ -1,16 +0,0 @@
1fn foo(comptime x: i32) i32 {
2 comptime {
3 if (x >= 0) return -x;
4 unreachable;
5 }
6}
7export fn entry() void {
8 _ = foo(-42);
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:4:9: error: reached unreachable code
16// tmp.zig:8:12: note: called from here
test/cases/compile_errors/stage1/obj/use_of_comptime-known_undefined_function_value.zig deleted-13
...@@ -1,13 +0,0 @@
1const Cmd = struct {
2 exec: fn () void,
3};
4export fn entry() void {
5 const command = Cmd{ .exec = undefined };
6 command.exec();
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:6:12: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig deleted-10
...@@ -1,10 +0,0 @@
1export fn foo() void {
2 _ = @wasmMemoryGrow(0, 1);
3 return;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only
test/cases/compile_errors/stage1/obj/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig deleted-10
...@@ -1,10 +0,0 @@
1export fn foo() void {
2 _ = @wasmMemorySize(0);
3 return;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only
test/cases/compile_errors/stage1/obj/wrong_type_for_reify_type.zig deleted-9
...@@ -1,9 +0,0 @@
1export fn entry() void {
2 _ = @Type(0);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int'
test/cases/compile_errors/stage1/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig created+13
...@@ -0,0 +1,13 @@
1export fn entry() bool {
2 var x: u0 = 0;
3 const p = @ptrCast(?*u0, &x);
4 return p == null;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation
12// tmp.zig:3:31: note: '*u0' has no in-memory bits
13// tmp.zig:3:24: note: '?*u0' has in-memory bits
test/cases/compile_errors/stage1/ptrToInt_on_void.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() bool {
2 return @ptrToInt(&{}) == @ptrToInt(&{});
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:23: error: pointer to size 0 type has no address
test/cases/compile_errors/stage1/recursive_inferred_error_set.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry() void {
2 foo() catch unreachable;
3}
4fn foo() !void {
5 try foo();
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet
test/cases/compile_errors/stage1/slicing_of_global_undefined_pointer.zig created+10
...@@ -0,0 +1,10 @@
1var buf: *[1]u8 = undefined;
2export fn entry() void {
3 _ = buf[0..1];
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:12: error: non-zero length slice of undefined pointer
test/cases/compile_errors/stage1/switch_with_invalid_expression_parameter.zig created+17
...@@ -0,0 +1,17 @@
1export fn entry() void {
2 Test(i32);
3}
4fn Test(comptime T: type) void {
5 const x = switch (T) {
6 []u8 => |x| x,
7 i32 => |x| x,
8 else => unreachable,
9 };
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:7:17: error: switch on type 'type' provides no expression parameter
test/cases/compile_errors/stage1/use_of_comptime-known_undefined_function_value.zig created+13
...@@ -0,0 +1,13 @@
1const Cmd = struct {
2 exec: fn () void,
3};
4export fn entry() void {
5 const command = Cmd{ .exec = undefined };
6 command.exec();
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:6:12: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage2/out_of_bounds_index.zig+4-4
...@@ -23,7 +23,7 @@ comptime {...@@ -23,7 +23,7 @@ comptime {
23// error23// error
24// target=native24// target=native
25//25//
26// :4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)26// :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)
27// :9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel)27// :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel)
28// :14:22: error: end index 5 out of bounds for array of length 428// :14:26: error: end index 5 out of bounds for array of length 4
29// :19:22: error: start index 3 is larger than end index 229// :19:23: error: start index 3 is larger than end index 2
test/cases/compile_errors/sub_overflow_in_function_evaluation.zig created+13
...@@ -0,0 +1,13 @@
1const y = sub(10, 20);
2fn sub(a: u16, b: u16) u16 {
3 return a - b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(&y)); }
7
8// error
9// backend=stage2
10// target=native
11//
12// :3:14: error: overflow of integer type 'u16' with value '-10'
13// :1:14: note: called from here
test/cases/compile_errors/switch_expression-duplicate_or_overlapping_integer_value.zig created+16
...@@ -0,0 +1,16 @@
1fn foo(x: u8) u8 {
2 return switch (x) {
3 0 ... 100 => @as(u8, 0),
4 101 ... 200 => 1,
5 201, 203 ... 207 => 2,
6 206 ... 255 => 3,
7 };
8}
9export fn entry() usize { return @sizeOf(@TypeOf(&foo)); }
10
11// error
12// backend=stage2
13// target=native
14//
15// :6:13: error: duplicate switch value
16// :5:18: note: previous value here
test/cases/compile_errors/switch_expression-switch_on_pointer_type_with_no_else.zig created+13
...@@ -0,0 +1,13 @@
1fn foo(x: *u8) void {
2 switch (x) {
3 &y => {},
4 }
5}
6var y: u8 = 100;
7export fn entry() usize { return @sizeOf(@TypeOf(&foo)); }
8
9// error
10// backend=stage2
11// target=native
12//
13// :2:5: error: else prong required when switching on type '*u8'
test/cases/compile_errors/switch_expression-unreachable_else_prong_bool.zig created+14
...@@ -0,0 +1,14 @@
1fn foo(x: bool) void {
2 switch (x) {
3 true => {},
4 false => {},
5 else => {},
6 }
7}
8export fn entry() usize { return @sizeOf(@TypeOf(&foo)); }
9
10// error
11// backend=stage2
12// target=native
13//
14// :5:14: error: unreachable else prong; all cases already handled
test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig created+22
...@@ -0,0 +1,22 @@
1const Payload = union {
2 A: i32,
3 B: f64,
4 C: bool,
5};
6export fn entry() void {
7 const a = Payload { .A = 1234 };
8 foo(&a);
9}
10fn foo(a: *const Payload) void {
11 switch (a.*) {
12 Payload.A => {},
13 else => unreachable,
14 }
15}
16
17// error
18// backend=stage2
19// target=native
20//
21// :11:14: error: switch on union with no attached enum
22// :1:17: note: consider 'union(enum)' here
test/cases/compile_errors/switch_with_overlapping_case_ranges.zig created+14
...@@ -0,0 +1,14 @@
1export fn entry() void {
2 var q: u8 = 0;
3 switch (q) {
4 1...2 => {},
5 0...255 => {},
6 }
7}
8
9// error
10// backend=stage2
11// target=native
12//
13// :5:10: error: duplicate switch value
14// :4:10: note: previous value here
test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig created+16
...@@ -0,0 +1,16 @@
1const FloatInt = extern union {
2 Float: f32,
3 Int: i32,
4};
5export fn entry() void {
6 var fi = FloatInt{.Float = 123.45};
7 var tagName = @tagName(fi);
8 _ = tagName;
9}
10
11// error
12// backend=stage2
13// target=native
14//
15// :7:19: error: union 'tmp.FloatInt' is untagged
16// :1:25: note: union declared here
test/cases/compile_errors/type_variables_must_be_constant.zig created+11
...@@ -0,0 +1,11 @@
1var foo = u8;
2export fn entry() foo {
3 return 1;
4}
5
6// error
7// backend=stage2
8// target=native
9//
10// :1:1: error: variable of type 'type' must be const or comptime
11// :1:1: note: types are not available at runtime
test/cases/compile_errors/unreachable_executed_at_comptime.zig created+16
...@@ -0,0 +1,16 @@
1fn foo(comptime x: i32) i32 {
2 comptime {
3 if (x >= 0) return -x;
4 unreachable;
5 }
6}
7export fn entry() void {
8 _ = comptime foo(-42);
9}
10
11// error
12// backend=stage2
13// target=native
14//
15// :4:9: error: reached unreachable code
16// :8:21: note: called from here
test/cases/compile_errors/unreachable_variable.zig+1-1
...@@ -7,4 +7,4 @@ export fn f() void {...@@ -7,4 +7,4 @@ export fn f() void {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :2:25: error: expected type 'noreturn', found 'void'10// :2:25: error: cannot cast to noreturn
test/cases/compile_errors/use_invalid_number_literal_as_array_index.zig+1
...@@ -9,3 +9,4 @@ export fn entry() void {...@@ -9,3 +9,4 @@ export fn entry() void {
9// target=native9// target=native
10//10//
11// :1:1: error: variable of type 'comptime_int' must be const or comptime11// :1:1: error: variable of type 'comptime_int' must be const or comptime
12// :1:1: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
test/cases/compile_errors/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig created+10
...@@ -0,0 +1,10 @@
1export fn foo() void {
2 _ = @wasmMemoryGrow(0, 1);
3 return;
4}
5
6// error
7// backend=stage2
8// target=x86_64-native
9//
10// :2:9: error: builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is x86_64
test/cases/compile_errors/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig created+10
...@@ -0,0 +1,10 @@
1export fn foo() void {
2 _ = @wasmMemorySize(0);
3 return;
4}
5
6// error
7// backend=stage2
8// target=x86_64-native
9//
10// :2:9: error: builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is x86_64
test/cases/compile_errors/wrong_type_for_reify_type.zig created+9
...@@ -0,0 +1,9 @@
1export fn entry() void {
2 _ = @Type(0);
3}
4
5// error
6// backend=stage2
7// target=native
8//
9// :2:15: error: expected type 'builtin.Type', found 'comptime_int'