authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-13 16:46:27-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-13 16:46:27-04:00
log06f2f4d64b63cf78a3ff77cc64dbc822123f454d
tree2444a286bc3a33c09fa769f692a4fc013316c7c3
parentea2f6594ce02187875ce052c1a7c43acf60884f9

change `unreachable{}` to `@unreachable()`

instead of a container init expression, it's a builtin function call.

13 files changed, 89 insertions(+), 81 deletions(-)

src/all_types.hpp+1
...@@ -1174,6 +1174,7 @@ enum BuiltinFnId {...@@ -1174,6 +1174,7 @@ enum BuiltinFnId {
1174 BuiltinFnIdDivExact,1174 BuiltinFnIdDivExact,
1175 BuiltinFnIdTruncate,1175 BuiltinFnIdTruncate,
1176 BuiltinFnIdIntType,1176 BuiltinFnIdIntType,
1177 BuiltinFnIdUnreachable,
1177};1178};
11781179
1179struct BuiltinFnEntry {1180struct BuiltinFnEntry {
src/analyze.cpp+2-7
...@@ -2677,13 +2677,6 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry...@@ -2677,13 +2677,6 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
2677 } else {2677 } else {
2678 return resolve_expr_const_val_as_void(g, node);2678 return resolve_expr_const_val_as_void(g, node);
2679 }2679 }
2680 } else if (container_type->id == TypeTableEntryIdUnreachable) {
2681 if (container_init_expr->entries.length != 0) {
2682 add_node_error(g, node, buf_sprintf("unreachable expression expects no arguments"));
2683 return g->builtin_types.entry_invalid;
2684 } else {
2685 return container_type;
2686 }
2687 } else {2680 } else {
2688 add_node_error(g, node,2681 add_node_error(g, node,
2689 buf_sprintf("type '%s' does not support %s initialization syntax",2682 buf_sprintf("type '%s' does not support %s initialization syntax",
...@@ -5435,6 +5428,8 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry...@@ -5435,6 +5428,8 @@ static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry
5435 return analyze_compile_err(g, import, context, node);5428 return analyze_compile_err(g, import, context, node);
5436 case BuiltinFnIdIntType:5429 case BuiltinFnIdIntType:
5437 return analyze_int_type(g, import, context, node);5430 return analyze_int_type(g, import, context, node);
5431 case BuiltinFnIdUnreachable:
5432 return g->builtin_types.entry_unreachable;
5438 }5433 }
5439 zig_unreachable();5434 zig_unreachable();
5440}5435}
src/codegen.cpp+17-9
...@@ -497,6 +497,20 @@ static LLVMValueRef gen_truncate(CodeGen *g, AstNode *node) {...@@ -497,6 +497,20 @@ static LLVMValueRef gen_truncate(CodeGen *g, AstNode *node) {
497 return LLVMBuildTrunc(g->builder, src_val, dest_type->type_ref, "");497 return LLVMBuildTrunc(g->builder, src_val, dest_type->type_ref, "");
498}498}
499499
500static LLVMValueRef gen_unreachable(CodeGen *g, AstNode *node) {
501 assert(node->type == NodeTypeFnCallExpr);
502
503 set_debug_source_node(g, node);
504
505 if (want_debug_safety(g, node) || g->is_test_build) {
506 gen_debug_safety_crash(g);
507 } else {
508 LLVMBuildUnreachable(g->builder);
509 }
510
511 return nullptr;
512}
513
500static LLVMValueRef gen_shl_with_overflow(CodeGen *g, AstNode *node) {514static LLVMValueRef gen_shl_with_overflow(CodeGen *g, AstNode *node) {
501 assert(node->type == NodeTypeFnCallExpr);515 assert(node->type == NodeTypeFnCallExpr);
502516
...@@ -689,6 +703,8 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {...@@ -689,6 +703,8 @@ static LLVMValueRef gen_builtin_fn_call_expr(CodeGen *g, AstNode *node) {
689 return gen_div_exact(g, node);703 return gen_div_exact(g, node);
690 case BuiltinFnIdTruncate:704 case BuiltinFnIdTruncate:
691 return gen_truncate(g, node);705 return gen_truncate(g, node);
706 case BuiltinFnIdUnreachable:
707 return gen_unreachable(g, node);
692 }708 }
693 zig_unreachable();709 zig_unreachable();
694}710}
...@@ -2949,15 +2965,6 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {...@@ -2949,15 +2965,6 @@ static LLVMValueRef gen_container_init_expr(CodeGen *g, AstNode *node) {
2949 }2965 }
29502966
2951 return tmp_struct_ptr;2967 return tmp_struct_ptr;
2952 } else if (type_entry->id == TypeTableEntryIdUnreachable) {
2953 assert(node->data.container_init_expr.entries.length == 0);
2954 set_debug_source_node(g, node);
2955 if (want_debug_safety(g, node) || g->is_test_build) {
2956 gen_debug_safety_crash(g);
2957 } else {
2958 LLVMBuildUnreachable(g->builder);
2959 }
2960 return nullptr;
2961 } else if (type_entry->id == TypeTableEntryIdVoid) {2968 } else if (type_entry->id == TypeTableEntryIdVoid) {
2962 assert(node->data.container_init_expr.entries.length == 0);2969 assert(node->data.container_init_expr.entries.length == 0);
2963 return nullptr;2970 return nullptr;
...@@ -4859,6 +4866,7 @@ static void define_builtin_fns(CodeGen *g) {...@@ -4859,6 +4866,7 @@ static void define_builtin_fns(CodeGen *g) {
4859 create_builtin_fn_with_arg_count(g, BuiltinFnIdTruncate, "truncate", 2);4866 create_builtin_fn_with_arg_count(g, BuiltinFnIdTruncate, "truncate", 2);
4860 create_builtin_fn_with_arg_count(g, BuiltinFnIdCompileErr, "compileError", 1);4867 create_builtin_fn_with_arg_count(g, BuiltinFnIdCompileErr, "compileError", 1);
4861 create_builtin_fn_with_arg_count(g, BuiltinFnIdIntType, "intType", 2);4868 create_builtin_fn_with_arg_count(g, BuiltinFnIdIntType, "intType", 2);
4869 create_builtin_fn_with_arg_count(g, BuiltinFnIdUnreachable, "unreachable", 0);
4862}4870}
48634871
4864static void init(CodeGen *g, Buf *source_path) {4872static void init(CodeGen *g, Buf *source_path) {
src/eval.cpp+11-7
...@@ -491,13 +491,6 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue *...@@ -491,13 +491,6 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue *
491 }491 }
492 } else if (container_type->id == TypeTableEntryIdVoid) {492 } else if (container_type->id == TypeTableEntryIdVoid) {
493 return false;493 return false;
494 } else if (container_type->id == TypeTableEntryIdUnreachable) {
495 ef->root->abort = true;
496 ErrorMsg *msg = add_node_error(ef->root->codegen, ef->root->fn->fn_def_node,
497 buf_sprintf("function evaluation reached unreachable expression"));
498 add_error_note(ef->root->codegen, msg, ef->root->call_node, buf_sprintf("called from here"));
499 add_error_note(ef->root->codegen, msg, node, buf_sprintf("unreachable expression here"));
500 return true;
501 } else if (container_type->id == TypeTableEntryIdStruct &&494 } else if (container_type->id == TypeTableEntryIdStruct &&
502 container_type->data.structure.is_slice &&495 container_type->data.structure.is_slice &&
503 kind == ContainerInitKindArray)496 kind == ContainerInitKindArray)
...@@ -791,6 +784,15 @@ static bool eval_div_exact(EvalFn *ef, AstNode *node, ConstExprValue *out_val) {...@@ -791,6 +784,15 @@ static bool eval_div_exact(EvalFn *ef, AstNode *node, ConstExprValue *out_val) {
791 return false;784 return false;
792}785}
793786
787static bool eval_unreachable(EvalFn *ef, AstNode *node, ConstExprValue *out_val) {
788 ef->root->abort = true;
789 ErrorMsg *msg = add_node_error(ef->root->codegen, ef->root->fn->fn_def_node,
790 buf_sprintf("function evaluation reached unreachable expression"));
791 add_error_note(ef->root->codegen, msg, ef->root->call_node, buf_sprintf("called from here"));
792 add_error_note(ef->root->codegen, msg, node, buf_sprintf("unreachable expression here"));
793 return true;
794}
795
794static bool eval_fn_with_overflow(EvalFn *ef, AstNode *node, ConstExprValue *out_val,796static bool eval_fn_with_overflow(EvalFn *ef, AstNode *node, ConstExprValue *out_val,
795 bool (*bignum_fn)(BigNum *dest, BigNum *op1, BigNum *op2))797 bool (*bignum_fn)(BigNum *dest, BigNum *op1, BigNum *op2))
796{798{
...@@ -851,6 +853,8 @@ static bool eval_fn_call_builtin(EvalFn *ef, AstNode *node, ConstExprValue *out_...@@ -851,6 +853,8 @@ static bool eval_fn_call_builtin(EvalFn *ef, AstNode *node, ConstExprValue *out_
851 return false;853 return false;
852 case BuiltinFnIdDivExact:854 case BuiltinFnIdDivExact:
853 return eval_div_exact(ef, node, out_val);855 return eval_div_exact(ef, node, out_val);
856 case BuiltinFnIdUnreachable:
857 return eval_unreachable(ef, node, out_val);
854 case BuiltinFnIdMemcpy:858 case BuiltinFnIdMemcpy:
855 case BuiltinFnIdMemset:859 case BuiltinFnIdMemset:
856 case BuiltinFnIdSizeof:860 case BuiltinFnIdSizeof:
std/compiler_rt.zig+1-1
...@@ -266,5 +266,5 @@ fn test_one_udivmoddi4(a: du_int, b: du_int, expected_q: du_int, expected_r: du_...@@ -266,5 +266,5 @@ fn test_one_udivmoddi4(a: du_int, b: du_int, expected_q: du_int, expected_r: du_
266}266}
267267
268fn assert(b: bool) {268fn assert(b: bool) {
269 if (!b) unreachable{};269 if (!b) @unreachable();
270}270}
std/debug.zig+1-1
...@@ -9,7 +9,7 @@ pub error InvalidDebugInfo;...@@ -9,7 +9,7 @@ pub error InvalidDebugInfo;
9pub error UnsupportedDebugInfo;9pub error UnsupportedDebugInfo;
1010
11pub fn assert(b: bool) {11pub fn assert(b: bool) {
12 if (!b) unreachable{}12 if (!b) @unreachable()
13}13}
1414
15pub fn printStackTrace() -> %void {15pub fn printStackTrace() -> %void {
std/hash_map.zig+4-4
...@@ -55,7 +55,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b...@@ -55,7 +55,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
55 return entry;55 return entry;
56 }56 }
57 }57 }
58 unreachable{} // no next item58 @unreachable() // no next item
59 }59 }
60 }60 }
61 61
...@@ -137,9 +137,9 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b...@@ -137,9 +137,9 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
137 entry.distance_from_start_index -= 1;137 entry.distance_from_start_index -= 1;
138 entry = next_entry;138 entry = next_entry;
139 }139 }
140 unreachable{} // shifting everything in the table140 @unreachable() // shifting everything in the table
141 }}141 }}
142 unreachable{} // key not found142 @unreachable() // key not found
143 }143 }
144144
145 pub fn entryIterator(hm: &Self) -> Iterator {145 pub fn entryIterator(hm: &Self) -> Iterator {
...@@ -210,7 +210,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b...@@ -210,7 +210,7 @@ pub struct SmallHashMap(K: type, V: type, hash: fn(key: K)->u32, eql: fn(a: K, b
210 };210 };
211 return;211 return;
212 }212 }
213 unreachable{} // put into a full map213 @unreachable() // put into a full map
214 }214 }
215215
216 fn internalGet(hm: &Self, key: K) -> ?&Entry {216 fn internalGet(hm: &Self, key: K) -> ?&Entry {
std/io.zig+7-7
...@@ -116,7 +116,7 @@ pub struct OutStream {...@@ -116,7 +116,7 @@ pub struct OutStream {
116 return switch (write_err) {116 return switch (write_err) {
117 errno.EINTR => continue,117 errno.EINTR => continue,
118118
119 errno.EINVAL => unreachable{},119 errno.EINVAL => @unreachable(),
120 errno.EDQUOT => error.DiskQuota,120 errno.EDQUOT => error.DiskQuota,
121 errno.EFBIG => error.FileTooBig,121 errno.EFBIG => error.FileTooBig,
122 errno.EIO => error.Io,122 errno.EIO => error.Io,
...@@ -165,8 +165,8 @@ pub struct InStream {...@@ -165,8 +165,8 @@ pub struct InStream {
165 return switch (err) {165 return switch (err) {
166 errno.EINTR => continue,166 errno.EINTR => continue,
167167
168 errno.EFAULT => unreachable{},168 errno.EFAULT => @unreachable(),
169 errno.EINVAL => unreachable{},169 errno.EINVAL => @unreachable(),
170 errno.EACCES => error.BadPerm,170 errno.EACCES => error.BadPerm,
171 errno.EFBIG, errno.EOVERFLOW => error.FileTooBig,171 errno.EFBIG, errno.EOVERFLOW => error.FileTooBig,
172 errno.EISDIR => error.IsDir,172 errno.EISDIR => error.IsDir,
...@@ -228,8 +228,8 @@ pub struct InStream {...@@ -228,8 +228,8 @@ pub struct InStream {
228 switch (read_err) {228 switch (read_err) {
229 errno.EINTR => continue,229 errno.EINTR => continue,
230230
231 errno.EINVAL => unreachable{},231 errno.EINVAL => @unreachable(),
232 errno.EFAULT => unreachable{},232 errno.EFAULT => @unreachable(),
233 errno.EBADF => return error.BadFd,233 errno.EBADF => return error.BadFd,
234 errno.EIO => return error.Io,234 errno.EIO => return error.Io,
235 else => return error.Unexpected,235 else => return error.Unexpected,
...@@ -426,9 +426,9 @@ fn bufPrintUnsigned(inline T: type, out_buf: []u8, x: T) -> usize {...@@ -426,9 +426,9 @@ fn bufPrintUnsigned(inline T: type, out_buf: []u8, x: T) -> usize {
426fn parseU64DigitTooBig() {426fn parseU64DigitTooBig() {
427 parseUnsigned(u64, "123a", 10) %% |err| {427 parseUnsigned(u64, "123a", 10) %% |err| {
428 if (err == error.InvalidChar) return;428 if (err == error.InvalidChar) return;
429 unreachable{};429 @unreachable();
430 };430 };
431 unreachable{};431 @unreachable();
432}432}
433433
434pub fn openSelfExe(stream: &InStream) -> %void {434pub fn openSelfExe(stream: &InStream) -> %void {
std/linux.zig+1-1
...@@ -299,7 +299,7 @@ pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {...@@ -299,7 +299,7 @@ pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
299299
300pub fn exit(status: i32) -> unreachable {300pub fn exit(status: i32) -> unreachable {
301 arch.syscall1(arch.SYS_exit, usize(status));301 arch.syscall1(arch.SYS_exit, usize(status));
302 unreachable{}302 @unreachable()
303}303}
304304
305pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {305pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
std/net.zig+13-13
...@@ -21,8 +21,8 @@ struct Connection {...@@ -21,8 +21,8 @@ struct Connection {
21 const send_err = linux.getErrno(send_ret);21 const send_err = linux.getErrno(send_ret);
22 switch (send_err) {22 switch (send_err) {
23 0 => return send_ret,23 0 => return send_ret,
24 errno.EINVAL => unreachable{},24 errno.EINVAL => @unreachable(),
25 errno.EFAULT => unreachable{},25 errno.EFAULT => @unreachable(),
26 errno.ECONNRESET => return error.ConnectionReset,26 errno.ECONNRESET => return error.ConnectionReset,
27 errno.EINTR => return error.SigInterrupt,27 errno.EINTR => return error.SigInterrupt,
28 // TODO there are more possible errors28 // TODO there are more possible errors
...@@ -35,8 +35,8 @@ struct Connection {...@@ -35,8 +35,8 @@ struct Connection {
35 const recv_err = linux.getErrno(recv_ret);35 const recv_err = linux.getErrno(recv_ret);
36 switch (recv_err) {36 switch (recv_err) {
37 0 => return buf[0...recv_ret],37 0 => return buf[0...recv_ret],
38 errno.EINVAL => unreachable{},38 errno.EINVAL => @unreachable(),
39 errno.EFAULT => unreachable{},39 errno.EFAULT => @unreachable(),
40 errno.ENOTSOCK => return error.NotSocket,40 errno.ENOTSOCK => return error.NotSocket,
41 errno.EINTR => return error.SigInterrupt,41 errno.EINTR => return error.SigInterrupt,
42 errno.ENOMEM => return error.NoMem,42 errno.ENOMEM => return error.NoMem,
...@@ -50,7 +50,7 @@ struct Connection {...@@ -50,7 +50,7 @@ struct Connection {
50 pub fn close(c: Connection) -> %void {50 pub fn close(c: Connection) -> %void {
51 switch (linux.getErrno(linux.close(c.socket_fd))) {51 switch (linux.getErrno(linux.close(c.socket_fd))) {
52 0 => return,52 0 => return,
53 errno.EBADF => unreachable{},53 errno.EBADF => @unreachable(),
54 errno.EINTR => return error.SigInterrupt,54 errno.EINTR => return error.SigInterrupt,
55 errno.EIO => return error.Io,55 errno.EIO => return error.Io,
56 else => return error.Unexpected,56 else => return error.Unexpected,
...@@ -74,7 +74,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {...@@ -74,7 +74,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
74// if (family != AF_INET)74// if (family != AF_INET)
75// buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };75// buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };
76//76//
77 unreachable{} // TODO77 @unreachable() // TODO
78 }78 }
7979
80 switch (parseIpLiteral(hostname)) {80 switch (parseIpLiteral(hostname)) {
...@@ -85,7 +85,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {...@@ -85,7 +85,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
85 else => {},85 else => {},
86 };86 };
8787
88 unreachable{} // TODO88 @unreachable() // TODO
89}89}
9090
91pub fn connectAddr(addr: &Address, port: u16) -> %Connection {91pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
...@@ -113,7 +113,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {...@@ -113,7 +113,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
113 @memcpy(&os_addr.addr[0], &addr.addr[0], 16);113 @memcpy(&os_addr.addr[0], &addr.addr[0], 16);
114 linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in6))114 linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in6))
115 } else {115 } else {
116 unreachable{}116 @unreachable()
117 };117 };
118 const connect_err = linux.getErrno(connect_ret);118 const connect_err = linux.getErrno(connect_ret);
119 if (connect_err > 0) {119 if (connect_err > 0) {
...@@ -321,11 +321,11 @@ fn parseIp4(buf: []const u8) -> %u32 {...@@ -321,11 +321,11 @@ fn parseIp4(buf: []const u8) -> %u32 {
321#attribute("test")321#attribute("test")
322fn testParseIp4() {322fn testParseIp4() {
323 assert(%%parseIp4("127.0.0.1") == endian.swapIfLe(u32, 0x7f000001));323 assert(%%parseIp4("127.0.0.1") == endian.swapIfLe(u32, 0x7f000001));
324 switch (parseIp4("256.0.0.1")) { Overflow => {}, else => unreachable {}, }324 switch (parseIp4("256.0.0.1")) { Overflow => {}, else => @unreachable(), }
325 switch (parseIp4("x.0.0.1")) { InvalidChar => {}, else => unreachable {}, }325 switch (parseIp4("x.0.0.1")) { InvalidChar => {}, else => @unreachable(), }
326 switch (parseIp4("127.0.0.1.1")) { JunkAtEnd => {}, else => unreachable {}, }326 switch (parseIp4("127.0.0.1.1")) { JunkAtEnd => {}, else => @unreachable(), }
327 switch (parseIp4("127.0.0.")) { Incomplete => {}, else => unreachable {}, }327 switch (parseIp4("127.0.0.")) { Incomplete => {}, else => @unreachable(), }
328 switch (parseIp4("100..0.1")) { InvalidChar => {}, else => unreachable {}, }328 switch (parseIp4("100..0.1")) { InvalidChar => {}, else => @unreachable(), }
329}329}
330330
331#attribute("test")331#attribute("test")
std/os.zig+2-2
...@@ -11,8 +11,8 @@ pub fn getRandomBytes(buf: []u8) -> %void {...@@ -11,8 +11,8 @@ pub fn getRandomBytes(buf: []u8) -> %void {
11 const err = linux.getErrno(ret);11 const err = linux.getErrno(ret);
12 if (err > 0) {12 if (err > 0) {
13 return switch (err) {13 return switch (err) {
14 errno.EINVAL => unreachable{},14 errno.EINVAL => @unreachable(),
15 errno.EFAULT => unreachable{},15 errno.EFAULT => @unreachable(),
16 errno.EINTR => error.SigInterrupt,16 errno.EINTR => error.SigInterrupt,
17 else => error.Unexpected,17 else => error.Unexpected,
18 }18 }
test/run_tests.cpp+2-2
...@@ -485,8 +485,8 @@ pub fn main(args: [][]u8) -> %void {...@@ -485,8 +485,8 @@ pub fn main(args: [][]u8) -> %void {
485const c = @cImport(@cInclude("stdlib.h"));485const c = @cImport(@cInclude("stdlib.h"));
486486
487export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {487export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {
488 const a_int = (&i32)(a ?? unreachable{});488 const a_int = (&i32)(a ?? @unreachable());
489 const b_int = (&i32)(b ?? unreachable{});489 const b_int = (&i32)(b ?? @unreachable());
490 if (*a_int < *b_int) {490 if (*a_int < *b_int) {
491 -1491 -1
492 } else if (*a_int > *b_int) {492 } else if (*a_int > *b_int) {
test/self_hosted.zig+27-27
...@@ -25,20 +25,20 @@ fn ifStatements() {...@@ -25,20 +25,20 @@ fn ifStatements() {
25}25}
26fn shouldBeEqual(a: i32, b: i32) {26fn shouldBeEqual(a: i32, b: i32) {
27 if (a != b) {27 if (a != b) {
28 unreachable{};28 @unreachable();
29 } else {29 } else {
30 return;30 return;
31 }31 }
32}32}
33fn firstEqlThird(a: i32, b: i32, c: i32) {33fn firstEqlThird(a: i32, b: i32, c: i32) {
34 if (a == b) {34 if (a == b) {
35 unreachable{};35 @unreachable();
36 } else if (b == c) {36 } else if (b == c) {
37 unreachable{};37 @unreachable();
38 } else if (a == c) {38 } else if (a == c) {
39 return;39 return;
40 } else {40 } else {
41 unreachable{};41 @unreachable();
42 }42 }
43}43}
4444
...@@ -58,7 +58,7 @@ fn localVariables() {...@@ -58,7 +58,7 @@ fn localVariables() {
58}58}
59fn testLocVars(b: i32) {59fn testLocVars(b: i32) {
60 const a: i32 = 1;60 const a: i32 = 1;
61 if (a + b != 3) unreachable{};61 if (a + b != 3) @unreachable();
62}62}
6363
64#attribute("test")64#attribute("test")
...@@ -145,7 +145,7 @@ fn shortCircuit() {...@@ -145,7 +145,7 @@ fn shortCircuit() {
145145
146#static_eval_enable(false)146#static_eval_enable(false)
147fn assertRuntime(b: bool) {147fn assertRuntime(b: bool) {
148 if (!b) unreachable{}148 if (!b) @unreachable()
149}149}
150150
151#attribute("test")151#attribute("test")
...@@ -328,10 +328,10 @@ fn maybeType() {...@@ -328,10 +328,10 @@ fn maybeType() {
328 if (y) {328 if (y) {
329 // OK329 // OK
330 } else {330 } else {
331 unreachable{};331 @unreachable();
332 }332 }
333 } else {333 } else {
334 unreachable{};334 @unreachable();
335 }335 }
336336
337 const next_x : ?i32 = null;337 const next_x : ?i32 = null;
...@@ -342,7 +342,7 @@ fn maybeType() {...@@ -342,7 +342,7 @@ fn maybeType() {
342342
343 const final_x : ?i32 = 13;343 const final_x : ?i32 = 13;
344344
345 const num = final_x ?? unreachable{};345 const num = final_x ?? @unreachable();
346346
347 assert(num == 13);347 assert(num == 13);
348}348}
...@@ -360,7 +360,7 @@ fn enumType() {...@@ -360,7 +360,7 @@ fn enumType() {
360 const expected_foo_size = switch (@compileVar("arch")) {360 const expected_foo_size = switch (@compileVar("arch")) {
361 i386 => 20,361 i386 => 20,
362 x86_64 => 24,362 x86_64 => 24,
363 else => unreachable{},363 else => @unreachable(),
364 };364 };
365 assert(@sizeOf(EnumTypeFoo) == expected_foo_size);365 assert(@sizeOf(EnumTypeFoo) == expected_foo_size);
366 assert(@sizeOf(EnumTypeBar) == 1);366 assert(@sizeOf(EnumTypeBar) == 1);
...@@ -437,7 +437,7 @@ error AnError;...@@ -437,7 +437,7 @@ error AnError;
437error AnError;437error AnError;
438error SecondError;438error SecondError;
439fn shouldBeNotEqual(a: error, b: error) {439fn shouldBeNotEqual(a: error, b: error) {
440 if (a == b) unreachable{}440 if (a == b) @unreachable()
441}441}
442442
443443
...@@ -454,13 +454,13 @@ fn constantEnumWithPayload() {...@@ -454,13 +454,13 @@ fn constantEnumWithPayload() {
454fn shouldBeEmpty(x: AnEnumWithPayload) {454fn shouldBeEmpty(x: AnEnumWithPayload) {
455 switch (x) {455 switch (x) {
456 Empty => {},456 Empty => {},
457 else => unreachable{},457 else => @unreachable(),
458 }458 }
459}459}
460460
461fn shouldBeNotEmpty(x: AnEnumWithPayload) {461fn shouldBeNotEmpty(x: AnEnumWithPayload) {
462 switch (x) {462 switch (x) {
463 Empty => unreachable{},463 Empty => @unreachable(),
464 else => {},464 else => {},
465 }465 }
466}466}
...@@ -482,7 +482,7 @@ fn continueInForLoop() {...@@ -482,7 +482,7 @@ fn continueInForLoop() {
482 }482 }
483 break;483 break;
484 }484 }
485 if (sum != 6) unreachable{}485 if (sum != 6) @unreachable()
486}486}
487487
488488
...@@ -514,9 +514,9 @@ enum Fruit {...@@ -514,9 +514,9 @@ enum Fruit {
514#static_eval_enable(false)514#static_eval_enable(false)
515fn nonConstSwitchOnEnum(fruit: Fruit) {515fn nonConstSwitchOnEnum(fruit: Fruit) {
516 switch (fruit) {516 switch (fruit) {
517 Apple => unreachable{},517 Apple => @unreachable(),
518 Orange => {},518 Orange => {},
519 Banana => unreachable{},519 Banana => @unreachable(),
520 }520 }
521}521}
522522
...@@ -532,7 +532,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) {...@@ -532,7 +532,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) {
532 C => 3,532 C => 3,
533 D => 4,533 D => 4,
534 };534 };
535 if (val != 3) unreachable{};535 if (val != 3) @unreachable();
536}536}
537enum SwitchStatmentFoo {537enum SwitchStatmentFoo {
538 A,538 A,
...@@ -557,10 +557,10 @@ enum SwitchProngWithVarEnum {...@@ -557,10 +557,10 @@ enum SwitchProngWithVarEnum {
557fn switchProngWithVarFn(a: SwitchProngWithVarEnum) {557fn switchProngWithVarFn(a: SwitchProngWithVarEnum) {
558 switch(a) {558 switch(a) {
559 One => |x| {559 One => |x| {
560 if (x != 13) unreachable{};560 if (x != 13) @unreachable();
561 },561 },
562 Two => |x| {562 Two => |x| {
563 if (x != 13.0) unreachable{};563 if (x != 13.0) @unreachable();
564 },564 },
565 Meh => |x| {565 Meh => |x| {
566 const v: void = x;566 const v: void = x;
...@@ -601,7 +601,7 @@ fn implicitCastFnUnreachableReturn() {...@@ -601,7 +601,7 @@ fn implicitCastFnUnreachableReturn() {
601fn wantsFnWithVoid(f: fn()) { }601fn wantsFnWithVoid(f: fn()) { }
602602
603fn fnWithUnreachable() -> unreachable {603fn fnWithUnreachable() -> unreachable {
604 unreachable {}604 @unreachable()
605}605}
606606
607607
...@@ -644,13 +644,13 @@ fn slicing() {...@@ -644,13 +644,13 @@ fn slicing() {
644644
645 var slice = array[5...10];645 var slice = array[5...10];
646646
647 if (slice.len != 5) unreachable{};647 if (slice.len != 5) @unreachable();
648648
649 const ptr = &slice[0];649 const ptr = &slice[0];
650 if (ptr[0] != 1234) unreachable{};650 if (ptr[0] != 1234) @unreachable();
651651
652 var slice_rest = array[10...];652 var slice_rest = array[10...];
653 if (slice_rest.len != 10) unreachable{};653 if (slice_rest.len != 10) @unreachable();
654}654}
655655
656656
...@@ -662,7 +662,7 @@ fn memcpyAndMemsetIntrinsics() {...@@ -662,7 +662,7 @@ fn memcpyAndMemsetIntrinsics() {
662 @memset(&foo[0], 'A', foo.len);662 @memset(&foo[0], 'A', foo.len);
663 @memcpy(&bar[0], &foo[0], bar.len);663 @memcpy(&bar[0], &foo[0], bar.len);
664664
665 if (bar[11] != 'A') unreachable{};665 if (bar[11] != 'A') @unreachable();
666}666}
667667
668668
...@@ -807,7 +807,7 @@ exit:...@@ -807,7 +807,7 @@ exit:
807 if (it_worked) {807 if (it_worked) {
808 return;808 return;
809 }809 }
810 unreachable{};810 @unreachable();
811entry:811entry:
812 defer it_worked = true;812 defer it_worked = true;
813 if (b) goto exit;813 if (b) goto exit;
...@@ -1221,7 +1221,7 @@ fn test3_1(f: Test3Foo) {...@@ -1221,7 +1221,7 @@ fn test3_1(f: Test3Foo) {
1221 assert(pt.x == 3);1221 assert(pt.x == 3);
1222 assert(pt.y == 4);1222 assert(pt.y == 4);
1223 },1223 },
1224 else => unreachable{},1224 else => @unreachable(),
1225 }1225 }
1226}1226}
1227#static_eval_enable(false)1227#static_eval_enable(false)
...@@ -1230,7 +1230,7 @@ fn test3_2(f: Test3Foo) {...@@ -1230,7 +1230,7 @@ fn test3_2(f: Test3Foo) {
1230 Two => |x| {1230 Two => |x| {
1231 assert(x == 13);1231 assert(x == 13);
1232 },1232 },
1233 else => unreachable{},1233 else => @unreachable(),
1234 }1234 }
1235}1235}
12361236