authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-09 23:42:14-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-06-09 23:42:14-04:00
logec1b6f66737f8c3cbc0420715c2c502c7e710081
tree495aa343982b191149988291901dd6520e757699
parentd464b2532200de3778ac7362e701791a11150d55
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

breaking syntax change: ??x to x.? (#1095)

See #1023 This also renames Nullable/Maybe to Optional

51 files changed, 489 insertions(+), 482 deletions(-)

build.zig+1-1
......@@ -75,7 +75,7 @@ pub fn build(b: *Builder) !void {
7575 cxx_compiler,
7676 "-print-file-name=libstdc++.a",
7777 });
78 const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next();
78 const libstdcxx_path = mem.split(libstdcxx_path_padded, "\r\n").next().?;
7979 if (mem.eql(u8, libstdcxx_path, "libstdc++.a")) {
8080 warn(
8181 \\Unable to determine path to libstdc++.a
doc/codegen.md+4-4
......@@ -6,7 +6,7 @@ Every type has a "handle". If a type is a simple primitive type such as i32 or
66f64, the handle is "by value", meaning that we pass around the value itself when
77we refer to a value of that type.
88
9If a type is a container, error union, maybe type, slice, or array, then its
9If a type is a container, error union, optional type, slice, or array, then its
1010handle is a pointer, and everywhere we refer to a value of this type we refer to
1111a pointer.
1212
......@@ -19,7 +19,7 @@ Error union types are represented as:
1919 payload: T,
2020 }
2121
22Maybe types are represented as:
22Optional types are represented as:
2323
2424 struct {
2525 payload: T,
......@@ -28,6 +28,6 @@ Maybe types are represented as:
2828
2929## Data Optimizations
3030
31Maybe pointer types are special: the 0x0 pointer value is used to represent a
32null pointer. Thus, instead of the struct above, maybe pointer types are
31Optional pointer types are special: the 0x0 pointer value is used to represent a
32null pointer. Thus, instead of the struct above, optional pointer types are
3333represented as a `usize` in codegen and the handle is by value.
doc/langref.html.in+60-62
......@@ -156,18 +156,18 @@ pub fn main() void {
156156 true or false,
157157 !true);
158158
159 // nullable
160 var nullable_value: ?[]const u8 = null;
161 assert(nullable_value == null);
159 // optional
160 var optional_value: ?[]const u8 = null;
161 assert(optional_value == null);
162162
163 warn("\nnullable 1\ntype: {}\nvalue: {}\n",
164 @typeName(@typeOf(nullable_value)), nullable_value);
163 warn("\noptional 1\ntype: {}\nvalue: {}\n",
164 @typeName(@typeOf(optional_value)), optional_value);
165165
166 nullable_value = "hi";
167 assert(nullable_value != null);
166 optional_value = "hi";
167 assert(optional_value != null);
168168
169 warn("\nnullable 2\ntype: {}\nvalue: {}\n",
170 @typeName(@typeOf(nullable_value)), nullable_value);
169 warn("\noptional 2\ntype: {}\nvalue: {}\n",
170 @typeName(@typeOf(optional_value)), optional_value);
171171
172172 // error union
173173 var number_or_error: error!i32 = error.ArgNotFound;
......@@ -428,7 +428,7 @@ pub fn main() void {
428428 </tr>
429429 <tr>
430430 <td><code>null</code></td>
431 <td>used to set a nullable type to <code>null</code></td>
431 <td>used to set an optional type to <code>null</code></td>
432432 </tr>
433433 <tr>
434434 <td><code>undefined</code></td>
......@@ -440,7 +440,7 @@ pub fn main() void {
440440 </tr>
441441 </table>
442442 </div>
443 {#see_also|Nullables|this#}
443 {#see_also|Optionals|this#}
444444 {#header_close#}
445445 {#header_open|String Literals#}
446446 {#code_begin|test#}
......@@ -988,7 +988,7 @@ a ^= b</code></pre></td>
988988 <td><pre><code class="zig">a ?? b</code></pre></td>
989989 <td>
990990 <ul>
991 <li>{#link|Nullables#}</li>
991 <li>{#link|Optionals#}</li>
992992 </ul>
993993 </td>
994994 <td>If <code>a</code> is <code>null</code>,
......@@ -1003,10 +1003,10 @@ unwrapped == 1234</code></pre>
10031003 </td>
10041004 </tr>
10051005 <tr>
1006 <td><pre><code class="zig">??a</code></pre></td>
1006 <td><pre><code class="zig">a.?</code></pre></td>
10071007 <td>
10081008 <ul>
1009 <li>{#link|Nullables#}</li>
1009 <li>{#link|Optionals#}</li>
10101010 </ul>
10111011 </td>
10121012 <td>
......@@ -1015,7 +1015,7 @@ unwrapped == 1234</code></pre>
10151015 </td>
10161016 <td>
10171017 <pre><code class="zig">const value: ?u32 = 5678;
1018??value == 5678</code></pre>
1018value.? == 5678</code></pre>
10191019 </td>
10201020 </tr>
10211021 <tr>
......@@ -1103,7 +1103,7 @@ unwrapped == 1234</code></pre>
11031103 <td><pre><code class="zig">a == null<code></pre></td>
11041104 <td>
11051105 <ul>
1106 <li>{#link|Nullables#}</li>
1106 <li>{#link|Optionals#}</li>
11071107 </ul>
11081108 </td>
11091109 <td>
......@@ -1267,8 +1267,8 @@ x.* == 1234</code></pre>
12671267 {#header_open|Precedence#}
12681268 <pre><code>x() x[] x.y
12691269a!b
1270!x -x -%x ~x &amp;x ?x ??x
1271x{} x.*
1270!x -x -%x ~x &amp;x ?x
1271x{} x.* x.?
12721272! * / % ** *%
12731273+ - ++ +% -%
12741274&lt;&lt; &gt;&gt;
......@@ -1483,17 +1483,17 @@ test "volatile" {
14831483 assert(@typeOf(mmio_ptr) == *volatile u8);
14841484}
14851485
1486test "nullable pointers" {
1487 // Pointers cannot be null. If you want a null pointer, use the nullable
1488 // prefix `?` to make the pointer type nullable.
1486test "optional pointers" {
1487 // Pointers cannot be null. If you want a null pointer, use the optional
1488 // prefix `?` to make the pointer type optional.
14891489 var ptr: ?*i32 = null;
14901490
14911491 var x: i32 = 1;
14921492 ptr = &x;
14931493
1494 assert((??ptr).* == 1);
1494 assert(ptr.?.* == 1);
14951495
1496 // Nullable pointers are the same size as normal pointers, because pointer
1496 // Optional pointers are the same size as normal pointers, because pointer
14971497 // value 0 is used as the null value.
14981498 assert(@sizeOf(?*i32) == @sizeOf(*i32));
14991499}
......@@ -1832,7 +1832,7 @@ test "linked list" {
18321832 .last = &node,
18331833 .len = 1,
18341834 };
1835 assert((??list2.first).data == 1234);
1835 assert(list2.first.?.data == 1234);
18361836}
18371837 {#code_end#}
18381838 {#see_also|comptime|@fieldParentPtr#}
......@@ -2270,7 +2270,7 @@ fn rangeHasNumber(begin: usize, end: usize, number: usize) bool {
22702270}
22712271
22722272test "while null capture" {
2273 // Just like if expressions, while loops can take a nullable as the
2273 // Just like if expressions, while loops can take an optional as the
22742274 // condition and capture the payload. When null is encountered the loop
22752275 // exits.
22762276 var sum1: u32 = 0;
......@@ -2280,7 +2280,7 @@ test "while null capture" {
22802280 }
22812281 assert(sum1 == 3);
22822282
2283 // The else branch is allowed on nullable iteration. In this case, it will
2283 // The else branch is allowed on optional iteration. In this case, it will
22842284 // be executed on the first null value encountered.
22852285 var sum2: u32 = 0;
22862286 numbers_left = 3;
......@@ -2340,7 +2340,7 @@ fn typeNameLength(comptime T: type) usize {
23402340 return @typeName(T).len;
23412341}
23422342 {#code_end#}
2343 {#see_also|if|Nullables|Errors|comptime|unreachable#}
2343 {#see_also|if|Optionals|Errors|comptime|unreachable#}
23442344 {#header_close#}
23452345 {#header_open|for#}
23462346 {#code_begin|test|for#}
......@@ -2400,7 +2400,7 @@ test "for else" {
24002400 if (value == null) {
24012401 break 9;
24022402 } else {
2403 sum += ??value;
2403 sum += value.?;
24042404 }
24052405 } else blk: {
24062406 assert(sum == 7);
......@@ -2461,7 +2461,7 @@ test "if boolean" {
24612461 assert(result == 47);
24622462}
24632463
2464test "if nullable" {
2464test "if optional" {
24652465 // If expressions test for null.
24662466
24672467 const a: ?u32 = 0;
......@@ -2544,7 +2544,7 @@ test "if error union" {
25442544 }
25452545}
25462546 {#code_end#}
2547 {#see_also|Nullables|Errors#}
2547 {#see_also|Optionals|Errors#}
25482548 {#header_close#}
25492549 {#header_open|defer#}
25502550 {#code_begin|test|defer#}
......@@ -3167,24 +3167,24 @@ test "inferred error set" {
31673167 <p>TODO</p>
31683168 {#header_close#}
31693169 {#header_close#}
3170 {#header_open|Nullables#}
3170 {#header_open|Optionals#}
31713171 <p>
31723172 One area that Zig provides safety without compromising efficiency or
3173 readability is with the nullable type.
3173 readability is with the optional type.
31743174 </p>
31753175 <p>
3176 The question mark symbolizes the nullable type. You can convert a type to a nullable
3176 The question mark symbolizes the optional type. You can convert a type to an optional
31773177 type by putting a question mark in front of it, like this:
31783178 </p>
31793179 {#code_begin|syntax#}
31803180// normal integer
31813181const normal_int: i32 = 1234;
31823182
3183// nullable integer
3184const nullable_int: ?i32 = 5678;
3183// optional integer
3184const optional_int: ?i32 = 5678;
31853185 {#code_end#}
31863186 <p>
3187 Now the variable <code>nullable_int</code> could be an <code>i32</code>, or <code>null</code>.
3187 Now the variable <code>optional_int</code> could be an <code>i32</code>, or <code>null</code>.
31883188 </p>
31893189 <p>
31903190 Instead of integers, let's talk about pointers. Null references are the source of many runtime
......@@ -3193,8 +3193,8 @@ const nullable_int: ?i32 = 5678;
31933193 </p>
31943194 <p>Zig does not have them.</p>
31953195 <p>
3196 Instead, you can use a nullable pointer. This secretly compiles down to a normal pointer,
3197 since we know we can use 0 as the null value for the nullable type. But the compiler
3196 Instead, you can use an optional pointer. This secretly compiles down to a normal pointer,
3197 since we know we can use 0 as the null value for the optional type. But the compiler
31983198 can check your work and make sure you don't assign null to something that can't be null.
31993199 </p>
32003200 <p>
......@@ -3226,7 +3226,7 @@ fn doAThing() ?*Foo {
32263226 <p>
32273227 Here, Zig is at least as convenient, if not more, than C. And, the type of "ptr"
32283228 is <code>*u8</code> <em>not</em> <code>?*u8</code>. The <code>??</code> operator
3229 unwrapped the nullable type and therefore <code>ptr</code> is guaranteed to be non-null everywhere
3229 unwrapped the optional type and therefore <code>ptr</code> is guaranteed to be non-null everywhere
32303230 it is used in the function.
32313231 </p>
32323232 <p>
......@@ -3245,10 +3245,10 @@ fn doAThing() ?*Foo {
32453245 In Zig you can accomplish the same thing:
32463246 </p>
32473247 {#code_begin|syntax#}
3248fn doAThing(nullable_foo: ?*Foo) void {
3248fn doAThing(optional_foo: ?*Foo) void {
32493249 // do some stuff
32503250
3251 if (nullable_foo) |foo| {
3251 if (optional_foo) |foo| {
32523252 doSomethingWithFoo(foo);
32533253 }
32543254
......@@ -3257,7 +3257,7 @@ fn doAThing(nullable_foo: ?*Foo) void {
32573257 {#code_end#}
32583258 <p>
32593259 Once again, the notable thing here is that inside the if block,
3260 <code>foo</code> is no longer a nullable pointer, it is a pointer, which
3260 <code>foo</code> is no longer an optional pointer, it is a pointer, which
32613261 cannot be null.
32623262 </p>
32633263 <p>
......@@ -3267,20 +3267,20 @@ fn doAThing(nullable_foo: ?*Foo) void {
32673267 The optimizer can sometimes make better decisions knowing that pointer arguments
32683268 cannot be null.
32693269 </p>
3270 {#header_open|Nullable Type#}
3271 <p>A nullable is created by putting <code>?</code> in front of a type. You can use compile-time
3272 reflection to access the child type of a nullable:</p>
3270 {#header_open|Optional Type#}
3271 <p>An optional is created by putting <code>?</code> in front of a type. You can use compile-time
3272 reflection to access the child type of an optional:</p>
32733273 {#code_begin|test#}
32743274const assert = @import("std").debug.assert;
32753275
3276test "nullable type" {
3277 // Declare a nullable and implicitly cast from null:
3276test "optional type" {
3277 // Declare an optional and implicitly cast from null:
32783278 var foo: ?i32 = null;
32793279
3280 // Implicitly cast from child type of a nullable
3280 // Implicitly cast from child type of an optional
32813281 foo = 1234;
32823282
3283 // Use compile-time reflection to access the child type of the nullable:
3283 // Use compile-time reflection to access the child type of the optional:
32843284 comptime assert(@typeOf(foo).Child == i32);
32853285}
32863286 {#code_end#}
......@@ -4888,7 +4888,7 @@ pub const TypeId = enum {
48884888 ComptimeInt,
48894889 Undefined,
48904890 Null,
4891 Nullable,
4891 Optional,
48924892 ErrorUnion,
48934893 Error,
48944894 Enum,
......@@ -4922,7 +4922,7 @@ pub const TypeInfo = union(TypeId) {
49224922 ComptimeInt: void,
49234923 Undefined: void,
49244924 Null: void,
4925 Nullable: Nullable,
4925 Optional: Optional,
49264926 ErrorUnion: ErrorUnion,
49274927 ErrorSet: ErrorSet,
49284928 Enum: Enum,
......@@ -4975,7 +4975,7 @@ pub const TypeInfo = union(TypeId) {
49754975 defs: []Definition,
49764976 };
49774977
4978 pub const Nullable = struct {
4978 pub const Optional = struct {
49794979 child: type,
49804980 };
49814981
......@@ -5366,8 +5366,8 @@ comptime {
53665366 <p>At compile-time:</p>
53675367 {#code_begin|test_err|unable to unwrap null#}
53685368comptime {
5369 const nullable_number: ?i32 = null;
5370 const number = ??nullable_number;
5369 const optional_number: ?i32 = null;
5370 const number = optional_number.?;
53715371}
53725372 {#code_end#}
53735373 <p>At runtime crashes with the message <code>attempt to unwrap null</code> and a stack trace.</p>
......@@ -5376,9 +5376,9 @@ comptime {
53765376 {#code_begin|exe|test#}
53775377const warn = @import("std").debug.warn;
53785378pub fn main() void {
5379 const nullable_number: ?i32 = null;
5379 const optional_number: ?i32 = null;
53805380
5381 if (nullable_number) |number| {
5381 if (optional_number) |number| {
53825382 warn("got number: {}\n", number);
53835383 } else {
53845384 warn("it's null\n");
......@@ -5939,9 +5939,9 @@ AsmInputItem = "[" Symbol "]" String "(" Expression ")"
59395939
59405940AsmClobbers= ":" list(String, ",")
59415941
5942UnwrapExpression = BoolOrExpression (UnwrapNullable | UnwrapError) | BoolOrExpression
5942UnwrapExpression = BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression
59435943
5944UnwrapNullable = "??" Expression
5944UnwrapOptional = "??" Expression
59455945
59465946UnwrapError = "catch" option("|" Symbol "|") Expression
59475947
......@@ -6015,12 +6015,10 @@ MultiplyOperator = "||" | "*" | "/" | "%" | "**" | "*%"
60156015
60166016PrefixOpExpression = PrefixOp TypeExpr | SuffixOpExpression
60176017
6018SuffixOpExpression = ("async" option("&lt;" SuffixOpExpression "&gt;") SuffixOpExpression FnCallExpression) | PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression | PtrDerefExpression)
6018SuffixOpExpression = ("async" option("&lt;" SuffixOpExpression "&gt;") SuffixOpExpression FnCallExpression) | PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression | ".*" | ".?")
60196019
60206020FieldAccessExpression = "." Symbol
60216021
6022PtrDerefExpression = ".*"
6023
60246022FnCallExpression = "(" list(Expression, ",") ")"
60256023
60266024ArrayAccessExpression = "[" Expression "]"
......@@ -6033,7 +6031,7 @@ ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")
60336031
60346032StructLiteralField = "." Symbol "=" Expression
60356033
6036PrefixOp = "!" | "-" | "~" | (("*" | "[*]") option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "??" | "-%" | "try" | "await"
6034PrefixOp = "!" | "-" | "~" | (("*" | "[*]") option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "-%" | "try" | "await"
60376035
60386036PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ContainerDecl | ("continue" option(":" Symbol)) | ErrorSetDecl | PromiseType
60396037
example/cat/main.zig+1-1
......@@ -7,7 +7,7 @@ const allocator = std.debug.global_allocator;
77
88pub fn main() !void {
99 var args_it = os.args();
10 const exe = try unwrapArg(??args_it.next(allocator));
10 const exe = try unwrapArg(args_it.next(allocator).?);
1111 var catted_anything = false;
1212 var stdout_file = try io.getStdOut();
1313
src-self-hosted/arg.zig+5-5
......@@ -99,7 +99,7 @@ pub const Args = struct {
9999 error.ArgumentNotInAllowedSet => {
100100 std.debug.warn("argument '{}' is invalid for flag '{}'\n", args[i], arg);
101101 std.debug.warn("allowed options are ");
102 for (??flag.allowed_set) |possible| {
102 for (flag.allowed_set.?) |possible| {
103103 std.debug.warn("'{}' ", possible);
104104 }
105105 std.debug.warn("\n");
......@@ -276,14 +276,14 @@ test "parse arguments" {
276276 debug.assert(!args.present("help2"));
277277 debug.assert(!args.present("init"));
278278
279 debug.assert(mem.eql(u8, ??args.single("build-file"), "build.zig"));
280 debug.assert(mem.eql(u8, ??args.single("color"), "on"));
279 debug.assert(mem.eql(u8, args.single("build-file").?, "build.zig"));
280 debug.assert(mem.eql(u8, args.single("color").?, "on"));
281281
282 const objects = ??args.many("object");
282 const objects = args.many("object").?;
283283 debug.assert(mem.eql(u8, objects[0], "obj1"));
284284 debug.assert(mem.eql(u8, objects[1], "obj2"));
285285
286 debug.assert(mem.eql(u8, ??args.single("library"), "lib2"));
286 debug.assert(mem.eql(u8, args.single("library").?, "lib2"));
287287
288288 const pos = args.positionals.toSliceConst();
289289 debug.assert(mem.eql(u8, pos[0], "build"));
src-self-hosted/llvm.zig+1-1
......@@ -8,6 +8,6 @@ pub const ContextRef = removeNullability(c.LLVMContextRef);
88pub const BuilderRef = removeNullability(c.LLVMBuilderRef);
99
1010fn removeNullability(comptime T: type) type {
11 comptime assert(@typeId(T) == builtin.TypeId.Nullable);
11 comptime assert(@typeId(T) == builtin.TypeId.Optional);
1212 return T.Child;
1313}
src-self-hosted/main.zig+4-4
......@@ -490,7 +490,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo
490490 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n");
491491 os.exit(1);
492492 }
493 cur_pkg = ??cur_pkg.parent;
493 cur_pkg = cur_pkg.parent.?;
494494 }
495495 }
496496
......@@ -514,7 +514,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo
514514 },
515515 }
516516
517 const basename = os.path.basename(??in_file);
517 const basename = os.path.basename(in_file.?);
518518 var it = mem.split(basename, ".");
519519 const root_name = it.next() ?? {
520520 try stderr.write("file name cannot be empty\n");
......@@ -523,12 +523,12 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo
523523
524524 const asm_a = flags.many("assembly");
525525 const obj_a = flags.many("object");
526 if (in_file == null and (obj_a == null or (??obj_a).len == 0) and (asm_a == null or (??asm_a).len == 0)) {
526 if (in_file == null and (obj_a == null or obj_a.?.len == 0) and (asm_a == null or asm_a.?.len == 0)) {
527527 try stderr.write("Expected source file argument or at least one --object or --assembly argument\n");
528528 os.exit(1);
529529 }
530530
531 if (out_type == Module.Kind.Obj and (obj_a != null and (??obj_a).len != 0)) {
531 if (out_type == Module.Kind.Obj and (obj_a != null and obj_a.?.len != 0)) {
532532 try stderr.write("When building an object file, --object arguments are invalid\n");
533533 os.exit(1);
534534 }
src/all_types.hpp+22-22
......@@ -145,8 +145,8 @@ enum ConstPtrSpecial {
145145 // emit a binary with a compile time known address.
146146 // In this case index is the numeric address value.
147147 // We also use this for null pointer. We need the data layout for ConstCastOnly == true
148 // types to be the same, so all nullables of pointer types use x_ptr
149 // instead of x_nullable
148 // types to be the same, so all optionals of pointer types use x_ptr
149 // instead of x_optional
150150 ConstPtrSpecialHardCodedAddr,
151151 // This means that the pointer represents memory of assigning to _.
152152 // That is, storing discards the data, and loading is invalid.
......@@ -222,10 +222,10 @@ enum RuntimeHintErrorUnion {
222222 RuntimeHintErrorUnionNonError,
223223};
224224
225enum RuntimeHintMaybe {
226 RuntimeHintMaybeUnknown,
227 RuntimeHintMaybeNull, // TODO is this value even possible? if this is the case it might mean the const value is compile time known.
228 RuntimeHintMaybeNonNull,
225enum RuntimeHintOptional {
226 RuntimeHintOptionalUnknown,
227 RuntimeHintOptionalNull, // TODO is this value even possible? if this is the case it might mean the const value is compile time known.
228 RuntimeHintOptionalNonNull,
229229};
230230
231231enum RuntimeHintPtr {
......@@ -254,7 +254,7 @@ struct ConstExprValue {
254254 bool x_bool;
255255 ConstBoundFnValue x_bound_fn;
256256 TypeTableEntry *x_type;
257 ConstExprValue *x_nullable;
257 ConstExprValue *x_optional;
258258 ConstErrValue x_err_union;
259259 ErrorTableEntry *x_err_set;
260260 BigInt x_enum_tag;
......@@ -268,7 +268,7 @@ struct ConstExprValue {
268268
269269 // populated if special == ConstValSpecialRuntime
270270 RuntimeHintErrorUnion rh_error_union;
271 RuntimeHintMaybe rh_maybe;
271 RuntimeHintOptional rh_maybe;
272272 RuntimeHintPtr rh_ptr;
273273 } data;
274274};
......@@ -556,7 +556,7 @@ enum BinOpType {
556556 BinOpTypeMultWrap,
557557 BinOpTypeDiv,
558558 BinOpTypeMod,
559 BinOpTypeUnwrapMaybe,
559 BinOpTypeUnwrapOptional,
560560 BinOpTypeArrayCat,
561561 BinOpTypeArrayMult,
562562 BinOpTypeErrorUnion,
......@@ -623,8 +623,8 @@ enum PrefixOp {
623623 PrefixOpBinNot,
624624 PrefixOpNegation,
625625 PrefixOpNegationWrap,
626 PrefixOpMaybe,
627 PrefixOpUnwrapMaybe,
626 PrefixOpOptional,
627 PrefixOpUnwrapOptional,
628628 PrefixOpAddrOf,
629629};
630630
......@@ -1052,7 +1052,7 @@ struct TypeTableEntryStruct {
10521052 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
10531053};
10541054
1055struct TypeTableEntryMaybe {
1055struct TypeTableEntryOptional {
10561056 TypeTableEntry *child_type;
10571057};
10581058
......@@ -1175,7 +1175,7 @@ enum TypeTableEntryId {
11751175 TypeTableEntryIdComptimeInt,
11761176 TypeTableEntryIdUndefined,
11771177 TypeTableEntryIdNull,
1178 TypeTableEntryIdMaybe,
1178 TypeTableEntryIdOptional,
11791179 TypeTableEntryIdErrorUnion,
11801180 TypeTableEntryIdErrorSet,
11811181 TypeTableEntryIdEnum,
......@@ -1206,7 +1206,7 @@ struct TypeTableEntry {
12061206 TypeTableEntryFloat floating;
12071207 TypeTableEntryArray array;
12081208 TypeTableEntryStruct structure;
1209 TypeTableEntryMaybe maybe;
1209 TypeTableEntryOptional maybe;
12101210 TypeTableEntryErrorUnion error_union;
12111211 TypeTableEntryErrorSet error_set;
12121212 TypeTableEntryEnum enumeration;
......@@ -1402,7 +1402,7 @@ enum PanicMsgId {
14021402 PanicMsgIdRemainderDivisionByZero,
14031403 PanicMsgIdExactDivisionRemainder,
14041404 PanicMsgIdSliceWidenRemainder,
1405 PanicMsgIdUnwrapMaybeFail,
1405 PanicMsgIdUnwrapOptionalFail,
14061406 PanicMsgIdInvalidErrorCode,
14071407 PanicMsgIdIncorrectAlignment,
14081408 PanicMsgIdBadUnionField,
......@@ -2016,8 +2016,8 @@ enum IrInstructionId {
20162016 IrInstructionIdAsm,
20172017 IrInstructionIdSizeOf,
20182018 IrInstructionIdTestNonNull,
2019 IrInstructionIdUnwrapMaybe,
2020 IrInstructionIdMaybeWrap,
2019 IrInstructionIdUnwrapOptional,
2020 IrInstructionIdOptionalWrap,
20212021 IrInstructionIdUnionTag,
20222022 IrInstructionIdClz,
20232023 IrInstructionIdCtz,
......@@ -2184,7 +2184,7 @@ enum IrUnOp {
21842184 IrUnOpNegation,
21852185 IrUnOpNegationWrap,
21862186 IrUnOpDereference,
2187 IrUnOpMaybe,
2187 IrUnOpOptional,
21882188};
21892189
21902190struct IrInstructionUnOp {
......@@ -2487,7 +2487,7 @@ struct IrInstructionTestNonNull {
24872487 IrInstruction *value;
24882488};
24892489
2490struct IrInstructionUnwrapMaybe {
2490struct IrInstructionUnwrapOptional {
24912491 IrInstruction base;
24922492
24932493 IrInstruction *value;
......@@ -2745,7 +2745,7 @@ struct IrInstructionUnwrapErrPayload {
27452745 bool safety_check_on;
27462746};
27472747
2748struct IrInstructionMaybeWrap {
2748struct IrInstructionOptionalWrap {
27492749 IrInstruction base;
27502750
27512751 IrInstruction *value;
......@@ -2954,10 +2954,10 @@ struct IrInstructionExport {
29542954struct IrInstructionErrorReturnTrace {
29552955 IrInstruction base;
29562956
2957 enum Nullable {
2957 enum Optional {
29582958 Null,
29592959 NonNull,
2960 } nullable;
2960 } optional;
29612961};
29622962
29632963struct IrInstructionErrorUnion {
src/analyze.cpp+35-35
......@@ -236,7 +236,7 @@ bool type_is_complete(TypeTableEntry *type_entry) {
236236 case TypeTableEntryIdComptimeInt:
237237 case TypeTableEntryIdUndefined:
238238 case TypeTableEntryIdNull:
239 case TypeTableEntryIdMaybe:
239 case TypeTableEntryIdOptional:
240240 case TypeTableEntryIdErrorUnion:
241241 case TypeTableEntryIdErrorSet:
242242 case TypeTableEntryIdFn:
......@@ -272,7 +272,7 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) {
272272 case TypeTableEntryIdComptimeInt:
273273 case TypeTableEntryIdUndefined:
274274 case TypeTableEntryIdNull:
275 case TypeTableEntryIdMaybe:
275 case TypeTableEntryIdOptional:
276276 case TypeTableEntryIdErrorUnion:
277277 case TypeTableEntryIdErrorSet:
278278 case TypeTableEntryIdFn:
......@@ -520,7 +520,7 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {
520520 } else {
521521 ensure_complete_type(g, child_type);
522522
523 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdMaybe);
523 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOptional);
524524 assert(child_type->type_ref || child_type->zero_bits);
525525 assert(child_type->di_type);
526526 entry->is_copyable = type_is_copyable(g, child_type);
......@@ -1361,7 +1361,7 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {
13611361 return type_entry->data.structure.layout == ContainerLayoutPacked;
13621362 case TypeTableEntryIdUnion:
13631363 return type_entry->data.unionation.layout == ContainerLayoutPacked;
1364 case TypeTableEntryIdMaybe:
1364 case TypeTableEntryIdOptional:
13651365 {
13661366 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
13671367 return type_is_codegen_pointer(child_type);
......@@ -1415,7 +1415,7 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {
14151415 return type_allowed_in_extern(g, type_entry->data.pointer.child_type);
14161416 case TypeTableEntryIdStruct:
14171417 return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked;
1418 case TypeTableEntryIdMaybe:
1418 case TypeTableEntryIdOptional:
14191419 {
14201420 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
14211421 return child_type->id == TypeTableEntryIdPointer || child_type->id == TypeTableEntryIdFn;
......@@ -1538,7 +1538,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
15381538 case TypeTableEntryIdPointer:
15391539 case TypeTableEntryIdArray:
15401540 case TypeTableEntryIdStruct:
1541 case TypeTableEntryIdMaybe:
1541 case TypeTableEntryIdOptional:
15421542 case TypeTableEntryIdErrorUnion:
15431543 case TypeTableEntryIdErrorSet:
15441544 case TypeTableEntryIdEnum:
......@@ -1632,7 +1632,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
16321632 case TypeTableEntryIdPointer:
16331633 case TypeTableEntryIdArray:
16341634 case TypeTableEntryIdStruct:
1635 case TypeTableEntryIdMaybe:
1635 case TypeTableEntryIdOptional:
16361636 case TypeTableEntryIdErrorUnion:
16371637 case TypeTableEntryIdErrorSet:
16381638 case TypeTableEntryIdEnum:
......@@ -2985,8 +2985,8 @@ static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {
29852985 return wrong_panic_prototype(g, proto_node, fn_type);
29862986 }
29872987
2988 TypeTableEntry *nullable_ptr_to_stack_trace_type = get_maybe_type(g, get_ptr_to_stack_trace_type(g));
2989 if (fn_type_id->param_info[1].type != nullable_ptr_to_stack_trace_type) {
2988 TypeTableEntry *optional_ptr_to_stack_trace_type = get_maybe_type(g, get_ptr_to_stack_trace_type(g));
2989 if (fn_type_id->param_info[1].type != optional_ptr_to_stack_trace_type) {
29902990 return wrong_panic_prototype(g, proto_node, fn_type);
29912991 }
29922992
......@@ -3368,7 +3368,7 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
33683368 case TypeTableEntryIdPointer:
33693369 case TypeTableEntryIdArray:
33703370 case TypeTableEntryIdStruct:
3371 case TypeTableEntryIdMaybe:
3371 case TypeTableEntryIdOptional:
33723372 case TypeTableEntryIdErrorUnion:
33733373 case TypeTableEntryIdErrorSet:
33743374 case TypeTableEntryIdEnum:
......@@ -3746,7 +3746,7 @@ static bool is_container(TypeTableEntry *type_entry) {
37463746 case TypeTableEntryIdComptimeInt:
37473747 case TypeTableEntryIdUndefined:
37483748 case TypeTableEntryIdNull:
3749 case TypeTableEntryIdMaybe:
3749 case TypeTableEntryIdOptional:
37503750 case TypeTableEntryIdErrorUnion:
37513751 case TypeTableEntryIdErrorSet:
37523752 case TypeTableEntryIdFn:
......@@ -3805,7 +3805,7 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {
38053805 case TypeTableEntryIdComptimeInt:
38063806 case TypeTableEntryIdUndefined:
38073807 case TypeTableEntryIdNull:
3808 case TypeTableEntryIdMaybe:
3808 case TypeTableEntryIdOptional:
38093809 case TypeTableEntryIdErrorUnion:
38103810 case TypeTableEntryIdErrorSet:
38113811 case TypeTableEntryIdFn:
......@@ -3824,7 +3824,7 @@ TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {
38243824 if (type->id == TypeTableEntryIdPointer) return type;
38253825 if (type->id == TypeTableEntryIdFn) return type;
38263826 if (type->id == TypeTableEntryIdPromise) return type;
3827 if (type->id == TypeTableEntryIdMaybe) {
3827 if (type->id == TypeTableEntryIdOptional) {
38283828 if (type->data.maybe.child_type->id == TypeTableEntryIdPointer) return type->data.maybe.child_type;
38293829 if (type->data.maybe.child_type->id == TypeTableEntryIdFn) return type->data.maybe.child_type;
38303830 if (type->data.maybe.child_type->id == TypeTableEntryIdPromise) return type->data.maybe.child_type;
......@@ -4331,7 +4331,7 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
43314331 return type_has_bits(type_entry);
43324332 case TypeTableEntryIdErrorUnion:
43334333 return type_has_bits(type_entry->data.error_union.payload_type);
4334 case TypeTableEntryIdMaybe:
4334 case TypeTableEntryIdOptional:
43354335 return type_has_bits(type_entry->data.maybe.child_type) &&
43364336 !type_is_codegen_pointer(type_entry->data.maybe.child_type);
43374337 case TypeTableEntryIdUnion:
......@@ -4709,12 +4709,12 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
47094709 case TypeTableEntryIdUnion:
47104710 // TODO better hashing algorithm
47114711 return 2709806591;
4712 case TypeTableEntryIdMaybe:
4712 case TypeTableEntryIdOptional:
47134713 if (get_codegen_ptr_type(const_val->type) != nullptr) {
47144714 return hash_const_val(const_val) * 1992916303;
47154715 } else {
4716 if (const_val->data.x_nullable) {
4717 return hash_const_val(const_val->data.x_nullable) * 1992916303;
4716 if (const_val->data.x_optional) {
4717 return hash_const_val(const_val->data.x_optional) * 1992916303;
47184718 } else {
47194719 return 4016830364;
47204720 }
......@@ -4817,12 +4817,12 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
48174817 }
48184818 return false;
48194819
4820 case TypeTableEntryIdMaybe:
4820 case TypeTableEntryIdOptional:
48214821 if (get_codegen_ptr_type(value->type) != nullptr)
48224822 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
4823 if (value->data.x_nullable == nullptr)
4823 if (value->data.x_optional == nullptr)
48244824 return false;
4825 return can_mutate_comptime_var_state(value->data.x_nullable);
4825 return can_mutate_comptime_var_state(value->data.x_optional);
48264826
48274827 case TypeTableEntryIdErrorUnion:
48284828 if (value->data.x_err_union.err != nullptr)
......@@ -4869,7 +4869,7 @@ static bool return_type_is_cacheable(TypeTableEntry *return_type) {
48694869 case TypeTableEntryIdUnion:
48704870 return false;
48714871
4872 case TypeTableEntryIdMaybe:
4872 case TypeTableEntryIdOptional:
48734873 return return_type_is_cacheable(return_type->data.maybe.child_type);
48744874
48754875 case TypeTableEntryIdErrorUnion:
......@@ -4978,7 +4978,7 @@ bool type_requires_comptime(TypeTableEntry *type_entry) {
49784978 case TypeTableEntryIdUnion:
49794979 assert(type_has_zero_bits_known(type_entry));
49804980 return type_entry->data.unionation.requires_comptime;
4981 case TypeTableEntryIdMaybe:
4981 case TypeTableEntryIdOptional:
49824982 return type_requires_comptime(type_entry->data.maybe.child_type);
49834983 case TypeTableEntryIdErrorUnion:
49844984 return type_requires_comptime(type_entry->data.error_union.payload_type);
......@@ -5460,13 +5460,13 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
54605460 zig_panic("TODO");
54615461 case TypeTableEntryIdNull:
54625462 zig_panic("TODO");
5463 case TypeTableEntryIdMaybe:
5463 case TypeTableEntryIdOptional:
54645464 if (get_codegen_ptr_type(a->type) != nullptr)
54655465 return const_values_equal_ptr(a, b);
5466 if (a->data.x_nullable == nullptr || b->data.x_nullable == nullptr) {
5467 return (a->data.x_nullable == nullptr && b->data.x_nullable == nullptr);
5466 if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) {
5467 return (a->data.x_optional == nullptr && b->data.x_optional == nullptr);
54685468 } else {
5469 return const_values_equal(a->data.x_nullable, b->data.x_nullable);
5469 return const_values_equal(a->data.x_optional, b->data.x_optional);
54705470 }
54715471 case TypeTableEntryIdErrorUnion:
54725472 zig_panic("TODO");
......@@ -5708,12 +5708,12 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
57085708 buf_appendf(buf, "undefined");
57095709 return;
57105710 }
5711 case TypeTableEntryIdMaybe:
5711 case TypeTableEntryIdOptional:
57125712 {
57135713 if (get_codegen_ptr_type(const_val->type) != nullptr)
57145714 return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);
5715 if (const_val->data.x_nullable) {
5716 render_const_value(g, buf, const_val->data.x_nullable);
5715 if (const_val->data.x_optional) {
5716 render_const_value(g, buf, const_val->data.x_optional);
57175717 } else {
57185718 buf_appendf(buf, "null");
57195719 }
......@@ -5819,7 +5819,7 @@ uint32_t type_id_hash(TypeId x) {
58195819 case TypeTableEntryIdComptimeInt:
58205820 case TypeTableEntryIdUndefined:
58215821 case TypeTableEntryIdNull:
5822 case TypeTableEntryIdMaybe:
5822 case TypeTableEntryIdOptional:
58235823 case TypeTableEntryIdErrorSet:
58245824 case TypeTableEntryIdEnum:
58255825 case TypeTableEntryIdUnion:
......@@ -5865,7 +5865,7 @@ bool type_id_eql(TypeId a, TypeId b) {
58655865 case TypeTableEntryIdComptimeInt:
58665866 case TypeTableEntryIdUndefined:
58675867 case TypeTableEntryIdNull:
5868 case TypeTableEntryIdMaybe:
5868 case TypeTableEntryIdOptional:
58695869 case TypeTableEntryIdPromise:
58705870 case TypeTableEntryIdErrorSet:
58715871 case TypeTableEntryIdEnum:
......@@ -5987,7 +5987,7 @@ static const TypeTableEntryId all_type_ids[] = {
59875987 TypeTableEntryIdComptimeInt,
59885988 TypeTableEntryIdUndefined,
59895989 TypeTableEntryIdNull,
5990 TypeTableEntryIdMaybe,
5990 TypeTableEntryIdOptional,
59915991 TypeTableEntryIdErrorUnion,
59925992 TypeTableEntryIdErrorSet,
59935993 TypeTableEntryIdEnum,
......@@ -6042,7 +6042,7 @@ size_t type_id_index(TypeTableEntry *entry) {
60426042 return 11;
60436043 case TypeTableEntryIdNull:
60446044 return 12;
6045 case TypeTableEntryIdMaybe:
6045 case TypeTableEntryIdOptional:
60466046 return 13;
60476047 case TypeTableEntryIdErrorUnion:
60486048 return 14;
......@@ -6100,8 +6100,8 @@ const char *type_id_name(TypeTableEntryId id) {
61006100 return "Undefined";
61016101 case TypeTableEntryIdNull:
61026102 return "Null";
6103 case TypeTableEntryIdMaybe:
6104 return "Nullable";
6103 case TypeTableEntryIdOptional:
6104 return "Optional";
61056105 case TypeTableEntryIdErrorUnion:
61066106 return "ErrorUnion";
61076107 case TypeTableEntryIdErrorSet:
src/ast_render.cpp+3-3
......@@ -50,7 +50,7 @@ static const char *bin_op_str(BinOpType bin_op) {
5050 case BinOpTypeAssignBitXor: return "^=";
5151 case BinOpTypeAssignBitOr: return "|=";
5252 case BinOpTypeAssignMergeErrorSets: return "||=";
53 case BinOpTypeUnwrapMaybe: return "??";
53 case BinOpTypeUnwrapOptional: return "??";
5454 case BinOpTypeArrayCat: return "++";
5555 case BinOpTypeArrayMult: return "**";
5656 case BinOpTypeErrorUnion: return "!";
......@@ -66,8 +66,8 @@ static const char *prefix_op_str(PrefixOp prefix_op) {
6666 case PrefixOpNegationWrap: return "-%";
6767 case PrefixOpBoolNot: return "!";
6868 case PrefixOpBinNot: return "~";
69 case PrefixOpMaybe: return "?";
70 case PrefixOpUnwrapMaybe: return "??";
69 case PrefixOpOptional: return "?";
70 case PrefixOpUnwrapOptional: return "??";
7171 case PrefixOpAddrOf: return "&";
7272 }
7373 zig_unreachable();
src/codegen.cpp+30-30
......@@ -865,7 +865,7 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
865865 return buf_create_from_str("exact division produced remainder");
866866 case PanicMsgIdSliceWidenRemainder:
867867 return buf_create_from_str("slice widening size mismatch");
868 case PanicMsgIdUnwrapMaybeFail:
868 case PanicMsgIdUnwrapOptionalFail:
869869 return buf_create_from_str("attempt to unwrap null");
870870 case PanicMsgIdUnreachable:
871871 return buf_create_from_str("reached unreachable code");
......@@ -2734,7 +2734,7 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst
27342734
27352735 switch (op_id) {
27362736 case IrUnOpInvalid:
2737 case IrUnOpMaybe:
2737 case IrUnOpOptional:
27382738 case IrUnOpDereference:
27392739 zig_unreachable();
27402740 case IrUnOpNegation:
......@@ -3333,7 +3333,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
33333333}
33343334
33353335static LLVMValueRef gen_non_null_bit(CodeGen *g, TypeTableEntry *maybe_type, LLVMValueRef maybe_handle) {
3336 assert(maybe_type->id == TypeTableEntryIdMaybe);
3336 assert(maybe_type->id == TypeTableEntryIdOptional);
33373337 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
33383338 if (child_type->zero_bits) {
33393339 return maybe_handle;
......@@ -3355,23 +3355,23 @@ static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable
33553355}
33563356
33573357static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
3358 IrInstructionUnwrapMaybe *instruction)
3358 IrInstructionUnwrapOptional *instruction)
33593359{
33603360 TypeTableEntry *ptr_type = instruction->value->value.type;
33613361 assert(ptr_type->id == TypeTableEntryIdPointer);
33623362 TypeTableEntry *maybe_type = ptr_type->data.pointer.child_type;
3363 assert(maybe_type->id == TypeTableEntryIdMaybe);
3363 assert(maybe_type->id == TypeTableEntryIdOptional);
33643364 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
33653365 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);
33663366 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);
33673367 if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on) {
33683368 LLVMValueRef non_null_bit = gen_non_null_bit(g, maybe_type, maybe_handle);
3369 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeOk");
3370 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeFail");
3369 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapOptionalOk");
3370 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapOptionalFail");
33713371 LLVMBuildCondBr(g->builder, non_null_bit, ok_block, fail_block);
33723372
33733373 LLVMPositionBuilderAtEnd(g->builder, fail_block);
3374 gen_safety_crash(g, PanicMsgIdUnwrapMaybeFail);
3374 gen_safety_crash(g, PanicMsgIdUnwrapOptionalFail);
33753375
33763376 LLVMPositionBuilderAtEnd(g->builder, ok_block);
33773377 }
......@@ -3593,17 +3593,17 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
35933593 } else if (target_type->id == TypeTableEntryIdFn) {
35943594 align_bytes = target_type->data.fn.fn_type_id.alignment;
35953595 ptr_val = target_val;
3596 } else if (target_type->id == TypeTableEntryIdMaybe &&
3596 } else if (target_type->id == TypeTableEntryIdOptional &&
35973597 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
35983598 {
35993599 align_bytes = target_type->data.maybe.child_type->data.pointer.alignment;
36003600 ptr_val = target_val;
3601 } else if (target_type->id == TypeTableEntryIdMaybe &&
3601 } else if (target_type->id == TypeTableEntryIdOptional &&
36023602 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)
36033603 {
36043604 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;
36053605 ptr_val = target_val;
3606 } else if (target_type->id == TypeTableEntryIdMaybe &&
3606 } else if (target_type->id == TypeTableEntryIdOptional &&
36073607 target_type->data.maybe.child_type->id == TypeTableEntryIdPromise)
36083608 {
36093609 zig_panic("TODO audit this function");
......@@ -3705,7 +3705,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
37053705 success_order, failure_order, instruction->is_weak);
37063706
37073707 TypeTableEntry *maybe_type = instruction->base.value.type;
3708 assert(maybe_type->id == TypeTableEntryIdMaybe);
3708 assert(maybe_type->id == TypeTableEntryIdOptional);
37093709 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
37103710
37113711 if (type_is_codegen_pointer(child_type)) {
......@@ -4115,10 +4115,10 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
41154115 }
41164116}
41174117
4118static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionMaybeWrap *instruction) {
4118static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {
41194119 TypeTableEntry *wanted_type = instruction->base.value.type;
41204120
4121 assert(wanted_type->id == TypeTableEntryIdMaybe);
4121 assert(wanted_type->id == TypeTableEntryIdOptional);
41224122
41234123 TypeTableEntry *child_type = wanted_type->data.maybe.child_type;
41244124
......@@ -4699,8 +4699,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
46994699 return ir_render_asm(g, executable, (IrInstructionAsm *)instruction);
47004700 case IrInstructionIdTestNonNull:
47014701 return ir_render_test_non_null(g, executable, (IrInstructionTestNonNull *)instruction);
4702 case IrInstructionIdUnwrapMaybe:
4703 return ir_render_unwrap_maybe(g, executable, (IrInstructionUnwrapMaybe *)instruction);
4702 case IrInstructionIdUnwrapOptional:
4703 return ir_render_unwrap_maybe(g, executable, (IrInstructionUnwrapOptional *)instruction);
47044704 case IrInstructionIdClz:
47054705 return ir_render_clz(g, executable, (IrInstructionClz *)instruction);
47064706 case IrInstructionIdCtz:
......@@ -4741,8 +4741,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
47414741 return ir_render_unwrap_err_code(g, executable, (IrInstructionUnwrapErrCode *)instruction);
47424742 case IrInstructionIdUnwrapErrPayload:
47434743 return ir_render_unwrap_err_payload(g, executable, (IrInstructionUnwrapErrPayload *)instruction);
4744 case IrInstructionIdMaybeWrap:
4745 return ir_render_maybe_wrap(g, executable, (IrInstructionMaybeWrap *)instruction);
4744 case IrInstructionIdOptionalWrap:
4745 return ir_render_maybe_wrap(g, executable, (IrInstructionOptionalWrap *)instruction);
47464746 case IrInstructionIdErrWrapCode:
47474747 return ir_render_err_wrap_code(g, executable, (IrInstructionErrWrapCode *)instruction);
47484748 case IrInstructionIdErrWrapPayload:
......@@ -4972,7 +4972,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
49724972 }
49734973 case TypeTableEntryIdPointer:
49744974 case TypeTableEntryIdFn:
4975 case TypeTableEntryIdMaybe:
4975 case TypeTableEntryIdOptional:
49764976 case TypeTableEntryIdPromise:
49774977 {
49784978 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");
......@@ -5137,19 +5137,19 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
51375137 } else {
51385138 return LLVMConstNull(LLVMInt1Type());
51395139 }
5140 case TypeTableEntryIdMaybe:
5140 case TypeTableEntryIdOptional:
51415141 {
51425142 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
51435143 if (child_type->zero_bits) {
5144 return LLVMConstInt(LLVMInt1Type(), const_val->data.x_nullable ? 1 : 0, false);
5144 return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false);
51455145 } else if (type_is_codegen_pointer(child_type)) {
51465146 return gen_const_val_ptr(g, const_val, name);
51475147 } else {
51485148 LLVMValueRef child_val;
51495149 LLVMValueRef maybe_val;
51505150 bool make_unnamed_struct;
5151 if (const_val->data.x_nullable) {
5152 child_val = gen_const_val(g, const_val->data.x_nullable, "");
5151 if (const_val->data.x_optional) {
5152 child_val = gen_const_val(g, const_val->data.x_optional, "");
51535153 maybe_val = LLVMConstAllOnes(LLVMInt1Type());
51545154
51555155 make_unnamed_struct = is_llvm_value_unnamed_type(const_val->type, child_val);
......@@ -5755,8 +5755,8 @@ static void do_code_gen(CodeGen *g) {
57555755 } else if (instruction->id == IrInstructionIdSlice) {
57565756 IrInstructionSlice *slice_instruction = (IrInstructionSlice *)instruction;
57575757 slot = &slice_instruction->tmp_ptr;
5758 } else if (instruction->id == IrInstructionIdMaybeWrap) {
5759 IrInstructionMaybeWrap *maybe_wrap_instruction = (IrInstructionMaybeWrap *)instruction;
5758 } else if (instruction->id == IrInstructionIdOptionalWrap) {
5759 IrInstructionOptionalWrap *maybe_wrap_instruction = (IrInstructionOptionalWrap *)instruction;
57605760 slot = &maybe_wrap_instruction->tmp_ptr;
57615761 } else if (instruction->id == IrInstructionIdErrWrapPayload) {
57625762 IrInstructionErrWrapPayload *err_wrap_payload_instruction = (IrInstructionErrWrapPayload *)instruction;
......@@ -6511,7 +6511,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
65116511 " ComptimeInt: void,\n"
65126512 " Undefined: void,\n"
65136513 " Null: void,\n"
6514 " Nullable: Nullable,\n"
6514 " Optional: Optional,\n"
65156515 " ErrorUnion: ErrorUnion,\n"
65166516 " ErrorSet: ErrorSet,\n"
65176517 " Enum: Enum,\n"
......@@ -6570,7 +6570,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
65706570 " defs: []Definition,\n"
65716571 " };\n"
65726572 "\n"
6573 " pub const Nullable = struct {\n"
6573 " pub const Optional = struct {\n"
65746574 " child: type,\n"
65756575 " };\n"
65766576 "\n"
......@@ -7145,7 +7145,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry
71457145 case TypeTableEntryIdArray:
71467146 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);
71477147 return;
7148 case TypeTableEntryIdMaybe:
7148 case TypeTableEntryIdOptional:
71497149 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);
71507150 return;
71517151 case TypeTableEntryIdFn:
......@@ -7234,7 +7234,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
72347234 buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf));
72357235 break;
72367236 }
7237 case TypeTableEntryIdMaybe:
7237 case TypeTableEntryIdOptional:
72387238 {
72397239 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
72407240 if (child_type->zero_bits) {
......@@ -7448,7 +7448,7 @@ static void gen_h_file(CodeGen *g) {
74487448 case TypeTableEntryIdBlock:
74497449 case TypeTableEntryIdBoundFn:
74507450 case TypeTableEntryIdArgTuple:
7451 case TypeTableEntryIdMaybe:
7451 case TypeTableEntryIdOptional:
74527452 case TypeTableEntryIdFn:
74537453 case TypeTableEntryIdPromise:
74547454 zig_unreachable();
src/ir.cpp+99-99
......@@ -47,7 +47,7 @@ enum ConstCastResultId {
4747 ConstCastResultIdErrSetGlobal,
4848 ConstCastResultIdPointerChild,
4949 ConstCastResultIdSliceChild,
50 ConstCastResultIdNullableChild,
50 ConstCastResultIdOptionalChild,
5151 ConstCastResultIdErrorUnionPayload,
5252 ConstCastResultIdErrorUnionErrorSet,
5353 ConstCastResultIdFnAlign,
......@@ -86,7 +86,7 @@ struct ConstCastOnly {
8686 ConstCastErrSetMismatch error_set;
8787 ConstCastOnly *pointer_child;
8888 ConstCastOnly *slice_child;
89 ConstCastOnly *nullable_child;
89 ConstCastOnly *optional_child;
9090 ConstCastOnly *error_union_payload;
9191 ConstCastOnly *error_union_error_set;
9292 ConstCastOnly *return_type;
......@@ -372,8 +372,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTestNonNull *) {
372372 return IrInstructionIdTestNonNull;
373373}
374374
375static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapMaybe *) {
376 return IrInstructionIdUnwrapMaybe;
375static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapOptional *) {
376 return IrInstructionIdUnwrapOptional;
377377}
378378
379379static constexpr IrInstructionId ir_instruction_id(IrInstructionClz *) {
......@@ -524,8 +524,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload
524524 return IrInstructionIdUnwrapErrPayload;
525525}
526526
527static constexpr IrInstructionId ir_instruction_id(IrInstructionMaybeWrap *) {
528 return IrInstructionIdMaybeWrap;
527static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalWrap *) {
528 return IrInstructionIdOptionalWrap;
529529}
530530
531531static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapPayload *) {
......@@ -1571,7 +1571,7 @@ static IrInstruction *ir_build_test_nonnull_from(IrBuilder *irb, IrInstruction *
15711571static IrInstruction *ir_build_unwrap_maybe(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value,
15721572 bool safety_check_on)
15731573{
1574 IrInstructionUnwrapMaybe *instruction = ir_build_instruction<IrInstructionUnwrapMaybe>(irb, scope, source_node);
1574 IrInstructionUnwrapOptional *instruction = ir_build_instruction<IrInstructionUnwrapOptional>(irb, scope, source_node);
15751575 instruction->value = value;
15761576 instruction->safety_check_on = safety_check_on;
15771577
......@@ -1590,7 +1590,7 @@ static IrInstruction *ir_build_unwrap_maybe_from(IrBuilder *irb, IrInstruction *
15901590}
15911591
15921592static IrInstruction *ir_build_maybe_wrap(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
1593 IrInstructionMaybeWrap *instruction = ir_build_instruction<IrInstructionMaybeWrap>(irb, scope, source_node);
1593 IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>(irb, scope, source_node);
15941594 instruction->value = value;
15951595
15961596 ir_ref_instruction(value, irb->current_basic_block);
......@@ -2496,9 +2496,9 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s
24962496 return &instruction->base;
24972497}
24982498
2499static IrInstruction *ir_build_error_return_trace(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstructionErrorReturnTrace::Nullable nullable) {
2499static IrInstruction *ir_build_error_return_trace(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstructionErrorReturnTrace::Optional optional) {
25002500 IrInstructionErrorReturnTrace *instruction = ir_build_instruction<IrInstructionErrorReturnTrace>(irb, scope, source_node);
2501 instruction->nullable = nullable;
2501 instruction->optional = optional;
25022502
25032503 return &instruction->base;
25042504}
......@@ -3295,9 +3295,9 @@ static IrInstruction *ir_gen_maybe_ok_or(IrBuilder *irb, Scope *parent_scope, As
32953295 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null);
32963296 }
32973297
3298 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "MaybeNonNull");
3299 IrBasicBlock *null_block = ir_create_basic_block(irb, parent_scope, "MaybeNull");
3300 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "MaybeEnd");
3298 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");
3299 IrBasicBlock *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");
3300 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd");
33013301 ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);
33023302
33033303 ir_set_cursor_at_end_and_append_block(irb, null_block);
......@@ -3426,7 +3426,7 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node)
34263426 return ir_gen_bin_op_id(irb, scope, node, IrBinOpArrayMult);
34273427 case BinOpTypeMergeErrorSets:
34283428 return ir_gen_bin_op_id(irb, scope, node, IrBinOpMergeErrorSets);
3429 case BinOpTypeUnwrapMaybe:
3429 case BinOpTypeUnwrapOptional:
34303430 return ir_gen_maybe_ok_or(irb, scope, node);
34313431 case BinOpTypeErrorUnion:
34323432 return ir_gen_error_union(irb, scope, node);
......@@ -4703,9 +4703,9 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
47034703 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegation), lval);
47044704 case PrefixOpNegationWrap:
47054705 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegationWrap), lval);
4706 case PrefixOpMaybe:
4707 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe), lval);
4708 case PrefixOpUnwrapMaybe:
4706 case PrefixOpOptional:
4707 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval);
4708 case PrefixOpUnwrapOptional:
47094709 return ir_gen_maybe_assert_ok(irb, scope, node, lval);
47104710 case PrefixOpAddrOf: {
47114711 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
......@@ -5370,9 +5370,9 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
53705370 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);
53715371 IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node, maybe_val);
53725372
5373 IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "MaybeThen");
5374 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "MaybeElse");
5375 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "MaybeEndIf");
5373 IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "OptionalThen");
5374 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "OptionalElse");
5375 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");
53765376
53775377 IrInstruction *is_comptime;
53785378 if (ir_should_inline(irb->exec, scope)) {
......@@ -7519,7 +7519,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
75197519 }
75207520 } else if (const_val_fits_in_num_lit(const_val, other_type)) {
75217521 return true;
7522 } else if (other_type->id == TypeTableEntryIdMaybe) {
7522 } else if (other_type->id == TypeTableEntryIdOptional) {
75237523 TypeTableEntry *child_type = other_type->data.maybe.child_type;
75247524 if (const_val_fits_in_num_lit(const_val, child_type)) {
75257525 return true;
......@@ -7663,7 +7663,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
76637663 return result;
76647664
76657665 // * and [*] can do a const-cast-only to ?* and ?[*], respectively
7666 if (expected_type->id == TypeTableEntryIdMaybe &&
7666 if (expected_type->id == TypeTableEntryIdOptional &&
76677667 expected_type->data.maybe.child_type->id == TypeTableEntryIdPointer &&
76687668 actual_type->id == TypeTableEntryIdPointer)
76697669 {
......@@ -7718,12 +7718,12 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
77187718 }
77197719
77207720 // maybe
7721 if (expected_type->id == TypeTableEntryIdMaybe && actual_type->id == TypeTableEntryIdMaybe) {
7721 if (expected_type->id == TypeTableEntryIdOptional && actual_type->id == TypeTableEntryIdOptional) {
77227722 ConstCastOnly child = types_match_const_cast_only(ira, expected_type->data.maybe.child_type, actual_type->data.maybe.child_type, source_node);
77237723 if (child.id != ConstCastResultIdOk) {
7724 result.id = ConstCastResultIdNullableChild;
7725 result.data.nullable_child = allocate_nonzero<ConstCastOnly>(1);
7726 *result.data.nullable_child = child;
7724 result.id = ConstCastResultIdOptionalChild;
7725 result.data.optional_child = allocate_nonzero<ConstCastOnly>(1);
7726 *result.data.optional_child = child;
77277727 }
77287728 return result;
77297729 }
......@@ -7925,7 +7925,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
79257925 }
79267926
79277927 // implicit conversion from ?T to ?U
7928 if (expected_type->id == TypeTableEntryIdMaybe && actual_type->id == TypeTableEntryIdMaybe) {
7928 if (expected_type->id == TypeTableEntryIdOptional && actual_type->id == TypeTableEntryIdOptional) {
79297929 ImplicitCastMatchResult res = ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type,
79307930 actual_type->data.maybe.child_type, value);
79317931 if (res != ImplicitCastMatchResultNo)
......@@ -7933,7 +7933,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
79337933 }
79347934
79357935 // implicit conversion from non maybe type to maybe type
7936 if (expected_type->id == TypeTableEntryIdMaybe) {
7936 if (expected_type->id == TypeTableEntryIdOptional) {
79377937 ImplicitCastMatchResult res = ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type,
79387938 actual_type, value);
79397939 if (res != ImplicitCastMatchResultNo)
......@@ -7941,7 +7941,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
79417941 }
79427942
79437943 // implicit conversion from null literal to maybe type
7944 if (expected_type->id == TypeTableEntryIdMaybe &&
7944 if (expected_type->id == TypeTableEntryIdOptional &&
79457945 actual_type->id == TypeTableEntryIdNull)
79467946 {
79477947 return ImplicitCastMatchResultYes;
......@@ -7963,7 +7963,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
79637963
79647964 // implicit conversion from T to U!?T
79657965 if (expected_type->id == TypeTableEntryIdErrorUnion &&
7966 expected_type->data.error_union.payload_type->id == TypeTableEntryIdMaybe &&
7966 expected_type->data.error_union.payload_type->id == TypeTableEntryIdOptional &&
79677967 ir_types_match_with_implicit_cast(ira,
79687968 expected_type->data.error_union.payload_type->data.maybe.child_type,
79697969 actual_type, value))
......@@ -8072,7 +8072,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
80728072 }
80738073
80748074 // implicit [N]T to ?[]const T
8075 if (expected_type->id == TypeTableEntryIdMaybe &&
8075 if (expected_type->id == TypeTableEntryIdOptional &&
80768076 is_slice(expected_type->data.maybe.child_type) &&
80778077 actual_type->id == TypeTableEntryIdArray)
80788078 {
......@@ -8552,13 +8552,13 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
85528552 continue;
85538553 }
85548554
8555 if (prev_type->id == TypeTableEntryIdMaybe &&
8555 if (prev_type->id == TypeTableEntryIdOptional &&
85568556 types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type, source_node).id == ConstCastResultIdOk)
85578557 {
85588558 continue;
85598559 }
85608560
8561 if (cur_type->id == TypeTableEntryIdMaybe &&
8561 if (cur_type->id == TypeTableEntryIdOptional &&
85628562 types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type, source_node).id == ConstCastResultIdOk)
85638563 {
85648564 prev_inst = cur_inst;
......@@ -8711,7 +8711,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
87118711 ir_add_error_node(ira, source_node,
87128712 buf_sprintf("unable to make maybe out of number literal"));
87138713 return ira->codegen->builtin_types.entry_invalid;
8714 } else if (prev_inst->value.type->id == TypeTableEntryIdMaybe) {
8714 } else if (prev_inst->value.type->id == TypeTableEntryIdOptional) {
87158715 return prev_inst->value.type;
87168716 } else {
87178717 return get_maybe_type(ira->codegen, prev_inst->value.type);
......@@ -9193,7 +9193,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
91939193}
91949194
91959195static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {
9196 assert(wanted_type->id == TypeTableEntryIdMaybe);
9196 assert(wanted_type->id == TypeTableEntryIdOptional);
91979197
91989198 if (instr_is_comptime(value)) {
91999199 TypeTableEntry *payload_type = wanted_type->data.maybe.child_type;
......@@ -9211,7 +9211,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
92119211 if (get_codegen_ptr_type(wanted_type) != nullptr) {
92129212 copy_const_val(&const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst);
92139213 } else {
9214 const_instruction->base.value.data.x_nullable = val;
9214 const_instruction->base.value.data.x_optional = val;
92159215 }
92169216 const_instruction->base.value.type = wanted_type;
92179217 return &const_instruction->base;
......@@ -9219,7 +9219,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
92199219
92209220 IrInstruction *result = ir_build_maybe_wrap(&ira->new_irb, source_instr->scope, source_instr->source_node, value);
92219221 result->value.type = wanted_type;
9222 result->value.data.rh_maybe = RuntimeHintMaybeNonNull;
9222 result->value.data.rh_maybe = RuntimeHintOptionalNonNull;
92239223 ir_add_alloca(ira, result, wanted_type);
92249224 return result;
92259225}
......@@ -9361,7 +9361,7 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
93619361}
93629362
93639363static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {
9364 assert(wanted_type->id == TypeTableEntryIdMaybe);
9364 assert(wanted_type->id == TypeTableEntryIdOptional);
93659365 assert(instr_is_comptime(value));
93669366
93679367 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
......@@ -9373,7 +9373,7 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
93739373 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
93749374 const_instruction->base.value.data.x_ptr.data.hard_coded_addr.addr = 0;
93759375 } else {
9376 const_instruction->base.value.data.x_nullable = nullptr;
9376 const_instruction->base.value.data.x_optional = nullptr;
93779377 }
93789378 const_instruction->base.value.type = wanted_type;
93799379 return &const_instruction->base;
......@@ -9992,7 +9992,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
99929992 }
99939993
99949994 // explicit cast from [N]T to ?[]const N
9995 if (wanted_type->id == TypeTableEntryIdMaybe &&
9995 if (wanted_type->id == TypeTableEntryIdOptional &&
99969996 is_slice(wanted_type->data.maybe.child_type) &&
99979997 actual_type->id == TypeTableEntryIdArray)
99989998 {
......@@ -10091,7 +10091,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1009110091
1009210092 // explicit cast from T to ?T
1009310093 // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism
10094 if (wanted_type->id == TypeTableEntryIdMaybe) {
10094 if (wanted_type->id == TypeTableEntryIdOptional) {
1009510095 TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type;
1009610096 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk) {
1009710097 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
......@@ -10120,7 +10120,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1012010120 }
1012110121
1012210122 // explicit cast from null literal to maybe type
10123 if (wanted_type->id == TypeTableEntryIdMaybe &&
10123 if (wanted_type->id == TypeTableEntryIdOptional &&
1012410124 actual_type->id == TypeTableEntryIdNull)
1012510125 {
1012610126 return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);
......@@ -10173,8 +10173,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1017310173
1017410174 // explicit cast from T to E!?T
1017510175 if (wanted_type->id == TypeTableEntryIdErrorUnion &&
10176 wanted_type->data.error_union.payload_type->id == TypeTableEntryIdMaybe &&
10177 actual_type->id != TypeTableEntryIdMaybe)
10176 wanted_type->data.error_union.payload_type->id == TypeTableEntryIdOptional &&
10177 actual_type->id != TypeTableEntryIdOptional)
1017810178 {
1017910179 TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;
1018010180 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk ||
......@@ -10737,13 +10737,13 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
1073710737 }
1073810738}
1073910739
10740static bool nullable_value_is_null(ConstExprValue *val) {
10740static bool optional_value_is_null(ConstExprValue *val) {
1074110741 assert(val->special == ConstValSpecialStatic);
1074210742 if (get_codegen_ptr_type(val->type) != nullptr) {
1074310743 return val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
1074410744 val->data.x_ptr.data.hard_coded_addr.addr == 0;
1074510745 } else {
10746 return val->data.x_nullable == nullptr;
10746 return val->data.x_optional == nullptr;
1074710747 }
1074810748}
1074910749
......@@ -10755,8 +10755,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1075510755 IrBinOp op_id = bin_op_instruction->op_id;
1075610756 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
1075710757 if (is_equality_cmp &&
10758 ((op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdMaybe) ||
10759 (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdMaybe) ||
10758 ((op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdOptional) ||
10759 (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdOptional) ||
1076010760 (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull)))
1076110761 {
1076210762 if (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull) {
......@@ -10776,7 +10776,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1077610776 ConstExprValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);
1077710777 if (!maybe_val)
1077810778 return ira->codegen->builtin_types.entry_invalid;
10779 bool is_null = nullable_value_is_null(maybe_val);
10779 bool is_null = optional_value_is_null(maybe_val);
1078010780 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
1078110781 out_val->data.x_bool = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
1078210782 return ira->codegen->builtin_types.entry_bool;
......@@ -10925,7 +10925,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
1092510925 case TypeTableEntryIdStruct:
1092610926 case TypeTableEntryIdUndefined:
1092710927 case TypeTableEntryIdNull:
10928 case TypeTableEntryIdMaybe:
10928 case TypeTableEntryIdOptional:
1092910929 case TypeTableEntryIdErrorUnion:
1093010930 case TypeTableEntryIdUnion:
1093110931 ir_add_error_node(ira, source_node,
......@@ -11998,7 +11998,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
1199811998 case TypeTableEntryIdComptimeInt:
1199911999 case TypeTableEntryIdUndefined:
1200012000 case TypeTableEntryIdNull:
12001 case TypeTableEntryIdMaybe:
12001 case TypeTableEntryIdOptional:
1200212002 case TypeTableEntryIdErrorUnion:
1200312003 case TypeTableEntryIdErrorSet:
1200412004 case TypeTableEntryIdNamespace:
......@@ -12022,7 +12022,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
1202212022 case TypeTableEntryIdComptimeInt:
1202312023 case TypeTableEntryIdUndefined:
1202412024 case TypeTableEntryIdNull:
12025 case TypeTableEntryIdMaybe:
12025 case TypeTableEntryIdOptional:
1202612026 case TypeTableEntryIdErrorUnion:
1202712027 case TypeTableEntryIdErrorSet:
1202812028 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));
......@@ -12049,24 +12049,24 @@ static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) {
1204912049static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
1205012050 IrInstructionErrorReturnTrace *instruction)
1205112051{
12052 if (instruction->nullable == IrInstructionErrorReturnTrace::Null) {
12052 if (instruction->optional == IrInstructionErrorReturnTrace::Null) {
1205312053 TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen);
12054 TypeTableEntry *nullable_type = get_maybe_type(ira->codegen, ptr_to_stack_trace_type);
12054 TypeTableEntry *optional_type = get_maybe_type(ira->codegen, ptr_to_stack_trace_type);
1205512055 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {
1205612056 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
12057 assert(get_codegen_ptr_type(nullable_type) != nullptr);
12057 assert(get_codegen_ptr_type(optional_type) != nullptr);
1205812058 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
1205912059 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
12060 return nullable_type;
12060 return optional_type;
1206112061 }
1206212062 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,
12063 instruction->base.source_node, instruction->nullable);
12063 instruction->base.source_node, instruction->optional);
1206412064 ir_link_new_instruction(new_instruction, &instruction->base);
12065 return nullable_type;
12065 return optional_type;
1206612066 } else {
1206712067 assert(ira->codegen->have_err_ret_tracing);
1206812068 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,
12069 instruction->base.source_node, instruction->nullable);
12069 instruction->base.source_node, instruction->optional);
1207012070 ir_link_new_instruction(new_instruction, &instruction->base);
1207112071 return get_ptr_to_stack_trace_type(ira->codegen);
1207212072 }
......@@ -12998,7 +12998,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
1299812998 case TypeTableEntryIdComptimeInt:
1299912999 case TypeTableEntryIdUndefined:
1300013000 case TypeTableEntryIdNull:
13001 case TypeTableEntryIdMaybe:
13001 case TypeTableEntryIdOptional:
1300213002 case TypeTableEntryIdErrorUnion:
1300313003 case TypeTableEntryIdErrorSet:
1300413004 case TypeTableEntryIdEnum:
......@@ -13017,7 +13017,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
1301713017 case TypeTableEntryIdUnreachable:
1301813018 case TypeTableEntryIdOpaque:
1301913019 ir_add_error_node(ira, un_op_instruction->base.source_node,
13020 buf_sprintf("type '%s' not nullable", buf_ptr(&type_entry->name)));
13020 buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name)));
1302113021 return ira->codegen->builtin_types.entry_invalid;
1302213022 }
1302313023 zig_unreachable();
......@@ -13109,7 +13109,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio
1310913109 return ir_analyze_negation(ira, un_op_instruction);
1311013110 case IrUnOpDereference:
1311113111 return ir_analyze_dereference(ira, un_op_instruction);
13112 case IrUnOpMaybe:
13112 case IrUnOpOptional:
1311313113 return ir_analyze_maybe(ira, un_op_instruction);
1311413114 }
1311513115 zig_unreachable();
......@@ -14155,7 +14155,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
1415514155 buf_ptr(&child_type->name), buf_ptr(field_name)));
1415614156 return ira->codegen->builtin_types.entry_invalid;
1415714157 }
14158 } else if (child_type->id == TypeTableEntryIdMaybe) {
14158 } else if (child_type->id == TypeTableEntryIdOptional) {
1415914159 if (buf_eql_str(field_name, "Child")) {
1416014160 bool ptr_is_const = true;
1416114161 bool ptr_is_volatile = false;
......@@ -14339,7 +14339,7 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
1433914339 case TypeTableEntryIdPointer:
1434014340 case TypeTableEntryIdArray:
1434114341 case TypeTableEntryIdStruct:
14342 case TypeTableEntryIdMaybe:
14342 case TypeTableEntryIdOptional:
1434314343 case TypeTableEntryIdErrorUnion:
1434414344 case TypeTableEntryIdErrorSet:
1434514345 case TypeTableEntryIdEnum:
......@@ -14607,7 +14607,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1460714607 case TypeTableEntryIdStruct:
1460814608 case TypeTableEntryIdComptimeFloat:
1460914609 case TypeTableEntryIdComptimeInt:
14610 case TypeTableEntryIdMaybe:
14610 case TypeTableEntryIdOptional:
1461114611 case TypeTableEntryIdErrorUnion:
1461214612 case TypeTableEntryIdErrorSet:
1461314613 case TypeTableEntryIdEnum:
......@@ -14715,7 +14715,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
1471514715 case TypeTableEntryIdStruct:
1471614716 case TypeTableEntryIdComptimeFloat:
1471714717 case TypeTableEntryIdComptimeInt:
14718 case TypeTableEntryIdMaybe:
14718 case TypeTableEntryIdOptional:
1471914719 case TypeTableEntryIdErrorUnion:
1472014720 case TypeTableEntryIdErrorSet:
1472114721 case TypeTableEntryIdEnum:
......@@ -14786,7 +14786,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
1478614786 case TypeTableEntryIdPointer:
1478714787 case TypeTableEntryIdArray:
1478814788 case TypeTableEntryIdStruct:
14789 case TypeTableEntryIdMaybe:
14789 case TypeTableEntryIdOptional:
1479014790 case TypeTableEntryIdErrorUnion:
1479114791 case TypeTableEntryIdErrorSet:
1479214792 case TypeTableEntryIdEnum:
......@@ -14810,14 +14810,14 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
1481014810
1481114811 TypeTableEntry *type_entry = value->value.type;
1481214812
14813 if (type_entry->id == TypeTableEntryIdMaybe) {
14813 if (type_entry->id == TypeTableEntryIdOptional) {
1481414814 if (instr_is_comptime(value)) {
1481514815 ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad);
1481614816 if (!maybe_val)
1481714817 return ira->codegen->builtin_types.entry_invalid;
1481814818
1481914819 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
14820 out_val->data.x_bool = !nullable_value_is_null(maybe_val);
14820 out_val->data.x_bool = !optional_value_is_null(maybe_val);
1482114821 return ira->codegen->builtin_types.entry_bool;
1482214822 }
1482314823
......@@ -14835,7 +14835,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
1483514835}
1483614836
1483714837static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
14838 IrInstructionUnwrapMaybe *unwrap_maybe_instruction)
14838 IrInstructionUnwrapOptional *unwrap_maybe_instruction)
1483914839{
1484014840 IrInstruction *value = unwrap_maybe_instruction->value->other;
1484114841 if (type_is_invalid(value->value.type))
......@@ -14863,9 +14863,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1486314863 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile);
1486414864 ir_link_new_instruction(result_instr, &unwrap_maybe_instruction->base);
1486514865 return result_instr->value.type;
14866 } else if (type_entry->id != TypeTableEntryIdMaybe) {
14866 } else if (type_entry->id != TypeTableEntryIdOptional) {
1486714867 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
14868 buf_sprintf("expected nullable type, found '%s'", buf_ptr(&type_entry->name)));
14868 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
1486914869 return ira->codegen->builtin_types.entry_invalid;
1487014870 }
1487114871 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
......@@ -14881,7 +14881,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1488114881 ConstExprValue *maybe_val = const_ptr_pointee(ira->codegen, val);
1488214882
1488314883 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
14884 if (nullable_value_is_null(maybe_val)) {
14884 if (optional_value_is_null(maybe_val)) {
1488514885 ir_add_error(ira, &unwrap_maybe_instruction->base, buf_sprintf("unable to unwrap null"));
1488614886 return ira->codegen->builtin_types.entry_invalid;
1488714887 }
......@@ -14891,7 +14891,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1489114891 if (type_is_codegen_pointer(child_type)) {
1489214892 out_val->data.x_ptr.data.ref.pointee = maybe_val;
1489314893 } else {
14894 out_val->data.x_ptr.data.ref.pointee = maybe_val->data.x_nullable;
14894 out_val->data.x_ptr.data.ref.pointee = maybe_val->data.x_optional;
1489514895 }
1489614896 return result_type;
1489714897 }
......@@ -15216,7 +15216,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1521615216 case TypeTableEntryIdStruct:
1521715217 case TypeTableEntryIdUndefined:
1521815218 case TypeTableEntryIdNull:
15219 case TypeTableEntryIdMaybe:
15219 case TypeTableEntryIdOptional:
1522015220 case TypeTableEntryIdBlock:
1522115221 case TypeTableEntryIdBoundFn:
1522215222 case TypeTableEntryIdArgTuple:
......@@ -15737,7 +15737,7 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
1573715737 case TypeTableEntryIdComptimeInt:
1573815738 case TypeTableEntryIdUndefined:
1573915739 case TypeTableEntryIdNull:
15740 case TypeTableEntryIdMaybe:
15740 case TypeTableEntryIdOptional:
1574115741 case TypeTableEntryIdErrorUnion:
1574215742 case TypeTableEntryIdErrorSet:
1574315743 case TypeTableEntryIdUnion:
......@@ -16255,11 +16255,11 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
1625516255 0, 0);
1625616256 fn_def_fields[6].type = get_maybe_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
1625716257 if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) {
16258 fn_def_fields[6].data.x_nullable = create_const_vals(1);
16258 fn_def_fields[6].data.x_optional = create_const_vals(1);
1625916259 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name);
16260 init_const_slice(ira->codegen, fn_def_fields[6].data.x_nullable, lib_name, 0, buf_len(fn_node->lib_name), true);
16260 init_const_slice(ira->codegen, fn_def_fields[6].data.x_optional, lib_name, 0, buf_len(fn_node->lib_name), true);
1626116261 } else {
16262 fn_def_fields[6].data.x_nullable = nullptr;
16262 fn_def_fields[6].data.x_optional = nullptr;
1626316263 }
1626416264 // return_type: type
1626516265 ensure_field_index(fn_def_val->type, "return_type", 7);
......@@ -16507,11 +16507,11 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
1650716507
1650816508 break;
1650916509 }
16510 case TypeTableEntryIdMaybe:
16510 case TypeTableEntryIdOptional:
1651116511 {
1651216512 result = create_const_vals(1);
1651316513 result->special = ConstValSpecialStatic;
16514 result->type = ir_type_info_get_type(ira, "Nullable");
16514 result->type = ir_type_info_get_type(ira, "Optional");
1651516515
1651616516 ConstExprValue *fields = create_const_vals(1);
1651716517 result->data.x_struct.fields = fields;
......@@ -16725,10 +16725,10 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
1672516725 inner_fields[1].type = get_maybe_type(ira->codegen, type_info_enum_field_type);
1672616726
1672716727 if (fields[1].data.x_type == ira->codegen->builtin_types.entry_undef) {
16728 inner_fields[1].data.x_nullable = nullptr;
16728 inner_fields[1].data.x_optional = nullptr;
1672916729 } else {
16730 inner_fields[1].data.x_nullable = create_const_vals(1);
16731 make_enum_field_val(inner_fields[1].data.x_nullable, union_field->enum_field, type_info_enum_field_type);
16730 inner_fields[1].data.x_optional = create_const_vals(1);
16731 make_enum_field_val(inner_fields[1].data.x_optional, union_field->enum_field, type_info_enum_field_type);
1673216732 }
1673316733
1673416734 inner_fields[2].special = ConstValSpecialStatic;
......@@ -16796,13 +16796,13 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
1679616796 inner_fields[1].type = get_maybe_type(ira->codegen, ira->codegen->builtin_types.entry_usize);
1679716797
1679816798 if (!type_has_bits(struct_field->type_entry)) {
16799 inner_fields[1].data.x_nullable = nullptr;
16799 inner_fields[1].data.x_optional = nullptr;
1680016800 } else {
1680116801 size_t byte_offset = LLVMOffsetOfElement(ira->codegen->target_data_ref, type_entry->type_ref, struct_field->gen_index);
16802 inner_fields[1].data.x_nullable = create_const_vals(1);
16803 inner_fields[1].data.x_nullable->special = ConstValSpecialStatic;
16804 inner_fields[1].data.x_nullable->type = ira->codegen->builtin_types.entry_usize;
16805 bigint_init_unsigned(&inner_fields[1].data.x_nullable->data.x_bigint, byte_offset);
16802 inner_fields[1].data.x_optional = create_const_vals(1);
16803 inner_fields[1].data.x_optional->special = ConstValSpecialStatic;
16804 inner_fields[1].data.x_optional->type = ira->codegen->builtin_types.entry_usize;
16805 bigint_init_unsigned(&inner_fields[1].data.x_optional->data.x_bigint, byte_offset);
1680616806 }
1680716807
1680816808 inner_fields[2].special = ConstValSpecialStatic;
......@@ -18027,7 +18027,7 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc
1802718027 case TypeTableEntryIdPromise:
1802818028 case TypeTableEntryIdArray:
1802918029 case TypeTableEntryIdStruct:
18030 case TypeTableEntryIdMaybe:
18030 case TypeTableEntryIdOptional:
1803118031 case TypeTableEntryIdErrorUnion:
1803218032 case TypeTableEntryIdErrorSet:
1803318033 case TypeTableEntryIdEnum:
......@@ -18591,7 +18591,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
1859118591 old_align_bytes = fn_type_id.alignment;
1859218592 fn_type_id.alignment = align_bytes;
1859318593 result_type = get_fn_type(ira->codegen, &fn_type_id);
18594 } else if (target_type->id == TypeTableEntryIdMaybe &&
18594 } else if (target_type->id == TypeTableEntryIdOptional &&
1859518595 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
1859618596 {
1859718597 TypeTableEntry *ptr_type = target_type->data.maybe.child_type;
......@@ -18599,7 +18599,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
1859918599 TypeTableEntry *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
1860018600
1860118601 result_type = get_maybe_type(ira->codegen, better_ptr_type);
18602 } else if (target_type->id == TypeTableEntryIdMaybe &&
18602 } else if (target_type->id == TypeTableEntryIdOptional &&
1860318603 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)
1860418604 {
1860518605 FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id;
......@@ -18757,7 +18757,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
1875718757 return;
1875818758 case TypeTableEntryIdStruct:
1875918759 zig_panic("TODO buf_write_value_bytes struct type");
18760 case TypeTableEntryIdMaybe:
18760 case TypeTableEntryIdOptional:
1876118761 zig_panic("TODO buf_write_value_bytes maybe type");
1876218762 case TypeTableEntryIdErrorUnion:
1876318763 zig_panic("TODO buf_write_value_bytes error union");
......@@ -18815,7 +18815,7 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
1881518815 zig_panic("TODO buf_read_value_bytes array type");
1881618816 case TypeTableEntryIdStruct:
1881718817 zig_panic("TODO buf_read_value_bytes struct type");
18818 case TypeTableEntryIdMaybe:
18818 case TypeTableEntryIdOptional:
1881918819 zig_panic("TODO buf_read_value_bytes maybe type");
1882018820 case TypeTableEntryIdErrorUnion:
1882118821 zig_panic("TODO buf_read_value_bytes error union");
......@@ -19731,7 +19731,7 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
1973119731 case IrInstructionIdUnionInit:
1973219732 case IrInstructionIdStructFieldPtr:
1973319733 case IrInstructionIdUnionFieldPtr:
19734 case IrInstructionIdMaybeWrap:
19734 case IrInstructionIdOptionalWrap:
1973519735 case IrInstructionIdErrWrapCode:
1973619736 case IrInstructionIdErrWrapPayload:
1973719737 case IrInstructionIdCast:
......@@ -19791,8 +19791,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
1979119791 return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction);
1979219792 case IrInstructionIdTestNonNull:
1979319793 return ir_analyze_instruction_test_non_null(ira, (IrInstructionTestNonNull *)instruction);
19794 case IrInstructionIdUnwrapMaybe:
19795 return ir_analyze_instruction_unwrap_maybe(ira, (IrInstructionUnwrapMaybe *)instruction);
19794 case IrInstructionIdUnwrapOptional:
19795 return ir_analyze_instruction_unwrap_maybe(ira, (IrInstructionUnwrapOptional *)instruction);
1979619796 case IrInstructionIdClz:
1979719797 return ir_analyze_instruction_clz(ira, (IrInstructionClz *)instruction);
1979819798 case IrInstructionIdCtz:
......@@ -20128,7 +20128,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2012820128 case IrInstructionIdSliceType:
2012920129 case IrInstructionIdSizeOf:
2013020130 case IrInstructionIdTestNonNull:
20131 case IrInstructionIdUnwrapMaybe:
20131 case IrInstructionIdUnwrapOptional:
2013220132 case IrInstructionIdClz:
2013320133 case IrInstructionIdCtz:
2013420134 case IrInstructionIdSwitchVar:
......@@ -20150,7 +20150,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2015020150 case IrInstructionIdFrameAddress:
2015120151 case IrInstructionIdTestErr:
2015220152 case IrInstructionIdUnwrapErrCode:
20153 case IrInstructionIdMaybeWrap:
20153 case IrInstructionIdOptionalWrap:
2015420154 case IrInstructionIdErrWrapCode:
2015520155 case IrInstructionIdErrWrapPayload:
2015620156 case IrInstructionIdFnProto:
src/ir_print.cpp+8-8
......@@ -148,7 +148,7 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {
148148 return "-%";
149149 case IrUnOpDereference:
150150 return "*";
151 case IrUnOpMaybe:
151 case IrUnOpOptional:
152152 return "?";
153153 }
154154 zig_unreachable();
......@@ -481,7 +481,7 @@ static void ir_print_test_null(IrPrint *irp, IrInstructionTestNonNull *instructi
481481 fprintf(irp->f, " != null");
482482}
483483
484static void ir_print_unwrap_maybe(IrPrint *irp, IrInstructionUnwrapMaybe *instruction) {
484static void ir_print_unwrap_maybe(IrPrint *irp, IrInstructionUnwrapOptional *instruction) {
485485 fprintf(irp->f, "&??*");
486486 ir_print_other_instruction(irp, instruction->value);
487487 if (!instruction->safety_check_on) {
......@@ -777,7 +777,7 @@ static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayl
777777 }
778778}
779779
780static void ir_print_maybe_wrap(IrPrint *irp, IrInstructionMaybeWrap *instruction) {
780static void ir_print_maybe_wrap(IrPrint *irp, IrInstructionOptionalWrap *instruction) {
781781 fprintf(irp->f, "@maybeWrap(");
782782 ir_print_other_instruction(irp, instruction->value);
783783 fprintf(irp->f, ")");
......@@ -1032,7 +1032,7 @@ static void ir_print_export(IrPrint *irp, IrInstructionExport *instruction) {
10321032
10331033static void ir_print_error_return_trace(IrPrint *irp, IrInstructionErrorReturnTrace *instruction) {
10341034 fprintf(irp->f, "@errorReturnTrace(");
1035 switch (instruction->nullable) {
1035 switch (instruction->optional) {
10361036 case IrInstructionErrorReturnTrace::Null:
10371037 fprintf(irp->f, "Null");
10381038 break;
......@@ -1348,8 +1348,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
13481348 case IrInstructionIdTestNonNull:
13491349 ir_print_test_null(irp, (IrInstructionTestNonNull *)instruction);
13501350 break;
1351 case IrInstructionIdUnwrapMaybe:
1352 ir_print_unwrap_maybe(irp, (IrInstructionUnwrapMaybe *)instruction);
1351 case IrInstructionIdUnwrapOptional:
1352 ir_print_unwrap_maybe(irp, (IrInstructionUnwrapOptional *)instruction);
13531353 break;
13541354 case IrInstructionIdCtz:
13551355 ir_print_ctz(irp, (IrInstructionCtz *)instruction);
......@@ -1465,8 +1465,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
14651465 case IrInstructionIdUnwrapErrPayload:
14661466 ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);
14671467 break;
1468 case IrInstructionIdMaybeWrap:
1469 ir_print_maybe_wrap(irp, (IrInstructionMaybeWrap *)instruction);
1468 case IrInstructionIdOptionalWrap:
1469 ir_print_maybe_wrap(irp, (IrInstructionOptionalWrap *)instruction);
14701470 break;
14711471 case IrInstructionIdErrWrapCode:
14721472 ir_print_err_wrap_code(irp, (IrInstructionErrWrapCode *)instruction);
src/parser.cpp+14-7
......@@ -1046,12 +1046,11 @@ static AstNode *ast_parse_fn_proto_partial(ParseContext *pc, size_t *token_index
10461046}
10471047
10481048/*
1049SuffixOpExpression = ("async" option("<" SuffixOpExpression ">") SuffixOpExpression FnCallExpression) | PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | PtrDerefExpression | SliceExpression)
1049SuffixOpExpression = ("async" option("&lt;" SuffixOpExpression "&gt;") SuffixOpExpression FnCallExpression) | PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression | ".*" | ".?")
10501050FnCallExpression : token(LParen) list(Expression, token(Comma)) token(RParen)
10511051ArrayAccessExpression : token(LBracket) Expression token(RBracket)
10521052SliceExpression = "[" Expression ".." option(Expression) "]"
10531053FieldAccessExpression : token(Dot) token(Symbol)
1054PtrDerefExpression = ".*"
10551054StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression
10561055*/
10571056static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
......@@ -1148,6 +1147,14 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index,
11481147 AstNode *node = ast_create_node(pc, NodeTypePtrDeref, first_token);
11491148 node->data.ptr_deref_expr.target = primary_expr;
11501149
1150 primary_expr = node;
1151 } else if (token->id == TokenIdQuestion) {
1152 *token_index += 1;
1153
1154 AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, first_token);
1155 node->data.prefix_op_expr.prefix_op = PrefixOpUnwrapOptional;
1156 node->data.prefix_op_expr.primary_expr = primary_expr;
1157
11511158 primary_expr = node;
11521159 } else {
11531160 ast_invalid_token_error(pc, token);
......@@ -1165,8 +1172,8 @@ static PrefixOp tok_to_prefix_op(Token *token) {
11651172 case TokenIdDash: return PrefixOpNegation;
11661173 case TokenIdMinusPercent: return PrefixOpNegationWrap;
11671174 case TokenIdTilde: return PrefixOpBinNot;
1168 case TokenIdMaybe: return PrefixOpMaybe;
1169 case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;
1175 case TokenIdQuestion: return PrefixOpOptional;
1176 case TokenIdDoubleQuestion: return PrefixOpUnwrapOptional;
11701177 case TokenIdAmpersand: return PrefixOpAddrOf;
11711178 default: return PrefixOpInvalid;
11721179 }
......@@ -2304,8 +2311,8 @@ static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool ma
23042311}
23052312
23062313/*
2307UnwrapExpression : BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpression
2308UnwrapMaybe : "??" BoolOrExpression
2314UnwrapExpression : BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression
2315UnwrapOptional : "??" BoolOrExpression
23092316UnwrapError = "catch" option("|" Symbol "|") Expression
23102317*/
23112318static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
......@@ -2322,7 +2329,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, boo
23222329
23232330 AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token);
23242331 node->data.bin_op_expr.op1 = lhs;
2325 node->data.bin_op_expr.bin_op = BinOpTypeUnwrapMaybe;
2332 node->data.bin_op_expr.bin_op = BinOpTypeUnwrapOptional;
23262333 node->data.bin_op_expr.op2 = rhs;
23272334
23282335 return node;
src/tokenizer.cpp+2-8
......@@ -625,7 +625,7 @@ void tokenize(Buf *buf, Tokenization *out) {
625625 t.state = TokenizeStateSawDot;
626626 break;
627627 case '?':
628 begin_token(&t, TokenIdMaybe);
628 begin_token(&t, TokenIdQuestion);
629629 t.state = TokenizeStateSawQuestionMark;
630630 break;
631631 default:
......@@ -639,11 +639,6 @@ void tokenize(Buf *buf, Tokenization *out) {
639639 end_token(&t);
640640 t.state = TokenizeStateStart;
641641 break;
642 case '=':
643 set_token_id(&t, t.cur_tok, TokenIdMaybeAssign);
644 end_token(&t);
645 t.state = TokenizeStateStart;
646 break;
647642 default:
648643 t.pos -= 1;
649644 end_token(&t);
......@@ -1609,8 +1604,7 @@ const char * token_name(TokenId id) {
16091604 case TokenIdLBrace: return "{";
16101605 case TokenIdLBracket: return "[";
16111606 case TokenIdLParen: return "(";
1612 case TokenIdMaybe: return "?";
1613 case TokenIdMaybeAssign: return "?=";
1607 case TokenIdQuestion: return "?";
16141608 case TokenIdMinusEq: return "-=";
16151609 case TokenIdMinusPercent: return "-%";
16161610 case TokenIdMinusPercentEq: return "-%=";
src/tokenizer.hpp+1-2
......@@ -100,8 +100,7 @@ enum TokenId {
100100 TokenIdLBrace,
101101 TokenIdLBracket,
102102 TokenIdLParen,
103 TokenIdMaybe,
104 TokenIdMaybeAssign,
103 TokenIdQuestion,
105104 TokenIdMinusEq,
106105 TokenIdMinusPercent,
107106 TokenIdMinusPercentEq,
src/translate_c.cpp+7-7
......@@ -382,7 +382,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r
382382 fn_def->data.fn_def.fn_proto = fn_proto;
383383 fn_proto->data.fn_proto.fn_def_node = fn_def;
384384
385 AstNode *unwrap_node = trans_create_node_prefix_op(c, PrefixOpUnwrapMaybe, ref_node);
385 AstNode *unwrap_node = trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, ref_node);
386386 AstNode *fn_call_node = trans_create_node(c, NodeTypeFnCallExpr);
387387 fn_call_node->data.fn_call_expr.fn_ref_expr = unwrap_node;
388388
......@@ -410,7 +410,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r
410410}
411411
412412static AstNode *trans_create_node_unwrap_null(Context *c, AstNode *child) {
413 return trans_create_node_prefix_op(c, PrefixOpUnwrapMaybe, child);
413 return trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, child);
414414}
415415
416416static AstNode *get_global(Context *c, Buf *name) {
......@@ -879,14 +879,14 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou
879879 }
880880
881881 if (qual_type_child_is_fn_proto(child_qt)) {
882 return trans_create_node_prefix_op(c, PrefixOpMaybe, child_node);
882 return trans_create_node_prefix_op(c, PrefixOpOptional, child_node);
883883 }
884884
885885 PtrLen ptr_len = type_is_opaque(c, child_qt.getTypePtr(), source_loc) ? PtrLenSingle : PtrLenUnknown;
886886
887887 AstNode *pointer_node = trans_create_node_ptr_type(c, child_qt.isConstQualified(),
888888 child_qt.isVolatileQualified(), child_node, ptr_len);
889 return trans_create_node_prefix_op(c, PrefixOpMaybe, pointer_node);
889 return trans_create_node_prefix_op(c, PrefixOpOptional, pointer_node);
890890 }
891891 case Type::Typedef:
892892 {
......@@ -1963,7 +1963,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
19631963 bool is_fn_ptr = qual_type_is_fn_ptr(stmt->getSubExpr()->getType());
19641964 if (is_fn_ptr)
19651965 return value_node;
1966 AstNode *unwrapped = trans_create_node_prefix_op(c, PrefixOpUnwrapMaybe, value_node);
1966 AstNode *unwrapped = trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, value_node);
19671967 return trans_create_node_ptr_deref(c, unwrapped);
19681968 }
19691969 case UO_Plus:
......@@ -2587,7 +2587,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *
25872587 }
25882588 }
25892589 if (callee_node == nullptr) {
2590 callee_node = trans_create_node_prefix_op(c, PrefixOpUnwrapMaybe, callee_raw_node);
2590 callee_node = trans_create_node_prefix_op(c, PrefixOpUnwrapOptional, callee_raw_node);
25912591 }
25922592 } else {
25932593 callee_node = callee_raw_node;
......@@ -4301,7 +4301,7 @@ static AstNode *trans_lookup_ast_maybe_fn(Context *c, AstNode *ref_node) {
43014301 return nullptr;
43024302 if (prefix_node->type != NodeTypePrefixOpExpr)
43034303 return nullptr;
4304 if (prefix_node->data.prefix_op_expr.prefix_op != PrefixOpMaybe)
4304 if (prefix_node->data.prefix_op_expr.prefix_op != PrefixOpOptional)
43054305 return nullptr;
43064306
43074307 AstNode *fn_proto_node = prefix_node->data.prefix_op_expr.primary_expr;
std/array_list.zig+1-1
......@@ -258,7 +258,7 @@ test "iterator ArrayList test" {
258258 }
259259
260260 it.reset();
261 assert(??it.next() == 1);
261 assert(it.next().? == 1);
262262}
263263
264264test "insert ArrayList test" {
std/buf_map.zig+3-3
......@@ -72,15 +72,15 @@ test "BufMap" {
7272 defer bufmap.deinit();
7373
7474 try bufmap.set("x", "1");
75 assert(mem.eql(u8, ??bufmap.get("x"), "1"));
75 assert(mem.eql(u8, bufmap.get("x").?, "1"));
7676 assert(1 == bufmap.count());
7777
7878 try bufmap.set("x", "2");
79 assert(mem.eql(u8, ??bufmap.get("x"), "2"));
79 assert(mem.eql(u8, bufmap.get("x").?, "2"));
8080 assert(1 == bufmap.count());
8181
8282 try bufmap.set("x", "3");
83 assert(mem.eql(u8, ??bufmap.get("x"), "3"));
83 assert(mem.eql(u8, bufmap.get("x").?, "3"));
8484 assert(1 == bufmap.count());
8585
8686 bufmap.delete("x");
std/event.zig+2-2
......@@ -40,9 +40,9 @@ pub const TcpServer = struct {
4040 self.listen_address = std.net.Address.initPosix(try std.os.posixGetSockName(self.sockfd));
4141
4242 self.accept_coro = try async<self.loop.allocator> TcpServer.handler(self);
43 errdefer cancel ??self.accept_coro;
43 errdefer cancel self.accept_coro.?;
4444
45 try self.loop.addFd(self.sockfd, ??self.accept_coro);
45 try self.loop.addFd(self.sockfd, self.accept_coro.?);
4646 errdefer self.loop.removeFd(self.sockfd);
4747 }
4848
std/fmt/index.zig+3-3
......@@ -111,7 +111,7 @@ pub fn formatType(
111111 builtin.TypeId.Bool => {
112112 return output(context, if (value) "true" else "false");
113113 },
114 builtin.TypeId.Nullable => {
114 builtin.TypeId.Optional => {
115115 if (value) |payload| {
116116 return formatType(payload, fmt, context, Errors, output);
117117 } else {
......@@ -819,11 +819,11 @@ test "parse unsigned comptime" {
819819test "fmt.format" {
820820 {
821821 const value: ?i32 = 1234;
822 try testFmt("nullable: 1234\n", "nullable: {}\n", value);
822 try testFmt("optional: 1234\n", "optional: {}\n", value);
823823 }
824824 {
825825 const value: ?i32 = null;
826 try testFmt("nullable: null\n", "nullable: {}\n", value);
826 try testFmt("optional: null\n", "optional: {}\n", value);
827827 }
828828 {
829829 const value: error!i32 = 1234;
std/hash_map.zig+4-4
......@@ -265,11 +265,11 @@ test "basic hash map usage" {
265265 assert((map.put(4, 44) catch unreachable) == null);
266266 assert((map.put(5, 55) catch unreachable) == null);
267267
268 assert(??(map.put(5, 66) catch unreachable) == 55);
269 assert(??(map.put(5, 55) catch unreachable) == 66);
268 assert((map.put(5, 66) catch unreachable).? == 55);
269 assert((map.put(5, 55) catch unreachable).? == 66);
270270
271271 assert(map.contains(2));
272 assert((??map.get(2)).value == 22);
272 assert(map.get(2).?.value == 22);
273273 _ = map.remove(2);
274274 assert(map.remove(2) == null);
275275 assert(map.get(2) == null);
......@@ -317,7 +317,7 @@ test "iterator hash map" {
317317 }
318318
319319 it.reset();
320 var entry = ??it.next();
320 var entry = it.next().?;
321321 assert(entry.key == keys[0]);
322322 assert(entry.value == values[0]);
323323}
std/heap.zig+2-2
......@@ -142,7 +142,7 @@ pub const DirectAllocator = struct {
142142 const root_addr = @intToPtr(*align(1) usize, old_record_addr).*;
143143 const old_ptr = @intToPtr(*c_void, root_addr);
144144 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) ?? blk: {
146146 if (new_size > old_mem.len) return error.OutOfMemory;
147147 const new_record_addr = old_record_addr - new_size + old_mem.len;
148148 @intToPtr(*align(1) usize, new_record_addr).* = root_addr;
......@@ -171,7 +171,7 @@ pub const DirectAllocator = struct {
171171 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;
172172 const root_addr = @intToPtr(*align(1) usize, record_addr).*;
173173 const ptr = @intToPtr(*c_void, root_addr);
174 _ = os.windows.HeapFree(??self.heap_handle, 0, ptr);
174 _ = os.windows.HeapFree(self.heap_handle.?, 0, ptr);
175175 },
176176 else => @compileError("Unsupported OS"),
177177 }
std/json.zig+6-6
......@@ -908,7 +908,7 @@ pub const TokenStream = struct {
908908};
909909
910910fn checkNext(p: *TokenStream, id: Token.Id) void {
911 const token = ??(p.next() catch unreachable);
911 const token = (p.next() catch unreachable).?;
912912 debug.assert(token.id == id);
913913}
914914
......@@ -1376,17 +1376,17 @@ test "json parser dynamic" {
13761376
13771377 var root = tree.root;
13781378
1379 var image = (??root.Object.get("Image")).value;
1379 var image = root.Object.get("Image").?.value;
13801380
1381 const width = (??image.Object.get("Width")).value;
1381 const width = image.Object.get("Width").?.value;
13821382 debug.assert(width.Integer == 800);
13831383
1384 const height = (??image.Object.get("Height")).value;
1384 const height = image.Object.get("Height").?.value;
13851385 debug.assert(height.Integer == 600);
13861386
1387 const title = (??image.Object.get("Title")).value;
1387 const title = image.Object.get("Title").?.value;
13881388 debug.assert(mem.eql(u8, title.String, "View from 15th Floor"));
13891389
1390 const animated = (??image.Object.get("Animated")).value;
1390 const animated = image.Object.get("Animated").?.value;
13911391 debug.assert(animated.Bool == false);
13921392}
std/linked_list.zig+4-4
......@@ -270,8 +270,8 @@ test "basic linked list test" {
270270 var last = list.pop(); // {2, 3, 4}
271271 list.remove(three); // {2, 4}
272272
273 assert((??list.first).data == 2);
274 assert((??list.last).data == 4);
273 assert(list.first.?.data == 2);
274 assert(list.last.?.data == 4);
275275 assert(list.len == 2);
276276}
277277
......@@ -336,7 +336,7 @@ test "basic intrusive linked list test" {
336336 var last = list.pop(); // {2, 3, 4}
337337 list.remove(&three.link); // {2, 4}
338338
339 assert((??list.first).toData().value == 2);
340 assert((??list.last).toData().value == 4);
339 assert(list.first.?.toData().value == 2);
340 assert(list.last.?.toData().value == 4);
341341 assert(list.len == 2);
342342}
std/macho.zig+1-1
......@@ -130,7 +130,7 @@ pub fn loadSymbols(allocator: *mem.Allocator, in: *io.FileInStream) !SymbolTable
130130 for (syms) |sym| {
131131 if (!isSymbol(sym)) continue;
132132 const start = sym.n_strx;
133 const end = ??mem.indexOfScalarPos(u8, strings, start, 0);
133 const end = mem.indexOfScalarPos(u8, strings, start, 0).?;
134134 const name = strings[start..end];
135135 const address = sym.n_value;
136136 symbols[nsym] = Symbol{ .name = name, .address = address };
std/mem.zig+11-11
......@@ -304,20 +304,20 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
304304}
305305
306306test "mem.indexOf" {
307 assert(??indexOf(u8, "one two three four", "four") == 14);
308 assert(??lastIndexOf(u8, "one two three two four", "two") == 14);
307 assert(indexOf(u8, "one two three four", "four").? == 14);
308 assert(lastIndexOf(u8, "one two three two four", "two").? == 14);
309309 assert(indexOf(u8, "one two three four", "gour") == null);
310310 assert(lastIndexOf(u8, "one two three four", "gour") == null);
311 assert(??indexOf(u8, "foo", "foo") == 0);
312 assert(??lastIndexOf(u8, "foo", "foo") == 0);
311 assert(indexOf(u8, "foo", "foo").? == 0);
312 assert(lastIndexOf(u8, "foo", "foo").? == 0);
313313 assert(indexOf(u8, "foo", "fool") == null);
314314 assert(lastIndexOf(u8, "foo", "lfoo") == null);
315315 assert(lastIndexOf(u8, "foo", "fool") == null);
316316
317 assert(??indexOf(u8, "foo foo", "foo") == 0);
318 assert(??lastIndexOf(u8, "foo foo", "foo") == 4);
319 assert(??lastIndexOfAny(u8, "boo, cat", "abo") == 6);
320 assert(??lastIndexOfScalar(u8, "boo", 'o') == 2);
317 assert(indexOf(u8, "foo foo", "foo").? == 0);
318 assert(lastIndexOf(u8, "foo foo", "foo").? == 4);
319 assert(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
320 assert(lastIndexOfScalar(u8, "boo", 'o').? == 2);
321321}
322322
323323/// Reads an integer from memory with size equal to bytes.len.
......@@ -432,9 +432,9 @@ pub fn split(buffer: []const u8, split_bytes: []const u8) SplitIterator {
432432
433433test "mem.split" {
434434 var it = split(" abc def ghi ", " ");
435 assert(eql(u8, ??it.next(), "abc"));
436 assert(eql(u8, ??it.next(), "def"));
437 assert(eql(u8, ??it.next(), "ghi"));
435 assert(eql(u8, it.next().?, "abc"));
436 assert(eql(u8, it.next().?, "def"));
437 assert(eql(u8, it.next().?, "ghi"));
438438 assert(it.next() == null);
439439}
440440
std/os/child_process.zig+9-9
......@@ -156,7 +156,7 @@ pub const ChildProcess = struct {
156156 };
157157 }
158158 try self.waitUnwrappedWindows();
159 return ??self.term;
159 return self.term.?;
160160 }
161161
162162 pub fn killPosix(self: *ChildProcess) !Term {
......@@ -175,7 +175,7 @@ pub const ChildProcess = struct {
175175 };
176176 }
177177 self.waitUnwrapped();
178 return ??self.term;
178 return self.term.?;
179179 }
180180
181181 /// Blocks until child process terminates and then cleans up all resources.
......@@ -212,8 +212,8 @@ pub const ChildProcess = struct {
212212 defer Buffer.deinit(&stdout);
213213 defer Buffer.deinit(&stderr);
214214
215 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
216 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
215 var stdout_file_in_stream = io.FileInStream.init(&child.stdout.?);
216 var stderr_file_in_stream = io.FileInStream.init(&child.stderr.?);
217217
218218 try stdout_file_in_stream.stream.readAllBuffer(&stdout, max_output_size);
219219 try stderr_file_in_stream.stream.readAllBuffer(&stderr, max_output_size);
......@@ -232,7 +232,7 @@ pub const ChildProcess = struct {
232232 }
233233
234234 try self.waitUnwrappedWindows();
235 return ??self.term;
235 return self.term.?;
236236 }
237237
238238 fn waitPosix(self: *ChildProcess) !Term {
......@@ -242,7 +242,7 @@ pub const ChildProcess = struct {
242242 }
243243
244244 self.waitUnwrapped();
245 return ??self.term;
245 return self.term.?;
246246 }
247247
248248 pub fn deinit(self: *ChildProcess) void {
......@@ -619,13 +619,13 @@ pub const ChildProcess = struct {
619619 self.term = null;
620620
621621 if (self.stdin_behavior == StdIo.Pipe) {
622 os.close(??g_hChildStd_IN_Rd);
622 os.close(g_hChildStd_IN_Rd.?);
623623 }
624624 if (self.stderr_behavior == StdIo.Pipe) {
625 os.close(??g_hChildStd_ERR_Wr);
625 os.close(g_hChildStd_ERR_Wr.?);
626626 }
627627 if (self.stdout_behavior == StdIo.Pipe) {
628 os.close(??g_hChildStd_OUT_Wr);
628 os.close(g_hChildStd_OUT_Wr.?);
629629 }
630630 }
631631
std/os/index.zig+2-2
......@@ -422,7 +422,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator:
422422
423423 const exe_path = argv[0];
424424 if (mem.indexOfScalar(u8, exe_path, '/') != null) {
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)));
426426 }
427427
428428 const PATH = getEnvPosix("PATH") ?? "/usr/local/bin:/bin/:/usr/bin";
......@@ -1729,7 +1729,7 @@ test "windows arg parsing" {
17291729fn testWindowsCmdLine(input_cmd_line: [*]const u8, expected_args: []const []const u8) void {
17301730 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
17311731 for (expected_args) |expected_arg| {
1732 const arg = ??it.next(debug.global_allocator) catch unreachable;
1732 const arg = it.next(debug.global_allocator).? catch unreachable;
17331733 assert(mem.eql(u8, arg, expected_arg));
17341734 }
17351735 assert(it.next(debug.global_allocator) == null);
std/os/linux/vdso.zig+1-1
......@@ -67,7 +67,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6767 if (0 == syms[i].st_shndx) continue;
6868 if (!mem.eql(u8, name, cstr.toSliceConst(strings + syms[i].st_name))) continue;
6969 if (maybe_versym) |versym| {
70 if (!checkver(??maybe_verdef, versym[i], vername, strings))
70 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
7171 continue;
7272 }
7373 return base + syms[i].st_value;
std/os/path.zig+4-4
......@@ -265,7 +265,7 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
265265 var it2 = mem.split(ns2, []u8{sep2});
266266
267267 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
268 return asciiEqlIgnoreCase(??it1.next(), ??it2.next());
268 return asciiEqlIgnoreCase(it1.next().?, it2.next().?);
269269}
270270
271271fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8) bool {
......@@ -286,7 +286,7 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
286286 var it2 = mem.split(p2, []u8{sep2});
287287
288288 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
289 return asciiEqlIgnoreCase(??it1.next(), ??it2.next()) and asciiEqlIgnoreCase(??it1.next(), ??it2.next());
289 return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);
290290 },
291291 }
292292}
......@@ -414,8 +414,8 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
414414 WindowsPath.Kind.NetworkShare => {
415415 result = try allocator.alloc(u8, max_size);
416416 var it = mem.split(paths[first_index], "/\\");
417 const server_name = ??it.next();
418 const other_name = ??it.next();
417 const server_name = it.next().?;
418 const other_name = it.next().?;
419419
420420 result[result_index] = '\\';
421421 result_index += 1;
std/segmented_list.zig+4-4
......@@ -364,7 +364,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
364364 assert(x == 0);
365365 }
366366
367 assert(??list.pop() == 100);
367 assert(list.pop().? == 100);
368368 assert(list.len == 99);
369369
370370 try list.pushMany([]i32{
......@@ -373,9 +373,9 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
373373 3,
374374 });
375375 assert(list.len == 102);
376 assert(??list.pop() == 3);
377 assert(??list.pop() == 2);
378 assert(??list.pop() == 1);
376 assert(list.pop().? == 3);
377 assert(list.pop().? == 2);
378 assert(list.pop().? == 1);
379379 assert(list.len == 99);
380380
381381 try list.pushMany([]const i32{});
std/special/bootstrap.zig+3-3
......@@ -54,10 +54,10 @@ fn posixCallMainAndExit() noreturn {
5454 const argc = argc_ptr[0];
5555 const argv = @ptrCast([*][*]u8, argc_ptr + 1);
5656
57 const envp_nullable = @ptrCast([*]?[*]u8, argv + argc + 1);
57 const envp_optional = @ptrCast([*]?[*]u8, argv + argc + 1);
5858 var envp_count: usize = 0;
59 while (envp_nullable[envp_count]) |_| : (envp_count += 1) {}
60 const envp = @ptrCast([*][*]u8, envp_nullable)[0..envp_count];
59 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
60 const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];
6161 if (builtin.os == builtin.Os.linux) {
6262 const auxv = @ptrCast([*]usize, envp.ptr + envp_count + 1);
6363 var i: usize = 0;
std/special/builtin.zig+4-4
......@@ -19,7 +19,7 @@ export fn memset(dest: ?[*]u8, c: u8, n: usize) ?[*]u8 {
1919
2020 var index: usize = 0;
2121 while (index != n) : (index += 1)
22 (??dest)[index] = c;
22 dest.?[index] = c;
2323
2424 return dest;
2525}
......@@ -29,7 +29,7 @@ export fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) ?[*]
2929
3030 var index: usize = 0;
3131 while (index != n) : (index += 1)
32 (??dest)[index] = (??src)[index];
32 dest.?[index] = src.?[index];
3333
3434 return dest;
3535}
......@@ -40,13 +40,13 @@ export fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) ?[*]u8 {
4040 if (@ptrToInt(dest) < @ptrToInt(src)) {
4141 var index: usize = 0;
4242 while (index != n) : (index += 1) {
43 (??dest)[index] = (??src)[index];
43 dest.?[index] = src.?[index];
4444 }
4545 } else {
4646 var index = n;
4747 while (index != 0) {
4848 index -= 1;
49 (??dest)[index] = (??src)[index];
49 dest.?[index] = src.?[index];
5050 }
5151 }
5252
std/unicode.zig+12-12
......@@ -286,15 +286,15 @@ fn testUtf8IteratorOnAscii() void {
286286 const s = Utf8View.initComptime("abc");
287287
288288 var it1 = s.iterator();
289 debug.assert(std.mem.eql(u8, "a", ??it1.nextCodepointSlice()));
290 debug.assert(std.mem.eql(u8, "b", ??it1.nextCodepointSlice()));
291 debug.assert(std.mem.eql(u8, "c", ??it1.nextCodepointSlice()));
289 debug.assert(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
290 debug.assert(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
291 debug.assert(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
292292 debug.assert(it1.nextCodepointSlice() == null);
293293
294294 var it2 = s.iterator();
295 debug.assert(??it2.nextCodepoint() == 'a');
296 debug.assert(??it2.nextCodepoint() == 'b');
297 debug.assert(??it2.nextCodepoint() == 'c');
295 debug.assert(it2.nextCodepoint().? == 'a');
296 debug.assert(it2.nextCodepoint().? == 'b');
297 debug.assert(it2.nextCodepoint().? == 'c');
298298 debug.assert(it2.nextCodepoint() == null);
299299}
300300
......@@ -321,15 +321,15 @@ fn testUtf8ViewOk() void {
321321 const s = Utf8View.initComptime("東京市");
322322
323323 var it1 = s.iterator();
324 debug.assert(std.mem.eql(u8, "東", ??it1.nextCodepointSlice()));
325 debug.assert(std.mem.eql(u8, "京", ??it1.nextCodepointSlice()));
326 debug.assert(std.mem.eql(u8, "市", ??it1.nextCodepointSlice()));
324 debug.assert(std.mem.eql(u8, "東", it1.nextCodepointSlice().?));
325 debug.assert(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
326 debug.assert(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
327327 debug.assert(it1.nextCodepointSlice() == null);
328328
329329 var it2 = s.iterator();
330 debug.assert(??it2.nextCodepoint() == 0x6771);
331 debug.assert(??it2.nextCodepoint() == 0x4eac);
332 debug.assert(??it2.nextCodepoint() == 0x5e02);
330 debug.assert(it2.nextCodepoint().? == 0x6771);
331 debug.assert(it2.nextCodepoint().? == 0x4eac);
332 debug.assert(it2.nextCodepoint().? == 0x5e02);
333333 debug.assert(it2.nextCodepoint() == null);
334334}
335335
std/zig/ast.zig+6-6
......@@ -1417,7 +1417,7 @@ pub const Node = struct {
14171417 Range,
14181418 Sub,
14191419 SubWrap,
1420 UnwrapMaybe,
1420 UnwrapOptional,
14211421 };
14221422
14231423 pub fn iterate(self: *InfixOp, index: usize) ?*Node {
......@@ -1475,7 +1475,7 @@ pub const Node = struct {
14751475 Op.Range,
14761476 Op.Sub,
14771477 Op.SubWrap,
1478 Op.UnwrapMaybe,
1478 Op.UnwrapOptional,
14791479 => {},
14801480 }
14811481
......@@ -1507,14 +1507,13 @@ pub const Node = struct {
15071507 BitNot,
15081508 BoolNot,
15091509 Cancel,
1510 MaybeType,
1510 OptionalType,
15111511 Negation,
15121512 NegationWrap,
15131513 Resume,
15141514 PtrType: PtrInfo,
15151515 SliceType: PtrInfo,
15161516 Try,
1517 UnwrapMaybe,
15181517 };
15191518
15201519 pub const PtrInfo = struct {
......@@ -1557,12 +1556,12 @@ pub const Node = struct {
15571556 Op.BitNot,
15581557 Op.BoolNot,
15591558 Op.Cancel,
1560 Op.MaybeType,
1559 Op.OptionalType,
15611560 Op.Negation,
15621561 Op.NegationWrap,
15631562 Op.Try,
15641563 Op.Resume,
1565 Op.UnwrapMaybe,
1564 Op.UnwrapOptional,
15661565 Op.PointerType,
15671566 => {},
15681567 }
......@@ -1619,6 +1618,7 @@ pub const Node = struct {
16191618 ArrayInitializer: InitList,
16201619 StructInitializer: InitList,
16211620 Deref,
1621 UnwrapOptional,
16221622
16231623 pub const InitList = SegmentedList(*Node, 2);
16241624
std/zig/parse.zig+22-13
......@@ -711,7 +711,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
711711 else => {
712712 // TODO: this is a special case. Remove this when #760 is fixed
713713 if (token_ptr.id == Token.Id.Keyword_error) {
714 if ((??tok_it.peek()).id == Token.Id.LBrace) {
714 if (tok_it.peek().?.id == Token.Id.LBrace) {
715715 const error_type_node = try arena.construct(ast.Node.ErrorType{
716716 .base = ast.Node{ .id = ast.Node.Id.ErrorType },
717717 .token = token_index,
......@@ -1434,8 +1434,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
14341434 try stack.append(State{
14351435 .ExpectTokenSave = ExpectTokenSave{
14361436 .id = Token.Id.AngleBracketRight,
1437 .ptr = &??async_node.rangle_bracket,
1438 },
1437 .ptr = &async_node.rangle_bracket.? },
14391438 });
14401439 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &async_node.allocator_type } });
14411440 continue;
......@@ -1567,7 +1566,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
15671566 .bit_range = null,
15681567 };
15691568 // TODO https://github.com/ziglang/zig/issues/1022
1570 const align_info = &??addr_of_info.align_info;
1569 const align_info = &addr_of_info.align_info.?;
15711570
15721571 try stack.append(State{ .AlignBitRange = align_info });
15731572 try stack.append(State{ .Expression = OptionalCtx{ .Required = &align_info.node } });
......@@ -1604,7 +1603,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
16041603 switch (token.ptr.id) {
16051604 Token.Id.Colon => {
16061605 align_info.bit_range = ast.Node.PrefixOp.PtrInfo.Align.BitRange(undefined);
1607 const bit_range = &??align_info.bit_range;
1606 const bit_range = &align_info.bit_range.?;
16081607
16091608 try stack.append(State{ .ExpectToken = Token.Id.RParen });
16101609 try stack.append(State{ .Expression = OptionalCtx{ .Required = &bit_range.end } });
......@@ -2144,7 +2143,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
21442143 State.CurlySuffixExpressionEnd => |opt_ctx| {
21452144 const lhs = opt_ctx.get() ?? continue;
21462145
2147 if ((??tok_it.peek()).id == Token.Id.Period) {
2146 if (tok_it.peek().?.id == Token.Id.Period) {
21482147 const node = try arena.construct(ast.Node.SuffixOp{
21492148 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
21502149 .lhs = lhs,
......@@ -2326,6 +2325,17 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
23262325 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
23272326 continue;
23282327 }
2328 if (eatToken(&tok_it, &tree, Token.Id.QuestionMark)) |question_token| {
2329 const node = try arena.construct(ast.Node.SuffixOp{
2330 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
2331 .lhs = lhs,
2332 .op = ast.Node.SuffixOp.Op.UnwrapOptional,
2333 .rtoken = question_token,
2334 });
2335 opt_ctx.store(&node.base);
2336 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2337 continue;
2338 }
23292339 const node = try arena.construct(ast.Node.InfixOp{
23302340 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
23312341 .lhs = lhs,
......@@ -2403,7 +2413,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
24032413 .arrow_token = next_token_index,
24042414 .return_type = undefined,
24052415 };
2406 const return_type_ptr = &((??node.result).return_type);
2416 const return_type_ptr = &node.result.?.return_type;
24072417 try stack.append(State{ .Expression = OptionalCtx{ .Required = return_type_ptr } });
24082418 continue;
24092419 },
......@@ -2875,7 +2885,7 @@ const OptionalCtx = union(enum) {
28752885 pub fn get(self: *const OptionalCtx) ?*ast.Node {
28762886 switch (self.*) {
28772887 OptionalCtx.Optional => |ptr| return ptr.*,
2878 OptionalCtx.RequiredNull => |ptr| return ??ptr.*,
2888 OptionalCtx.RequiredNull => |ptr| return ptr.*.?,
28792889 OptionalCtx.Required => |ptr| return ptr.*,
28802890 }
28812891 }
......@@ -3237,7 +3247,7 @@ fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {
32373247fn tokenIdToUnwrapExpr(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {
32383248 return switch (id) {
32393249 Token.Id.Keyword_catch => ast.Node.InfixOp.Op{ .Catch = null },
3240 Token.Id.QuestionMarkQuestionMark => ast.Node.InfixOp.Op{ .UnwrapMaybe = void{} },
3250 Token.Id.QuestionMarkQuestionMark => ast.Node.InfixOp.Op{ .UnwrapOptional = void{} },
32413251 else => null,
32423252 };
32433253}
......@@ -3299,8 +3309,7 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {
32993309 .volatile_token = null,
33003310 },
33013311 },
3302 Token.Id.QuestionMark => ast.Node.PrefixOp.Op{ .MaybeType = void{} },
3303 Token.Id.QuestionMarkQuestionMark => ast.Node.PrefixOp.Op{ .UnwrapMaybe = void{} },
3312 Token.Id.QuestionMark => ast.Node.PrefixOp.Op{ .OptionalType = void{} },
33043313 Token.Id.Keyword_await => ast.Node.PrefixOp.Op{ .Await = void{} },
33053314 Token.Id.Keyword_try => ast.Node.PrefixOp.Op{ .Try = void{} },
33063315 else => null,
......@@ -3322,7 +3331,7 @@ fn createToCtxLiteral(arena: *mem.Allocator, opt_ctx: *const OptionalCtx, compti
33223331}
33233332
33243333fn eatToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree, id: @TagType(Token.Id)) ?TokenIndex {
3325 const token = ??tok_it.peek();
3334 const token = tok_it.peek().?;
33263335
33273336 if (token.id == id) {
33283337 return nextToken(tok_it, tree).index;
......@@ -3334,7 +3343,7 @@ fn eatToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree, id: @TagType(
33343343fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedToken {
33353344 const result = AnnotatedToken{
33363345 .index = tok_it.index,
3337 .ptr = ??tok_it.next(),
3346 .ptr = tok_it.next().?,
33383347 };
33393348 assert(result.ptr.id != Token.Id.LineComment);
33403349
std/zig/parser_test.zig+3-2
......@@ -650,9 +650,10 @@ test "zig fmt: statements with empty line between" {
650650 );
651651}
652652
653test "zig fmt: ptr deref operator" {
653test "zig fmt: ptr deref operator and unwrap optional operator" {
654654 try testCanonical(
655655 \\const a = b.*;
656 \\const a = b.?;
656657 \\
657658 );
658659}
......@@ -1209,7 +1210,7 @@ test "zig fmt: precedence" {
12091210test "zig fmt: prefix operators" {
12101211 try testCanonical(
12111212 \\test "prefix operators" {
1212 \\ try return --%~??!*&0;
1213 \\ try return --%~!*&0;
12131214 \\}
12141215 \\
12151216 );
std/zig/render.zig+12-13
......@@ -222,7 +222,7 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i
222222 }
223223 }
224224
225 const value_expr = ??tag.value_expr;
225 const value_expr = tag.value_expr.?;
226226 try renderToken(tree, stream, tree.prevToken(value_expr.firstToken()), indent, start_col, Space.Space); // =
227227 try renderExpression(allocator, stream, tree, indent, start_col, value_expr, Space.Comma); // value,
228228 },
......@@ -465,8 +465,7 @@ fn renderExpression(
465465 ast.Node.PrefixOp.Op.BoolNot,
466466 ast.Node.PrefixOp.Op.Negation,
467467 ast.Node.PrefixOp.Op.NegationWrap,
468 ast.Node.PrefixOp.Op.UnwrapMaybe,
469 ast.Node.PrefixOp.Op.MaybeType,
468 ast.Node.PrefixOp.Op.OptionalType,
470469 ast.Node.PrefixOp.Op.AddressOf,
471470 => {
472471 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None);
......@@ -513,7 +512,7 @@ fn renderExpression(
513512
514513 var it = call_info.params.iterator(0);
515514 while (true) {
516 const param_node = ??it.next();
515 const param_node = it.next().?;
517516
518517 const param_node_new_indent = if (param_node.*.id == ast.Node.Id.MultilineStringLiteral) blk: {
519518 break :blk indent;
......@@ -559,10 +558,10 @@ fn renderExpression(
559558 return renderToken(tree, stream, rbracket, indent, start_col, space); // ]
560559 },
561560
562 ast.Node.SuffixOp.Op.Deref => {
561 ast.Node.SuffixOp.Op.Deref, ast.Node.SuffixOp.Op.UnwrapOptional => {
563562 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
564563 try renderToken(tree, stream, tree.prevToken(suffix_op.rtoken), indent, start_col, Space.None); // .
565 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space); // *
564 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space); // * or ?
566565 },
567566
568567 @TagType(ast.Node.SuffixOp.Op).Slice => |range| {
......@@ -595,7 +594,7 @@ fn renderExpression(
595594 }
596595
597596 if (field_inits.len == 1) blk: {
598 const field_init = ??field_inits.at(0).*.cast(ast.Node.FieldInitializer);
597 const field_init = field_inits.at(0).*.cast(ast.Node.FieldInitializer).?;
599598
600599 if (field_init.expr.cast(ast.Node.SuffixOp)) |nested_suffix_op| {
601600 if (nested_suffix_op.op == ast.Node.SuffixOp.Op.StructInitializer) {
......@@ -688,7 +687,7 @@ fn renderExpression(
688687 var count: usize = 1;
689688 var it = exprs.iterator(0);
690689 while (true) {
691 const expr = (??it.next()).*;
690 const expr = it.next().?.*;
692691 if (it.peek()) |next_expr| {
693692 const expr_last_token = expr.*.lastToken() + 1;
694693 const loc = tree.tokenLocation(tree.tokens.at(expr_last_token).end, next_expr.*.firstToken());
......@@ -806,7 +805,7 @@ fn renderExpression(
806805 },
807806 }
808807
809 return renderExpression(allocator, stream, tree, indent, start_col, ??flow_expr.rhs, space);
808 return renderExpression(allocator, stream, tree, indent, start_col, flow_expr.rhs.?, space);
810809 },
811810
812811 ast.Node.Id.Payload => {
......@@ -1245,7 +1244,7 @@ fn renderExpression(
12451244 } else {
12461245 var it = switch_case.items.iterator(0);
12471246 while (true) {
1248 const node = ??it.next();
1247 const node = it.next().?;
12491248 if (it.peek()) |next_node| {
12501249 try renderExpression(allocator, stream, tree, indent, start_col, node.*, Space.None);
12511250
......@@ -1550,7 +1549,7 @@ fn renderExpression(
15501549
15511550 var it = asm_node.outputs.iterator(0);
15521551 while (true) {
1553 const asm_output = ??it.next();
1552 const asm_output = it.next().?;
15541553 const node = &(asm_output.*).base;
15551554
15561555 if (it.peek()) |next_asm_output| {
......@@ -1588,7 +1587,7 @@ fn renderExpression(
15881587
15891588 var it = asm_node.inputs.iterator(0);
15901589 while (true) {
1591 const asm_input = ??it.next();
1590 const asm_input = it.next().?;
15921591 const node = &(asm_input.*).base;
15931592
15941593 if (it.peek()) |next_asm_input| {
......@@ -1620,7 +1619,7 @@ fn renderExpression(
16201619
16211620 var it = asm_node.clobbers.iterator(0);
16221621 while (true) {
1623 const clobber_token = ??it.next();
1622 const clobber_token = it.next().?;
16241623
16251624 if (it.peek() == null) {
16261625 try renderToken(tree, stream, clobber_token.*, indent_once, start_col, Space.Newline);
test/cases/bugs/656.zig+1-1
......@@ -9,7 +9,7 @@ const Value = struct {
99 align_expr: ?u32,
1010};
1111
12test "nullable if after an if in a switch prong of a switch with 2 prongs in an else" {
12test "optional if after an if in a switch prong of a switch with 2 prongs in an else" {
1313 foo(false, true);
1414}
1515
test/cases/cast.zig+25-25
......@@ -109,16 +109,16 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
109109 const Self = this;
110110 x: u8,
111111 fn constConst(p: *const *const Self) u8 {
112 return (p.*).x;
112 return p.*.x;
113113 }
114114 fn maybeConstConst(p: ?*const *const Self) u8 {
115 return ((??p).*).x;
115 return p.?.*.x;
116116 }
117117 fn constConstConst(p: *const *const *const Self) u8 {
118 return (p.*.*).x;
118 return p.*.*.x;
119119 }
120120 fn maybeConstConstConst(p: ?*const *const *const Self) u8 {
121 return ((??p).*.*).x;
121 return p.?.*.*.x;
122122 }
123123 };
124124 const s = S{ .x = 42 };
......@@ -177,56 +177,56 @@ test "string literal to &const []const u8" {
177177}
178178
179179test "implicitly cast from T to error!?T" {
180 castToMaybeTypeError(1);
181 comptime castToMaybeTypeError(1);
180 castToOptionalTypeError(1);
181 comptime castToOptionalTypeError(1);
182182}
183183const A = struct {
184184 a: i32,
185185};
186fn castToMaybeTypeError(z: i32) void {
186fn castToOptionalTypeError(z: i32) void {
187187 const x = i32(1);
188188 const y: error!?i32 = x;
189 assert(??(try y) == 1);
189 assert((try y).? == 1);
190190
191191 const f = z;
192192 const g: error!?i32 = f;
193193
194194 const a = A{ .a = z };
195195 const b: error!?A = a;
196 assert((??(b catch unreachable)).a == 1);
196 assert((b catch unreachable).?.a == 1);
197197}
198198
199199test "implicitly cast from int to error!?T" {
200 implicitIntLitToMaybe();
201 comptime implicitIntLitToMaybe();
200 implicitIntLitToOptional();
201 comptime implicitIntLitToOptional();
202202}
203fn implicitIntLitToMaybe() void {
203fn implicitIntLitToOptional() void {
204204 const f: ?i32 = 1;
205205 const g: error!?i32 = 1;
206206}
207207
208208test "return null from fn() error!?&T" {
209 const a = returnNullFromMaybeTypeErrorRef();
210 const b = returnNullLitFromMaybeTypeErrorRef();
209 const a = returnNullFromOptionalTypeErrorRef();
210 const b = returnNullLitFromOptionalTypeErrorRef();
211211 assert((try a) == null and (try b) == null);
212212}
213fn returnNullFromMaybeTypeErrorRef() error!?*A {
213fn returnNullFromOptionalTypeErrorRef() error!?*A {
214214 const a: ?*A = null;
215215 return a;
216216}
217fn returnNullLitFromMaybeTypeErrorRef() error!?*A {
217fn returnNullLitFromOptionalTypeErrorRef() error!?*A {
218218 return null;
219219}
220220
221221test "peer type resolution: ?T and T" {
222 assert(??peerTypeTAndMaybeT(true, false) == 0);
223 assert(??peerTypeTAndMaybeT(false, false) == 3);
222 assert(peerTypeTAndOptionalT(true, false).? == 0);
223 assert(peerTypeTAndOptionalT(false, false).? == 3);
224224 comptime {
225 assert(??peerTypeTAndMaybeT(true, false) == 0);
226 assert(??peerTypeTAndMaybeT(false, false) == 3);
225 assert(peerTypeTAndOptionalT(true, false).? == 0);
226 assert(peerTypeTAndOptionalT(false, false).? == 3);
227227 }
228228}
229fn peerTypeTAndMaybeT(c: bool, b: bool) ?usize {
229fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
230230 if (c) {
231231 return if (b) null else usize(0);
232232 }
......@@ -251,11 +251,11 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
251251}
252252
253253test "implicitly cast from [N]T to ?[]const T" {
254 assert(mem.eql(u8, ??castToMaybeSlice(), "hi"));
255 comptime assert(mem.eql(u8, ??castToMaybeSlice(), "hi"));
254 assert(mem.eql(u8, castToOptionalSlice().?, "hi"));
255 comptime assert(mem.eql(u8, castToOptionalSlice().?, "hi"));
256256}
257257
258fn castToMaybeSlice() ?[]const u8 {
258fn castToOptionalSlice() ?[]const u8 {
259259 return "hi";
260260}
261261
......@@ -404,5 +404,5 @@ fn testCastPtrOfArrayToSliceAndPtr() void {
404404test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
405405 const window_name = [1][*]const u8{c"window name"};
406406 const x: [*]const ?[*]const u8 = &window_name;
407 assert(mem.eql(u8, std.cstr.toSliceConst(??x[0]), "window name"));
407 assert(mem.eql(u8, std.cstr.toSliceConst(x[0].?), "window name"));
408408}
test/cases/error.zig+1-1
......@@ -140,7 +140,7 @@ fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {
140140 if (x) |v| assert(v == 1234) else |err| @compileError("bad");
141141}
142142
143test "syntax: nullable operator in front of error union operator" {
143test "syntax: optional operator in front of error union operator" {
144144 comptime {
145145 assert(?error!i32 == ?(error!i32));
146146 }
test/cases/eval.zig+1-1
......@@ -12,7 +12,7 @@ fn fibonacci(x: i32) i32 {
1212}
1313
1414fn unwrapAndAddOne(blah: ?i32) i32 {
15 return ??blah + 1;
15 return blah.? + 1;
1616}
1717const should_be_1235 = unwrapAndAddOne(1234);
1818test "static add one" {
test/cases/generics.zig+1-1
......@@ -127,7 +127,7 @@ test "generic fn with implicit cast" {
127127 }) == 0);
128128}
129129fn getByte(ptr: ?*const u8) u8 {
130 return (??ptr).*;
130 return ptr.?.*;
131131}
132132fn getFirstByte(comptime T: type, mem: []const T) u8 {
133133 return getByte(@ptrCast(*const u8, &mem[0]));
test/cases/misc.zig+1-1
......@@ -505,7 +505,7 @@ test "@typeId" {
505505 assert(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat);
506506 assert(@typeId(@typeOf(undefined)) == Tid.Undefined);
507507 assert(@typeId(@typeOf(null)) == Tid.Null);
508 assert(@typeId(?i32) == Tid.Nullable);
508 assert(@typeId(?i32) == Tid.Optional);
509509 assert(@typeId(error!i32) == Tid.ErrorUnion);
510510 assert(@typeId(error) == Tid.ErrorSet);
511511 assert(@typeId(AnEnum) == Tid.Enum);
test/cases/null.zig+15-15
......@@ -1,6 +1,6 @@
11const assert = @import("std").debug.assert;
22
3test "nullable type" {
3test "optional type" {
44 const x: ?bool = true;
55
66 if (x) |y| {
......@@ -33,7 +33,7 @@ test "test maybe object and get a pointer to the inner value" {
3333 b.* = false;
3434 }
3535
36 assert(??maybe_bool == false);
36 assert(maybe_bool.? == false);
3737}
3838
3939test "rhs maybe unwrap return" {
......@@ -47,9 +47,9 @@ test "maybe return" {
4747}
4848
4949fn maybeReturnImpl() void {
50 assert(??foo(1235));
50 assert(foo(1235).?);
5151 if (foo(null) != null) unreachable;
52 assert(!??foo(1234));
52 assert(!foo(1234).?);
5353}
5454
5555fn foo(x: ?i32) ?bool {
......@@ -102,12 +102,12 @@ fn testTestNullRuntime(x: ?i32) void {
102102 assert(!(x != null));
103103}
104104
105test "nullable void" {
106 nullableVoidImpl();
107 comptime nullableVoidImpl();
105test "optional void" {
106 optionalVoidImpl();
107 comptime optionalVoidImpl();
108108}
109109
110fn nullableVoidImpl() void {
110fn optionalVoidImpl() void {
111111 assert(bar(null) == null);
112112 assert(bar({}) != null);
113113}
......@@ -120,19 +120,19 @@ fn bar(x: ?void) ?void {
120120 }
121121}
122122
123const StructWithNullable = struct {
123const StructWithOptional = struct {
124124 field: ?i32,
125125};
126126
127var struct_with_nullable: StructWithNullable = undefined;
127var struct_with_optional: StructWithOptional = undefined;
128128
129test "unwrap nullable which is field of global var" {
130 struct_with_nullable.field = null;
131 if (struct_with_nullable.field) |payload| {
129test "unwrap optional which is field of global var" {
130 struct_with_optional.field = null;
131 if (struct_with_optional.field) |payload| {
132132 unreachable;
133133 }
134 struct_with_nullable.field = 1234;
135 if (struct_with_nullable.field) |payload| {
134 struct_with_optional.field = 1234;
135 if (struct_with_optional.field) |payload| {
136136 assert(payload == 1234);
137137 } else {
138138 unreachable;
test/cases/reflection.zig+1-1
......@@ -2,7 +2,7 @@ const assert = @import("std").debug.assert;
22const mem = @import("std").mem;
33const reflection = this;
44
5test "reflection: array, pointer, nullable, error union type child" {
5test "reflection: array, pointer, optional, error union type child" {
66 comptime {
77 assert(([10]u8).Child == u8);
88 assert((*u8).Child == u8);
test/cases/type_info.zig+7-7
......@@ -88,15 +88,15 @@ fn testArray() void {
8888 assert(arr_info.Array.child == bool);
8989}
9090
91test "type info: nullable type info" {
92 testNullable();
93 comptime testNullable();
91test "type info: optional type info" {
92 testOptional();
93 comptime testOptional();
9494}
9595
96fn testNullable() void {
96fn testOptional() void {
9797 const null_info = @typeInfo(?void);
98 assert(TypeId(null_info) == TypeId.Nullable);
99 assert(null_info.Nullable.child == void);
98 assert(TypeId(null_info) == TypeId.Optional);
99 assert(null_info.Optional.child == void);
100100}
101101
102102test "type info: promise info" {
......@@ -168,7 +168,7 @@ fn testUnion() void {
168168 assert(typeinfo_info.Union.tag_type == TypeId);
169169 assert(typeinfo_info.Union.fields.len == 25);
170170 assert(typeinfo_info.Union.fields[4].enum_field != null);
171 assert((??typeinfo_info.Union.fields[4].enum_field).value == 4);
171 assert(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
172172 assert(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));
173173 assert(typeinfo_info.Union.defs.len == 20);
174174
test/cases/while.zig+6-6
......@@ -81,7 +81,7 @@ test "while with else" {
8181 assert(got_else == 1);
8282}
8383
84test "while with nullable as condition" {
84test "while with optional as condition" {
8585 numbers_left = 10;
8686 var sum: i32 = 0;
8787 while (getNumberOrNull()) |value| {
......@@ -90,7 +90,7 @@ test "while with nullable as condition" {
9090 assert(sum == 45);
9191}
9292
93test "while with nullable as condition with else" {
93test "while with optional as condition with else" {
9494 numbers_left = 10;
9595 var sum: i32 = 0;
9696 var got_else: i32 = 0;
......@@ -132,7 +132,7 @@ fn getNumberOrNull() ?i32 {
132132 };
133133}
134134
135test "while on nullable with else result follow else prong" {
135test "while on optional with else result follow else prong" {
136136 const result = while (returnNull()) |value| {
137137 break value;
138138 } else
......@@ -140,8 +140,8 @@ test "while on nullable with else result follow else prong" {
140140 assert(result == 2);
141141}
142142
143test "while on nullable with else result follow break prong" {
144 const result = while (returnMaybe(10)) |value| {
143test "while on optional with else result follow break prong" {
144 const result = while (returnOptional(10)) |value| {
145145 break value;
146146 } else
147147 i32(2);
......@@ -210,7 +210,7 @@ fn testContinueOuter() void {
210210fn returnNull() ?i32 {
211211 return null;
212212}
213fn returnMaybe(x: i32) ?i32 {
213fn returnOptional(x: i32) ?i32 {
214214 return x;
215215}
216216fn returnError() error!i32 {
test/compile_errors.zig+8-8
......@@ -1341,7 +1341,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
13411341 \\ if (true) |x| { }
13421342 \\}
13431343 ,
1344 ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'",
1344 ".tmp_source.zig:2:9: error: expected optional type, found 'bool'",
13451345 );
13461346
13471347 cases.add(
......@@ -1780,7 +1780,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
17801780 );
17811781
17821782 cases.add(
1783 "assign null to non-nullable pointer",
1783 "assign null to non-optional pointer",
17841784 \\const a: *u8 = null;
17851785 \\
17861786 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
......@@ -2817,7 +2817,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28172817 );
28182818
28192819 cases.add(
2820 "while expected bool, got nullable",
2820 "while expected bool, got optional",
28212821 \\export fn foo() void {
28222822 \\ while (bar()) {}
28232823 \\}
......@@ -2837,23 +2837,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28372837 );
28382838
28392839 cases.add(
2840 "while expected nullable, got bool",
2840 "while expected optional, got bool",
28412841 \\export fn foo() void {
28422842 \\ while (bar()) |x| {}
28432843 \\}
28442844 \\fn bar() bool { return true; }
28452845 ,
2846 ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'",
2846 ".tmp_source.zig:2:15: error: expected optional type, found 'bool'",
28472847 );
28482848
28492849 cases.add(
2850 "while expected nullable, got error union",
2850 "while expected optional, got error union",
28512851 \\export fn foo() void {
28522852 \\ while (bar()) |x| {}
28532853 \\}
28542854 \\fn bar() error!i32 { return 1; }
28552855 ,
2856 ".tmp_source.zig:2:15: error: expected nullable type, found 'error!i32'",
2856 ".tmp_source.zig:2:15: error: expected optional type, found 'error!i32'",
28572857 );
28582858
28592859 cases.add(
......@@ -2867,7 +2867,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28672867 );
28682868
28692869 cases.add(
2870 "while expected error union, got nullable",
2870 "while expected error union, got optional",
28712871 \\export fn foo() void {
28722872 \\ while (bar()) |x| {} else |err| {}
28732873 \\}
test/tests.zig+6-6
......@@ -282,8 +282,8 @@ pub const CompareOutputContext = struct {
282282 var stdout = Buffer.initNull(b.allocator);
283283 var stderr = Buffer.initNull(b.allocator);
284284
285 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
286 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
285 var stdout_file_in_stream = io.FileInStream.init(&child.stdout.?);
286 var stderr_file_in_stream = io.FileInStream.init(&child.stderr.?);
287287
288288 stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable;
289289 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
......@@ -601,8 +601,8 @@ pub const CompileErrorContext = struct {
601601 var stdout_buf = Buffer.initNull(b.allocator);
602602 var stderr_buf = Buffer.initNull(b.allocator);
603603
604 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
605 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
604 var stdout_file_in_stream = io.FileInStream.init(&child.stdout.?);
605 var stderr_file_in_stream = io.FileInStream.init(&child.stderr.?);
606606
607607 stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
608608 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
......@@ -872,8 +872,8 @@ pub const TranslateCContext = struct {
872872 var stdout_buf = Buffer.initNull(b.allocator);
873873 var stderr_buf = Buffer.initNull(b.allocator);
874874
875 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
876 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
875 var stdout_file_in_stream = io.FileInStream.init(&child.stdout.?);
876 var stderr_file_in_stream = io.FileInStream.init(&child.stderr.?);
877877
878878 stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
879879 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;