authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-10 01:13:51-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-06-10 01:13:51-04:00
log77678b2cbc7ac9ba2d5d4725241f6a9f7ac64fa4
tree207f75d690aa32ba054c0a4a78ad05ad1ca9902e
parentec1b6f66737f8c3cbc0420715c2c502c7e710081
signature Signed by PGP key 4AEE18F83AFDEB23

breaking syntax change: orelse keyword instead of ?? (#1096)

use the `zig-fmt-optional-default` branch to have zig fmt automatically do the changes. closes #1023

33 files changed, 187 insertions(+), 189 deletions(-)

build.zig+3-3
...@@ -102,11 +102,11 @@ pub fn build(b: *Builder) !void {...@@ -102,11 +102,11 @@ pub fn build(b: *Builder) !void {
102102
103 b.default_step.dependOn(&exe.step);103 b.default_step.dependOn(&exe.step);
104104
105 const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") ?? false;105 const skip_self_hosted = b.option(bool, "skip-self-hosted", "Main test suite skips building self hosted compiler") orelse false;
106 if (!skip_self_hosted) {106 if (!skip_self_hosted) {
107 test_step.dependOn(&exe.step);107 test_step.dependOn(&exe.step);
108 }108 }
109 const verbose_link_exe = b.option(bool, "verbose-link", "Print link command for self hosted compiler") ?? false;109 const verbose_link_exe = b.option(bool, "verbose-link", "Print link command for self hosted compiler") orelse false;
110 exe.setVerboseLink(verbose_link_exe);110 exe.setVerboseLink(verbose_link_exe);
111111
112 b.installArtifact(exe);112 b.installArtifact(exe);
...@@ -114,7 +114,7 @@ pub fn build(b: *Builder) !void {...@@ -114,7 +114,7 @@ pub fn build(b: *Builder) !void {
114 installCHeaders(b, c_header_files);114 installCHeaders(b, c_header_files);
115115
116 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");116 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
117 const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") ?? false;117 const with_lldb = b.option(bool, "with-lldb", "Run tests in LLDB to get a backtrace if one fails") orelse false;
118118
119 test_step.dependOn(docs_step);119 test_step.dependOn(docs_step);
120120
doc/docgen.zig+3-3
...@@ -25,13 +25,13 @@ pub fn main() !void {...@@ -25,13 +25,13 @@ pub fn main() !void {
2525
26 if (!args_it.skip()) @panic("expected self arg");26 if (!args_it.skip()) @panic("expected self arg");
2727
28 const zig_exe = try (args_it.next(allocator) ?? @panic("expected zig exe arg"));28 const zig_exe = try (args_it.next(allocator) orelse @panic("expected zig exe arg"));
29 defer allocator.free(zig_exe);29 defer allocator.free(zig_exe);
3030
31 const in_file_name = try (args_it.next(allocator) ?? @panic("expected input arg"));31 const in_file_name = try (args_it.next(allocator) orelse @panic("expected input arg"));
32 defer allocator.free(in_file_name);32 defer allocator.free(in_file_name);
3333
34 const out_file_name = try (args_it.next(allocator) ?? @panic("expected output arg"));34 const out_file_name = try (args_it.next(allocator) orelse @panic("expected output arg"));
35 defer allocator.free(out_file_name);35 defer allocator.free(out_file_name);
3636
37 var in_file = try os.File.openRead(allocator, in_file_name);37 var in_file = try os.File.openRead(allocator, in_file_name);
doc/langref.html.in+8-8
...@@ -985,7 +985,7 @@ a ^= b</code></pre></td>...@@ -985,7 +985,7 @@ a ^= b</code></pre></td>
985 </td>985 </td>
986 </tr>986 </tr>
987 <tr>987 <tr>
988 <td><pre><code class="zig">a ?? b</code></pre></td>988 <td><pre><code class="zig">a orelse b</code></pre></td>
989 <td>989 <td>
990 <ul>990 <ul>
991 <li>{#link|Optionals#}</li>991 <li>{#link|Optionals#}</li>
...@@ -998,7 +998,7 @@ a ^= b</code></pre></td>...@@ -998,7 +998,7 @@ a ^= b</code></pre></td>
998 </td>998 </td>
999 <td>999 <td>
1000 <pre><code class="zig">const value: ?u32 = null;1000 <pre><code class="zig">const value: ?u32 = null;
1001const unwrapped = value ?? 1234;1001const unwrapped = value orelse 1234;
1002unwrapped == 1234</code></pre>1002unwrapped == 1234</code></pre>
1003 </td>1003 </td>
1004 </tr>1004 </tr>
...@@ -1011,7 +1011,7 @@ unwrapped == 1234</code></pre>...@@ -1011,7 +1011,7 @@ unwrapped == 1234</code></pre>
1011 </td>1011 </td>
1012 <td>1012 <td>
1013 Equivalent to:1013 Equivalent to:
1014 <pre><code class="zig">a ?? unreachable</code></pre>1014 <pre><code class="zig">a orelse unreachable</code></pre>
1015 </td>1015 </td>
1016 <td>1016 <td>
1017 <pre><code class="zig">const value: ?u32 = 5678;1017 <pre><code class="zig">const value: ?u32 = 5678;
...@@ -1278,7 +1278,7 @@ x{} x.* x.?...@@ -1278,7 +1278,7 @@ x{} x.* x.?
1278== != &lt; &gt; &lt;= &gt;=1278== != &lt; &gt; &lt;= &gt;=
1279and1279and
1280or1280or
1281?? catch1281orelse catch
1282= *= /= %= += -= &lt;&lt;= &gt;&gt;= &amp;= ^= |=</code></pre>1282= *= /= %= += -= &lt;&lt;= &gt;&gt;= &amp;= ^= |=</code></pre>
1283 {#header_close#}1283 {#header_close#}
1284 {#header_close#}1284 {#header_close#}
...@@ -3062,7 +3062,7 @@ fn createFoo(param: i32) !Foo {...@@ -3062,7 +3062,7 @@ fn createFoo(param: i32) !Foo {
3062 // but we want to return it if the function succeeds.3062 // but we want to return it if the function succeeds.
3063 errdefer deallocateFoo(foo);3063 errdefer deallocateFoo(foo);
30643064
3065 const tmp_buf = allocateTmpBuffer() ?? return error.OutOfMemory;3065 const tmp_buf = allocateTmpBuffer() orelse return error.OutOfMemory;
3066 // tmp_buf is truly a temporary resource, and we for sure want to clean it up3066 // tmp_buf is truly a temporary resource, and we for sure want to clean it up
3067 // before this block leaves scope3067 // before this block leaves scope
3068 defer deallocateTmpBuffer(tmp_buf);3068 defer deallocateTmpBuffer(tmp_buf);
...@@ -3219,13 +3219,13 @@ struct Foo *do_a_thing(void) {...@@ -3219,13 +3219,13 @@ struct Foo *do_a_thing(void) {
3219extern fn malloc(size: size_t) ?*u8;3219extern fn malloc(size: size_t) ?*u8;
32203220
3221fn doAThing() ?*Foo {3221fn doAThing() ?*Foo {
3222 const ptr = malloc(1234) ?? return null;3222 const ptr = malloc(1234) orelse return null;
3223 // ...3223 // ...
3224}3224}
3225 {#code_end#}3225 {#code_end#}
3226 <p>3226 <p>
3227 Here, Zig is at least as convenient, if not more, than C. And, the type of "ptr"3227 Here, Zig is at least as convenient, if not more, than C. And, the type of "ptr"
3228 is <code>*u8</code> <em>not</em> <code>?*u8</code>. The <code>??</code> operator3228 is <code>*u8</code> <em>not</em> <code>?*u8</code>. The <code>orelse</code> keyword
3229 unwrapped the optional type and therefore <code>ptr</code> is guaranteed to be non-null everywhere3229 unwrapped the optional type and therefore <code>ptr</code> is guaranteed to be non-null everywhere
3230 it is used in the function.3230 it is used in the function.
3231 </p>3231 </p>
...@@ -5941,7 +5941,7 @@ AsmClobbers= ":" list(String, ",")...@@ -5941,7 +5941,7 @@ AsmClobbers= ":" list(String, ",")
59415941
5942UnwrapExpression = BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression5942UnwrapExpression = BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression
59435943
5944UnwrapOptional = "??" Expression5944UnwrapOptional = "orelse" Expression
59455945
5946UnwrapError = "catch" option("|" Symbol "|") Expression5946UnwrapError = "catch" option("|" Symbol "|") Expression
59475947
src-self-hosted/main.zig+7-7
...@@ -212,7 +212,7 @@ fn cmdBuild(allocator: *Allocator, args: []const []const u8) !void {...@@ -212,7 +212,7 @@ fn cmdBuild(allocator: *Allocator, args: []const []const u8) !void {
212 const build_runner_path = try os.path.join(allocator, special_dir, "build_runner.zig");212 const build_runner_path = try os.path.join(allocator, special_dir, "build_runner.zig");
213 defer allocator.free(build_runner_path);213 defer allocator.free(build_runner_path);
214214
215 const build_file = flags.single("build-file") ?? "build.zig";215 const build_file = flags.single("build-file") orelse "build.zig";
216 const build_file_abs = try os.path.resolve(allocator, ".", build_file);216 const build_file_abs = try os.path.resolve(allocator, ".", build_file);
217 defer allocator.free(build_file_abs);217 defer allocator.free(build_file_abs);
218218
...@@ -516,7 +516,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo...@@ -516,7 +516,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo
516516
517 const basename = os.path.basename(in_file.?);517 const basename = os.path.basename(in_file.?);
518 var it = mem.split(basename, ".");518 var it = mem.split(basename, ".");
519 const root_name = it.next() ?? {519 const root_name = it.next() orelse {
520 try stderr.write("file name cannot be empty\n");520 try stderr.write("file name cannot be empty\n");
521 os.exit(1);521 os.exit(1);
522 };522 };
...@@ -535,7 +535,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo...@@ -535,7 +535,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo
535535
536 const zig_root_source_file = in_file;536 const zig_root_source_file = in_file;
537537
538 const full_cache_dir = os.path.resolve(allocator, ".", flags.single("cache-dir") ?? "zig-cache"[0..]) catch {538 const full_cache_dir = os.path.resolve(allocator, ".", flags.single("cache-dir") orelse "zig-cache"[0..]) catch {
539 os.exit(1);539 os.exit(1);
540 };540 };
541 defer allocator.free(full_cache_dir);541 defer allocator.free(full_cache_dir);
...@@ -555,9 +555,9 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo...@@ -555,9 +555,9 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo
555 );555 );
556 defer module.destroy();556 defer module.destroy();
557557
558 module.version_major = try std.fmt.parseUnsigned(u32, flags.single("ver-major") ?? "0", 10);558 module.version_major = try std.fmt.parseUnsigned(u32, flags.single("ver-major") orelse "0", 10);
559 module.version_minor = try std.fmt.parseUnsigned(u32, flags.single("ver-minor") ?? "0", 10);559 module.version_minor = try std.fmt.parseUnsigned(u32, flags.single("ver-minor") orelse "0", 10);
560 module.version_patch = try std.fmt.parseUnsigned(u32, flags.single("ver-patch") ?? "0", 10);560 module.version_patch = try std.fmt.parseUnsigned(u32, flags.single("ver-patch") orelse "0", 10);
561561
562 module.is_test = false;562 module.is_test = false;
563563
...@@ -652,7 +652,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo...@@ -652,7 +652,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo
652 }652 }
653653
654 try module.build();654 try module.build();
655 try module.link(flags.single("out-file") ?? null);655 try module.link(flags.single("out-file") orelse null);
656656
657 if (flags.present("print-timing-info")) {657 if (flags.present("print-timing-info")) {
658 // codegen_print_timing_info(g, stderr);658 // codegen_print_timing_info(g, stderr);
src-self-hosted/module.zig+4-4
...@@ -130,13 +130,13 @@ pub const Module = struct {...@@ -130,13 +130,13 @@ pub const Module = struct {
130 var name_buffer = try Buffer.init(allocator, name);130 var name_buffer = try Buffer.init(allocator, name);
131 errdefer name_buffer.deinit();131 errdefer name_buffer.deinit();
132132
133 const context = c.LLVMContextCreate() ?? return error.OutOfMemory;133 const context = c.LLVMContextCreate() orelse return error.OutOfMemory;
134 errdefer c.LLVMContextDispose(context);134 errdefer c.LLVMContextDispose(context);
135135
136 const module = c.LLVMModuleCreateWithNameInContext(name_buffer.ptr(), context) ?? return error.OutOfMemory;136 const module = c.LLVMModuleCreateWithNameInContext(name_buffer.ptr(), context) orelse return error.OutOfMemory;
137 errdefer c.LLVMDisposeModule(module);137 errdefer c.LLVMDisposeModule(module);
138138
139 const builder = c.LLVMCreateBuilderInContext(context) ?? return error.OutOfMemory;139 const builder = c.LLVMCreateBuilderInContext(context) orelse return error.OutOfMemory;
140 errdefer c.LLVMDisposeBuilder(builder);140 errdefer c.LLVMDisposeBuilder(builder);
141141
142 const module_ptr = try allocator.create(Module);142 const module_ptr = try allocator.create(Module);
...@@ -223,7 +223,7 @@ pub const Module = struct {...@@ -223,7 +223,7 @@ pub const Module = struct {
223 c.ZigLLVMParseCommandLineOptions(self.llvm_argv.len + 1, c_compatible_args.ptr);223 c.ZigLLVMParseCommandLineOptions(self.llvm_argv.len + 1, c_compatible_args.ptr);
224 }224 }
225225
226 const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path");226 const root_src_path = self.root_src_path orelse @panic("TODO handle null root src path");
227 const root_src_real_path = os.path.real(self.allocator, root_src_path) catch |err| {227 const root_src_real_path = os.path.real(self.allocator, root_src_path) catch |err| {
228 try printError("unable to get real path '{}': {}", root_src_path, err);228 try printError("unable to get real path '{}': {}", root_src_path, err);
229 return err;229 return err;
src/all_types.hpp+6-1
...@@ -387,6 +387,7 @@ enum NodeType {...@@ -387,6 +387,7 @@ enum NodeType {
387 NodeTypeSliceExpr,387 NodeTypeSliceExpr,
388 NodeTypeFieldAccessExpr,388 NodeTypeFieldAccessExpr,
389 NodeTypePtrDeref,389 NodeTypePtrDeref,
390 NodeTypeUnwrapOptional,
390 NodeTypeUse,391 NodeTypeUse,
391 NodeTypeBoolLiteral,392 NodeTypeBoolLiteral,
392 NodeTypeNullLiteral,393 NodeTypeNullLiteral,
...@@ -575,6 +576,10 @@ struct AstNodeCatchExpr {...@@ -575,6 +576,10 @@ struct AstNodeCatchExpr {
575 AstNode *op2;576 AstNode *op2;
576};577};
577578
579struct AstNodeUnwrapOptional {
580 AstNode *expr;
581};
582
578enum CastOp {583enum CastOp {
579 CastOpNoCast, // signifies the function call expression is not a cast584 CastOpNoCast, // signifies the function call expression is not a cast
580 CastOpNoop, // fn call expr is a cast, but does nothing585 CastOpNoop, // fn call expr is a cast, but does nothing
...@@ -624,7 +629,6 @@ enum PrefixOp {...@@ -624,7 +629,6 @@ enum PrefixOp {
624 PrefixOpNegation,629 PrefixOpNegation,
625 PrefixOpNegationWrap,630 PrefixOpNegationWrap,
626 PrefixOpOptional,631 PrefixOpOptional,
627 PrefixOpUnwrapOptional,
628 PrefixOpAddrOf,632 PrefixOpAddrOf,
629};633};
630634
...@@ -909,6 +913,7 @@ struct AstNode {...@@ -909,6 +913,7 @@ struct AstNode {
909 AstNodeTestDecl test_decl;913 AstNodeTestDecl test_decl;
910 AstNodeBinOpExpr bin_op_expr;914 AstNodeBinOpExpr bin_op_expr;
911 AstNodeCatchExpr unwrap_err_expr;915 AstNodeCatchExpr unwrap_err_expr;
916 AstNodeUnwrapOptional unwrap_optional;
912 AstNodePrefixOpExpr prefix_op_expr;917 AstNodePrefixOpExpr prefix_op_expr;
913 AstNodePointerType pointer_type;918 AstNodePointerType pointer_type;
914 AstNodeFnCallExpr fn_call_expr;919 AstNodeFnCallExpr fn_call_expr;
src/analyze.cpp+1
...@@ -3308,6 +3308,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -3308,6 +3308,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
3308 case NodeTypeAsmExpr:3308 case NodeTypeAsmExpr:
3309 case NodeTypeFieldAccessExpr:3309 case NodeTypeFieldAccessExpr:
3310 case NodeTypePtrDeref:3310 case NodeTypePtrDeref:
3311 case NodeTypeUnwrapOptional:
3311 case NodeTypeStructField:3312 case NodeTypeStructField:
3312 case NodeTypeContainerInitExpr:3313 case NodeTypeContainerInitExpr:
3313 case NodeTypeStructValueField:3314 case NodeTypeStructValueField:
src/ast_render.cpp+10-2
...@@ -50,7 +50,7 @@ static const char *bin_op_str(BinOpType bin_op) {...@@ -50,7 +50,7 @@ static const char *bin_op_str(BinOpType bin_op) {
50 case BinOpTypeAssignBitXor: return "^=";50 case BinOpTypeAssignBitXor: return "^=";
51 case BinOpTypeAssignBitOr: return "|=";51 case BinOpTypeAssignBitOr: return "|=";
52 case BinOpTypeAssignMergeErrorSets: return "||=";52 case BinOpTypeAssignMergeErrorSets: return "||=";
53 case BinOpTypeUnwrapOptional: return "??";53 case BinOpTypeUnwrapOptional: return "orelse";
54 case BinOpTypeArrayCat: return "++";54 case BinOpTypeArrayCat: return "++";
55 case BinOpTypeArrayMult: return "**";55 case BinOpTypeArrayMult: return "**";
56 case BinOpTypeErrorUnion: return "!";56 case BinOpTypeErrorUnion: return "!";
...@@ -67,7 +67,6 @@ static const char *prefix_op_str(PrefixOp prefix_op) {...@@ -67,7 +67,6 @@ static const char *prefix_op_str(PrefixOp prefix_op) {
67 case PrefixOpBoolNot: return "!";67 case PrefixOpBoolNot: return "!";
68 case PrefixOpBinNot: return "~";68 case PrefixOpBinNot: return "~";
69 case PrefixOpOptional: return "?";69 case PrefixOpOptional: return "?";
70 case PrefixOpUnwrapOptional: return "??";
71 case PrefixOpAddrOf: return "&";70 case PrefixOpAddrOf: return "&";
72 }71 }
73 zig_unreachable();72 zig_unreachable();
...@@ -222,6 +221,8 @@ static const char *node_type_str(NodeType node_type) {...@@ -222,6 +221,8 @@ static const char *node_type_str(NodeType node_type) {
222 return "FieldAccessExpr";221 return "FieldAccessExpr";
223 case NodeTypePtrDeref:222 case NodeTypePtrDeref:
224 return "PtrDerefExpr";223 return "PtrDerefExpr";
224 case NodeTypeUnwrapOptional:
225 return "UnwrapOptional";
225 case NodeTypeContainerDecl:226 case NodeTypeContainerDecl:
226 return "ContainerDecl";227 return "ContainerDecl";
227 case NodeTypeStructField:228 case NodeTypeStructField:
...@@ -711,6 +712,13 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -711,6 +712,13 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
711 fprintf(ar->f, ".*");712 fprintf(ar->f, ".*");
712 break;713 break;
713 }714 }
715 case NodeTypeUnwrapOptional:
716 {
717 AstNode *lhs = node->data.unwrap_optional.expr;
718 render_node_ungrouped(ar, lhs);
719 fprintf(ar->f, ".?");
720 break;
721 }
714 case NodeTypeUndefinedLiteral:722 case NodeTypeUndefinedLiteral:
715 fprintf(ar->f, "undefined");723 fprintf(ar->f, "undefined");
716 break;724 break;
src/ir.cpp+13-18
...@@ -4661,21 +4661,6 @@ static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode...@@ -4661,21 +4661,6 @@ static IrInstruction *ir_gen_err_assert_ok(IrBuilder *irb, Scope *scope, AstNode
4661 return ir_build_load_ptr(irb, scope, source_node, payload_ptr);4661 return ir_build_load_ptr(irb, scope, source_node, payload_ptr);
4662}4662}
46634663
4664static IrInstruction *ir_gen_maybe_assert_ok(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) {
4665 assert(node->type == NodeTypePrefixOpExpr);
4666 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
4667
4668 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR);
4669 if (maybe_ptr == irb->codegen->invalid_instruction)
4670 return irb->codegen->invalid_instruction;
4671
4672 IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, scope, node, maybe_ptr, true);
4673 if (lval.is_ptr)
4674 return unwrapped_ptr;
4675
4676 return ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
4677}
4678
4679static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *node) {4664static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *node) {
4680 assert(node->type == NodeTypePrefixOpExpr);4665 assert(node->type == NodeTypePrefixOpExpr);
4681 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;4666 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
...@@ -4705,8 +4690,6 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod...@@ -4705,8 +4690,6 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
4705 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegationWrap), lval);4690 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegationWrap), lval);
4706 case PrefixOpOptional:4691 case PrefixOpOptional:
4707 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval);4692 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval);
4708 case PrefixOpUnwrapOptional:
4709 return ir_gen_maybe_assert_ok(irb, scope, node, lval);
4710 case PrefixOpAddrOf: {4693 case PrefixOpAddrOf: {
4711 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;4694 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
4712 return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR), lval);4695 return ir_lval_wrap(irb, scope, ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR), lval);
...@@ -6541,7 +6524,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -6541,7 +6524,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
6541 return ir_build_load_ptr(irb, scope, node, ptr_instruction);6524 return ir_build_load_ptr(irb, scope, node, ptr_instruction);
6542 }6525 }
6543 case NodeTypePtrDeref: {6526 case NodeTypePtrDeref: {
6544 assert(node->type == NodeTypePtrDeref);
6545 AstNode *expr_node = node->data.ptr_deref_expr.target;6527 AstNode *expr_node = node->data.ptr_deref_expr.target;
6546 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval);6528 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval);
6547 if (value == irb->codegen->invalid_instruction)6529 if (value == irb->codegen->invalid_instruction)
...@@ -6549,6 +6531,19 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -6549,6 +6531,19 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
65496531
6550 return ir_build_un_op(irb, scope, node, IrUnOpDereference, value);6532 return ir_build_un_op(irb, scope, node, IrUnOpDereference, value);
6551 }6533 }
6534 case NodeTypeUnwrapOptional: {
6535 AstNode *expr_node = node->data.unwrap_optional.expr;
6536
6537 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LVAL_PTR);
6538 if (maybe_ptr == irb->codegen->invalid_instruction)
6539 return irb->codegen->invalid_instruction;
6540
6541 IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, scope, node, maybe_ptr, true);
6542 if (lval.is_ptr)
6543 return unwrapped_ptr;
6544
6545 return ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
6546 }
6552 case NodeTypeThisLiteral:6547 case NodeTypeThisLiteral:
6553 return ir_lval_wrap(irb, scope, ir_gen_this_literal(irb, scope, node), lval);6548 return ir_lval_wrap(irb, scope, ir_gen_this_literal(irb, scope, node), lval);
6554 case NodeTypeBoolLiteral:6549 case NodeTypeBoolLiteral:
src/parser.cpp+7-6
...@@ -1151,9 +1151,8 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index,...@@ -1151,9 +1151,8 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index,
1151 } else if (token->id == TokenIdQuestion) {1151 } else if (token->id == TokenIdQuestion) {
1152 *token_index += 1;1152 *token_index += 1;
11531153
1154 AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, first_token);1154 AstNode *node = ast_create_node(pc, NodeTypeUnwrapOptional, first_token);
1155 node->data.prefix_op_expr.prefix_op = PrefixOpUnwrapOptional;1155 node->data.unwrap_optional.expr = primary_expr;
1156 node->data.prefix_op_expr.primary_expr = primary_expr;
11571156
1158 primary_expr = node;1157 primary_expr = node;
1159 } else {1158 } else {
...@@ -1173,7 +1172,6 @@ static PrefixOp tok_to_prefix_op(Token *token) {...@@ -1173,7 +1172,6 @@ static PrefixOp tok_to_prefix_op(Token *token) {
1173 case TokenIdMinusPercent: return PrefixOpNegationWrap;1172 case TokenIdMinusPercent: return PrefixOpNegationWrap;
1174 case TokenIdTilde: return PrefixOpBinNot;1173 case TokenIdTilde: return PrefixOpBinNot;
1175 case TokenIdQuestion: return PrefixOpOptional;1174 case TokenIdQuestion: return PrefixOpOptional;
1176 case TokenIdDoubleQuestion: return PrefixOpUnwrapOptional;
1177 case TokenIdAmpersand: return PrefixOpAddrOf;1175 case TokenIdAmpersand: return PrefixOpAddrOf;
1178 default: return PrefixOpInvalid;1176 default: return PrefixOpInvalid;
1179 }1177 }
...@@ -2312,7 +2310,7 @@ static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool ma...@@ -2312,7 +2310,7 @@ static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool ma
23122310
2313/*2311/*
2314UnwrapExpression : BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression2312UnwrapExpression : BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression
2315UnwrapOptional : "??" BoolOrExpression2313UnwrapOptional = "orelse" Expression
2316UnwrapError = "catch" option("|" Symbol "|") Expression2314UnwrapError = "catch" option("|" Symbol "|") Expression
2317*/2315*/
2318static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) {2316static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
...@@ -2322,7 +2320,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, boo...@@ -2322,7 +2320,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, boo
23222320
2323 Token *token = &pc->tokens->at(*token_index);2321 Token *token = &pc->tokens->at(*token_index);
23242322
2325 if (token->id == TokenIdDoubleQuestion) {2323 if (token->id == TokenIdKeywordOrElse) {
2326 *token_index += 1;2324 *token_index += 1;
23272325
2328 AstNode *rhs = ast_parse_expression(pc, token_index, true);2326 AstNode *rhs = ast_parse_expression(pc, token_index, true);
...@@ -3035,6 +3033,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont...@@ -3035,6 +3033,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
3035 case NodeTypePtrDeref:3033 case NodeTypePtrDeref:
3036 visit_field(&node->data.ptr_deref_expr.target, visit, context);3034 visit_field(&node->data.ptr_deref_expr.target, visit, context);
3037 break;3035 break;
3036 case NodeTypeUnwrapOptional:
3037 visit_field(&node->data.unwrap_optional.expr, visit, context);
3038 break;
3038 case NodeTypeUse:3039 case NodeTypeUse:
3039 visit_field(&node->data.use.expr, visit, context);3040 visit_field(&node->data.use.expr, visit, context);
3040 break;3041 break;
src/tokenizer.cpp+6-21
...@@ -134,6 +134,7 @@ static const struct ZigKeyword zig_keywords[] = {...@@ -134,6 +134,7 @@ static const struct ZigKeyword zig_keywords[] = {
134 {"noalias", TokenIdKeywordNoAlias},134 {"noalias", TokenIdKeywordNoAlias},
135 {"null", TokenIdKeywordNull},135 {"null", TokenIdKeywordNull},
136 {"or", TokenIdKeywordOr},136 {"or", TokenIdKeywordOr},
137 {"orelse", TokenIdKeywordOrElse},
137 {"packed", TokenIdKeywordPacked},138 {"packed", TokenIdKeywordPacked},
138 {"promise", TokenIdKeywordPromise},139 {"promise", TokenIdKeywordPromise},
139 {"pub", TokenIdKeywordPub},140 {"pub", TokenIdKeywordPub},
...@@ -215,7 +216,6 @@ enum TokenizeState {...@@ -215,7 +216,6 @@ enum TokenizeState {
215 TokenizeStateSawGreaterThanGreaterThan,216 TokenizeStateSawGreaterThanGreaterThan,
216 TokenizeStateSawDot,217 TokenizeStateSawDot,
217 TokenizeStateSawDotDot,218 TokenizeStateSawDotDot,
218 TokenizeStateSawQuestionMark,
219 TokenizeStateSawAtSign,219 TokenizeStateSawAtSign,
220 TokenizeStateCharCode,220 TokenizeStateCharCode,
221 TokenizeStateError,221 TokenizeStateError,
...@@ -532,6 +532,10 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -532,6 +532,10 @@ void tokenize(Buf *buf, Tokenization *out) {
532 begin_token(&t, TokenIdComma);532 begin_token(&t, TokenIdComma);
533 end_token(&t);533 end_token(&t);
534 break;534 break;
535 case '?':
536 begin_token(&t, TokenIdQuestion);
537 end_token(&t);
538 break;
535 case '{':539 case '{':
536 begin_token(&t, TokenIdLBrace);540 begin_token(&t, TokenIdLBrace);
537 end_token(&t);541 end_token(&t);
...@@ -624,28 +628,10 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -624,28 +628,10 @@ void tokenize(Buf *buf, Tokenization *out) {
624 begin_token(&t, TokenIdDot);628 begin_token(&t, TokenIdDot);
625 t.state = TokenizeStateSawDot;629 t.state = TokenizeStateSawDot;
626 break;630 break;
627 case '?':
628 begin_token(&t, TokenIdQuestion);
629 t.state = TokenizeStateSawQuestionMark;
630 break;
631 default:631 default:
632 invalid_char_error(&t, c);632 invalid_char_error(&t, c);
633 }633 }
634 break;634 break;
635 case TokenizeStateSawQuestionMark:
636 switch (c) {
637 case '?':
638 set_token_id(&t, t.cur_tok, TokenIdDoubleQuestion);
639 end_token(&t);
640 t.state = TokenizeStateStart;
641 break;
642 default:
643 t.pos -= 1;
644 end_token(&t);
645 t.state = TokenizeStateStart;
646 continue;
647 }
648 break;
649 case TokenizeStateSawDot:635 case TokenizeStateSawDot:
650 switch (c) {636 switch (c) {
651 case '.':637 case '.':
...@@ -1480,7 +1466,6 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -1480,7 +1466,6 @@ void tokenize(Buf *buf, Tokenization *out) {
1480 case TokenizeStateSawGreaterThan:1466 case TokenizeStateSawGreaterThan:
1481 case TokenizeStateSawGreaterThanGreaterThan:1467 case TokenizeStateSawGreaterThanGreaterThan:
1482 case TokenizeStateSawDot:1468 case TokenizeStateSawDot:
1483 case TokenizeStateSawQuestionMark:
1484 case TokenizeStateSawAtSign:1469 case TokenizeStateSawAtSign:
1485 case TokenizeStateSawStarPercent:1470 case TokenizeStateSawStarPercent:
1486 case TokenizeStateSawPlusPercent:1471 case TokenizeStateSawPlusPercent:
...@@ -1545,7 +1530,6 @@ const char * token_name(TokenId id) {...@@ -1545,7 +1530,6 @@ const char * token_name(TokenId id) {
1545 case TokenIdDash: return "-";1530 case TokenIdDash: return "-";
1546 case TokenIdDivEq: return "/=";1531 case TokenIdDivEq: return "/=";
1547 case TokenIdDot: return ".";1532 case TokenIdDot: return ".";
1548 case TokenIdDoubleQuestion: return "??";
1549 case TokenIdEllipsis2: return "..";1533 case TokenIdEllipsis2: return "..";
1550 case TokenIdEllipsis3: return "...";1534 case TokenIdEllipsis3: return "...";
1551 case TokenIdEof: return "EOF";1535 case TokenIdEof: return "EOF";
...@@ -1582,6 +1566,7 @@ const char * token_name(TokenId id) {...@@ -1582,6 +1566,7 @@ const char * token_name(TokenId id) {
1582 case TokenIdKeywordNoAlias: return "noalias";1566 case TokenIdKeywordNoAlias: return "noalias";
1583 case TokenIdKeywordNull: return "null";1567 case TokenIdKeywordNull: return "null";
1584 case TokenIdKeywordOr: return "or";1568 case TokenIdKeywordOr: return "or";
1569 case TokenIdKeywordOrElse: return "orelse";
1585 case TokenIdKeywordPacked: return "packed";1570 case TokenIdKeywordPacked: return "packed";
1586 case TokenIdKeywordPromise: return "promise";1571 case TokenIdKeywordPromise: return "promise";
1587 case TokenIdKeywordPub: return "pub";1572 case TokenIdKeywordPub: return "pub";
src/tokenizer.hpp+1-1
...@@ -41,7 +41,6 @@ enum TokenId {...@@ -41,7 +41,6 @@ enum TokenId {
41 TokenIdDash,41 TokenIdDash,
42 TokenIdDivEq,42 TokenIdDivEq,
43 TokenIdDot,43 TokenIdDot,
44 TokenIdDoubleQuestion,
45 TokenIdEllipsis2,44 TokenIdEllipsis2,
46 TokenIdEllipsis3,45 TokenIdEllipsis3,
47 TokenIdEof,46 TokenIdEof,
...@@ -76,6 +75,7 @@ enum TokenId {...@@ -76,6 +75,7 @@ enum TokenId {
76 TokenIdKeywordNoAlias,75 TokenIdKeywordNoAlias,
77 TokenIdKeywordNull,76 TokenIdKeywordNull,
78 TokenIdKeywordOr,77 TokenIdKeywordOr,
78 TokenIdKeywordOrElse,
79 TokenIdKeywordPacked,79 TokenIdKeywordPacked,
80 TokenIdKeywordPromise,80 TokenIdKeywordPromise,
81 TokenIdKeywordPub,81 TokenIdKeywordPub,
src/translate_c.cpp+9-7
...@@ -260,6 +260,12 @@ static AstNode *trans_create_node_prefix_op(Context *c, PrefixOp op, AstNode *ch...@@ -260,6 +260,12 @@ static AstNode *trans_create_node_prefix_op(Context *c, PrefixOp op, AstNode *ch
260 return node;260 return node;
261}261}
262262
263static AstNode *trans_create_node_unwrap_null(Context *c, AstNode *child_node) {
264 AstNode *node = trans_create_node(c, NodeTypeUnwrapOptional);
265 node->data.unwrap_optional.expr = child_node;
266 return node;
267}
268
263static AstNode *trans_create_node_bin_op(Context *c, AstNode *lhs_node, BinOpType op, AstNode *rhs_node) {269static AstNode *trans_create_node_bin_op(Context *c, AstNode *lhs_node, BinOpType op, AstNode *rhs_node) {
264 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);270 AstNode *node = trans_create_node(c, NodeTypeBinOpExpr);
265 node->data.bin_op_expr.op1 = lhs_node;271 node->data.bin_op_expr.op1 = lhs_node;
...@@ -382,7 +388,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r...@@ -382,7 +388,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r
382 fn_def->data.fn_def.fn_proto = fn_proto;388 fn_def->data.fn_def.fn_proto = fn_proto;
383 fn_proto->data.fn_proto.fn_def_node = fn_def;389 fn_proto->data.fn_proto.fn_def_node = fn_def;
384390
385 AstNode *unwrap_node = trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, ref_node);391 AstNode *unwrap_node = trans_create_node_unwrap_null(c, ref_node);
386 AstNode *fn_call_node = trans_create_node(c, NodeTypeFnCallExpr);392 AstNode *fn_call_node = trans_create_node(c, NodeTypeFnCallExpr);
387 fn_call_node->data.fn_call_expr.fn_ref_expr = unwrap_node;393 fn_call_node->data.fn_call_expr.fn_ref_expr = unwrap_node;
388394
...@@ -409,10 +415,6 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r...@@ -409,10 +415,6 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r
409 return fn_def;415 return fn_def;
410}416}
411417
412static AstNode *trans_create_node_unwrap_null(Context *c, AstNode *child) {
413 return trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, child);
414}
415
416static AstNode *get_global(Context *c, Buf *name) {418static AstNode *get_global(Context *c, Buf *name) {
417 {419 {
418 auto entry = c->global_table.maybe_get(name);420 auto entry = c->global_table.maybe_get(name);
...@@ -1963,7 +1965,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc...@@ -1963,7 +1965,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
1963 bool is_fn_ptr = qual_type_is_fn_ptr(stmt->getSubExpr()->getType());1965 bool is_fn_ptr = qual_type_is_fn_ptr(stmt->getSubExpr()->getType());
1964 if (is_fn_ptr)1966 if (is_fn_ptr)
1965 return value_node;1967 return value_node;
1966 AstNode *unwrapped = trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, value_node);1968 AstNode *unwrapped = trans_create_node_unwrap_null(c, value_node);
1967 return trans_create_node_ptr_deref(c, unwrapped);1969 return trans_create_node_ptr_deref(c, unwrapped);
1968 }1970 }
1969 case UO_Plus:1971 case UO_Plus:
...@@ -2587,7 +2589,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *...@@ -2587,7 +2589,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *
2587 }2589 }
2588 }2590 }
2589 if (callee_node == nullptr) {2591 if (callee_node == nullptr) {
2590 callee_node = trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, callee_raw_node);2592 callee_node = trans_create_node_unwrap_null(c, callee_raw_node);
2591 }2593 }
2592 } else {2594 } else {
2593 callee_node = callee_raw_node;2595 callee_node = callee_raw_node;
std/atomic/queue.zig+2-2
...@@ -33,8 +33,8 @@ pub fn Queue(comptime T: type) type {...@@ -33,8 +33,8 @@ pub fn Queue(comptime T: type) type {
33 pub fn get(self: *Self) ?*Node {33 pub fn get(self: *Self) ?*Node {
34 var head = @atomicLoad(*Node, &self.head, AtomicOrder.SeqCst);34 var head = @atomicLoad(*Node, &self.head, AtomicOrder.SeqCst);
35 while (true) {35 while (true) {
36 const node = head.next ?? return null;36 const node = head.next orelse return null;
37 head = @cmpxchgWeak(*Node, &self.head, head, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? return node;37 head = @cmpxchgWeak(*Node, &self.head, head, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) orelse return node;
38 }38 }
39 }39 }
40 };40 };
std/atomic/stack.zig+2-2
...@@ -28,14 +28,14 @@ pub fn Stack(comptime T: type) type {...@@ -28,14 +28,14 @@ pub fn Stack(comptime T: type) type {
28 var root = @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst);28 var root = @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst);
29 while (true) {29 while (true) {
30 node.next = root;30 node.next = root;
31 root = @cmpxchgWeak(?*Node, &self.root, root, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? break;31 root = @cmpxchgWeak(?*Node, &self.root, root, node, AtomicOrder.SeqCst, AtomicOrder.SeqCst) orelse break;
32 }32 }
33 }33 }
3434
35 pub fn pop(self: *Self) ?*Node {35 pub fn pop(self: *Self) ?*Node {
36 var root = @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst);36 var root = @atomicLoad(?*Node, &self.root, AtomicOrder.SeqCst);
37 while (true) {37 while (true) {
38 root = @cmpxchgWeak(?*Node, &self.root, root, (root ?? return null).next, AtomicOrder.SeqCst, AtomicOrder.SeqCst) ?? return root;38 root = @cmpxchgWeak(?*Node, &self.root, root, (root orelse return null).next, AtomicOrder.SeqCst, AtomicOrder.SeqCst) orelse return root;
39 }39 }
40 }40 }
4141
std/buf_map.zig+3-3
...@@ -19,7 +19,7 @@ pub const BufMap = struct {...@@ -19,7 +19,7 @@ pub const BufMap = struct {
19 pub fn deinit(self: *const BufMap) void {19 pub fn deinit(self: *const BufMap) void {
20 var it = self.hash_map.iterator();20 var it = self.hash_map.iterator();
21 while (true) {21 while (true) {
22 const entry = it.next() ?? break;22 const entry = it.next() orelse break;
23 self.free(entry.key);23 self.free(entry.key);
24 self.free(entry.value);24 self.free(entry.value);
25 }25 }
...@@ -37,12 +37,12 @@ pub const BufMap = struct {...@@ -37,12 +37,12 @@ pub const BufMap = struct {
37 }37 }
3838
39 pub fn get(self: *const BufMap, key: []const u8) ?[]const u8 {39 pub fn get(self: *const BufMap, key: []const u8) ?[]const u8 {
40 const entry = self.hash_map.get(key) ?? return null;40 const entry = self.hash_map.get(key) orelse return null;
41 return entry.value;41 return entry.value;
42 }42 }
4343
44 pub fn delete(self: *BufMap, key: []const u8) void {44 pub fn delete(self: *BufMap, key: []const u8) void {
45 const entry = self.hash_map.remove(key) ?? return;45 const entry = self.hash_map.remove(key) orelse return;
46 self.free(entry.key);46 self.free(entry.key);
47 self.free(entry.value);47 self.free(entry.value);
48 }48 }
std/buf_set.zig+2-2
...@@ -17,7 +17,7 @@ pub const BufSet = struct {...@@ -17,7 +17,7 @@ pub const BufSet = struct {
17 pub fn deinit(self: *const BufSet) void {17 pub fn deinit(self: *const BufSet) void {
18 var it = self.hash_map.iterator();18 var it = self.hash_map.iterator();
19 while (true) {19 while (true) {
20 const entry = it.next() ?? break;20 const entry = it.next() orelse break;
21 self.free(entry.key);21 self.free(entry.key);
22 }22 }
2323
...@@ -33,7 +33,7 @@ pub const BufSet = struct {...@@ -33,7 +33,7 @@ pub const BufSet = struct {
33 }33 }
3434
35 pub fn delete(self: *BufSet, key: []const u8) void {35 pub fn delete(self: *BufSet, key: []const u8) void {
36 const entry = self.hash_map.remove(key) ?? return;36 const entry = self.hash_map.remove(key) orelse return;
37 self.free(entry.key);37 self.free(entry.key);
38 }38 }
3939
std/build.zig+12-12
...@@ -136,7 +136,7 @@ pub const Builder = struct {...@@ -136,7 +136,7 @@ pub const Builder = struct {
136 }136 }
137137
138 pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {138 pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {
139 self.prefix = maybe_prefix ?? "/usr/local"; // TODO better default139 self.prefix = maybe_prefix orelse "/usr/local"; // TODO better default
140 self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable;140 self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable;
141 self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable;141 self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable;
142 }142 }
...@@ -312,9 +312,9 @@ pub const Builder = struct {...@@ -312,9 +312,9 @@ pub const Builder = struct {
312 if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {312 if (os.getEnvVarOwned(self.allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
313 var it = mem.split(nix_cflags_compile, " ");313 var it = mem.split(nix_cflags_compile, " ");
314 while (true) {314 while (true) {
315 const word = it.next() ?? break;315 const word = it.next() orelse break;
316 if (mem.eql(u8, word, "-isystem")) {316 if (mem.eql(u8, word, "-isystem")) {
317 const include_path = it.next() ?? {317 const include_path = it.next() orelse {
318 warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n");318 warn("Expected argument after -isystem in NIX_CFLAGS_COMPILE\n");
319 break;319 break;
320 };320 };
...@@ -330,9 +330,9 @@ pub const Builder = struct {...@@ -330,9 +330,9 @@ pub const Builder = struct {
330 if (os.getEnvVarOwned(self.allocator, "NIX_LDFLAGS")) |nix_ldflags| {330 if (os.getEnvVarOwned(self.allocator, "NIX_LDFLAGS")) |nix_ldflags| {
331 var it = mem.split(nix_ldflags, " ");331 var it = mem.split(nix_ldflags, " ");
332 while (true) {332 while (true) {
333 const word = it.next() ?? break;333 const word = it.next() orelse break;
334 if (mem.eql(u8, word, "-rpath")) {334 if (mem.eql(u8, word, "-rpath")) {
335 const rpath = it.next() ?? {335 const rpath = it.next() orelse {
336 warn("Expected argument after -rpath in NIX_LDFLAGS\n");336 warn("Expected argument after -rpath in NIX_LDFLAGS\n");
337 break;337 break;
338 };338 };
...@@ -362,7 +362,7 @@ pub const Builder = struct {...@@ -362,7 +362,7 @@ pub const Builder = struct {
362 }362 }
363 self.available_options_list.append(available_option) catch unreachable;363 self.available_options_list.append(available_option) catch unreachable;
364364
365 const entry = self.user_input_options.get(name) ?? return null;365 const entry = self.user_input_options.get(name) orelse return null;
366 entry.value.used = true;366 entry.value.used = true;
367 switch (type_id) {367 switch (type_id) {
368 TypeId.Bool => switch (entry.value.value) {368 TypeId.Bool => switch (entry.value.value) {
...@@ -416,9 +416,9 @@ pub const Builder = struct {...@@ -416,9 +416,9 @@ pub const Builder = struct {
416 pub fn standardReleaseOptions(self: *Builder) builtin.Mode {416 pub fn standardReleaseOptions(self: *Builder) builtin.Mode {
417 if (self.release_mode) |mode| return mode;417 if (self.release_mode) |mode| return mode;
418418
419 const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false;419 const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") orelse false;
420 const release_fast = self.option(bool, "release-fast", "optimizations on and safety off") ?? false;420 const release_fast = self.option(bool, "release-fast", "optimizations on and safety off") orelse false;
421 const release_small = self.option(bool, "release-small", "size optimizations on and safety off") ?? false;421 const release_small = self.option(bool, "release-small", "size optimizations on and safety off") orelse false;
422422
423 const mode = if (release_safe and !release_fast and !release_small) builtin.Mode.ReleaseSafe else if (release_fast and !release_safe and !release_small) builtin.Mode.ReleaseFast else if (release_small and !release_fast and !release_safe) builtin.Mode.ReleaseSmall else if (!release_fast and !release_safe and !release_small) builtin.Mode.Debug else x: {423 const mode = if (release_safe and !release_fast and !release_small) builtin.Mode.ReleaseSafe else if (release_fast and !release_safe and !release_small) builtin.Mode.ReleaseFast else if (release_small and !release_fast and !release_safe) builtin.Mode.ReleaseSmall else if (!release_fast and !release_safe and !release_small) builtin.Mode.Debug else x: {
424 warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)");424 warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)");
...@@ -518,7 +518,7 @@ pub const Builder = struct {...@@ -518,7 +518,7 @@ pub const Builder = struct {
518 // make sure all args are used518 // make sure all args are used
519 var it = self.user_input_options.iterator();519 var it = self.user_input_options.iterator();
520 while (true) {520 while (true) {
521 const entry = it.next() ?? break;521 const entry = it.next() orelse break;
522 if (!entry.value.used) {522 if (!entry.value.used) {
523 warn("Invalid option: -D{}\n\n", entry.key);523 warn("Invalid option: -D{}\n\n", entry.key);
524 self.markInvalidUserInput();524 self.markInvalidUserInput();
...@@ -1246,7 +1246,7 @@ pub const LibExeObjStep = struct {...@@ -1246,7 +1246,7 @@ pub const LibExeObjStep = struct {
1246 {1246 {
1247 var it = self.link_libs.iterator();1247 var it = self.link_libs.iterator();
1248 while (true) {1248 while (true) {
1249 const entry = it.next() ?? break;1249 const entry = it.next() orelse break;
1250 zig_args.append("--library") catch unreachable;1250 zig_args.append("--library") catch unreachable;
1251 zig_args.append(entry.key) catch unreachable;1251 zig_args.append(entry.key) catch unreachable;
1252 }1252 }
...@@ -1696,7 +1696,7 @@ pub const TestStep = struct {...@@ -1696,7 +1696,7 @@ pub const TestStep = struct {
1696 {1696 {
1697 var it = self.link_libs.iterator();1697 var it = self.link_libs.iterator();
1698 while (true) {1698 while (true) {
1699 const entry = it.next() ?? break;1699 const entry = it.next() orelse break;
1700 try zig_args.append("--library");1700 try zig_args.append("--library");
1701 try zig_args.append(entry.key);1701 try zig_args.append(entry.key);
1702 }1702 }
std/debug/index.zig+10-10
...@@ -208,7 +208,7 @@ fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: us...@@ -208,7 +208,7 @@ fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: us
208 .name = "???",208 .name = "???",
209 .address = address,209 .address = address,
210 };210 };
211 const symbol = debug_info.symbol_table.search(address) ?? &unknown;211 const symbol = debug_info.symbol_table.search(address) orelse &unknown;
212 try out_stream.print(WHITE ++ "{}" ++ RESET ++ ": " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n", symbol.name, address);212 try out_stream.print(WHITE ++ "{}" ++ RESET ++ ": " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n", symbol.name, address);
213 },213 },
214 else => {214 else => {
...@@ -268,10 +268,10 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {...@@ -268,10 +268,10 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace {
268 try st.elf.openFile(allocator, &st.self_exe_file);268 try st.elf.openFile(allocator, &st.self_exe_file);
269 errdefer st.elf.close();269 errdefer st.elf.close();
270270
271 st.debug_info = (try st.elf.findSection(".debug_info")) ?? return error.MissingDebugInfo;271 st.debug_info = (try st.elf.findSection(".debug_info")) orelse return error.MissingDebugInfo;
272 st.debug_abbrev = (try st.elf.findSection(".debug_abbrev")) ?? return error.MissingDebugInfo;272 st.debug_abbrev = (try st.elf.findSection(".debug_abbrev")) orelse return error.MissingDebugInfo;
273 st.debug_str = (try st.elf.findSection(".debug_str")) ?? return error.MissingDebugInfo;273 st.debug_str = (try st.elf.findSection(".debug_str")) orelse return error.MissingDebugInfo;
274 st.debug_line = (try st.elf.findSection(".debug_line")) ?? return error.MissingDebugInfo;274 st.debug_line = (try st.elf.findSection(".debug_line")) orelse return error.MissingDebugInfo;
275 st.debug_ranges = (try st.elf.findSection(".debug_ranges"));275 st.debug_ranges = (try st.elf.findSection(".debug_ranges"));
276 try scanAllCompileUnits(st);276 try scanAllCompileUnits(st);
277 return st;277 return st;
...@@ -443,7 +443,7 @@ const Die = struct {...@@ -443,7 +443,7 @@ const Die = struct {
443 }443 }
444444
445 fn getAttrAddr(self: *const Die, id: u64) !u64 {445 fn getAttrAddr(self: *const Die, id: u64) !u64 {
446 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;446 const form_value = self.getAttr(id) orelse return error.MissingDebugInfo;
447 return switch (form_value.*) {447 return switch (form_value.*) {
448 FormValue.Address => |value| value,448 FormValue.Address => |value| value,
449 else => error.InvalidDebugInfo,449 else => error.InvalidDebugInfo,
...@@ -451,7 +451,7 @@ const Die = struct {...@@ -451,7 +451,7 @@ const Die = struct {
451 }451 }
452452
453 fn getAttrSecOffset(self: *const Die, id: u64) !u64 {453 fn getAttrSecOffset(self: *const Die, id: u64) !u64 {
454 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;454 const form_value = self.getAttr(id) orelse return error.MissingDebugInfo;
455 return switch (form_value.*) {455 return switch (form_value.*) {
456 FormValue.Const => |value| value.asUnsignedLe(),456 FormValue.Const => |value| value.asUnsignedLe(),
457 FormValue.SecOffset => |value| value,457 FormValue.SecOffset => |value| value,
...@@ -460,7 +460,7 @@ const Die = struct {...@@ -460,7 +460,7 @@ const Die = struct {
460 }460 }
461461
462 fn getAttrUnsignedLe(self: *const Die, id: u64) !u64 {462 fn getAttrUnsignedLe(self: *const Die, id: u64) !u64 {
463 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;463 const form_value = self.getAttr(id) orelse return error.MissingDebugInfo;
464 return switch (form_value.*) {464 return switch (form_value.*) {
465 FormValue.Const => |value| value.asUnsignedLe(),465 FormValue.Const => |value| value.asUnsignedLe(),
466 else => error.InvalidDebugInfo,466 else => error.InvalidDebugInfo,
...@@ -468,7 +468,7 @@ const Die = struct {...@@ -468,7 +468,7 @@ const Die = struct {
468 }468 }
469469
470 fn getAttrString(self: *const Die, st: *ElfStackTrace, id: u64) ![]u8 {470 fn getAttrString(self: *const Die, st: *ElfStackTrace, id: u64) ![]u8 {
471 const form_value = self.getAttr(id) ?? return error.MissingDebugInfo;471 const form_value = self.getAttr(id) orelse return error.MissingDebugInfo;
472 return switch (form_value.*) {472 return switch (form_value.*) {
473 FormValue.String => |value| value,473 FormValue.String => |value| value,
474 FormValue.StrPtr => |offset| getString(st, offset),474 FormValue.StrPtr => |offset| getString(st, offset),
...@@ -748,7 +748,7 @@ fn parseDie(st: *ElfStackTrace, abbrev_table: *const AbbrevTable, is_64: bool) !...@@ -748,7 +748,7 @@ fn parseDie(st: *ElfStackTrace, abbrev_table: *const AbbrevTable, is_64: bool) !
748 var in_file_stream = io.FileInStream.init(in_file);748 var in_file_stream = io.FileInStream.init(in_file);
749 const in_stream = &in_file_stream.stream;749 const in_stream = &in_file_stream.stream;
750 const abbrev_code = try readULeb128(in_stream);750 const abbrev_code = try readULeb128(in_stream);
751 const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) ?? return error.InvalidDebugInfo;751 const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) orelse return error.InvalidDebugInfo;
752752
753 var result = Die{753 var result = Die{
754 .tag_id = table_entry.tag_id,754 .tag_id = table_entry.tag_id,
std/heap.zig+5-5
...@@ -97,12 +97,12 @@ pub const DirectAllocator = struct {...@@ -97,12 +97,12 @@ pub const DirectAllocator = struct {
97 },97 },
98 Os.windows => {98 Os.windows => {
99 const amt = n + alignment + @sizeOf(usize);99 const amt = n + alignment + @sizeOf(usize);
100 const heap_handle = self.heap_handle ?? blk: {100 const heap_handle = self.heap_handle orelse blk: {
101 const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0) ?? return error.OutOfMemory;101 const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0) orelse return error.OutOfMemory;
102 self.heap_handle = hh;102 self.heap_handle = hh;
103 break :blk hh;103 break :blk hh;
104 };104 };
105 const ptr = os.windows.HeapAlloc(heap_handle, 0, amt) ?? return error.OutOfMemory;105 const ptr = os.windows.HeapAlloc(heap_handle, 0, amt) orelse return error.OutOfMemory;
106 const root_addr = @ptrToInt(ptr);106 const root_addr = @ptrToInt(ptr);
107 const rem = @rem(root_addr, alignment);107 const rem = @rem(root_addr, alignment);
108 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);108 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);
...@@ -142,7 +142,7 @@ pub const DirectAllocator = struct {...@@ -142,7 +142,7 @@ pub const DirectAllocator = struct {
142 const root_addr = @intToPtr(*align(1) usize, old_record_addr).*;142 const root_addr = @intToPtr(*align(1) usize, old_record_addr).*;
143 const old_ptr = @intToPtr(*c_void, root_addr);143 const old_ptr = @intToPtr(*c_void, root_addr);
144 const amt = new_size + alignment + @sizeOf(usize);144 const amt = new_size + alignment + @sizeOf(usize);
145 const new_ptr = os.windows.HeapReAlloc(self.heap_handle.?, 0, old_ptr, amt) ?? blk: {145 const new_ptr = os.windows.HeapReAlloc(self.heap_handle.?, 0, old_ptr, amt) orelse blk: {
146 if (new_size > old_mem.len) return error.OutOfMemory;146 if (new_size > old_mem.len) return error.OutOfMemory;
147 const new_record_addr = old_record_addr - new_size + old_mem.len;147 const new_record_addr = old_record_addr - new_size + old_mem.len;
148 @intToPtr(*align(1) usize, new_record_addr).* = root_addr;148 @intToPtr(*align(1) usize, new_record_addr).* = root_addr;
...@@ -343,7 +343,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {...@@ -343,7 +343,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {
343 if (new_end_index > self.buffer.len) {343 if (new_end_index > self.buffer.len) {
344 return error.OutOfMemory;344 return error.OutOfMemory;
345 }345 }
346 end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) ?? return self.buffer[adjusted_index..new_end_index];346 end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) orelse return self.buffer[adjusted_index..new_end_index];
347 }347 }
348 }348 }
349349
std/linked_list.zig+2-2
...@@ -169,7 +169,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -169,7 +169,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
169 /// Returns:169 /// Returns:
170 /// A pointer to the last node in the list.170 /// A pointer to the last node in the list.
171 pub fn pop(list: *Self) ?*Node {171 pub fn pop(list: *Self) ?*Node {
172 const last = list.last ?? return null;172 const last = list.last orelse return null;
173 list.remove(last);173 list.remove(last);
174 return last;174 return last;
175 }175 }
...@@ -179,7 +179,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -179,7 +179,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
179 /// Returns:179 /// Returns:
180 /// A pointer to the first node in the list.180 /// A pointer to the first node in the list.
181 pub fn popFirst(list: *Self) ?*Node {181 pub fn popFirst(list: *Self) ?*Node {
182 const first = list.first ?? return null;182 const first = list.first orelse return null;
183 list.remove(first);183 list.remove(first);
184 return first;184 return first;
185 }185 }
std/os/index.zig+7-7
...@@ -425,7 +425,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator:...@@ -425,7 +425,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator:
425 return posixExecveErrnoToErr(posix.getErrno(posix.execve(argv_buf[0].?, argv_buf.ptr, envp_buf.ptr)));425 return posixExecveErrnoToErr(posix.getErrno(posix.execve(argv_buf[0].?, argv_buf.ptr, envp_buf.ptr)));
426 }426 }
427427
428 const PATH = getEnvPosix("PATH") ?? "/usr/local/bin:/bin/:/usr/bin";428 const PATH = getEnvPosix("PATH") orelse "/usr/local/bin:/bin/:/usr/bin";
429 // PATH.len because it is >= the largest search_path429 // PATH.len because it is >= the largest search_path
430 // +1 for the / to join the search path and exe_path430 // +1 for the / to join the search path and exe_path
431 // +1 for the null terminating byte431 // +1 for the null terminating byte
...@@ -490,7 +490,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {...@@ -490,7 +490,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
490 errdefer result.deinit();490 errdefer result.deinit();
491491
492 if (is_windows) {492 if (is_windows) {
493 const ptr = windows.GetEnvironmentStringsA() ?? return error.OutOfMemory;493 const ptr = windows.GetEnvironmentStringsA() orelse return error.OutOfMemory;
494 defer assert(windows.FreeEnvironmentStringsA(ptr) != 0);494 defer assert(windows.FreeEnvironmentStringsA(ptr) != 0);
495495
496 var i: usize = 0;496 var i: usize = 0;
...@@ -573,7 +573,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) ![]u8 {...@@ -573,7 +573,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) ![]u8 {
573 return allocator.shrink(u8, buf, result);573 return allocator.shrink(u8, buf, result);
574 }574 }
575 } else {575 } else {
576 const result = getEnvPosix(key) ?? return error.EnvironmentVariableNotFound;576 const result = getEnvPosix(key) orelse return error.EnvironmentVariableNotFound;
577 return mem.dupe(allocator, u8, result);577 return mem.dupe(allocator, u8, result);
578 }578 }
579}579}
...@@ -1641,7 +1641,7 @@ pub const ArgIterator = struct {...@@ -1641,7 +1641,7 @@ pub const ArgIterator = struct {
1641 if (builtin.os == Os.windows) {1641 if (builtin.os == Os.windows) {
1642 return self.inner.next(allocator);1642 return self.inner.next(allocator);
1643 } else {1643 } else {
1644 return mem.dupe(allocator, u8, self.inner.next() ?? return null);1644 return mem.dupe(allocator, u8, self.inner.next() orelse return null);
1645 }1645 }
1646 }1646 }
16471647
...@@ -2457,9 +2457,9 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread...@@ -2457,9 +2457,9 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread
2457 }2457 }
2458 };2458 };
24592459
2460 const heap_handle = windows.GetProcessHeap() ?? return SpawnThreadError.OutOfMemory;2460 const heap_handle = windows.GetProcessHeap() orelse return SpawnThreadError.OutOfMemory;
2461 const byte_count = @alignOf(WinThread.OuterContext) + @sizeOf(WinThread.OuterContext);2461 const byte_count = @alignOf(WinThread.OuterContext) + @sizeOf(WinThread.OuterContext);
2462 const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) ?? return SpawnThreadError.OutOfMemory;2462 const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) orelse return SpawnThreadError.OutOfMemory;
2463 errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);2463 errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0);
2464 const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];2464 const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count];
2465 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable;2465 const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable;
...@@ -2468,7 +2468,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread...@@ -2468,7 +2468,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread
2468 outer_context.thread.data.alloc_start = bytes_ptr;2468 outer_context.thread.data.alloc_start = bytes_ptr;
24692469
2470 const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner);2470 const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner);
2471 outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) ?? {2471 outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse {
2472 const err = windows.GetLastError();2472 const err = windows.GetLastError();
2473 return switch (err) {2473 return switch (err) {
2474 else => os.unexpectedErrorWindows(err),2474 else => os.unexpectedErrorWindows(err),
std/os/linux/vdso.zig+4-4
...@@ -28,7 +28,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -28,7 +28,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
28 }28 }
29 }29 }
30 }30 }
31 const dynv = maybe_dynv ?? return 0;31 const dynv = maybe_dynv orelse return 0;
32 if (base == @maxValue(usize)) return 0;32 if (base == @maxValue(usize)) return 0;
3333
34 var maybe_strings: ?[*]u8 = null;34 var maybe_strings: ?[*]u8 = null;
...@@ -52,9 +52,9 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -52,9 +52,9 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
52 }52 }
53 }53 }
5454
55 const strings = maybe_strings ?? return 0;55 const strings = maybe_strings orelse return 0;
56 const syms = maybe_syms ?? return 0;56 const syms = maybe_syms orelse return 0;
57 const hashtab = maybe_hashtab ?? return 0;57 const hashtab = maybe_hashtab orelse return 0;
58 if (maybe_verdef == null) maybe_versym = null;58 if (maybe_verdef == null) maybe_versym = null;
5959
60 const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON);60 const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON);
std/os/path.zig+6-6
...@@ -182,8 +182,8 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {...@@ -182,8 +182,8 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
182 }182 }
183183
184 var it = mem.split(path, []u8{this_sep});184 var it = mem.split(path, []u8{this_sep});
185 _ = (it.next() ?? return relative_path);185 _ = (it.next() orelse return relative_path);
186 _ = (it.next() ?? return relative_path);186 _ = (it.next() orelse return relative_path);
187 return WindowsPath{187 return WindowsPath{
188 .is_abs = isAbsoluteWindows(path),188 .is_abs = isAbsoluteWindows(path),
189 .kind = WindowsPath.Kind.NetworkShare,189 .kind = WindowsPath.Kind.NetworkShare,
...@@ -200,8 +200,8 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {...@@ -200,8 +200,8 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
200 }200 }
201201
202 var it = mem.split(path, []u8{this_sep});202 var it = mem.split(path, []u8{this_sep});
203 _ = (it.next() ?? return relative_path);203 _ = (it.next() orelse return relative_path);
204 _ = (it.next() ?? return relative_path);204 _ = (it.next() orelse return relative_path);
205 return WindowsPath{205 return WindowsPath{
206 .is_abs = isAbsoluteWindows(path),206 .is_abs = isAbsoluteWindows(path),
207 .kind = WindowsPath.Kind.NetworkShare,207 .kind = WindowsPath.Kind.NetworkShare,
...@@ -923,7 +923,7 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)...@@ -923,7 +923,7 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
923 var from_it = mem.split(resolved_from, "/\\");923 var from_it = mem.split(resolved_from, "/\\");
924 var to_it = mem.split(resolved_to, "/\\");924 var to_it = mem.split(resolved_to, "/\\");
925 while (true) {925 while (true) {
926 const from_component = from_it.next() ?? return mem.dupe(allocator, u8, to_it.rest());926 const from_component = from_it.next() orelse return mem.dupe(allocator, u8, to_it.rest());
927 const to_rest = to_it.rest();927 const to_rest = to_it.rest();
928 if (to_it.next()) |to_component| {928 if (to_it.next()) |to_component| {
929 // TODO ASCII is wrong, we actually need full unicode support to compare paths.929 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
...@@ -974,7 +974,7 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![...@@ -974,7 +974,7 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
974 var from_it = mem.split(resolved_from, "/");974 var from_it = mem.split(resolved_from, "/");
975 var to_it = mem.split(resolved_to, "/");975 var to_it = mem.split(resolved_to, "/");
976 while (true) {976 while (true) {
977 const from_component = from_it.next() ?? return mem.dupe(allocator, u8, to_it.rest());977 const from_component = from_it.next() orelse return mem.dupe(allocator, u8, to_it.rest());
978 const to_rest = to_it.rest();978 const to_rest = to_it.rest();
979 if (to_it.next()) |to_component| {979 if (to_it.next()) |to_component| {
980 if (mem.eql(u8, from_component, to_component))980 if (mem.eql(u8, from_component, to_component))
std/os/windows/util.zig+1-1
...@@ -153,7 +153,7 @@ pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap)...@@ -153,7 +153,7 @@ pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap)
153pub fn windowsLoadDll(allocator: *mem.Allocator, dll_path: []const u8) !windows.HMODULE {153pub fn windowsLoadDll(allocator: *mem.Allocator, dll_path: []const u8) !windows.HMODULE {
154 const padded_buff = try cstr.addNullByte(allocator, dll_path);154 const padded_buff = try cstr.addNullByte(allocator, dll_path);
155 defer allocator.free(padded_buff);155 defer allocator.free(padded_buff);
156 return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound;156 return windows.LoadLibraryA(padded_buff.ptr) orelse error.DllNotFound;
157}157}
158158
159pub fn windowsUnloadDll(hModule: windows.HMODULE) void {159pub fn windowsUnloadDll(hModule: windows.HMODULE) void {
std/special/build_runner.zig+5-5
...@@ -27,15 +27,15 @@ pub fn main() !void {...@@ -27,15 +27,15 @@ pub fn main() !void {
27 // skip my own exe name27 // skip my own exe name
28 _ = arg_it.skip();28 _ = arg_it.skip();
2929
30 const zig_exe = try unwrapArg(arg_it.next(allocator) ?? {30 const zig_exe = try unwrapArg(arg_it.next(allocator) orelse {
31 warn("Expected first argument to be path to zig compiler\n");31 warn("Expected first argument to be path to zig compiler\n");
32 return error.InvalidArgs;32 return error.InvalidArgs;
33 });33 });
34 const build_root = try unwrapArg(arg_it.next(allocator) ?? {34 const build_root = try unwrapArg(arg_it.next(allocator) orelse {
35 warn("Expected second argument to be build root directory path\n");35 warn("Expected second argument to be build root directory path\n");
36 return error.InvalidArgs;36 return error.InvalidArgs;
37 });37 });
38 const cache_root = try unwrapArg(arg_it.next(allocator) ?? {38 const cache_root = try unwrapArg(arg_it.next(allocator) orelse {
39 warn("Expected third argument to be cache root directory path\n");39 warn("Expected third argument to be cache root directory path\n");
40 return error.InvalidArgs;40 return error.InvalidArgs;
41 });41 });
...@@ -84,12 +84,12 @@ pub fn main() !void {...@@ -84,12 +84,12 @@ pub fn main() !void {
84 } else if (mem.eql(u8, arg, "--help")) {84 } else if (mem.eql(u8, arg, "--help")) {
85 return usage(&builder, false, try stdout_stream);85 return usage(&builder, false, try stdout_stream);
86 } else if (mem.eql(u8, arg, "--prefix")) {86 } else if (mem.eql(u8, arg, "--prefix")) {
87 prefix = try unwrapArg(arg_it.next(allocator) ?? {87 prefix = try unwrapArg(arg_it.next(allocator) orelse {
88 warn("Expected argument after --prefix\n\n");88 warn("Expected argument after --prefix\n\n");
89 return usageAndErr(&builder, false, try stderr_stream);89 return usageAndErr(&builder, false, try stderr_stream);
90 });90 });
91 } else if (mem.eql(u8, arg, "--search-prefix")) {91 } else if (mem.eql(u8, arg, "--search-prefix")) {
92 const search_prefix = try unwrapArg(arg_it.next(allocator) ?? {92 const search_prefix = try unwrapArg(arg_it.next(allocator) orelse {
93 warn("Expected argument after --search-prefix\n\n");93 warn("Expected argument after --search-prefix\n\n");
94 return usageAndErr(&builder, false, try stderr_stream);94 return usageAndErr(&builder, false, try stderr_stream);
95 });95 });
std/unicode.zig+1-1
...@@ -220,7 +220,7 @@ const Utf8Iterator = struct {...@@ -220,7 +220,7 @@ const Utf8Iterator = struct {
220 }220 }
221221
222 pub fn nextCodepoint(it: *Utf8Iterator) ?u32 {222 pub fn nextCodepoint(it: *Utf8Iterator) ?u32 {
223 const slice = it.nextCodepointSlice() ?? return null;223 const slice = it.nextCodepointSlice() orelse return null;
224224
225 switch (slice.len) {225 switch (slice.len) {
226 1 => return u32(slice[0]),226 1 => return u32(slice[0]),
std/zig/parse.zig+24-23
...@@ -43,7 +43,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -43,7 +43,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
4343
44 // skip over line comments at the top of the file44 // skip over line comments at the top of the file
45 while (true) {45 while (true) {
46 const next_tok = tok_it.peek() ?? break;46 const next_tok = tok_it.peek() orelse break;
47 if (next_tok.id != Token.Id.LineComment) break;47 if (next_tok.id != Token.Id.LineComment) break;
48 _ = tok_it.next();48 _ = tok_it.next();
49 }49 }
...@@ -197,7 +197,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -197,7 +197,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
197 const lib_name_token = nextToken(&tok_it, &tree);197 const lib_name_token = nextToken(&tok_it, &tree);
198 const lib_name_token_index = lib_name_token.index;198 const lib_name_token_index = lib_name_token.index;
199 const lib_name_token_ptr = lib_name_token.ptr;199 const lib_name_token_ptr = lib_name_token.ptr;
200 break :blk (try parseStringLiteral(arena, &tok_it, lib_name_token_ptr, lib_name_token_index, &tree)) ?? {200 break :blk (try parseStringLiteral(arena, &tok_it, lib_name_token_ptr, lib_name_token_index, &tree)) orelse {
201 prevToken(&tok_it, &tree);201 prevToken(&tok_it, &tree);
202 break :blk null;202 break :blk null;
203 };203 };
...@@ -1434,13 +1434,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1434,13 +1434,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1434 try stack.append(State{1434 try stack.append(State{
1435 .ExpectTokenSave = ExpectTokenSave{1435 .ExpectTokenSave = ExpectTokenSave{
1436 .id = Token.Id.AngleBracketRight,1436 .id = Token.Id.AngleBracketRight,
1437 .ptr = &async_node.rangle_bracket.? },1437 .ptr = &async_node.rangle_bracket.?,
1438 },
1438 });1439 });
1439 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &async_node.allocator_type } });1440 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &async_node.allocator_type } });
1440 continue;1441 continue;
1441 },1442 },
1442 State.AsyncEnd => |ctx| {1443 State.AsyncEnd => |ctx| {
1443 const node = ctx.ctx.get() ?? continue;1444 const node = ctx.ctx.get() orelse continue;
14441445
1445 switch (node.id) {1446 switch (node.id) {
1446 ast.Node.Id.FnProto => {1447 ast.Node.Id.FnProto => {
...@@ -1813,7 +1814,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1813,7 +1814,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1813 continue;1814 continue;
1814 },1815 },
1815 State.RangeExpressionEnd => |opt_ctx| {1816 State.RangeExpressionEnd => |opt_ctx| {
1816 const lhs = opt_ctx.get() ?? continue;1817 const lhs = opt_ctx.get() orelse continue;
18171818
1818 if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {1819 if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
1819 const node = try arena.construct(ast.Node.InfixOp{1820 const node = try arena.construct(ast.Node.InfixOp{
...@@ -1835,7 +1836,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1835,7 +1836,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1835 },1836 },
18361837
1837 State.AssignmentExpressionEnd => |opt_ctx| {1838 State.AssignmentExpressionEnd => |opt_ctx| {
1838 const lhs = opt_ctx.get() ?? continue;1839 const lhs = opt_ctx.get() orelse continue;
18391840
1840 const token = nextToken(&tok_it, &tree);1841 const token = nextToken(&tok_it, &tree);
1841 const token_index = token.index;1842 const token_index = token.index;
...@@ -1865,7 +1866,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1865,7 +1866,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1865 },1866 },
18661867
1867 State.UnwrapExpressionEnd => |opt_ctx| {1868 State.UnwrapExpressionEnd => |opt_ctx| {
1868 const lhs = opt_ctx.get() ?? continue;1869 const lhs = opt_ctx.get() orelse continue;
18691870
1870 const token = nextToken(&tok_it, &tree);1871 const token = nextToken(&tok_it, &tree);
1871 const token_index = token.index;1872 const token_index = token.index;
...@@ -1900,7 +1901,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1900,7 +1901,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1900 },1901 },
19011902
1902 State.BoolOrExpressionEnd => |opt_ctx| {1903 State.BoolOrExpressionEnd => |opt_ctx| {
1903 const lhs = opt_ctx.get() ?? continue;1904 const lhs = opt_ctx.get() orelse continue;
19041905
1905 if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| {1906 if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| {
1906 const node = try arena.construct(ast.Node.InfixOp{1907 const node = try arena.construct(ast.Node.InfixOp{
...@@ -1924,7 +1925,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1924,7 +1925,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1924 },1925 },
19251926
1926 State.BoolAndExpressionEnd => |opt_ctx| {1927 State.BoolAndExpressionEnd => |opt_ctx| {
1927 const lhs = opt_ctx.get() ?? continue;1928 const lhs = opt_ctx.get() orelse continue;
19281929
1929 if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| {1930 if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| {
1930 const node = try arena.construct(ast.Node.InfixOp{1931 const node = try arena.construct(ast.Node.InfixOp{
...@@ -1948,7 +1949,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1948,7 +1949,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1948 },1949 },
19491950
1950 State.ComparisonExpressionEnd => |opt_ctx| {1951 State.ComparisonExpressionEnd => |opt_ctx| {
1951 const lhs = opt_ctx.get() ?? continue;1952 const lhs = opt_ctx.get() orelse continue;
19521953
1953 const token = nextToken(&tok_it, &tree);1954 const token = nextToken(&tok_it, &tree);
1954 const token_index = token.index;1955 const token_index = token.index;
...@@ -1978,7 +1979,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1978,7 +1979,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1978 },1979 },
19791980
1980 State.BinaryOrExpressionEnd => |opt_ctx| {1981 State.BinaryOrExpressionEnd => |opt_ctx| {
1981 const lhs = opt_ctx.get() ?? continue;1982 const lhs = opt_ctx.get() orelse continue;
19821983
1983 if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| {1984 if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| {
1984 const node = try arena.construct(ast.Node.InfixOp{1985 const node = try arena.construct(ast.Node.InfixOp{
...@@ -2002,7 +2003,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2002,7 +2003,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2002 },2003 },
20032004
2004 State.BinaryXorExpressionEnd => |opt_ctx| {2005 State.BinaryXorExpressionEnd => |opt_ctx| {
2005 const lhs = opt_ctx.get() ?? continue;2006 const lhs = opt_ctx.get() orelse continue;
20062007
2007 if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| {2008 if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| {
2008 const node = try arena.construct(ast.Node.InfixOp{2009 const node = try arena.construct(ast.Node.InfixOp{
...@@ -2026,7 +2027,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2026,7 +2027,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2026 },2027 },
20272028
2028 State.BinaryAndExpressionEnd => |opt_ctx| {2029 State.BinaryAndExpressionEnd => |opt_ctx| {
2029 const lhs = opt_ctx.get() ?? continue;2030 const lhs = opt_ctx.get() orelse continue;
20302031
2031 if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| {2032 if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| {
2032 const node = try arena.construct(ast.Node.InfixOp{2033 const node = try arena.construct(ast.Node.InfixOp{
...@@ -2050,7 +2051,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2050,7 +2051,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2050 },2051 },
20512052
2052 State.BitShiftExpressionEnd => |opt_ctx| {2053 State.BitShiftExpressionEnd => |opt_ctx| {
2053 const lhs = opt_ctx.get() ?? continue;2054 const lhs = opt_ctx.get() orelse continue;
20542055
2055 const token = nextToken(&tok_it, &tree);2056 const token = nextToken(&tok_it, &tree);
2056 const token_index = token.index;2057 const token_index = token.index;
...@@ -2080,7 +2081,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2080,7 +2081,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2080 },2081 },
20812082
2082 State.AdditionExpressionEnd => |opt_ctx| {2083 State.AdditionExpressionEnd => |opt_ctx| {
2083 const lhs = opt_ctx.get() ?? continue;2084 const lhs = opt_ctx.get() orelse continue;
20842085
2085 const token = nextToken(&tok_it, &tree);2086 const token = nextToken(&tok_it, &tree);
2086 const token_index = token.index;2087 const token_index = token.index;
...@@ -2110,7 +2111,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2110,7 +2111,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2110 },2111 },
21112112
2112 State.MultiplyExpressionEnd => |opt_ctx| {2113 State.MultiplyExpressionEnd => |opt_ctx| {
2113 const lhs = opt_ctx.get() ?? continue;2114 const lhs = opt_ctx.get() orelse continue;
21142115
2115 const token = nextToken(&tok_it, &tree);2116 const token = nextToken(&tok_it, &tree);
2116 const token_index = token.index;2117 const token_index = token.index;
...@@ -2141,7 +2142,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2141,7 +2142,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2141 },2142 },
21422143
2143 State.CurlySuffixExpressionEnd => |opt_ctx| {2144 State.CurlySuffixExpressionEnd => |opt_ctx| {
2144 const lhs = opt_ctx.get() ?? continue;2145 const lhs = opt_ctx.get() orelse continue;
21452146
2146 if (tok_it.peek().?.id == Token.Id.Period) {2147 if (tok_it.peek().?.id == Token.Id.Period) {
2147 const node = try arena.construct(ast.Node.SuffixOp{2148 const node = try arena.construct(ast.Node.SuffixOp{
...@@ -2189,7 +2190,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2189,7 +2190,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2189 },2190 },
21902191
2191 State.TypeExprEnd => |opt_ctx| {2192 State.TypeExprEnd => |opt_ctx| {
2192 const lhs = opt_ctx.get() ?? continue;2193 const lhs = opt_ctx.get() orelse continue;
21932194
2194 if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| {2195 if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| {
2195 const node = try arena.construct(ast.Node.InfixOp{2196 const node = try arena.construct(ast.Node.InfixOp{
...@@ -2269,7 +2270,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2269,7 +2270,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2269 },2270 },
22702271
2271 State.SuffixOpExpressionEnd => |opt_ctx| {2272 State.SuffixOpExpressionEnd => |opt_ctx| {
2272 const lhs = opt_ctx.get() ?? continue;2273 const lhs = opt_ctx.get() orelse continue;
22732274
2274 const token = nextToken(&tok_it, &tree);2275 const token = nextToken(&tok_it, &tree);
2275 const token_index = token.index;2276 const token_index = token.index;
...@@ -2418,7 +2419,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2418,7 +2419,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2418 continue;2419 continue;
2419 },2420 },
2420 Token.Id.StringLiteral, Token.Id.MultilineStringLiteralLine => {2421 Token.Id.StringLiteral, Token.Id.MultilineStringLiteralLine => {
2421 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, &tree)) ?? unreachable);2422 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, &tree)) orelse unreachable);
2422 continue;2423 continue;
2423 },2424 },
2424 Token.Id.LParen => {2425 Token.Id.LParen => {
...@@ -2648,7 +2649,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2648,7 +2649,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2648 const token = nextToken(&tok_it, &tree);2649 const token = nextToken(&tok_it, &tree);
2649 const token_index = token.index;2650 const token_index = token.index;
2650 const token_ptr = token.ptr;2651 const token_ptr = token.ptr;
2651 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token_ptr, token_index, &tree)) ?? {2652 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token_ptr, token_index, &tree)) orelse {
2652 prevToken(&tok_it, &tree);2653 prevToken(&tok_it, &tree);
2653 if (opt_ctx != OptionalCtx.Optional) {2654 if (opt_ctx != OptionalCtx.Optional) {
2654 ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token_index } };2655 ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token_index } };
...@@ -3348,7 +3349,7 @@ fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedTok...@@ -3348,7 +3349,7 @@ fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedTok
3348 assert(result.ptr.id != Token.Id.LineComment);3349 assert(result.ptr.id != Token.Id.LineComment);
33493350
3350 while (true) {3351 while (true) {
3351 const next_tok = tok_it.peek() ?? return result;3352 const next_tok = tok_it.peek() orelse return result;
3352 if (next_tok.id != Token.Id.LineComment) return result;3353 if (next_tok.id != Token.Id.LineComment) return result;
3353 _ = tok_it.next();3354 _ = tok_it.next();
3354 }3355 }
...@@ -3356,7 +3357,7 @@ fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedTok...@@ -3356,7 +3357,7 @@ fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedTok
33563357
3357fn prevToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) void {3358fn prevToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) void {
3358 while (true) {3359 while (true) {
3359 const prev_tok = tok_it.prev() ?? return;3360 const prev_tok = tok_it.prev() orelse return;
3360 if (prev_tok.id == Token.Id.LineComment) continue;3361 if (prev_tok.id == Token.Id.LineComment) continue;
3361 return;3362 return;
3362 }3363 }
std/zig/render.zig+4-4
...@@ -83,7 +83,7 @@ fn renderRoot(...@@ -83,7 +83,7 @@ fn renderRoot(
83 var start_col: usize = 0;83 var start_col: usize = 0;
84 var it = tree.root_node.decls.iterator(0);84 var it = tree.root_node.decls.iterator(0);
85 while (true) {85 while (true) {
86 var decl = (it.next() ?? return).*;86 var decl = (it.next() orelse return).*;
87 // look for zig fmt: off comment87 // look for zig fmt: off comment
88 var start_token_index = decl.firstToken();88 var start_token_index = decl.firstToken();
89 zig_fmt_loop: while (start_token_index != 0) {89 zig_fmt_loop: while (start_token_index != 0) {
...@@ -112,7 +112,7 @@ fn renderRoot(...@@ -112,7 +112,7 @@ fn renderRoot(
112 const start = tree.tokens.at(start_token_index + 1).start;112 const start = tree.tokens.at(start_token_index + 1).start;
113 try stream.print("{}\n", tree.source[start..end_token.end]);113 try stream.print("{}\n", tree.source[start..end_token.end]);
114 while (tree.tokens.at(decl.firstToken()).start < end_token.end) {114 while (tree.tokens.at(decl.firstToken()).start < end_token.end) {
115 decl = (it.next() ?? return).*;115 decl = (it.next() orelse return).*;
116 }116 }
117 break :zig_fmt_loop;117 break :zig_fmt_loop;
118 }118 }
...@@ -1993,7 +1993,7 @@ fn renderDocComments(...@@ -1993,7 +1993,7 @@ fn renderDocComments(
1993 indent: usize,1993 indent: usize,
1994 start_col: *usize,1994 start_col: *usize,
1995) (@typeOf(stream).Child.Error || Error)!void {1995) (@typeOf(stream).Child.Error || Error)!void {
1996 const comment = node.doc_comments ?? return;1996 const comment = node.doc_comments orelse return;
1997 var it = comment.lines.iterator(0);1997 var it = comment.lines.iterator(0);
1998 const first_token = node.firstToken();1998 const first_token = node.firstToken();
1999 while (it.next()) |line_token_index| {1999 while (it.next()) |line_token_index| {
...@@ -2021,7 +2021,7 @@ fn nodeIsBlock(base: *const ast.Node) bool {...@@ -2021,7 +2021,7 @@ fn nodeIsBlock(base: *const ast.Node) bool {
2021}2021}
20222022
2023fn nodeCausesSliceOpSpace(base: *ast.Node) bool {2023fn nodeCausesSliceOpSpace(base: *ast.Node) bool {
2024 const infix_op = base.cast(ast.Node.InfixOp) ?? return false;2024 const infix_op = base.cast(ast.Node.InfixOp) orelse return false;
2025 return switch (infix_op.op) {2025 return switch (infix_op.op) {
2026 ast.Node.InfixOp.Op.Period => false,2026 ast.Node.InfixOp.Op.Period => false,
2027 else => true,2027 else => true,
test/cases/cast.zig+3-3
...@@ -73,7 +73,7 @@ fn Struct(comptime T: type) type {...@@ -73,7 +73,7 @@ fn Struct(comptime T: type) type {
7373
74 fn maybePointer(self: ?*const Self) Self {74 fn maybePointer(self: ?*const Self) Self {
75 const none = Self{ .x = if (T == void) void{} else 0 };75 const none = Self{ .x = if (T == void) void{} else 0 };
76 return (self ?? &none).*;76 return (self orelse &none).*;
77 }77 }
78 };78 };
79}79}
...@@ -87,7 +87,7 @@ const Union = union {...@@ -87,7 +87,7 @@ const Union = union {
8787
88 fn maybePointer(self: ?*const Union) Union {88 fn maybePointer(self: ?*const Union) Union {
89 const none = Union{ .x = 0 };89 const none = Union{ .x = 0 };
90 return (self ?? &none).*;90 return (self orelse &none).*;
91 }91 }
92};92};
9393
...@@ -100,7 +100,7 @@ const Enum = enum {...@@ -100,7 +100,7 @@ const Enum = enum {
100 }100 }
101101
102 fn maybePointer(self: ?*const Enum) Enum {102 fn maybePointer(self: ?*const Enum) Enum {
103 return (self ?? &Enum.None).*;103 return (self orelse &Enum.None).*;
104 }104 }
105};105};
106106
test/cases/null.zig+5-5
...@@ -15,13 +15,13 @@ test "optional type" {...@@ -15,13 +15,13 @@ test "optional type" {
1515
16 const next_x: ?i32 = null;16 const next_x: ?i32 = null;
1717
18 const z = next_x ?? 1234;18 const z = next_x orelse 1234;
1919
20 assert(z == 1234);20 assert(z == 1234);
2121
22 const final_x: ?i32 = 13;22 const final_x: ?i32 = 13;
2323
24 const num = final_x ?? unreachable;24 const num = final_x orelse unreachable;
2525
26 assert(num == 13);26 assert(num == 13);
27}27}
...@@ -38,7 +38,7 @@ test "test maybe object and get a pointer to the inner value" {...@@ -38,7 +38,7 @@ test "test maybe object and get a pointer to the inner value" {
3838
39test "rhs maybe unwrap return" {39test "rhs maybe unwrap return" {
40 const x: ?bool = true;40 const x: ?bool = true;
41 const y = x ?? return;41 const y = x orelse return;
42}42}
4343
44test "maybe return" {44test "maybe return" {
...@@ -53,7 +53,7 @@ fn maybeReturnImpl() void {...@@ -53,7 +53,7 @@ fn maybeReturnImpl() void {
53}53}
5454
55fn foo(x: ?i32) ?bool {55fn foo(x: ?i32) ?bool {
56 const value = x ?? return null;56 const value = x orelse return null;
57 return value > 1234;57 return value > 1234;
58}58}
5959
...@@ -140,6 +140,6 @@ test "unwrap optional which is field of global var" {...@@ -140,6 +140,6 @@ test "unwrap optional which is field of global var" {
140}140}
141141
142test "null with default unwrap" {142test "null with default unwrap" {
143 const x: i32 = null ?? 1;143 const x: i32 = null orelse 1;
144 assert(x == 1);144 assert(x == 1);
145}145}
test/compile_errors.zig+1-1
...@@ -2296,7 +2296,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2296,7 +2296,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2296 \\2296 \\
2297 \\ defer try canFail();2297 \\ defer try canFail();
2298 \\2298 \\
2299 \\ const a = maybeInt() ?? return;2299 \\ const a = maybeInt() orelse return;
2300 \\}2300 \\}
2301 \\2301 \\
2302 \\fn canFail() error!void { }2302 \\fn canFail() error!void { }
test/translate_c.zig+10-10
...@@ -246,13 +246,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -246,13 +246,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
246 \\pub extern var fn_ptr: ?extern fn() void;246 \\pub extern var fn_ptr: ?extern fn() void;
247 ,247 ,
248 \\pub inline fn foo() void {248 \\pub inline fn foo() void {
249 \\ return (??fn_ptr)();249 \\ return fn_ptr.?();
250 \\}250 \\}
251 ,251 ,
252 \\pub extern var fn_ptr2: ?extern fn(c_int, f32) u8;252 \\pub extern var fn_ptr2: ?extern fn(c_int, f32) u8;
253 ,253 ,
254 \\pub inline fn bar(arg0: c_int, arg1: f32) u8 {254 \\pub inline fn bar(arg0: c_int, arg1: f32) u8 {
255 \\ return (??fn_ptr2)(arg0, arg1);255 \\ return fn_ptr2.?(arg0, arg1);
256 \\}256 \\}
257 );257 );
258258
...@@ -608,7 +608,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -608,7 +608,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
608 \\ field: c_int,608 \\ field: c_int,
609 \\};609 \\};
610 \\pub export fn read_field(foo: ?[*]struct_Foo) c_int {610 \\pub export fn read_field(foo: ?[*]struct_Foo) c_int {
611 \\ return (??foo).field;611 \\ return foo.?.field;
612 \\}612 \\}
613 );613 );
614614
...@@ -969,11 +969,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -969,11 +969,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
969 \\pub export fn bar() void {969 \\pub export fn bar() void {
970 \\ var f: ?extern fn() void = foo;970 \\ var f: ?extern fn() void = foo;
971 \\ var b: ?extern fn() c_int = baz;971 \\ var b: ?extern fn() c_int = baz;
972 \\ (??f)();972 \\ f.?();
973 \\ (??f)();973 \\ f.?();
974 \\ foo();974 \\ foo();
975 \\ _ = (??b)();975 \\ _ = b.?();
976 \\ _ = (??b)();976 \\ _ = b.?();
977 \\ _ = baz();977 \\ _ = baz();
978 \\}978 \\}
979 );979 );
...@@ -984,7 +984,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -984,7 +984,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
984 \\}984 \\}
985 ,985 ,
986 \\pub export fn foo(x: ?[*]c_int) void {986 \\pub export fn foo(x: ?[*]c_int) void {
987 \\ (??x).* = 1;987 \\ x.?.* = 1;
988 \\}988 \\}
989 );989 );
990990
...@@ -1012,7 +1012,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1012,7 +1012,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1012 \\pub fn foo() c_int {1012 \\pub fn foo() c_int {
1013 \\ var x: c_int = 1234;1013 \\ var x: c_int = 1234;
1014 \\ var ptr: ?[*]c_int = &x;1014 \\ var ptr: ?[*]c_int = &x;
1015 \\ return (??ptr).*;1015 \\ return ptr.?.*;
1016 \\}1016 \\}
1017 );1017 );
10181018
...@@ -1119,7 +1119,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1119,7 +1119,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1119 \\pub const glClearPFN = PFNGLCLEARPROC;1119 \\pub const glClearPFN = PFNGLCLEARPROC;
1120 ,1120 ,
1121 \\pub inline fn glClearUnion(arg0: GLbitfield) void {1121 \\pub inline fn glClearUnion(arg0: GLbitfield) void {
1122 \\ return (??glProcs.gl.Clear)(arg0);1122 \\ return glProcs.gl.Clear.?(arg0);
1123 \\}1123 \\}
1124 ,1124 ,
1125 \\pub const OpenGLProcs = union_OpenGLProcs;1125 \\pub const OpenGLProcs = union_OpenGLProcs;