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