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 {...@@ -75,7 +75,7 @@ pub fn build(b: *Builder) !void {
75 cxx_compiler,75 cxx_compiler,
76 "-print-file-name=libstdc++.a",76 "-print-file-name=libstdc++.a",
77 });77 });
78 const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\r\n").next();78 const libstdcxx_path = mem.split(libstdcxx_path_padded, "\r\n").next().?;
79 if (mem.eql(u8, libstdcxx_path, "libstdc++.a")) {79 if (mem.eql(u8, libstdcxx_path, "libstdc++.a")) {
80 warn(80 warn(
81 \\Unable to determine path to libstdc++.a81 \\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...@@ -6,7 +6,7 @@ Every type has a "handle". If a type is a simple primitive type such as i32 or
6f64, the handle is "by value", meaning that we pass around the value itself when6f64, the handle is "by value", meaning that we pass around the value itself when
7we refer to a value of that type.7we refer to a value of that type.
88
9If a type is a container, error union, maybe type, slice, or array, then its9If a type is a container, error union, optional type, slice, or array, then its
10handle is a pointer, and everywhere we refer to a value of this type we refer to10handle is a pointer, and everywhere we refer to a value of this type we refer to
11a pointer.11a pointer.
1212
...@@ -19,7 +19,7 @@ Error union types are represented as:...@@ -19,7 +19,7 @@ Error union types are represented as:
19 payload: T,19 payload: T,
20 }20 }
2121
22Maybe types are represented as:22Optional types are represented as:
2323
24 struct {24 struct {
25 payload: T,25 payload: T,
...@@ -28,6 +28,6 @@ Maybe types are represented as:...@@ -28,6 +28,6 @@ Maybe types are represented as:
2828
29## Data Optimizations29## Data Optimizations
3030
31Maybe pointer types are special: the 0x0 pointer value is used to represent a31Optional pointer types are special: the 0x0 pointer value is used to represent a
32null pointer. Thus, instead of the struct above, maybe pointer types are32null pointer. Thus, instead of the struct above, optional pointer types are
33represented as a `usize` in codegen and the handle is by value.33represented 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 {...@@ -156,18 +156,18 @@ pub fn main() void {
156 true or false,156 true or false,
157 !true);157 !true);
158 158
159 // nullable159 // optional
160 var nullable_value: ?[]const u8 = null;160 var optional_value: ?[]const u8 = null;
161 assert(nullable_value == null);161 assert(optional_value == null);
162162
163 warn("\nnullable 1\ntype: {}\nvalue: {}\n",163 warn("\noptional 1\ntype: {}\nvalue: {}\n",
164 @typeName(@typeOf(nullable_value)), nullable_value);164 @typeName(@typeOf(optional_value)), optional_value);
165165
166 nullable_value = "hi";166 optional_value = "hi";
167 assert(nullable_value != null);167 assert(optional_value != null);
168168
169 warn("\nnullable 2\ntype: {}\nvalue: {}\n",169 warn("\noptional 2\ntype: {}\nvalue: {}\n",
170 @typeName(@typeOf(nullable_value)), nullable_value);170 @typeName(@typeOf(optional_value)), optional_value);
171171
172 // error union172 // error union
173 var number_or_error: error!i32 = error.ArgNotFound;173 var number_or_error: error!i32 = error.ArgNotFound;
...@@ -428,7 +428,7 @@ pub fn main() void {...@@ -428,7 +428,7 @@ pub fn main() void {
428 </tr>428 </tr>
429 <tr>429 <tr>
430 <td><code>null</code></td>430 <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>
432 </tr>432 </tr>
433 <tr>433 <tr>
434 <td><code>undefined</code></td>434 <td><code>undefined</code></td>
...@@ -440,7 +440,7 @@ pub fn main() void {...@@ -440,7 +440,7 @@ pub fn main() void {
440 </tr>440 </tr>
441 </table>441 </table>
442 </div>442 </div>
443 {#see_also|Nullables|this#}443 {#see_also|Optionals|this#}
444 {#header_close#}444 {#header_close#}
445 {#header_open|String Literals#}445 {#header_open|String Literals#}
446 {#code_begin|test#}446 {#code_begin|test#}
...@@ -988,7 +988,7 @@ a ^= b</code></pre></td>...@@ -988,7 +988,7 @@ a ^= b</code></pre></td>
988 <td><pre><code class="zig">a ?? b</code></pre></td>988 <td><pre><code class="zig">a ?? b</code></pre></td>
989 <td>989 <td>
990 <ul>990 <ul>
991 <li>{#link|Nullables#}</li>991 <li>{#link|Optionals#}</li>
992 </ul>992 </ul>
993 </td>993 </td>
994 <td>If <code>a</code> is <code>null</code>,994 <td>If <code>a</code> is <code>null</code>,
...@@ -1003,10 +1003,10 @@ unwrapped == 1234</code></pre>...@@ -1003,10 +1003,10 @@ unwrapped == 1234</code></pre>
1003 </td>1003 </td>
1004 </tr>1004 </tr>
1005 <tr>1005 <tr>
1006 <td><pre><code class="zig">??a</code></pre></td>1006 <td><pre><code class="zig">a.?</code></pre></td>
1007 <td>1007 <td>
1008 <ul>1008 <ul>
1009 <li>{#link|Nullables#}</li>1009 <li>{#link|Optionals#}</li>
1010 </ul>1010 </ul>
1011 </td>1011 </td>
1012 <td>1012 <td>
...@@ -1015,7 +1015,7 @@ unwrapped == 1234</code></pre>...@@ -1015,7 +1015,7 @@ unwrapped == 1234</code></pre>
1015 </td>1015 </td>
1016 <td>1016 <td>
1017 <pre><code class="zig">const value: ?u32 = 5678;1017 <pre><code class="zig">const value: ?u32 = 5678;
1018??value == 5678</code></pre>1018value.? == 5678</code></pre>
1019 </td>1019 </td>
1020 </tr>1020 </tr>
1021 <tr>1021 <tr>
...@@ -1103,7 +1103,7 @@ unwrapped == 1234</code></pre>...@@ -1103,7 +1103,7 @@ unwrapped == 1234</code></pre>
1103 <td><pre><code class="zig">a == null<code></pre></td>1103 <td><pre><code class="zig">a == null<code></pre></td>
1104 <td>1104 <td>
1105 <ul>1105 <ul>
1106 <li>{#link|Nullables#}</li>1106 <li>{#link|Optionals#}</li>
1107 </ul>1107 </ul>
1108 </td>1108 </td>
1109 <td>1109 <td>
...@@ -1267,8 +1267,8 @@ x.* == 1234</code></pre>...@@ -1267,8 +1267,8 @@ x.* == 1234</code></pre>
1267 {#header_open|Precedence#}1267 {#header_open|Precedence#}
1268 <pre><code>x() x[] x.y1268 <pre><code>x() x[] x.y
1269a!b1269a!b
1270!x -x -%x ~x &amp;x ?x ??x1270!x -x -%x ~x &amp;x ?x
1271x{} x.*1271x{} x.* x.?
1272! * / % ** *%1272! * / % ** *%
1273+ - ++ +% -%1273+ - ++ +% -%
1274&lt;&lt; &gt;&gt;1274&lt;&lt; &gt;&gt;
...@@ -1483,17 +1483,17 @@ test "volatile" {...@@ -1483,17 +1483,17 @@ test "volatile" {
1483 assert(@typeOf(mmio_ptr) == *volatile u8);1483 assert(@typeOf(mmio_ptr) == *volatile u8);
1484}1484}
14851485
1486test "nullable pointers" {1486test "optional pointers" {
1487 // Pointers cannot be null. If you want a null pointer, use the nullable1487 // Pointers cannot be null. If you want a null pointer, use the optional
1488 // prefix `?` to make the pointer type nullable.1488 // prefix `?` to make the pointer type optional.
1489 var ptr: ?*i32 = null;1489 var ptr: ?*i32 = null;
14901490
1491 var x: i32 = 1;1491 var x: i32 = 1;
1492 ptr = &x;1492 ptr = &x;
14931493
1494 assert((??ptr).* == 1);1494 assert(ptr.?.* == 1);
14951495
1496 // Nullable pointers are the same size as normal pointers, because pointer1496 // Optional pointers are the same size as normal pointers, because pointer
1497 // value 0 is used as the null value.1497 // value 0 is used as the null value.
1498 assert(@sizeOf(?*i32) == @sizeOf(*i32));1498 assert(@sizeOf(?*i32) == @sizeOf(*i32));
1499}1499}
...@@ -1832,7 +1832,7 @@ test "linked list" {...@@ -1832,7 +1832,7 @@ test "linked list" {
1832 .last = &node,1832 .last = &node,
1833 .len = 1,1833 .len = 1,
1834 };1834 };
1835 assert((??list2.first).data == 1234);1835 assert(list2.first.?.data == 1234);
1836}1836}
1837 {#code_end#}1837 {#code_end#}
1838 {#see_also|comptime|@fieldParentPtr#}1838 {#see_also|comptime|@fieldParentPtr#}
...@@ -2270,7 +2270,7 @@ fn rangeHasNumber(begin: usize, end: usize, number: usize) bool {...@@ -2270,7 +2270,7 @@ fn rangeHasNumber(begin: usize, end: usize, number: usize) bool {
2270}2270}
22712271
2272test "while null capture" {2272test "while null capture" {
2273 // Just like if expressions, while loops can take a nullable as the2273 // Just like if expressions, while loops can take an optional as the
2274 // condition and capture the payload. When null is encountered the loop2274 // condition and capture the payload. When null is encountered the loop
2275 // exits.2275 // exits.
2276 var sum1: u32 = 0;2276 var sum1: u32 = 0;
...@@ -2280,7 +2280,7 @@ test "while null capture" {...@@ -2280,7 +2280,7 @@ test "while null capture" {
2280 }2280 }
2281 assert(sum1 == 3);2281 assert(sum1 == 3);
22822282
2283 // The else branch is allowed on nullable iteration. In this case, it will2283 // The else branch is allowed on optional iteration. In this case, it will
2284 // be executed on the first null value encountered.2284 // be executed on the first null value encountered.
2285 var sum2: u32 = 0;2285 var sum2: u32 = 0;
2286 numbers_left = 3;2286 numbers_left = 3;
...@@ -2340,7 +2340,7 @@ fn typeNameLength(comptime T: type) usize {...@@ -2340,7 +2340,7 @@ fn typeNameLength(comptime T: type) usize {
2340 return @typeName(T).len;2340 return @typeName(T).len;
2341}2341}
2342 {#code_end#}2342 {#code_end#}
2343 {#see_also|if|Nullables|Errors|comptime|unreachable#}2343 {#see_also|if|Optionals|Errors|comptime|unreachable#}
2344 {#header_close#}2344 {#header_close#}
2345 {#header_open|for#}2345 {#header_open|for#}
2346 {#code_begin|test|for#}2346 {#code_begin|test|for#}
...@@ -2400,7 +2400,7 @@ test "for else" {...@@ -2400,7 +2400,7 @@ test "for else" {
2400 if (value == null) {2400 if (value == null) {
2401 break 9;2401 break 9;
2402 } else {2402 } else {
2403 sum += ??value;2403 sum += value.?;
2404 }2404 }
2405 } else blk: {2405 } else blk: {
2406 assert(sum == 7);2406 assert(sum == 7);
...@@ -2461,7 +2461,7 @@ test "if boolean" {...@@ -2461,7 +2461,7 @@ test "if boolean" {
2461 assert(result == 47);2461 assert(result == 47);
2462}2462}
24632463
2464test "if nullable" {2464test "if optional" {
2465 // If expressions test for null.2465 // If expressions test for null.
24662466
2467 const a: ?u32 = 0;2467 const a: ?u32 = 0;
...@@ -2544,7 +2544,7 @@ test "if error union" {...@@ -2544,7 +2544,7 @@ test "if error union" {
2544 }2544 }
2545}2545}
2546 {#code_end#}2546 {#code_end#}
2547 {#see_also|Nullables|Errors#}2547 {#see_also|Optionals|Errors#}
2548 {#header_close#}2548 {#header_close#}
2549 {#header_open|defer#}2549 {#header_open|defer#}
2550 {#code_begin|test|defer#}2550 {#code_begin|test|defer#}
...@@ -3167,24 +3167,24 @@ test "inferred error set" {...@@ -3167,24 +3167,24 @@ test "inferred error set" {
3167 <p>TODO</p>3167 <p>TODO</p>
3168 {#header_close#}3168 {#header_close#}
3169 {#header_close#}3169 {#header_close#}
3170 {#header_open|Nullables#}3170 {#header_open|Optionals#}
3171 <p>3171 <p>
3172 One area that Zig provides safety without compromising efficiency or3172 One area that Zig provides safety without compromising efficiency or
3173 readability is with the nullable type.3173 readability is with the optional type.
3174 </p>3174 </p>
3175 <p>3175 <p>
3176 The question mark symbolizes the nullable type. You can convert a type to a nullable3176 The question mark symbolizes the optional type. You can convert a type to an optional
3177 type by putting a question mark in front of it, like this:3177 type by putting a question mark in front of it, like this:
3178 </p>3178 </p>
3179 {#code_begin|syntax#}3179 {#code_begin|syntax#}
3180// normal integer3180// normal integer
3181const normal_int: i32 = 1234;3181const normal_int: i32 = 1234;
31823182
3183// nullable integer3183// optional integer
3184const nullable_int: ?i32 = 5678;3184const optional_int: ?i32 = 5678;
3185 {#code_end#}3185 {#code_end#}
3186 <p>3186 <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>.
3188 </p>3188 </p>
3189 <p>3189 <p>
3190 Instead of integers, let's talk about pointers. Null references are the source of many runtime3190 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;...@@ -3193,8 +3193,8 @@ const nullable_int: ?i32 = 5678;
3193 </p>3193 </p>
3194 <p>Zig does not have them.</p>3194 <p>Zig does not have them.</p>
3195 <p>3195 <p>
3196 Instead, you can use a nullable pointer. This secretly compiles down to a normal pointer,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 nullable type. But the compiler3197 since we know we can use 0 as the null value for the optional type. But the compiler
3198 can check your work and make sure you don't assign null to something that can't be null.3198 can check your work and make sure you don't assign null to something that can't be null.
3199 </p>3199 </p>
3200 <p>3200 <p>
...@@ -3226,7 +3226,7 @@ fn doAThing() ?*Foo {...@@ -3226,7 +3226,7 @@ fn doAThing() ?*Foo {
3226 <p>3226 <p>
3227 Here, Zig is at least as convenient, if not more, than C. And, the type of "ptr"3227 Here, Zig is at least as convenient, if not more, than C. And, the type of "ptr"
3228 is <code>*u8</code> <em>not</em> <code>?*u8</code>. The <code>??</code> operator3228 is <code>*u8</code> <em>not</em> <code>?*u8</code>. The <code>??</code> operator
3229 unwrapped the nullable type and therefore <code>ptr</code> is guaranteed to be non-null everywhere3229 unwrapped the optional type and therefore <code>ptr</code> is guaranteed to be non-null everywhere
3230 it is used in the function.3230 it is used in the function.
3231 </p>3231 </p>
3232 <p>3232 <p>
...@@ -3245,10 +3245,10 @@ fn doAThing() ?*Foo {...@@ -3245,10 +3245,10 @@ fn doAThing() ?*Foo {
3245 In Zig you can accomplish the same thing:3245 In Zig you can accomplish the same thing:
3246 </p>3246 </p>
3247 {#code_begin|syntax#}3247 {#code_begin|syntax#}
3248fn doAThing(nullable_foo: ?*Foo) void {3248fn doAThing(optional_foo: ?*Foo) void {
3249 // do some stuff3249 // do some stuff
32503250
3251 if (nullable_foo) |foo| {3251 if (optional_foo) |foo| {
3252 doSomethingWithFoo(foo);3252 doSomethingWithFoo(foo);
3253 }3253 }
32543254
...@@ -3257,7 +3257,7 @@ fn doAThing(nullable_foo: ?*Foo) void {...@@ -3257,7 +3257,7 @@ fn doAThing(nullable_foo: ?*Foo) void {
3257 {#code_end#}3257 {#code_end#}
3258 <p>3258 <p>
3259 Once again, the notable thing here is that inside the if block,3259 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, which3260 <code>foo</code> is no longer an optional pointer, it is a pointer, which
3261 cannot be null.3261 cannot be null.
3262 </p>3262 </p>
3263 <p>3263 <p>
...@@ -3267,20 +3267,20 @@ fn doAThing(nullable_foo: ?*Foo) void {...@@ -3267,20 +3267,20 @@ fn doAThing(nullable_foo: ?*Foo) void {
3267 The optimizer can sometimes make better decisions knowing that pointer arguments3267 The optimizer can sometimes make better decisions knowing that pointer arguments
3268 cannot be null.3268 cannot be null.
3269 </p>3269 </p>
3270 {#header_open|Nullable Type#}3270 {#header_open|Optional Type#}
3271 <p>A nullable is created by putting <code>?</code> in front of a type. You can use compile-time3271 <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 a nullable:</p>3272 reflection to access the child type of an optional:</p>
3273 {#code_begin|test#}3273 {#code_begin|test#}
3274const assert = @import("std").debug.assert;3274const assert = @import("std").debug.assert;
32753275
3276test "nullable type" {3276test "optional type" {
3277 // Declare a nullable and implicitly cast from null:3277 // Declare an optional and implicitly cast from null:
3278 var foo: ?i32 = null;3278 var foo: ?i32 = null;
32793279
3280 // Implicitly cast from child type of a nullable3280 // Implicitly cast from child type of an optional
3281 foo = 1234;3281 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:
3284 comptime assert(@typeOf(foo).Child == i32);3284 comptime assert(@typeOf(foo).Child == i32);
3285}3285}
3286 {#code_end#}3286 {#code_end#}
...@@ -4888,7 +4888,7 @@ pub const TypeId = enum {...@@ -4888,7 +4888,7 @@ pub const TypeId = enum {
4888 ComptimeInt,4888 ComptimeInt,
4889 Undefined,4889 Undefined,
4890 Null,4890 Null,
4891 Nullable,4891 Optional,
4892 ErrorUnion,4892 ErrorUnion,
4893 Error,4893 Error,
4894 Enum,4894 Enum,
...@@ -4922,7 +4922,7 @@ pub const TypeInfo = union(TypeId) {...@@ -4922,7 +4922,7 @@ pub const TypeInfo = union(TypeId) {
4922 ComptimeInt: void,4922 ComptimeInt: void,
4923 Undefined: void,4923 Undefined: void,
4924 Null: void,4924 Null: void,
4925 Nullable: Nullable,4925 Optional: Optional,
4926 ErrorUnion: ErrorUnion,4926 ErrorUnion: ErrorUnion,
4927 ErrorSet: ErrorSet,4927 ErrorSet: ErrorSet,
4928 Enum: Enum,4928 Enum: Enum,
...@@ -4975,7 +4975,7 @@ pub const TypeInfo = union(TypeId) {...@@ -4975,7 +4975,7 @@ pub const TypeInfo = union(TypeId) {
4975 defs: []Definition,4975 defs: []Definition,
4976 };4976 };
49774977
4978 pub const Nullable = struct {4978 pub const Optional = struct {
4979 child: type,4979 child: type,
4980 };4980 };
49814981
...@@ -5366,8 +5366,8 @@ comptime {...@@ -5366,8 +5366,8 @@ comptime {
5366 <p>At compile-time:</p>5366 <p>At compile-time:</p>
5367 {#code_begin|test_err|unable to unwrap null#}5367 {#code_begin|test_err|unable to unwrap null#}
5368comptime {5368comptime {
5369 const nullable_number: ?i32 = null;5369 const optional_number: ?i32 = null;
5370 const number = ??nullable_number;5370 const number = optional_number.?;
5371}5371}
5372 {#code_end#}5372 {#code_end#}
5373 <p>At runtime crashes with the message <code>attempt to unwrap null</code> and a stack trace.</p>5373 <p>At runtime crashes with the message <code>attempt to unwrap null</code> and a stack trace.</p>
...@@ -5376,9 +5376,9 @@ comptime {...@@ -5376,9 +5376,9 @@ comptime {
5376 {#code_begin|exe|test#}5376 {#code_begin|exe|test#}
5377const warn = @import("std").debug.warn;5377const warn = @import("std").debug.warn;
5378pub fn main() void {5378pub 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| {
5382 warn("got number: {}\n", number);5382 warn("got number: {}\n", number);
5383 } else {5383 } else {
5384 warn("it's null\n");5384 warn("it's null\n");
...@@ -5939,9 +5939,9 @@ AsmInputItem = "[" Symbol "]" String "(" Expression ")"...@@ -5939,9 +5939,9 @@ AsmInputItem = "[" Symbol "]" String "(" Expression ")"
59395939
5940AsmClobbers= ":" list(String, ",")5940AsmClobbers= ":" list(String, ",")
59415941
5942UnwrapExpression = BoolOrExpression (UnwrapNullable | UnwrapError) | BoolOrExpression5942UnwrapExpression = BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression
59435943
5944UnwrapNullable = "??" Expression5944UnwrapOptional = "??" Expression
59455945
5946UnwrapError = "catch" option("|" Symbol "|") Expression5946UnwrapError = "catch" option("|" Symbol "|") Expression
59475947
...@@ -6015,12 +6015,10 @@ MultiplyOperator = "||" | "*" | "/" | "%" | "**" | "*%"...@@ -6015,12 +6015,10 @@ MultiplyOperator = "||" | "*" | "/" | "%" | "**" | "*%"
60156015
6016PrefixOpExpression = PrefixOp TypeExpr | SuffixOpExpression6016PrefixOpExpression = 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
6020FieldAccessExpression = "." Symbol6020FieldAccessExpression = "." Symbol
60216021
6022PtrDerefExpression = ".*"
6023
6024FnCallExpression = "(" list(Expression, ",") ")"6022FnCallExpression = "(" list(Expression, ",") ")"
60256023
6026ArrayAccessExpression = "[" Expression "]"6024ArrayAccessExpression = "[" Expression "]"
...@@ -6033,7 +6031,7 @@ ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")...@@ -6033,7 +6031,7 @@ ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")
60336031
6034StructLiteralField = "." Symbol "=" Expression6032StructLiteralField = "." 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
6038PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ContainerDecl | ("continue" option(":" Symbol)) | ErrorSetDecl | PromiseType6036PrimaryExpression = 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;...@@ -7,7 +7,7 @@ const allocator = std.debug.global_allocator;
77
8pub fn main() !void {8pub fn main() !void {
9 var args_it = os.args();9 var args_it = os.args();
10 const exe = try unwrapArg(??args_it.next(allocator));10 const exe = try unwrapArg(args_it.next(allocator).?);
11 var catted_anything = false;11 var catted_anything = false;
12 var stdout_file = try io.getStdOut();12 var stdout_file = try io.getStdOut();
1313
src-self-hosted/arg.zig+5-5
...@@ -99,7 +99,7 @@ pub const Args = struct {...@@ -99,7 +99,7 @@ pub const Args = struct {
99 error.ArgumentNotInAllowedSet => {99 error.ArgumentNotInAllowedSet => {
100 std.debug.warn("argument '{}' is invalid for flag '{}'\n", args[i], arg);100 std.debug.warn("argument '{}' is invalid for flag '{}'\n", args[i], arg);
101 std.debug.warn("allowed options are ");101 std.debug.warn("allowed options are ");
102 for (??flag.allowed_set) |possible| {102 for (flag.allowed_set.?) |possible| {
103 std.debug.warn("'{}' ", possible);103 std.debug.warn("'{}' ", possible);
104 }104 }
105 std.debug.warn("\n");105 std.debug.warn("\n");
...@@ -276,14 +276,14 @@ test "parse arguments" {...@@ -276,14 +276,14 @@ test "parse arguments" {
276 debug.assert(!args.present("help2"));276 debug.assert(!args.present("help2"));
277 debug.assert(!args.present("init"));277 debug.assert(!args.present("init"));
278278
279 debug.assert(mem.eql(u8, ??args.single("build-file"), "build.zig"));279 debug.assert(mem.eql(u8, args.single("build-file").?, "build.zig"));
280 debug.assert(mem.eql(u8, ??args.single("color"), "on"));280 debug.assert(mem.eql(u8, args.single("color").?, "on"));
281281
282 const objects = ??args.many("object");282 const objects = args.many("object").?;
283 debug.assert(mem.eql(u8, objects[0], "obj1"));283 debug.assert(mem.eql(u8, objects[0], "obj1"));
284 debug.assert(mem.eql(u8, objects[1], "obj2"));284 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
288 const pos = args.positionals.toSliceConst();288 const pos = args.positionals.toSliceConst();
289 debug.assert(mem.eql(u8, pos[0], "build"));289 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);...@@ -8,6 +8,6 @@ pub const ContextRef = removeNullability(c.LLVMContextRef);
8pub const BuilderRef = removeNullability(c.LLVMBuilderRef);8pub const BuilderRef = removeNullability(c.LLVMBuilderRef);
99
10fn removeNullability(comptime T: type) type {10fn removeNullability(comptime T: type) type {
11 comptime assert(@typeId(T) == builtin.TypeId.Nullable);11 comptime assert(@typeId(T) == builtin.TypeId.Optional);
12 return T.Child;12 return T.Child;
13}13}
src-self-hosted/main.zig+4-4
...@@ -490,7 +490,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo...@@ -490,7 +490,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo
490 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n");490 try stderr.print("encountered --pkg-end with no matching --pkg-begin\n");
491 os.exit(1);491 os.exit(1);
492 }492 }
493 cur_pkg = ??cur_pkg.parent;493 cur_pkg = cur_pkg.parent.?;
494 }494 }
495 }495 }
496496
...@@ -514,7 +514,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo...@@ -514,7 +514,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo
514 },514 },
515 }515 }
516516
517 const basename = os.path.basename(??in_file);517 const basename = os.path.basename(in_file.?);
518 var it = mem.split(basename, ".");518 var it = mem.split(basename, ".");
519 const root_name = it.next() ?? {519 const root_name = it.next() ?? {
520 try stderr.write("file name cannot be empty\n");520 try stderr.write("file name cannot be empty\n");
...@@ -523,12 +523,12 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo...@@ -523,12 +523,12 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Mo
523523
524 const asm_a = flags.many("assembly");524 const asm_a = flags.many("assembly");
525 const obj_a = flags.many("object");525 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)) {
527 try stderr.write("Expected source file argument or at least one --object or --assembly argument\n");527 try stderr.write("Expected source file argument or at least one --object or --assembly argument\n");
528 os.exit(1);528 os.exit(1);
529 }529 }
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)) {
532 try stderr.write("When building an object file, --object arguments are invalid\n");532 try stderr.write("When building an object file, --object arguments are invalid\n");
533 os.exit(1);533 os.exit(1);
534 }534 }
src/all_types.hpp+22-22
...@@ -145,8 +145,8 @@ enum ConstPtrSpecial {...@@ -145,8 +145,8 @@ enum ConstPtrSpecial {
145 // emit a binary with a compile time known address.145 // emit a binary with a compile time known address.
146 // In this case index is the numeric address value.146 // In this case index is the numeric address value.
147 // We also use this for null pointer. We need the data layout for ConstCastOnly == true147 // 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_ptr148 // types to be the same, so all optionals of pointer types use x_ptr
149 // instead of x_nullable149 // instead of x_optional
150 ConstPtrSpecialHardCodedAddr,150 ConstPtrSpecialHardCodedAddr,
151 // This means that the pointer represents memory of assigning to _.151 // This means that the pointer represents memory of assigning to _.
152 // That is, storing discards the data, and loading is invalid.152 // That is, storing discards the data, and loading is invalid.
...@@ -222,10 +222,10 @@ enum RuntimeHintErrorUnion {...@@ -222,10 +222,10 @@ enum RuntimeHintErrorUnion {
222 RuntimeHintErrorUnionNonError,222 RuntimeHintErrorUnionNonError,
223};223};
224224
225enum RuntimeHintMaybe {225enum RuntimeHintOptional {
226 RuntimeHintMaybeUnknown,226 RuntimeHintOptionalUnknown,
227 RuntimeHintMaybeNull, // TODO is this value even possible? if this is the case it might mean the const value is compile time known.227 RuntimeHintOptionalNull, // TODO is this value even possible? if this is the case it might mean the const value is compile time known.
228 RuntimeHintMaybeNonNull,228 RuntimeHintOptionalNonNull,
229};229};
230230
231enum RuntimeHintPtr {231enum RuntimeHintPtr {
...@@ -254,7 +254,7 @@ struct ConstExprValue {...@@ -254,7 +254,7 @@ struct ConstExprValue {
254 bool x_bool;254 bool x_bool;
255 ConstBoundFnValue x_bound_fn;255 ConstBoundFnValue x_bound_fn;
256 TypeTableEntry *x_type;256 TypeTableEntry *x_type;
257 ConstExprValue *x_nullable;257 ConstExprValue *x_optional;
258 ConstErrValue x_err_union;258 ConstErrValue x_err_union;
259 ErrorTableEntry *x_err_set;259 ErrorTableEntry *x_err_set;
260 BigInt x_enum_tag;260 BigInt x_enum_tag;
...@@ -268,7 +268,7 @@ struct ConstExprValue {...@@ -268,7 +268,7 @@ struct ConstExprValue {
268268
269 // populated if special == ConstValSpecialRuntime269 // populated if special == ConstValSpecialRuntime
270 RuntimeHintErrorUnion rh_error_union;270 RuntimeHintErrorUnion rh_error_union;
271 RuntimeHintMaybe rh_maybe;271 RuntimeHintOptional rh_maybe;
272 RuntimeHintPtr rh_ptr;272 RuntimeHintPtr rh_ptr;
273 } data;273 } data;
274};274};
...@@ -556,7 +556,7 @@ enum BinOpType {...@@ -556,7 +556,7 @@ enum BinOpType {
556 BinOpTypeMultWrap,556 BinOpTypeMultWrap,
557 BinOpTypeDiv,557 BinOpTypeDiv,
558 BinOpTypeMod,558 BinOpTypeMod,
559 BinOpTypeUnwrapMaybe,559 BinOpTypeUnwrapOptional,
560 BinOpTypeArrayCat,560 BinOpTypeArrayCat,
561 BinOpTypeArrayMult,561 BinOpTypeArrayMult,
562 BinOpTypeErrorUnion,562 BinOpTypeErrorUnion,
...@@ -623,8 +623,8 @@ enum PrefixOp {...@@ -623,8 +623,8 @@ enum PrefixOp {
623 PrefixOpBinNot,623 PrefixOpBinNot,
624 PrefixOpNegation,624 PrefixOpNegation,
625 PrefixOpNegationWrap,625 PrefixOpNegationWrap,
626 PrefixOpMaybe,626 PrefixOpOptional,
627 PrefixOpUnwrapMaybe,627 PrefixOpUnwrapOptional,
628 PrefixOpAddrOf,628 PrefixOpAddrOf,
629};629};
630630
...@@ -1052,7 +1052,7 @@ struct TypeTableEntryStruct {...@@ -1052,7 +1052,7 @@ struct TypeTableEntryStruct {
1052 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;1052 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
1053};1053};
10541054
1055struct TypeTableEntryMaybe {1055struct TypeTableEntryOptional {
1056 TypeTableEntry *child_type;1056 TypeTableEntry *child_type;
1057};1057};
10581058
...@@ -1175,7 +1175,7 @@ enum TypeTableEntryId {...@@ -1175,7 +1175,7 @@ enum TypeTableEntryId {
1175 TypeTableEntryIdComptimeInt,1175 TypeTableEntryIdComptimeInt,
1176 TypeTableEntryIdUndefined,1176 TypeTableEntryIdUndefined,
1177 TypeTableEntryIdNull,1177 TypeTableEntryIdNull,
1178 TypeTableEntryIdMaybe,1178 TypeTableEntryIdOptional,
1179 TypeTableEntryIdErrorUnion,1179 TypeTableEntryIdErrorUnion,
1180 TypeTableEntryIdErrorSet,1180 TypeTableEntryIdErrorSet,
1181 TypeTableEntryIdEnum,1181 TypeTableEntryIdEnum,
...@@ -1206,7 +1206,7 @@ struct TypeTableEntry {...@@ -1206,7 +1206,7 @@ struct TypeTableEntry {
1206 TypeTableEntryFloat floating;1206 TypeTableEntryFloat floating;
1207 TypeTableEntryArray array;1207 TypeTableEntryArray array;
1208 TypeTableEntryStruct structure;1208 TypeTableEntryStruct structure;
1209 TypeTableEntryMaybe maybe;1209 TypeTableEntryOptional maybe;
1210 TypeTableEntryErrorUnion error_union;1210 TypeTableEntryErrorUnion error_union;
1211 TypeTableEntryErrorSet error_set;1211 TypeTableEntryErrorSet error_set;
1212 TypeTableEntryEnum enumeration;1212 TypeTableEntryEnum enumeration;
...@@ -1402,7 +1402,7 @@ enum PanicMsgId {...@@ -1402,7 +1402,7 @@ enum PanicMsgId {
1402 PanicMsgIdRemainderDivisionByZero,1402 PanicMsgIdRemainderDivisionByZero,
1403 PanicMsgIdExactDivisionRemainder,1403 PanicMsgIdExactDivisionRemainder,
1404 PanicMsgIdSliceWidenRemainder,1404 PanicMsgIdSliceWidenRemainder,
1405 PanicMsgIdUnwrapMaybeFail,1405 PanicMsgIdUnwrapOptionalFail,
1406 PanicMsgIdInvalidErrorCode,1406 PanicMsgIdInvalidErrorCode,
1407 PanicMsgIdIncorrectAlignment,1407 PanicMsgIdIncorrectAlignment,
1408 PanicMsgIdBadUnionField,1408 PanicMsgIdBadUnionField,
...@@ -2016,8 +2016,8 @@ enum IrInstructionId {...@@ -2016,8 +2016,8 @@ enum IrInstructionId {
2016 IrInstructionIdAsm,2016 IrInstructionIdAsm,
2017 IrInstructionIdSizeOf,2017 IrInstructionIdSizeOf,
2018 IrInstructionIdTestNonNull,2018 IrInstructionIdTestNonNull,
2019 IrInstructionIdUnwrapMaybe,2019 IrInstructionIdUnwrapOptional,
2020 IrInstructionIdMaybeWrap,2020 IrInstructionIdOptionalWrap,
2021 IrInstructionIdUnionTag,2021 IrInstructionIdUnionTag,
2022 IrInstructionIdClz,2022 IrInstructionIdClz,
2023 IrInstructionIdCtz,2023 IrInstructionIdCtz,
...@@ -2184,7 +2184,7 @@ enum IrUnOp {...@@ -2184,7 +2184,7 @@ enum IrUnOp {
2184 IrUnOpNegation,2184 IrUnOpNegation,
2185 IrUnOpNegationWrap,2185 IrUnOpNegationWrap,
2186 IrUnOpDereference,2186 IrUnOpDereference,
2187 IrUnOpMaybe,2187 IrUnOpOptional,
2188};2188};
21892189
2190struct IrInstructionUnOp {2190struct IrInstructionUnOp {
...@@ -2487,7 +2487,7 @@ struct IrInstructionTestNonNull {...@@ -2487,7 +2487,7 @@ struct IrInstructionTestNonNull {
2487 IrInstruction *value;2487 IrInstruction *value;
2488};2488};
24892489
2490struct IrInstructionUnwrapMaybe {2490struct IrInstructionUnwrapOptional {
2491 IrInstruction base;2491 IrInstruction base;
24922492
2493 IrInstruction *value;2493 IrInstruction *value;
...@@ -2745,7 +2745,7 @@ struct IrInstructionUnwrapErrPayload {...@@ -2745,7 +2745,7 @@ struct IrInstructionUnwrapErrPayload {
2745 bool safety_check_on;2745 bool safety_check_on;
2746};2746};
27472747
2748struct IrInstructionMaybeWrap {2748struct IrInstructionOptionalWrap {
2749 IrInstruction base;2749 IrInstruction base;
27502750
2751 IrInstruction *value;2751 IrInstruction *value;
...@@ -2954,10 +2954,10 @@ struct IrInstructionExport {...@@ -2954,10 +2954,10 @@ struct IrInstructionExport {
2954struct IrInstructionErrorReturnTrace {2954struct IrInstructionErrorReturnTrace {
2955 IrInstruction base;2955 IrInstruction base;
29562956
2957 enum Nullable {2957 enum Optional {
2958 Null,2958 Null,
2959 NonNull,2959 NonNull,
2960 } nullable;2960 } optional;
2961};2961};
29622962
2963struct IrInstructionErrorUnion {2963struct IrInstructionErrorUnion {
src/analyze.cpp+35-35
...@@ -236,7 +236,7 @@ bool type_is_complete(TypeTableEntry *type_entry) {...@@ -236,7 +236,7 @@ bool type_is_complete(TypeTableEntry *type_entry) {
236 case TypeTableEntryIdComptimeInt:236 case TypeTableEntryIdComptimeInt:
237 case TypeTableEntryIdUndefined:237 case TypeTableEntryIdUndefined:
238 case TypeTableEntryIdNull:238 case TypeTableEntryIdNull:
239 case TypeTableEntryIdMaybe:239 case TypeTableEntryIdOptional:
240 case TypeTableEntryIdErrorUnion:240 case TypeTableEntryIdErrorUnion:
241 case TypeTableEntryIdErrorSet:241 case TypeTableEntryIdErrorSet:
242 case TypeTableEntryIdFn:242 case TypeTableEntryIdFn:
...@@ -272,7 +272,7 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) {...@@ -272,7 +272,7 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) {
272 case TypeTableEntryIdComptimeInt:272 case TypeTableEntryIdComptimeInt:
273 case TypeTableEntryIdUndefined:273 case TypeTableEntryIdUndefined:
274 case TypeTableEntryIdNull:274 case TypeTableEntryIdNull:
275 case TypeTableEntryIdMaybe:275 case TypeTableEntryIdOptional:
276 case TypeTableEntryIdErrorUnion:276 case TypeTableEntryIdErrorUnion:
277 case TypeTableEntryIdErrorSet:277 case TypeTableEntryIdErrorSet:
278 case TypeTableEntryIdFn:278 case TypeTableEntryIdFn:
...@@ -520,7 +520,7 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {...@@ -520,7 +520,7 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {
520 } else {520 } else {
521 ensure_complete_type(g, child_type);521 ensure_complete_type(g, child_type);
522522
523 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdMaybe);523 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOptional);
524 assert(child_type->type_ref || child_type->zero_bits);524 assert(child_type->type_ref || child_type->zero_bits);
525 assert(child_type->di_type);525 assert(child_type->di_type);
526 entry->is_copyable = type_is_copyable(g, child_type);526 entry->is_copyable = type_is_copyable(g, child_type);
...@@ -1361,7 +1361,7 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {...@@ -1361,7 +1361,7 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {
1361 return type_entry->data.structure.layout == ContainerLayoutPacked;1361 return type_entry->data.structure.layout == ContainerLayoutPacked;
1362 case TypeTableEntryIdUnion:1362 case TypeTableEntryIdUnion:
1363 return type_entry->data.unionation.layout == ContainerLayoutPacked;1363 return type_entry->data.unionation.layout == ContainerLayoutPacked;
1364 case TypeTableEntryIdMaybe:1364 case TypeTableEntryIdOptional:
1365 {1365 {
1366 TypeTableEntry *child_type = type_entry->data.maybe.child_type;1366 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
1367 return type_is_codegen_pointer(child_type);1367 return type_is_codegen_pointer(child_type);
...@@ -1415,7 +1415,7 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {...@@ -1415,7 +1415,7 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {
1415 return type_allowed_in_extern(g, type_entry->data.pointer.child_type);1415 return type_allowed_in_extern(g, type_entry->data.pointer.child_type);
1416 case TypeTableEntryIdStruct:1416 case TypeTableEntryIdStruct:
1417 return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked;1417 return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked;
1418 case TypeTableEntryIdMaybe:1418 case TypeTableEntryIdOptional:
1419 {1419 {
1420 TypeTableEntry *child_type = type_entry->data.maybe.child_type;1420 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
1421 return child_type->id == TypeTableEntryIdPointer || child_type->id == TypeTableEntryIdFn;1421 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...@@ -1538,7 +1538,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1538 case TypeTableEntryIdPointer:1538 case TypeTableEntryIdPointer:
1539 case TypeTableEntryIdArray:1539 case TypeTableEntryIdArray:
1540 case TypeTableEntryIdStruct:1540 case TypeTableEntryIdStruct:
1541 case TypeTableEntryIdMaybe:1541 case TypeTableEntryIdOptional:
1542 case TypeTableEntryIdErrorUnion:1542 case TypeTableEntryIdErrorUnion:
1543 case TypeTableEntryIdErrorSet:1543 case TypeTableEntryIdErrorSet:
1544 case TypeTableEntryIdEnum:1544 case TypeTableEntryIdEnum:
...@@ -1632,7 +1632,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1632,7 +1632,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1632 case TypeTableEntryIdPointer:1632 case TypeTableEntryIdPointer:
1633 case TypeTableEntryIdArray:1633 case TypeTableEntryIdArray:
1634 case TypeTableEntryIdStruct:1634 case TypeTableEntryIdStruct:
1635 case TypeTableEntryIdMaybe:1635 case TypeTableEntryIdOptional:
1636 case TypeTableEntryIdErrorUnion:1636 case TypeTableEntryIdErrorUnion:
1637 case TypeTableEntryIdErrorSet:1637 case TypeTableEntryIdErrorSet:
1638 case TypeTableEntryIdEnum:1638 case TypeTableEntryIdEnum:
...@@ -2985,8 +2985,8 @@ static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {...@@ -2985,8 +2985,8 @@ static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {
2985 return wrong_panic_prototype(g, proto_node, fn_type);2985 return wrong_panic_prototype(g, proto_node, fn_type);
2986 }2986 }
29872987
2988 TypeTableEntry *nullable_ptr_to_stack_trace_type = get_maybe_type(g, get_ptr_to_stack_trace_type(g));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 != nullable_ptr_to_stack_trace_type) {2989 if (fn_type_id->param_info[1].type != optional_ptr_to_stack_trace_type) {
2990 return wrong_panic_prototype(g, proto_node, fn_type);2990 return wrong_panic_prototype(g, proto_node, fn_type);
2991 }2991 }
29922992
...@@ -3368,7 +3368,7 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt...@@ -3368,7 +3368,7 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
3368 case TypeTableEntryIdPointer:3368 case TypeTableEntryIdPointer:
3369 case TypeTableEntryIdArray:3369 case TypeTableEntryIdArray:
3370 case TypeTableEntryIdStruct:3370 case TypeTableEntryIdStruct:
3371 case TypeTableEntryIdMaybe:3371 case TypeTableEntryIdOptional:
3372 case TypeTableEntryIdErrorUnion:3372 case TypeTableEntryIdErrorUnion:
3373 case TypeTableEntryIdErrorSet:3373 case TypeTableEntryIdErrorSet:
3374 case TypeTableEntryIdEnum:3374 case TypeTableEntryIdEnum:
...@@ -3746,7 +3746,7 @@ static bool is_container(TypeTableEntry *type_entry) {...@@ -3746,7 +3746,7 @@ static bool is_container(TypeTableEntry *type_entry) {
3746 case TypeTableEntryIdComptimeInt:3746 case TypeTableEntryIdComptimeInt:
3747 case TypeTableEntryIdUndefined:3747 case TypeTableEntryIdUndefined:
3748 case TypeTableEntryIdNull:3748 case TypeTableEntryIdNull:
3749 case TypeTableEntryIdMaybe:3749 case TypeTableEntryIdOptional:
3750 case TypeTableEntryIdErrorUnion:3750 case TypeTableEntryIdErrorUnion:
3751 case TypeTableEntryIdErrorSet:3751 case TypeTableEntryIdErrorSet:
3752 case TypeTableEntryIdFn:3752 case TypeTableEntryIdFn:
...@@ -3805,7 +3805,7 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {...@@ -3805,7 +3805,7 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {
3805 case TypeTableEntryIdComptimeInt:3805 case TypeTableEntryIdComptimeInt:
3806 case TypeTableEntryIdUndefined:3806 case TypeTableEntryIdUndefined:
3807 case TypeTableEntryIdNull:3807 case TypeTableEntryIdNull:
3808 case TypeTableEntryIdMaybe:3808 case TypeTableEntryIdOptional:
3809 case TypeTableEntryIdErrorUnion:3809 case TypeTableEntryIdErrorUnion:
3810 case TypeTableEntryIdErrorSet:3810 case TypeTableEntryIdErrorSet:
3811 case TypeTableEntryIdFn:3811 case TypeTableEntryIdFn:
...@@ -3824,7 +3824,7 @@ TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {...@@ -3824,7 +3824,7 @@ TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {
3824 if (type->id == TypeTableEntryIdPointer) return type;3824 if (type->id == TypeTableEntryIdPointer) return type;
3825 if (type->id == TypeTableEntryIdFn) return type;3825 if (type->id == TypeTableEntryIdFn) return type;
3826 if (type->id == TypeTableEntryIdPromise) return type;3826 if (type->id == TypeTableEntryIdPromise) return type;
3827 if (type->id == TypeTableEntryIdMaybe) {3827 if (type->id == TypeTableEntryIdOptional) {
3828 if (type->data.maybe.child_type->id == TypeTableEntryIdPointer) return type->data.maybe.child_type;3828 if (type->data.maybe.child_type->id == TypeTableEntryIdPointer) return type->data.maybe.child_type;
3829 if (type->data.maybe.child_type->id == TypeTableEntryIdFn) return type->data.maybe.child_type;3829 if (type->data.maybe.child_type->id == TypeTableEntryIdFn) return type->data.maybe.child_type;
3830 if (type->data.maybe.child_type->id == TypeTableEntryIdPromise) return type->data.maybe.child_type;3830 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) {...@@ -4331,7 +4331,7 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
4331 return type_has_bits(type_entry);4331 return type_has_bits(type_entry);
4332 case TypeTableEntryIdErrorUnion:4332 case TypeTableEntryIdErrorUnion:
4333 return type_has_bits(type_entry->data.error_union.payload_type);4333 return type_has_bits(type_entry->data.error_union.payload_type);
4334 case TypeTableEntryIdMaybe:4334 case TypeTableEntryIdOptional:
4335 return type_has_bits(type_entry->data.maybe.child_type) &&4335 return type_has_bits(type_entry->data.maybe.child_type) &&
4336 !type_is_codegen_pointer(type_entry->data.maybe.child_type);4336 !type_is_codegen_pointer(type_entry->data.maybe.child_type);
4337 case TypeTableEntryIdUnion:4337 case TypeTableEntryIdUnion:
...@@ -4709,12 +4709,12 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4709,12 +4709,12 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4709 case TypeTableEntryIdUnion:4709 case TypeTableEntryIdUnion:
4710 // TODO better hashing algorithm4710 // TODO better hashing algorithm
4711 return 2709806591;4711 return 2709806591;
4712 case TypeTableEntryIdMaybe:4712 case TypeTableEntryIdOptional:
4713 if (get_codegen_ptr_type(const_val->type) != nullptr) {4713 if (get_codegen_ptr_type(const_val->type) != nullptr) {
4714 return hash_const_val(const_val) * 1992916303;4714 return hash_const_val(const_val) * 1992916303;
4715 } else {4715 } else {
4716 if (const_val->data.x_nullable) {4716 if (const_val->data.x_optional) {
4717 return hash_const_val(const_val->data.x_nullable) * 1992916303;4717 return hash_const_val(const_val->data.x_optional) * 1992916303;
4718 } else {4718 } else {
4719 return 4016830364;4719 return 4016830364;
4720 }4720 }
...@@ -4817,12 +4817,12 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {...@@ -4817,12 +4817,12 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
4817 }4817 }
4818 return false;4818 return false;
48194819
4820 case TypeTableEntryIdMaybe:4820 case TypeTableEntryIdOptional:
4821 if (get_codegen_ptr_type(value->type) != nullptr)4821 if (get_codegen_ptr_type(value->type) != nullptr)
4822 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;4822 return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
4823 if (value->data.x_nullable == nullptr)4823 if (value->data.x_optional == nullptr)
4824 return false;4824 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
4827 case TypeTableEntryIdErrorUnion:4827 case TypeTableEntryIdErrorUnion:
4828 if (value->data.x_err_union.err != nullptr)4828 if (value->data.x_err_union.err != nullptr)
...@@ -4869,7 +4869,7 @@ static bool return_type_is_cacheable(TypeTableEntry *return_type) {...@@ -4869,7 +4869,7 @@ static bool return_type_is_cacheable(TypeTableEntry *return_type) {
4869 case TypeTableEntryIdUnion:4869 case TypeTableEntryIdUnion:
4870 return false;4870 return false;
48714871
4872 case TypeTableEntryIdMaybe:4872 case TypeTableEntryIdOptional:
4873 return return_type_is_cacheable(return_type->data.maybe.child_type);4873 return return_type_is_cacheable(return_type->data.maybe.child_type);
48744874
4875 case TypeTableEntryIdErrorUnion:4875 case TypeTableEntryIdErrorUnion:
...@@ -4978,7 +4978,7 @@ bool type_requires_comptime(TypeTableEntry *type_entry) {...@@ -4978,7 +4978,7 @@ bool type_requires_comptime(TypeTableEntry *type_entry) {
4978 case TypeTableEntryIdUnion:4978 case TypeTableEntryIdUnion:
4979 assert(type_has_zero_bits_known(type_entry));4979 assert(type_has_zero_bits_known(type_entry));
4980 return type_entry->data.unionation.requires_comptime;4980 return type_entry->data.unionation.requires_comptime;
4981 case TypeTableEntryIdMaybe:4981 case TypeTableEntryIdOptional:
4982 return type_requires_comptime(type_entry->data.maybe.child_type);4982 return type_requires_comptime(type_entry->data.maybe.child_type);
4983 case TypeTableEntryIdErrorUnion:4983 case TypeTableEntryIdErrorUnion:
4984 return type_requires_comptime(type_entry->data.error_union.payload_type);4984 return type_requires_comptime(type_entry->data.error_union.payload_type);
...@@ -5460,13 +5460,13 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -5460,13 +5460,13 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
5460 zig_panic("TODO");5460 zig_panic("TODO");
5461 case TypeTableEntryIdNull:5461 case TypeTableEntryIdNull:
5462 zig_panic("TODO");5462 zig_panic("TODO");
5463 case TypeTableEntryIdMaybe:5463 case TypeTableEntryIdOptional:
5464 if (get_codegen_ptr_type(a->type) != nullptr)5464 if (get_codegen_ptr_type(a->type) != nullptr)
5465 return const_values_equal_ptr(a, b);5465 return const_values_equal_ptr(a, b);
5466 if (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_nullable == nullptr && b->data.x_nullable == nullptr);5467 return (a->data.x_optional == nullptr && b->data.x_optional == nullptr);
5468 } else {5468 } 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);
5470 }5470 }
5471 case TypeTableEntryIdErrorUnion:5471 case TypeTableEntryIdErrorUnion:
5472 zig_panic("TODO");5472 zig_panic("TODO");
...@@ -5708,12 +5708,12 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5708,12 +5708,12 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5708 buf_appendf(buf, "undefined");5708 buf_appendf(buf, "undefined");
5709 return;5709 return;
5710 }5710 }
5711 case TypeTableEntryIdMaybe:5711 case TypeTableEntryIdOptional:
5712 {5712 {
5713 if (get_codegen_ptr_type(const_val->type) != nullptr)5713 if (get_codegen_ptr_type(const_val->type) != nullptr)
5714 return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);5714 return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);
5715 if (const_val->data.x_nullable) {5715 if (const_val->data.x_optional) {
5716 render_const_value(g, buf, const_val->data.x_nullable);5716 render_const_value(g, buf, const_val->data.x_optional);
5717 } else {5717 } else {
5718 buf_appendf(buf, "null");5718 buf_appendf(buf, "null");
5719 }5719 }
...@@ -5819,7 +5819,7 @@ uint32_t type_id_hash(TypeId x) {...@@ -5819,7 +5819,7 @@ uint32_t type_id_hash(TypeId x) {
5819 case TypeTableEntryIdComptimeInt:5819 case TypeTableEntryIdComptimeInt:
5820 case TypeTableEntryIdUndefined:5820 case TypeTableEntryIdUndefined:
5821 case TypeTableEntryIdNull:5821 case TypeTableEntryIdNull:
5822 case TypeTableEntryIdMaybe:5822 case TypeTableEntryIdOptional:
5823 case TypeTableEntryIdErrorSet:5823 case TypeTableEntryIdErrorSet:
5824 case TypeTableEntryIdEnum:5824 case TypeTableEntryIdEnum:
5825 case TypeTableEntryIdUnion:5825 case TypeTableEntryIdUnion:
...@@ -5865,7 +5865,7 @@ bool type_id_eql(TypeId a, TypeId b) {...@@ -5865,7 +5865,7 @@ bool type_id_eql(TypeId a, TypeId b) {
5865 case TypeTableEntryIdComptimeInt:5865 case TypeTableEntryIdComptimeInt:
5866 case TypeTableEntryIdUndefined:5866 case TypeTableEntryIdUndefined:
5867 case TypeTableEntryIdNull:5867 case TypeTableEntryIdNull:
5868 case TypeTableEntryIdMaybe:5868 case TypeTableEntryIdOptional:
5869 case TypeTableEntryIdPromise:5869 case TypeTableEntryIdPromise:
5870 case TypeTableEntryIdErrorSet:5870 case TypeTableEntryIdErrorSet:
5871 case TypeTableEntryIdEnum:5871 case TypeTableEntryIdEnum:
...@@ -5987,7 +5987,7 @@ static const TypeTableEntryId all_type_ids[] = {...@@ -5987,7 +5987,7 @@ static const TypeTableEntryId all_type_ids[] = {
5987 TypeTableEntryIdComptimeInt,5987 TypeTableEntryIdComptimeInt,
5988 TypeTableEntryIdUndefined,5988 TypeTableEntryIdUndefined,
5989 TypeTableEntryIdNull,5989 TypeTableEntryIdNull,
5990 TypeTableEntryIdMaybe,5990 TypeTableEntryIdOptional,
5991 TypeTableEntryIdErrorUnion,5991 TypeTableEntryIdErrorUnion,
5992 TypeTableEntryIdErrorSet,5992 TypeTableEntryIdErrorSet,
5993 TypeTableEntryIdEnum,5993 TypeTableEntryIdEnum,
...@@ -6042,7 +6042,7 @@ size_t type_id_index(TypeTableEntry *entry) {...@@ -6042,7 +6042,7 @@ size_t type_id_index(TypeTableEntry *entry) {
6042 return 11;6042 return 11;
6043 case TypeTableEntryIdNull:6043 case TypeTableEntryIdNull:
6044 return 12;6044 return 12;
6045 case TypeTableEntryIdMaybe:6045 case TypeTableEntryIdOptional:
6046 return 13;6046 return 13;
6047 case TypeTableEntryIdErrorUnion:6047 case TypeTableEntryIdErrorUnion:
6048 return 14;6048 return 14;
...@@ -6100,8 +6100,8 @@ const char *type_id_name(TypeTableEntryId id) {...@@ -6100,8 +6100,8 @@ const char *type_id_name(TypeTableEntryId id) {
6100 return "Undefined";6100 return "Undefined";
6101 case TypeTableEntryIdNull:6101 case TypeTableEntryIdNull:
6102 return "Null";6102 return "Null";
6103 case TypeTableEntryIdMaybe:6103 case TypeTableEntryIdOptional:
6104 return "Nullable";6104 return "Optional";
6105 case TypeTableEntryIdErrorUnion:6105 case TypeTableEntryIdErrorUnion:
6106 return "ErrorUnion";6106 return "ErrorUnion";
6107 case TypeTableEntryIdErrorSet:6107 case TypeTableEntryIdErrorSet:
src/ast_render.cpp+3-3
...@@ -50,7 +50,7 @@ static const char *bin_op_str(BinOpType bin_op) {...@@ -50,7 +50,7 @@ static const char *bin_op_str(BinOpType bin_op) {
50 case BinOpTypeAssignBitXor: return "^=";50 case BinOpTypeAssignBitXor: return "^=";
51 case BinOpTypeAssignBitOr: return "|=";51 case BinOpTypeAssignBitOr: return "|=";
52 case BinOpTypeAssignMergeErrorSets: return "||=";52 case BinOpTypeAssignMergeErrorSets: return "||=";
53 case BinOpTypeUnwrapMaybe: return "??";53 case BinOpTypeUnwrapOptional: return "??";
54 case BinOpTypeArrayCat: return "++";54 case BinOpTypeArrayCat: return "++";
55 case BinOpTypeArrayMult: return "**";55 case BinOpTypeArrayMult: return "**";
56 case BinOpTypeErrorUnion: return "!";56 case BinOpTypeErrorUnion: return "!";
...@@ -66,8 +66,8 @@ static const char *prefix_op_str(PrefixOp prefix_op) {...@@ -66,8 +66,8 @@ static const char *prefix_op_str(PrefixOp prefix_op) {
66 case PrefixOpNegationWrap: return "-%";66 case PrefixOpNegationWrap: return "-%";
67 case PrefixOpBoolNot: return "!";67 case PrefixOpBoolNot: return "!";
68 case PrefixOpBinNot: return "~";68 case PrefixOpBinNot: return "~";
69 case PrefixOpMaybe: return "?";69 case PrefixOpOptional: return "?";
70 case PrefixOpUnwrapMaybe: return "??";70 case PrefixOpUnwrapOptional: return "??";
71 case PrefixOpAddrOf: return "&";71 case PrefixOpAddrOf: return "&";
72 }72 }
73 zig_unreachable();73 zig_unreachable();
src/codegen.cpp+30-30
...@@ -865,7 +865,7 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {...@@ -865,7 +865,7 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
865 return buf_create_from_str("exact division produced remainder");865 return buf_create_from_str("exact division produced remainder");
866 case PanicMsgIdSliceWidenRemainder:866 case PanicMsgIdSliceWidenRemainder:
867 return buf_create_from_str("slice widening size mismatch");867 return buf_create_from_str("slice widening size mismatch");
868 case PanicMsgIdUnwrapMaybeFail:868 case PanicMsgIdUnwrapOptionalFail:
869 return buf_create_from_str("attempt to unwrap null");869 return buf_create_from_str("attempt to unwrap null");
870 case PanicMsgIdUnreachable:870 case PanicMsgIdUnreachable:
871 return buf_create_from_str("reached unreachable code");871 return buf_create_from_str("reached unreachable code");
...@@ -2734,7 +2734,7 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst...@@ -2734,7 +2734,7 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst
27342734
2735 switch (op_id) {2735 switch (op_id) {
2736 case IrUnOpInvalid:2736 case IrUnOpInvalid:
2737 case IrUnOpMaybe:2737 case IrUnOpOptional:
2738 case IrUnOpDereference:2738 case IrUnOpDereference:
2739 zig_unreachable();2739 zig_unreachable();
2740 case IrUnOpNegation:2740 case IrUnOpNegation:
...@@ -3333,7 +3333,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru...@@ -3333,7 +3333,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
3333}3333}
33343334
3335static LLVMValueRef gen_non_null_bit(CodeGen *g, TypeTableEntry *maybe_type, LLVMValueRef maybe_handle) {3335static 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);
3337 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;3337 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
3338 if (child_type->zero_bits) {3338 if (child_type->zero_bits) {
3339 return maybe_handle;3339 return maybe_handle;
...@@ -3355,23 +3355,23 @@ static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable...@@ -3355,23 +3355,23 @@ static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable
3355}3355}
33563356
3357static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,3357static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
3358 IrInstructionUnwrapMaybe *instruction)3358 IrInstructionUnwrapOptional *instruction)
3359{3359{
3360 TypeTableEntry *ptr_type = instruction->value->value.type;3360 TypeTableEntry *ptr_type = instruction->value->value.type;
3361 assert(ptr_type->id == TypeTableEntryIdPointer);3361 assert(ptr_type->id == TypeTableEntryIdPointer);
3362 TypeTableEntry *maybe_type = ptr_type->data.pointer.child_type;3362 TypeTableEntry *maybe_type = ptr_type->data.pointer.child_type;
3363 assert(maybe_type->id == TypeTableEntryIdMaybe);3363 assert(maybe_type->id == TypeTableEntryIdOptional);
3364 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;3364 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
3365 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);3365 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);
3366 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);3366 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);
3367 if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on) {3367 if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on) {
3368 LLVMValueRef non_null_bit = gen_non_null_bit(g, maybe_type, maybe_handle);3368 LLVMValueRef non_null_bit = gen_non_null_bit(g, maybe_type, maybe_handle);
3369 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeOk");3369 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapOptionalOk");
3370 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeFail");3370 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapOptionalFail");
3371 LLVMBuildCondBr(g->builder, non_null_bit, ok_block, fail_block);3371 LLVMBuildCondBr(g->builder, non_null_bit, ok_block, fail_block);
33723372
3373 LLVMPositionBuilderAtEnd(g->builder, fail_block);3373 LLVMPositionBuilderAtEnd(g->builder, fail_block);
3374 gen_safety_crash(g, PanicMsgIdUnwrapMaybeFail);3374 gen_safety_crash(g, PanicMsgIdUnwrapOptionalFail);
33753375
3376 LLVMPositionBuilderAtEnd(g->builder, ok_block);3376 LLVMPositionBuilderAtEnd(g->builder, ok_block);
3377 }3377 }
...@@ -3593,17 +3593,17 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I...@@ -3593,17 +3593,17 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
3593 } else if (target_type->id == TypeTableEntryIdFn) {3593 } else if (target_type->id == TypeTableEntryIdFn) {
3594 align_bytes = target_type->data.fn.fn_type_id.alignment;3594 align_bytes = target_type->data.fn.fn_type_id.alignment;
3595 ptr_val = target_val;3595 ptr_val = target_val;
3596 } else if (target_type->id == TypeTableEntryIdMaybe &&3596 } else if (target_type->id == TypeTableEntryIdOptional &&
3597 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)3597 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
3598 {3598 {
3599 align_bytes = target_type->data.maybe.child_type->data.pointer.alignment;3599 align_bytes = target_type->data.maybe.child_type->data.pointer.alignment;
3600 ptr_val = target_val;3600 ptr_val = target_val;
3601 } else if (target_type->id == TypeTableEntryIdMaybe &&3601 } else if (target_type->id == TypeTableEntryIdOptional &&
3602 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)3602 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)
3603 {3603 {
3604 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;3604 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;
3605 ptr_val = target_val;3605 ptr_val = target_val;
3606 } else if (target_type->id == TypeTableEntryIdMaybe &&3606 } else if (target_type->id == TypeTableEntryIdOptional &&
3607 target_type->data.maybe.child_type->id == TypeTableEntryIdPromise)3607 target_type->data.maybe.child_type->id == TypeTableEntryIdPromise)
3608 {3608 {
3609 zig_panic("TODO audit this function");3609 zig_panic("TODO audit this function");
...@@ -3705,7 +3705,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn...@@ -3705,7 +3705,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
3705 success_order, failure_order, instruction->is_weak);3705 success_order, failure_order, instruction->is_weak);
37063706
3707 TypeTableEntry *maybe_type = instruction->base.value.type;3707 TypeTableEntry *maybe_type = instruction->base.value.type;
3708 assert(maybe_type->id == TypeTableEntryIdMaybe);3708 assert(maybe_type->id == TypeTableEntryIdOptional);
3709 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;3709 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
37103710
3711 if (type_is_codegen_pointer(child_type)) {3711 if (type_is_codegen_pointer(child_type)) {
...@@ -4115,10 +4115,10 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu...@@ -4115,10 +4115,10 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
4115 }4115 }
4116}4116}
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) {
4119 TypeTableEntry *wanted_type = instruction->base.value.type;4119 TypeTableEntry *wanted_type = instruction->base.value.type;
41204120
4121 assert(wanted_type->id == TypeTableEntryIdMaybe);4121 assert(wanted_type->id == TypeTableEntryIdOptional);
41224122
4123 TypeTableEntry *child_type = wanted_type->data.maybe.child_type;4123 TypeTableEntry *child_type = wanted_type->data.maybe.child_type;
41244124
...@@ -4699,8 +4699,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -4699,8 +4699,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
4699 return ir_render_asm(g, executable, (IrInstructionAsm *)instruction);4699 return ir_render_asm(g, executable, (IrInstructionAsm *)instruction);
4700 case IrInstructionIdTestNonNull:4700 case IrInstructionIdTestNonNull:
4701 return ir_render_test_non_null(g, executable, (IrInstructionTestNonNull *)instruction);4701 return ir_render_test_non_null(g, executable, (IrInstructionTestNonNull *)instruction);
4702 case IrInstructionIdUnwrapMaybe:4702 case IrInstructionIdUnwrapOptional:
4703 return ir_render_unwrap_maybe(g, executable, (IrInstructionUnwrapMaybe *)instruction);4703 return ir_render_unwrap_maybe(g, executable, (IrInstructionUnwrapOptional *)instruction);
4704 case IrInstructionIdClz:4704 case IrInstructionIdClz:
4705 return ir_render_clz(g, executable, (IrInstructionClz *)instruction);4705 return ir_render_clz(g, executable, (IrInstructionClz *)instruction);
4706 case IrInstructionIdCtz:4706 case IrInstructionIdCtz:
...@@ -4741,8 +4741,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -4741,8 +4741,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
4741 return ir_render_unwrap_err_code(g, executable, (IrInstructionUnwrapErrCode *)instruction);4741 return ir_render_unwrap_err_code(g, executable, (IrInstructionUnwrapErrCode *)instruction);
4742 case IrInstructionIdUnwrapErrPayload:4742 case IrInstructionIdUnwrapErrPayload:
4743 return ir_render_unwrap_err_payload(g, executable, (IrInstructionUnwrapErrPayload *)instruction);4743 return ir_render_unwrap_err_payload(g, executable, (IrInstructionUnwrapErrPayload *)instruction);
4744 case IrInstructionIdMaybeWrap:4744 case IrInstructionIdOptionalWrap:
4745 return ir_render_maybe_wrap(g, executable, (IrInstructionMaybeWrap *)instruction);4745 return ir_render_maybe_wrap(g, executable, (IrInstructionOptionalWrap *)instruction);
4746 case IrInstructionIdErrWrapCode:4746 case IrInstructionIdErrWrapCode:
4747 return ir_render_err_wrap_code(g, executable, (IrInstructionErrWrapCode *)instruction);4747 return ir_render_err_wrap_code(g, executable, (IrInstructionErrWrapCode *)instruction);
4748 case IrInstructionIdErrWrapPayload:4748 case IrInstructionIdErrWrapPayload:
...@@ -4972,7 +4972,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con...@@ -4972,7 +4972,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
4972 }4972 }
4973 case TypeTableEntryIdPointer:4973 case TypeTableEntryIdPointer:
4974 case TypeTableEntryIdFn:4974 case TypeTableEntryIdFn:
4975 case TypeTableEntryIdMaybe:4975 case TypeTableEntryIdOptional:
4976 case TypeTableEntryIdPromise:4976 case TypeTableEntryIdPromise:
4977 {4977 {
4978 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");4978 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...@@ -5137,19 +5137,19 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5137 } else {5137 } else {
5138 return LLVMConstNull(LLVMInt1Type());5138 return LLVMConstNull(LLVMInt1Type());
5139 }5139 }
5140 case TypeTableEntryIdMaybe:5140 case TypeTableEntryIdOptional:
5141 {5141 {
5142 TypeTableEntry *child_type = type_entry->data.maybe.child_type;5142 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
5143 if (child_type->zero_bits) {5143 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);
5145 } else if (type_is_codegen_pointer(child_type)) {5145 } else if (type_is_codegen_pointer(child_type)) {
5146 return gen_const_val_ptr(g, const_val, name);5146 return gen_const_val_ptr(g, const_val, name);
5147 } else {5147 } else {
5148 LLVMValueRef child_val;5148 LLVMValueRef child_val;
5149 LLVMValueRef maybe_val;5149 LLVMValueRef maybe_val;
5150 bool make_unnamed_struct;5150 bool make_unnamed_struct;
5151 if (const_val->data.x_nullable) {5151 if (const_val->data.x_optional) {
5152 child_val = gen_const_val(g, const_val->data.x_nullable, "");5152 child_val = gen_const_val(g, const_val->data.x_optional, "");
5153 maybe_val = LLVMConstAllOnes(LLVMInt1Type());5153 maybe_val = LLVMConstAllOnes(LLVMInt1Type());
51545154
5155 make_unnamed_struct = is_llvm_value_unnamed_type(const_val->type, child_val);5155 make_unnamed_struct = is_llvm_value_unnamed_type(const_val->type, child_val);
...@@ -5755,8 +5755,8 @@ static void do_code_gen(CodeGen *g) {...@@ -5755,8 +5755,8 @@ static void do_code_gen(CodeGen *g) {
5755 } else if (instruction->id == IrInstructionIdSlice) {5755 } else if (instruction->id == IrInstructionIdSlice) {
5756 IrInstructionSlice *slice_instruction = (IrInstructionSlice *)instruction;5756 IrInstructionSlice *slice_instruction = (IrInstructionSlice *)instruction;
5757 slot = &slice_instruction->tmp_ptr;5757 slot = &slice_instruction->tmp_ptr;
5758 } else if (instruction->id == IrInstructionIdMaybeWrap) {5758 } else if (instruction->id == IrInstructionIdOptionalWrap) {
5759 IrInstructionMaybeWrap *maybe_wrap_instruction = (IrInstructionMaybeWrap *)instruction;5759 IrInstructionOptionalWrap *maybe_wrap_instruction = (IrInstructionOptionalWrap *)instruction;
5760 slot = &maybe_wrap_instruction->tmp_ptr;5760 slot = &maybe_wrap_instruction->tmp_ptr;
5761 } else if (instruction->id == IrInstructionIdErrWrapPayload) {5761 } else if (instruction->id == IrInstructionIdErrWrapPayload) {
5762 IrInstructionErrWrapPayload *err_wrap_payload_instruction = (IrInstructionErrWrapPayload *)instruction;5762 IrInstructionErrWrapPayload *err_wrap_payload_instruction = (IrInstructionErrWrapPayload *)instruction;
...@@ -6511,7 +6511,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -6511,7 +6511,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
6511 " ComptimeInt: void,\n"6511 " ComptimeInt: void,\n"
6512 " Undefined: void,\n"6512 " Undefined: void,\n"
6513 " Null: void,\n"6513 " Null: void,\n"
6514 " Nullable: Nullable,\n"6514 " Optional: Optional,\n"
6515 " ErrorUnion: ErrorUnion,\n"6515 " ErrorUnion: ErrorUnion,\n"
6516 " ErrorSet: ErrorSet,\n"6516 " ErrorSet: ErrorSet,\n"
6517 " Enum: Enum,\n"6517 " Enum: Enum,\n"
...@@ -6570,7 +6570,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -6570,7 +6570,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
6570 " defs: []Definition,\n"6570 " defs: []Definition,\n"
6571 " };\n"6571 " };\n"
6572 "\n"6572 "\n"
6573 " pub const Nullable = struct {\n"6573 " pub const Optional = struct {\n"
6574 " child: type,\n"6574 " child: type,\n"
6575 " };\n"6575 " };\n"
6576 "\n"6576 "\n"
...@@ -7145,7 +7145,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry...@@ -7145,7 +7145,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry
7145 case TypeTableEntryIdArray:7145 case TypeTableEntryIdArray:
7146 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);7146 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);
7147 return;7147 return;
7148 case TypeTableEntryIdMaybe:7148 case TypeTableEntryIdOptional:
7149 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);7149 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);
7150 return;7150 return;
7151 case TypeTableEntryIdFn:7151 case TypeTableEntryIdFn:
...@@ -7234,7 +7234,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf...@@ -7234,7 +7234,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
7234 buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf));7234 buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf));
7235 break;7235 break;
7236 }7236 }
7237 case TypeTableEntryIdMaybe:7237 case TypeTableEntryIdOptional:
7238 {7238 {
7239 TypeTableEntry *child_type = type_entry->data.maybe.child_type;7239 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
7240 if (child_type->zero_bits) {7240 if (child_type->zero_bits) {
...@@ -7448,7 +7448,7 @@ static void gen_h_file(CodeGen *g) {...@@ -7448,7 +7448,7 @@ static void gen_h_file(CodeGen *g) {
7448 case TypeTableEntryIdBlock:7448 case TypeTableEntryIdBlock:
7449 case TypeTableEntryIdBoundFn:7449 case TypeTableEntryIdBoundFn:
7450 case TypeTableEntryIdArgTuple:7450 case TypeTableEntryIdArgTuple:
7451 case TypeTableEntryIdMaybe:7451 case TypeTableEntryIdOptional:
7452 case TypeTableEntryIdFn:7452 case TypeTableEntryIdFn:
7453 case TypeTableEntryIdPromise:7453 case TypeTableEntryIdPromise:
7454 zig_unreachable();7454 zig_unreachable();
src/ir.cpp+99-99
...@@ -47,7 +47,7 @@ enum ConstCastResultId {...@@ -47,7 +47,7 @@ enum ConstCastResultId {
47 ConstCastResultIdErrSetGlobal,47 ConstCastResultIdErrSetGlobal,
48 ConstCastResultIdPointerChild,48 ConstCastResultIdPointerChild,
49 ConstCastResultIdSliceChild,49 ConstCastResultIdSliceChild,
50 ConstCastResultIdNullableChild,50 ConstCastResultIdOptionalChild,
51 ConstCastResultIdErrorUnionPayload,51 ConstCastResultIdErrorUnionPayload,
52 ConstCastResultIdErrorUnionErrorSet,52 ConstCastResultIdErrorUnionErrorSet,
53 ConstCastResultIdFnAlign,53 ConstCastResultIdFnAlign,
...@@ -86,7 +86,7 @@ struct ConstCastOnly {...@@ -86,7 +86,7 @@ struct ConstCastOnly {
86 ConstCastErrSetMismatch error_set;86 ConstCastErrSetMismatch error_set;
87 ConstCastOnly *pointer_child;87 ConstCastOnly *pointer_child;
88 ConstCastOnly *slice_child;88 ConstCastOnly *slice_child;
89 ConstCastOnly *nullable_child;89 ConstCastOnly *optional_child;
90 ConstCastOnly *error_union_payload;90 ConstCastOnly *error_union_payload;
91 ConstCastOnly *error_union_error_set;91 ConstCastOnly *error_union_error_set;
92 ConstCastOnly *return_type;92 ConstCastOnly *return_type;
...@@ -372,8 +372,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTestNonNull *) {...@@ -372,8 +372,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTestNonNull *) {
372 return IrInstructionIdTestNonNull;372 return IrInstructionIdTestNonNull;
373}373}
374374
375static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapMaybe *) {375static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapOptional *) {
376 return IrInstructionIdUnwrapMaybe;376 return IrInstructionIdUnwrapOptional;
377}377}
378378
379static constexpr IrInstructionId ir_instruction_id(IrInstructionClz *) {379static constexpr IrInstructionId ir_instruction_id(IrInstructionClz *) {
...@@ -524,8 +524,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload...@@ -524,8 +524,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload
524 return IrInstructionIdUnwrapErrPayload;524 return IrInstructionIdUnwrapErrPayload;
525}525}
526526
527static constexpr IrInstructionId ir_instruction_id(IrInstructionMaybeWrap *) {527static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalWrap *) {
528 return IrInstructionIdMaybeWrap;528 return IrInstructionIdOptionalWrap;
529}529}
530530
531static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapPayload *) {531static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapPayload *) {
...@@ -1571,7 +1571,7 @@ static IrInstruction *ir_build_test_nonnull_from(IrBuilder *irb, IrInstruction *...@@ -1571,7 +1571,7 @@ static IrInstruction *ir_build_test_nonnull_from(IrBuilder *irb, IrInstruction *
1571static IrInstruction *ir_build_unwrap_maybe(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value,1571static IrInstruction *ir_build_unwrap_maybe(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value,
1572 bool safety_check_on)1572 bool safety_check_on)
1573{1573{
1574 IrInstructionUnwrapMaybe *instruction = ir_build_instruction<IrInstructionUnwrapMaybe>(irb, scope, source_node);1574 IrInstructionUnwrapOptional *instruction = ir_build_instruction<IrInstructionUnwrapOptional>(irb, scope, source_node);
1575 instruction->value = value;1575 instruction->value = value;
1576 instruction->safety_check_on = safety_check_on;1576 instruction->safety_check_on = safety_check_on;
15771577
...@@ -1590,7 +1590,7 @@ static IrInstruction *ir_build_unwrap_maybe_from(IrBuilder *irb, IrInstruction *...@@ -1590,7 +1590,7 @@ static IrInstruction *ir_build_unwrap_maybe_from(IrBuilder *irb, IrInstruction *
1590}1590}
15911591
1592static IrInstruction *ir_build_maybe_wrap(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {1592static 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);
1594 instruction->value = value;1594 instruction->value = value;
15951595
1596 ir_ref_instruction(value, irb->current_basic_block);1596 ir_ref_instruction(value, irb->current_basic_block);
...@@ -2496,9 +2496,9 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2496,9 +2496,9 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s
2496 return &instruction->base;2496 return &instruction->base;
2497}2497}
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) {
2500 IrInstructionErrorReturnTrace *instruction = ir_build_instruction<IrInstructionErrorReturnTrace>(irb, scope, source_node);2500 IrInstructionErrorReturnTrace *instruction = ir_build_instruction<IrInstructionErrorReturnTrace>(irb, scope, source_node);
2501 instruction->nullable = nullable;2501 instruction->optional = optional;
25022502
2503 return &instruction->base;2503 return &instruction->base;
2504}2504}
...@@ -3295,9 +3295,9 @@ static IrInstruction *ir_gen_maybe_ok_or(IrBuilder *irb, Scope *parent_scope, As...@@ -3295,9 +3295,9 @@ static IrInstruction *ir_gen_maybe_ok_or(IrBuilder *irb, Scope *parent_scope, As
3295 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null);3295 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null);
3296 }3296 }
32973297
3298 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "MaybeNonNull");3298 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");
3299 IrBasicBlock *null_block = ir_create_basic_block(irb, parent_scope, "MaybeNull");3299 IrBasicBlock *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");
3300 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "MaybeEnd");3300 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd");
3301 ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);3301 ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);
33023302
3303 ir_set_cursor_at_end_and_append_block(irb, null_block);3303 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)...@@ -3426,7 +3426,7 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node)
3426 return ir_gen_bin_op_id(irb, scope, node, IrBinOpArrayMult);3426 return ir_gen_bin_op_id(irb, scope, node, IrBinOpArrayMult);
3427 case BinOpTypeMergeErrorSets:3427 case BinOpTypeMergeErrorSets:
3428 return ir_gen_bin_op_id(irb, scope, node, IrBinOpMergeErrorSets);3428 return ir_gen_bin_op_id(irb, scope, node, IrBinOpMergeErrorSets);
3429 case BinOpTypeUnwrapMaybe:3429 case BinOpTypeUnwrapOptional:
3430 return ir_gen_maybe_ok_or(irb, scope, node);3430 return ir_gen_maybe_ok_or(irb, scope, node);
3431 case BinOpTypeErrorUnion:3431 case BinOpTypeErrorUnion:
3432 return ir_gen_error_union(irb, scope, node);3432 return ir_gen_error_union(irb, scope, node);
...@@ -4703,9 +4703,9 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod...@@ -4703,9 +4703,9 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
4703 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegation), lval);4703 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegation), lval);
4704 case PrefixOpNegationWrap:4704 case PrefixOpNegationWrap:
4705 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegationWrap), lval);4705 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpNegationWrap), lval);
4706 case PrefixOpMaybe:4706 case PrefixOpOptional:
4707 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe), lval);4707 return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpOptional), lval);
4708 case PrefixOpUnwrapMaybe:4708 case PrefixOpUnwrapOptional:
4709 return ir_gen_maybe_assert_ok(irb, scope, node, lval);4709 return ir_gen_maybe_assert_ok(irb, scope, node, lval);
4710 case PrefixOpAddrOf: {4710 case PrefixOpAddrOf: {
4711 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;4711 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...@@ -5370,9 +5370,9 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
5370 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);5370 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);
5371 IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node, maybe_val);5371 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");5373 IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "OptionalThen");
5374 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "MaybeElse");5374 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "OptionalElse");
5375 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "MaybeEndIf");5375 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");
53765376
5377 IrInstruction *is_comptime;5377 IrInstruction *is_comptime;
5378 if (ir_should_inline(irb->exec, scope)) {5378 if (ir_should_inline(irb->exec, scope)) {
...@@ -7519,7 +7519,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -7519,7 +7519,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
7519 }7519 }
7520 } else if (const_val_fits_in_num_lit(const_val, other_type)) {7520 } else if (const_val_fits_in_num_lit(const_val, other_type)) {
7521 return true;7521 return true;
7522 } else if (other_type->id == TypeTableEntryIdMaybe) {7522 } else if (other_type->id == TypeTableEntryIdOptional) {
7523 TypeTableEntry *child_type = other_type->data.maybe.child_type;7523 TypeTableEntry *child_type = other_type->data.maybe.child_type;
7524 if (const_val_fits_in_num_lit(const_val, child_type)) {7524 if (const_val_fits_in_num_lit(const_val, child_type)) {
7525 return true;7525 return true;
...@@ -7663,7 +7663,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry...@@ -7663,7 +7663,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
7663 return result;7663 return result;
76647664
7665 // * and [*] can do a const-cast-only to ?* and ?[*], respectively7665 // * and [*] can do a const-cast-only to ?* and ?[*], respectively
7666 if (expected_type->id == TypeTableEntryIdMaybe &&7666 if (expected_type->id == TypeTableEntryIdOptional &&
7667 expected_type->data.maybe.child_type->id == TypeTableEntryIdPointer &&7667 expected_type->data.maybe.child_type->id == TypeTableEntryIdPointer &&
7668 actual_type->id == TypeTableEntryIdPointer)7668 actual_type->id == TypeTableEntryIdPointer)
7669 {7669 {
...@@ -7718,12 +7718,12 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry...@@ -7718,12 +7718,12 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
7718 }7718 }
77197719
7720 // maybe7720 // maybe
7721 if (expected_type->id == TypeTableEntryIdMaybe && actual_type->id == TypeTableEntryIdMaybe) {7721 if (expected_type->id == TypeTableEntryIdOptional && actual_type->id == TypeTableEntryIdOptional) {
7722 ConstCastOnly child = types_match_const_cast_only(ira, expected_type->data.maybe.child_type, actual_type->data.maybe.child_type, source_node);7722 ConstCastOnly child = types_match_const_cast_only(ira, expected_type->data.maybe.child_type, actual_type->data.maybe.child_type, source_node);
7723 if (child.id != ConstCastResultIdOk) {7723 if (child.id != ConstCastResultIdOk) {
7724 result.id = ConstCastResultIdNullableChild;7724 result.id = ConstCastResultIdOptionalChild;
7725 result.data.nullable_child = allocate_nonzero<ConstCastOnly>(1);7725 result.data.optional_child = allocate_nonzero<ConstCastOnly>(1);
7726 *result.data.nullable_child = child;7726 *result.data.optional_child = child;
7727 }7727 }
7728 return result;7728 return result;
7729 }7729 }
...@@ -7925,7 +7925,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -7925,7 +7925,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
7925 }7925 }
79267926
7927 // implicit conversion from ?T to ?U7927 // 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) {
7929 ImplicitCastMatchResult res = ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type,7929 ImplicitCastMatchResult res = ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type,
7930 actual_type->data.maybe.child_type, value);7930 actual_type->data.maybe.child_type, value);
7931 if (res != ImplicitCastMatchResultNo)7931 if (res != ImplicitCastMatchResultNo)
...@@ -7933,7 +7933,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -7933,7 +7933,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
7933 }7933 }
79347934
7935 // implicit conversion from non maybe type to maybe type7935 // implicit conversion from non maybe type to maybe type
7936 if (expected_type->id == TypeTableEntryIdMaybe) {7936 if (expected_type->id == TypeTableEntryIdOptional) {
7937 ImplicitCastMatchResult res = ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type,7937 ImplicitCastMatchResult res = ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type,
7938 actual_type, value);7938 actual_type, value);
7939 if (res != ImplicitCastMatchResultNo)7939 if (res != ImplicitCastMatchResultNo)
...@@ -7941,7 +7941,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -7941,7 +7941,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
7941 }7941 }
79427942
7943 // implicit conversion from null literal to maybe type7943 // implicit conversion from null literal to maybe type
7944 if (expected_type->id == TypeTableEntryIdMaybe &&7944 if (expected_type->id == TypeTableEntryIdOptional &&
7945 actual_type->id == TypeTableEntryIdNull)7945 actual_type->id == TypeTableEntryIdNull)
7946 {7946 {
7947 return ImplicitCastMatchResultYes;7947 return ImplicitCastMatchResultYes;
...@@ -7963,7 +7963,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -7963,7 +7963,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
79637963
7964 // implicit conversion from T to U!?T7964 // implicit conversion from T to U!?T
7965 if (expected_type->id == TypeTableEntryIdErrorUnion &&7965 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 &&
7967 ir_types_match_with_implicit_cast(ira,7967 ir_types_match_with_implicit_cast(ira,
7968 expected_type->data.error_union.payload_type->data.maybe.child_type,7968 expected_type->data.error_union.payload_type->data.maybe.child_type,
7969 actual_type, value))7969 actual_type, value))
...@@ -8072,7 +8072,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -8072,7 +8072,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
8072 }8072 }
80738073
8074 // implicit [N]T to ?[]const T8074 // implicit [N]T to ?[]const T
8075 if (expected_type->id == TypeTableEntryIdMaybe &&8075 if (expected_type->id == TypeTableEntryIdOptional &&
8076 is_slice(expected_type->data.maybe.child_type) &&8076 is_slice(expected_type->data.maybe.child_type) &&
8077 actual_type->id == TypeTableEntryIdArray)8077 actual_type->id == TypeTableEntryIdArray)
8078 {8078 {
...@@ -8552,13 +8552,13 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -8552,13 +8552,13 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
8552 continue;8552 continue;
8553 }8553 }
85548554
8555 if (prev_type->id == TypeTableEntryIdMaybe &&8555 if (prev_type->id == TypeTableEntryIdOptional &&
8556 types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type, source_node).id == ConstCastResultIdOk)8556 types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type, source_node).id == ConstCastResultIdOk)
8557 {8557 {
8558 continue;8558 continue;
8559 }8559 }
85608560
8561 if (cur_type->id == TypeTableEntryIdMaybe &&8561 if (cur_type->id == TypeTableEntryIdOptional &&
8562 types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type, source_node).id == ConstCastResultIdOk)8562 types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type, source_node).id == ConstCastResultIdOk)
8563 {8563 {
8564 prev_inst = cur_inst;8564 prev_inst = cur_inst;
...@@ -8711,7 +8711,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod...@@ -8711,7 +8711,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
8711 ir_add_error_node(ira, source_node,8711 ir_add_error_node(ira, source_node,
8712 buf_sprintf("unable to make maybe out of number literal"));8712 buf_sprintf("unable to make maybe out of number literal"));
8713 return ira->codegen->builtin_types.entry_invalid;8713 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) {
8715 return prev_inst->value.type;8715 return prev_inst->value.type;
8716 } else {8716 } else {
8717 return get_maybe_type(ira->codegen, prev_inst->value.type);8717 return get_maybe_type(ira->codegen, prev_inst->value.type);
...@@ -9193,7 +9193,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -9193,7 +9193,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
9193}9193}
91949194
9195static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {9195static 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
9198 if (instr_is_comptime(value)) {9198 if (instr_is_comptime(value)) {
9199 TypeTableEntry *payload_type = wanted_type->data.maybe.child_type;9199 TypeTableEntry *payload_type = wanted_type->data.maybe.child_type;
...@@ -9211,7 +9211,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc...@@ -9211,7 +9211,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
9211 if (get_codegen_ptr_type(wanted_type) != nullptr) {9211 if (get_codegen_ptr_type(wanted_type) != nullptr) {
9212 copy_const_val(&const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst);9212 copy_const_val(&const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst);
9213 } else {9213 } else {
9214 const_instruction->base.value.data.x_nullable = val;9214 const_instruction->base.value.data.x_optional = val;
9215 }9215 }
9216 const_instruction->base.value.type = wanted_type;9216 const_instruction->base.value.type = wanted_type;
9217 return &const_instruction->base;9217 return &const_instruction->base;
...@@ -9219,7 +9219,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc...@@ -9219,7 +9219,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
92199219
9220 IrInstruction *result = ir_build_maybe_wrap(&ira->new_irb, source_instr->scope, source_instr->source_node, value);9220 IrInstruction *result = ir_build_maybe_wrap(&ira->new_irb, source_instr->scope, source_instr->source_node, value);
9221 result->value.type = wanted_type;9221 result->value.type = wanted_type;
9222 result->value.data.rh_maybe = RuntimeHintMaybeNonNull;9222 result->value.data.rh_maybe = RuntimeHintOptionalNonNull;
9223 ir_add_alloca(ira, result, wanted_type);9223 ir_add_alloca(ira, result, wanted_type);
9224 return result;9224 return result;
9225}9225}
...@@ -9361,7 +9361,7 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_...@@ -9361,7 +9361,7 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
9361}9361}
93629362
9363static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {9363static 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);
9365 assert(instr_is_comptime(value));9365 assert(instr_is_comptime(value));
93669366
9367 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);9367 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
...@@ -9373,7 +9373,7 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so...@@ -9373,7 +9373,7 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
9373 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr;9373 const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
9374 const_instruction->base.value.data.x_ptr.data.hard_coded_addr.addr = 0;9374 const_instruction->base.value.data.x_ptr.data.hard_coded_addr.addr = 0;
9375 } else {9375 } else {
9376 const_instruction->base.value.data.x_nullable = nullptr;9376 const_instruction->base.value.data.x_optional = nullptr;
9377 }9377 }
9378 const_instruction->base.value.type = wanted_type;9378 const_instruction->base.value.type = wanted_type;
9379 return &const_instruction->base;9379 return &const_instruction->base;
...@@ -9992,7 +9992,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -9992,7 +9992,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
9992 }9992 }
99939993
9994 // explicit cast from [N]T to ?[]const N9994 // explicit cast from [N]T to ?[]const N
9995 if (wanted_type->id == TypeTableEntryIdMaybe &&9995 if (wanted_type->id == TypeTableEntryIdOptional &&
9996 is_slice(wanted_type->data.maybe.child_type) &&9996 is_slice(wanted_type->data.maybe.child_type) &&
9997 actual_type->id == TypeTableEntryIdArray)9997 actual_type->id == TypeTableEntryIdArray)
9998 {9998 {
...@@ -10091,7 +10091,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10091,7 +10091,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1009110091
10092 // explicit cast from T to ?T10092 // explicit cast from T to ?T
10093 // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism10093 // 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) {
10095 TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type;10095 TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type;
10096 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk) {10096 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk) {
10097 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);10097 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...@@ -10120,7 +10120,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10120 }10120 }
1012110121
10122 // explicit cast from null literal to maybe type10122 // explicit cast from null literal to maybe type
10123 if (wanted_type->id == TypeTableEntryIdMaybe &&10123 if (wanted_type->id == TypeTableEntryIdOptional &&
10124 actual_type->id == TypeTableEntryIdNull)10124 actual_type->id == TypeTableEntryIdNull)
10125 {10125 {
10126 return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);10126 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...@@ -10173,8 +10173,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1017310173
10174 // explicit cast from T to E!?T10174 // explicit cast from T to E!?T
10175 if (wanted_type->id == TypeTableEntryIdErrorUnion &&10175 if (wanted_type->id == TypeTableEntryIdErrorUnion &&
10176 wanted_type->data.error_union.payload_type->id == TypeTableEntryIdMaybe &&10176 wanted_type->data.error_union.payload_type->id == TypeTableEntryIdOptional &&
10177 actual_type->id != TypeTableEntryIdMaybe)10177 actual_type->id != TypeTableEntryIdOptional)
10178 {10178 {
10179 TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;10179 TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;
10180 if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk ||10180 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) {...@@ -10737,13 +10737,13 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
10737 }10737 }
10738}10738}
1073910739
10740static bool nullable_value_is_null(ConstExprValue *val) {10740static bool optional_value_is_null(ConstExprValue *val) {
10741 assert(val->special == ConstValSpecialStatic);10741 assert(val->special == ConstValSpecialStatic);
10742 if (get_codegen_ptr_type(val->type) != nullptr) {10742 if (get_codegen_ptr_type(val->type) != nullptr) {
10743 return val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&10743 return val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
10744 val->data.x_ptr.data.hard_coded_addr.addr == 0;10744 val->data.x_ptr.data.hard_coded_addr.addr == 0;
10745 } else {10745 } else {
10746 return val->data.x_nullable == nullptr;10746 return val->data.x_optional == nullptr;
10747 }10747 }
10748}10748}
1074910749
...@@ -10755,8 +10755,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -10755,8 +10755,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
10755 IrBinOp op_id = bin_op_instruction->op_id;10755 IrBinOp op_id = bin_op_instruction->op_id;
10756 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);10756 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
10757 if (is_equality_cmp &&10757 if (is_equality_cmp &&
10758 ((op1->value.type->id == TypeTableEntryIdNull && op2->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 == TypeTableEntryIdMaybe) ||10759 (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdOptional) ||
10760 (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull)))10760 (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull)))
10761 {10761 {
10762 if (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull) {10762 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...@@ -10776,7 +10776,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
10776 ConstExprValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);10776 ConstExprValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);
10777 if (!maybe_val)10777 if (!maybe_val)
10778 return ira->codegen->builtin_types.entry_invalid;10778 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);
10780 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);10780 ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
10781 out_val->data.x_bool = (op_id == IrBinOpCmpEq) ? is_null : !is_null;10781 out_val->data.x_bool = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
10782 return ira->codegen->builtin_types.entry_bool;10782 return ira->codegen->builtin_types.entry_bool;
...@@ -10925,7 +10925,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -10925,7 +10925,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
10925 case TypeTableEntryIdStruct:10925 case TypeTableEntryIdStruct:
10926 case TypeTableEntryIdUndefined:10926 case TypeTableEntryIdUndefined:
10927 case TypeTableEntryIdNull:10927 case TypeTableEntryIdNull:
10928 case TypeTableEntryIdMaybe:10928 case TypeTableEntryIdOptional:
10929 case TypeTableEntryIdErrorUnion:10929 case TypeTableEntryIdErrorUnion:
10930 case TypeTableEntryIdUnion:10930 case TypeTableEntryIdUnion:
10931 ir_add_error_node(ira, source_node,10931 ir_add_error_node(ira, source_node,
...@@ -11998,7 +11998,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi...@@ -11998,7 +11998,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
11998 case TypeTableEntryIdComptimeInt:11998 case TypeTableEntryIdComptimeInt:
11999 case TypeTableEntryIdUndefined:11999 case TypeTableEntryIdUndefined:
12000 case TypeTableEntryIdNull:12000 case TypeTableEntryIdNull:
12001 case TypeTableEntryIdMaybe:12001 case TypeTableEntryIdOptional:
12002 case TypeTableEntryIdErrorUnion:12002 case TypeTableEntryIdErrorUnion:
12003 case TypeTableEntryIdErrorSet:12003 case TypeTableEntryIdErrorSet:
12004 case TypeTableEntryIdNamespace:12004 case TypeTableEntryIdNamespace:
...@@ -12022,7 +12022,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi...@@ -12022,7 +12022,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
12022 case TypeTableEntryIdComptimeInt:12022 case TypeTableEntryIdComptimeInt:
12023 case TypeTableEntryIdUndefined:12023 case TypeTableEntryIdUndefined:
12024 case TypeTableEntryIdNull:12024 case TypeTableEntryIdNull:
12025 case TypeTableEntryIdMaybe:12025 case TypeTableEntryIdOptional:
12026 case TypeTableEntryIdErrorUnion:12026 case TypeTableEntryIdErrorUnion:
12027 case TypeTableEntryIdErrorSet:12027 case TypeTableEntryIdErrorSet:
12028 zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));12028 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) {...@@ -12049,24 +12049,24 @@ static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) {
12049static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,12049static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
12050 IrInstructionErrorReturnTrace *instruction)12050 IrInstructionErrorReturnTrace *instruction)
12051{12051{
12052 if (instruction->nullable == IrInstructionErrorReturnTrace::Null) {12052 if (instruction->optional == IrInstructionErrorReturnTrace::Null) {
12053 TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen);12053 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);
12055 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {12055 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {
12056 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);12056 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);
12058 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;12058 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
12059 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;12059 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
12060 return nullable_type;12060 return optional_type;
12061 }12061 }
12062 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,12062 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);
12064 ir_link_new_instruction(new_instruction, &instruction->base);12064 ir_link_new_instruction(new_instruction, &instruction->base);
12065 return nullable_type;12065 return optional_type;
12066 } else {12066 } else {
12067 assert(ira->codegen->have_err_ret_tracing);12067 assert(ira->codegen->have_err_ret_tracing);
12068 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,12068 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);
12070 ir_link_new_instruction(new_instruction, &instruction->base);12070 ir_link_new_instruction(new_instruction, &instruction->base);
12071 return get_ptr_to_stack_trace_type(ira->codegen);12071 return get_ptr_to_stack_trace_type(ira->codegen);
12072 }12072 }
...@@ -12998,7 +12998,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op...@@ -12998,7 +12998,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
12998 case TypeTableEntryIdComptimeInt:12998 case TypeTableEntryIdComptimeInt:
12999 case TypeTableEntryIdUndefined:12999 case TypeTableEntryIdUndefined:
13000 case TypeTableEntryIdNull:13000 case TypeTableEntryIdNull:
13001 case TypeTableEntryIdMaybe:13001 case TypeTableEntryIdOptional:
13002 case TypeTableEntryIdErrorUnion:13002 case TypeTableEntryIdErrorUnion:
13003 case TypeTableEntryIdErrorSet:13003 case TypeTableEntryIdErrorSet:
13004 case TypeTableEntryIdEnum:13004 case TypeTableEntryIdEnum:
...@@ -13017,7 +13017,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op...@@ -13017,7 +13017,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
13017 case TypeTableEntryIdUnreachable:13017 case TypeTableEntryIdUnreachable:
13018 case TypeTableEntryIdOpaque:13018 case TypeTableEntryIdOpaque:
13019 ir_add_error_node(ira, un_op_instruction->base.source_node,13019 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)));
13021 return ira->codegen->builtin_types.entry_invalid;13021 return ira->codegen->builtin_types.entry_invalid;
13022 }13022 }
13023 zig_unreachable();13023 zig_unreachable();
...@@ -13109,7 +13109,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio...@@ -13109,7 +13109,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio
13109 return ir_analyze_negation(ira, un_op_instruction);13109 return ir_analyze_negation(ira, un_op_instruction);
13110 case IrUnOpDereference:13110 case IrUnOpDereference:
13111 return ir_analyze_dereference(ira, un_op_instruction);13111 return ir_analyze_dereference(ira, un_op_instruction);
13112 case IrUnOpMaybe:13112 case IrUnOpOptional:
13113 return ir_analyze_maybe(ira, un_op_instruction);13113 return ir_analyze_maybe(ira, un_op_instruction);
13114 }13114 }
13115 zig_unreachable();13115 zig_unreachable();
...@@ -14155,7 +14155,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -14155,7 +14155,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
14155 buf_ptr(&child_type->name), buf_ptr(field_name)));14155 buf_ptr(&child_type->name), buf_ptr(field_name)));
14156 return ira->codegen->builtin_types.entry_invalid;14156 return ira->codegen->builtin_types.entry_invalid;
14157 }14157 }
14158 } else if (child_type->id == TypeTableEntryIdMaybe) {14158 } else if (child_type->id == TypeTableEntryIdOptional) {
14159 if (buf_eql_str(field_name, "Child")) {14159 if (buf_eql_str(field_name, "Child")) {
14160 bool ptr_is_const = true;14160 bool ptr_is_const = true;
14161 bool ptr_is_volatile = false;14161 bool ptr_is_volatile = false;
...@@ -14339,7 +14339,7 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi...@@ -14339,7 +14339,7 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
14339 case TypeTableEntryIdPointer:14339 case TypeTableEntryIdPointer:
14340 case TypeTableEntryIdArray:14340 case TypeTableEntryIdArray:
14341 case TypeTableEntryIdStruct:14341 case TypeTableEntryIdStruct:
14342 case TypeTableEntryIdMaybe:14342 case TypeTableEntryIdOptional:
14343 case TypeTableEntryIdErrorUnion:14343 case TypeTableEntryIdErrorUnion:
14344 case TypeTableEntryIdErrorSet:14344 case TypeTableEntryIdErrorSet:
14345 case TypeTableEntryIdEnum:14345 case TypeTableEntryIdEnum:
...@@ -14607,7 +14607,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -14607,7 +14607,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
14607 case TypeTableEntryIdStruct:14607 case TypeTableEntryIdStruct:
14608 case TypeTableEntryIdComptimeFloat:14608 case TypeTableEntryIdComptimeFloat:
14609 case TypeTableEntryIdComptimeInt:14609 case TypeTableEntryIdComptimeInt:
14610 case TypeTableEntryIdMaybe:14610 case TypeTableEntryIdOptional:
14611 case TypeTableEntryIdErrorUnion:14611 case TypeTableEntryIdErrorUnion:
14612 case TypeTableEntryIdErrorSet:14612 case TypeTableEntryIdErrorSet:
14613 case TypeTableEntryIdEnum:14613 case TypeTableEntryIdEnum:
...@@ -14715,7 +14715,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -14715,7 +14715,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
14715 case TypeTableEntryIdStruct:14715 case TypeTableEntryIdStruct:
14716 case TypeTableEntryIdComptimeFloat:14716 case TypeTableEntryIdComptimeFloat:
14717 case TypeTableEntryIdComptimeInt:14717 case TypeTableEntryIdComptimeInt:
14718 case TypeTableEntryIdMaybe:14718 case TypeTableEntryIdOptional:
14719 case TypeTableEntryIdErrorUnion:14719 case TypeTableEntryIdErrorUnion:
14720 case TypeTableEntryIdErrorSet:14720 case TypeTableEntryIdErrorSet:
14721 case TypeTableEntryIdEnum:14721 case TypeTableEntryIdEnum:
...@@ -14786,7 +14786,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,...@@ -14786,7 +14786,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
14786 case TypeTableEntryIdPointer:14786 case TypeTableEntryIdPointer:
14787 case TypeTableEntryIdArray:14787 case TypeTableEntryIdArray:
14788 case TypeTableEntryIdStruct:14788 case TypeTableEntryIdStruct:
14789 case TypeTableEntryIdMaybe:14789 case TypeTableEntryIdOptional:
14790 case TypeTableEntryIdErrorUnion:14790 case TypeTableEntryIdErrorUnion:
14791 case TypeTableEntryIdErrorSet:14791 case TypeTableEntryIdErrorSet:
14792 case TypeTableEntryIdEnum:14792 case TypeTableEntryIdEnum:
...@@ -14810,14 +14810,14 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn...@@ -14810,14 +14810,14 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
1481014810
14811 TypeTableEntry *type_entry = value->value.type;14811 TypeTableEntry *type_entry = value->value.type;
1481214812
14813 if (type_entry->id == TypeTableEntryIdMaybe) {14813 if (type_entry->id == TypeTableEntryIdOptional) {
14814 if (instr_is_comptime(value)) {14814 if (instr_is_comptime(value)) {
14815 ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad);14815 ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad);
14816 if (!maybe_val)14816 if (!maybe_val)
14817 return ira->codegen->builtin_types.entry_invalid;14817 return ira->codegen->builtin_types.entry_invalid;
1481814818
14819 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);14819 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);
14821 return ira->codegen->builtin_types.entry_bool;14821 return ira->codegen->builtin_types.entry_bool;
14822 }14822 }
1482314823
...@@ -14835,7 +14835,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn...@@ -14835,7 +14835,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
14835}14835}
1483614836
14837static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,14837static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
14838 IrInstructionUnwrapMaybe *unwrap_maybe_instruction)14838 IrInstructionUnwrapOptional *unwrap_maybe_instruction)
14839{14839{
14840 IrInstruction *value = unwrap_maybe_instruction->value->other;14840 IrInstruction *value = unwrap_maybe_instruction->value->other;
14841 if (type_is_invalid(value->value.type))14841 if (type_is_invalid(value->value.type))
...@@ -14863,9 +14863,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -14863,9 +14863,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
14863 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile);14863 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile);
14864 ir_link_new_instruction(result_instr, &unwrap_maybe_instruction->base);14864 ir_link_new_instruction(result_instr, &unwrap_maybe_instruction->base);
14865 return result_instr->value.type;14865 return result_instr->value.type;
14866 } else if (type_entry->id != TypeTableEntryIdMaybe) {14866 } else if (type_entry->id != TypeTableEntryIdOptional) {
14867 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,14867 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)));
14869 return ira->codegen->builtin_types.entry_invalid;14869 return ira->codegen->builtin_types.entry_invalid;
14870 }14870 }
14871 TypeTableEntry *child_type = type_entry->data.maybe.child_type;14871 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
...@@ -14881,7 +14881,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -14881,7 +14881,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
14881 ConstExprValue *maybe_val = const_ptr_pointee(ira->codegen, val);14881 ConstExprValue *maybe_val = const_ptr_pointee(ira->codegen, val);
1488214882
14883 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {14883 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
14884 if (nullable_value_is_null(maybe_val)) {14884 if (optional_value_is_null(maybe_val)) {
14885 ir_add_error(ira, &unwrap_maybe_instruction->base, buf_sprintf("unable to unwrap null"));14885 ir_add_error(ira, &unwrap_maybe_instruction->base, buf_sprintf("unable to unwrap null"));
14886 return ira->codegen->builtin_types.entry_invalid;14886 return ira->codegen->builtin_types.entry_invalid;
14887 }14887 }
...@@ -14891,7 +14891,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -14891,7 +14891,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
14891 if (type_is_codegen_pointer(child_type)) {14891 if (type_is_codegen_pointer(child_type)) {
14892 out_val->data.x_ptr.data.ref.pointee = maybe_val;14892 out_val->data.x_ptr.data.ref.pointee = maybe_val;
14893 } else {14893 } 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;
14895 }14895 }
14896 return result_type;14896 return result_type;
14897 }14897 }
...@@ -15216,7 +15216,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -15216,7 +15216,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
15216 case TypeTableEntryIdStruct:15216 case TypeTableEntryIdStruct:
15217 case TypeTableEntryIdUndefined:15217 case TypeTableEntryIdUndefined:
15218 case TypeTableEntryIdNull:15218 case TypeTableEntryIdNull:
15219 case TypeTableEntryIdMaybe:15219 case TypeTableEntryIdOptional:
15220 case TypeTableEntryIdBlock:15220 case TypeTableEntryIdBlock:
15221 case TypeTableEntryIdBoundFn:15221 case TypeTableEntryIdBoundFn:
15222 case TypeTableEntryIdArgTuple:15222 case TypeTableEntryIdArgTuple:
...@@ -15737,7 +15737,7 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_...@@ -15737,7 +15737,7 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
15737 case TypeTableEntryIdComptimeInt:15737 case TypeTableEntryIdComptimeInt:
15738 case TypeTableEntryIdUndefined:15738 case TypeTableEntryIdUndefined:
15739 case TypeTableEntryIdNull:15739 case TypeTableEntryIdNull:
15740 case TypeTableEntryIdMaybe:15740 case TypeTableEntryIdOptional:
15741 case TypeTableEntryIdErrorUnion:15741 case TypeTableEntryIdErrorUnion:
15742 case TypeTableEntryIdErrorSet:15742 case TypeTableEntryIdErrorSet:
15743 case TypeTableEntryIdUnion:15743 case TypeTableEntryIdUnion:
...@@ -16255,11 +16255,11 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -16255,11 +16255,11 @@ static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
16255 0, 0);16255 0, 0);
16256 fn_def_fields[6].type = get_maybe_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));16256 fn_def_fields[6].type = get_maybe_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
16257 if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) {16257 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);
16259 ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name);16259 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);
16261 } else {16261 } else {
16262 fn_def_fields[6].data.x_nullable = nullptr;16262 fn_def_fields[6].data.x_optional = nullptr;
16263 }16263 }
16264 // return_type: type16264 // return_type: type
16265 ensure_field_index(fn_def_val->type, "return_type", 7);16265 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...@@ -16507,11 +16507,11 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
1650716507
16508 break;16508 break;
16509 }16509 }
16510 case TypeTableEntryIdMaybe:16510 case TypeTableEntryIdOptional:
16511 {16511 {
16512 result = create_const_vals(1);16512 result = create_const_vals(1);
16513 result->special = ConstValSpecialStatic;16513 result->special = ConstValSpecialStatic;
16514 result->type = ir_type_info_get_type(ira, "Nullable");16514 result->type = ir_type_info_get_type(ira, "Optional");
1651516515
16516 ConstExprValue *fields = create_const_vals(1);16516 ConstExprValue *fields = create_const_vals(1);
16517 result->data.x_struct.fields = fields;16517 result->data.x_struct.fields = fields;
...@@ -16725,10 +16725,10 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16725,10 +16725,10 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16725 inner_fields[1].type = get_maybe_type(ira->codegen, type_info_enum_field_type);16725 inner_fields[1].type = get_maybe_type(ira->codegen, type_info_enum_field_type);
1672616726
16727 if (fields[1].data.x_type == ira->codegen->builtin_types.entry_undef) {16727 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;
16729 } else {16729 } else {
16730 inner_fields[1].data.x_nullable = create_const_vals(1);16730 inner_fields[1].data.x_optional = create_const_vals(1);
16731 make_enum_field_val(inner_fields[1].data.x_nullable, union_field->enum_field, type_info_enum_field_type);16731 make_enum_field_val(inner_fields[1].data.x_optional, union_field->enum_field, type_info_enum_field_type);
16732 }16732 }
1673316733
16734 inner_fields[2].special = ConstValSpecialStatic;16734 inner_fields[2].special = ConstValSpecialStatic;
...@@ -16796,13 +16796,13 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16796,13 +16796,13 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16796 inner_fields[1].type = get_maybe_type(ira->codegen, ira->codegen->builtin_types.entry_usize);16796 inner_fields[1].type = get_maybe_type(ira->codegen, ira->codegen->builtin_types.entry_usize);
1679716797
16798 if (!type_has_bits(struct_field->type_entry)) {16798 if (!type_has_bits(struct_field->type_entry)) {
16799 inner_fields[1].data.x_nullable = nullptr;16799 inner_fields[1].data.x_optional = nullptr;
16800 } else {16800 } else {
16801 size_t byte_offset = LLVMOffsetOfElement(ira->codegen->target_data_ref, type_entry->type_ref, struct_field->gen_index);16801 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);16802 inner_fields[1].data.x_optional = create_const_vals(1);
16803 inner_fields[1].data.x_nullable->special = ConstValSpecialStatic;16803 inner_fields[1].data.x_optional->special = ConstValSpecialStatic;
16804 inner_fields[1].data.x_nullable->type = ira->codegen->builtin_types.entry_usize;16804 inner_fields[1].data.x_optional->type = ira->codegen->builtin_types.entry_usize;
16805 bigint_init_unsigned(&inner_fields[1].data.x_nullable->data.x_bigint, byte_offset);16805 bigint_init_unsigned(&inner_fields[1].data.x_optional->data.x_bigint, byte_offset);
16806 }16806 }
1680716807
16808 inner_fields[2].special = ConstValSpecialStatic;16808 inner_fields[2].special = ConstValSpecialStatic;
...@@ -18027,7 +18027,7 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc...@@ -18027,7 +18027,7 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc
18027 case TypeTableEntryIdPromise:18027 case TypeTableEntryIdPromise:
18028 case TypeTableEntryIdArray:18028 case TypeTableEntryIdArray:
18029 case TypeTableEntryIdStruct:18029 case TypeTableEntryIdStruct:
18030 case TypeTableEntryIdMaybe:18030 case TypeTableEntryIdOptional:
18031 case TypeTableEntryIdErrorUnion:18031 case TypeTableEntryIdErrorUnion:
18032 case TypeTableEntryIdErrorSet:18032 case TypeTableEntryIdErrorSet:
18033 case TypeTableEntryIdEnum:18033 case TypeTableEntryIdEnum:
...@@ -18591,7 +18591,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -18591,7 +18591,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
18591 old_align_bytes = fn_type_id.alignment;18591 old_align_bytes = fn_type_id.alignment;
18592 fn_type_id.alignment = align_bytes;18592 fn_type_id.alignment = align_bytes;
18593 result_type = get_fn_type(ira->codegen, &fn_type_id);18593 result_type = get_fn_type(ira->codegen, &fn_type_id);
18594 } else if (target_type->id == TypeTableEntryIdMaybe &&18594 } else if (target_type->id == TypeTableEntryIdOptional &&
18595 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)18595 target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
18596 {18596 {
18597 TypeTableEntry *ptr_type = target_type->data.maybe.child_type;18597 TypeTableEntry *ptr_type = target_type->data.maybe.child_type;
...@@ -18599,7 +18599,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -18599,7 +18599,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
18599 TypeTableEntry *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);18599 TypeTableEntry *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
1860018600
18601 result_type = get_maybe_type(ira->codegen, better_ptr_type);18601 result_type = get_maybe_type(ira->codegen, better_ptr_type);
18602 } else if (target_type->id == TypeTableEntryIdMaybe &&18602 } else if (target_type->id == TypeTableEntryIdOptional &&
18603 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)18603 target_type->data.maybe.child_type->id == TypeTableEntryIdFn)
18604 {18604 {
18605 FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id;18605 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...@@ -18757,7 +18757,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
18757 return;18757 return;
18758 case TypeTableEntryIdStruct:18758 case TypeTableEntryIdStruct:
18759 zig_panic("TODO buf_write_value_bytes struct type");18759 zig_panic("TODO buf_write_value_bytes struct type");
18760 case TypeTableEntryIdMaybe:18760 case TypeTableEntryIdOptional:
18761 zig_panic("TODO buf_write_value_bytes maybe type");18761 zig_panic("TODO buf_write_value_bytes maybe type");
18762 case TypeTableEntryIdErrorUnion:18762 case TypeTableEntryIdErrorUnion:
18763 zig_panic("TODO buf_write_value_bytes error union");18763 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...@@ -18815,7 +18815,7 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
18815 zig_panic("TODO buf_read_value_bytes array type");18815 zig_panic("TODO buf_read_value_bytes array type");
18816 case TypeTableEntryIdStruct:18816 case TypeTableEntryIdStruct:
18817 zig_panic("TODO buf_read_value_bytes struct type");18817 zig_panic("TODO buf_read_value_bytes struct type");
18818 case TypeTableEntryIdMaybe:18818 case TypeTableEntryIdOptional:
18819 zig_panic("TODO buf_read_value_bytes maybe type");18819 zig_panic("TODO buf_read_value_bytes maybe type");
18820 case TypeTableEntryIdErrorUnion:18820 case TypeTableEntryIdErrorUnion:
18821 zig_panic("TODO buf_read_value_bytes error union");18821 zig_panic("TODO buf_read_value_bytes error union");
...@@ -19731,7 +19731,7 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -19731,7 +19731,7 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
19731 case IrInstructionIdUnionInit:19731 case IrInstructionIdUnionInit:
19732 case IrInstructionIdStructFieldPtr:19732 case IrInstructionIdStructFieldPtr:
19733 case IrInstructionIdUnionFieldPtr:19733 case IrInstructionIdUnionFieldPtr:
19734 case IrInstructionIdMaybeWrap:19734 case IrInstructionIdOptionalWrap:
19735 case IrInstructionIdErrWrapCode:19735 case IrInstructionIdErrWrapCode:
19736 case IrInstructionIdErrWrapPayload:19736 case IrInstructionIdErrWrapPayload:
19737 case IrInstructionIdCast:19737 case IrInstructionIdCast:
...@@ -19791,8 +19791,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -19791,8 +19791,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
19791 return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction);19791 return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction);
19792 case IrInstructionIdTestNonNull:19792 case IrInstructionIdTestNonNull:
19793 return ir_analyze_instruction_test_non_null(ira, (IrInstructionTestNonNull *)instruction);19793 return ir_analyze_instruction_test_non_null(ira, (IrInstructionTestNonNull *)instruction);
19794 case IrInstructionIdUnwrapMaybe:19794 case IrInstructionIdUnwrapOptional:
19795 return ir_analyze_instruction_unwrap_maybe(ira, (IrInstructionUnwrapMaybe *)instruction);19795 return ir_analyze_instruction_unwrap_maybe(ira, (IrInstructionUnwrapOptional *)instruction);
19796 case IrInstructionIdClz:19796 case IrInstructionIdClz:
19797 return ir_analyze_instruction_clz(ira, (IrInstructionClz *)instruction);19797 return ir_analyze_instruction_clz(ira, (IrInstructionClz *)instruction);
19798 case IrInstructionIdCtz:19798 case IrInstructionIdCtz:
...@@ -20128,7 +20128,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -20128,7 +20128,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
20128 case IrInstructionIdSliceType:20128 case IrInstructionIdSliceType:
20129 case IrInstructionIdSizeOf:20129 case IrInstructionIdSizeOf:
20130 case IrInstructionIdTestNonNull:20130 case IrInstructionIdTestNonNull:
20131 case IrInstructionIdUnwrapMaybe:20131 case IrInstructionIdUnwrapOptional:
20132 case IrInstructionIdClz:20132 case IrInstructionIdClz:
20133 case IrInstructionIdCtz:20133 case IrInstructionIdCtz:
20134 case IrInstructionIdSwitchVar:20134 case IrInstructionIdSwitchVar:
...@@ -20150,7 +20150,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -20150,7 +20150,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
20150 case IrInstructionIdFrameAddress:20150 case IrInstructionIdFrameAddress:
20151 case IrInstructionIdTestErr:20151 case IrInstructionIdTestErr:
20152 case IrInstructionIdUnwrapErrCode:20152 case IrInstructionIdUnwrapErrCode:
20153 case IrInstructionIdMaybeWrap:20153 case IrInstructionIdOptionalWrap:
20154 case IrInstructionIdErrWrapCode:20154 case IrInstructionIdErrWrapCode:
20155 case IrInstructionIdErrWrapPayload:20155 case IrInstructionIdErrWrapPayload:
20156 case IrInstructionIdFnProto:20156 case IrInstructionIdFnProto:
src/ir_print.cpp+8-8
...@@ -148,7 +148,7 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {...@@ -148,7 +148,7 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {
148 return "-%";148 return "-%";
149 case IrUnOpDereference:149 case IrUnOpDereference:
150 return "*";150 return "*";
151 case IrUnOpMaybe:151 case IrUnOpOptional:
152 return "?";152 return "?";
153 }153 }
154 zig_unreachable();154 zig_unreachable();
...@@ -481,7 +481,7 @@ static void ir_print_test_null(IrPrint *irp, IrInstructionTestNonNull *instructi...@@ -481,7 +481,7 @@ static void ir_print_test_null(IrPrint *irp, IrInstructionTestNonNull *instructi
481 fprintf(irp->f, " != null");481 fprintf(irp->f, " != null");
482}482}
483483
484static void ir_print_unwrap_maybe(IrPrint *irp, IrInstructionUnwrapMaybe *instruction) {484static void ir_print_unwrap_maybe(IrPrint *irp, IrInstructionUnwrapOptional *instruction) {
485 fprintf(irp->f, "&??*");485 fprintf(irp->f, "&??*");
486 ir_print_other_instruction(irp, instruction->value);486 ir_print_other_instruction(irp, instruction->value);
487 if (!instruction->safety_check_on) {487 if (!instruction->safety_check_on) {
...@@ -777,7 +777,7 @@ static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayl...@@ -777,7 +777,7 @@ static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayl
777 }777 }
778}778}
779779
780static void ir_print_maybe_wrap(IrPrint *irp, IrInstructionMaybeWrap *instruction) {780static void ir_print_maybe_wrap(IrPrint *irp, IrInstructionOptionalWrap *instruction) {
781 fprintf(irp->f, "@maybeWrap(");781 fprintf(irp->f, "@maybeWrap(");
782 ir_print_other_instruction(irp, instruction->value);782 ir_print_other_instruction(irp, instruction->value);
783 fprintf(irp->f, ")");783 fprintf(irp->f, ")");
...@@ -1032,7 +1032,7 @@ static void ir_print_export(IrPrint *irp, IrInstructionExport *instruction) {...@@ -1032,7 +1032,7 @@ static void ir_print_export(IrPrint *irp, IrInstructionExport *instruction) {
10321032
1033static void ir_print_error_return_trace(IrPrint *irp, IrInstructionErrorReturnTrace *instruction) {1033static void ir_print_error_return_trace(IrPrint *irp, IrInstructionErrorReturnTrace *instruction) {
1034 fprintf(irp->f, "@errorReturnTrace(");1034 fprintf(irp->f, "@errorReturnTrace(");
1035 switch (instruction->nullable) {1035 switch (instruction->optional) {
1036 case IrInstructionErrorReturnTrace::Null:1036 case IrInstructionErrorReturnTrace::Null:
1037 fprintf(irp->f, "Null");1037 fprintf(irp->f, "Null");
1038 break;1038 break;
...@@ -1348,8 +1348,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1348,8 +1348,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1348 case IrInstructionIdTestNonNull:1348 case IrInstructionIdTestNonNull:
1349 ir_print_test_null(irp, (IrInstructionTestNonNull *)instruction);1349 ir_print_test_null(irp, (IrInstructionTestNonNull *)instruction);
1350 break;1350 break;
1351 case IrInstructionIdUnwrapMaybe:1351 case IrInstructionIdUnwrapOptional:
1352 ir_print_unwrap_maybe(irp, (IrInstructionUnwrapMaybe *)instruction);1352 ir_print_unwrap_maybe(irp, (IrInstructionUnwrapOptional *)instruction);
1353 break;1353 break;
1354 case IrInstructionIdCtz:1354 case IrInstructionIdCtz:
1355 ir_print_ctz(irp, (IrInstructionCtz *)instruction);1355 ir_print_ctz(irp, (IrInstructionCtz *)instruction);
...@@ -1465,8 +1465,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1465,8 +1465,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1465 case IrInstructionIdUnwrapErrPayload:1465 case IrInstructionIdUnwrapErrPayload:
1466 ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);1466 ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);
1467 break;1467 break;
1468 case IrInstructionIdMaybeWrap:1468 case IrInstructionIdOptionalWrap:
1469 ir_print_maybe_wrap(irp, (IrInstructionMaybeWrap *)instruction);1469 ir_print_maybe_wrap(irp, (IrInstructionOptionalWrap *)instruction);
1470 break;1470 break;
1471 case IrInstructionIdErrWrapCode:1471 case IrInstructionIdErrWrapCode:
1472 ir_print_err_wrap_code(irp, (IrInstructionErrWrapCode *)instruction);1472 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...@@ -1046,12 +1046,11 @@ static AstNode *ast_parse_fn_proto_partial(ParseContext *pc, size_t *token_index
1046}1046}
10471047
1048/*1048/*
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 | ".*" | ".?")
1050FnCallExpression : token(LParen) list(Expression, token(Comma)) token(RParen)1050FnCallExpression : token(LParen) list(Expression, token(Comma)) token(RParen)
1051ArrayAccessExpression : token(LBracket) Expression token(RBracket)1051ArrayAccessExpression : token(LBracket) Expression token(RBracket)
1052SliceExpression = "[" Expression ".." option(Expression) "]"1052SliceExpression = "[" Expression ".." option(Expression) "]"
1053FieldAccessExpression : token(Dot) token(Symbol)1053FieldAccessExpression : token(Dot) token(Symbol)
1054PtrDerefExpression = ".*"
1055StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression1054StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression
1056*/1055*/
1057static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {1056static 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,...@@ -1148,6 +1147,14 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index,
1148 AstNode *node = ast_create_node(pc, NodeTypePtrDeref, first_token);1147 AstNode *node = ast_create_node(pc, NodeTypePtrDeref, first_token);
1149 node->data.ptr_deref_expr.target = primary_expr;1148 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
1151 primary_expr = node;1158 primary_expr = node;
1152 } else {1159 } else {
1153 ast_invalid_token_error(pc, token);1160 ast_invalid_token_error(pc, token);
...@@ -1165,8 +1172,8 @@ static PrefixOp tok_to_prefix_op(Token *token) {...@@ -1165,8 +1172,8 @@ static PrefixOp tok_to_prefix_op(Token *token) {
1165 case TokenIdDash: return PrefixOpNegation;1172 case TokenIdDash: return PrefixOpNegation;
1166 case TokenIdMinusPercent: return PrefixOpNegationWrap;1173 case TokenIdMinusPercent: return PrefixOpNegationWrap;
1167 case TokenIdTilde: return PrefixOpBinNot;1174 case TokenIdTilde: return PrefixOpBinNot;
1168 case TokenIdMaybe: return PrefixOpMaybe;1175 case TokenIdQuestion: return PrefixOpOptional;
1169 case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;1176 case TokenIdDoubleQuestion: return PrefixOpUnwrapOptional;
1170 case TokenIdAmpersand: return PrefixOpAddrOf;1177 case TokenIdAmpersand: return PrefixOpAddrOf;
1171 default: return PrefixOpInvalid;1178 default: return PrefixOpInvalid;
1172 }1179 }
...@@ -2304,8 +2311,8 @@ static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool ma...@@ -2304,8 +2311,8 @@ static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool ma
2304}2311}
23052312
2306/*2313/*
2307UnwrapExpression : BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpression2314UnwrapExpression : BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression
2308UnwrapMaybe : "??" BoolOrExpression2315UnwrapOptional : "??" BoolOrExpression
2309UnwrapError = "catch" option("|" Symbol "|") Expression2316UnwrapError = "catch" option("|" Symbol "|") Expression
2310*/2317*/
2311static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) {2318static 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...@@ -2322,7 +2329,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, boo
23222329
2323 AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token);2330 AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token);
2324 node->data.bin_op_expr.op1 = lhs;2331 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;
2326 node->data.bin_op_expr.op2 = rhs;2333 node->data.bin_op_expr.op2 = rhs;
23272334
2328 return node;2335 return node;
src/tokenizer.cpp+2-8
...@@ -625,7 +625,7 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -625,7 +625,7 @@ void tokenize(Buf *buf, Tokenization *out) {
625 t.state = TokenizeStateSawDot;625 t.state = TokenizeStateSawDot;
626 break;626 break;
627 case '?':627 case '?':
628 begin_token(&t, TokenIdMaybe);628 begin_token(&t, TokenIdQuestion);
629 t.state = TokenizeStateSawQuestionMark;629 t.state = TokenizeStateSawQuestionMark;
630 break;630 break;
631 default:631 default:
...@@ -639,11 +639,6 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -639,11 +639,6 @@ void tokenize(Buf *buf, Tokenization *out) {
639 end_token(&t);639 end_token(&t);
640 t.state = TokenizeStateStart;640 t.state = TokenizeStateStart;
641 break;641 break;
642 case '=':
643 set_token_id(&t, t.cur_tok, TokenIdMaybeAssign);
644 end_token(&t);
645 t.state = TokenizeStateStart;
646 break;
647 default:642 default:
648 t.pos -= 1;643 t.pos -= 1;
649 end_token(&t);644 end_token(&t);
...@@ -1609,8 +1604,7 @@ const char * token_name(TokenId id) {...@@ -1609,8 +1604,7 @@ const char * token_name(TokenId id) {
1609 case TokenIdLBrace: return "{";1604 case TokenIdLBrace: return "{";
1610 case TokenIdLBracket: return "[";1605 case TokenIdLBracket: return "[";
1611 case TokenIdLParen: return "(";1606 case TokenIdLParen: return "(";
1612 case TokenIdMaybe: return "?";1607 case TokenIdQuestion: return "?";
1613 case TokenIdMaybeAssign: return "?=";
1614 case TokenIdMinusEq: return "-=";1608 case TokenIdMinusEq: return "-=";
1615 case TokenIdMinusPercent: return "-%";1609 case TokenIdMinusPercent: return "-%";
1616 case TokenIdMinusPercentEq: return "-%=";1610 case TokenIdMinusPercentEq: return "-%=";
src/tokenizer.hpp+1-2
...@@ -100,8 +100,7 @@ enum TokenId {...@@ -100,8 +100,7 @@ enum TokenId {
100 TokenIdLBrace,100 TokenIdLBrace,
101 TokenIdLBracket,101 TokenIdLBracket,
102 TokenIdLParen,102 TokenIdLParen,
103 TokenIdMaybe,103 TokenIdQuestion,
104 TokenIdMaybeAssign,
105 TokenIdMinusEq,104 TokenIdMinusEq,
106 TokenIdMinusPercent,105 TokenIdMinusPercent,
107 TokenIdMinusPercentEq,106 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...@@ -382,7 +382,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r
382 fn_def->data.fn_def.fn_proto = fn_proto;382 fn_def->data.fn_def.fn_proto = fn_proto;
383 fn_proto->data.fn_proto.fn_def_node = fn_def;383 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);
386 AstNode *fn_call_node = trans_create_node(c, NodeTypeFnCallExpr);386 AstNode *fn_call_node = trans_create_node(c, NodeTypeFnCallExpr);
387 fn_call_node->data.fn_call_expr.fn_ref_expr = unwrap_node;387 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...@@ -410,7 +410,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r
410}410}
411411
412static AstNode *trans_create_node_unwrap_null(Context *c, AstNode *child) {412static 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);
414}414}
415415
416static AstNode *get_global(Context *c, Buf *name) {416static AstNode *get_global(Context *c, Buf *name) {
...@@ -879,14 +879,14 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou...@@ -879,14 +879,14 @@ static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &sou
879 }879 }
880880
881 if (qual_type_child_is_fn_proto(child_qt)) {881 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);
883 }883 }
884884
885 PtrLen ptr_len = type_is_opaque(c, child_qt.getTypePtr(), source_loc) ? PtrLenSingle : PtrLenUnknown;885 PtrLen ptr_len = type_is_opaque(c, child_qt.getTypePtr(), source_loc) ? PtrLenSingle : PtrLenUnknown;
886886
887 AstNode *pointer_node = trans_create_node_ptr_type(c, child_qt.isConstQualified(),887 AstNode *pointer_node = trans_create_node_ptr_type(c, child_qt.isConstQualified(),
888 child_qt.isVolatileQualified(), child_node, ptr_len);888 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);
890 }890 }
891 case Type::Typedef:891 case Type::Typedef:
892 {892 {
...@@ -1963,7 +1963,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc...@@ -1963,7 +1963,7 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
1963 bool is_fn_ptr = qual_type_is_fn_ptr(stmt->getSubExpr()->getType());1963 bool is_fn_ptr = qual_type_is_fn_ptr(stmt->getSubExpr()->getType());
1964 if (is_fn_ptr)1964 if (is_fn_ptr)
1965 return value_node;1965 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);
1967 return trans_create_node_ptr_deref(c, unwrapped);1967 return trans_create_node_ptr_deref(c, unwrapped);
1968 }1968 }
1969 case UO_Plus:1969 case UO_Plus:
...@@ -2587,7 +2587,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *...@@ -2587,7 +2587,7 @@ static AstNode *trans_call_expr(Context *c, ResultUsed result_used, TransScope *
2587 }2587 }
2588 }2588 }
2589 if (callee_node == nullptr) {2589 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);
2591 }2591 }
2592 } else {2592 } else {
2593 callee_node = callee_raw_node;2593 callee_node = callee_raw_node;
...@@ -4301,7 +4301,7 @@ static AstNode *trans_lookup_ast_maybe_fn(Context *c, AstNode *ref_node) {...@@ -4301,7 +4301,7 @@ static AstNode *trans_lookup_ast_maybe_fn(Context *c, AstNode *ref_node) {
4301 return nullptr;4301 return nullptr;
4302 if (prefix_node->type != NodeTypePrefixOpExpr)4302 if (prefix_node->type != NodeTypePrefixOpExpr)
4303 return nullptr;4303 return nullptr;
4304 if (prefix_node->data.prefix_op_expr.prefix_op != PrefixOpMaybe)4304 if (prefix_node->data.prefix_op_expr.prefix_op != PrefixOpOptional)
4305 return nullptr;4305 return nullptr;
43064306
4307 AstNode *fn_proto_node = prefix_node->data.prefix_op_expr.primary_expr;4307 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" {...@@ -258,7 +258,7 @@ test "iterator ArrayList test" {
258 }258 }
259259
260 it.reset();260 it.reset();
261 assert(??it.next() == 1);261 assert(it.next().? == 1);
262}262}
263263
264test "insert ArrayList test" {264test "insert ArrayList test" {
std/buf_map.zig+3-3
...@@ -72,15 +72,15 @@ test "BufMap" {...@@ -72,15 +72,15 @@ test "BufMap" {
72 defer bufmap.deinit();72 defer bufmap.deinit();
7373
74 try bufmap.set("x", "1");74 try bufmap.set("x", "1");
75 assert(mem.eql(u8, ??bufmap.get("x"), "1"));75 assert(mem.eql(u8, bufmap.get("x").?, "1"));
76 assert(1 == bufmap.count());76 assert(1 == bufmap.count());
7777
78 try bufmap.set("x", "2");78 try bufmap.set("x", "2");
79 assert(mem.eql(u8, ??bufmap.get("x"), "2"));79 assert(mem.eql(u8, bufmap.get("x").?, "2"));
80 assert(1 == bufmap.count());80 assert(1 == bufmap.count());
8181
82 try bufmap.set("x", "3");82 try bufmap.set("x", "3");
83 assert(mem.eql(u8, ??bufmap.get("x"), "3"));83 assert(mem.eql(u8, bufmap.get("x").?, "3"));
84 assert(1 == bufmap.count());84 assert(1 == bufmap.count());
8585
86 bufmap.delete("x");86 bufmap.delete("x");
std/event.zig+2-2
...@@ -40,9 +40,9 @@ pub const TcpServer = struct {...@@ -40,9 +40,9 @@ pub const TcpServer = struct {
40 self.listen_address = std.net.Address.initPosix(try std.os.posixGetSockName(self.sockfd));40 self.listen_address = std.net.Address.initPosix(try std.os.posixGetSockName(self.sockfd));
4141
42 self.accept_coro = try async<self.loop.allocator> TcpServer.handler(self);42 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.?);
46 errdefer self.loop.removeFd(self.sockfd);46 errdefer self.loop.removeFd(self.sockfd);
47 }47 }
4848
std/fmt/index.zig+3-3
...@@ -111,7 +111,7 @@ pub fn formatType(...@@ -111,7 +111,7 @@ pub fn formatType(
111 builtin.TypeId.Bool => {111 builtin.TypeId.Bool => {
112 return output(context, if (value) "true" else "false");112 return output(context, if (value) "true" else "false");
113 },113 },
114 builtin.TypeId.Nullable => {114 builtin.TypeId.Optional => {
115 if (value) |payload| {115 if (value) |payload| {
116 return formatType(payload, fmt, context, Errors, output);116 return formatType(payload, fmt, context, Errors, output);
117 } else {117 } else {
...@@ -819,11 +819,11 @@ test "parse unsigned comptime" {...@@ -819,11 +819,11 @@ test "parse unsigned comptime" {
819test "fmt.format" {819test "fmt.format" {
820 {820 {
821 const value: ?i32 = 1234;821 const value: ?i32 = 1234;
822 try testFmt("nullable: 1234\n", "nullable: {}\n", value);822 try testFmt("optional: 1234\n", "optional: {}\n", value);
823 }823 }
824 {824 {
825 const value: ?i32 = null;825 const value: ?i32 = null;
826 try testFmt("nullable: null\n", "nullable: {}\n", value);826 try testFmt("optional: null\n", "optional: {}\n", value);
827 }827 }
828 {828 {
829 const value: error!i32 = 1234;829 const value: error!i32 = 1234;
std/hash_map.zig+4-4
...@@ -265,11 +265,11 @@ test "basic hash map usage" {...@@ -265,11 +265,11 @@ test "basic hash map usage" {
265 assert((map.put(4, 44) catch unreachable) == null);265 assert((map.put(4, 44) catch unreachable) == null);
266 assert((map.put(5, 55) catch unreachable) == null);266 assert((map.put(5, 55) catch unreachable) == null);
267267
268 assert(??(map.put(5, 66) catch unreachable) == 55);268 assert((map.put(5, 66) catch unreachable).? == 55);
269 assert(??(map.put(5, 55) catch unreachable) == 66);269 assert((map.put(5, 55) catch unreachable).? == 66);
270270
271 assert(map.contains(2));271 assert(map.contains(2));
272 assert((??map.get(2)).value == 22);272 assert(map.get(2).?.value == 22);
273 _ = map.remove(2);273 _ = map.remove(2);
274 assert(map.remove(2) == null);274 assert(map.remove(2) == null);
275 assert(map.get(2) == null);275 assert(map.get(2) == null);
...@@ -317,7 +317,7 @@ test "iterator hash map" {...@@ -317,7 +317,7 @@ test "iterator hash map" {
317 }317 }
318318
319 it.reset();319 it.reset();
320 var entry = ??it.next();320 var entry = it.next().?;
321 assert(entry.key == keys[0]);321 assert(entry.key == keys[0]);
322 assert(entry.value == values[0]);322 assert(entry.value == values[0]);
323}323}
std/heap.zig+2-2
...@@ -142,7 +142,7 @@ pub const DirectAllocator = struct {...@@ -142,7 +142,7 @@ pub const DirectAllocator = struct {
142 const root_addr = @intToPtr(*align(1) usize, old_record_addr).*;142 const root_addr = @intToPtr(*align(1) usize, old_record_addr).*;
143 const old_ptr = @intToPtr(*c_void, root_addr);143 const old_ptr = @intToPtr(*c_void, root_addr);
144 const amt = new_size + alignment + @sizeOf(usize);144 const amt = new_size + alignment + @sizeOf(usize);
145 const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: {145 const new_ptr = os.windows.HeapReAlloc(self.heap_handle.?, 0, old_ptr, amt) ?? blk: {
146 if (new_size > old_mem.len) return error.OutOfMemory;146 if (new_size > old_mem.len) return error.OutOfMemory;
147 const new_record_addr = old_record_addr - new_size + old_mem.len;147 const new_record_addr = old_record_addr - new_size + old_mem.len;
148 @intToPtr(*align(1) usize, new_record_addr).* = root_addr;148 @intToPtr(*align(1) usize, new_record_addr).* = root_addr;
...@@ -171,7 +171,7 @@ pub const DirectAllocator = struct {...@@ -171,7 +171,7 @@ pub const DirectAllocator = struct {
171 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;171 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;
172 const root_addr = @intToPtr(*align(1) usize, record_addr).*;172 const root_addr = @intToPtr(*align(1) usize, record_addr).*;
173 const ptr = @intToPtr(*c_void, root_addr);173 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);
175 },175 },
176 else => @compileError("Unsupported OS"),176 else => @compileError("Unsupported OS"),
177 }177 }
std/json.zig+6-6
...@@ -908,7 +908,7 @@ pub const TokenStream = struct {...@@ -908,7 +908,7 @@ pub const TokenStream = struct {
908};908};
909909
910fn checkNext(p: *TokenStream, id: Token.Id) void {910fn checkNext(p: *TokenStream, id: Token.Id) void {
911 const token = ??(p.next() catch unreachable);911 const token = (p.next() catch unreachable).?;
912 debug.assert(token.id == id);912 debug.assert(token.id == id);
913}913}
914914
...@@ -1376,17 +1376,17 @@ test "json parser dynamic" {...@@ -1376,17 +1376,17 @@ test "json parser dynamic" {
13761376
1377 var root = tree.root;1377 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;
1382 debug.assert(width.Integer == 800);1382 debug.assert(width.Integer == 800);
13831383
1384 const height = (??image.Object.get("Height")).value;1384 const height = image.Object.get("Height").?.value;
1385 debug.assert(height.Integer == 600);1385 debug.assert(height.Integer == 600);
13861386
1387 const title = (??image.Object.get("Title")).value;1387 const title = image.Object.get("Title").?.value;
1388 debug.assert(mem.eql(u8, title.String, "View from 15th Floor"));1388 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;
1391 debug.assert(animated.Bool == false);1391 debug.assert(animated.Bool == false);
1392}1392}
std/linked_list.zig+4-4
...@@ -270,8 +270,8 @@ test "basic linked list test" {...@@ -270,8 +270,8 @@ test "basic linked list test" {
270 var last = list.pop(); // {2, 3, 4}270 var last = list.pop(); // {2, 3, 4}
271 list.remove(three); // {2, 4}271 list.remove(three); // {2, 4}
272272
273 assert((??list.first).data == 2);273 assert(list.first.?.data == 2);
274 assert((??list.last).data == 4);274 assert(list.last.?.data == 4);
275 assert(list.len == 2);275 assert(list.len == 2);
276}276}
277277
...@@ -336,7 +336,7 @@ test "basic intrusive linked list test" {...@@ -336,7 +336,7 @@ test "basic intrusive linked list test" {
336 var last = list.pop(); // {2, 3, 4}336 var last = list.pop(); // {2, 3, 4}
337 list.remove(&three.link); // {2, 4}337 list.remove(&three.link); // {2, 4}
338338
339 assert((??list.first).toData().value == 2);339 assert(list.first.?.toData().value == 2);
340 assert((??list.last).toData().value == 4);340 assert(list.last.?.toData().value == 4);
341 assert(list.len == 2);341 assert(list.len == 2);
342}342}
std/macho.zig+1-1
...@@ -130,7 +130,7 @@ pub fn loadSymbols(allocator: *mem.Allocator, in: *io.FileInStream) !SymbolTable...@@ -130,7 +130,7 @@ pub fn loadSymbols(allocator: *mem.Allocator, in: *io.FileInStream) !SymbolTable
130 for (syms) |sym| {130 for (syms) |sym| {
131 if (!isSymbol(sym)) continue;131 if (!isSymbol(sym)) continue;
132 const start = sym.n_strx;132 const start = sym.n_strx;
133 const end = ??mem.indexOfScalarPos(u8, strings, start, 0);133 const end = mem.indexOfScalarPos(u8, strings, start, 0).?;
134 const name = strings[start..end];134 const name = strings[start..end];
135 const address = sym.n_value;135 const address = sym.n_value;
136 symbols[nsym] = Symbol{ .name = name, .address = address };136 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...@@ -304,20 +304,20 @@ pub fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, nee
304}304}
305305
306test "mem.indexOf" {306test "mem.indexOf" {
307 assert(??indexOf(u8, "one two three four", "four") == 14);307 assert(indexOf(u8, "one two three four", "four").? == 14);
308 assert(??lastIndexOf(u8, "one two three two four", "two") == 14);308 assert(lastIndexOf(u8, "one two three two four", "two").? == 14);
309 assert(indexOf(u8, "one two three four", "gour") == null);309 assert(indexOf(u8, "one two three four", "gour") == null);
310 assert(lastIndexOf(u8, "one two three four", "gour") == null);310 assert(lastIndexOf(u8, "one two three four", "gour") == null);
311 assert(??indexOf(u8, "foo", "foo") == 0);311 assert(indexOf(u8, "foo", "foo").? == 0);
312 assert(??lastIndexOf(u8, "foo", "foo") == 0);312 assert(lastIndexOf(u8, "foo", "foo").? == 0);
313 assert(indexOf(u8, "foo", "fool") == null);313 assert(indexOf(u8, "foo", "fool") == null);
314 assert(lastIndexOf(u8, "foo", "lfoo") == null);314 assert(lastIndexOf(u8, "foo", "lfoo") == null);
315 assert(lastIndexOf(u8, "foo", "fool") == null);315 assert(lastIndexOf(u8, "foo", "fool") == null);
316316
317 assert(??indexOf(u8, "foo foo", "foo") == 0);317 assert(indexOf(u8, "foo foo", "foo").? == 0);
318 assert(??lastIndexOf(u8, "foo foo", "foo") == 4);318 assert(lastIndexOf(u8, "foo foo", "foo").? == 4);
319 assert(??lastIndexOfAny(u8, "boo, cat", "abo") == 6);319 assert(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
320 assert(??lastIndexOfScalar(u8, "boo", 'o') == 2);320 assert(lastIndexOfScalar(u8, "boo", 'o').? == 2);
321}321}
322322
323/// Reads an integer from memory with size equal to bytes.len.323/// 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 {...@@ -432,9 +432,9 @@ pub fn split(buffer: []const u8, split_bytes: []const u8) SplitIterator {
432432
433test "mem.split" {433test "mem.split" {
434 var it = split(" abc def ghi ", " ");434 var it = split(" abc def ghi ", " ");
435 assert(eql(u8, ??it.next(), "abc"));435 assert(eql(u8, it.next().?, "abc"));
436 assert(eql(u8, ??it.next(), "def"));436 assert(eql(u8, it.next().?, "def"));
437 assert(eql(u8, ??it.next(), "ghi"));437 assert(eql(u8, it.next().?, "ghi"));
438 assert(it.next() == null);438 assert(it.next() == null);
439}439}
440440
std/os/child_process.zig+9-9
...@@ -156,7 +156,7 @@ pub const ChildProcess = struct {...@@ -156,7 +156,7 @@ pub const ChildProcess = struct {
156 };156 };
157 }157 }
158 try self.waitUnwrappedWindows();158 try self.waitUnwrappedWindows();
159 return ??self.term;159 return self.term.?;
160 }160 }
161161
162 pub fn killPosix(self: *ChildProcess) !Term {162 pub fn killPosix(self: *ChildProcess) !Term {
...@@ -175,7 +175,7 @@ pub const ChildProcess = struct {...@@ -175,7 +175,7 @@ pub const ChildProcess = struct {
175 };175 };
176 }176 }
177 self.waitUnwrapped();177 self.waitUnwrapped();
178 return ??self.term;178 return self.term.?;
179 }179 }
180180
181 /// Blocks until child process terminates and then cleans up all resources.181 /// Blocks until child process terminates and then cleans up all resources.
...@@ -212,8 +212,8 @@ pub const ChildProcess = struct {...@@ -212,8 +212,8 @@ pub const ChildProcess = struct {
212 defer Buffer.deinit(&stdout);212 defer Buffer.deinit(&stdout);
213 defer Buffer.deinit(&stderr);213 defer Buffer.deinit(&stderr);
214214
215 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);215 var stdout_file_in_stream = io.FileInStream.init(&child.stdout.?);
216 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);216 var stderr_file_in_stream = io.FileInStream.init(&child.stderr.?);
217217
218 try stdout_file_in_stream.stream.readAllBuffer(&stdout, max_output_size);218 try stdout_file_in_stream.stream.readAllBuffer(&stdout, max_output_size);
219 try stderr_file_in_stream.stream.readAllBuffer(&stderr, max_output_size);219 try stderr_file_in_stream.stream.readAllBuffer(&stderr, max_output_size);
...@@ -232,7 +232,7 @@ pub const ChildProcess = struct {...@@ -232,7 +232,7 @@ pub const ChildProcess = struct {
232 }232 }
233233
234 try self.waitUnwrappedWindows();234 try self.waitUnwrappedWindows();
235 return ??self.term;235 return self.term.?;
236 }236 }
237237
238 fn waitPosix(self: *ChildProcess) !Term {238 fn waitPosix(self: *ChildProcess) !Term {
...@@ -242,7 +242,7 @@ pub const ChildProcess = struct {...@@ -242,7 +242,7 @@ pub const ChildProcess = struct {
242 }242 }
243243
244 self.waitUnwrapped();244 self.waitUnwrapped();
245 return ??self.term;245 return self.term.?;
246 }246 }
247247
248 pub fn deinit(self: *ChildProcess) void {248 pub fn deinit(self: *ChildProcess) void {
...@@ -619,13 +619,13 @@ pub const ChildProcess = struct {...@@ -619,13 +619,13 @@ pub const ChildProcess = struct {
619 self.term = null;619 self.term = null;
620620
621 if (self.stdin_behavior == StdIo.Pipe) {621 if (self.stdin_behavior == StdIo.Pipe) {
622 os.close(??g_hChildStd_IN_Rd);622 os.close(g_hChildStd_IN_Rd.?);
623 }623 }
624 if (self.stderr_behavior == StdIo.Pipe) {624 if (self.stderr_behavior == StdIo.Pipe) {
625 os.close(??g_hChildStd_ERR_Wr);625 os.close(g_hChildStd_ERR_Wr.?);
626 }626 }
627 if (self.stdout_behavior == StdIo.Pipe) {627 if (self.stdout_behavior == StdIo.Pipe) {
628 os.close(??g_hChildStd_OUT_Wr);628 os.close(g_hChildStd_OUT_Wr.?);
629 }629 }
630 }630 }
631631
std/os/index.zig+2-2
...@@ -422,7 +422,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator:...@@ -422,7 +422,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator:
422422
423 const exe_path = argv[0];423 const exe_path = argv[0];
424 if (mem.indexOfScalar(u8, exe_path, '/') != null) {424 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)));
426 }426 }
427427
428 const PATH = getEnvPosix("PATH") ?? "/usr/local/bin:/bin/:/usr/bin";428 const PATH = getEnvPosix("PATH") ?? "/usr/local/bin:/bin/:/usr/bin";
...@@ -1729,7 +1729,7 @@ test "windows arg parsing" {...@@ -1729,7 +1729,7 @@ test "windows arg parsing" {
1729fn testWindowsCmdLine(input_cmd_line: [*]const u8, expected_args: []const []const u8) void {1729fn testWindowsCmdLine(input_cmd_line: [*]const u8, expected_args: []const []const u8) void {
1730 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);1730 var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
1731 for (expected_args) |expected_arg| {1731 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;
1733 assert(mem.eql(u8, arg, expected_arg));1733 assert(mem.eql(u8, arg, expected_arg));
1734 }1734 }
1735 assert(it.next(debug.global_allocator) == null);1735 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 {...@@ -67,7 +67,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
67 if (0 == syms[i].st_shndx) continue;67 if (0 == syms[i].st_shndx) continue;
68 if (!mem.eql(u8, name, cstr.toSliceConst(strings + syms[i].st_name))) continue;68 if (!mem.eql(u8, name, cstr.toSliceConst(strings + syms[i].st_name))) continue;
69 if (maybe_versym) |versym| {69 if (maybe_versym) |versym| {
70 if (!checkver(??maybe_verdef, versym[i], vername, strings))70 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
71 continue;71 continue;
72 }72 }
73 return base + syms[i].st_value;73 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 {...@@ -265,7 +265,7 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
265 var it2 = mem.split(ns2, []u8{sep2});265 var it2 = mem.split(ns2, []u8{sep2});
266266
267 // TODO ASCII is wrong, we actually need full unicode support to compare paths.267 // 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().?);
269}269}
270270
271fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8) bool {271fn 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...@@ -286,7 +286,7 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
286 var it2 = mem.split(p2, []u8{sep2});286 var it2 = mem.split(p2, []u8{sep2});
287287
288 // TODO ASCII is wrong, we actually need full unicode support to compare paths.288 // 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().?);
290 },290 },
291 }291 }
292}292}
...@@ -414,8 +414,8 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {...@@ -414,8 +414,8 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
414 WindowsPath.Kind.NetworkShare => {414 WindowsPath.Kind.NetworkShare => {
415 result = try allocator.alloc(u8, max_size);415 result = try allocator.alloc(u8, max_size);
416 var it = mem.split(paths[first_index], "/\\");416 var it = mem.split(paths[first_index], "/\\");
417 const server_name = ??it.next();417 const server_name = it.next().?;
418 const other_name = ??it.next();418 const other_name = it.next().?;
419419
420 result[result_index] = '\\';420 result[result_index] = '\\';
421 result_index += 1;421 result_index += 1;
std/segmented_list.zig+4-4
...@@ -364,7 +364,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {...@@ -364,7 +364,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
364 assert(x == 0);364 assert(x == 0);
365 }365 }
366366
367 assert(??list.pop() == 100);367 assert(list.pop().? == 100);
368 assert(list.len == 99);368 assert(list.len == 99);
369369
370 try list.pushMany([]i32{370 try list.pushMany([]i32{
...@@ -373,9 +373,9 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {...@@ -373,9 +373,9 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
373 3,373 3,
374 });374 });
375 assert(list.len == 102);375 assert(list.len == 102);
376 assert(??list.pop() == 3);376 assert(list.pop().? == 3);
377 assert(??list.pop() == 2);377 assert(list.pop().? == 2);
378 assert(??list.pop() == 1);378 assert(list.pop().? == 1);
379 assert(list.len == 99);379 assert(list.len == 99);
380380
381 try list.pushMany([]const i32{});381 try list.pushMany([]const i32{});
std/special/bootstrap.zig+3-3
...@@ -54,10 +54,10 @@ fn posixCallMainAndExit() noreturn {...@@ -54,10 +54,10 @@ fn posixCallMainAndExit() noreturn {
54 const argc = argc_ptr[0];54 const argc = argc_ptr[0];
55 const argv = @ptrCast([*][*]u8, argc_ptr + 1);55 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);
58 var envp_count: usize = 0;58 var envp_count: usize = 0;
59 while (envp_nullable[envp_count]) |_| : (envp_count += 1) {}59 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
60 const envp = @ptrCast([*][*]u8, envp_nullable)[0..envp_count];60 const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];
61 if (builtin.os == builtin.Os.linux) {61 if (builtin.os == builtin.Os.linux) {
62 const auxv = @ptrCast([*]usize, envp.ptr + envp_count + 1);62 const auxv = @ptrCast([*]usize, envp.ptr + envp_count + 1);
63 var i: usize = 0;63 var i: usize = 0;
std/special/builtin.zig+4-4
...@@ -19,7 +19,7 @@ export fn memset(dest: ?[*]u8, c: u8, n: usize) ?[*]u8 {...@@ -19,7 +19,7 @@ export fn memset(dest: ?[*]u8, c: u8, n: usize) ?[*]u8 {
1919
20 var index: usize = 0;20 var index: usize = 0;
21 while (index != n) : (index += 1)21 while (index != n) : (index += 1)
22 (??dest)[index] = c;22 dest.?[index] = c;
2323
24 return dest;24 return dest;
25}25}
...@@ -29,7 +29,7 @@ export fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) ?[*]...@@ -29,7 +29,7 @@ export fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) ?[*]
2929
30 var index: usize = 0;30 var index: usize = 0;
31 while (index != n) : (index += 1)31 while (index != n) : (index += 1)
32 (??dest)[index] = (??src)[index];32 dest.?[index] = src.?[index];
3333
34 return dest;34 return dest;
35}35}
...@@ -40,13 +40,13 @@ export fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) ?[*]u8 {...@@ -40,13 +40,13 @@ export fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) ?[*]u8 {
40 if (@ptrToInt(dest) < @ptrToInt(src)) {40 if (@ptrToInt(dest) < @ptrToInt(src)) {
41 var index: usize = 0;41 var index: usize = 0;
42 while (index != n) : (index += 1) {42 while (index != n) : (index += 1) {
43 (??dest)[index] = (??src)[index];43 dest.?[index] = src.?[index];
44 }44 }
45 } else {45 } else {
46 var index = n;46 var index = n;
47 while (index != 0) {47 while (index != 0) {
48 index -= 1;48 index -= 1;
49 (??dest)[index] = (??src)[index];49 dest.?[index] = src.?[index];
50 }50 }
51 }51 }
5252
std/unicode.zig+12-12
...@@ -286,15 +286,15 @@ fn testUtf8IteratorOnAscii() void {...@@ -286,15 +286,15 @@ fn testUtf8IteratorOnAscii() void {
286 const s = Utf8View.initComptime("abc");286 const s = Utf8View.initComptime("abc");
287287
288 var it1 = s.iterator();288 var it1 = s.iterator();
289 debug.assert(std.mem.eql(u8, "a", ??it1.nextCodepointSlice()));289 debug.assert(std.mem.eql(u8, "a", it1.nextCodepointSlice().?));
290 debug.assert(std.mem.eql(u8, "b", ??it1.nextCodepointSlice()));290 debug.assert(std.mem.eql(u8, "b", it1.nextCodepointSlice().?));
291 debug.assert(std.mem.eql(u8, "c", ??it1.nextCodepointSlice()));291 debug.assert(std.mem.eql(u8, "c", it1.nextCodepointSlice().?));
292 debug.assert(it1.nextCodepointSlice() == null);292 debug.assert(it1.nextCodepointSlice() == null);
293293
294 var it2 = s.iterator();294 var it2 = s.iterator();
295 debug.assert(??it2.nextCodepoint() == 'a');295 debug.assert(it2.nextCodepoint().? == 'a');
296 debug.assert(??it2.nextCodepoint() == 'b');296 debug.assert(it2.nextCodepoint().? == 'b');
297 debug.assert(??it2.nextCodepoint() == 'c');297 debug.assert(it2.nextCodepoint().? == 'c');
298 debug.assert(it2.nextCodepoint() == null);298 debug.assert(it2.nextCodepoint() == null);
299}299}
300300
...@@ -321,15 +321,15 @@ fn testUtf8ViewOk() void {...@@ -321,15 +321,15 @@ fn testUtf8ViewOk() void {
321 const s = Utf8View.initComptime("東京市");321 const s = Utf8View.initComptime("東京市");
322322
323 var it1 = s.iterator();323 var it1 = s.iterator();
324 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()));325 debug.assert(std.mem.eql(u8, "京", it1.nextCodepointSlice().?));
326 debug.assert(std.mem.eql(u8, "市", ??it1.nextCodepointSlice()));326 debug.assert(std.mem.eql(u8, "市", it1.nextCodepointSlice().?));
327 debug.assert(it1.nextCodepointSlice() == null);327 debug.assert(it1.nextCodepointSlice() == null);
328328
329 var it2 = s.iterator();329 var it2 = s.iterator();
330 debug.assert(??it2.nextCodepoint() == 0x6771);330 debug.assert(it2.nextCodepoint().? == 0x6771);
331 debug.assert(??it2.nextCodepoint() == 0x4eac);331 debug.assert(it2.nextCodepoint().? == 0x4eac);
332 debug.assert(??it2.nextCodepoint() == 0x5e02);332 debug.assert(it2.nextCodepoint().? == 0x5e02);
333 debug.assert(it2.nextCodepoint() == null);333 debug.assert(it2.nextCodepoint() == null);
334}334}
335335
std/zig/ast.zig+6-6
...@@ -1417,7 +1417,7 @@ pub const Node = struct {...@@ -1417,7 +1417,7 @@ pub const Node = struct {
1417 Range,1417 Range,
1418 Sub,1418 Sub,
1419 SubWrap,1419 SubWrap,
1420 UnwrapMaybe,1420 UnwrapOptional,
1421 };1421 };
14221422
1423 pub fn iterate(self: *InfixOp, index: usize) ?*Node {1423 pub fn iterate(self: *InfixOp, index: usize) ?*Node {
...@@ -1475,7 +1475,7 @@ pub const Node = struct {...@@ -1475,7 +1475,7 @@ pub const Node = struct {
1475 Op.Range,1475 Op.Range,
1476 Op.Sub,1476 Op.Sub,
1477 Op.SubWrap,1477 Op.SubWrap,
1478 Op.UnwrapMaybe,1478 Op.UnwrapOptional,
1479 => {},1479 => {},
1480 }1480 }
14811481
...@@ -1507,14 +1507,13 @@ pub const Node = struct {...@@ -1507,14 +1507,13 @@ pub const Node = struct {
1507 BitNot,1507 BitNot,
1508 BoolNot,1508 BoolNot,
1509 Cancel,1509 Cancel,
1510 MaybeType,1510 OptionalType,
1511 Negation,1511 Negation,
1512 NegationWrap,1512 NegationWrap,
1513 Resume,1513 Resume,
1514 PtrType: PtrInfo,1514 PtrType: PtrInfo,
1515 SliceType: PtrInfo,1515 SliceType: PtrInfo,
1516 Try,1516 Try,
1517 UnwrapMaybe,
1518 };1517 };
15191518
1520 pub const PtrInfo = struct {1519 pub const PtrInfo = struct {
...@@ -1557,12 +1556,12 @@ pub const Node = struct {...@@ -1557,12 +1556,12 @@ pub const Node = struct {
1557 Op.BitNot,1556 Op.BitNot,
1558 Op.BoolNot,1557 Op.BoolNot,
1559 Op.Cancel,1558 Op.Cancel,
1560 Op.MaybeType,1559 Op.OptionalType,
1561 Op.Negation,1560 Op.Negation,
1562 Op.NegationWrap,1561 Op.NegationWrap,
1563 Op.Try,1562 Op.Try,
1564 Op.Resume,1563 Op.Resume,
1565 Op.UnwrapMaybe,1564 Op.UnwrapOptional,
1566 Op.PointerType,1565 Op.PointerType,
1567 => {},1566 => {},
1568 }1567 }
...@@ -1619,6 +1618,7 @@ pub const Node = struct {...@@ -1619,6 +1618,7 @@ pub const Node = struct {
1619 ArrayInitializer: InitList,1618 ArrayInitializer: InitList,
1620 StructInitializer: InitList,1619 StructInitializer: InitList,
1621 Deref,1620 Deref,
1621 UnwrapOptional,
16221622
1623 pub const InitList = SegmentedList(*Node, 2);1623 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 {...@@ -711,7 +711,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
711 else => {711 else => {
712 // TODO: this is a special case. Remove this when #760 is fixed712 // TODO: this is a special case. Remove this when #760 is fixed
713 if (token_ptr.id == Token.Id.Keyword_error) {713 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) {
715 const error_type_node = try arena.construct(ast.Node.ErrorType{715 const error_type_node = try arena.construct(ast.Node.ErrorType{
716 .base = ast.Node{ .id = ast.Node.Id.ErrorType },716 .base = ast.Node{ .id = ast.Node.Id.ErrorType },
717 .token = token_index,717 .token = token_index,
...@@ -1434,8 +1434,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1434,8 +1434,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1434 try stack.append(State{1434 try stack.append(State{
1435 .ExpectTokenSave = ExpectTokenSave{1435 .ExpectTokenSave = ExpectTokenSave{
1436 .id = Token.Id.AngleBracketRight,1436 .id = Token.Id.AngleBracketRight,
1437 .ptr = &??async_node.rangle_bracket,1437 .ptr = &async_node.rangle_bracket.? },
1438 },
1439 });1438 });
1440 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &async_node.allocator_type } });1439 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &async_node.allocator_type } });
1441 continue;1440 continue;
...@@ -1567,7 +1566,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -1567,7 +1566,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1567 .bit_range = null,1566 .bit_range = null,
1568 };1567 };
1569 // TODO https://github.com/ziglang/zig/issues/10221568 // 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
1572 try stack.append(State{ .AlignBitRange = align_info });1571 try stack.append(State{ .AlignBitRange = align_info });
1573 try stack.append(State{ .Expression = OptionalCtx{ .Required = &align_info.node } });1572 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 {...@@ -1604,7 +1603,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
1604 switch (token.ptr.id) {1603 switch (token.ptr.id) {
1605 Token.Id.Colon => {1604 Token.Id.Colon => {
1606 align_info.bit_range = ast.Node.PrefixOp.PtrInfo.Align.BitRange(undefined);1605 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
1609 try stack.append(State{ .ExpectToken = Token.Id.RParen });1608 try stack.append(State{ .ExpectToken = Token.Id.RParen });
1610 try stack.append(State{ .Expression = OptionalCtx{ .Required = &bit_range.end } });1609 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 {...@@ -2144,7 +2143,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2144 State.CurlySuffixExpressionEnd => |opt_ctx| {2143 State.CurlySuffixExpressionEnd => |opt_ctx| {
2145 const lhs = opt_ctx.get() ?? continue;2144 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) {
2148 const node = try arena.construct(ast.Node.SuffixOp{2147 const node = try arena.construct(ast.Node.SuffixOp{
2149 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },2148 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
2150 .lhs = lhs,2149 .lhs = lhs,
...@@ -2326,6 +2325,17 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2326,6 +2325,17 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2326 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;2325 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2327 continue;2326 continue;
2328 }2327 }
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 }
2329 const node = try arena.construct(ast.Node.InfixOp{2339 const node = try arena.construct(ast.Node.InfixOp{
2330 .base = ast.Node{ .id = ast.Node.Id.InfixOp },2340 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
2331 .lhs = lhs,2341 .lhs = lhs,
...@@ -2403,7 +2413,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {...@@ -2403,7 +2413,7 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
2403 .arrow_token = next_token_index,2413 .arrow_token = next_token_index,
2404 .return_type = undefined,2414 .return_type = undefined,
2405 };2415 };
2406 const return_type_ptr = &((??node.result).return_type);2416 const return_type_ptr = &node.result.?.return_type;
2407 try stack.append(State{ .Expression = OptionalCtx{ .Required = return_type_ptr } });2417 try stack.append(State{ .Expression = OptionalCtx{ .Required = return_type_ptr } });
2408 continue;2418 continue;
2409 },2419 },
...@@ -2875,7 +2885,7 @@ const OptionalCtx = union(enum) {...@@ -2875,7 +2885,7 @@ const OptionalCtx = union(enum) {
2875 pub fn get(self: *const OptionalCtx) ?*ast.Node {2885 pub fn get(self: *const OptionalCtx) ?*ast.Node {
2876 switch (self.*) {2886 switch (self.*) {
2877 OptionalCtx.Optional => |ptr| return ptr.*,2887 OptionalCtx.Optional => |ptr| return ptr.*,
2878 OptionalCtx.RequiredNull => |ptr| return ??ptr.*,2888 OptionalCtx.RequiredNull => |ptr| return ptr.*.?,
2879 OptionalCtx.Required => |ptr| return ptr.*,2889 OptionalCtx.Required => |ptr| return ptr.*,
2880 }2890 }
2881 }2891 }
...@@ -3237,7 +3247,7 @@ fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {...@@ -3237,7 +3247,7 @@ fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {
3237fn tokenIdToUnwrapExpr(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {3247fn tokenIdToUnwrapExpr(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {
3238 return switch (id) {3248 return switch (id) {
3239 Token.Id.Keyword_catch => ast.Node.InfixOp.Op{ .Catch = null },3249 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{} },
3241 else => null,3251 else => null,
3242 };3252 };
3243}3253}
...@@ -3299,8 +3309,7 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {...@@ -3299,8 +3309,7 @@ fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {
3299 .volatile_token = null,3309 .volatile_token = null,
3300 },3310 },
3301 },3311 },
3302 Token.Id.QuestionMark => ast.Node.PrefixOp.Op{ .MaybeType = void{} },3312 Token.Id.QuestionMark => ast.Node.PrefixOp.Op{ .OptionalType = void{} },
3303 Token.Id.QuestionMarkQuestionMark => ast.Node.PrefixOp.Op{ .UnwrapMaybe = void{} },
3304 Token.Id.Keyword_await => ast.Node.PrefixOp.Op{ .Await = void{} },3313 Token.Id.Keyword_await => ast.Node.PrefixOp.Op{ .Await = void{} },
3305 Token.Id.Keyword_try => ast.Node.PrefixOp.Op{ .Try = void{} },3314 Token.Id.Keyword_try => ast.Node.PrefixOp.Op{ .Try = void{} },
3306 else => null,3315 else => null,
...@@ -3322,7 +3331,7 @@ fn createToCtxLiteral(arena: *mem.Allocator, opt_ctx: *const OptionalCtx, compti...@@ -3322,7 +3331,7 @@ fn createToCtxLiteral(arena: *mem.Allocator, opt_ctx: *const OptionalCtx, compti
3322}3331}
33233332
3324fn eatToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree, id: @TagType(Token.Id)) ?TokenIndex {3333fn 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
3327 if (token.id == id) {3336 if (token.id == id) {
3328 return nextToken(tok_it, tree).index;3337 return nextToken(tok_it, tree).index;
...@@ -3334,7 +3343,7 @@ fn eatToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree, id: @TagType(...@@ -3334,7 +3343,7 @@ fn eatToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree, id: @TagType(
3334fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedToken {3343fn nextToken(tok_it: *ast.Tree.TokenList.Iterator, tree: *ast.Tree) AnnotatedToken {
3335 const result = AnnotatedToken{3344 const result = AnnotatedToken{
3336 .index = tok_it.index,3345 .index = tok_it.index,
3337 .ptr = ??tok_it.next(),3346 .ptr = tok_it.next().?,
3338 };3347 };
3339 assert(result.ptr.id != Token.Id.LineComment);3348 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" {...@@ -650,9 +650,10 @@ test "zig fmt: statements with empty line between" {
650 );650 );
651}651}
652652
653test "zig fmt: ptr deref operator" {653test "zig fmt: ptr deref operator and unwrap optional operator" {
654 try testCanonical(654 try testCanonical(
655 \\const a = b.*;655 \\const a = b.*;
656 \\const a = b.?;
656 \\657 \\
657 );658 );
658}659}
...@@ -1209,7 +1210,7 @@ test "zig fmt: precedence" {...@@ -1209,7 +1210,7 @@ test "zig fmt: precedence" {
1209test "zig fmt: prefix operators" {1210test "zig fmt: prefix operators" {
1210 try testCanonical(1211 try testCanonical(
1211 \\test "prefix operators" {1212 \\test "prefix operators" {
1212 \\ try return --%~??!*&0;1213 \\ try return --%~!*&0;
1213 \\}1214 \\}
1214 \\1215 \\
1215 );1216 );
std/zig/render.zig+12-13
...@@ -222,7 +222,7 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i...@@ -222,7 +222,7 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i
222 }222 }
223 }223 }
224224
225 const value_expr = ??tag.value_expr;225 const value_expr = tag.value_expr.?;
226 try renderToken(tree, stream, tree.prevToken(value_expr.firstToken()), indent, start_col, Space.Space); // =226 try renderToken(tree, stream, tree.prevToken(value_expr.firstToken()), indent, start_col, Space.Space); // =
227 try renderExpression(allocator, stream, tree, indent, start_col, value_expr, Space.Comma); // value,227 try renderExpression(allocator, stream, tree, indent, start_col, value_expr, Space.Comma); // value,
228 },228 },
...@@ -465,8 +465,7 @@ fn renderExpression(...@@ -465,8 +465,7 @@ fn renderExpression(
465 ast.Node.PrefixOp.Op.BoolNot,465 ast.Node.PrefixOp.Op.BoolNot,
466 ast.Node.PrefixOp.Op.Negation,466 ast.Node.PrefixOp.Op.Negation,
467 ast.Node.PrefixOp.Op.NegationWrap,467 ast.Node.PrefixOp.Op.NegationWrap,
468 ast.Node.PrefixOp.Op.UnwrapMaybe,468 ast.Node.PrefixOp.Op.OptionalType,
469 ast.Node.PrefixOp.Op.MaybeType,
470 ast.Node.PrefixOp.Op.AddressOf,469 ast.Node.PrefixOp.Op.AddressOf,
471 => {470 => {
472 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None);471 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None);
...@@ -513,7 +512,7 @@ fn renderExpression(...@@ -513,7 +512,7 @@ fn renderExpression(
513512
514 var it = call_info.params.iterator(0);513 var it = call_info.params.iterator(0);
515 while (true) {514 while (true) {
516 const param_node = ??it.next();515 const param_node = it.next().?;
517516
518 const param_node_new_indent = if (param_node.*.id == ast.Node.Id.MultilineStringLiteral) blk: {517 const param_node_new_indent = if (param_node.*.id == ast.Node.Id.MultilineStringLiteral) blk: {
519 break :blk indent;518 break :blk indent;
...@@ -559,10 +558,10 @@ fn renderExpression(...@@ -559,10 +558,10 @@ fn renderExpression(
559 return renderToken(tree, stream, rbracket, indent, start_col, space); // ]558 return renderToken(tree, stream, rbracket, indent, start_col, space); // ]
560 },559 },
561560
562 ast.Node.SuffixOp.Op.Deref => {561 ast.Node.SuffixOp.Op.Deref, ast.Node.SuffixOp.Op.UnwrapOptional => {
563 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);562 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
564 try renderToken(tree, stream, tree.prevToken(suffix_op.rtoken), indent, start_col, Space.None); // .563 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 ?
566 },565 },
567566
568 @TagType(ast.Node.SuffixOp.Op).Slice => |range| {567 @TagType(ast.Node.SuffixOp.Op).Slice => |range| {
...@@ -595,7 +594,7 @@ fn renderExpression(...@@ -595,7 +594,7 @@ fn renderExpression(
595 }594 }
596595
597 if (field_inits.len == 1) blk: {596 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
600 if (field_init.expr.cast(ast.Node.SuffixOp)) |nested_suffix_op| {599 if (field_init.expr.cast(ast.Node.SuffixOp)) |nested_suffix_op| {
601 if (nested_suffix_op.op == ast.Node.SuffixOp.Op.StructInitializer) {600 if (nested_suffix_op.op == ast.Node.SuffixOp.Op.StructInitializer) {
...@@ -688,7 +687,7 @@ fn renderExpression(...@@ -688,7 +687,7 @@ fn renderExpression(
688 var count: usize = 1;687 var count: usize = 1;
689 var it = exprs.iterator(0);688 var it = exprs.iterator(0);
690 while (true) {689 while (true) {
691 const expr = (??it.next()).*;690 const expr = it.next().?.*;
692 if (it.peek()) |next_expr| {691 if (it.peek()) |next_expr| {
693 const expr_last_token = expr.*.lastToken() + 1;692 const expr_last_token = expr.*.lastToken() + 1;
694 const loc = tree.tokenLocation(tree.tokens.at(expr_last_token).end, next_expr.*.firstToken());693 const loc = tree.tokenLocation(tree.tokens.at(expr_last_token).end, next_expr.*.firstToken());
...@@ -806,7 +805,7 @@ fn renderExpression(...@@ -806,7 +805,7 @@ fn renderExpression(
806 },805 },
807 }806 }
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);
810 },809 },
811810
812 ast.Node.Id.Payload => {811 ast.Node.Id.Payload => {
...@@ -1245,7 +1244,7 @@ fn renderExpression(...@@ -1245,7 +1244,7 @@ fn renderExpression(
1245 } else {1244 } else {
1246 var it = switch_case.items.iterator(0);1245 var it = switch_case.items.iterator(0);
1247 while (true) {1246 while (true) {
1248 const node = ??it.next();1247 const node = it.next().?;
1249 if (it.peek()) |next_node| {1248 if (it.peek()) |next_node| {
1250 try renderExpression(allocator, stream, tree, indent, start_col, node.*, Space.None);1249 try renderExpression(allocator, stream, tree, indent, start_col, node.*, Space.None);
12511250
...@@ -1550,7 +1549,7 @@ fn renderExpression(...@@ -1550,7 +1549,7 @@ fn renderExpression(
15501549
1551 var it = asm_node.outputs.iterator(0);1550 var it = asm_node.outputs.iterator(0);
1552 while (true) {1551 while (true) {
1553 const asm_output = ??it.next();1552 const asm_output = it.next().?;
1554 const node = &(asm_output.*).base;1553 const node = &(asm_output.*).base;
15551554
1556 if (it.peek()) |next_asm_output| {1555 if (it.peek()) |next_asm_output| {
...@@ -1588,7 +1587,7 @@ fn renderExpression(...@@ -1588,7 +1587,7 @@ fn renderExpression(
15881587
1589 var it = asm_node.inputs.iterator(0);1588 var it = asm_node.inputs.iterator(0);
1590 while (true) {1589 while (true) {
1591 const asm_input = ??it.next();1590 const asm_input = it.next().?;
1592 const node = &(asm_input.*).base;1591 const node = &(asm_input.*).base;
15931592
1594 if (it.peek()) |next_asm_input| {1593 if (it.peek()) |next_asm_input| {
...@@ -1620,7 +1619,7 @@ fn renderExpression(...@@ -1620,7 +1619,7 @@ fn renderExpression(
16201619
1621 var it = asm_node.clobbers.iterator(0);1620 var it = asm_node.clobbers.iterator(0);
1622 while (true) {1621 while (true) {
1623 const clobber_token = ??it.next();1622 const clobber_token = it.next().?;
16241623
1625 if (it.peek() == null) {1624 if (it.peek() == null) {
1626 try renderToken(tree, stream, clobber_token.*, indent_once, start_col, Space.Newline);1625 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 {...@@ -9,7 +9,7 @@ const Value = struct {
9 align_expr: ?u32,9 align_expr: ?u32,
10};10};
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" {
13 foo(false, true);13 foo(false, true);
14}14}
1515
test/cases/cast.zig+25-25
...@@ -109,16 +109,16 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {...@@ -109,16 +109,16 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
109 const Self = this;109 const Self = this;
110 x: u8,110 x: u8,
111 fn constConst(p: *const *const Self) u8 {111 fn constConst(p: *const *const Self) u8 {
112 return (p.*).x;112 return p.*.x;
113 }113 }
114 fn maybeConstConst(p: ?*const *const Self) u8 {114 fn maybeConstConst(p: ?*const *const Self) u8 {
115 return ((??p).*).x;115 return p.?.*.x;
116 }116 }
117 fn constConstConst(p: *const *const *const Self) u8 {117 fn constConstConst(p: *const *const *const Self) u8 {
118 return (p.*.*).x;118 return p.*.*.x;
119 }119 }
120 fn maybeConstConstConst(p: ?*const *const *const Self) u8 {120 fn maybeConstConstConst(p: ?*const *const *const Self) u8 {
121 return ((??p).*.*).x;121 return p.?.*.*.x;
122 }122 }
123 };123 };
124 const s = S{ .x = 42 };124 const s = S{ .x = 42 };
...@@ -177,56 +177,56 @@ test "string literal to &const []const u8" {...@@ -177,56 +177,56 @@ test "string literal to &const []const u8" {
177}177}
178178
179test "implicitly cast from T to error!?T" {179test "implicitly cast from T to error!?T" {
180 castToMaybeTypeError(1);180 castToOptionalTypeError(1);
181 comptime castToMaybeTypeError(1);181 comptime castToOptionalTypeError(1);
182}182}
183const A = struct {183const A = struct {
184 a: i32,184 a: i32,
185};185};
186fn castToMaybeTypeError(z: i32) void {186fn castToOptionalTypeError(z: i32) void {
187 const x = i32(1);187 const x = i32(1);
188 const y: error!?i32 = x;188 const y: error!?i32 = x;
189 assert(??(try y) == 1);189 assert((try y).? == 1);
190190
191 const f = z;191 const f = z;
192 const g: error!?i32 = f;192 const g: error!?i32 = f;
193193
194 const a = A{ .a = z };194 const a = A{ .a = z };
195 const b: error!?A = a;195 const b: error!?A = a;
196 assert((??(b catch unreachable)).a == 1);196 assert((b catch unreachable).?.a == 1);
197}197}
198198
199test "implicitly cast from int to error!?T" {199test "implicitly cast from int to error!?T" {
200 implicitIntLitToMaybe();200 implicitIntLitToOptional();
201 comptime implicitIntLitToMaybe();201 comptime implicitIntLitToOptional();
202}202}
203fn implicitIntLitToMaybe() void {203fn implicitIntLitToOptional() void {
204 const f: ?i32 = 1;204 const f: ?i32 = 1;
205 const g: error!?i32 = 1;205 const g: error!?i32 = 1;
206}206}
207207
208test "return null from fn() error!?&T" {208test "return null from fn() error!?&T" {
209 const a = returnNullFromMaybeTypeErrorRef();209 const a = returnNullFromOptionalTypeErrorRef();
210 const b = returnNullLitFromMaybeTypeErrorRef();210 const b = returnNullLitFromOptionalTypeErrorRef();
211 assert((try a) == null and (try b) == null);211 assert((try a) == null and (try b) == null);
212}212}
213fn returnNullFromMaybeTypeErrorRef() error!?*A {213fn returnNullFromOptionalTypeErrorRef() error!?*A {
214 const a: ?*A = null;214 const a: ?*A = null;
215 return a;215 return a;
216}216}
217fn returnNullLitFromMaybeTypeErrorRef() error!?*A {217fn returnNullLitFromOptionalTypeErrorRef() error!?*A {
218 return null;218 return null;
219}219}
220220
221test "peer type resolution: ?T and T" {221test "peer type resolution: ?T and T" {
222 assert(??peerTypeTAndMaybeT(true, false) == 0);222 assert(peerTypeTAndOptionalT(true, false).? == 0);
223 assert(??peerTypeTAndMaybeT(false, false) == 3);223 assert(peerTypeTAndOptionalT(false, false).? == 3);
224 comptime {224 comptime {
225 assert(??peerTypeTAndMaybeT(true, false) == 0);225 assert(peerTypeTAndOptionalT(true, false).? == 0);
226 assert(??peerTypeTAndMaybeT(false, false) == 3);226 assert(peerTypeTAndOptionalT(false, false).? == 3);
227 }227 }
228}228}
229fn peerTypeTAndMaybeT(c: bool, b: bool) ?usize {229fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
230 if (c) {230 if (c) {
231 return if (b) null else usize(0);231 return if (b) null else usize(0);
232 }232 }
...@@ -251,11 +251,11 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {...@@ -251,11 +251,11 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
251}251}
252252
253test "implicitly cast from [N]T to ?[]const T" {253test "implicitly cast from [N]T to ?[]const T" {
254 assert(mem.eql(u8, ??castToMaybeSlice(), "hi"));254 assert(mem.eql(u8, castToOptionalSlice().?, "hi"));
255 comptime assert(mem.eql(u8, ??castToMaybeSlice(), "hi"));255 comptime assert(mem.eql(u8, castToOptionalSlice().?, "hi"));
256}256}
257257
258fn castToMaybeSlice() ?[]const u8 {258fn castToOptionalSlice() ?[]const u8 {
259 return "hi";259 return "hi";
260}260}
261261
...@@ -404,5 +404,5 @@ fn testCastPtrOfArrayToSliceAndPtr() void {...@@ -404,5 +404,5 @@ fn testCastPtrOfArrayToSliceAndPtr() void {
404test "cast *[1][*]const u8 to [*]const ?[*]const u8" {404test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
405 const window_name = [1][*]const u8{c"window name"};405 const window_name = [1][*]const u8{c"window name"};
406 const x: [*]const ?[*]const u8 = &window_name;406 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"));
408}408}
test/cases/error.zig+1-1
...@@ -140,7 +140,7 @@ fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {...@@ -140,7 +140,7 @@ fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {
140 if (x) |v| assert(v == 1234) else |err| @compileError("bad");140 if (x) |v| assert(v == 1234) else |err| @compileError("bad");
141}141}
142142
143test "syntax: nullable operator in front of error union operator" {143test "syntax: optional operator in front of error union operator" {
144 comptime {144 comptime {
145 assert(?error!i32 == ?(error!i32));145 assert(?error!i32 == ?(error!i32));
146 }146 }
test/cases/eval.zig+1-1
...@@ -12,7 +12,7 @@ fn fibonacci(x: i32) i32 {...@@ -12,7 +12,7 @@ fn fibonacci(x: i32) i32 {
12}12}
1313
14fn unwrapAndAddOne(blah: ?i32) i32 {14fn unwrapAndAddOne(blah: ?i32) i32 {
15 return ??blah + 1;15 return blah.? + 1;
16}16}
17const should_be_1235 = unwrapAndAddOne(1234);17const should_be_1235 = unwrapAndAddOne(1234);
18test "static add one" {18test "static add one" {
test/cases/generics.zig+1-1
...@@ -127,7 +127,7 @@ test "generic fn with implicit cast" {...@@ -127,7 +127,7 @@ test "generic fn with implicit cast" {
127 }) == 0);127 }) == 0);
128}128}
129fn getByte(ptr: ?*const u8) u8 {129fn getByte(ptr: ?*const u8) u8 {
130 return (??ptr).*;130 return ptr.?.*;
131}131}
132fn getFirstByte(comptime T: type, mem: []const T) u8 {132fn getFirstByte(comptime T: type, mem: []const T) u8 {
133 return getByte(@ptrCast(*const u8, &mem[0]));133 return getByte(@ptrCast(*const u8, &mem[0]));
test/cases/misc.zig+1-1
...@@ -505,7 +505,7 @@ test "@typeId" {...@@ -505,7 +505,7 @@ test "@typeId" {
505 assert(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat);505 assert(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat);
506 assert(@typeId(@typeOf(undefined)) == Tid.Undefined);506 assert(@typeId(@typeOf(undefined)) == Tid.Undefined);
507 assert(@typeId(@typeOf(null)) == Tid.Null);507 assert(@typeId(@typeOf(null)) == Tid.Null);
508 assert(@typeId(?i32) == Tid.Nullable);508 assert(@typeId(?i32) == Tid.Optional);
509 assert(@typeId(error!i32) == Tid.ErrorUnion);509 assert(@typeId(error!i32) == Tid.ErrorUnion);
510 assert(@typeId(error) == Tid.ErrorSet);510 assert(@typeId(error) == Tid.ErrorSet);
511 assert(@typeId(AnEnum) == Tid.Enum);511 assert(@typeId(AnEnum) == Tid.Enum);
test/cases/null.zig+15-15
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3test "nullable type" {3test "optional type" {
4 const x: ?bool = true;4 const x: ?bool = true;
55
6 if (x) |y| {6 if (x) |y| {
...@@ -33,7 +33,7 @@ test "test maybe object and get a pointer to the inner value" {...@@ -33,7 +33,7 @@ test "test maybe object and get a pointer to the inner value" {
33 b.* = false;33 b.* = false;
34 }34 }
3535
36 assert(??maybe_bool == false);36 assert(maybe_bool.? == false);
37}37}
3838
39test "rhs maybe unwrap return" {39test "rhs maybe unwrap return" {
...@@ -47,9 +47,9 @@ test "maybe return" {...@@ -47,9 +47,9 @@ test "maybe return" {
47}47}
4848
49fn maybeReturnImpl() void {49fn maybeReturnImpl() void {
50 assert(??foo(1235));50 assert(foo(1235).?);
51 if (foo(null) != null) unreachable;51 if (foo(null) != null) unreachable;
52 assert(!??foo(1234));52 assert(!foo(1234).?);
53}53}
5454
55fn foo(x: ?i32) ?bool {55fn foo(x: ?i32) ?bool {
...@@ -102,12 +102,12 @@ fn testTestNullRuntime(x: ?i32) void {...@@ -102,12 +102,12 @@ fn testTestNullRuntime(x: ?i32) void {
102 assert(!(x != null));102 assert(!(x != null));
103}103}
104104
105test "nullable void" {105test "optional void" {
106 nullableVoidImpl();106 optionalVoidImpl();
107 comptime nullableVoidImpl();107 comptime optionalVoidImpl();
108}108}
109109
110fn nullableVoidImpl() void {110fn optionalVoidImpl() void {
111 assert(bar(null) == null);111 assert(bar(null) == null);
112 assert(bar({}) != null);112 assert(bar({}) != null);
113}113}
...@@ -120,19 +120,19 @@ fn bar(x: ?void) ?void {...@@ -120,19 +120,19 @@ fn bar(x: ?void) ?void {
120 }120 }
121}121}
122122
123const StructWithNullable = struct {123const StructWithOptional = struct {
124 field: ?i32,124 field: ?i32,
125};125};
126126
127var struct_with_nullable: StructWithNullable = undefined;127var struct_with_optional: StructWithOptional = undefined;
128128
129test "unwrap nullable which is field of global var" {129test "unwrap optional which is field of global var" {
130 struct_with_nullable.field = null;130 struct_with_optional.field = null;
131 if (struct_with_nullable.field) |payload| {131 if (struct_with_optional.field) |payload| {
132 unreachable;132 unreachable;
133 }133 }
134 struct_with_nullable.field = 1234;134 struct_with_optional.field = 1234;
135 if (struct_with_nullable.field) |payload| {135 if (struct_with_optional.field) |payload| {
136 assert(payload == 1234);136 assert(payload == 1234);
137 } else {137 } else {
138 unreachable;138 unreachable;
test/cases/reflection.zig+1-1
...@@ -2,7 +2,7 @@ const assert = @import("std").debug.assert;...@@ -2,7 +2,7 @@ const assert = @import("std").debug.assert;
2const mem = @import("std").mem;2const mem = @import("std").mem;
3const reflection = this;3const reflection = this;
44
5test "reflection: array, pointer, nullable, error union type child" {5test "reflection: array, pointer, optional, error union type child" {
6 comptime {6 comptime {
7 assert(([10]u8).Child == u8);7 assert(([10]u8).Child == u8);
8 assert((*u8).Child == u8);8 assert((*u8).Child == u8);
test/cases/type_info.zig+7-7
...@@ -88,15 +88,15 @@ fn testArray() void {...@@ -88,15 +88,15 @@ fn testArray() void {
88 assert(arr_info.Array.child == bool);88 assert(arr_info.Array.child == bool);
89}89}
9090
91test "type info: nullable type info" {91test "type info: optional type info" {
92 testNullable();92 testOptional();
93 comptime testNullable();93 comptime testOptional();
94}94}
9595
96fn testNullable() void {96fn testOptional() void {
97 const null_info = @typeInfo(?void);97 const null_info = @typeInfo(?void);
98 assert(TypeId(null_info) == TypeId.Nullable);98 assert(TypeId(null_info) == TypeId.Optional);
99 assert(null_info.Nullable.child == void);99 assert(null_info.Optional.child == void);
100}100}
101101
102test "type info: promise info" {102test "type info: promise info" {
...@@ -168,7 +168,7 @@ fn testUnion() void {...@@ -168,7 +168,7 @@ fn testUnion() void {
168 assert(typeinfo_info.Union.tag_type == TypeId);168 assert(typeinfo_info.Union.tag_type == TypeId);
169 assert(typeinfo_info.Union.fields.len == 25);169 assert(typeinfo_info.Union.fields.len == 25);
170 assert(typeinfo_info.Union.fields[4].enum_field != null);170 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);
172 assert(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));172 assert(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));
173 assert(typeinfo_info.Union.defs.len == 20);173 assert(typeinfo_info.Union.defs.len == 20);
174174
test/cases/while.zig+6-6
...@@ -81,7 +81,7 @@ test "while with else" {...@@ -81,7 +81,7 @@ test "while with else" {
81 assert(got_else == 1);81 assert(got_else == 1);
82}82}
8383
84test "while with nullable as condition" {84test "while with optional as condition" {
85 numbers_left = 10;85 numbers_left = 10;
86 var sum: i32 = 0;86 var sum: i32 = 0;
87 while (getNumberOrNull()) |value| {87 while (getNumberOrNull()) |value| {
...@@ -90,7 +90,7 @@ test "while with nullable as condition" {...@@ -90,7 +90,7 @@ test "while with nullable as condition" {
90 assert(sum == 45);90 assert(sum == 45);
91}91}
9292
93test "while with nullable as condition with else" {93test "while with optional as condition with else" {
94 numbers_left = 10;94 numbers_left = 10;
95 var sum: i32 = 0;95 var sum: i32 = 0;
96 var got_else: i32 = 0;96 var got_else: i32 = 0;
...@@ -132,7 +132,7 @@ fn getNumberOrNull() ?i32 {...@@ -132,7 +132,7 @@ fn getNumberOrNull() ?i32 {
132 };132 };
133}133}
134134
135test "while on nullable with else result follow else prong" {135test "while on optional with else result follow else prong" {
136 const result = while (returnNull()) |value| {136 const result = while (returnNull()) |value| {
137 break value;137 break value;
138 } else138 } else
...@@ -140,8 +140,8 @@ test "while on nullable with else result follow else prong" {...@@ -140,8 +140,8 @@ test "while on nullable with else result follow else prong" {
140 assert(result == 2);140 assert(result == 2);
141}141}
142142
143test "while on nullable with else result follow break prong" {143test "while on optional with else result follow break prong" {
144 const result = while (returnMaybe(10)) |value| {144 const result = while (returnOptional(10)) |value| {
145 break value;145 break value;
146 } else146 } else
147 i32(2);147 i32(2);
...@@ -210,7 +210,7 @@ fn testContinueOuter() void {...@@ -210,7 +210,7 @@ fn testContinueOuter() void {
210fn returnNull() ?i32 {210fn returnNull() ?i32 {
211 return null;211 return null;
212}212}
213fn returnMaybe(x: i32) ?i32 {213fn returnOptional(x: i32) ?i32 {
214 return x;214 return x;
215}215}
216fn returnError() error!i32 {216fn returnError() error!i32 {
test/compile_errors.zig+8-8
...@@ -1341,7 +1341,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1341,7 +1341,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1341 \\ if (true) |x| { }1341 \\ if (true) |x| { }
1342 \\}1342 \\}
1343 ,1343 ,
1344 ".tmp_source.zig:2:9: error: expected nullable type, found 'bool'",1344 ".tmp_source.zig:2:9: error: expected optional type, found 'bool'",
1345 );1345 );
13461346
1347 cases.add(1347 cases.add(
...@@ -1780,7 +1780,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1780,7 +1780,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1780 );1780 );
17811781
1782 cases.add(1782 cases.add(
1783 "assign null to non-nullable pointer",1783 "assign null to non-optional pointer",
1784 \\const a: *u8 = null;1784 \\const a: *u8 = null;
1785 \\1785 \\
1786 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }1786 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
...@@ -2817,7 +2817,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2817,7 +2817,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2817 );2817 );
28182818
2819 cases.add(2819 cases.add(
2820 "while expected bool, got nullable",2820 "while expected bool, got optional",
2821 \\export fn foo() void {2821 \\export fn foo() void {
2822 \\ while (bar()) {}2822 \\ while (bar()) {}
2823 \\}2823 \\}
...@@ -2837,23 +2837,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2837,23 +2837,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2837 );2837 );
28382838
2839 cases.add(2839 cases.add(
2840 "while expected nullable, got bool",2840 "while expected optional, got bool",
2841 \\export fn foo() void {2841 \\export fn foo() void {
2842 \\ while (bar()) |x| {}2842 \\ while (bar()) |x| {}
2843 \\}2843 \\}
2844 \\fn bar() bool { return true; }2844 \\fn bar() bool { return true; }
2845 ,2845 ,
2846 ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'",2846 ".tmp_source.zig:2:15: error: expected optional type, found 'bool'",
2847 );2847 );
28482848
2849 cases.add(2849 cases.add(
2850 "while expected nullable, got error union",2850 "while expected optional, got error union",
2851 \\export fn foo() void {2851 \\export fn foo() void {
2852 \\ while (bar()) |x| {}2852 \\ while (bar()) |x| {}
2853 \\}2853 \\}
2854 \\fn bar() error!i32 { return 1; }2854 \\fn bar() error!i32 { return 1; }
2855 ,2855 ,
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'",
2857 );2857 );
28582858
2859 cases.add(2859 cases.add(
...@@ -2867,7 +2867,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2867,7 +2867,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2867 );2867 );
28682868
2869 cases.add(2869 cases.add(
2870 "while expected error union, got nullable",2870 "while expected error union, got optional",
2871 \\export fn foo() void {2871 \\export fn foo() void {
2872 \\ while (bar()) |x| {} else |err| {}2872 \\ while (bar()) |x| {} else |err| {}
2873 \\}2873 \\}
test/tests.zig+6-6
...@@ -282,8 +282,8 @@ pub const CompareOutputContext = struct {...@@ -282,8 +282,8 @@ pub const CompareOutputContext = struct {
282 var stdout = Buffer.initNull(b.allocator);282 var stdout = Buffer.initNull(b.allocator);
283 var stderr = Buffer.initNull(b.allocator);283 var stderr = Buffer.initNull(b.allocator);
284284
285 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);285 var stdout_file_in_stream = io.FileInStream.init(&child.stdout.?);
286 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);286 var stderr_file_in_stream = io.FileInStream.init(&child.stderr.?);
287287
288 stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable;288 stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable;
289 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;289 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
...@@ -601,8 +601,8 @@ pub const CompileErrorContext = struct {...@@ -601,8 +601,8 @@ pub const CompileErrorContext = struct {
601 var stdout_buf = Buffer.initNull(b.allocator);601 var stdout_buf = Buffer.initNull(b.allocator);
602 var stderr_buf = Buffer.initNull(b.allocator);602 var stderr_buf = Buffer.initNull(b.allocator);
603603
604 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);604 var stdout_file_in_stream = io.FileInStream.init(&child.stdout.?);
605 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);605 var stderr_file_in_stream = io.FileInStream.init(&child.stderr.?);
606606
607 stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;607 stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
608 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;608 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
...@@ -872,8 +872,8 @@ pub const TranslateCContext = struct {...@@ -872,8 +872,8 @@ pub const TranslateCContext = struct {
872 var stdout_buf = Buffer.initNull(b.allocator);872 var stdout_buf = Buffer.initNull(b.allocator);
873 var stderr_buf = Buffer.initNull(b.allocator);873 var stderr_buf = Buffer.initNull(b.allocator);
874874
875 var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);875 var stdout_file_in_stream = io.FileInStream.init(&child.stdout.?);
876 var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);876 var stderr_file_in_stream = io.FileInStream.init(&child.stderr.?);
877877
878 stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;878 stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
879 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;879 stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;