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...@@ -155,7 +155,7 @@ GotoExpression = "goto" Symbol
155155
156GroupedExpression = "(" Expression ")"156GroupedExpression = "(" Expression ")"
157157
158KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this"158KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this" | "unreachable"
159159
160ContainerDecl = option("extern" | "packed") ("struct" | "enum" | "union") "{" many(ContainerMember) "}"160ContainerDecl = option("extern" | "packed") ("struct" | "enum" | "union") "{" many(ContainerMember) "}"
161161
...@@ -213,60 +213,6 @@ f32 float 32-bit floating point...@@ -213,60 +213,6 @@ f32 float 32-bit floating point
213f64 double 64-bit floating point213f64 double 64-bit floating point
214```214```
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
270## Expressions216## Expressions
271217
272### Literals218### Literals
...@@ -347,31 +293,6 @@ has a terminating null byte....@@ -347,31 +293,6 @@ has a terminating null byte.
347 Floating point | 123.0E+77 | Optional293 Floating point | 123.0E+77 | Optional
348 Hex floating point | 0x103.70p-5 | Optional294 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
375## Built-in Functions296## Built-in Functions
376297
377Built-in functions are prefixed with `@`. Remember that the `comptime` keyword on298Built-in functions are prefixed with `@`. Remember that the `comptime` keyword on
...@@ -682,10 +603,6 @@ code....@@ -682,10 +603,6 @@ code.
682603
683This function returns an integer type with the given signness and bit count.604This 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
689### @setDebugSafety(scope, safety_on: bool)606### @setDebugSafety(scope, safety_on: bool)
690607
691Sets a whether we want debug safety checks on for a given scope.608Sets 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...@@ -16,7 +16,7 @@ syn keyword zigRepeat while for
1616
17syn keyword zigConstant null undefined this17syn keyword zigConstant null undefined this
18syn keyword zigKeyword fn use test18syn keyword zigKeyword fn use test
19syn keyword zigType bool f32 f64 void Unreachable type error19syn keyword zigType bool f32 f64 void noreturn type error
20syn keyword zigType i8 u8 i16 u16 i32 u32 i64 u64 isize usize20syn keyword zigType i8 u8 i16 u16 i32 u32 i64 u64 isize usize
21syn keyword zigType c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong c_long_double21syn 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 {...@@ -334,6 +334,7 @@ enum NodeType {
334 NodeTypeNullLiteral,334 NodeTypeNullLiteral,
335 NodeTypeUndefinedLiteral,335 NodeTypeUndefinedLiteral,
336 NodeTypeThisLiteral,336 NodeTypeThisLiteral,
337 NodeTypeUnreachable,
337 NodeTypeIfBoolExpr,338 NodeTypeIfBoolExpr,
338 NodeTypeIfVarExpr,339 NodeTypeIfVarExpr,
339 NodeTypeWhileExpr,340 NodeTypeWhileExpr,
...@@ -758,6 +759,9 @@ struct AstNodeBreakExpr {...@@ -758,6 +759,9 @@ struct AstNodeBreakExpr {
758759
759struct AstNodeContinueExpr {760struct AstNodeContinueExpr {
760};761};
762struct AstNodeUnreachableExpr {
763};
764
761765
762struct AstNodeArrayType {766struct AstNodeArrayType {
763 AstNode *size;767 AstNode *size;
...@@ -827,6 +831,7 @@ struct AstNode {...@@ -827,6 +831,7 @@ struct AstNode {
827 AstNodeBoolLiteral bool_literal;831 AstNodeBoolLiteral bool_literal;
828 AstNodeBreakExpr break_expr;832 AstNodeBreakExpr break_expr;
829 AstNodeContinueExpr continue_expr;833 AstNodeContinueExpr continue_expr;
834 AstNodeUnreachableExpr unreachable_expr;
830 AstNodeArrayType array_type;835 AstNodeArrayType array_type;
831 AstNodeErrorType error_type;836 AstNodeErrorType error_type;
832 AstNodeTypeLiteral type_literal;837 AstNodeTypeLiteral type_literal;
...@@ -1173,7 +1178,6 @@ enum BuiltinFnId {...@@ -1173,7 +1178,6 @@ enum BuiltinFnId {
1173 BuiltinFnIdDivExact,1178 BuiltinFnIdDivExact,
1174 BuiltinFnIdTruncate,1179 BuiltinFnIdTruncate,
1175 BuiltinFnIdIntType,1180 BuiltinFnIdIntType,
1176 BuiltinFnIdUnreachable,
1177 BuiltinFnIdSetFnVisible,1181 BuiltinFnIdSetFnVisible,
1178 BuiltinFnIdSetDebugSafety,1182 BuiltinFnIdSetDebugSafety,
1179 BuiltinFnIdAlloca,1183 BuiltinFnIdAlloca,
src/analyze.cpp+1
...@@ -2110,6 +2110,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -2110,6 +2110,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
2110 case NodeTypeGoto:2110 case NodeTypeGoto:
2111 case NodeTypeBreak:2111 case NodeTypeBreak:
2112 case NodeTypeContinue:2112 case NodeTypeContinue:
2113 case NodeTypeUnreachable:
2113 case NodeTypeAsmExpr:2114 case NodeTypeAsmExpr:
2114 case NodeTypeFieldAccessExpr:2115 case NodeTypeFieldAccessExpr:
2115 case NodeTypeStructField:2116 case NodeTypeStructField:
src/ast_render.cpp+7
...@@ -216,6 +216,8 @@ static const char *node_type_str(NodeType node_type) {...@@ -216,6 +216,8 @@ static const char *node_type_str(NodeType node_type) {
216 return "Break";216 return "Break";
217 case NodeTypeContinue:217 case NodeTypeContinue:
218 return "Continue";218 return "Continue";
219 case NodeTypeUnreachable:
220 return "Unreachable";
219 case NodeTypeAsmExpr:221 case NodeTypeAsmExpr:
220 return "AsmExpr";222 return "AsmExpr";
221 case NodeTypeFieldAccessExpr:223 case NodeTypeFieldAccessExpr:
...@@ -890,6 +892,11 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -890,6 +892,11 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
890 fprintf(ar->f, "continue");892 fprintf(ar->f, "continue");
891 break;893 break;
892 }894 }
895 case NodeTypeUnreachable:
896 {
897 fprintf(ar->f, "unreachable");
898 break;
899 }
893 case NodeTypeSliceExpr:900 case NodeTypeSliceExpr:
894 {901 {
895 render_node_ungrouped(ar, node->data.slice_expr.array_ref_expr);902 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) {...@@ -3786,7 +3786,7 @@ static void define_builtin_types(CodeGen *g) {
3786 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUnreachable);3786 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUnreachable);
3787 entry->type_ref = LLVMVoidType();3787 entry->type_ref = LLVMVoidType();
3788 entry->zero_bits = true;3788 entry->zero_bits = true;
3789 buf_init_from_str(&entry->name, "unreachable");3789 buf_init_from_str(&entry->name, "noreturn");
3790 entry->di_type = g->builtin_types.entry_void->di_type;3790 entry->di_type = g->builtin_types.entry_void->di_type;
3791 g->builtin_types.entry_unreachable = entry;3791 g->builtin_types.entry_unreachable = entry;
3792 g->primitive_type_table.put(&entry->name, entry);3792 g->primitive_type_table.put(&entry->name, entry);
...@@ -4096,7 +4096,6 @@ static void define_builtin_fns(CodeGen *g) {...@@ -4096,7 +4096,6 @@ static void define_builtin_fns(CodeGen *g) {
4096 create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);4096 create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);
4097 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);4097 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
4098 create_builtin_fn(g, BuiltinFnIdIntType, "intType", 2);4098 create_builtin_fn(g, BuiltinFnIdIntType, "intType", 2);
4099 create_builtin_fn(g, BuiltinFnIdUnreachable, "unreachable", 0);
4100 create_builtin_fn(g, BuiltinFnIdSetFnVisible, "setFnVisible", 2);4099 create_builtin_fn(g, BuiltinFnIdSetFnVisible, "setFnVisible", 2);
4101 create_builtin_fn(g, BuiltinFnIdSetDebugSafety, "setDebugSafety", 2);4100 create_builtin_fn(g, BuiltinFnIdSetDebugSafety, "setDebugSafety", 2);
4102 create_builtin_fn(g, BuiltinFnIdAlloca, "alloca", 2);4101 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...@@ -3751,8 +3751,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
3751 switch (builtin_fn->id) {3751 switch (builtin_fn->id) {
3752 case BuiltinFnIdInvalid:3752 case BuiltinFnIdInvalid:
3753 zig_unreachable();3753 zig_unreachable();
3754 case BuiltinFnIdUnreachable:
3755 return ir_build_unreachable(irb, scope, node);
3756 case BuiltinFnIdTypeof:3754 case BuiltinFnIdTypeof:
3757 {3755 {
3758 AstNode *arg_node = node->data.fn_call_expr.params.at(0);3756 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...@@ -5467,6 +5465,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
5467 return ir_lval_wrap(irb, scope, ir_gen_break(irb, scope, node), lval);5465 return ir_lval_wrap(irb, scope, ir_gen_break(irb, scope, node), lval);
5468 case NodeTypeContinue:5466 case NodeTypeContinue:
5469 return ir_lval_wrap(irb, scope, ir_gen_continue(irb, scope, node), lval);5467 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);
5470 case NodeTypeDefer:5470 case NodeTypeDefer:
5471 return ir_lval_wrap(irb, scope, ir_gen_defer(irb, scope, node), lval);5471 return ir_lval_wrap(irb, scope, ir_gen_defer(irb, scope, node), lval);
5472 case NodeTypeSliceExpr:5472 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...@@ -705,7 +705,7 @@ static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool m
705705
706/*706/*
707PrimaryExpression = Number | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | Symbol | ("@" Symbol FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." Symbol) | ContainerDecl707PrimaryExpression = 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"
709*/709*/
710static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) {710static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
711 Token *token = &pc->tokens->at(*token_index);711 Token *token = &pc->tokens->at(*token_index);
...@@ -757,6 +757,10 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo...@@ -757,6 +757,10 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
757 AstNode *node = ast_create_node(pc, NodeTypeThisLiteral, token);757 AstNode *node = ast_create_node(pc, NodeTypeThisLiteral, token);
758 *token_index += 1;758 *token_index += 1;
759 return node;759 return node;
760 } else if (token->id == TokenIdKeywordUnreachable) {
761 AstNode *node = ast_create_node(pc, NodeTypeUnreachable, token);
762 *token_index += 1;
763 return node;
760 } else if (token->id == TokenIdKeywordType) {764 } else if (token->id == TokenIdKeywordType) {
761 AstNode *node = ast_create_node(pc, NodeTypeTypeLiteral, token);765 AstNode *node = ast_create_node(pc, NodeTypeTypeLiteral, token);
762 *token_index += 1;766 *token_index += 1;
...@@ -2728,6 +2732,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont...@@ -2728,6 +2732,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
2728 case NodeTypeContinue:2732 case NodeTypeContinue:
2729 // none2733 // none
2730 break;2734 break;
2735 case NodeTypeUnreachable:
2736 // none
2737 break;
2731 case NodeTypeAsmExpr:2738 case NodeTypeAsmExpr:
2732 for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) {2739 for (size_t i = 0; i < node->data.asm_expr.input_list.length; i += 1) {
2733 AsmInput *asm_input = node->data.asm_expr.input_list.at(i);2740 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[] = {...@@ -140,6 +140,7 @@ static const struct ZigKeyword zig_keywords[] = {
140 {"type", TokenIdKeywordType},140 {"type", TokenIdKeywordType},
141 {"undefined", TokenIdKeywordUndefined},141 {"undefined", TokenIdKeywordUndefined},
142 {"union", TokenIdKeywordUnion},142 {"union", TokenIdKeywordUnion},
143 {"unreachable", TokenIdKeywordUnreachable},
143 {"use", TokenIdKeywordUse},144 {"use", TokenIdKeywordUse},
144 {"var", TokenIdKeywordVar},145 {"var", TokenIdKeywordVar},
145 {"volatile", TokenIdKeywordVolatile},146 {"volatile", TokenIdKeywordVolatile},
...@@ -1516,6 +1517,7 @@ const char * token_name(TokenId id) {...@@ -1516,6 +1517,7 @@ const char * token_name(TokenId id) {
1516 case TokenIdKeywordType: return "type";1517 case TokenIdKeywordType: return "type";
1517 case TokenIdKeywordUndefined: return "undefined";1518 case TokenIdKeywordUndefined: return "undefined";
1518 case TokenIdKeywordUnion: return "union";1519 case TokenIdKeywordUnion: return "union";
1520 case TokenIdKeywordUnreachable: return "unreachable";
1519 case TokenIdKeywordUse: return "use";1521 case TokenIdKeywordUse: return "use";
1520 case TokenIdKeywordVar: return "var";1522 case TokenIdKeywordVar: return "var";
1521 case TokenIdKeywordVolatile: return "volatile";1523 case TokenIdKeywordVolatile: return "volatile";
src/tokenizer.hpp+1
...@@ -81,6 +81,7 @@ enum TokenId {...@@ -81,6 +81,7 @@ enum TokenId {
81 TokenIdKeywordType,81 TokenIdKeywordType,
82 TokenIdKeywordUndefined,82 TokenIdKeywordUndefined,
83 TokenIdKeywordUnion,83 TokenIdKeywordUnion,
84 TokenIdKeywordUnreachable,
84 TokenIdKeywordUse,85 TokenIdKeywordUse,
85 TokenIdKeywordVar,86 TokenIdKeywordVar,
86 TokenIdKeywordVolatile,87 TokenIdKeywordVolatile,
std/bootstrap.zig+4-4
...@@ -16,10 +16,10 @@ const exit = switch(@compileVar("os")) {...@@ -16,10 +16,10 @@ const exit = switch(@compileVar("os")) {
16var argc: usize = undefined;16var argc: usize = undefined;
17var argv: &&u8 = undefined;17var argv: &&u8 = undefined;
1818
19export nakedcc fn _start() -> unreachable {19export nakedcc fn _start() -> noreturn {
20 @setFnVisible(this, want_start_symbol);20 @setFnVisible(this, want_start_symbol);
21 if (!want_start_symbol) {21 if (!want_start_symbol) {
22 @unreachable();22 unreachable;
23 }23 }
2424
25 switch (@compileVar("arch")) {25 switch (@compileVar("arch")) {
...@@ -45,7 +45,7 @@ fn callMain() -> %void {...@@ -45,7 +45,7 @@ fn callMain() -> %void {
45 return root.main(args);45 return root.main(args);
46}46}
4747
48fn callMainAndExit() -> unreachable {48fn callMainAndExit() -> noreturn {
49 callMain() %% exit(1);49 callMain() %% exit(1);
50 exit(0);50 exit(0);
51}51}
...@@ -53,7 +53,7 @@ fn callMainAndExit() -> unreachable {...@@ -53,7 +53,7 @@ fn callMainAndExit() -> unreachable {
53export fn main(c_argc: i32, c_argv: &&u8) -> i32 {53export fn main(c_argc: i32, c_argv: &&u8) -> i32 {
54 @setFnVisible(this, want_main_symbol);54 @setFnVisible(this, want_main_symbol);
55 if (!want_main_symbol) {55 if (!want_main_symbol) {
56 @unreachable();56 unreachable;
57 }57 }
5858
59 argc = usize(c_argc);59 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) {...@@ -31,6 +31,6 @@ export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
31}31}
3232
33// Avoid dragging in the debug safety mechanisms into this .o file.33// Avoid dragging in the debug safety mechanisms into this .o file.
34pub fn panic(message: []const u8) -> unreachable {34pub fn panic(message: []const u8) -> noreturn {
35 @unreachable();35 unreachable;
36}36}
std/c/index.zig+1-1
...@@ -7,7 +7,7 @@ pub use switch(@compileVar("os")) {...@@ -7,7 +7,7 @@ pub use switch(@compileVar("os")) {
7 else => empty_import,7 else => empty_import,
8};8};
99
10pub extern fn abort() -> unreachable;10pub extern fn abort() -> noreturn;
1111
1212
13const empty_import = @import("empty.zig");13const empty_import = @import("empty.zig");
std/compiler_rt.zig+4-4
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1// Avoid dragging in the debug safety mechanisms into this .o file,1// Avoid dragging in the debug safety mechanisms into this .o file,
2// unless we're trying to test this file.2// unless we're trying to test this file.
3pub fn panic(message: []const u8) -> unreachable {3pub fn panic(message: []const u8) -> noreturn {
4 if (@compileVar("is_test")) {4 if (@compileVar("is_test")) {
5 @import("std").debug.panic(message);5 @import("std").debug.panic(message);
6 } else {6 } else {
7 @unreachable();7 unreachable;
8 }8 }
9}9}
1010
...@@ -259,7 +259,7 @@ export nakedcc fn __aeabi_uidivmod() {...@@ -259,7 +259,7 @@ export nakedcc fn __aeabi_uidivmod() {
259 \\ add sp, sp, #4259 \\ add sp, sp, #4
260 \\ pop { pc }260 \\ pop { pc }
261 ::: "r2", "r1");261 ::: "r2", "r1");
262 @unreachable();262 unreachable;
263 }263 }
264264
265 @setFnVisible(this, false);265 @setFnVisible(this, false);
...@@ -511,5 +511,5 @@ fn test_one_udivsi3(a: su_int, b: su_int, expected_q: su_int) {...@@ -511,5 +511,5 @@ fn test_one_udivsi3(a: su_int, b: su_int, expected_q: su_int) {
511511
512512
513fn assert(ok: bool) {513fn assert(ok: bool) {
514 if (!ok) @unreachable();514 if (!ok) unreachable;
515}515}
std/darwin.zig+2-2
...@@ -48,9 +48,9 @@ pub const SIGPWR = 30;...@@ -48,9 +48,9 @@ pub const SIGPWR = 30;
48pub const SIGSYS = 31;48pub const SIGSYS = 31;
49pub const SIGUNUSED = SIGSYS;49pub const SIGUNUSED = SIGSYS;
5050
51pub fn exit(status: usize) -> unreachable {51pub fn exit(status: usize) -> noreturn {
52 _ = arch.syscall1(arch.SYS_exit, status);52 _ = arch.syscall1(arch.SYS_exit, status);
53 @unreachable()53 unreachable
54}54}
5555
56/// Get the errno from a syscall return value, or 0 for no error.56/// Get the errno from a syscall return value, or 0 for no error.
std/debug.zig+3-3
...@@ -10,12 +10,12 @@ error InvalidDebugInfo;...@@ -10,12 +10,12 @@ error InvalidDebugInfo;
10error UnsupportedDebugInfo;10error UnsupportedDebugInfo;
1111
12pub fn assert(ok: bool) {12pub fn assert(ok: bool) {
13 if (!ok) @unreachable()13 if (!ok) unreachable
14}14}
1515
16var panicking = false;16var panicking = false;
17/// This is the default panic implementation.17/// This is the default panic implementation.
18pub coldcc fn panic(message: []const u8) -> unreachable {18pub coldcc fn panic(message: []const u8) -> noreturn {
19 // TODO19 // TODO
20 // if (@atomicRmw(AtomicOp.XChg, &panicking, true, AtomicOrder.SeqCst)) { }20 // if (@atomicRmw(AtomicOp.XChg, &panicking, true, AtomicOrder.SeqCst)) { }
21 if (panicking) {21 if (panicking) {
...@@ -252,7 +252,7 @@ fn parseFormValueTargetAddrSize(in_stream: &io.InStream) -> %u64 {...@@ -252,7 +252,7 @@ fn parseFormValueTargetAddrSize(in_stream: &io.InStream) -> %u64 {
252 } else if (@sizeOf(usize) == 8) {252 } else if (@sizeOf(usize) == 8) {
253 %return in_stream.readIntLe(u64)253 %return in_stream.readIntLe(u64)
254 } else {254 } else {
255 @unreachable();255 unreachable;
256 };256 };
257}257}
258258
std/fmt.zig+3-3
...@@ -287,7 +287,7 @@ fn digitToChar(digit: u8, uppercase: bool) -> u8 {...@@ -287,7 +287,7 @@ fn digitToChar(digit: u8, uppercase: bool) -> u8 {
287 return switch (digit) {287 return switch (digit) {
288 0 ... 9 => digit + '0',288 0 ... 9 => digit + '0',
289 10 ... 35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10),289 10 ... 35 => digit + ((if (uppercase) u8('A') else u8('a')) - 10),
290 else => @unreachable(),290 else => unreachable,
291 };291 };
292}292}
293293
...@@ -316,9 +316,9 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u...@@ -316,9 +316,9 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u
316test "testParseU64DigitTooBig" {316test "testParseU64DigitTooBig" {
317 parseUnsigned(u64, "123a", 10) %% |err| {317 parseUnsigned(u64, "123a", 10) %% |err| {
318 if (err == error.InvalidChar) return;318 if (err == error.InvalidChar) return;
319 @unreachable();319 unreachable;
320 };320 };
321 @unreachable();321 unreachable;
322}322}
323323
324test "testParseUnsignedComptime" {324test "testParseUnsignedComptime" {
std/hash_map.zig+4-4
...@@ -50,7 +50,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -50,7 +50,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
50 return entry;50 return entry;
51 }51 }
52 }52 }
53 @unreachable() // no next item53 unreachable // no next item
54 }54 }
55 };55 };
5656
...@@ -125,9 +125,9 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -125,9 +125,9 @@ pub fn HashMap(comptime K: type, comptime V: type,
125 entry.distance_from_start_index -= 1;125 entry.distance_from_start_index -= 1;
126 entry = next_entry;126 entry = next_entry;
127 }127 }
128 @unreachable() // shifting everything in the table128 unreachable // shifting everything in the table
129 }}129 }}
130 @unreachable() // key not found130 unreachable // key not found
131 }131 }
132132
133 pub fn entryIterator(hm: &Self) -> Iterator {133 pub fn entryIterator(hm: &Self) -> Iterator {
...@@ -198,7 +198,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -198,7 +198,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
198 };198 };
199 return;199 return;
200 }200 }
201 @unreachable() // put into a full map201 unreachable // put into a full map
202 }202 }
203203
204 fn internalGet(hm: &Self, key: K) -> ?&Entry {204 fn internalGet(hm: &Self, key: K) -> ?&Entry {
std/io.zig+5-5
...@@ -129,7 +129,7 @@ pub const OutStream = struct {...@@ -129,7 +129,7 @@ pub const OutStream = struct {
129 if (write_err > 0) {129 if (write_err > 0) {
130 return switch (write_err) {130 return switch (write_err) {
131 errno.EINTR => continue,131 errno.EINTR => continue,
132 errno.EINVAL => @unreachable(),132 errno.EINVAL => unreachable,
133 errno.EDQUOT => error.DiskQuota,133 errno.EDQUOT => error.DiskQuota,
134 errno.EFBIG => error.FileTooBig,134 errno.EFBIG => error.FileTooBig,
135 errno.EIO => error.Io,135 errno.EIO => error.Io,
...@@ -171,8 +171,8 @@ pub const InStream = struct {...@@ -171,8 +171,8 @@ pub const InStream = struct {
171 return switch (err) {171 return switch (err) {
172 errno.EINTR => continue,172 errno.EINTR => continue,
173173
174 errno.EFAULT => @unreachable(),174 errno.EFAULT => unreachable,
175 errno.EINVAL => @unreachable(),175 errno.EINVAL => unreachable,
176 errno.EACCES => error.BadPerm,176 errno.EACCES => error.BadPerm,
177 errno.EFBIG, errno.EOVERFLOW => error.FileTooBig,177 errno.EFBIG, errno.EOVERFLOW => error.FileTooBig,
178 errno.EISDIR => error.IsDir,178 errno.EISDIR => error.IsDir,
...@@ -235,8 +235,8 @@ pub const InStream = struct {...@@ -235,8 +235,8 @@ pub const InStream = struct {
235 switch (read_err) {235 switch (read_err) {
236 errno.EINTR => continue,236 errno.EINTR => continue,
237237
238 errno.EINVAL => @unreachable(),238 errno.EINVAL => unreachable,
239 errno.EFAULT => @unreachable(),239 errno.EFAULT => unreachable,
240 errno.EBADF => return error.BadFd,240 errno.EBADF => return error.BadFd,
241 errno.EIO => return error.Io,241 errno.EIO => return error.Io,
242 else => return error.Unexpected,242 else => return error.Unexpected,
std/linux.zig+2-2
...@@ -297,9 +297,9 @@ pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {...@@ -297,9 +297,9 @@ pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
297 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)297 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
298}298}
299299
300pub fn exit(status: i32) -> unreachable {300pub fn exit(status: i32) -> noreturn {
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/math.zig+1-1
...@@ -57,7 +57,7 @@ pub fn abs(x: var) -> @typeOf(x) {...@@ -57,7 +57,7 @@ pub fn abs(x: var) -> @typeOf(x) {
57 } else if (@isFloat(T)) {57 } else if (@isFloat(T)) {
58 @compileError("TODO implement abs for floats");58 @compileError("TODO implement abs for floats");
59 } else {59 } else {
60 @unreachable();60 unreachable;
61 }61 }
62}62}
63fn getReturnTypeForAbs(comptime T: type) -> type {63fn getReturnTypeForAbs(comptime T: type) -> type {
std/net.zig+13-13
...@@ -21,8 +21,8 @@ const Connection = struct {...@@ -21,8 +21,8 @@ const Connection = struct {
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 @@ const Connection = struct {...@@ -35,8 +35,8 @@ const Connection = struct {
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 @@ const Connection = struct {...@@ -50,7 +50,7 @@ const Connection = struct {
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 // TODO80 // TODO
...@@ -86,7 +86,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {...@@ -86,7 +86,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
86 // else => {},86 // else => {},
87 //};87 //};
8888
89 @unreachable() // TODO89 unreachable // TODO
90}90}
9191
92pub fn connectAddr(addr: &Address, port: u16) -> %Connection {92pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
...@@ -114,7 +114,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {...@@ -114,7 +114,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
114 @memcpy(&os_addr.addr[0], &addr.addr[0], 16);114 @memcpy(&os_addr.addr[0], &addr.addr[0], 16);
115 linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in6))115 linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in6))
116 } else {116 } else {
117 @unreachable()117 unreachable
118 };118 };
119 const connect_err = linux.getErrno(connect_ret);119 const connect_err = linux.getErrno(connect_ret);
120 if (connect_err > 0) {120 if (connect_err > 0) {
...@@ -324,11 +324,11 @@ fn parseIp4(buf: []const u8) -> %u32 {...@@ -324,11 +324,11 @@ fn parseIp4(buf: []const u8) -> %u32 {
324// @setFnTest(this);324// @setFnTest(this);
325//325//
326// assert(%%parseIp4("127.0.0.1") == endian.swapIfLe(u32, 0x7f000001));326// assert(%%parseIp4("127.0.0.1") == endian.swapIfLe(u32, 0x7f000001));
327// switch (parseIp4("256.0.0.1")) { Overflow => {}, else => @unreachable(), }327// switch (parseIp4("256.0.0.1")) { Overflow => {}, else => unreachable, }
328// switch (parseIp4("x.0.0.1")) { InvalidChar => {}, else => @unreachable(), }328// switch (parseIp4("x.0.0.1")) { InvalidChar => {}, else => unreachable, }
329// switch (parseIp4("127.0.0.1.1")) { JunkAtEnd => {}, else => @unreachable(), }329// switch (parseIp4("127.0.0.1.1")) { JunkAtEnd => {}, else => unreachable, }
330// switch (parseIp4("127.0.0.")) { Incomplete => {}, else => @unreachable(), }330// switch (parseIp4("127.0.0.")) { Incomplete => {}, else => unreachable, }
331// switch (parseIp4("100..0.1")) { InvalidChar => {}, else => @unreachable(), }331// switch (parseIp4("100..0.1")) { InvalidChar => {}, else => unreachable, }
332//}332//}
333//333//
334//fn testParseIp6() {334//fn testParseIp6() {
std/os.zig+3-3
...@@ -46,8 +46,8 @@ pub fn getRandomBytes(buf: []u8) -> %void {...@@ -46,8 +46,8 @@ pub fn getRandomBytes(buf: []u8) -> %void {
46 };46 };
47 if (err > 0) {47 if (err > 0) {
48 return switch (err) {48 return switch (err) {
49 errno.EINVAL => @unreachable(),49 errno.EINVAL => unreachable,
50 errno.EFAULT => @unreachable(),50 errno.EFAULT => unreachable,
51 errno.EINTR => continue,51 errno.EINTR => continue,
52 else => error.Unexpected,52 else => error.Unexpected,
53 }53 }
...@@ -59,7 +59,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {...@@ -59,7 +59,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
59/// Raises a signal in the current kernel thread, ending its execution.59/// Raises a signal in the current kernel thread, ending its execution.
60/// If linking against libc, this calls the abort() libc function. Otherwise60/// If linking against libc, this calls the abort() libc function. Otherwise
61/// it uses the zig standard library implementation.61/// it uses the zig standard library implementation.
62pub coldcc fn abort() -> unreachable {62pub coldcc fn abort() -> noreturn {
63 if (linking_libc) {63 if (linking_libc) {
64 c.abort();64 c.abort();
65 }65 }
std/panic.zig+1-1
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3// If this file wants to import other files *by name*, support for that would3// If this file wants to import other files *by name*, support for that would
4// have to be added in the compiler.4// have to be added in the compiler.
55
6pub coldcc fn panic(message: []const u8) -> unreachable {6pub coldcc fn panic(message: []const u8) -> noreturn {
7 if (@compileVar("os") == Os.freestanding) {7 if (@compileVar("os") == Os.freestanding) {
8 while (true) {}8 while (true) {}
9 } else {9 } else {
test/cases/enum.zig+3-3
...@@ -16,7 +16,7 @@ test "enumType" {...@@ -16,7 +16,7 @@ test "enumType" {
16test "enumAsReturnValue" {16test "enumAsReturnValue" {
17 switch (returnAnInt(13)) {17 switch (returnAnInt(13)) {
18 Foo.One => |value| assert(value == 13),18 Foo.One => |value| assert(value == 13),
19 else => @unreachable(),19 else => unreachable,
20 }20 }
21}21}
2222
...@@ -51,13 +51,13 @@ test "constantEnumWithPayload" {...@@ -51,13 +51,13 @@ test "constantEnumWithPayload" {
51fn shouldBeEmpty(x: &const AnEnumWithPayload) {51fn shouldBeEmpty(x: &const AnEnumWithPayload) {
52 switch (*x) {52 switch (*x) {
53 AnEnumWithPayload.Empty => {},53 AnEnumWithPayload.Empty => {},
54 else => @unreachable(),54 else => unreachable,
55 }55 }
56}56}
5757
58fn shouldBeNotEmpty(x: &const AnEnumWithPayload) {58fn shouldBeNotEmpty(x: &const AnEnumWithPayload) {
59 switch (*x) {59 switch (*x) {
60 AnEnumWithPayload.Empty => @unreachable(),60 AnEnumWithPayload.Empty => unreachable,
61 else => {},61 else => {},
62 }62 }
63}63}
test/cases/error.zig+1-1
...@@ -48,7 +48,7 @@ error AnError;...@@ -48,7 +48,7 @@ error AnError;
48error AnError;48error AnError;
49error SecondError;49error SecondError;
50fn shouldBeNotEqual(a: error, b: error) {50fn shouldBeNotEqual(a: error, b: error) {
51 if (a == b) @unreachable()51 if (a == b) unreachable
52}52}
5353
5454
test/cases/fn.zig+3-3
...@@ -13,7 +13,7 @@ test "localVariables" {...@@ -13,7 +13,7 @@ test "localVariables" {
13}13}
14fn testLocVars(b: i32) {14fn testLocVars(b: i32) {
15 const a: i32 = 1;15 const a: i32 = 1;
16 if (a + b != 3) @unreachable();16 if (a + b != 3) unreachable;
17}17}
1818
1919
...@@ -72,8 +72,8 @@ test "implicitCastFnUnreachableReturn" {...@@ -72,8 +72,8 @@ test "implicitCastFnUnreachableReturn" {
7272
73fn wantsFnWithVoid(f: fn()) { }73fn wantsFnWithVoid(f: fn()) { }
7474
75fn fnWithUnreachable() -> unreachable {75fn fnWithUnreachable() -> noreturn {
76 @unreachable()76 unreachable
77}77}
7878
7979
test/cases/for.zig+1-1
...@@ -12,7 +12,7 @@ test "continueInForLoop" {...@@ -12,7 +12,7 @@ test "continueInForLoop" {
12 }12 }
13 break;13 break;
14 }14 }
15 if (sum != 6) @unreachable()15 if (sum != 6) unreachable
16}16}
1717
18test "forLoopWithPointerElemVar" {18test "forLoopWithPointerElemVar" {
test/cases/goto.zig+1-1
...@@ -30,7 +30,7 @@ exit:...@@ -30,7 +30,7 @@ exit:
30 if (it_worked) {30 if (it_worked) {
31 return;31 return;
32 }32 }
33 @unreachable();33 unreachable;
34entry:34entry:
35 defer it_worked = true;35 defer it_worked = true;
36 if (b) goto exit;36 if (b) goto exit;
test/cases/if.zig+4-4
...@@ -6,20 +6,20 @@ test "ifStatements" {...@@ -6,20 +6,20 @@ test "ifStatements" {
6}6}
7fn shouldBeEqual(a: i32, b: i32) {7fn shouldBeEqual(a: i32, b: i32) {
8 if (a != b) {8 if (a != b) {
9 @unreachable();9 unreachable;
10 } else {10 } else {
11 return;11 return;
12 }12 }
13}13}
14fn firstEqlThird(a: i32, b: i32, c: i32) {14fn firstEqlThird(a: i32, b: i32, c: i32) {
15 if (a == b) {15 if (a == b) {
16 @unreachable();16 unreachable;
17 } else if (b == c) {17 } else if (b == c) {
18 @unreachable();18 unreachable;
19 } else if (a == c) {19 } else if (a == c) {
20 return;20 return;
21 } else {21 } else {
22 @unreachable();22 unreachable;
23 }23 }
24}24}
2525
test/cases/misc.zig+6-6
...@@ -163,7 +163,7 @@ test "memcpyAndMemsetIntrinsics" {...@@ -163,7 +163,7 @@ test "memcpyAndMemsetIntrinsics" {
163 @memset(&foo[0], 'A', foo.len);163 @memset(&foo[0], 'A', foo.len);
164 @memcpy(&bar[0], &foo[0], bar.len);164 @memcpy(&bar[0], &foo[0], bar.len);
165165
166 if (bar[11] != 'A') @unreachable();166 if (bar[11] != 'A') unreachable;
167}167}
168168
169test "builtinStaticEval" {169test "builtinStaticEval" {
...@@ -178,13 +178,13 @@ test "slicing" {...@@ -178,13 +178,13 @@ test "slicing" {
178178
179 var slice = array[5...10];179 var slice = array[5...10];
180180
181 if (slice.len != 5) @unreachable();181 if (slice.len != 5) unreachable;
182182
183 const ptr = &slice[0];183 const ptr = &slice[0];
184 if (ptr[0] != 1234) @unreachable();184 if (ptr[0] != 1234) unreachable;
185185
186 var slice_rest = array[10...];186 var slice_rest = array[10...];
187 if (slice_rest.len != 10) @unreachable();187 if (slice_rest.len != 10) unreachable;
188}188}
189189
190190
...@@ -344,7 +344,7 @@ fn test3_1(f: &const Test3Foo) {...@@ -344,7 +344,7 @@ fn test3_1(f: &const Test3Foo) {
344 assert(pt.x == 3);344 assert(pt.x == 3);
345 assert(pt.y == 4);345 assert(pt.y == 4);
346 },346 },
347 else => @unreachable(),347 else => unreachable,
348 }348 }
349}349}
350fn test3_2(f: &const Test3Foo) {350fn test3_2(f: &const Test3Foo) {
...@@ -352,7 +352,7 @@ fn test3_2(f: &const Test3Foo) {...@@ -352,7 +352,7 @@ fn test3_2(f: &const Test3Foo) {
352 Test3Foo.Two => |x| {352 Test3Foo.Two => |x| {
353 assert(x == 13);353 assert(x == 13);
354 },354 },
355 else => @unreachable(),355 else => unreachable,
356 }356 }
357}357}
358358
test/cases/null.zig+3-3
...@@ -7,10 +7,10 @@ test "nullableType" {...@@ -7,10 +7,10 @@ test "nullableType" {
7 if (y) {7 if (y) {
8 // OK8 // OK
9 } else {9 } else {
10 @unreachable();10 unreachable;
11 }11 }
12 } else {12 } else {
13 @unreachable();13 unreachable;
14 }14 }
1515
16 const next_x : ?i32 = @generatedCode(null);16 const next_x : ?i32 = @generatedCode(null);
...@@ -21,7 +21,7 @@ test "nullableType" {...@@ -21,7 +21,7 @@ test "nullableType" {
2121
22 const final_x : ?i32 = @generatedCode(13);22 const final_x : ?i32 = @generatedCode(13);
2323
24 const num = final_x ?? @unreachable();24 const num = final_x ?? unreachable;
2525
26 assert(num == 13);26 assert(num == 13);
27}27}
test/cases/switch.zig+5-5
...@@ -55,9 +55,9 @@ const Fruit = enum {...@@ -55,9 +55,9 @@ const Fruit = enum {
55};55};
56fn nonConstSwitchOnEnum(fruit: Fruit) {56fn nonConstSwitchOnEnum(fruit: Fruit) {
57 switch (fruit) {57 switch (fruit) {
58 Fruit.Apple => @unreachable(),58 Fruit.Apple => unreachable,
59 Fruit.Orange => {},59 Fruit.Orange => {},
60 Fruit.Banana => @unreachable(),60 Fruit.Banana => unreachable,
61 }61 }
62}62}
6363
...@@ -72,7 +72,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) {...@@ -72,7 +72,7 @@ fn nonConstSwitch(foo: SwitchStatmentFoo) {
72 SwitchStatmentFoo.C => 3,72 SwitchStatmentFoo.C => 3,
73 SwitchStatmentFoo.D => 4,73 SwitchStatmentFoo.D => 4,
74 };74 };
75 if (val != 3) @unreachable();75 if (val != 3) unreachable;
76}76}
77const SwitchStatmentFoo = enum {77const SwitchStatmentFoo = enum {
78 A,78 A,
...@@ -95,10 +95,10 @@ const SwitchProngWithVarEnum = enum {...@@ -95,10 +95,10 @@ const SwitchProngWithVarEnum = enum {
95fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) {95fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) {
96 switch(*a) {96 switch(*a) {
97 SwitchProngWithVarEnum.One => |x| {97 SwitchProngWithVarEnum.One => |x| {
98 if (x != 13) @unreachable();98 if (x != 13) unreachable;
99 },99 },
100 SwitchProngWithVarEnum.Two => |x| {100 SwitchProngWithVarEnum.Two => |x| {
101 if (x != 13.0) @unreachable();101 if (x != 13.0) unreachable;
102 },102 },
103 SwitchProngWithVarEnum.Meh => |x| {103 SwitchProngWithVarEnum.Meh => |x| {
104 const v: void = x;104 const v: void = x;
test/cases/try.zig+1-1
...@@ -52,7 +52,7 @@ fn failIfTrue(ok: bool) -> %void {...@@ -52,7 +52,7 @@ fn failIfTrue(ok: bool) -> %void {
52// @setFnTest(this);52// @setFnTest(this);
53//53//
54// try (_ = failIfTrue(true)) {54// try (_ = failIfTrue(true)) {
55// @unreachable();55// unreachable;
56// } else |err| {56// } else |err| {
57// assert(err == error.ItBroke);57// assert(err == error.ItBroke);
58// }58// }
test/run_tests.cpp+25-25
...@@ -471,8 +471,8 @@ const foo : i32 = 0;...@@ -471,8 +471,8 @@ const foo : i32 = 0;
471const c = @cImport(@cInclude("stdlib.h"));471const c = @cImport(@cInclude("stdlib.h"));
472472
473export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {473export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {
474 const a_int = (&i32)(a ?? @unreachable());474 const a_int = (&i32)(a ?? unreachable);
475 const b_int = (&i32)(b ?? @unreachable());475 const b_int = (&i32)(b ?? unreachable);
476 if (*a_int < *b_int) {476 if (*a_int < *b_int) {
477 -1477 -1
478 } else if (*a_int > *b_int) {478 } else if (*a_int > *b_int) {
...@@ -628,9 +628,9 @@ export fn entry() { a(); }...@@ -628,9 +628,9 @@ export fn entry() { a(); }
628 )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'a'");628 )SOURCE", 1, ".tmp_source.zig:3:1: error: redefinition of 'a'");
629629
630 add_compile_fail_case("unreachable with return", R"SOURCE(630 add_compile_fail_case("unreachable with return", R"SOURCE(
631fn a() -> unreachable {return;}631fn a() -> noreturn {return;}
632export fn entry() { a(); }632export 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
635 add_compile_fail_case("control reaches end of non-void function", R"SOURCE(635 add_compile_fail_case("control reaches end of non-void function", R"SOURCE(
636fn a() -> i32 {}636fn a() -> i32 {}
...@@ -656,7 +656,7 @@ export fn entry() { _ = a(); }...@@ -656,7 +656,7 @@ export fn entry() { _ = a(); }
656 )SOURCE", 1, ".tmp_source.zig:2:11: error: use of undeclared identifier 'bogus'");656 )SOURCE", 1, ".tmp_source.zig:2:11: error: use of undeclared identifier 'bogus'");
657657
658 add_compile_fail_case("pointer to unreachable", R"SOURCE(658 add_compile_fail_case("pointer to unreachable", R"SOURCE(
659fn a() -> &unreachable {}659fn a() -> &noreturn {}
660export fn entry() { _ = a(); }660export fn entry() { _ = a(); }
661 )SOURCE", 1, ".tmp_source.zig:2:12: error: pointer to unreachable not allowed");661 )SOURCE", 1, ".tmp_source.zig:2:12: error: pointer to unreachable not allowed");
662662
...@@ -724,14 +724,14 @@ export fn f() {...@@ -724,14 +724,14 @@ export fn f() {
724724
725 add_compile_fail_case("unreachable variable", R"SOURCE(725 add_compile_fail_case("unreachable variable", R"SOURCE(
726export fn f() {726export fn f() {
727 const a : unreachable = {};727 const a: noreturn = {};
728}728}
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
731 add_compile_fail_case("unreachable parameter", R"SOURCE(731 add_compile_fail_case("unreachable parameter", R"SOURCE(
732fn f(a : unreachable) {}732fn f(a: noreturn) {}
733export fn entry() { f(); }733export 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
736 add_compile_fail_case("bad assignment target", R"SOURCE(736 add_compile_fail_case("bad assignment target", R"SOURCE(
737export fn f() {737export fn f() {
...@@ -1737,7 +1737,7 @@ export fn foo() {...@@ -1737,7 +1737,7 @@ export fn foo() {
1737}1737}
17381738
1739fn assert(ok: bool) {1739fn assert(ok: bool) {
1740 if (!ok) @unreachable();1740 if (!ok) unreachable;
1741}1741}
1742 )SOURCE", 2,1742 )SOURCE", 2,
1743 ".tmp_source.zig:11:14: error: unable to evaluate constant expression",1743 ".tmp_source.zig:11:14: error: unable to evaluate constant expression",
...@@ -1830,7 +1830,7 @@ export fn entry() {...@@ -1830,7 +1830,7 @@ export fn entry() {
18301830
1831static void add_debug_safety_test_cases(void) {1831static void add_debug_safety_test_cases(void) {
1832 add_debug_safety_case("out of bounds slice access", R"SOURCE(1832 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 {
1834 @breakpoint();1834 @breakpoint();
1835 while (true) {}1835 while (true) {}
1836}1836}
...@@ -1845,7 +1845,7 @@ fn baz(a: i32) { }...@@ -1845,7 +1845,7 @@ fn baz(a: i32) { }
1845 )SOURCE");1845 )SOURCE");
18461846
1847 add_debug_safety_case("integer addition overflow", R"SOURCE(1847 add_debug_safety_case("integer addition overflow", R"SOURCE(
1848pub fn panic(message: []const u8) -> unreachable {1848pub fn panic(message: []const u8) -> noreturn {
1849 @breakpoint();1849 @breakpoint();
1850 while (true) {}1850 while (true) {}
1851}1851}
...@@ -1860,7 +1860,7 @@ fn add(a: u16, b: u16) -> u16 {...@@ -1860,7 +1860,7 @@ fn add(a: u16, b: u16) -> u16 {
1860 )SOURCE");1860 )SOURCE");
18611861
1862 add_debug_safety_case("integer subtraction overflow", R"SOURCE(1862 add_debug_safety_case("integer subtraction overflow", R"SOURCE(
1863pub fn panic(message: []const u8) -> unreachable {1863pub fn panic(message: []const u8) -> noreturn {
1864 @breakpoint();1864 @breakpoint();
1865 while (true) {}1865 while (true) {}
1866}1866}
...@@ -1875,7 +1875,7 @@ fn sub(a: u16, b: u16) -> u16 {...@@ -1875,7 +1875,7 @@ fn sub(a: u16, b: u16) -> u16 {
1875 )SOURCE");1875 )SOURCE");
18761876
1877 add_debug_safety_case("integer multiplication overflow", R"SOURCE(1877 add_debug_safety_case("integer multiplication overflow", R"SOURCE(
1878pub fn panic(message: []const u8) -> unreachable {1878pub fn panic(message: []const u8) -> noreturn {
1879 @breakpoint();1879 @breakpoint();
1880 while (true) {}1880 while (true) {}
1881}1881}
...@@ -1890,7 +1890,7 @@ fn mul(a: u16, b: u16) -> u16 {...@@ -1890,7 +1890,7 @@ fn mul(a: u16, b: u16) -> u16 {
1890 )SOURCE");1890 )SOURCE");
18911891
1892 add_debug_safety_case("integer negation overflow", R"SOURCE(1892 add_debug_safety_case("integer negation overflow", R"SOURCE(
1893pub fn panic(message: []const u8) -> unreachable {1893pub fn panic(message: []const u8) -> noreturn {
1894 @breakpoint();1894 @breakpoint();
1895 while (true) {}1895 while (true) {}
1896}1896}
...@@ -1905,7 +1905,7 @@ fn neg(a: i16) -> i16 {...@@ -1905,7 +1905,7 @@ fn neg(a: i16) -> i16 {
1905 )SOURCE");1905 )SOURCE");
19061906
1907 add_debug_safety_case("signed integer division overflow", R"SOURCE(1907 add_debug_safety_case("signed integer division overflow", R"SOURCE(
1908pub fn panic(message: []const u8) -> unreachable {1908pub fn panic(message: []const u8) -> noreturn {
1909 @breakpoint();1909 @breakpoint();
1910 while (true) {}1910 while (true) {}
1911}1911}
...@@ -1920,7 +1920,7 @@ fn div(a: i16, b: i16) -> i16 {...@@ -1920,7 +1920,7 @@ fn div(a: i16, b: i16) -> i16 {
1920 )SOURCE");1920 )SOURCE");
19211921
1922 add_debug_safety_case("signed shift left overflow", R"SOURCE(1922 add_debug_safety_case("signed shift left overflow", R"SOURCE(
1923pub fn panic(message: []const u8) -> unreachable {1923pub fn panic(message: []const u8) -> noreturn {
1924 @breakpoint();1924 @breakpoint();
1925 while (true) {}1925 while (true) {}
1926}1926}
...@@ -1935,7 +1935,7 @@ fn shl(a: i16, b: i16) -> i16 {...@@ -1935,7 +1935,7 @@ fn shl(a: i16, b: i16) -> i16 {
1935 )SOURCE");1935 )SOURCE");
19361936
1937 add_debug_safety_case("unsigned shift left overflow", R"SOURCE(1937 add_debug_safety_case("unsigned shift left overflow", R"SOURCE(
1938pub fn panic(message: []const u8) -> unreachable {1938pub fn panic(message: []const u8) -> noreturn {
1939 @breakpoint();1939 @breakpoint();
1940 while (true) {}1940 while (true) {}
1941}1941}
...@@ -1950,7 +1950,7 @@ fn shl(a: u16, b: u16) -> u16 {...@@ -1950,7 +1950,7 @@ fn shl(a: u16, b: u16) -> u16 {
1950 )SOURCE");1950 )SOURCE");
19511951
1952 add_debug_safety_case("integer division by zero", R"SOURCE(1952 add_debug_safety_case("integer division by zero", R"SOURCE(
1953pub fn panic(message: []const u8) -> unreachable {1953pub fn panic(message: []const u8) -> noreturn {
1954 @breakpoint();1954 @breakpoint();
1955 while (true) {}1955 while (true) {}
1956}1956}
...@@ -1964,7 +1964,7 @@ fn div0(a: i32, b: i32) -> i32 {...@@ -1964,7 +1964,7 @@ fn div0(a: i32, b: i32) -> i32 {
1964 )SOURCE");1964 )SOURCE");
19651965
1966 add_debug_safety_case("exact division failure", R"SOURCE(1966 add_debug_safety_case("exact division failure", R"SOURCE(
1967pub fn panic(message: []const u8) -> unreachable {1967pub fn panic(message: []const u8) -> noreturn {
1968 @breakpoint();1968 @breakpoint();
1969 while (true) {}1969 while (true) {}
1970}1970}
...@@ -1979,7 +1979,7 @@ fn divExact(a: i32, b: i32) -> i32 {...@@ -1979,7 +1979,7 @@ fn divExact(a: i32, b: i32) -> i32 {
1979 )SOURCE");1979 )SOURCE");
19801980
1981 add_debug_safety_case("cast []u8 to bigger slice of wrong size", R"SOURCE(1981 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 {
1983 @breakpoint();1983 @breakpoint();
1984 while (true) {}1984 while (true) {}
1985}1985}
...@@ -1994,7 +1994,7 @@ fn widenSlice(slice: []const u8) -> []const i32 {...@@ -1994,7 +1994,7 @@ fn widenSlice(slice: []const u8) -> []const i32 {
1994 )SOURCE");1994 )SOURCE");
19951995
1996 add_debug_safety_case("value does not fit in shortening cast", R"SOURCE(1996 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 {
1998 @breakpoint();1998 @breakpoint();
1999 while (true) {}1999 while (true) {}
2000}2000}
...@@ -2009,7 +2009,7 @@ fn shorten_cast(x: i32) -> i8 {...@@ -2009,7 +2009,7 @@ fn shorten_cast(x: i32) -> i8 {
2009 )SOURCE");2009 )SOURCE");
20102010
2011 add_debug_safety_case("signed integer not fitting in cast to unsigned integer", R"SOURCE(2011 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 {
2013 @breakpoint();2013 @breakpoint();
2014 while (true) {}2014 while (true) {}
2015}2015}
...@@ -2024,7 +2024,7 @@ fn unsigned_cast(x: i32) -> u32 {...@@ -2024,7 +2024,7 @@ fn unsigned_cast(x: i32) -> u32 {
2024 )SOURCE");2024 )SOURCE");
20252025
2026 add_debug_safety_case("unwrap error", R"SOURCE(2026 add_debug_safety_case("unwrap error", R"SOURCE(
2027pub fn panic(message: []const u8) -> unreachable {2027pub fn panic(message: []const u8) -> noreturn {
2028 @breakpoint();2028 @breakpoint();
2029 while (true) {}2029 while (true) {}
2030}2030}
...@@ -2055,7 +2055,7 @@ void baz(int8_t a, int16_t b, int32_t c, int64_t d);...@@ -2055,7 +2055,7 @@ void baz(int8_t a, int16_t b, int32_t c, int64_t d);
20552055
2056 add_parseh_case("noreturn attribute", AllowWarningsNo, R"SOURCE(2056 add_parseh_case("noreturn attribute", AllowWarningsNo, R"SOURCE(
2057void foo(void) __attribute__((noreturn));2057void 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
2060 add_parseh_case("enums", AllowWarningsNo, R"SOURCE(2060 add_parseh_case("enums", AllowWarningsNo, R"SOURCE(
2061enum Foo {2061enum Foo {