authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-26 04:58:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-26 04:58:48-04:00
log451ce090674d6d5f2c23e6667047e1e479917c93
treecbe8722f059086fdf30a76ce94d1ac16086dacd5
parent22e6bfca9602fdb79f669b494fa7f1c58094706c

new unreachable syntax

* `noreturn` is the primitive type. * `unreachable` is a control flow keyword. * `@unreachable()` builtin function is deleted. closes #214

35 files changed, 130 insertions(+), 192 deletions(-)

doc/langref.md+1-84
......@@ -155,7 +155,7 @@ GotoExpression = "goto" Symbol
155155
156156GroupedExpression = "(" Expression ")"
157157
158KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this"
158KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this" | "unreachable"
159159
160160ContainerDecl = option("extern" | "packed") ("struct" | "enum" | "union") "{" many(ContainerMember) "}"
161161
......@@ -213,60 +213,6 @@ f32 float 32-bit floating point
213213f64 double 64-bit floating point
214214```
215215
216### Boolean Type
217
218The boolean type has the name `bool` and represents either true or false.
219
220### Function Type
221
222TODO
223
224### Fixed-Size Array Type
225
226Example: The string `"aoeu"` has type `[4]u8`.
227
228The size is known at compile time and is part of the type.
229
230### Slice Type
231
232A slice can be obtained with the slicing syntax: `array[start...end]`
233
234Example: `"aoeu"[0...2]` has type `[]u8`.
235
236### Struct Type
237
238TODO
239
240### Enum Type
241
242TODO
243
244### Maybe Type
245
246TODO
247
248### Pure Error Type
249
250TODO
251
252### Error Union Type
253
254TODO
255
256### Pointer Type
257
258TODO
259
260### Unreachable Type
261
262The unreachable type has the name `unreachable`. TODO explanation
263
264### Void Type
265
266The void type has the name `void`. void types are zero bits and are omitted
267from codegen.
268
269
270216## Expressions
271217
272218### Literals
......@@ -347,31 +293,6 @@ has a terminating null byte.
347293 Floating point | 123.0E+77 | Optional
348294 Hex floating point | 0x103.70p-5 | Optional
349295
350### Identifiers
351
352TODO
353
354### Declarations
355
356Declarations have type `void`.
357
358#### Function Declarations
359
360TODO
361
362#### Variable Declarations
363
364TODO
365
366#### Struct Declarations
367
368TODO
369
370#### Enum Declarations
371
372TODO
373
374
375296## Built-in Functions
376297
377298Built-in functions are prefixed with `@`. Remember that the `comptime` keyword on
......@@ -682,10 +603,6 @@ code.
682603
683604This function returns an integer type with the given signness and bit count.
684605
685### @setFnTest(func)
686
687Makes the target function a test function.
688
689606### @setDebugSafety(scope, safety_on: bool)
690607
691608Sets a whether we want debug safety checks on for a given scope.
doc/vim/syntax/zig.vim+1-1
......@@ -16,7 +16,7 @@ syn keyword zigRepeat while for
1616
1717syn keyword zigConstant null undefined this
1818syn keyword zigKeyword fn use test
19syn keyword zigType bool f32 f64 void Unreachable type error
19syn keyword zigType bool f32 f64 void noreturn type error
2020syn keyword zigType i8 u8 i16 u16 i32 u32 i64 u64 isize usize
2121syn keyword zigType c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong c_long_double
2222
src/all_types.hpp+5-1
......@@ -334,6 +334,7 @@ enum NodeType {
334334 NodeTypeNullLiteral,
335335 NodeTypeUndefinedLiteral,
336336 NodeTypeThisLiteral,
337 NodeTypeUnreachable,
337338 NodeTypeIfBoolExpr,
338339 NodeTypeIfVarExpr,
339340 NodeTypeWhileExpr,
......@@ -758,6 +759,9 @@ struct AstNodeBreakExpr {
758759
759760struct AstNodeContinueExpr {
760761};
762struct AstNodeUnreachableExpr {
763};
764
761765
762766struct AstNodeArrayType {
763767 AstNode *size;
......@@ -827,6 +831,7 @@ struct AstNode {
827831 AstNodeBoolLiteral bool_literal;
828832 AstNodeBreakExpr break_expr;
829833 AstNodeContinueExpr continue_expr;
834 AstNodeUnreachableExpr unreachable_expr;
830835 AstNodeArrayType array_type;
831836 AstNodeErrorType error_type;
832837 AstNodeTypeLiteral type_literal;
......@@ -1173,7 +1178,6 @@ enum BuiltinFnId {
11731178 BuiltinFnIdDivExact,
11741179 BuiltinFnIdTruncate,
11751180 BuiltinFnIdIntType,
1176 BuiltinFnIdUnreachable,
11771181 BuiltinFnIdSetFnVisible,
11781182 BuiltinFnIdSetDebugSafety,
11791183 BuiltinFnIdAlloca,
src/analyze.cpp+1
......@@ -2110,6 +2110,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
21102110 case NodeTypeGoto:
21112111 case NodeTypeBreak:
21122112 case NodeTypeContinue:
2113 case NodeTypeUnreachable:
21132114 case NodeTypeAsmExpr:
21142115 case NodeTypeFieldAccessExpr:
21152116 case NodeTypeStructField:
src/ast_render.cpp+7
......@@ -216,6 +216,8 @@ static const char *node_type_str(NodeType node_type) {
216216 return "Break";
217217 case NodeTypeContinue:
218218 return "Continue";
219 case NodeTypeUnreachable:
220 return "Unreachable";
219221 case NodeTypeAsmExpr:
220222 return "AsmExpr";
221223 case NodeTypeFieldAccessExpr:
......@@ -890,6 +892,11 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
890892 fprintf(ar->f, "continue");
891893 break;
892894 }
895 case NodeTypeUnreachable:
896 {
897 fprintf(ar->f, "unreachable");
898 break;
899 }
893900 case NodeTypeSliceExpr:
894901 {
895902 render_node_ungrouped(ar, node->data.slice_expr.array_ref_expr);
src/codegen.cpp+1-2
......@@ -3786,7 +3786,7 @@ static void define_builtin_types(CodeGen *g) {
37863786 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUnreachable);
37873787 entry->type_ref = LLVMVoidType();
37883788 entry->zero_bits = true;
3789 buf_init_from_str(&entry->name, "unreachable");
3789 buf_init_from_str(&entry->name, "noreturn");
37903790 entry->di_type = g->builtin_types.entry_void->di_type;
37913791 g->builtin_types.entry_unreachable = entry;
37923792 g->primitive_type_table.put(&entry->name, entry);
......@@ -4096,7 +4096,6 @@ static void define_builtin_fns(CodeGen *g) {
40964096 create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);
40974097 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
40984098 create_builtin_fn(g, BuiltinFnIdIntType, "intType", 2);
4099 create_builtin_fn(g, BuiltinFnIdUnreachable, "unreachable", 0);
41004099 create_builtin_fn(g, BuiltinFnIdSetFnVisible, "setFnVisible", 2);
41014100 create_builtin_fn(g, BuiltinFnIdSetDebugSafety, "setDebugSafety", 2);
41024101 create_builtin_fn(g, BuiltinFnIdAlloca, "alloca", 2);
src/ir.cpp+2-2
......@@ -3751,8 +3751,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
37513751 switch (builtin_fn->id) {
37523752 case BuiltinFnIdInvalid:
37533753 zig_unreachable();
3754 case BuiltinFnIdUnreachable:
3755 return ir_build_unreachable(irb, scope, node);
37563754 case BuiltinFnIdTypeof:
37573755 {
37583756 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
......@@ -5467,6 +5465,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
54675465 return ir_lval_wrap(irb, scope, ir_gen_break(irb, scope, node), lval);
54685466 case NodeTypeContinue:
54695467 return ir_lval_wrap(irb, scope, ir_gen_continue(irb, scope, node), lval);
5468 case NodeTypeUnreachable:
5469 return ir_lval_wrap(irb, scope, ir_build_unreachable(irb, scope, node), lval);
54705470 case NodeTypeDefer:
54715471 return ir_lval_wrap(irb, scope, ir_gen_defer(irb, scope, node), lval);
54725472 case NodeTypeSliceExpr:
src/parser.cpp+8-1
......@@ -705,7 +705,7 @@ static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool m
705705
706706/*
707707PrimaryExpression = Number | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | Symbol | ("@" Symbol FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." Symbol) | ContainerDecl
708KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this"
708KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this" | "unreachable"
709709*/
710710static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
711711 Token *token = &pc->tokens->at(*token_index);
......@@ -757,6 +757,10 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
757757 AstNode *node = ast_create_node(pc, NodeTypeThisLiteral, token);
758758 *token_index += 1;
759759 return node;
760 } else if (token->id == TokenIdKeywordUnreachable) {
761 AstNode *node = ast_create_node(pc, NodeTypeUnreachable, token);
762 *token_index += 1;
763 return node;
760764 } else if (token->id == TokenIdKeywordType) {
761765 AstNode *node = ast_create_node(pc, NodeTypeTypeLiteral, token);
762766 *token_index += 1;
......@@ -2728,6 +2732,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
27282732 case NodeTypeContinue:
27292733 // none
27302734 break;
2735 case NodeTypeUnreachable:
2736 // none
2737 break;
27312738 case NodeTypeAsmExpr:
27322739 for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
27332740 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);
src/tokenizer.cpp+2
......@@ -140,6 +140,7 @@ static const struct ZigKeyword zig_keywords[] = {
140140 {"type", TokenIdKeywordType},
141141 {"undefined", TokenIdKeywordUndefined},
142142 {"union", TokenIdKeywordUnion},
143 {"unreachable", TokenIdKeywordUnreachable},
143144 {"use", TokenIdKeywordUse},
144145 {"var", TokenIdKeywordVar},
145146 {"volatile", TokenIdKeywordVolatile},
......@@ -1516,6 +1517,7 @@ const char * token_name(TokenId id) {
15161517 case TokenIdKeywordType: return "type";
15171518 case TokenIdKeywordUndefined: return "undefined";
15181519 case TokenIdKeywordUnion: return "union";
1520 case TokenIdKeywordUnreachable: return "unreachable";
15191521 case TokenIdKeywordUse: return "use";
15201522 case TokenIdKeywordVar: return "var";
15211523 case TokenIdKeywordVolatile: return "volatile";
src/tokenizer.hpp+1
......@@ -81,6 +81,7 @@ enum TokenId {
8181 TokenIdKeywordType,
8282 TokenIdKeywordUndefined,
8383 TokenIdKeywordUnion,
84 TokenIdKeywordUnreachable,
8485 TokenIdKeywordUse,
8586 TokenIdKeywordVar,
8687 TokenIdKeywordVolatile,
std/bootstrap.zig+4-4
......@@ -16,10 +16,10 @@ const exit = switch(@compileVar("os")) {
1616var argc: usize = undefined;
1717var argv: &&u8 = undefined;
1818
19export nakedcc fn _start() -> unreachable {
19export nakedcc fn _start() -> noreturn {
2020 @setFnVisible(this, want_start_symbol);
2121 if (!want_start_symbol) {
22 @unreachable();
22 unreachable;
2323 }
2424
2525 switch (@compileVar("arch")) {
......@@ -45,7 +45,7 @@ fn callMain() -> %void {
4545 return root.main(args);
4646}
4747
48fn callMainAndExit() -> unreachable {
48fn callMainAndExit() -> noreturn {
4949 callMain() %% exit(1);
5050 exit(0);
5151}
......@@ -53,7 +53,7 @@ fn callMainAndExit() -> unreachable {
5353export fn main(c_argc: i32, c_argv: &&u8) -> i32 {
5454 @setFnVisible(this, want_main_symbol);
5555 if (!want_main_symbol) {
56 @unreachable();
56 unreachable;
5757 }
5858
5959 argc = usize(c_argc);
std/builtin.zig+2-2
......@@ -31,6 +31,6 @@ export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
3131}
3232
3333// Avoid dragging in the debug safety mechanisms into this .o file.
34pub fn panic(message: []const u8) -> unreachable {
35 @unreachable();
34pub fn panic(message: []const u8) -> noreturn {
35 unreachable;
3636}
std/c/index.zig+1-1
......@@ -7,7 +7,7 @@ pub use switch(@compileVar("os")) {
77 else => empty_import,
88};
99
10pub extern fn abort() -> unreachable;
10pub extern fn abort() -> noreturn;
1111
1212
1313const empty_import = @import("empty.zig");
std/compiler_rt.zig+4-4
......@@ -1,10 +1,10 @@
11// Avoid dragging in the debug safety mechanisms into this .o file,
22// unless we're trying to test this file.
3pub fn panic(message: []const u8) -> unreachable {
3pub fn panic(message: []const u8) -> noreturn {
44 if (@compileVar("is_test")) {
55 @import("std").debug.panic(message);
66 } else {
7 @unreachable();
7 unreachable;
88 }
99}
1010
......@@ -259,7 +259,7 @@ export nakedcc fn __aeabi_uidivmod() {
259259 \\ add sp, sp, #4
260260 \\ pop { pc }
261261 ::: "r2", "r1");
262 @unreachable();
262 unreachable;
263263 }
264264
265265 @setFnVisible(this, false);
......@@ -511,5 +511,5 @@ fn test_one_udivsi3(a: su_int, b: su_int, expected_q: su_int) {
511511
512512
513513fn assert(ok: bool) {
514 if (!ok) @unreachable();
514 if (!ok) unreachable;
515515}
std/darwin.zig+2-2
......@@ -48,9 +48,9 @@ pub const SIGPWR = 30;
4848pub const SIGSYS = 31;
4949pub const SIGUNUSED = SIGSYS;
5050
51pub fn exit(status: usize) -> unreachable {
51pub fn exit(status: usize) -> noreturn {
5252 _ = arch.syscall1(arch.SYS_exit, status);
53 @unreachable()
53 unreachable
5454}
5555
5656/// Get the errno from a syscall return value, or 0 for no error.
std/debug.zig+3-3
......@@ -10,12 +10,12 @@ error InvalidDebugInfo;
1010error UnsupportedDebugInfo;
1111
1212pub fn assert(ok: bool) {
13 if (!ok) @unreachable()
13 if (!ok) unreachable
1414}
1515
1616var panicking = false;
1717/// This is the default panic implementation.
18pub coldcc fn panic(message: []const u8) -> unreachable {
18pub coldcc fn panic(message: []const u8) -> noreturn {
1919 // TODO
2020 // if (@atomicRmw(AtomicOp.XChg, &panicking, true, AtomicOrder.SeqCst)) { }
2121 if (panicking) {
......@@ -252,7 +252,7 @@ fn parseFormValueTargetAddrSize(in_stream: &io.InStream) -> %u64 {
252252 } else if (@sizeOf(usize) == 8) {
253253 %return in_stream.readIntLe(u64)
254254 } else {
255 @unreachable();
255 unreachable;
256256 };
257257}
258258
std/fmt.zig+3-3
......@@ -287,7 +287,7 @@ fn digitToChar(digit: u8, uppercase: bool) -> u8 {
287287 return switch (digit) {
288288 0 ... 9 => digit + '0',
289289 10 ... 35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10),
290 else => @unreachable(),
290 else => unreachable,
291291 };
292292}
293293
......@@ -316,9 +316,9 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u
316316test "testParseU64DigitTooBig" {
317317 parseUnsigned(u64, "123a", 10) %% |err| {
318318 if (err == error.InvalidChar) return;
319 @unreachable();
319 unreachable;
320320 };
321 @unreachable();
321 unreachable;
322322}
323323
324324test "testParseUnsignedComptime" {
std/hash_map.zig+4-4
......@@ -50,7 +50,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
5050 return entry;
5151 }
5252 }
53 @unreachable() // no next item
53 unreachable // no next item
5454 }
5555 };
5656
......@@ -125,9 +125,9 @@ pub fn HashMap(comptime K: type, comptime V: type,
125125 entry.distance_from_start_index -= 1;
126126 entry = next_entry;
127127 }
128 @unreachable() // shifting everything in the table
128 unreachable // shifting everything in the table
129129 }}
130 @unreachable() // key not found
130 unreachable // key not found
131131 }
132132
133133 pub fn entryIterator(hm: &Self) -> Iterator {
......@@ -198,7 +198,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
198198 };
199199 return;
200200 }
201 @unreachable() // put into a full map
201 unreachable // put into a full map
202202 }
203203
204204 fn internalGet(hm: &Self, key: K) -> ?&Entry {
std/io.zig+5-5
......@@ -129,7 +129,7 @@ pub const OutStream = struct {
129129 if (write_err > 0) {
130130 return switch (write_err) {
131131 errno.EINTR => continue,
132 errno.EINVAL => @unreachable(),
132 errno.EINVAL => unreachable,
133133 errno.EDQUOT => error.DiskQuota,
134134 errno.EFBIG => error.FileTooBig,
135135 errno.EIO => error.Io,
......@@ -171,8 +171,8 @@ pub const InStream = struct {
171171 return switch (err) {
172172 errno.EINTR => continue,
173173
174 errno.EFAULT => @unreachable(),
175 errno.EINVAL => @unreachable(),
174 errno.EFAULT => unreachable,
175 errno.EINVAL => unreachable,
176176 errno.EACCES => error.BadPerm,
177177 errno.EFBIG, errno.EOVERFLOW => error.FileTooBig,
178178 errno.EISDIR => error.IsDir,
......@@ -235,8 +235,8 @@ pub const InStream = struct {
235235 switch (read_err) {
236236 errno.EINTR => continue,
237237
238 errno.EINVAL => @unreachable(),
239 errno.EFAULT => @unreachable(),
238 errno.EINVAL => unreachable,
239 errno.EFAULT => unreachable,
240240 errno.EBADF => return error.BadFd,
241241 errno.EIO => return error.Io,
242242 else => return error.Unexpected,
std/linux.zig+2-2
......@@ -297,9 +297,9 @@ pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
297297 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
298298}
299299
300pub fn exit(status: i32) -> unreachable {
300pub fn exit(status: i32) -> noreturn {
301301 _ = arch.syscall1(arch.SYS_exit, usize(status));
302 @unreachable()
302 unreachable
303303}
304304
305305pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
std/math.zig+1-1
......@@ -57,7 +57,7 @@ pub fn abs(x: var) -> @typeOf(x) {
5757 } else if (@isFloat(T)) {
5858 @compileError("TODO implement abs for floats");
5959 } else {
60 @unreachable();
60 unreachable;
6161 }
6262}
6363fn getReturnTypeForAbs(comptime T: type) -> type {
std/net.zig+13-13
......@@ -21,8 +21,8 @@ const Connection = struct {
2121 const send_err = linux.getErrno(send_ret);
2222 switch (send_err) {
2323 0 => return send_ret,
24 errno.EINVAL => @unreachable(),
25 errno.EFAULT => @unreachable(),
24 errno.EINVAL => unreachable,
25 errno.EFAULT => unreachable,
2626 errno.ECONNRESET => return error.ConnectionReset,
2727 errno.EINTR => return error.SigInterrupt,
2828 // TODO there are more possible errors
......@@ -35,8 +35,8 @@ const Connection = struct {
3535 const recv_err = linux.getErrno(recv_ret);
3636 switch (recv_err) {
3737 0 => return buf[0...recv_ret],
38 errno.EINVAL => @unreachable(),
39 errno.EFAULT => @unreachable(),
38 errno.EINVAL => unreachable,
39 errno.EFAULT => unreachable,
4040 errno.ENOTSOCK => return error.NotSocket,
4141 errno.EINTR => return error.SigInterrupt,
4242 errno.ENOMEM => return error.NoMem,
......@@ -50,7 +50,7 @@ const Connection = struct {
5050 pub fn close(c: Connection) -> %void {
5151 switch (linux.getErrno(linux.close(c.socket_fd))) {
5252 0 => return,
53 errno.EBADF => @unreachable(),
53 errno.EBADF => unreachable,
5454 errno.EINTR => return error.SigInterrupt,
5555 errno.EIO => return error.Io,
5656 else => return error.Unexpected,
......@@ -74,7 +74,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
7474// if (family != AF_INET)
7575// buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };
7676//
77 @unreachable() // TODO
77 unreachable // TODO
7878 }
7979
8080 // TODO
......@@ -86,7 +86,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
8686 // else => {},
8787 //};
8888
89 @unreachable() // TODO
89 unreachable // TODO
9090}
9191
9292pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
......@@ -114,7 +114,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
114114 @memcpy(&os_addr.addr[0], &addr.addr[0], 16);
115115 linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in6))
116116 } else {
117 @unreachable()
117 unreachable
118118 };
119119 const connect_err = linux.getErrno(connect_ret);
120120 if (connect_err > 0) {
......@@ -324,11 +324,11 @@ fn parseIp4(buf: []const u8) -> %u32 {
324324// @setFnTest(this);
325325//
326326// assert(%%parseIp4("127.0.0.1") == endian.swapIfLe(u32, 0x7f000001));
327// switch (parseIp4("256.0.0.1")) { Overflow => {}, else => @unreachable(), }
328// switch (parseIp4("x.0.0.1")) { InvalidChar => {}, else => @unreachable(), }
329// switch (parseIp4("127.0.0.1.1")) { JunkAtEnd => {}, else => @unreachable(), }
330// switch (parseIp4("127.0.0.")) { Incomplete => {}, else => @unreachable(), }
331// switch (parseIp4("100..0.1")) { InvalidChar => {}, else => @unreachable(), }
327// switch (parseIp4("256.0.0.1")) { Overflow => {}, else => unreachable, }
328// switch (parseIp4("x.0.0.1")) { InvalidChar => {}, else => unreachable, }
329// switch (parseIp4("127.0.0.1.1")) { JunkAtEnd => {}, else => unreachable, }
330// switch (parseIp4("127.0.0.")) { Incomplete => {}, else => unreachable, }
331// switch (parseIp4("100..0.1")) { InvalidChar => {}, else => unreachable, }
332332//}
333333//
334334//fn testParseIp6() {
std/os.zig+3-3
......@@ -46,8 +46,8 @@ pub fn getRandomBytes(buf: []u8) -> %void {
4646 };
4747 if (err > 0) {
4848 return switch (err) {
49 errno.EINVAL => @unreachable(),
50 errno.EFAULT => @unreachable(),
49 errno.EINVAL => unreachable,
50 errno.EFAULT => unreachable,
5151 errno.EINTR => continue,
5252 else => error.Unexpected,
5353 }
......@@ -59,7 +59,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
5959/// Raises a signal in the current kernel thread, ending its execution.
6060/// If linking against libc, this calls the abort() libc function. Otherwise
6161/// it uses the zig standard library implementation.
62pub coldcc fn abort() -> unreachable {
62pub coldcc fn abort() -> noreturn {
6363 if (linking_libc) {
6464 c.abort();
6565 }
std/panic.zig+1-1
......@@ -3,7 +3,7 @@
33// If this file wants to import other files *by name*, support for that would
44// have to be added in the compiler.
55
6pub coldcc fn panic(message: []const u8) -> unreachable {
6pub coldcc fn panic(message: []const u8) -> noreturn {
77 if (@compileVar("os") == Os.freestanding) {
88 while (true) {}
99 } else {
test/cases/enum.zig+3-3
......@@ -16,7 +16,7 @@ test "enumType" {
1616test "enumAsReturnValue" {
1717 switch (returnAnInt(13)) {
1818 Foo.One => |value| assert(value == 13),
19 else => @unreachable(),
19 else => unreachable,
2020 }
2121}
2222
......@@ -51,13 +51,13 @@ test "constantEnumWithPayload" {
5151fn shouldBeEmpty(x: &const AnEnumWithPayload) {
5252 switch (*x) {
5353 AnEnumWithPayload.Empty => {},
54 else => @unreachable(),
54 else => unreachable,
5555 }
5656}
5757
5858fn shouldBeNotEmpty(x: &const AnEnumWithPayload) {
5959 switch (*x) {
60 AnEnumWithPayload.Empty => @unreachable(),
60 AnEnumWithPayload.Empty => unreachable,
6161 else => {},
6262 }
6363}
test/cases/error.zig+1-1
......@@ -48,7 +48,7 @@ error AnError;
4848error AnError;
4949error SecondError;
5050fn shouldBeNotEqual(a: error, b: error) {
51 if (a == b) @unreachable()
51 if (a == b) unreachable
5252}
5353
5454
test/cases/fn.zig+3-3
......@@ -13,7 +13,7 @@ test "localVariables" {
1313}
1414fn testLocVars(b: i32) {
1515 const a: i32 = 1;
16 if (a + b != 3) @unreachable();
16 if (a + b != 3) unreachable;
1717}
1818
1919
......@@ -72,8 +72,8 @@ test "implicitCastFnUnreachableReturn" {
7272
7373fn wantsFnWithVoid(f: fn()) { }
7474
75fn fnWithUnreachable() -> unreachable {
76 @unreachable()
75fn fnWithUnreachable() -> noreturn {
76 unreachable
7777}
7878
7979
test/cases/for.zig+1-1
......@@ -12,7 +12,7 @@ test "continueInForLoop" {
1212 }
1313 break;
1414 }
15 if (sum != 6) @unreachable()
15 if (sum != 6) unreachable
1616}
1717
1818test "forLoopWithPointerElemVar" {
test/cases/goto.zig+1-1
......@@ -30,7 +30,7 @@ exit:
3030 if (it_worked) {
3131 return;
3232 }
33 @unreachable();
33 unreachable;
3434entry:
3535 defer it_worked = true;
3636 if (b) goto exit;
test/cases/if.zig+4-4
......@@ -6,20 +6,20 @@ test "ifStatements" {
66}
77fn shouldBeEqual(a: i32, b: i32) {
88 if (a != b) {
9 @unreachable();
9 unreachable;
1010 } else {
1111 return;
1212 }
1313}
1414fn firstEqlThird(a: i32, b: i32, c: i32) {
1515 if (a == b) {
16 @unreachable();
16 unreachable;
1717 } else if (b == c) {
18 @unreachable();
18 unreachable;
1919 } else if (a == c) {
2020 return;
2121 } else {
22 @unreachable();
22 unreachable;
2323 }
2424}
2525
test/cases/misc.zig+6-6
......@@ -163,7 +163,7 @@ test "memcpyAndMemsetIntrinsics" {
163163 @memset(&foo[0], 'A', foo.len);
164164 @memcpy(&bar[0], &foo[0], bar.len);
165165
166 if (bar[11] != 'A') @unreachable();
166 if (bar[11] != 'A') unreachable;
167167}
168168
169169test "builtinStaticEval" {
......@@ -178,13 +178,13 @@ test "slicing" {
178178
179179 var slice = array[5...10];
180180
181 if (slice.len != 5) @unreachable();
181 if (slice.len != 5) unreachable;
182182
183183 const ptr = &slice[0];
184 if (ptr[0] != 1234) @unreachable();
184 if (ptr[0] != 1234) unreachable;
185185
186186 var slice_rest = array[10...];
187 if (slice_rest.len != 10) @unreachable();
187 if (slice_rest.len != 10) unreachable;
188188}
189189
190190
......@@ -344,7 +344,7 @@ fn test3_1(f: &const Test3Foo) {
344344 assert(pt.x == 3);
345345 assert(pt.y == 4);
346346 },
347 else => @unreachable(),
347 else => unreachable,
348348 }
349349}
350350fn test3_2(f: &const Test3Foo) {
......@@ -352,7 +352,7 @@ fn test3_2(f: &const Test3Foo) {
352352 Test3Foo.Two => |x| {
353353 assert(x == 13);
354354 },
355 else => @unreachable(),
355 else => unreachable,
356356 }
357357}
358358
test/cases/null.zig+3-3
......@@ -7,10 +7,10 @@ test "nullableType" {
77 if (y) {
88 // OK
99 } else {
10 @unreachable();
10 unreachable;
1111 }
1212 } else {
13 @unreachable();
13 unreachable;
1414 }
1515
1616 const next_x : ?i32 = @generatedCode(null);
......@@ -21,7 +21,7 @@ test "nullableType" {
2121
2222 const final_x : ?i32 = @generatedCode(13);
2323
24 const num = final_x ?? @unreachable();
24 const num = final_x ?? unreachable;
2525
2626 assert(num == 13);
2727}
test/cases/switch.zig+5-5
......@@ -55,9 +55,9 @@ const Fruit = enum {
5555};
5656fn nonConstSwitchOnEnum(fruit: Fruit) {
5757 switch (fruit) {
58 Fruit.Apple => @unreachable(),
58 Fruit.Apple => unreachable,
5959 Fruit.Orange => {},
60 Fruit.Banana => @unreachable(),
60 Fruit.Banana => unreachable,
6161 }
6262}
6363
......@@ -72,7 +72,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) {
7272 SwitchStatmentFoo.C => 3,
7373 SwitchStatmentFoo.D => 4,
7474 };
75 if (val != 3) @unreachable();
75 if (val != 3) unreachable;
7676}
7777const SwitchStatmentFoo = enum {
7878 A,
......@@ -95,10 +95,10 @@ const SwitchProngWithVarEnum = enum {
9595fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) {
9696 switch(*a) {
9797 SwitchProngWithVarEnum.One => |x| {
98 if (x != 13) @unreachable();
98 if (x != 13) unreachable;
9999 },
100100 SwitchProngWithVarEnum.Two => |x| {
101 if (x != 13.0) @unreachable();
101 if (x != 13.0) unreachable;
102102 },
103103 SwitchProngWithVarEnum.Meh => |x| {
104104 const v: void = x;
test/cases/try.zig+1-1
......@@ -52,7 +52,7 @@ fn failIfTrue(ok: bool) -> %void {
5252// @setFnTest(this);
5353//
5454// try (_ = failIfTrue(true)) {
55// @unreachable();
55// unreachable;
5656// } else |err| {
5757// assert(err == error.ItBroke);
5858// }
test/run_tests.cpp+25-25
......@@ -471,8 +471,8 @@ const foo : i32 = 0;
471471const c = @cImport(@cInclude("stdlib.h"));
472472
473473export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {
474 const a_int = (&i32)(a ?? @unreachable());
475 const b_int = (&i32)(b ?? @unreachable());
474 const a_int = (&i32)(a ?? unreachable);
475 const b_int = (&i32)(b ?? unreachable);
476476 if (*a_int < *b_int) {
477477 -1
478478 } else if (*a_int > *b_int) {
......@@ -628,9 +628,9 @@ export fn entry() { a(); }
628628 )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'a'");
629629
630630 add_compile_fail_case("unreachable with return", R"SOURCE(
631fn a() -> unreachable {return;}
631fn a() -> noreturn {return;}
632632export fn entry() { a(); }
633 )SOURCE", 1, ".tmp_source.zig:2:24: error: expected type 'unreachable', found 'void'");
633 )SOURCE", 1, ".tmp_source.zig:2:21: error: expected type 'noreturn', found 'void'");
634634
635635 add_compile_fail_case("control reaches end of non-void function", R"SOURCE(
636636fn a() -> i32 {}
......@@ -656,7 +656,7 @@ export fn entry() { _ = a(); }
656656 )SOURCE", 1, ".tmp_source.zig:2:11: error: use of undeclared identifier 'bogus'");
657657
658658 add_compile_fail_case("pointer to unreachable", R"SOURCE(
659fn a() -> &unreachable {}
659fn a() -> &noreturn {}
660660export fn entry() { _ = a(); }
661661 )SOURCE", 1, ".tmp_source.zig:2:12: error: pointer to unreachable not allowed");
662662
......@@ -724,14 +724,14 @@ export fn f() {
724724
725725 add_compile_fail_case("unreachable variable", R"SOURCE(
726726export fn f() {
727 const a : unreachable = {};
727 const a: noreturn = {};
728728}
729 )SOURCE", 1, ".tmp_source.zig:3:15: error: variable of type 'unreachable' not allowed");
729 )SOURCE", 1, ".tmp_source.zig:3:14: error: variable of type 'noreturn' not allowed");
730730
731731 add_compile_fail_case("unreachable parameter", R"SOURCE(
732fn f(a : unreachable) {}
732fn f(a: noreturn) {}
733733export fn entry() { f(); }
734 )SOURCE", 1, ".tmp_source.zig:2:10: error: parameter of type 'unreachable' not allowed");
734 )SOURCE", 1, ".tmp_source.zig:2:9: error: parameter of type 'noreturn' not allowed");
735735
736736 add_compile_fail_case("bad assignment target", R"SOURCE(
737737export fn f() {
......@@ -1737,7 +1737,7 @@ export fn foo() {
17371737}
17381738
17391739fn assert(ok: bool) {
1740 if (!ok) @unreachable();
1740 if (!ok) unreachable;
17411741}
17421742 )SOURCE", 2,
17431743 ".tmp_source.zig:11:14: error: unable to evaluate constant expression",
......@@ -1830,7 +1830,7 @@ export fn entry() {
18301830
18311831static void add_debug_safety_test_cases(void) {
18321832 add_debug_safety_case("out of bounds slice access", R"SOURCE(
1833pub fn panic(message: []const u8) -> unreachable {
1833pub fn panic(message: []const u8) -> noreturn {
18341834 @breakpoint();
18351835 while (true) {}
18361836}
......@@ -1845,7 +1845,7 @@ fn baz(a: i32) { }
18451845 )SOURCE");
18461846
18471847 add_debug_safety_case("integer addition overflow", R"SOURCE(
1848pub fn panic(message: []const u8) -> unreachable {
1848pub fn panic(message: []const u8) -> noreturn {
18491849 @breakpoint();
18501850 while (true) {}
18511851}
......@@ -1860,7 +1860,7 @@ fn add(a: u16, b: u16) -> u16 {
18601860 )SOURCE");
18611861
18621862 add_debug_safety_case("integer subtraction overflow", R"SOURCE(
1863pub fn panic(message: []const u8) -> unreachable {
1863pub fn panic(message: []const u8) -> noreturn {
18641864 @breakpoint();
18651865 while (true) {}
18661866}
......@@ -1875,7 +1875,7 @@ fn sub(a: u16, b: u16) -> u16 {
18751875 )SOURCE");
18761876
18771877 add_debug_safety_case("integer multiplication overflow", R"SOURCE(
1878pub fn panic(message: []const u8) -> unreachable {
1878pub fn panic(message: []const u8) -> noreturn {
18791879 @breakpoint();
18801880 while (true) {}
18811881}
......@@ -1890,7 +1890,7 @@ fn mul(a: u16, b: u16) -> u16 {
18901890 )SOURCE");
18911891
18921892 add_debug_safety_case("integer negation overflow", R"SOURCE(
1893pub fn panic(message: []const u8) -> unreachable {
1893pub fn panic(message: []const u8) -> noreturn {
18941894 @breakpoint();
18951895 while (true) {}
18961896}
......@@ -1905,7 +1905,7 @@ fn neg(a: i16) -> i16 {
19051905 )SOURCE");
19061906
19071907 add_debug_safety_case("signed integer division overflow", R"SOURCE(
1908pub fn panic(message: []const u8) -> unreachable {
1908pub fn panic(message: []const u8) -> noreturn {
19091909 @breakpoint();
19101910 while (true) {}
19111911}
......@@ -1920,7 +1920,7 @@ fn div(a: i16, b: i16) -> i16 {
19201920 )SOURCE");
19211921
19221922 add_debug_safety_case("signed shift left overflow", R"SOURCE(
1923pub fn panic(message: []const u8) -> unreachable {
1923pub fn panic(message: []const u8) -> noreturn {
19241924 @breakpoint();
19251925 while (true) {}
19261926}
......@@ -1935,7 +1935,7 @@ fn shl(a: i16, b: i16) -> i16 {
19351935 )SOURCE");
19361936
19371937 add_debug_safety_case("unsigned shift left overflow", R"SOURCE(
1938pub fn panic(message: []const u8) -> unreachable {
1938pub fn panic(message: []const u8) -> noreturn {
19391939 @breakpoint();
19401940 while (true) {}
19411941}
......@@ -1950,7 +1950,7 @@ fn shl(a: u16, b: u16) -> u16 {
19501950 )SOURCE");
19511951
19521952 add_debug_safety_case("integer division by zero", R"SOURCE(
1953pub fn panic(message: []const u8) -> unreachable {
1953pub fn panic(message: []const u8) -> noreturn {
19541954 @breakpoint();
19551955 while (true) {}
19561956}
......@@ -1964,7 +1964,7 @@ fn div0(a: i32, b: i32) -> i32 {
19641964 )SOURCE");
19651965
19661966 add_debug_safety_case("exact division failure", R"SOURCE(
1967pub fn panic(message: []const u8) -> unreachable {
1967pub fn panic(message: []const u8) -> noreturn {
19681968 @breakpoint();
19691969 while (true) {}
19701970}
......@@ -1979,7 +1979,7 @@ fn divExact(a: i32, b: i32) -> i32 {
19791979 )SOURCE");
19801980
19811981 add_debug_safety_case("cast []u8 to bigger slice of wrong size", R"SOURCE(
1982pub fn panic(message: []const u8) -> unreachable {
1982pub fn panic(message: []const u8) -> noreturn {
19831983 @breakpoint();
19841984 while (true) {}
19851985}
......@@ -1994,7 +1994,7 @@ fn widenSlice(slice: []const u8) -> []const i32 {
19941994 )SOURCE");
19951995
19961996 add_debug_safety_case("value does not fit in shortening cast", R"SOURCE(
1997pub fn panic(message: []const u8) -> unreachable {
1997pub fn panic(message: []const u8) -> noreturn {
19981998 @breakpoint();
19991999 while (true) {}
20002000}
......@@ -2009,7 +2009,7 @@ fn shorten_cast(x: i32) -> i8 {
20092009 )SOURCE");
20102010
20112011 add_debug_safety_case("signed integer not fitting in cast to unsigned integer", R"SOURCE(
2012pub fn panic(message: []const u8) -> unreachable {
2012pub fn panic(message: []const u8) -> noreturn {
20132013 @breakpoint();
20142014 while (true) {}
20152015}
......@@ -2024,7 +2024,7 @@ fn unsigned_cast(x: i32) -> u32 {
20242024 )SOURCE");
20252025
20262026 add_debug_safety_case("unwrap error", R"SOURCE(
2027pub fn panic(message: []const u8) -> unreachable {
2027pub fn panic(message: []const u8) -> noreturn {
20282028 @breakpoint();
20292029 while (true) {}
20302030}
......@@ -2055,7 +2055,7 @@ void baz(int8_t a, int16_t b, int32_t c, int64_t d);
20552055
20562056 add_parseh_case("noreturn attribute", AllowWarningsNo, R"SOURCE(
20572057void foo(void) __attribute__((noreturn));
2058 )SOURCE", 1, R"OUTPUT(pub extern fn foo() -> unreachable;)OUTPUT");
2058 )SOURCE", 1, R"OUTPUT(pub extern fn foo() -> noreturn;)OUTPUT");
20592059
20602060 add_parseh_case("enums", AllowWarningsNo, R"SOURCE(
20612061enum Foo {