authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-10-23 08:00:41+02:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-10-23 08:00:41+02:00
logfb255db0adc7fb39f4d33738fcf3c5831a1a7649
treea5ade7b27a5c2002ffacb7ba02d21c0dd75e9049
parent0a01fe2bc6748b5fa2b03cebdcaae0e655501ad4
parent755333971b19907375410c131433668528bb1bc0

Merge pull request 'Parser: Add error when operator precedence is undefined' (#30160) from CMDRZero/zig:ambiguous-precedence into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30160 Reviewed-by: Ryan Liptak <squeek502@noreply.codeberg.org>

114 files changed, 1588 insertions(+), 508 deletions(-)

doc/langref.html.in+100-7
......@@ -1894,20 +1894,77 @@ const B = error{Two};
18941894 </div>
18951895 {#header_close#}
18961896 {#header_open|Precedence#}
1897 <p>
1898 Zig features partial operator precedence: not every operator has a defined precedence with
1899 every other operator. Mixing operators with ambiguous precedence is prohibited and parentheses
1900 are mandatory. Consequently, valid code is typically auto-descriptive; when reading and
1901 writing Zig code, there are very few precedence rules you'll need to remember.
1902 </p>
1903
1904 {#code|operator_precedence.zig#}
1905
1906 {#code|ambiguous_precedence_orelse.zig#}
1907
1908 <p>
1909 There is a set of operators (prefix operators, suffix operators, etc) that have unambiguously
1910 higher precedence than all other operators. That set of operators has the following precedence table:
1911 </p>
1912
18971913 <pre>{#syntax#}x() x[] x.y x.* x.?
18981914a!b
18991915x{}
19001916!x -x -%x ~x &x ?x try
1901* / % *% *| ||
1902+ - ++ +% -% +| -|
1903<< >> <<|
1904& ^ | orelse catch
1917// lower precedence operators omitted{#endsyntax#}</pre>
1918
1919 <p>
1920 For the other operators, simplified operator precedence tables are provided below, each containing only
1921 the information that you'll need to know when reading/writing code that uses that particular category of operators.
1922 The operators that have ambiguous precedence or semantic errors with the relevant operators have been omitted,
1923 as have the operators with higher precedence (those shown above).
1924 </p>
1925
1926 <p>
1927 For arithmetic operators:
1928 </p>
1929
1930 <pre>{#syntax#}* / *% *| %
1931+ - +% -% +| -|
1932== != < > <= >=
1933and or{#endsyntax#}</pre>
1934
1935 <p>
1936 For bitwise operators:
1937 </p>
1938
1939 <pre>{#syntax#}<< <<| >> & ^ |
19051940== != < > <= >=
1906and
1907or
1908= *= *%= *|= /= %= += +%= +|= -= -%= -|= <<= <<|= >>= &= ^= |={#endsyntax#}</pre>
1941and or{#endsyntax#}</pre>
1942
1943 <p>
1944 For null and error recovery operators:
1945 </p>
1946
1947 <pre>{#syntax#}catch orelse{#endsyntax#}</pre>
1948
1949 <p>
1950 For error set operators:
1951 </p>
1952
1953 <pre>{#syntax#}||{#endsyntax#}</pre>
1954
1955 <p>
1956 For array concatenation operators:
1957 </p>
1958
1959 <pre>{#syntax#}++{#endsyntax#}</pre>
1960
1961 <p>
1962 The full precedence rules can be found in the {#link|Grammar#}, which also includes an {#link|Operator Precedence Flowchart#}.
1963 </p>
1964
19091965 {#header_close#}
19101966 {#header_close#}
1967
19111968 {#header_open|Arrays#}
19121969 {#code|test_arrays.zig#}
19131970
......@@ -7879,6 +7936,42 @@ fn readU32Be() u32 {}
78797936 {#header_open|Appendix#}
78807937 {#header_open|Grammar#}
78817938 {#grammar#}
7939 {#header_open|Operator Precedence Flowchart#}
7940 <p>
7941 To help understand the grammar, this flowchart is provided for the operator precedence.
7942 The bottom represents any location where an expression may occur and the topmost row represents
7943 a parenthesized expression. An operator will have a higher precedence (and therefore be the parent) to
7944 another node if it is strictly lower on the tree (having a directed path from one to another). This is inverted from classical precedence, but
7945 is closer to how a recursive descent parser views the grammar.
7946 </p>
7947 <pre><code>
7948 ┏━━━━━━━━━━━━━━━━━━━┓
7949 ┃(expr) ┃
7950 ┃x() x[] x.y x.* x.?┃
7951 ┃E!T ┃
7952 ┃x{} ┃
7953 ┃!x -x -%x ~x &x ?x ┃
7954 ┗━━━━━━━━━▲━━━━━━━━━┛
7955 ┌─────────────┬──────┴───────┬───────┬──┬──┬─┐
7956 │ │ │ │ │ │ │
7957 ┏━━━━━━┷━━━━━┓╭Non╌Chaining╮ ╭Non╌Chaining╮┏┷┓┏┷┓┏┷┓│
7958 ┃* *% *| / ||┃╎ % ╎ ╎ &lt;&lt; &lt;&lt;| >> ╎┃&┃┃^┃┃|┃│
7959 ┗━━━━━━▲━━━━━┛╰╌╌╌╌╌╌▲╌╌╌╌╌╯ ╰╌╌╌╌╌╌▲╌╌╌╌╌╯┗▲┛┗▲┛┗▲┛│
7960 ┏━━┷━━━━━━━━━━━━━┷━┓ ┌────┴───────┴──┴──┘ │
7961 ┃+ - +% -% +| -| ++┃ │ │
7962 ┗━━━━━━━━━━━▲━━━━━━┛ │ │
7963 ╭┴╌Non-Chaining╌┴╮ │
7964 ╎== != &lt; &lt;= >= >╎ │
7965 ╰╌╌╌▲╌╌╌╌▲╌╌╌╌╌╌╌╯ ┌──────┬─────┘
7966 ┏━┷━┓┏━┷━┓ ┏━━━┷━━┓┏━━┷━━┓
7967 ┃and┃┃or ┃ ┃orelse┃┃catch┃
7968 ┗━▲━┛┗━▲━┛ ┗━━━▲━━┛┗━━▲━━┛
7969 ╭╌╌┴╌╌╌╌┴╌╌╌╌╌╌╌╌╌╌╌╌╌╌┴╌╌╌╌╌╌┴╌╮
7970 ╎ Any expression location ╎
7971 ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯
7972
7973 </code></pre>
7974 {#header_close#}
78827975 {#header_close#}
78837976 {#header_open|Zen#}
78847977 <ul>
doc/langref/ambiguous_precedence_orelse.zig created+12
......@@ -0,0 +1,12 @@
1test "ambiguous precedence" {
2 const x: ?bool = true;
3 const y: bool = false;
4 const z: bool = false;
5
6 // The following expression is always considered ambiguous,
7 // and, in this particular case, `(x orelse y) == z` would
8 // produce a different result than `x orelse (y == z)`.
9 _ = x orelse y == z;
10}
11
12// obj=ambiguous operator precedence with operators ... orelse ... == ...; use parentheses to disambiguate
doc/langref/grammar.peg+44-18
......@@ -127,21 +127,34 @@ AssignExpr <- Expr (AssignOp Expr / (COMMA Expr)+ EQUAL Expr / !AssignOp !COMMA)
127127
128128SingleAssignExpr <- Expr (AssignOp Expr / !AssignOp)
129129
130Expr <- BoolOrExpr
130Expr <- PrefixExpr (OrElseExpr / CatchExpr / BoolExpr)
131131
132BoolOrExpr <- BoolAndExpr (OrOp BoolAndExpr)* !OrOp
132OrElseExpr <- (OrElseOp PrefixExpr)+ !RecoveryNonmixingOp
133CatchExpr <- (CatchOp PrefixExpr)+ !RecoveryNonmixingOp
134RecoveryNonmixingOp <- ControlOp / CompareOp / BitwiseNonmixingOp
135ControlOp <- OrElseOp / CatchOp / AndOp / OrOp
133136
134BoolAndExpr <- CompareExpr (AndOp CompareExpr)* !AndOp
137BoolExpr <- CompareExpr (BoolAndExpr / BoolOrExpr / !ControlOp)
138BoolAndExpr <- (AndOp PrefixExpr CompareExpr)+ !ControlOp
139BoolOrExpr <- (OrOp PrefixExpr CompareExpr)+ !ControlOp
135140
136CompareExpr <- BitwiseExpr (CompareOp BitwiseExpr)? !CompareOp
141CompareExpr <- CompareOperand (CompareOp PrefixExpr CompareOperand)? !(CompareOp / OrElseOp / CatchOp)
142CompareOperand
143 <- (BitwiseOrOp PrefixExpr)+ !BitwiseNonmixingOp
144 / (BitwiseAndOp PrefixExpr)+ !BitwiseNonmixingOp
145 / (BitwiseXorOp PrefixExpr)+ !BitwiseNonmixingOp
146 / BitShiftOp PrefixExpr !BitwiseNonmixingOp
147 / !BitOp AdditionExpr
137148
138BitwiseExpr <- BitShiftExpr (BitwiseOp BitShiftExpr)* !BitwiseOp
149BitOp <- BitwiseOrOp / BitwiseAndOp / BitwiseXorOp / BitShiftOp
150BitwiseNonmixingOp <- MultiplyNonmixingOp / AdditionOp
139151
140BitShiftExpr <- AdditionExpr (BitShiftOp AdditionExpr)* !BitShiftOp
152AdditionExpr <- MulOrModExpr (AdditionOp PrefixExpr MulOrModExpr)* !(AdditionOp / BitOp / OrElseOp / CatchOp)
141153
142AdditionExpr <- MultiplyExpr (AdditionOp MultiplyExpr)* !AdditionOp
143
144MultiplyExpr <- PrefixExpr (MultiplyOp PrefixExpr)* !MultiplyOp
154MulOrModExpr <- ModExpr / !ModOp MultiplyExpr
155ModExpr <- ModOp PrefixExpr !MultiplyNonmixingOp
156MultiplyExpr <- (MultiplyOp PrefixExpr)* !MultiplyNonmixingOp
157MultiplyNonmixingOp <- MultiplyOp / ModOp / BitOp / OrElseOp / CatchOp
145158
146159PrefixExpr <- PrefixOp* !PrefixOp PrimaryExpr
147160
......@@ -323,15 +336,26 @@ CompareOpTok
323336 / LARROWEQUAL
324337 / RARROWEQUAL
325338
326BitwiseOp <- pre_op_white BitwiseOpTok post_op_white
327 / !pre_op_white BitwiseOpTok !post_op_white
328 / pre_op_white KEYWORD_catch post_op_white Payload?
329 / !pre_op_white KEYWORD_catch !post_op_white Payload?
330BitwiseOpTok
339BitwiseAndOp <- pre_op_white BitwiseAndOpTok post_op_white
340 / !pre_op_white BitwiseAndOpTok !post_op_white
341BitwiseAndOpTok
331342 <- AMPERSAND ![&]
332 / CARET
333 / PIPE
334 / KEYWORD_orelse
343
344BitwiseOrOp <- pre_op_white BitwiseOrOpTok post_op_white
345 / !pre_op_white BitwiseOrOpTok !post_op_white
346BitwiseOrOpTok
347 <- PIPE
348
349BitwiseXorOp <- pre_op_white BitwiseXorOpTok post_op_white
350 / !pre_op_white BitwiseXorOpTok !post_op_white
351BitwiseXorOpTok
352 <- CARET
353
354CatchOp <- pre_op_white KEYWORD_catch post_op_white Payload?
355 / !pre_op_white KEYWORD_catch !post_op_white Payload?
356
357OrElseOp <- pre_op_white KEYWORD_orelse post_op_white
358 / !pre_op_white KEYWORD_orelse !post_op_white
335359
336360BitShiftOp <- pre_op_white BitShiftOpTok post_op_white
337361 / !pre_op_white BitShiftOpTok !post_op_white
......@@ -357,10 +381,12 @@ MultiplyOpTok
357381 <- PIPE2
358382 / ASTERISK
359383 / SLASH
360 / PERCENT
361384 / ASTERISKPERCENT
362385 / ASTERISKPIPE
363386
387ModOp <- pre_op_white PERCENT post_op_white
388 / !pre_op_white PERCENT !post_op_white
389
364390PrefixOp
365391 <- EXCLAMATIONMARK
366392 / MINUS
doc/langref/operator_precedence.zig created+86
......@@ -0,0 +1,86 @@
1const std = @import("std");
2
3test "operator precedence" {
4 // Arithmetic operators follow the conventional order of operations.
5 {
6 const a = 1 + 2 * 3 - 4 / 2;
7 const b = 1 + (2 * 3) - (4 / 2);
8 try std.testing.expectEqual(a, b);
9 }
10
11 // Remainder division is a special case. It still has a higher precedence than
12 // addition and subtraction, but it has ambiguous precedence with itself and
13 // other multiplication/division operators.
14 {
15 const a = 1 + 2 % 3;
16 const b = 1 + (2 % 3);
17 try std.testing.expectEqual(a, b);
18
19 // `1 % 2 % 3`, `1 % 2 / 3`, etc. would be a compile error,
20 // and parentheses would be required to disambiguate.
21 }
22
23 // Bitwise operators have ambiguous precedence with other bitwise operators.
24 // However, non-shifting bitwise operators (&, |, ^) can be chained with themselves.
25 {
26 const a = 1 ^ 2 ^ 3;
27 const b = (1 ^ 2) ^ 3;
28 try std.testing.expectEqual(a, b);
29
30 // `1 ^ 2 | 3`, `1 << 2 << 3`, etc. would be a compile error,
31 // and parentheses would be required to disambiguate.
32
33 // To mix bitwise operators, parentheses must be used.
34 try std.testing.expectEqual(0x10101, (1 << 16) | (1 << 8) | 1);
35 }
36
37 // Comparison operators have lower precedence than both arithmetic and bitwise
38 // operators. Comparisons cannot be chained.
39 {
40 const a = 1 | 4 <= 1 + 4;
41 const b = (1 | 4) <= (1 + 4);
42 try std.testing.expectEqual(a, b);
43
44 // `1 == 2 >= 3`, etc. would be a compile error,
45 // and parentheses would be required to disambiguate.
46 }
47
48 // Logical operators have lower precedence than comparison operators,
49 // and may only be chained homogeneously (`and` with `and`, but not
50 // with `or`, and vice versa).
51 {
52 const false_expr: bool = 7 < 2;
53 const true_expr: bool = 1 + 1 == 2;
54
55 const a = false_expr or false_expr or true_expr;
56 const b = 7 < 2 or 7 < 2 or 1 + 1 == 2;
57 const c = ((7 < 2) or (7 < 2)) or (1 + 1 == 2);
58 try std.testing.expect(a and b and c);
59
60 // `a or b and c`, etc. would be a compile error,
61 // and parentheses would be required to disambiguate.
62 }
63
64 // `orelse` and `catch` may be chained with themselves, but not each other.
65 {
66 const some_null: ?u8 = null;
67
68 const a = some_null orelse some_null orelse 2;
69 const b = (some_null orelse some_null) orelse 2;
70 try std.testing.expectEqual(a, b);
71
72 // `a catch b orelse c`, etc. would be a compile error,
73 // and parentheses would be required to disambiguate.
74
75 // Prefix operators like `try` have higher precedence than `orelse`/`catch`.
76 const c = try maybe() orelse 1;
77 const d = (try maybe()) orelse 1;
78 try std.testing.expectEqual(c, d);
79 }
80}
81
82fn maybe() error{Fail}!?u8 {
83 return null;
84}
85
86// test
lib/c/math.zig+2-2
......@@ -355,7 +355,7 @@ fn pow10f(x: f32) callconv(.c) f32 {
355355fn rint(x: f64) callconv(.c) f64 {
356356 const toint: f64 = 1.0 / math.floatEps(f64);
357357 const a: u64 = @bitCast(x);
358 const e = a >> 52 & 0x7ff;
358 const e = (a >> 52) & 0x7ff;
359359 const s = a >> 63;
360360 var y: f64 = undefined;
361361
......@@ -376,7 +376,7 @@ fn rint(x: f64) callconv(.c) f64 {
376376fn rintf(x: f32) callconv(.c) f32 {
377377 const toint: f32 = 1.0 / math.floatEps(f32);
378378 const a: u32 = @bitCast(x);
379 const e = a >> 23 & 0xff;
379 const e = (a >> 23) & 0xff;
380380 const s = a >> 31;
381381 var y: f32 = undefined;
382382
lib/c/stdlib/drand48.zig+6-6
......@@ -30,7 +30,7 @@ var lcg: Lcg = .init(0, default_multiplier, default_addend);
3030var seed48_xi: [3]c_ushort = undefined;
3131
3232fn erand48(xsubi: *[3]c_ushort) callconv(.c) f64 {
33 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | (@as(u48, @as(u16, @truncate(xsubi[1])))) << 16) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
33 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | ((@as(u48, @as(u16, @truncate(xsubi[1])))) << 16)) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
3434
3535 var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);
3636 const next_xi = separate_lcg.next();
......@@ -40,7 +40,7 @@ fn erand48(xsubi: *[3]c_ushort) callconv(.c) f64 {
4040}
4141
4242fn jrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {
43 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | (@as(u48, @as(u16, @truncate(xsubi[1])))) << 16) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
43 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | ((@as(u48, @as(u16, @truncate(xsubi[1])))) << 16)) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
4444
4545 var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);
4646 const next_xi = separate_lcg.next();
......@@ -50,7 +50,7 @@ fn jrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {
5050}
5151
5252fn nrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {
53 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | (@as(u48, @as(u16, @truncate(xsubi[1])))) << 16) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
53 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | ((@as(u48, @as(u16, @truncate(xsubi[1])))) << 16)) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
5454
5555 var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);
5656 const next_xi = separate_lcg.next();
......@@ -74,14 +74,14 @@ fn mrand48() callconv(.c) c_long {
7474// 0..3 is `Xi`, 3..6 is `a`, 6 is `c`
7575// first low 16-bits, then mid, then high.
7676fn lcong48(param: *[7]c_ushort) callconv(.c) void {
77 lcg.xi = (@as(u48, @as(u16, @truncate(param[0]))) | (@as(u48, @as(u16, @truncate(param[1])))) << 16) | (@as(u48, @as(u16, @truncate(param[2]))) << 32);
78 lcg.a = (@as(u48, @as(u16, @truncate(param[3]))) | (@as(u48, @as(u16, @truncate(param[4])))) << 16) | (@as(u48, @as(u16, @truncate(param[5]))) << 32);
77 lcg.xi = (@as(u48, @as(u16, @truncate(param[0]))) | ((@as(u48, @as(u16, @truncate(param[1])))) << 16)) | (@as(u48, @as(u16, @truncate(param[2]))) << 32);
78 lcg.a = (@as(u48, @as(u16, @truncate(param[3]))) | ((@as(u48, @as(u16, @truncate(param[4])))) << 16)) | (@as(u48, @as(u16, @truncate(param[5]))) << 32);
7979 lcg.c = @as(u16, @truncate(param[6]));
8080}
8181
8282fn seed48(seed16v: *[3]c_ushort) callconv(.c) *[3]c_ushort {
8383 seed48_xi = .{ @truncate(lcg.xi & 0xFFFF), @truncate((lcg.xi >> 16) & 0xFFFF), @truncate((lcg.xi >> 32) & 0xFFFF) };
84 const xi = (@as(u48, @as(u16, @truncate(seed16v[0]))) | (@as(u48, @as(u16, @truncate(seed16v[1])))) << 16) | (@as(u48, @as(u16, @truncate(seed16v[2]))) << 32);
84 const xi = (@as(u48, @as(u16, @truncate(seed16v[0]))) | ((@as(u48, @as(u16, @truncate(seed16v[1])))) << 16)) | (@as(u48, @as(u16, @truncate(seed16v[2]))) << 32);
8585 lcg = .init(xi, default_multiplier, default_addend);
8686 return &seed48_xi;
8787}
lib/compiler/Maker/Step/Compile.zig+1-1
......@@ -45,7 +45,7 @@ pub fn make(
4545
4646 try lowerZigArgs(arena, compile_index, maker, progress_node, &argv, false);
4747
48 const incremental = conf_comp.flags4.incremental.toBool() orelse graph.incremental == true;
48 const incremental = conf_comp.flags4.incremental.toBool() orelse graph.incremental orelse false;
4949
5050 const opt_cache_digest = Step.evalZigProcess(
5151 compile_index,
lib/compiler/aro/aro/Compilation.zig+3-3
......@@ -287,7 +287,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
287287 const gnuc_version = comp.langopts.gnuc_version orelse comp.langopts.emulate.defaultGccVersion();
288288 if (gnuc_version > 0) {
289289 try w.print("#define __GNUC__ {d}\n", .{gnuc_version / 10_000});
290 try w.print("#define __GNUC_MINOR__ {d}\n", .{gnuc_version / 100 % 100});
290 try w.print("#define __GNUC_MINOR__ {d}\n", .{(gnuc_version / 100) % 100});
291291 try w.print("#define __GNUC_PATCHLEVEL__ {d}\n", .{gnuc_version % 100});
292292 }
293293
......@@ -962,7 +962,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
962962 try define(w, "__ARM_ARCH_EXT_IDIV__");
963963 }
964964 var sat = false;
965 if (arm_version == 6 and !target.cpu.has(.arm, .mclass) or arm_version > 6) {
965 if ((arm_version == 6 and !target.cpu.has(.arm, .mclass)) or arm_version > 6) {
966966 try define(w, "__ARM_FEATURE_SAT");
967967 sat = true;
968968 }
......@@ -2856,7 +2856,7 @@ test "addSourceFromBuffer - exhaustive check for carriage return elimination" {
28562856 if (buf[j] == alphabet[0]) buf[j - 1] = alphabet[(idx + 1) % alen] else break;
28572857 }
28582858 }
2859 try std.testing.expect(source_count == std.math.powi(usize, alen, alen) catch unreachable);
2859 try std.testing.expect(source_count == (std.math.powi(usize, alen, alen) catch unreachable));
28602860}
28612861
28622862test "ignore BOM at beginning of file" {
lib/compiler/aro/aro/Driver.zig+1-1
......@@ -1373,7 +1373,7 @@ fn getOutFileName(d: *Driver, source: Source, buf: *[std.fs.max_name_bytes]u8) !
13731373 if (d.only_preprocess_and_compile) ".s" else d.comp.target.ofmt.fileExt(d.comp.target.cpu.arch),
13741374 };
13751375 return d.output_name orelse
1376 mem.print(buf, fmt_template, fmt_args) catch return d.fatal("Filename too long for filesystem: " ++ fmt_template, fmt_args);
1376 (mem.print(buf, fmt_template, fmt_args) catch return d.fatal("Filename too long for filesystem: " ++ fmt_template, fmt_args));
13771377 }
13781378
13791379 return d.getRandomFilename(buf, d.comp.target.ofmt.fileExt(d.comp.target.cpu.arch));
lib/compiler/aro/aro/Parser.zig+1-1
......@@ -7084,7 +7084,7 @@ pub const Result = struct {
70847084 const b_child_qt = b.qt.get(p.comp, .pointer).?.child;
70857085
70867086 if (!a_child_qt.eql(b_child_qt, p.comp)) try p.err(tok, .incompatible_pointers, .{ a.qt, b.qt });
7087 if (a.qt.childType(p.comp).sizeofOrNull(p.comp) orelse 1 == 0) try p.err(tok, .subtract_pointers_zero_elem_size, .{a.qt.childType(p.comp)});
7087 if ((a.qt.childType(p.comp).sizeofOrNull(p.comp) orelse 1) == 0) try p.err(tok, .subtract_pointers_zero_elem_size, .{a.qt.childType(p.comp)});
70887088 a.qt = p.comp.type_store.ptrdiff;
70897089 }
70907090
lib/compiler/aro/aro/Preprocessor.zig+3-3
......@@ -310,13 +310,13 @@ pub const InitOptions = struct {
310310};
311311
312312pub fn init(comp: *Compilation, options: InitOptions) !Preprocessor {
313 const source_epoch: SourceEpoch = options.source_epoch orelse comp.environment.sourceEpoch(comp.io) catch |er| switch (er) {
313 const source_epoch: SourceEpoch = options.source_epoch orelse (comp.environment.sourceEpoch(comp.io) catch |er| switch (er) {
314314 error.InvalidEpoch => blk: {
315315 const diagnostic: Diagnostic = .invalid_source_epoch;
316316 try comp.diagnostics.add(.{ .text = diagnostic.fmt, .kind = diagnostic.kind, .opt = diagnostic.opt, .location = null });
317317 break :blk .default;
318318 },
319 };
319 });
320320
321321 var pp: Preprocessor = .{
322322 .comp = comp,
......@@ -3882,7 +3882,7 @@ pub fn prettyPrintTokens(pp: *Preprocessor, w: *std.Io.Writer, macro_dump_mode:
38823882 },
38833883 .keyword_pragma => {
38843884 const pragma_name = pp.expandedSlice(pp.tokens.get(i + 1));
3885 const end_idx = mem.findScalarPos(Token.Id, tok_ids, i, .nl) orelse i + 1;
3885 const end_idx = mem.findScalarPos(Token.Id, tok_ids, i, .nl) orelse (i + 1);
38863886 const pragma_len = @as(u32, @intCast(end_idx)) - i;
38873887
38883888 if (pp.comp.getPragma(pragma_name)) |prag| {
lib/compiler/aro/aro/Preprocessor/Parser.zig+1-1
......@@ -323,7 +323,7 @@ fn binaryExpr(p: *Parser, min_prec: Token.Precedence, eval: bool) Error!?Value {
323323 const else_res = try p.binaryExpr(op_prec, eval_else) orelse return null;
324324
325325 lhs = if (lhs.toBool()) rhs else else_res;
326 if (eval and rhs == .unsigned or else_res == .unsigned) {
326 if (rhs == .unsigned or else_res == .unsigned) {
327327 try lhs.toUnsigned(p, operator, "right");
328328 }
329329 },
lib/compiler/aro/aro/char_info.zig+2-2
......@@ -492,7 +492,7 @@ pub fn isXidStart(c: u21) bool {
492492 assert(c > 0x7F);
493493 const idx = c / 8 / tables.chunk;
494494 const chunk: usize = if (idx < tables.trie_start.len) tables.trie_start[idx] else 0;
495 const offset = chunk * tables.chunk / 2 + c / 8 % tables.chunk;
495 const offset = chunk * tables.chunk / 2 + (c / 8) % tables.chunk;
496496 return (tables.leaf[offset] >> (@as(u3, @intCast(c % 8)))) & 1 != 0;
497497}
498498
......@@ -500,7 +500,7 @@ pub fn isXidContinue(c: u21) bool {
500500 assert(c > 0x7F);
501501 const idx = c / 8 / tables.chunk;
502502 const chunk: usize = if (idx < tables.trie_continue.len) tables.trie_continue[idx] else 0;
503 const offset = chunk * tables.chunk / 2 + c / 8 % tables.chunk;
503 const offset = chunk * tables.chunk / 2 + (c / 8) % tables.chunk;
504504 return (tables.leaf[offset] >> (@as(u3, @intCast(c % 8)))) & 1 != 0;
505505}
506506
lib/compiler/aro/aro/record_layout.zig+1-1
......@@ -324,7 +324,7 @@ const SysVContext = struct {
324324
325325 // On Clang, the alignment requested by annotations is not respected if it is
326326 // larger than the value of #pragma pack. See test case 0083.
327 if (annotation_alignment <= self.max_field_align_bits orelse std.math.maxInt(u29)) {
327 if (annotation_alignment <= (self.max_field_align_bits orelse std.math.maxInt(u29))) {
328328 field_align_bits = @max(field_align_bits, annotation_alignment);
329329 }
330330 // On Clang, if there are no packing annotations and the field would cross a
lib/compiler_rt/absv.zig+1-1
......@@ -11,7 +11,7 @@ pub inline fn absv(comptime ST: type, a: ST) ST {
1111 // compute the integer absolute value (abs) without branching
1212 var x: ST = a;
1313 const N: UT = @bitSizeOf(ST);
14 const sign: ST = a >> N - 1;
14 const sign: ST = a >> (N - 1);
1515 x +%= sign;
1616 x ^= sign;
1717 if (x < 0) @panic("integer overflow");
lib/compiler_rt/addf3.zig+1-1
......@@ -259,7 +259,7 @@ inline fn addf3(comptime T: type, a: T, b: T) T {
259259 // adjust the exponent:
260260 if (aSignificand & (integerBit << 4) != 0) {
261261 const sticky = aSignificand & 1;
262 aSignificand = aSignificand >> 1 | sticky;
262 aSignificand = (aSignificand >> 1) | sticky;
263263 aExponent += 1;
264264 }
265265 }
lib/compiler_rt/atomics.zig+1-1
......@@ -241,7 +241,7 @@ fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T {
241241 while (true) {
242242 const old = @as(T, @truncate((wide_old & mask) >> inner_shift));
243243 const new = update(val, old);
244 const wide_new = wide_old & ~mask | (@as(WideAtomic, new) << inner_shift);
244 const wide_new = (wide_old & ~mask) | (@as(WideAtomic, new) << inner_shift);
245245 if (@cmpxchgWeak(WideAtomic, wide_ptr, wide_old, wide_new, .seq_cst, .seq_cst)) |new_wide_old| {
246246 wide_old = new_wide_old;
247247 } else {
lib/compiler_rt/comparef.zig+4-4
......@@ -130,13 +130,13 @@ fn __aeabi_fcmplt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
130130 return @intFromBool(cmp_f32(a, b) == .lt);
131131}
132132fn __aeabi_fcmple(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
133 return @intFromBool(cmp_f32(a, b) orelse .gt != .gt);
133 return @intFromBool((cmp_f32(a, b) orelse .gt) != .gt);
134134}
135135fn __gesf2(a: compiler_rt.f32.Abi, b: compiler_rt.f32.Abi) callconv(.c) Order {
136136 return cmp_f32(compiler_rt.f32.fromAbi(a), compiler_rt.f32.fromAbi(b)) orelse .lt;
137137}
138138fn __aeabi_fcmpge(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
139 return @intFromBool(cmp_f32(a, b) orelse .lt != .lt);
139 return @intFromBool((cmp_f32(a, b) orelse .lt) != .lt);
140140}
141141fn __aeabi_fcmpgt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
142142 return @intFromBool(cmp_f32(a, b) == .gt);
......@@ -164,13 +164,13 @@ fn __aeabi_dcmplt(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
164164 return @intFromBool(cmp_f64(a, b) == .lt);
165165}
166166fn __aeabi_dcmple(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
167 return @intFromBool(cmp_f64(a, b) orelse .gt != .gt);
167 return @intFromBool((cmp_f64(a, b) orelse .gt) != .gt);
168168}
169169fn __gedf2(a: compiler_rt.f64.Abi, b: compiler_rt.f64.Abi) callconv(.c) Order {
170170 return cmp_f64(compiler_rt.f64.fromAbi(a), compiler_rt.f64.fromAbi(b)) orelse .lt;
171171}
172172fn __aeabi_dcmpge(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
173 return @intFromBool(cmp_f64(a, b) orelse .lt != .lt);
173 return @intFromBool((cmp_f64(a, b) orelse .lt) != .lt);
174174}
175175fn __aeabi_dcmpgt(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
176176 return @intFromBool(cmp_f64(a, b) == .gt);
lib/compiler_rt/divdf3.zig+8-8
......@@ -119,12 +119,12 @@ pub fn div_f64(a: f64, b: f64) f64 {
119119 // with each iteration, so after three iterations, we have about 28 binary
120120 // digits of accuracy.
121121 var correction32: u32 = undefined;
122 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
123 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
124 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
125 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
126 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);
127 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);
122 correction32 = @truncate(~((@as(u64, recip32) *% q31b) >> 32) +% 1);
123 recip32 = @truncate((@as(u64, recip32) *% correction32) >> 31);
124 correction32 = @truncate(~((@as(u64, recip32) *% q31b) >> 32) +% 1);
125 recip32 = @truncate((@as(u64, recip32) *% correction32) >> 31);
126 correction32 = @truncate(~((@as(u64, recip32) *% q31b) >> 32) +% 1);
127 recip32 = @truncate((@as(u64, recip32) *% correction32) >> 31);
128128
129129 // recip32 might have overflowed to exactly zero in the preceding
130130 // computation if the high word of b is exactly 1.0. This would sabotage
......@@ -137,10 +137,10 @@ pub fn div_f64(a: f64, b: f64) f64 {
137137 const q63blo: u32 = @truncate(bSignificand << 11);
138138 var correction: u64 = undefined;
139139 var reciprocal: u64 = undefined;
140 correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;
140 correction = ~(@as(u64, recip32) *% q31b +% ((@as(u64, recip32) *% q63blo) >> 32)) +% 1;
141141 const cHi: u32 = @truncate(correction >> 32);
142142 const cLo: u32 = @truncate(correction);
143 reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);
143 reciprocal = @as(u64, recip32) *% cHi +% ((@as(u64, recip32) *% cLo) >> 32);
144144
145145 // We already adjusted the 32-bit estimate, now we need to adjust the final
146146 // 64-bit reciprocal estimate downward to ensure that it is strictly smaller
lib/compiler_rt/divsf3.zig+7-7
......@@ -126,12 +126,12 @@ pub fn div_f32(a: f32, b: f32) f32 {
126126 // with each iteration, so after three iterations, we have about 28 binary
127127 // digits of accuracy.
128128 var correction: u32 = undefined;
129 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
130 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
131 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
132 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
133 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);
134 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);
129 correction = @truncate(~((@as(u64, reciprocal) *% q31b) >> 32) +% 1);
130 reciprocal = @truncate((@as(u64, reciprocal) *% correction) >> 31);
131 correction = @truncate(~((@as(u64, reciprocal) *% q31b) >> 32) +% 1);
132 reciprocal = @truncate((@as(u64, reciprocal) *% correction) >> 31);
133 correction = @truncate(~((@as(u64, reciprocal) *% q31b) >> 32) +% 1);
134 reciprocal = @truncate((@as(u64, reciprocal) *% correction) >> 31);
135135
136136 // Exhaustive testing shows that the error in reciprocal after three steps
137137 // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our
......@@ -153,7 +153,7 @@ pub fn div_f32(a: f32, b: f32) f32 {
153153 // is the error in the reciprocal of b scaled by the maximum
154154 // possible value of a. As a consequence of this error bound,
155155 // either q or nextafter(q) is the correctly rounded
156 var quotient: Z = @truncate(@as(u64, reciprocal) *% (aSignificand << 1) >> 32);
156 var quotient: Z = @truncate((@as(u64, reciprocal) *% (aSignificand << 1)) >> 32);
157157
158158 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
159159 // In either case, we are going to compute a residual of the form
lib/compiler_rt/divtf3.zig+10-10
......@@ -119,16 +119,16 @@ pub fn div_f128(a: f128, b: f128) f128 {
119119 // This doubles the number of correct binary digits in the approximation
120120 // with each iteration.
121121 var correction64: u64 = undefined;
122 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
123 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
124 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
125 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
126 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
127 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
128 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
129 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
130 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
131 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
122 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
123 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
124 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
125 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
126 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
127 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
128 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
129 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
130 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
131 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
132132
133133 // The reciprocal may have overflowed to zero if the upper half of b is
134134 // exactly 1.0. This would sabatoge the full-width final stage of the
lib/compiler_rt/divxf3.zig+10-10
......@@ -102,16 +102,16 @@ pub fn div_f80(a: f80, b: f80) f80 {
102102 // This doubles the number of correct binary digits in the approximation
103103 // with each iteration.
104104 var correction64: u64 = undefined;
105 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
106 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
107 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
108 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
109 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
110 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
111 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
112 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
113 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);
114 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);
105 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
106 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
107 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
108 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
109 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
110 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
111 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
112 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
113 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
114 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
115115
116116 // The reciprocal may have overflowed to zero if the upper half of b is
117117 // exactly 1.0. This would sabatoge the full-width final stage of the
lib/compiler_rt/elf/tls.zig+1-1
......@@ -251,7 +251,7 @@ fn setThreadPointer(addr: usize) void {
251251 // Update the %gs selector
252252 asm volatile ("movl %[gs_val], %%gs"
253253 :
254 : [gs_val] "r" (gdt_entry_number << 3 | 3),
254 : [gs_val] "r" ((gdt_entry_number << 3) | 3),
255255 );
256256 },
257257 .x86_64 => {
lib/compiler_rt/extendf.zig+2-2
......@@ -165,7 +165,7 @@ pub fn f128_floatCast_f80(a: f80) f128 {
165165 }
166166
167167 // Apply the signbit to (dst_t)abs(a).
168 const result: u128 = abs_result | @as(u128, sign) << (dst_bits - 16);
168 const result: u128 = abs_result | (@as(u128, sign) << (dst_bits - 16));
169169 return @bitCast(result);
170170}
171171
......@@ -232,7 +232,7 @@ inline fn extendf(comptime dst_t: type, comptime src_t: type, f: src_t) dst_t {
232232 }
233233
234234 // Apply the signbit to (dst_t)abs(a).
235 const result: dst_rep_t = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits);
235 const result: dst_rep_t = absResult | (@as(dst_rep_t, sign) << (dstBits - srcBits));
236236 return @bitCast(result);
237237}
238238
lib/compiler_rt/floor_ceil.zig+4-4
......@@ -141,13 +141,13 @@ inline fn impl(comptime T: type, comptime op: enum { floor, ceil }, x: T) T {
141141 const m = (@as(U, 1) << @intCast(mantissa - e)) - 1;
142142 if (u & m == 0) return x;
143143 if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
144 if (u >> bits - 1 == @intFromBool(op == .floor)) u += m;
144 if (u >> (bits - 1) == @intFromBool(op == .floor)) u += m;
145145 return @bitCast(u & ~m);
146146 } else {
147147 if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
148148 return switch (op) {
149 .floor => if (u >> bits - 1 == 0) 0.0 else if (u << 1 != 0) -1.0 else x,
150 .ceil => if (u >> bits - 1 != 0) -0.0 else if (u << 1 != 0) 1.0 else x,
149 .floor => if (u >> (bits - 1) == 0) 0.0 else if (u << 1 != 0) -1.0 else x,
150 .ceil => if (u >> (bits - 1) != 0) -0.0 else if (u << 1 != 0) 1.0 else x,
151151 };
152152 }
153153 },
......@@ -155,7 +155,7 @@ inline fn impl(comptime T: type, comptime op: enum { floor, ceil }, x: T) T {
155155 const e = (u >> mantissa) & mask;
156156 if (e >= bias + math.floatFractionalBits(T) or x == 0) return x;
157157
158 const positive = u >> @bitSizeOf(T) - 1 == 0;
158 const positive = u >> (@bitSizeOf(T) - 1) == 0;
159159 const y: T = if (positive)
160160 x + C - C - x
161161 else
lib/compiler_rt/fmod.zig+2-2
......@@ -204,8 +204,8 @@ pub fn fmod_f128(a: f128, b: f128) f128 {
204204 }
205205
206206 // OR in extra non-stored mantissa digit
207 var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
208 const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;
207 var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | (1 << 48);
208 const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | (1 << 48);
209209 var lowA: u64 = aPtr_u64[low_index];
210210 const lowB: u64 = bPtr_u64[low_index];
211211
lib/compiler_rt/mulf3.zig+1-1
......@@ -237,7 +237,7 @@ fn wideShrWithTruncation(comptime Z: type, hi: *Z, lo: *Z, count: u32) bool {
237237 lo.* = (hi.* << @intCast(typeWidth -% count)) | (lo.* >> @intCast(count));
238238 hi.* = hi.* >> @intCast(count);
239239 } else if (count < 2 * typeWidth) {
240 inexact = (hi.* << @intCast(2 * typeWidth -% count) | lo.*) != 0;
240 inexact = ((hi.* << @intCast(2 * typeWidth -% count)) | lo.*) != 0;
241241 lo.* = hi.* >> @intCast(count -% typeWidth);
242242 hi.* = 0;
243243 } else {
lib/compiler_rt/rem_pio2l.zig+1-1
......@@ -37,7 +37,7 @@ pub fn rem_pio2l(comptime T: type, x: T, y: *[2]T) i32 {
3737 const se = ld.signExponent(x_val);
3838 const top = ld.mantissaTop(x_val);
3939 const lhs = (@as(u32, se & 0x7fff) << 16) | top;
40 const rhs: u32 = ((0x3fff + 25) << 16) | 0x921f >> 1 | 0x8000;
40 const rhs: u32 = ((0x3fff + 25) << 16) | (0x921f >> 1) | 0x8000;
4141 return lhs < rhs;
4242 }
4343
lib/compiler_rt/sqrt.zig+5-5
......@@ -523,15 +523,15 @@ const rsqrt_tab: [128]u16 = .{
523523};
524524
525525inline fn mul16(a: u16, b: u16) u16 {
526 return @intCast(@as(u32, a) * b >> 16);
526 return @intCast((@as(u32, a) * b) >> 16);
527527}
528528
529529inline fn mul32(a: u32, b: u32) u32 {
530 return @intCast(@as(u64, a) * b >> 32);
530 return @intCast((@as(u64, a) * b) >> 32);
531531}
532532
533533inline fn mul64(a: u64, b: u64) u64 {
534 return @intCast(@as(u128, a) * b >> 64);
534 return @intCast((@as(u128, a) * b) >> 64);
535535}
536536
537537inline fn mul80(a: u80, b: u80) u80 {
......@@ -539,7 +539,7 @@ inline fn mul80(a: u80, b: u80) u80 {
539539 const alo = a & 0xFF_FFFF_FFFF;
540540 const bhi = b >> 40;
541541 const blo = b & 0xFF_FFFF_FFFF;
542 return ahi * bhi + (ahi * blo >> 40) + (alo * bhi >> 40);
542 return ahi * bhi + ((ahi * blo) >> 40) + ((alo * bhi) >> 40);
543543}
544544
545545inline fn mul128(a: u128, b: u128) u128 {
......@@ -547,7 +547,7 @@ inline fn mul128(a: u128, b: u128) u128 {
547547 const alo = a & 0xFFFF_FFFF_FFFF_FFFF;
548548 const bhi = b >> 64;
549549 const blo = b & 0xFFFF_FFFF_FFFF_FFFF;
550 return ahi * bhi + (ahi * blo >> 64) + (alo * bhi >> 64);
550 return ahi * bhi + ((ahi * blo) >> 64) + ((alo * bhi) >> 64);
551551}
552552
553553inline fn mul80_tail(a: u80, b: u80) u80 {
lib/compiler_rt/truncf.zig+3-3
......@@ -279,7 +279,7 @@ inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
279279 absResult = 0;
280280 } else {
281281 const sticky: src_rep_t = @intFromBool(significand << @intCast(srcBits - shift) != 0);
282 const denormalizedSignificand: src_rep_t = significand >> @intCast(shift) | sticky;
282 const denormalizedSignificand: src_rep_t = (significand >> @intCast(shift)) | sticky;
283283 absResult = @intCast(denormalizedSignificand >> (srcSigBits - dstSigBits));
284284 const roundBits: src_rep_t = denormalizedSignificand & roundMask;
285285 if (roundBits > halfway) {
......@@ -362,7 +362,7 @@ inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
362362 abs_result = 0;
363363 } else {
364364 const sticky = @intFromBool(a_rep.fraction << @intCast(shift) != 0);
365 const denormalized_significand = a_rep.fraction >> @intCast(shift) | sticky;
365 const denormalized_significand = (a_rep.fraction >> @intCast(shift)) | sticky;
366366 abs_result = @intCast(denormalized_significand >> (src_sig_bits - dst_sig_bits));
367367 const round_bits = denormalized_significand & round_mask;
368368 if (round_bits > halfway) {
......@@ -375,7 +375,7 @@ inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
375375 }
376376 }
377377
378 const result align(@alignOf(dst_t)) = abs_result | @as(dst_rep_t, sign) << dst_bits - 16;
378 const result align(@alignOf(dst_t)) = abs_result | (@as(dst_rep_t, sign) << (dst_bits - 16));
379379 return @bitCast(result);
380380}
381381
lib/std/Io/Dispatch.zig+2-2
......@@ -1931,10 +1931,10 @@ const BatchWaiter = struct {
19311931
19321932fn batchAwaitAsync(userdata: ?*anyopaque, batch: *Io.Batch) Io.Cancelable!void {
19331933 const ev: *Evented = @ptrCast(@alignCast(userdata));
1934 const queue = ev.batchDrainSubmitted(batch, false) catch |err| switch (err) {
1934 const queue = (ev.batchDrainSubmitted(batch, false) catch |err| switch (err) {
19351935 error.ConcurrencyUnavailable => unreachable, // passed concurrency=false
19361936 error.Canceled => |e| return e,
1937 } orelse return;
1937 }) orelse return;
19381938 if (batch.pending.head == .none) return;
19391939 var waiter: BatchWaiter = .{
19401940 .sleeper = .init(ev.queue, Thread.current().currentFiber()),
lib/std/Io/Kqueue.zig+1-1
......@@ -164,7 +164,7 @@ pub const InitError = Allocator.Error || CreateFileDescriptorError;
164164pub fn init(k: *Kqueue, gpa: Allocator, options: InitOptions) !void {
165165 assert(options.n_threads != 0);
166166
167 const n_threads = @max(1, options.n_threads orelse std.Thread.getCpuCount() catch 1);
167 const n_threads = @max(1, options.n_threads orelse (std.Thread.getCpuCount() catch 1));
168168 const threads_size = n_threads * @sizeOf(Thread);
169169 const idle_stack_end_offset = std.mem.alignForward(usize, threads_size + idle_stack_size, std.heap.page_size_max);
170170 const allocated_slice = try gpa.alignedAlloc(u8, .of(Thread), idle_stack_end_offset);
lib/std/Io/Threaded/test.zig+1-1
......@@ -36,7 +36,7 @@ fn put(io: Io, queue: *Io.Queue(u8)) void {
3636}
3737
3838fn get(io: Io, queue: *Io.Queue(u8)) void {
39 assert(queue.getOneUncancelable(io) catch unreachable == 42);
39 assert((queue.getOneUncancelable(io) catch unreachable) == 42);
4040}
4141
4242test "concurrent vs concurrent prevents deadlock via oversubscription" {
lib/std/Io/Writer.zig+1-1
......@@ -1827,7 +1827,7 @@ pub fn printFloatHex(w: *Writer, value: anytype, case: std.fmt.Case, opt_precisi
18271827 // Restore the alignment.
18281828 mantissa <<= @as(std.math.Log2Int(TU), @intCast((mantissa_digits - precision) * 4));
18291829
1830 const overflow = mantissa & (1 << 1 + mantissa_digits * 4) != 0;
1830 const overflow = mantissa & (1 << (1 + mantissa_digits * 4)) != 0;
18311831 // Prefer a normalized result in case of overflow.
18321832 if (overflow) {
18331833 mantissa >>= 1;
lib/std/Io/net/HostName.zig+1-1
......@@ -230,7 +230,7 @@ pub fn expand(noalias packet: []const u8, start_i: usize, noalias dest_buffer: [
230230 i += 1 + label_len;
231231 } else {
232232 return .{
233 len orelse i - start_i + 1,
233 len orelse (i - start_i + 1),
234234 try .init(dest[0..dest_i]),
235235 };
236236 }
lib/std/base64.zig+3-3
......@@ -148,7 +148,7 @@ pub const Base64Encoder = struct {
148148 if (idx + 2 < source.len) {
149149 dest[out_idx] = encoder.alphabet_chars[source[idx] >> 2];
150150 dest[out_idx + 1] = encoder.alphabet_chars[((source[idx] & 0x3) << 4) | (source[idx + 1] >> 4)];
151 dest[out_idx + 2] = encoder.alphabet_chars[(source[idx + 1] & 0xf) << 2 | (source[idx + 2] >> 6)];
151 dest[out_idx + 2] = encoder.alphabet_chars[((source[idx + 1] & 0xf) << 2) | (source[idx + 2] >> 6)];
152152 dest[out_idx + 3] = encoder.alphabet_chars[source[idx + 2] & 0x3f];
153153 out_idx += 4;
154154 } else if (idx + 1 < source.len) {
......@@ -282,7 +282,7 @@ pub const Base64Decoder = struct {
282282 dest_idx += 1;
283283 }
284284 }
285 if (acc_len > 4 or (acc & (@as(u12, 1) << acc_len) - 1) != 0) {
285 if (acc_len > 4 or (acc & ((@as(u12, 1) << acc_len) - 1)) != 0) {
286286 return error.InvalidPadding;
287287 }
288288 if (leftover_idx == null) return;
......@@ -357,7 +357,7 @@ pub const Base64DecoderWithIgnore = struct {
357357 dest_idx += 1;
358358 }
359359 }
360 if (acc_len > 4 or (acc & (@as(u12, 1) << acc_len) - 1) != 0) {
360 if (acc_len > 4 or (acc & ((@as(u12, 1) << acc_len) - 1)) != 0) {
361361 return error.InvalidPadding;
362362 }
363363 const padding_len = acc_len / 2;
lib/std/bit_set.zig+4-4
......@@ -468,11 +468,11 @@ pub fn Array(comptime MaskIntType: type, comptime size: usize) type {
468468
469469 if (start_mask_index == end_mask_index) {
470470 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;
471 var mask2 = std.math.boolMask(MaskInt, true) >> (mask_len - 1) - (end_bit - 1);
471 var mask2 = std.math.boolMask(MaskInt, true) >> ((mask_len - 1) - (end_bit - 1));
472472 self.masks[start_mask_index] &= ~(mask1 & mask2);
473473
474474 mask1 = std.math.boolMask(MaskInt, value) << start_bit;
475 mask2 = std.math.boolMask(MaskInt, value) >> (mask_len - 1) - (end_bit - 1);
475 mask2 = std.math.boolMask(MaskInt, value) >> ((mask_len - 1) - (end_bit - 1));
476476 self.masks[start_mask_index] |= mask1 & mask2;
477477 } else {
478478 var bulk_mask_index: usize = undefined;
......@@ -875,11 +875,11 @@ pub const Dynamic = struct {
875875
876876 if (start_mask_index == end_mask_index) {
877877 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;
878 var mask2 = std.math.boolMask(MaskInt, true) >> (@bitSizeOf(MaskInt) - 1) - (end_bit - 1);
878 var mask2 = std.math.boolMask(MaskInt, true) >> ((@bitSizeOf(MaskInt) - 1) - (end_bit - 1));
879879 self.masks[start_mask_index] &= ~(mask1 & mask2);
880880
881881 mask1 = std.math.boolMask(MaskInt, value) << start_bit;
882 mask2 = std.math.boolMask(MaskInt, value) >> (@bitSizeOf(MaskInt) - 1) - (end_bit - 1);
882 mask2 = std.math.boolMask(MaskInt, value) >> ((@bitSizeOf(MaskInt) - 1) - (end_bit - 1));
883883 self.masks[start_mask_index] |= mask1 & mask2;
884884 } else {
885885 var bulk_mask_index: usize = undefined;
lib/std/coff.zig+1-1
......@@ -2035,7 +2035,7 @@ pub const ArchiveMemberHeader = extern struct {
20352035 if (trim.len == 0) return error.BadName;
20362036 return if (trim[0] == '/') name: {
20372037 if (trim.len == 1 or
2038 trim.len == 2 and trim[1] == '/')
2038 (trim.len == 2 and trim[1] == '/'))
20392039 break :name trim;
20402040
20412041 const offset = std.fmt.parseUnsigned(u50, trim[1..], 10) catch
lib/std/compress/flate/Compress.zig+2-2
......@@ -1333,8 +1333,8 @@ const huffman = struct {
13331333
13341334 const incomplete_allowed = smith.value(bool);
13351335 while (nfreqs < @as(u8, @intFromBool(!incomplete_allowed)) + 1 or
1336 nfreqs != freqs_buf.len and freqs_limit != 0 and
1337 smith.eosWeightedSimple(15, 1))
1336 (nfreqs != freqs_buf.len and freqs_limit != 0 and
1337 smith.eosWeightedSimple(15, 1)))
13381338 {
13391339 const f = smith.valueWeighted(u16, &.{
13401340 .rangeAtMost(u16, 0, @min(31, freqs_limit), @max(freqs_limit, 1)),
lib/std/crypto/aes/soft.zig+1-1
......@@ -728,7 +728,7 @@ pub const Aes256 = struct {
728728// constants
729729
730730// Rijndael's irreducible polynomial.
731const poly: u9 = 1 << 8 | 1 << 4 | 1 << 3 | 1 << 1 | 1 << 0; // x⁸ + x⁴ + x³ + x + 1
731const poly: u9 = (1 << 8) | (1 << 4) | (1 << 3) | (1 << 1) | (1 << 0); // x⁸ + x⁴ + x³ + x + 1
732732
733733// Powers of x mod poly in GF(2).
734734const powx = init: {
lib/std/crypto/codecs/base64_hex_ct.zig+1-1
......@@ -29,7 +29,7 @@ pub const hex = struct {
2929 const c: u16 = v & 0xf;
3030 const off = if (case == .upper) 32 else 0;
3131 const x =
32 ((87 - off + c + (((c -% 10) >> 8) & ~@as(u16, 38 - off))) & 0xff) << 8 |
32 (((87 - off + c + (((c -% 10) >> 8) & ~@as(u16, 38 - off))) & 0xff) << 8) |
3333 ((87 - off + b + (((b -% 10) >> 8) & ~@as(u16, 38 - off))) & 0xff);
3434 encoded[i * 2] = @truncate(x);
3535 encoded[i * 2 + 1] = @truncate(x >> 8);
lib/std/crypto/ml_kem.zig+1-1
......@@ -1264,7 +1264,7 @@ const Poly = struct {
12641264 const b1 = @as(i16, buf[3 * i + 1]);
12651265 const b2 = @as(i16, buf[3 * i + 2]);
12661266 ret.cs[2 * i] = b0 | ((b1 & 0xf) << 8);
1267 ret.cs[2 * i + 1] = (b1 >> 4) | b2 << 4;
1267 ret.cs[2 * i + 1] = (b1 >> 4) | (b2 << 4);
12681268 }
12691269 return ret;
12701270 }
lib/std/crypto/scrypt.zig+1-1
......@@ -82,7 +82,7 @@ fn blockMix(tmp: *align(16) [16]u32, in: []align(16) const u32, out: []align(16)
8282
8383fn integerify(b: []align(16) const u32, r: u30) u64 {
8484 const j = (2 * r - 1) * 16;
85 return @as(u64, b[j]) | @as(u64, b[j + 1]) << 32;
85 return @as(u64, b[j]) | (@as(u64, b[j + 1]) << 32);
8686}
8787
8888fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {
lib/std/crypto/sha2.zig+1-1
......@@ -557,7 +557,7 @@ fn Sha2x64(comptime iv: Iv64, digest_bits: comptime_int) type {
557557 }
558558
559559 if (digest_bits % 8 != 0) @compileError("impl doesn't support non-byte digest_len");
560 const bytes_left = digest_bits / 8 % 8;
560 const bytes_left = (digest_bits / 8) % 8;
561561 if (bytes_left > 0) {
562562 const rest = d.s[(digest_bits / 64)];
563563 var buf: [8]u8 = undefined;
lib/std/debug.zig+1-1
......@@ -1306,7 +1306,7 @@ fn printLineInfo(
13061306 try writer.print("0x{x} in {s} ({s})", .{
13071307 address,
13081308 symbol.name orelse "???",
1309 symbol.compile_unit_name orelse debug_info.getModuleName(io, address) catch "???",
1309 symbol.compile_unit_name orelse (debug_info.getModuleName(io, address) catch "???"),
13101310 });
13111311 t.setColor(.reset) catch {};
13121312 try writer.writeAll("\n");
lib/std/debug/SelfInfo/Elf.zig+4-4
......@@ -16,11 +16,11 @@ pub fn deinit(si: *SelfInfo, io: Io) void {
1616 const gpa = std.debug.getDebugInfoAllocator();
1717 for (si.modules.items) |*mod| {
1818 unwind: {
19 const u = &(mod.unwind orelse break :unwind catch break :unwind);
19 const u = &((mod.unwind orelse break :unwind) catch break :unwind);
2020 for (u.buf[0..u.len]) |*unwind| unwind.deinit(gpa);
2121 }
2222 loaded: {
23 const l = &(mod.loaded_elf orelse break :loaded catch break :loaded);
23 const l = &((mod.loaded_elf orelse break :loaded) catch break :loaded);
2424 l.file.deinit(gpa);
2525 }
2626 }
......@@ -431,11 +431,11 @@ fn findModule(si: *SelfInfo, gpa: Allocator, io: Io, address: usize, lock: enum
431431 }
432432 for (si.modules.items) |*mod| {
433433 unwind: {
434 const u = &(mod.unwind orelse break :unwind catch break :unwind);
434 const u = &((mod.unwind orelse break :unwind) catch break :unwind);
435435 for (u.buf[0..u.len]) |*unwind| unwind.deinit(gpa);
436436 }
437437 loaded: {
438 const l = &(mod.loaded_elf orelse break :loaded catch break :loaded);
438 const l = &((mod.loaded_elf orelse break :loaded) catch break :loaded);
439439 l.file.deinit(gpa);
440440 }
441441 }
lib/std/debug/SelfInfo/MachO.zig+2-2
......@@ -11,11 +11,11 @@ pub fn deinit(si: *SelfInfo, io: Io) void {
1111 const gpa = std.debug.getDebugInfoAllocator();
1212 for (si.modules.keys()) |*module| {
1313 unwind: {
14 const u = &(module.unwind orelse break :unwind catch break :unwind);
14 const u = &((module.unwind orelse break :unwind) catch break :unwind);
1515 if (u.dwarf) |*dwarf| dwarf.deinit(gpa);
1616 }
1717 file: {
18 const f = &(module.file orelse break :file catch break :file);
18 const f = &((module.file orelse break :file) catch break :file);
1919 f.deinit(gpa);
2020 }
2121 }
lib/std/debug/SelfInfo/Windows.zig+4-4
......@@ -280,7 +280,7 @@ const Module = struct {
280280 // we have no information to add to the address
281281 break :pdb;
282282 };
283 const module = pdb.getModule(mod_index) catch |err| switch (err) {
283 const module = (pdb.getModule(mod_index) catch |err| switch (err) {
284284 error.InvalidDebugInfo,
285285 error.MissingDebugInfo,
286286 error.OutOfMemory,
......@@ -289,7 +289,7 @@ const Module = struct {
289289 error.ReadFailed,
290290 error.EndOfStream,
291291 => return error.InvalidDebugInfo,
292 } orelse {
292 }) orelse {
293293 return error.InvalidDebugInfo; // bad module index
294294 };
295295
......@@ -539,9 +539,9 @@ const Module = struct {
539539 }
540540
541541 var opt_pdb: ?Pdb = pdb: {
542 const path = coff_obj.getPdbPath() catch {
542 const path = (coff_obj.getPdbPath() catch {
543543 return error.InvalidDebugInfo;
544 } orelse {
544 }) orelse {
545545 break :pdb null;
546546 };
547547 const pdb_file_open_result = if (fs.path.isAbsolute(path)) res: {
lib/std/dynamic_library.zig+7-7
......@@ -13,7 +13,7 @@ const posix = std.posix;
1313/// Platform-specific functionality is available through the `inner` field.
1414pub const DynLib = struct {
1515 const InnerType = switch (native_os) {
16 .linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .static)
16 .linux => if (!builtin.link_libc or (builtin.abi == .musl and builtin.link_mode == .static))
1717 ElfDynLib
1818 else
1919 DlDynLib,
......@@ -434,15 +434,15 @@ pub const ElfDynLib = struct {
434434 pub fn lookupAddress(self: *const ElfDynLib, vername: []const u8, name: []const u8) ?usize {
435435 const maybe_versym = if (self.verdef == null) null else self.versym;
436436
437 const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON);
438 const OK_BINDS = (1 << elf.STB_GLOBAL | 1 << elf.STB_WEAK | 1 << elf.STB_GNU_UNIQUE);
437 const OK_TYPES = (1 << elf.STT_NOTYPE) | (1 << elf.STT_OBJECT) | (1 << elf.STT_FUNC) | (1 << elf.STT_COMMON);
438 const OK_BINDS = (1 << elf.STB_GLOBAL) | (1 << elf.STB_WEAK) | (1 << elf.STB_GNU_UNIQUE);
439439
440440 switch (self.hash_table) {
441441 .dt_hash => |hashtab| {
442442 var i: usize = 0;
443443 while (i < hashtab[1]) : (i += 1) {
444 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info & 0xf)) & OK_TYPES)) continue;
445 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info >> 4)) & OK_BINDS)) continue;
444 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info & 0xf))) & OK_TYPES) continue;
445 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info >> 4))) & OK_BINDS) continue;
446446 if (0 == self.syms[i].st_shndx) continue;
447447 if (!mem.eql(u8, name, mem.sliceTo(self.strings + self.syms[i].st_name, 0))) continue;
448448 if (maybe_versym) |versym| {
......@@ -494,8 +494,8 @@ pub const ElfDynLib = struct {
494494 const symbol_index = current_index + gnu_hash_header.symoffset;
495495 const symbol = self.syms[symbol_index];
496496
497 if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info & 0xf)) & OK_TYPES)) continue;
498 if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info >> 4)) & OK_BINDS)) continue;
497 if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info & 0xf))) & OK_TYPES) continue;
498 if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info >> 4))) & OK_BINDS) continue;
499499 if (0 == symbol.st_shndx) continue;
500500
501501 const symbol_name = mem.sliceTo(self.strings + symbol.st_name, 0);
lib/std/fmt/parse_float/common.zig+1-1
......@@ -82,7 +82,7 @@ pub fn isDigit(c: u8, comptime base: u8) bool {
8282 return if (base == 10)
8383 '0' <= c and c <= '9'
8484 else
85 '0' <= c and c <= '9' or 'a' <= c and c <= 'f' or 'A' <= c and c <= 'F';
85 ('0' <= c and c <= '9') or ('a' <= c and c <= 'f') or ('A' <= c and c <= 'F');
8686}
8787
8888/// Returns the underlying storage type used for the mantissa of floating-point type.
lib/std/hash/cityhash.zig+1-1
......@@ -222,7 +222,7 @@ pub const CityHash64 = struct {
222222 const c: u8 = str[str.len - 1];
223223 const y: u32 = @as(u32, @intCast(a)) +% (@as(u32, @intCast(b)) << 8);
224224 const z: u32 = @as(u32, @truncate(str.len)) +% (@as(u32, @intCast(c)) << 2);
225 return shiftmix(@as(u64, @intCast(y)) *% k2 ^ @as(u64, @intCast(z)) *% k0) *% k2;
225 return shiftmix((@as(u64, @intCast(y)) *% k2) ^ (@as(u64, @intCast(z)) *% k0)) *% k2;
226226 }
227227 return k2;
228228 }
lib/std/hash/xxhash.zig+1-1
......@@ -398,7 +398,7 @@ pub const XxHash32 = struct {
398398 }
399399
400400 fn avalanche(value: u32) u32 {
401 var acc = value ^ value >> 15;
401 var acc = value ^ (value >> 15);
402402 acc *%= prime_2;
403403 acc ^= acc >> 13;
404404 acc *%= prime_3;
lib/std/hash_map.zig+1-1
......@@ -2019,7 +2019,7 @@ test "getOrPutAdapted" {
20192019 const AdaptedContext = struct {
20202020 fn eql(self: @This(), adapted_key: []const u8, test_key: u64) bool {
20212021 _ = self;
2022 return std.fmt.parseInt(u64, adapted_key, 10) catch unreachable == test_key;
2022 return (std.fmt.parseInt(u64, adapted_key, 10) catch unreachable) == test_key;
20232023 }
20242024 fn hash(self: @This(), adapted_key: []const u8) u64 {
20252025 _ = self;
lib/std/heap/SafeAllocator.zig+1-1
......@@ -211,7 +211,7 @@ const Bucket = struct {
211211
212212 fn of(s: *SafeAllocator, ptr: [*]u8) *Bucket {
213213 const size_log2 = s.bucket_size_log2;
214 return @ptrFromInt(@intFromPtr(ptr) >> @intCast(size_log2) << @intCast(size_log2));
214 return @ptrFromInt((@intFromPtr(ptr) >> @intCast(size_log2)) << @intCast(size_log2));
215215 }
216216
217217 fn fillAt(s: *SafeAllocator, ptr: [*]const u8) u32 {
lib/std/math.zig+14-14
......@@ -710,7 +710,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
710710
711711 if (comptime isPowerOfTwo(@typeInfo(T).int.bits)) {
712712 const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).int.bits));
713 return x >> ar | x << (1 +% ~ar);
713 return (x >> ar) | (x << (1 +% ~ar));
714714 } else {
715715 const ar = @mod(r, @typeInfo(T).int.bits);
716716 return shr(T, x, ar) | shl(T, x, @typeInfo(T).int.bits - ar);
......@@ -753,7 +753,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
753753
754754 if (comptime isPowerOfTwo(@typeInfo(T).int.bits)) {
755755 const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).int.bits));
756 return x << ar | x >> 1 +% ~ar;
756 return (x << ar) | (x >> (1 +% ~ar));
757757 } else {
758758 const ar = @mod(r, @typeInfo(T).int.bits);
759759 return shl(T, x, ar) | shr(T, x, @typeInfo(T).int.bits - ar);
......@@ -1542,21 +1542,21 @@ pub const Order = enum {
15421542 const neg: i32 = -1;
15431543 const zero: i32 = 0;
15441544 const pos: i32 = 1;
1545 try testing.expect(order(zero, neg).differ() orelse
1546 order(pos, zero) == .gt);
1547 try testing.expect(order(zero, zero).differ() orelse
1548 order(zero, zero) == .eq);
1549 try testing.expect(order(pos, pos).differ() orelse
1550 order(neg, zero) == .lt);
1551 try testing.expect(order(zero, zero).differ() orelse
1545 try testing.expect((order(zero, neg).differ() orelse
1546 order(pos, zero)) == .gt);
1547 try testing.expect((order(zero, zero).differ() orelse
1548 order(zero, zero)) == .eq);
1549 try testing.expect((order(pos, pos).differ() orelse
1550 order(neg, zero)) == .lt);
1551 try testing.expect((order(zero, zero).differ() orelse
15521552 order(pos, neg).differ() orelse
1553 order(neg, zero) == .gt);
1554 try testing.expect(order(pos, pos).differ() orelse
1553 order(neg, zero)) == .gt);
1554 try testing.expect((order(pos, pos).differ() orelse
15551555 order(pos, pos).differ() orelse
1556 order(neg, neg) == .eq);
1557 try testing.expect(order(zero, pos).differ() orelse
1556 order(neg, neg)) == .eq);
1557 try testing.expect((order(zero, pos).differ() orelse
15581558 order(neg, pos).differ() orelse
1559 order(pos, neg) == .lt);
1559 order(pos, neg)) == .lt);
15601560 }
15611561
15621562 pub fn compare(self: Order, op: CompareOperator) bool {
lib/std/math/acos.zig+1-1
......@@ -176,7 +176,7 @@ fn acosBinary64(x: f64) f64 {
176176 // |x| >= 1 or nan
177177 if (ix >= 0x3ff0_0000) {
178178 const lx: u32 = @truncate(@as(u64, @bitCast(x)));
179 if ((ix - 0x3ff0_0000 | lx) == 0) {
179 if (((ix - 0x3ff0_0000) | lx) == 0) {
180180 if (hx >> 31 != 0) {
181181 return 2.0 * pio2_hi + 0x1.0p-120;
182182 }
lib/std/math/asin.zig+1-1
......@@ -156,7 +156,7 @@ fn asinBinary64(x: f64) f64 {
156156 if (ix >= 0x3ff0_0000) {
157157 const lx: u32 = @truncate(@as(u64, @bitCast(x)));
158158 // asin(1) = +-pi/2 with inexact
159 if ((ix - 0x3ff0_0000 | lx) == 0) {
159 if (((ix - 0x3ff0_0000) | lx) == 0) {
160160 return x * pio2_hi + 0x1.0p-120;
161161 }
162162 return 0.0 / (x - x);
lib/std/math/big/int.zig+3-3
......@@ -2401,7 +2401,7 @@ pub const Const = struct {
24012401 const shift: usize = @intCast(exponent - @bitSizeOf(Repr.Normalized.Fraction));
24022402 mantissa.shiftRight(normalized_abs, shift);
24032403 const final_limb_index = (shift - 1) / limb_bits;
2404 const round_bits = normalized_abs.limbs[final_limb_index] << @truncate(-%shift) |
2404 const round_bits = (normalized_abs.limbs[final_limb_index] << @truncate(-%shift)) |
24052405 @intFromBool(!std.mem.allEqual(Limb, normalized_abs.limbs[0..final_limb_index], 0));
24062406 if (round_bits == 0) break :exactness .exact;
24072407 round: switch (round) {
......@@ -4902,10 +4902,10 @@ test "format" {
49024902 try a.set(20000000000000000000); // > maxInt(u64)
49034903 try testFormat(a, "20000000000000000000");
49044904
4905 try a.set(1 << 64 * @sizeOf(usize) * 8);
4905 try a.set(1 << (64 * @sizeOf(usize) * 8));
49064906 try testFormat(a, "(BigInt)");
49074907
4908 try a.set(-(1 << 64 * @sizeOf(usize) * 8));
4908 try a.set(-(1 << (64 * @sizeOf(usize) * 8)));
49094909 try testFormat(a, "(BigInt)");
49104910}
49114911
lib/std/math/big/int_test.zig+16-16
......@@ -2489,14 +2489,14 @@ test "truncate to minimum signed integer" {
24892489 .len = undefined,
24902490 .positive = undefined,
24912491 };
2492 res.truncate(.{ .positive = true, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .signed, @bitSizeOf(Limb));
2493 try testing.expect(res.toConst().orderAgainstScalar(-1 << @bitSizeOf(Limb) - 1).compare(.eq));
2494 res.truncate(.{ .positive = false, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .signed, @bitSizeOf(Limb));
2495 try testing.expect(res.toConst().orderAgainstScalar(-1 << @bitSizeOf(Limb) - 1).compare(.eq));
2496 res.truncate(.{ .positive = true, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .unsigned, @bitSizeOf(Limb));
2497 try testing.expect(res.toConst().orderAgainstScalar(1 << @bitSizeOf(Limb) - 1).compare(.eq));
2498 res.truncate(.{ .positive = false, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .unsigned, @bitSizeOf(Limb));
2499 try testing.expect(res.toConst().orderAgainstScalar(1 << @bitSizeOf(Limb) - 1).compare(.eq));
2492 res.truncate(.{ .positive = true, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .signed, @bitSizeOf(Limb));
2493 try testing.expect(res.toConst().orderAgainstScalar(-1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
2494 res.truncate(.{ .positive = false, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .signed, @bitSizeOf(Limb));
2495 try testing.expect(res.toConst().orderAgainstScalar(-1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
2496 res.truncate(.{ .positive = true, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .unsigned, @bitSizeOf(Limb));
2497 try testing.expect(res.toConst().orderAgainstScalar(1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
2498 res.truncate(.{ .positive = false, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .unsigned, @bitSizeOf(Limb));
2499 try testing.expect(res.toConst().orderAgainstScalar(1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
25002500}
25012501
25022502test "saturate single signed positive" {
......@@ -3880,7 +3880,7 @@ test "clz" {
38803880 try testing.expectEqual(0, neg_limb_max_squared_plus_one.clz(@bitSizeOf(Limb) * 2 + 1));
38813881
38823882 const neg_limb_msb_squared: std.math.big.int.Const = .{
3883 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
3883 .limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
38843884 .positive = false,
38853885 };
38863886 try testing.expectEqual(0, neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2));
......@@ -3896,7 +3896,7 @@ test "clz" {
38963896 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) * 2 + 1));
38973897
38983898 const neg_limb_msb: std.math.big.int.Const = .{
3899 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
3899 .limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
39003900 .positive = false,
39013901 };
39023902 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb)));
......@@ -3936,7 +3936,7 @@ test "clz" {
39363936 try testing.expectEqual(@bitSizeOf(Limb) * 2, one.clz(@bitSizeOf(Limb) * 2 + 1));
39373937
39383938 const limb_msb: std.math.big.int.Const = .{
3939 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
3939 .limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
39403940 .positive = true,
39413941 };
39423942 try testing.expectEqual(0, limb_msb.clz(@bitSizeOf(Limb)));
......@@ -3956,7 +3956,7 @@ test "clz" {
39563956 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_max.clz(@bitSizeOf(Limb) * 2 + 1));
39573957
39583958 const limb_msb_squared: std.math.big.int.Const = .{
3959 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
3959 .limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
39603960 .positive = true,
39613961 };
39623962 try testing.expectEqual(0, limb_msb_squared.clz(@bitSizeOf(Limb) * 2 - 1));
......@@ -3992,7 +3992,7 @@ test "ctz" {
39923992 try testing.expectEqual(@bitSizeOf(Limb) + 1, neg_limb_max_squared_plus_one.ctz(@bitSizeOf(Limb) * 2 + 1));
39933993
39943994 const neg_limb_msb_squared: std.math.big.int.Const = .{
3995 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
3995 .limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
39963996 .positive = false,
39973997 };
39983998 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2));
......@@ -4008,7 +4008,7 @@ test "ctz" {
40084008 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));
40094009
40104010 const neg_limb_msb: std.math.big.int.Const = .{
4011 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
4011 .limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
40124012 .positive = false,
40134013 };
40144014 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb)));
......@@ -4048,7 +4048,7 @@ test "ctz" {
40484048 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) * 2 + 1));
40494049
40504050 const limb_msb: std.math.big.int.Const = .{
4051 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
4051 .limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
40524052 .positive = true,
40534053 };
40544054 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb)));
......@@ -4068,7 +4068,7 @@ test "ctz" {
40684068 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));
40694069
40704070 const limb_msb_squared: std.math.big.int.Const = .{
4071 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
4071 .limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
40724072 .positive = true,
40734073 };
40744074 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 - 1));
lib/std/math/float.zig+2-2
......@@ -281,7 +281,7 @@ pub inline fn nan(comptime Type: type) Type {
281281 return reconstructFloat(
282282 RuntimeType,
283283 floatExponentMax(RuntimeType) + 1,
284 mantissaOne(RuntimeType) | 1 << (floatFractionalBits(RuntimeType) - 1),
284 mantissaOne(RuntimeType) | (1 << (floatFractionalBits(RuntimeType) - 1)),
285285 );
286286}
287287
......@@ -297,7 +297,7 @@ pub inline fn snan(comptime Type: type) Type {
297297 return reconstructFloat(
298298 RuntimeType,
299299 floatExponentMax(RuntimeType) + 1,
300 mantissaOne(RuntimeType) | 1 << (floatFractionalBits(RuntimeType) - 2),
300 mantissaOne(RuntimeType) | (1 << (floatFractionalBits(RuntimeType) - 2)),
301301 );
302302}
303303
lib/std/mem.zig+1-1
......@@ -4354,7 +4354,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {
43544354 @compileError("expected many item pointer, got " ++ @typeName(T));
43554355
43564356 // Do nothing if the pointer is already well-aligned.
4357 if (align_to <= info.pointer.attrs.@"align" orelse @alignOf(info.pointer.child))
4357 if (align_to <= (info.pointer.attrs.@"align" orelse @alignOf(info.pointer.child)))
43584358 return 0;
43594359
43604360 // Calculate the aligned base address with an eye out for overflow.
lib/std/os/linux/vdso.zig+4-4
......@@ -62,13 +62,13 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6262 const hashtab = maybe_hashtab orelse return 0;
6363 if (maybe_verdef == null) maybe_versym = null;
6464
65 const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON);
66 const OK_BINDS = (1 << elf.STB_GLOBAL | 1 << elf.STB_WEAK | 1 << elf.STB_GNU_UNIQUE);
65 const OK_TYPES = (1 << elf.STT_NOTYPE) | (1 << elf.STT_OBJECT) | (1 << elf.STT_FUNC) | (1 << elf.STT_COMMON);
66 const OK_BINDS = (1 << elf.STB_GLOBAL) | (1 << elf.STB_WEAK) | (1 << elf.STB_GNU_UNIQUE);
6767
6868 var i: usize = 0;
6969 while (i < hashtab[1]) : (i += 1) {
70 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info & 0xf)) & OK_TYPES)) continue;
71 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info >> 4)) & OK_BINDS)) continue;
70 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info & 0xf))) & OK_TYPES) continue;
71 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info >> 4))) & OK_BINDS) continue;
7272 if (0 == syms[i].st_shndx) continue;
7373 const sym_name = @as([*:0]u8, @ptrCast(strings + syms[i].st_name));
7474 if (!mem.eql(u8, name, mem.sliceTo(sym_name, 0))) continue;
lib/std/os/uefi/status.zig+1-1
......@@ -1,6 +1,6 @@
11const testing = @import("std").testing;
22
3const high_bit = 1 << @typeInfo(usize).int.bits - 1;
3const high_bit = 1 << (@typeInfo(usize).int.bits - 1);
44
55pub const Status = enum(usize) {
66 /// The operation completed successfully.
lib/std/unicode.zig+1-1
......@@ -485,7 +485,7 @@ pub fn utf16DecodeSurrogatePair(surrogate_pair: []const u16) !u21 {
485485 const high_half: u21 = surrogate_pair[0];
486486 const low_half = surrogate_pair[1];
487487 if (!utf16IsLowSurrogate(low_half)) return error.ExpectedSecondSurrogateHalf;
488 return 0x10000 + ((high_half & 0x03ff) << 10) | (low_half & 0x03ff);
488 return (0x10000 + ((high_half & 0x03ff) << 10)) | (low_half & 0x03ff);
489489}
490490
491491pub const Utf16LeIterator = struct {
lib/std/zig/Ast.zig+32
......@@ -555,6 +555,33 @@ pub fn renderError(tree: Ast, parse_error: Error, w: *Writer) Writer.Error!void
555555 .var_const_decl => {
556556 return w.writeAll("use 'var' or 'const' to declare variable");
557557 },
558 .ambiguous_operator_precedence => {
559 return w.print("ambiguous operator precedence with operators ... {s} ... {s} ...; use parentheses to disambiguate", .{
560 tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
561 tree.tokenTag(parse_error.token).lexeme().?,
562 });
563 },
564 .previous_ambiguous_operator => {
565 return w.writeAll("previous ambiguous operator here");
566 },
567 .illegal_chained_operators => {
568 return w.print("repetition of non-chainable operators ... {s} ... {s} ...; use parentheses to disambiguate", .{
569 tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
570 tree.tokenTag(parse_error.token).lexeme().?,
571 });
572 },
573 .hint_operator_precedence_left => {
574 return w.print("in zig 0.17.x, this was evaluated as (... {s} ...) {s} ...", .{
575 tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
576 tree.tokenTag(parse_error.token).lexeme().?,
577 });
578 },
579 .hint_operator_precedence_right => {
580 return w.print("in zig 0.17.x, this was evaluated as ... {s} (... {s} ...)", .{
581 tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
582 tree.tokenTag(parse_error.token).lexeme().?,
583 });
584 },
558585
559586 .invalid_byte => {
560587 const tok_slice = tree.source[tree.tokens.items(.start)[parse_error.token]..];
......@@ -2893,6 +2920,11 @@ pub const Error = struct {
28932920 expected_var_const,
28942921 wrong_equal_var_decl,
28952922 var_const_decl,
2923 ambiguous_operator_precedence,
2924 previous_ambiguous_operator,
2925 hint_operator_precedence_left,
2926 hint_operator_precedence_right,
2927 illegal_chained_operators,
28962928
28972929 zig_style_container,
28982930 previous_field,
lib/std/zig/Ast/Render.zig+34-5
......@@ -45,6 +45,8 @@ pub const Fixups = struct {
4545 replace_nodes_with_node: std.AutoHashMapUnmanaged(Ast.Node.Index, Ast.Node.Index) = .empty,
4646 /// Change all identifier names matching the key to be value instead.
4747 rename_identifiers: std.array_hash_map.String([]const u8) = .empty,
48 /// Add parentheses surrounding the node.
49 insert_parentheses: std.AutoHashMapUnmanaged(Ast.Node.Index, void) = .empty,
4850
4951 /// All `@import` builtin calls which refer to a file path will be prefixed
5052 /// with this path.
......@@ -58,6 +60,7 @@ pub const Fixups = struct {
5860 f.append_string_after_node.count() +
5961 f.replace_nodes_with_node.count() +
6062 f.rename_identifiers.count() +
63 f.insert_parentheses.count() +
6164 @intFromBool(f.rebase_imported_paths != null);
6265 }
6366
......@@ -69,6 +72,7 @@ pub const Fixups = struct {
6972 f.append_string_after_node.clearRetainingCapacity();
7073 f.replace_nodes_with_node.clearRetainingCapacity();
7174 f.rename_identifiers.clearRetainingCapacity();
75 f.insert_parentheses.clearRetainingCapacity();
7276
7377 f.rebase_imported_paths = null;
7478 }
......@@ -81,6 +85,7 @@ pub const Fixups = struct {
8185 f.append_string_after_node.deinit(gpa);
8286 f.replace_nodes_with_node.deinit(gpa);
8387 f.rename_identifiers.deinit(gpa);
88 f.insert_parentheses.deinit(gpa);
8489 f.* = undefined;
8590 }
8691};
......@@ -420,6 +425,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
420425 tree.tokenTag(fallback_first) == .multiline_string_literal_line;
421426 const after_op_space: Space = if (seperate_line) .newline else .space;
422427
428 if (r.fixups.insert_parentheses.contains(node)) {
429 try ais.writeByte('(');
430 }
423431 try renderExpression(r, lhs, .space); // target
424432
425433 try ais.pushIndent(.normal);
......@@ -432,7 +440,16 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
432440 assert(tree.tokenTag(fallback_first - 1) == .keyword_catch);
433441 try renderToken(r, main_token, after_op_space); // catch keyword
434442 }
435 try renderExpression(r, rhs, space); // fallback
443 if (r.fixups.insert_parentheses.contains(node)) {
444 try renderExpression(r, rhs, .none);
445 try ais.writeByte(')');
446 const right_most_token = tree.lastToken(rhs);
447 const lexeme = tokenSliceForRender(tree, right_most_token);
448 // If our space is .none, then the above code functions is normal and below shouldn't run
449 if (space != .none) try renderSpace(r, right_most_token, lexeme.len, space);
450 } else {
451 try renderExpression(r, rhs, space); // fallback
452 }
436453 ais.popIndent();
437454 },
438455
......@@ -539,13 +556,25 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
539556 .@"orelse",
540557 => {
541558 const lhs, const rhs = tree.nodeData(node).node_and_node;
559 if (r.fixups.insert_parentheses.contains(node)) {
560 try ais.writeByte('(');
561 }
542562 try renderExpression(r, lhs, .space);
543563 const op_token = tree.nodeMainToken(node);
544564 try ais.pushIndent(.binop);
545565 const rhs_seperate_line = !tree.tokensOnSameLine(op_token, op_token + 1) or
546566 tree.tokenTag(op_token + 1) == .multiline_string_literal_line;
547567 try renderToken(r, op_token, if (rhs_seperate_line) .newline else .space);
548 try renderExpression(r, rhs, space);
568 if (r.fixups.insert_parentheses.contains(node)) {
569 try renderExpression(r, rhs, .none);
570 try ais.writeByte(')');
571 const right_most_token = tree.lastToken(rhs);
572 const lexeme = tokenSliceForRender(tree, right_most_token);
573 // If our space was already .none, then the line below will be redundent as above handles it.
574 if (space != .none) try renderSpace(r, right_most_token, lexeme.len, space);
575 } else {
576 try renderExpression(r, rhs, space);
577 }
549578 ais.popIndent();
550579 },
551580
......@@ -1483,9 +1512,9 @@ fn renderThenElse(
14831512 last_else_token = error_token + 1; // |
14841513 }
14851514
1486 const indent_else_expr = indent_then_expr and
1515 const indent_else_expr = (indent_then_expr and
14871516 !nodeIsBlock(tree.nodeTag(else_expr)) and
1488 !nodeIsIfForWhileSwitch(tree.nodeTag(else_expr)) or
1517 !nodeIsIfForWhileSwitch(tree.nodeTag(else_expr))) or
14891518 tree.tokenTag(tree.firstToken(else_expr)) ==
14901519 .multiline_string_literal_line;
14911520 if (indent_else_expr) {
......@@ -3195,7 +3224,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {
31953224 }
31963225 }
31973226
3198 index = 1 + (newline orelse end - 1);
3227 index = 1 + (newline orelse (end - 1));
31993228
32003229 const comment_content = mem.trimStart(u8, trimmed_comment["//".len..], &std.ascii.whitespace);
32013230 if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) {
lib/std/zig/Parse.zig+319-55
......@@ -1512,7 +1512,7 @@ fn expectAssignExpr(p: *Parse) !Node.Index {
15121512}
15131513
15141514fn parseExpr(p: *Parse) Error!?Node.Index {
1515 return p.parseExprPrecedence(0);
1515 return p.parseExprPrecedence(.start, p.tok_i);
15161516}
15171517
15181518fn expectExpr(p: *Parse) Error!Node.Index {
......@@ -1524,67 +1524,335 @@ const Assoc = enum {
15241524 none,
15251525};
15261526
1527const PrecClass = struct {
1528 group: Group,
1529 assoc: Assoc = Assoc.left,
1530
1531 const Group = enum {
1532 const num_distinct = std.meta.fieldNames(Group).len;
1533
1534 top,
1535
1536 arithmetic_product_chainable,
1537 arithmetic_mod_nonchainable,
1538 arithmetic_sum,
1539
1540 bitwise_shift,
1541 bitwise_and,
1542 bitwise_xor,
1543 bitwise_or,
1544
1545 comparison,
1546
1547 bool_and,
1548 bool_or,
1549
1550 recovery_orelse,
1551 recovery_catch,
1552
1553 root,
1554
1555 const Major = enum {
1556 top,
1557 arithmetic,
1558 bitwise,
1559 comparison,
1560 bool,
1561 recovery,
1562 root,
1563 };
1564
1565 fn getMajor(group: Group) Major {
1566 return switch (group) {
1567 .top,
1568 => .top,
1569
1570 .arithmetic_product_chainable,
1571 .arithmetic_mod_nonchainable,
1572 .arithmetic_sum,
1573 => .arithmetic,
1574
1575 .bitwise_shift,
1576 .bitwise_and,
1577 .bitwise_xor,
1578 .bitwise_or,
1579 => .bitwise,
1580
1581 .comparison,
1582 => .comparison,
1583
1584 .bool_and,
1585 .bool_or,
1586 => .bool,
1587
1588 .recovery_orelse,
1589 .recovery_catch,
1590 => .recovery,
1591
1592 .root,
1593 => .root,
1594 };
1595 }
1596 };
1597
1598 pub const start: PrecClass = .{ .group = .root };
1599
1600 pub const Rel = enum(i2) {
1601 lt = -1,
1602 eq = 0,
1603 gt = 1,
1604
1605 fn inverted(self: Rel) Rel {
1606 return @fromBackingInt(@intCast(-@backingInt(self)));
1607 }
1608 };
1609
1610 const PrecedenceArray = [Group.num_distinct][Group.num_distinct]?Rel;
1611
1612 fn setMajorRelation(prec_array: *PrecedenceArray, major_a: Group.Major, rel: Rel, major_b: Group.Major) void {
1613 for (std.meta.fieldNames(Group), 0..) |fieldname_i, i| {
1614 if (@field(Group, fieldname_i).getMajor() != major_a) continue;
1615
1616 for (std.meta.fieldNames(Group), 0..) |fieldname_j, j| {
1617 if (@field(Group, fieldname_j).getMajor() != major_b) continue;
1618
1619 prec_array[i][j] = rel;
1620 prec_array[j][i] = rel.inverted();
1621 }
1622 }
1623 }
1624
1625 fn setMinorRelation(prec_array: *PrecedenceArray, minor_a: Group, rel: Rel, minor_b: Group) void {
1626 prec_array[@backingInt(minor_a)][@backingInt(minor_b)] = rel;
1627 prec_array[@backingInt(minor_b)][@backingInt(minor_a)] = rel.inverted();
1628 }
1629
1630 /// order[y][x] --> y cmp x
1631 const precedence_ordering = b: {
1632 @setEvalBranchQuota(20_000);
1633 const major_greater_than_relations = [_][2]Group.Major{
1634 // zig fmt: off
1635 .{ .top, .arithmetic },
1636 .{ .top, .bitwise },
1637 .{ .top, .recovery },
1638 .{ .arithmetic, .comparison },
1639 .{ .bitwise, .comparison },
1640 .{ .comparison, .bool },
1641 .{ .bool, .root },
1642 .{ .recovery, .root },
1643 // zig fmt: on
1644 };
1645
1646 var order: PrecedenceArray = @splat(@splat(null));
1647
1648 for (major_greater_than_relations) |relation| {
1649 setMajorRelation(&order, relation[0], .gt, relation[1]);
1650 }
1651
1652 setMinorRelation(&order, .arithmetic_mod_nonchainable, .gt, .arithmetic_sum);
1653 setMinorRelation(&order, .arithmetic_product_chainable, .gt, .arithmetic_sum);
1654
1655 computeTransitiveOrdering(&order);
1656 break :b order;
1657 };
1658
1659 /// Uses the table from Zig-0.17.0
1660 /// * / % *% *| ||
1661 /// + - ++ +% -% +| -|
1662 /// << >> <<|
1663 /// & ^ | orelse catch
1664 /// == != < > <= >=
1665 /// and
1666 /// or
1667 const v0_17_precedence_ordering = b: {
1668 @setEvalBranchQuota(20_000);
1669
1670 var order: PrecedenceArray = @splat(@splat(null));
1671
1672 setMinorRelation(&order, .top, .gt, .arithmetic_product_chainable);
1673
1674 setMinorRelation(&order, .arithmetic_product_chainable, .eq, .arithmetic_mod_nonchainable);
1675 setMinorRelation(&order, .arithmetic_mod_nonchainable, .gt, .arithmetic_sum);
1676
1677 setMinorRelation(&order, .arithmetic_sum, .gt, .bitwise_shift);
1678
1679 setMinorRelation(&order, .bitwise_shift, .gt, .bitwise_and);
1680
1681 setMinorRelation(&order, .bitwise_and, .eq, .bitwise_xor);
1682 setMinorRelation(&order, .bitwise_and, .eq, .bitwise_or);
1683 setMinorRelation(&order, .bitwise_and, .eq, .recovery_catch);
1684 setMinorRelation(&order, .bitwise_and, .eq, .recovery_orelse);
1685
1686 setMinorRelation(&order, .bitwise_and, .gt, .comparison);
1687
1688 setMinorRelation(&order, .comparison, .gt, .bool_and);
1689
1690 setMinorRelation(&order, .bool_and, .gt, .bool_or);
1691
1692 setMinorRelation(&order, .bool_or, .gt, .root);
1693
1694 computeTransitiveOrdering(&order);
1695 for (order) |row| {
1696 for (row) |item| {
1697 if (item == null) @compileError("Null entry in old precedence ordering which had none.");
1698 }
1699 }
1700 break :b order;
1701 };
1702
1703 pub fn cmp(lhs: PrecClass, rhs: PrecClass) ?Rel {
1704 return PrecClass.precedence_ordering[@backingInt(lhs.group)][@backingInt(rhs.group)];
1705 }
1706
1707 pub fn v0_17_cmp(lhs: PrecClass, rhs: PrecClass) Rel {
1708 return PrecClass.v0_17_precedence_ordering[@backingInt(lhs.group)][@backingInt(rhs.group)].?;
1709 }
1710
1711 fn computeTransitiveOrdering(order: *PrecedenceArray) void {
1712 for (0..Group.num_distinct) |i| for (0..Group.num_distinct) |j| for (0..Group.num_distinct) |k| {
1713 if (order[i][j] == null or order[j][k] == null) continue;
1714 // X < Y < Z ==> X < Z X > Y > Z ==> X > Z
1715 if (order[i][j] == order[j][k]) order[i][k] = order[i][j];
1716 // X = Y < Z ==> X < Z X = Y > Z ==> X > Z
1717 if (order[i][j] == .eq) order[i][k] = order[j][k];
1718 // X < Y = Z ==> X < Z X > Y = Z ==> X > Z
1719 if (order[j][k] == .eq) order[i][k] = order[i][j];
1720 };
1721 for (0..Group.num_distinct) |i| for (0..Group.num_distinct) |j| {
1722 if (i == j) order[i][j] = .eq;
1723 if (order[i][j] == null and order[j][i] != null) order[i][j] = order[j][i].?.inverted();
1724 };
1725 }
1726};
1727
15271728const OperInfo = struct {
1528 prec: i8,
1729 prec: PrecClass,
15291730 tag: Node.Tag,
1530 assoc: Assoc = Assoc.left,
15311731};
15321732
1533// A table of binary operator information. Higher precedence numbers are
1534// stickier. All operators at the same precedence level should have the same
1535// associativity.
1536const operTable = std.enums.directEnumArrayDefault(Token.Tag, OperInfo, .{ .prec = -1, .tag = Node.Tag.root }, 0, .{
1537 .keyword_or = .{ .prec = 10, .tag = .bool_or },
1538
1539 .keyword_and = .{ .prec = 20, .tag = .bool_and },
1540
1541 .equal_equal = .{ .prec = 30, .tag = .equal_equal, .assoc = Assoc.none },
1542 .bang_equal = .{ .prec = 30, .tag = .bang_equal, .assoc = Assoc.none },
1543 .angle_bracket_left = .{ .prec = 30, .tag = .less_than, .assoc = Assoc.none },
1544 .angle_bracket_right = .{ .prec = 30, .tag = .greater_than, .assoc = Assoc.none },
1545 .angle_bracket_left_equal = .{ .prec = 30, .tag = .less_or_equal, .assoc = Assoc.none },
1546 .angle_bracket_right_equal = .{ .prec = 30, .tag = .greater_or_equal, .assoc = Assoc.none },
1547
1548 .ampersand = .{ .prec = 40, .tag = .bit_and },
1549 .caret = .{ .prec = 40, .tag = .bit_xor },
1550 .pipe = .{ .prec = 40, .tag = .bit_or },
1551 .keyword_orelse = .{ .prec = 40, .tag = .@"orelse" },
1552 .keyword_catch = .{ .prec = 40, .tag = .@"catch" },
1553
1554 .angle_bracket_angle_bracket_left = .{ .prec = 50, .tag = .shl },
1555 .angle_bracket_angle_bracket_left_pipe = .{ .prec = 50, .tag = .shl_sat },
1556 .angle_bracket_angle_bracket_right = .{ .prec = 50, .tag = .shr },
1557
1558 .plus = .{ .prec = 60, .tag = .add },
1559 .minus = .{ .prec = 60, .tag = .sub },
1560 .plus_plus = .{ .prec = 60, .tag = .array_cat },
1561 .plus_percent = .{ .prec = 60, .tag = .add_wrap },
1562 .minus_percent = .{ .prec = 60, .tag = .sub_wrap },
1563 .plus_pipe = .{ .prec = 60, .tag = .add_sat },
1564 .minus_pipe = .{ .prec = 60, .tag = .sub_sat },
1565
1566 .pipe_pipe = .{ .prec = 70, .tag = .merge_error_sets },
1567 .asterisk = .{ .prec = 70, .tag = .mul },
1568 .slash = .{ .prec = 70, .tag = .div },
1569 .percent = .{ .prec = 70, .tag = .mod },
1570 .asterisk_percent = .{ .prec = 70, .tag = .mul_wrap },
1571 .asterisk_pipe = .{ .prec = 70, .tag = .mul_sat },
1733const operTable = std.enums.directEnumArrayDefault(Token.Tag, OperInfo, .{ .prec = .start, .tag = Node.Tag.root }, 0, .{
1734 // zig fmt: off
1735 .keyword_or = .{ .prec = .{ .group = .bool_or }, .tag = .bool_or },
1736
1737 .keyword_and = .{ .prec = .{ .group = .bool_and }, .tag = .bool_and },
1738
1739 .equal_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .equal_equal },
1740 .bang_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .bang_equal },
1741 .angle_bracket_left = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .less_than },
1742 .angle_bracket_right = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .greater_than },
1743 .angle_bracket_left_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .less_or_equal },
1744 .angle_bracket_right_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .greater_or_equal },
1745
1746 .ampersand = .{ .prec = .{ .group = .bitwise_and }, .tag = .bit_and },
1747 .caret = .{ .prec = .{ .group = .bitwise_xor }, .tag = .bit_xor },
1748 .pipe = .{ .prec = .{ .group = .bitwise_or }, .tag = .bit_or },
1749
1750 .keyword_orelse = .{ .prec = .{ .group = .recovery_orelse }, .tag = .@"orelse" },
1751 .keyword_catch = .{ .prec = .{ .group = .recovery_catch }, .tag = .@"catch" },
1752
1753 .angle_bracket_angle_bracket_left = .{ .prec = .{ .group = .bitwise_shift, .assoc = Assoc.none }, .tag = .shl },
1754 .angle_bracket_angle_bracket_left_pipe = .{ .prec = .{ .group = .bitwise_shift, .assoc = Assoc.none }, .tag = .shl_sat },
1755 .angle_bracket_angle_bracket_right = .{ .prec = .{ .group = .bitwise_shift, .assoc = Assoc.none }, .tag = .shr },
1756
1757 .plus = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .add },
1758 .minus = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .sub },
1759 .plus_plus = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .array_cat },
1760 .plus_percent = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .add_wrap },
1761 .minus_percent = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .sub_wrap },
1762 .plus_pipe = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .add_sat },
1763 .minus_pipe = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .sub_sat },
1764
1765 .pipe_pipe = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .merge_error_sets },
1766 .asterisk = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .mul },
1767 .slash = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .div },
1768 .asterisk_percent = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .mul_wrap },
1769 .asterisk_pipe = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .mul_sat },
1770
1771 .percent = .{ .prec = .{ .group = .arithmetic_mod_nonchainable, .assoc = Assoc.none }, .tag = .mod },
1772 // zig fmt: on
15721773});
15731774
1574fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {
1575 assert(min_prec >= 0);
1775fn parseExprPrecedence(p: *Parse, min_exc_prec: PrecClass, prev_operator_token: u32) Error!?Node.Index {
15761776 var node = try p.parsePrefixExpr() orelse return null;
15771777
1578 var banned_prec: i8 = -1;
1579
15801778 while (true) {
15811779 const tok_tag = p.tokenTag(p.tok_i);
1582 const info = operTable[@as(usize, @intCast(@backingInt(tok_tag)))];
1583 if (info.prec < min_prec) {
1780 const info = operTable[@backingInt(tok_tag)];
1781
1782 const rel = info.prec.cmp(min_exc_prec) orelse b: {
1783 const prev_op_tok_tag = p.tokenTag(prev_operator_token);
1784 const prev_op_info = operTable[@backingInt(prev_op_tok_tag)];
1785 const v0_17_rel = prev_op_info.prec.v0_17_cmp(info.prec);
1786 try p.warnMsg(.{
1787 .tag = .ambiguous_operator_precedence,
1788 .is_note = false,
1789 .token = p.tok_i,
1790 .extra = .{
1791 .offset = p.tok_i - prev_operator_token,
1792 },
1793 });
1794 try p.warnMsg(.{
1795 .tag = .previous_ambiguous_operator,
1796 .is_note = true,
1797 .token = prev_operator_token,
1798 });
1799 if (v0_17_rel == .gt or v0_17_rel == .eq) {
1800 try p.warnMsg(.{
1801 .tag = .hint_operator_precedence_left,
1802 .is_note = true,
1803 .token = p.tok_i,
1804 .extra = .{
1805 .offset = p.tok_i - prev_operator_token,
1806 },
1807 });
1808 } else {
1809 try p.warnMsg(.{
1810 .tag = .hint_operator_precedence_right,
1811 .is_note = true,
1812 .token = p.tok_i,
1813 .extra = .{
1814 .offset = p.tok_i - prev_operator_token,
1815 },
1816 });
1817 }
1818 // Use the old precedence rules to construct the tree to ease automatic fixups
1819 break :b info.prec.v0_17_cmp(min_exc_prec);
1820 };
1821
1822 if (rel == .lt) {
15841823 break;
15851824 }
1586 if (info.prec == banned_prec) {
1587 return p.fail(.chained_comparison_operators);
1825
1826 if (min_exc_prec.group == info.prec.group and min_exc_prec.assoc == .none and info.prec.assoc == .none) {
1827 if (info.prec.group == .comparison) {
1828 try p.warn(.chained_comparison_operators);
1829 } else {
1830 try p.warnMsg(.{
1831 .tag = .illegal_chained_operators,
1832 .is_note = false,
1833 .token = p.tok_i,
1834 .extra = .{
1835 .offset = p.tok_i - prev_operator_token,
1836 },
1837 });
1838 try p.warnMsg(.{
1839 .tag = .previous_ambiguous_operator,
1840 .is_note = true,
1841 .token = prev_operator_token,
1842 });
1843 try p.warnMsg(.{
1844 .tag = .hint_operator_precedence_left,
1845 .is_note = true,
1846 .token = p.tok_i,
1847 .extra = .{
1848 .offset = p.tok_i - prev_operator_token,
1849 },
1850 });
1851 }
1852 }
1853
1854 if (rel == .eq) {
1855 break;
15881856 }
15891857
15901858 const oper_token = p.nextToken();
......@@ -1614,7 +1882,7 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {
16141882 }
16151883 }
16161884
1617 const rhs = try p.parseExprPrecedence(info.prec + 1) orelse {
1885 const rhs = try p.parseExprPrecedence(info.prec, oper_token) orelse {
16181886 try p.warn(.expected_expr);
16191887 return node;
16201888 };
......@@ -1624,10 +1892,6 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {
16241892 .main_token = oper_token,
16251893 .data = .{ .node_and_node = .{ node, rhs } },
16261894 });
1627
1628 if (info.assoc == Assoc.none) {
1629 banned_prec = info.prec;
1630 }
16311895 }
16321896
16331897 return node;
lib/std/zig/TokenSmith.zig+1-1
......@@ -160,7 +160,7 @@ pub fn gen(smith: *Smith) TokenSmith {
160160 var no_period = false;
161161 var not_exponent = true;
162162 for (t.source_buf[t.source_len..][0..len], 0..) |*c, i| {
163 const invalid_period = no_period and c.* == '.' or i + 1 == len;
163 const invalid_period = (no_period and c.* == '.') or i + 1 == len;
164164 const is_exponent = c.* == '-' or c.* == '+';
165165 const invalid_exponent = not_exponent and is_exponent;
166166 const valid_exponent = !not_exponent and is_exponent;
lib/std/zig/llvm/BitcodeReader.zig+1-1
......@@ -404,7 +404,7 @@ fn readFixed(bc: *BitcodeReader, comptime T: type, bits: u7) !T {
404404 if (bc.bit_offset == 0) bc.bit_buffer = try bc.read32Bits();
405405 const chunk_len = @min(@as(u6, 32) - bc.bit_offset, remaining);
406406 const chunk_mask = @as(u32, std.math.maxInt(u32)) >> @intCast(32 - chunk_len);
407 result |= @as(T, @intCast(bc.bit_buffer >> bc.bit_offset & chunk_mask)) << @intCast(shift);
407 result |= @as(T, @intCast((bc.bit_buffer >> bc.bit_offset) & chunk_mask)) << @intCast(shift);
408408 shift += @intCast(chunk_len);
409409 remaining -= chunk_len;
410410 bc.bit_offset = @truncate(bc.bit_offset + chunk_len);
lib/std/zig/llvm/Builder.zig+26-26
......@@ -1076,7 +1076,7 @@ pub const Type = enum(u32) {
10761076 child: Type,
10771077
10781078 fn length(self: Array) u64 {
1079 return @as(u64, self.len_hi) << 32 | self.len_lo;
1079 return (@as(u64, self.len_hi) << 32) | self.len_lo;
10801080 }
10811081 };
10821082
......@@ -9520,7 +9520,7 @@ pub const Metadata = packed struct(u32) {
95209520 size_in_bits_hi: u32,
95219521
95229522 pub fn bitSize(self: BasicType) u64 {
9523 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
9523 return (@as(u64, self.size_in_bits_hi) << 32) | self.size_in_bits_lo;
95249524 }
95259525 };
95269526
......@@ -9537,10 +9537,10 @@ pub const Metadata = packed struct(u32) {
95379537 fields_tuple: Metadata.Optional,
95389538
95399539 pub fn bitSize(self: CompositeType) u64 {
9540 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
9540 return (@as(u64, self.size_in_bits_hi) << 32) | self.size_in_bits_lo;
95419541 }
95429542 pub fn bitAlign(self: CompositeType) u64 {
9543 return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo;
9543 return (@as(u64, self.align_in_bits_hi) << 32) | self.align_in_bits_lo;
95449544 }
95459545 };
95469546
......@@ -9558,13 +9558,13 @@ pub const Metadata = packed struct(u32) {
95589558 offset_in_bits_hi: u32,
95599559
95609560 pub fn bitSize(self: DerivedType) u64 {
9561 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
9561 return (@as(u64, self.size_in_bits_hi) << 32) | self.size_in_bits_lo;
95629562 }
95639563 pub fn bitAlign(self: DerivedType) u64 {
9564 return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo;
9564 return (@as(u64, self.align_in_bits_hi) << 32) | self.align_in_bits_lo;
95659565 }
95669566 pub fn bitOffset(self: DerivedType) u64 {
9567 return @as(u64, self.offset_in_bits_hi) << 32 | self.offset_in_bits_lo;
9567 return (@as(u64, self.offset_in_bits_hi) << 32) | self.offset_in_bits_lo;
95689568 }
95699569 };
95709570
......@@ -12457,7 +12457,7 @@ fn doubleConstAssumeCapacity(self: *Builder, val: f64) Constant {
1245712457 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .double) return false;
1245812458 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
1245912459 const rhs_extra = ctx.builder.constantExtraData(Constant.Double, rhs_data);
12460 return @as(u64, @bitCast(lhs_key)) == @as(u64, rhs_extra.hi) << 32 | rhs_extra.lo;
12460 return @as(u64, @bitCast(lhs_key)) == (@as(u64, rhs_extra.hi) << 32) | rhs_extra.lo;
1246112461 }
1246212462 };
1246312463 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
......@@ -12488,8 +12488,8 @@ fn fp128ConstAssumeCapacity(self: *Builder, val: f128) Constant {
1248812488 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .fp128) return false;
1248912489 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
1249012490 const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);
12491 return @as(u128, @bitCast(lhs_key)) == @as(u128, rhs_extra.hi_hi) << 96 |
12492 @as(u128, rhs_extra.hi_lo) << 64 | @as(u128, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo;
12491 return @as(u128, @bitCast(lhs_key)) == (@as(u128, rhs_extra.hi_hi) << 96) |
12492 (@as(u128, rhs_extra.hi_lo) << 64) | (@as(u128, rhs_extra.lo_hi) << 32) | rhs_extra.lo_lo;
1249312493 }
1249412494 };
1249512495 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
......@@ -12522,8 +12522,8 @@ fn x86_fp80ConstAssumeCapacity(self: *Builder, val: f80) Constant {
1252212522 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .x86_fp80) return false;
1252312523 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
1252412524 const rhs_extra = ctx.builder.constantExtraData(Constant.Fp80, rhs_data);
12525 return @as(u80, @bitCast(lhs_key)) == @as(u80, rhs_extra.hi) << 64 |
12526 @as(u80, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo;
12525 return @as(u80, @bitCast(lhs_key)) == (@as(u80, rhs_extra.hi) << 64) |
12526 (@as(u80, rhs_extra.lo_hi) << 32) | rhs_extra.lo_lo;
1252712527 }
1252812528 };
1252912529 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
......@@ -12555,8 +12555,8 @@ fn ppc_fp128ConstAssumeCapacity(self: *Builder, val: [2]f64) Constant {
1255512555 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .ppc_fp128) return false;
1255612556 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
1255712557 const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);
12558 return @as(u64, @bitCast(lhs_key[0])) == @as(u64, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo and
12559 @as(u64, @bitCast(lhs_key[1])) == @as(u64, rhs_extra.hi_hi) << 32 | rhs_extra.hi_lo;
12558 return @as(u64, @bitCast(lhs_key[0])) == (@as(u64, rhs_extra.lo_hi) << 32) | rhs_extra.lo_lo and
12559 @as(u64, @bitCast(lhs_key[1])) == (@as(u64, rhs_extra.hi_hi) << 32) | rhs_extra.hi_lo;
1256012560 }
1256112561 };
1256212562 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
......@@ -15225,18 +15225,18 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1522515225 for (limbs) |*limb| {
1522615226 const val = std.mem.littleToNative(i64, @bitCast(limb.*));
1522715227 limb.* = @bitCast(if (val >= 0)
15228 val << 1 | 0
15228 (val << 1) | 0
1522915229 else
15230 -%val << 1 | 1);
15230 (-%val << 1) | 1);
1523115231 }
1523215232 try constants_block.writeUnabbrev(5, record.items);
1523315233 continue;
1523415234 };
1523515235 try constants_block.writeAbbrev(ConstantsBlock.Integer{
1523615236 .value = @bitCast(if (val >= 0)
15237 val << 1 | 0
15237 (val << 1) | 0
1523815238 else
15239 -%val << 1 | 1),
15239 (-%val << 1) | 1),
1524015240 });
1524115241 },
1524215242 .half,
......@@ -15252,8 +15252,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1525215252 .x86_fp80 => {
1525315253 const extra = self.constantExtraData(Constant.Fp80, data);
1525415254 try constants_block.writeAbbrev(ConstantsBlock.Fp80{
15255 .hi = @as(u64, extra.hi) << 48 | @as(u64, extra.lo_hi) << 16 |
15256 extra.lo_lo >> 16,
15255 .hi = (@as(u64, extra.hi) << 48) | (@as(u64, extra.lo_hi) << 16) |
15256 (extra.lo_lo >> 16),
1525715257 .lo = @truncate(extra.lo_lo),
1525815258 });
1525915259 },
......@@ -15262,8 +15262,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1526215262 => {
1526315263 const extra = self.constantExtraData(Constant.Fp128, data);
1526415264 try constants_block.writeAbbrev(ConstantsBlock.Fp128{
15265 .lo = @as(u64, extra.lo_hi) << 32 | @as(u64, extra.lo_lo),
15266 .hi = @as(u64, extra.hi_hi) << 32 | @as(u64, extra.hi_lo),
15265 .lo = (@as(u64, extra.lo_hi) << 32) | @as(u64, extra.lo_lo),
15266 .hi = (@as(u64, extra.hi_hi) << 32) | @as(u64, extra.hi_lo),
1526715267 });
1526815268 },
1526915269 .array,
......@@ -15724,9 +15724,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1572415724 for (limbs) |*limb| {
1572515725 const val = std.mem.littleToNative(i64, @bitCast(limb.*));
1572615726 limb.* = @bitCast(if (val >= 0)
15727 val << 1 | 0
15727 (val << 1) | 0
1572815728 else
15729 -%val << 1 | 1);
15729 (-%val << 1) | 1);
1573015730 }
1573115731 try metadata_block.writeUnabbrev(@backingInt(MetadataBlock.Code.ENUMERATOR), record.items);
1573215732 continue;
......@@ -15736,9 +15736,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1573615736 .bit_width = extra.bit_width,
1573715737 .name = extra.name,
1573815738 .value = @bitCast(if (val >= 0)
15739 val << 1 | 0
15739 (val << 1) | 0
1574015740 else
15741 -%val << 1 | 1),
15741 (-%val << 1) | 1),
1574215742 }, metadata_adapter);
1574315743 },
1574415744 .subrange => {
lib/std/zig/llvm/bitcode_writer.zig+1-1
......@@ -102,7 +102,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
102102 // If input is larger than one VBR block can store
103103 // then store vbr_bits - 1 bits and a continue bit
104104 while (in_buffer > mask) {
105 try self.writeBits(in_buffer & mask | continue_bit, vbr_bits);
105 try self.writeBits((in_buffer & mask) | continue_bit, vbr_bits);
106106 in_buffer >>= @intCast(vbr_bits - 1);
107107 }
108108
lib/std/zig/parser_generated_oracle.zig+477-67
......@@ -42,13 +42,22 @@ const Def = enum {
4242 defAssignExpr,
4343 defSingleAssignExpr,
4444 defExpr,
45 defBoolOrExpr,
45 defOrElseExpr,
46 defCatchExpr,
47 defRecoveryNonmixingOp,
48 defControlOp,
49 defBoolExpr,
4650 defBoolAndExpr,
51 defBoolOrExpr,
4752 defCompareExpr,
48 defBitwiseExpr,
49 defBitShiftExpr,
53 defCompareOperand,
54 defBitOp,
55 defBitwiseNonmixingOp,
5056 defAdditionExpr,
57 defMulOrModExpr,
58 defModExpr,
5159 defMultiplyExpr,
60 defMultiplyNonmixingOp,
5261 defPrefixExpr,
5362 defPrimaryExpr,
5463 defIfExpr,
......@@ -103,14 +112,21 @@ const Def = enum {
103112 defAndOp,
104113 defCompareOp,
105114 defCompareOpTok,
106 defBitwiseOp,
107 defBitwiseOpTok,
115 defBitwiseAndOp,
116 defBitwiseAndOpTok,
117 defBitwiseOrOp,
118 defBitwiseOrOpTok,
119 defBitwiseXorOp,
120 defBitwiseXorOpTok,
121 defCatchOp,
122 defOrElseOp,
108123 defBitShiftOp,
109124 defBitShiftOpTok,
110125 defAdditionOp,
111126 defAdditionOpTok,
112127 defMultiplyOp,
113128 defMultiplyOpTok,
129 defModOp,
114130 defPrefixOp,
115131 defPrefixTypeOp,
116132 defPtrMods,
......@@ -290,7 +306,7 @@ const Def = enum {
290306const Parser = struct {
291307 source: []const u8,
292308 i: usize,
293 depths: [272]u8,
309 depths: [288]u8,
294310 pub fn parseRoot(p: *Parser) Error!bool {
295311 const def_index = @backingInt(Def.defRoot);
296312 if (p.depths[def_index] > max_depth) return error.MaxDepth;
......@@ -964,33 +980,44 @@ const Parser = struct {
964980 defer p.depths[def_index] -= 1;
965981 return blk_0: {
966982 const pos_0 = p.i;
967 if (try p.parseBoolOrExpr()) break :blk_0 true;
983 if (try p.parsePrefixExpr() and blk_2: {
984 const pos_2 = p.i;
985 if (try p.parseOrElseExpr()) break :blk_2 true;
986 p.i = pos_2;
987 if (try p.parseCatchExpr()) break :blk_2 true;
988 p.i = pos_2;
989 if (try p.parseBoolExpr()) break :blk_2 true;
990 p.i = pos_2;
991 break :blk_2 false;
992 }) break :blk_0 true;
968993 p.i = pos_0;
969994 break :blk_0 false;
970995 };
971996 }
972 pub fn parseBoolOrExpr(p: *Parser) Error!bool {
973 const def_index = @backingInt(Def.defBoolOrExpr);
997 pub fn parseOrElseExpr(p: *Parser) Error!bool {
998 const def_index = @backingInt(Def.defOrElseExpr);
974999 if (p.depths[def_index] > max_depth) return error.MaxDepth;
9751000 p.depths[def_index] += 1;
9761001 defer p.depths[def_index] -= 1;
9771002 return blk_0: {
9781003 const pos_0 = p.i;
979 if (try p.parseBoolAndExpr() and blk_1: {
1004 if (blk_1: {
1005 var match_1 = false;
9801006 var i_1: usize = 0;
9811007 while (blk_3: {
9821008 const pos_3 = p.i;
983 if (try p.parseOrOp() and try p.parseBoolAndExpr()) break :blk_3 true;
1009 if (try p.parseOrElseOp() and try p.parsePrefixExpr()) break :blk_3 true;
9841010 p.i = pos_3;
9851011 break :blk_3 false;
9861012 }) {
1013 match_1 = true;
9871014 if (i_1 > max_depth) return error.MaxDepth;
9881015 i_1 += 1;
9891016 }
990 break :blk_1 true;
1017 break :blk_1 match_1;
9911018 } and blk_1: {
9921019 const pos_1 = p.i;
993 const match_1 = try p.parseOrOp();
1020 const match_1 = try p.parseRecoveryNonmixingOp();
9941021 p.i = pos_1;
9951022 break :blk_1 !match_1;
9961023 }) break :blk_0 true;
......@@ -998,28 +1025,30 @@ const Parser = struct {
9981025 break :blk_0 false;
9991026 };
10001027 }
1001 pub fn parseBoolAndExpr(p: *Parser) Error!bool {
1002 const def_index = @backingInt(Def.defBoolAndExpr);
1028 pub fn parseCatchExpr(p: *Parser) Error!bool {
1029 const def_index = @backingInt(Def.defCatchExpr);
10031030 if (p.depths[def_index] > max_depth) return error.MaxDepth;
10041031 p.depths[def_index] += 1;
10051032 defer p.depths[def_index] -= 1;
10061033 return blk_0: {
10071034 const pos_0 = p.i;
1008 if (try p.parseCompareExpr() and blk_1: {
1035 if (blk_1: {
1036 var match_1 = false;
10091037 var i_1: usize = 0;
10101038 while (blk_3: {
10111039 const pos_3 = p.i;
1012 if (try p.parseAndOp() and try p.parseCompareExpr()) break :blk_3 true;
1040 if (try p.parseCatchOp() and try p.parsePrefixExpr()) break :blk_3 true;
10131041 p.i = pos_3;
10141042 break :blk_3 false;
10151043 }) {
1044 match_1 = true;
10161045 if (i_1 > max_depth) return error.MaxDepth;
10171046 i_1 += 1;
10181047 }
1019 break :blk_1 true;
1048 break :blk_1 match_1;
10201049 } and blk_1: {
10211050 const pos_1 = p.i;
1022 const match_1 = try p.parseAndOp();
1051 const match_1 = try p.parseRecoveryNonmixingOp();
10231052 p.i = pos_1;
10241053 break :blk_1 !match_1;
10251054 }) break :blk_0 true;
......@@ -1027,21 +1056,90 @@ const Parser = struct {
10271056 break :blk_0 false;
10281057 };
10291058 }
1030 pub fn parseCompareExpr(p: *Parser) Error!bool {
1031 const def_index = @backingInt(Def.defCompareExpr);
1059 pub fn parseRecoveryNonmixingOp(p: *Parser) Error!bool {
1060 const def_index = @backingInt(Def.defRecoveryNonmixingOp);
10321061 if (p.depths[def_index] > max_depth) return error.MaxDepth;
10331062 p.depths[def_index] += 1;
10341063 defer p.depths[def_index] -= 1;
10351064 return blk_0: {
10361065 const pos_0 = p.i;
1037 if (try p.parseBitwiseExpr() and (blk_3: {
1038 const pos_3 = p.i;
1039 if (try p.parseCompareOp() and try p.parseBitwiseExpr()) break :blk_3 true;
1040 p.i = pos_3;
1041 break :blk_3 false;
1042 } or true) and blk_1: {
1066 if (try p.parseControlOp()) break :blk_0 true;
1067 p.i = pos_0;
1068 if (try p.parseCompareOp()) break :blk_0 true;
1069 p.i = pos_0;
1070 if (try p.parseBitwiseNonmixingOp()) break :blk_0 true;
1071 p.i = pos_0;
1072 break :blk_0 false;
1073 };
1074 }
1075 pub fn parseControlOp(p: *Parser) Error!bool {
1076 const def_index = @backingInt(Def.defControlOp);
1077 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1078 p.depths[def_index] += 1;
1079 defer p.depths[def_index] -= 1;
1080 return blk_0: {
1081 const pos_0 = p.i;
1082 if (try p.parseOrElseOp()) break :blk_0 true;
1083 p.i = pos_0;
1084 if (try p.parseCatchOp()) break :blk_0 true;
1085 p.i = pos_0;
1086 if (try p.parseAndOp()) break :blk_0 true;
1087 p.i = pos_0;
1088 if (try p.parseOrOp()) break :blk_0 true;
1089 p.i = pos_0;
1090 break :blk_0 false;
1091 };
1092 }
1093 pub fn parseBoolExpr(p: *Parser) Error!bool {
1094 const def_index = @backingInt(Def.defBoolExpr);
1095 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1096 p.depths[def_index] += 1;
1097 defer p.depths[def_index] -= 1;
1098 return blk_0: {
1099 const pos_0 = p.i;
1100 if (try p.parseCompareExpr() and blk_2: {
1101 const pos_2 = p.i;
1102 if (try p.parseBoolAndExpr()) break :blk_2 true;
1103 p.i = pos_2;
1104 if (try p.parseBoolOrExpr()) break :blk_2 true;
1105 p.i = pos_2;
1106 if (blk_3: {
1107 const pos_3 = p.i;
1108 const match_3 = try p.parseControlOp();
1109 p.i = pos_3;
1110 break :blk_3 !match_3;
1111 }) break :blk_2 true;
1112 p.i = pos_2;
1113 break :blk_2 false;
1114 }) break :blk_0 true;
1115 p.i = pos_0;
1116 break :blk_0 false;
1117 };
1118 }
1119 pub fn parseBoolAndExpr(p: *Parser) Error!bool {
1120 const def_index = @backingInt(Def.defBoolAndExpr);
1121 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1122 p.depths[def_index] += 1;
1123 defer p.depths[def_index] -= 1;
1124 return blk_0: {
1125 const pos_0 = p.i;
1126 if (blk_1: {
1127 var match_1 = false;
1128 var i_1: usize = 0;
1129 while (blk_3: {
1130 const pos_3 = p.i;
1131 if (try p.parseAndOp() and try p.parsePrefixExpr() and try p.parseCompareExpr()) break :blk_3 true;
1132 p.i = pos_3;
1133 break :blk_3 false;
1134 }) {
1135 match_1 = true;
1136 if (i_1 > max_depth) return error.MaxDepth;
1137 i_1 += 1;
1138 }
1139 break :blk_1 match_1;
1140 } and blk_1: {
10431141 const pos_1 = p.i;
1044 const match_1 = try p.parseCompareOp();
1142 const match_1 = try p.parseControlOp();
10451143 p.i = pos_1;
10461144 break :blk_1 !match_1;
10471145 }) break :blk_0 true;
......@@ -1049,28 +1147,30 @@ const Parser = struct {
10491147 break :blk_0 false;
10501148 };
10511149 }
1052 pub fn parseBitwiseExpr(p: *Parser) Error!bool {
1053 const def_index = @backingInt(Def.defBitwiseExpr);
1150 pub fn parseBoolOrExpr(p: *Parser) Error!bool {
1151 const def_index = @backingInt(Def.defBoolOrExpr);
10541152 if (p.depths[def_index] > max_depth) return error.MaxDepth;
10551153 p.depths[def_index] += 1;
10561154 defer p.depths[def_index] -= 1;
10571155 return blk_0: {
10581156 const pos_0 = p.i;
1059 if (try p.parseBitShiftExpr() and blk_1: {
1157 if (blk_1: {
1158 var match_1 = false;
10601159 var i_1: usize = 0;
10611160 while (blk_3: {
10621161 const pos_3 = p.i;
1063 if (try p.parseBitwiseOp() and try p.parseBitShiftExpr()) break :blk_3 true;
1162 if (try p.parseOrOp() and try p.parsePrefixExpr() and try p.parseCompareExpr()) break :blk_3 true;
10641163 p.i = pos_3;
10651164 break :blk_3 false;
10661165 }) {
1166 match_1 = true;
10671167 if (i_1 > max_depth) return error.MaxDepth;
10681168 i_1 += 1;
10691169 }
1070 break :blk_1 true;
1170 break :blk_1 match_1;
10711171 } and blk_1: {
10721172 const pos_1 = p.i;
1073 const match_1 = try p.parseBitwiseOp();
1173 const match_1 = try p.parseControlOp();
10741174 p.i = pos_1;
10751175 break :blk_1 !match_1;
10761176 }) break :blk_0 true;
......@@ -1078,32 +1178,153 @@ const Parser = struct {
10781178 break :blk_0 false;
10791179 };
10801180 }
1081 pub fn parseBitShiftExpr(p: *Parser) Error!bool {
1082 const def_index = @backingInt(Def.defBitShiftExpr);
1181 pub fn parseCompareExpr(p: *Parser) Error!bool {
1182 const def_index = @backingInt(Def.defCompareExpr);
10831183 if (p.depths[def_index] > max_depth) return error.MaxDepth;
10841184 p.depths[def_index] += 1;
10851185 defer p.depths[def_index] -= 1;
10861186 return blk_0: {
10871187 const pos_0 = p.i;
1088 if (try p.parseAdditionExpr() and blk_1: {
1188 if (try p.parseCompareOperand() and (blk_3: {
1189 const pos_3 = p.i;
1190 if (try p.parseCompareOp() and try p.parsePrefixExpr() and try p.parseCompareOperand()) break :blk_3 true;
1191 p.i = pos_3;
1192 break :blk_3 false;
1193 } or true) and blk_1: {
1194 const pos_1 = p.i;
1195 const match_1 = blk_3: {
1196 const pos_3 = p.i;
1197 if (try p.parseCompareOp()) break :blk_3 true;
1198 p.i = pos_3;
1199 if (try p.parseOrElseOp()) break :blk_3 true;
1200 p.i = pos_3;
1201 if (try p.parseCatchOp()) break :blk_3 true;
1202 p.i = pos_3;
1203 break :blk_3 false;
1204 };
1205 p.i = pos_1;
1206 break :blk_1 !match_1;
1207 }) break :blk_0 true;
1208 p.i = pos_0;
1209 break :blk_0 false;
1210 };
1211 }
1212 pub fn parseCompareOperand(p: *Parser) Error!bool {
1213 const def_index = @backingInt(Def.defCompareOperand);
1214 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1215 p.depths[def_index] += 1;
1216 defer p.depths[def_index] -= 1;
1217 return blk_0: {
1218 const pos_0 = p.i;
1219 if (blk_1: {
1220 var match_1 = false;
10891221 var i_1: usize = 0;
10901222 while (blk_3: {
10911223 const pos_3 = p.i;
1092 if (try p.parseBitShiftOp() and try p.parseAdditionExpr()) break :blk_3 true;
1224 if (try p.parseBitwiseOrOp() and try p.parsePrefixExpr()) break :blk_3 true;
10931225 p.i = pos_3;
10941226 break :blk_3 false;
10951227 }) {
1228 match_1 = true;
10961229 if (i_1 > max_depth) return error.MaxDepth;
10971230 i_1 += 1;
10981231 }
1099 break :blk_1 true;
1232 break :blk_1 match_1;
1233 } and blk_1: {
1234 const pos_1 = p.i;
1235 const match_1 = try p.parseBitwiseNonmixingOp();
1236 p.i = pos_1;
1237 break :blk_1 !match_1;
1238 }) break :blk_0 true;
1239 p.i = pos_0;
1240 if (blk_1: {
1241 var match_1 = false;
1242 var i_1: usize = 0;
1243 while (blk_3: {
1244 const pos_3 = p.i;
1245 if (try p.parseBitwiseAndOp() and try p.parsePrefixExpr()) break :blk_3 true;
1246 p.i = pos_3;
1247 break :blk_3 false;
1248 }) {
1249 match_1 = true;
1250 if (i_1 > max_depth) return error.MaxDepth;
1251 i_1 += 1;
1252 }
1253 break :blk_1 match_1;
1254 } and blk_1: {
1255 const pos_1 = p.i;
1256 const match_1 = try p.parseBitwiseNonmixingOp();
1257 p.i = pos_1;
1258 break :blk_1 !match_1;
1259 }) break :blk_0 true;
1260 p.i = pos_0;
1261 if (blk_1: {
1262 var match_1 = false;
1263 var i_1: usize = 0;
1264 while (blk_3: {
1265 const pos_3 = p.i;
1266 if (try p.parseBitwiseXorOp() and try p.parsePrefixExpr()) break :blk_3 true;
1267 p.i = pos_3;
1268 break :blk_3 false;
1269 }) {
1270 match_1 = true;
1271 if (i_1 > max_depth) return error.MaxDepth;
1272 i_1 += 1;
1273 }
1274 break :blk_1 match_1;
11001275 } and blk_1: {
11011276 const pos_1 = p.i;
1102 const match_1 = try p.parseBitShiftOp();
1277 const match_1 = try p.parseBitwiseNonmixingOp();
11031278 p.i = pos_1;
11041279 break :blk_1 !match_1;
11051280 }) break :blk_0 true;
11061281 p.i = pos_0;
1282 if (try p.parseBitShiftOp() and try p.parsePrefixExpr() and blk_1: {
1283 const pos_1 = p.i;
1284 const match_1 = try p.parseBitwiseNonmixingOp();
1285 p.i = pos_1;
1286 break :blk_1 !match_1;
1287 }) break :blk_0 true;
1288 p.i = pos_0;
1289 if (blk_1: {
1290 const pos_1 = p.i;
1291 const match_1 = try p.parseBitOp();
1292 p.i = pos_1;
1293 break :blk_1 !match_1;
1294 } and try p.parseAdditionExpr()) break :blk_0 true;
1295 p.i = pos_0;
1296 break :blk_0 false;
1297 };
1298 }
1299 pub fn parseBitOp(p: *Parser) Error!bool {
1300 const def_index = @backingInt(Def.defBitOp);
1301 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1302 p.depths[def_index] += 1;
1303 defer p.depths[def_index] -= 1;
1304 return blk_0: {
1305 const pos_0 = p.i;
1306 if (try p.parseBitwiseOrOp()) break :blk_0 true;
1307 p.i = pos_0;
1308 if (try p.parseBitwiseAndOp()) break :blk_0 true;
1309 p.i = pos_0;
1310 if (try p.parseBitwiseXorOp()) break :blk_0 true;
1311 p.i = pos_0;
1312 if (try p.parseBitShiftOp()) break :blk_0 true;
1313 p.i = pos_0;
1314 break :blk_0 false;
1315 };
1316 }
1317 pub fn parseBitwiseNonmixingOp(p: *Parser) Error!bool {
1318 const def_index = @backingInt(Def.defBitwiseNonmixingOp);
1319 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1320 p.depths[def_index] += 1;
1321 defer p.depths[def_index] -= 1;
1322 return blk_0: {
1323 const pos_0 = p.i;
1324 if (try p.parseMultiplyNonmixingOp()) break :blk_0 true;
1325 p.i = pos_0;
1326 if (try p.parseAdditionOp()) break :blk_0 true;
1327 p.i = pos_0;
11071328 break :blk_0 false;
11081329 };
11091330 }
......@@ -1114,11 +1335,11 @@ const Parser = struct {
11141335 defer p.depths[def_index] -= 1;
11151336 return blk_0: {
11161337 const pos_0 = p.i;
1117 if (try p.parseMultiplyExpr() and blk_1: {
1338 if (try p.parseMulOrModExpr() and blk_1: {
11181339 var i_1: usize = 0;
11191340 while (blk_3: {
11201341 const pos_3 = p.i;
1121 if (try p.parseAdditionOp() and try p.parseMultiplyExpr()) break :blk_3 true;
1342 if (try p.parseAdditionOp() and try p.parsePrefixExpr() and try p.parseMulOrModExpr()) break :blk_3 true;
11221343 p.i = pos_3;
11231344 break :blk_3 false;
11241345 }) {
......@@ -1128,7 +1349,54 @@ const Parser = struct {
11281349 break :blk_1 true;
11291350 } and blk_1: {
11301351 const pos_1 = p.i;
1131 const match_1 = try p.parseAdditionOp();
1352 const match_1 = blk_3: {
1353 const pos_3 = p.i;
1354 if (try p.parseAdditionOp()) break :blk_3 true;
1355 p.i = pos_3;
1356 if (try p.parseBitOp()) break :blk_3 true;
1357 p.i = pos_3;
1358 if (try p.parseOrElseOp()) break :blk_3 true;
1359 p.i = pos_3;
1360 if (try p.parseCatchOp()) break :blk_3 true;
1361 p.i = pos_3;
1362 break :blk_3 false;
1363 };
1364 p.i = pos_1;
1365 break :blk_1 !match_1;
1366 }) break :blk_0 true;
1367 p.i = pos_0;
1368 break :blk_0 false;
1369 };
1370 }
1371 pub fn parseMulOrModExpr(p: *Parser) Error!bool {
1372 const def_index = @backingInt(Def.defMulOrModExpr);
1373 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1374 p.depths[def_index] += 1;
1375 defer p.depths[def_index] -= 1;
1376 return blk_0: {
1377 const pos_0 = p.i;
1378 if (try p.parseModExpr()) break :blk_0 true;
1379 p.i = pos_0;
1380 if (blk_1: {
1381 const pos_1 = p.i;
1382 const match_1 = try p.parseModOp();
1383 p.i = pos_1;
1384 break :blk_1 !match_1;
1385 } and try p.parseMultiplyExpr()) break :blk_0 true;
1386 p.i = pos_0;
1387 break :blk_0 false;
1388 };
1389 }
1390 pub fn parseModExpr(p: *Parser) Error!bool {
1391 const def_index = @backingInt(Def.defModExpr);
1392 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1393 p.depths[def_index] += 1;
1394 defer p.depths[def_index] -= 1;
1395 return blk_0: {
1396 const pos_0 = p.i;
1397 if (try p.parseModOp() and try p.parsePrefixExpr() and blk_1: {
1398 const pos_1 = p.i;
1399 const match_1 = try p.parseMultiplyNonmixingOp();
11321400 p.i = pos_1;
11331401 break :blk_1 !match_1;
11341402 }) break :blk_0 true;
......@@ -1143,7 +1411,7 @@ const Parser = struct {
11431411 defer p.depths[def_index] -= 1;
11441412 return blk_0: {
11451413 const pos_0 = p.i;
1146 if (try p.parsePrefixExpr() and blk_1: {
1414 if (blk_1: {
11471415 var i_1: usize = 0;
11481416 while (blk_3: {
11491417 const pos_3 = p.i;
......@@ -1157,7 +1425,7 @@ const Parser = struct {
11571425 break :blk_1 true;
11581426 } and blk_1: {
11591427 const pos_1 = p.i;
1160 const match_1 = try p.parseMultiplyOp();
1428 const match_1 = try p.parseMultiplyNonmixingOp();
11611429 p.i = pos_1;
11621430 break :blk_1 !match_1;
11631431 }) break :blk_0 true;
......@@ -1165,6 +1433,26 @@ const Parser = struct {
11651433 break :blk_0 false;
11661434 };
11671435 }
1436 pub fn parseMultiplyNonmixingOp(p: *Parser) Error!bool {
1437 const def_index = @backingInt(Def.defMultiplyNonmixingOp);
1438 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1439 p.depths[def_index] += 1;
1440 defer p.depths[def_index] -= 1;
1441 return blk_0: {
1442 const pos_0 = p.i;
1443 if (try p.parseMultiplyOp()) break :blk_0 true;
1444 p.i = pos_0;
1445 if (try p.parseModOp()) break :blk_0 true;
1446 p.i = pos_0;
1447 if (try p.parseBitOp()) break :blk_0 true;
1448 p.i = pos_0;
1449 if (try p.parseOrElseOp()) break :blk_0 true;
1450 p.i = pos_0;
1451 if (try p.parseCatchOp()) break :blk_0 true;
1452 p.i = pos_0;
1453 break :blk_0 false;
1454 };
1455 }
11681456 pub fn parsePrefixExpr(p: *Parser) Error!bool {
11691457 const def_index = @backingInt(Def.defPrefixExpr);
11701458 if (p.depths[def_index] > max_depth) return error.MaxDepth;
......@@ -2259,70 +2547,170 @@ const Parser = struct {
22592547 break :blk_0 false;
22602548 };
22612549 }
2262 pub fn parseBitwiseOp(p: *Parser) Error!bool {
2263 const def_index = @backingInt(Def.defBitwiseOp);
2550 pub fn parseBitwiseAndOp(p: *Parser) Error!bool {
2551 const def_index = @backingInt(Def.defBitwiseAndOp);
22642552 if (p.depths[def_index] > max_depth) return error.MaxDepth;
22652553 p.depths[def_index] += 1;
22662554 defer p.depths[def_index] -= 1;
22672555 return blk_0: {
22682556 const pos_0 = p.i;
2269 if (try p.parsepre_op_white() and try p.parseBitwiseOpTok() and try p.parsepost_op_white()) break :blk_0 true;
2557 if (try p.parsepre_op_white() and try p.parseBitwiseAndOpTok() and try p.parsepost_op_white()) break :blk_0 true;
22702558 p.i = pos_0;
22712559 if (blk_1: {
22722560 const pos_1 = p.i;
22732561 const match_1 = try p.parsepre_op_white();
22742562 p.i = pos_1;
22752563 break :blk_1 !match_1;
2276 } and try p.parseBitwiseOpTok() and blk_1: {
2564 } and try p.parseBitwiseAndOpTok() and blk_1: {
22772565 const pos_1 = p.i;
22782566 const match_1 = try p.parsepost_op_white();
22792567 p.i = pos_1;
22802568 break :blk_1 !match_1;
22812569 }) break :blk_0 true;
22822570 p.i = pos_0;
2283 if (try p.parsepre_op_white() and try p.parseKEYWORD_catch() and try p.parsepost_op_white() and (try p.parsePayload() or true)) break :blk_0 true;
2571 break :blk_0 false;
2572 };
2573 }
2574 pub fn parseBitwiseAndOpTok(p: *Parser) Error!bool {
2575 const def_index = @backingInt(Def.defBitwiseAndOpTok);
2576 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2577 p.depths[def_index] += 1;
2578 defer p.depths[def_index] -= 1;
2579 return blk_0: {
2580 const pos_0 = p.i;
2581 if (try p.parseAMPERSAND() and blk_1: {
2582 const pos_1 = p.i;
2583 const match_1 = (p.i < p.source.len and switch (p.source[p.i]) {
2584 '&'...'&',
2585 => blk_2: {
2586 p.i += 1;
2587 break :blk_2 true;
2588 },
2589 else => false,
2590 });
2591 p.i = pos_1;
2592 break :blk_1 !match_1;
2593 }) break :blk_0 true;
2594 p.i = pos_0;
2595 break :blk_0 false;
2596 };
2597 }
2598 pub fn parseBitwiseOrOp(p: *Parser) Error!bool {
2599 const def_index = @backingInt(Def.defBitwiseOrOp);
2600 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2601 p.depths[def_index] += 1;
2602 defer p.depths[def_index] -= 1;
2603 return blk_0: {
2604 const pos_0 = p.i;
2605 if (try p.parsepre_op_white() and try p.parseBitwiseOrOpTok() and try p.parsepost_op_white()) break :blk_0 true;
22842606 p.i = pos_0;
22852607 if (blk_1: {
22862608 const pos_1 = p.i;
22872609 const match_1 = try p.parsepre_op_white();
22882610 p.i = pos_1;
22892611 break :blk_1 !match_1;
2290 } and try p.parseKEYWORD_catch() and blk_1: {
2612 } and try p.parseBitwiseOrOpTok() and blk_1: {
22912613 const pos_1 = p.i;
22922614 const match_1 = try p.parsepost_op_white();
22932615 p.i = pos_1;
22942616 break :blk_1 !match_1;
2295 } and (try p.parsePayload() or true)) break :blk_0 true;
2617 }) break :blk_0 true;
22962618 p.i = pos_0;
22972619 break :blk_0 false;
22982620 };
22992621 }
2300 pub fn parseBitwiseOpTok(p: *Parser) Error!bool {
2301 const def_index = @backingInt(Def.defBitwiseOpTok);
2622 pub fn parseBitwiseOrOpTok(p: *Parser) Error!bool {
2623 const def_index = @backingInt(Def.defBitwiseOrOpTok);
23022624 if (p.depths[def_index] > max_depth) return error.MaxDepth;
23032625 p.depths[def_index] += 1;
23042626 defer p.depths[def_index] -= 1;
23052627 return blk_0: {
23062628 const pos_0 = p.i;
2307 if (try p.parseAMPERSAND() and blk_1: {
2629 if (try p.parsePIPE()) break :blk_0 true;
2630 p.i = pos_0;
2631 break :blk_0 false;
2632 };
2633 }
2634 pub fn parseBitwiseXorOp(p: *Parser) Error!bool {
2635 const def_index = @backingInt(Def.defBitwiseXorOp);
2636 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2637 p.depths[def_index] += 1;
2638 defer p.depths[def_index] -= 1;
2639 return blk_0: {
2640 const pos_0 = p.i;
2641 if (try p.parsepre_op_white() and try p.parseBitwiseXorOpTok() and try p.parsepost_op_white()) break :blk_0 true;
2642 p.i = pos_0;
2643 if (blk_1: {
23082644 const pos_1 = p.i;
2309 const match_1 = (p.i < p.source.len and switch (p.source[p.i]) {
2310 '&'...'&',
2311 => blk_2: {
2312 p.i += 1;
2313 break :blk_2 true;
2314 },
2315 else => false,
2316 });
2645 const match_1 = try p.parsepre_op_white();
2646 p.i = pos_1;
2647 break :blk_1 !match_1;
2648 } and try p.parseBitwiseXorOpTok() and blk_1: {
2649 const pos_1 = p.i;
2650 const match_1 = try p.parsepost_op_white();
23172651 p.i = pos_1;
23182652 break :blk_1 !match_1;
23192653 }) break :blk_0 true;
23202654 p.i = pos_0;
2655 break :blk_0 false;
2656 };
2657 }
2658 pub fn parseBitwiseXorOpTok(p: *Parser) Error!bool {
2659 const def_index = @backingInt(Def.defBitwiseXorOpTok);
2660 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2661 p.depths[def_index] += 1;
2662 defer p.depths[def_index] -= 1;
2663 return blk_0: {
2664 const pos_0 = p.i;
23212665 if (try p.parseCARET()) break :blk_0 true;
23222666 p.i = pos_0;
2323 if (try p.parsePIPE()) break :blk_0 true;
2667 break :blk_0 false;
2668 };
2669 }
2670 pub fn parseCatchOp(p: *Parser) Error!bool {
2671 const def_index = @backingInt(Def.defCatchOp);
2672 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2673 p.depths[def_index] += 1;
2674 defer p.depths[def_index] -= 1;
2675 return blk_0: {
2676 const pos_0 = p.i;
2677 if (try p.parsepre_op_white() and try p.parseKEYWORD_catch() and try p.parsepost_op_white() and (try p.parsePayload() or true)) break :blk_0 true;
23242678 p.i = pos_0;
2325 if (try p.parseKEYWORD_orelse()) break :blk_0 true;
2679 if (blk_1: {
2680 const pos_1 = p.i;
2681 const match_1 = try p.parsepre_op_white();
2682 p.i = pos_1;
2683 break :blk_1 !match_1;
2684 } and try p.parseKEYWORD_catch() and blk_1: {
2685 const pos_1 = p.i;
2686 const match_1 = try p.parsepost_op_white();
2687 p.i = pos_1;
2688 break :blk_1 !match_1;
2689 } and (try p.parsePayload() or true)) break :blk_0 true;
2690 p.i = pos_0;
2691 break :blk_0 false;
2692 };
2693 }
2694 pub fn parseOrElseOp(p: *Parser) Error!bool {
2695 const def_index = @backingInt(Def.defOrElseOp);
2696 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2697 p.depths[def_index] += 1;
2698 defer p.depths[def_index] -= 1;
2699 return blk_0: {
2700 const pos_0 = p.i;
2701 if (try p.parsepre_op_white() and try p.parseKEYWORD_orelse() and try p.parsepost_op_white()) break :blk_0 true;
2702 p.i = pos_0;
2703 if (blk_1: {
2704 const pos_1 = p.i;
2705 const match_1 = try p.parsepre_op_white();
2706 p.i = pos_1;
2707 break :blk_1 !match_1;
2708 } and try p.parseKEYWORD_orelse() and blk_1: {
2709 const pos_1 = p.i;
2710 const match_1 = try p.parsepost_op_white();
2711 p.i = pos_1;
2712 break :blk_1 !match_1;
2713 }) break :blk_0 true;
23262714 p.i = pos_0;
23272715 break :blk_0 false;
23282716 };
......@@ -2452,8 +2840,6 @@ const Parser = struct {
24522840 p.i = pos_0;
24532841 if (try p.parseSLASH()) break :blk_0 true;
24542842 p.i = pos_0;
2455 if (try p.parsePERCENT()) break :blk_0 true;
2456 p.i = pos_0;
24572843 if (try p.parseASTERISKPERCENT()) break :blk_0 true;
24582844 p.i = pos_0;
24592845 if (try p.parseASTERISKPIPE()) break :blk_0 true;
......@@ -2461,6 +2847,30 @@ const Parser = struct {
24612847 break :blk_0 false;
24622848 };
24632849 }
2850 pub fn parseModOp(p: *Parser) Error!bool {
2851 const def_index = @backingInt(Def.defModOp);
2852 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2853 p.depths[def_index] += 1;
2854 defer p.depths[def_index] -= 1;
2855 return blk_0: {
2856 const pos_0 = p.i;
2857 if (try p.parsepre_op_white() and try p.parsePERCENT() and try p.parsepost_op_white()) break :blk_0 true;
2858 p.i = pos_0;
2859 if (blk_1: {
2860 const pos_1 = p.i;
2861 const match_1 = try p.parsepre_op_white();
2862 p.i = pos_1;
2863 break :blk_1 !match_1;
2864 } and try p.parsePERCENT() and blk_1: {
2865 const pos_1 = p.i;
2866 const match_1 = try p.parsepost_op_white();
2867 p.i = pos_1;
2868 break :blk_1 !match_1;
2869 }) break :blk_0 true;
2870 p.i = pos_0;
2871 break :blk_0 false;
2872 };
2873 }
24642874 pub fn parsePrefixOp(p: *Parser) Error!bool {
24652875 const def_index = @backingInt(Def.defPrefixOp);
24662876 if (p.depths[def_index] > max_depth) return error.MaxDepth;
lib/std/zig/parser_test.zig+42-6
......@@ -3046,19 +3046,14 @@ test "zig fmt: precedence" {
30463046 \\ !(a{});
30473047 \\ a + b{};
30483048 \\ (a + b){};
3049 \\ a << b + c;
30503049 \\ (a << b) + c;
3051 \\ a & b << c;
30523050 \\ (a & b) << c;
3053 \\ a ^ b & c;
30543051 \\ (a ^ b) & c;
3055 \\ a | b ^ c;
30563052 \\ (a | b) ^ c;
30573053 \\ a == b | c;
30583054 \\ (a == b) | c;
30593055 \\ a and b == c;
30603056 \\ (a and b) == c;
3061 \\ a or b and c;
30623057 \\ (a or b) and c;
30633058 \\ (a or b) and c;
30643059 \\ a == b and c == d;
......@@ -3067,6 +3062,47 @@ test "zig fmt: precedence" {
30673062 );
30683063}
30693064
3065test "zig fmt: ambiguous precedence" {
3066 try testError(
3067 \\test "ambiguous precedence" {
3068 \\ a & b << c;
3069 \\ a << b + c;
3070 \\ a << b | c;
3071 \\ a ^ b & c;
3072 \\ a | b ^ c;
3073 \\ a or b and c;
3074 \\ a orelse b catch c;
3075 \\ a % b % c;
3076 \\}
3077 \\
3078 , &[_]Error{
3079 .ambiguous_operator_precedence,
3080 .previous_ambiguous_operator,
3081 .hint_operator_precedence_right,
3082 .ambiguous_operator_precedence,
3083 .previous_ambiguous_operator,
3084 .hint_operator_precedence_right,
3085 .ambiguous_operator_precedence,
3086 .previous_ambiguous_operator,
3087 .hint_operator_precedence_left,
3088 .ambiguous_operator_precedence,
3089 .previous_ambiguous_operator,
3090 .hint_operator_precedence_left,
3091 .ambiguous_operator_precedence,
3092 .previous_ambiguous_operator,
3093 .hint_operator_precedence_left,
3094 .ambiguous_operator_precedence,
3095 .previous_ambiguous_operator,
3096 .hint_operator_precedence_right,
3097 .ambiguous_operator_precedence,
3098 .previous_ambiguous_operator,
3099 .hint_operator_precedence_left,
3100 .illegal_chained_operators,
3101 .previous_ambiguous_operator,
3102 .hint_operator_precedence_left,
3103 });
3104}
3105
30703106test "zig fmt: prefix operators" {
30713107 try testCanonical(
30723108 \\test "prefix operators" {
......@@ -7205,7 +7241,7 @@ test "recovery: missing comma" {
72057241 \\ 2 => {}
72067242 \\ 3 => {}
72077243 \\ else => {
7208 \\ foo & bar +;
7244 \\ foo & bar &;
72097245 \\ }
72107246 \\ }
72117247 \\}
lib/std/zig/system.zig+5-5
......@@ -266,8 +266,8 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
266266 // Minor * 1(0),000 summed has been convention since FreeBSD 2.2 (1997)
267267 // e.g. 492101 = 4.11-STABLE = 4.(9+2)
268268 const major = value / 100_000;
269 const minor1 = value % 100_000 / 10_000; // usually 0 since 5.1
270 const minor2 = value % 10_000 / 1_000; // 0 before 5.1, minor version since
269 const minor1 = (value % 100_000) / 10_000; // usually 0 since 5.1
270 const minor2 = (value % 10_000) / 1_000; // 0 before 5.1, minor version since
271271 const patch = value % 1_000;
272272 os.version_range.semver.min = .{ .major = major, .minor = minor1 + minor2, .patch = patch };
273273 os.version_range.semver.max = os.version_range.semver.min;
......@@ -280,8 +280,8 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
280280 // r = 0 (*)
281281 // p = patchlevel
282282 const major = value / 100_000_000;
283 const minor = value % 100_000_000 / 1_000_000;
284 const patch = value % 10_000 / 100;
283 const minor = (value % 100_000_000) / 1_000_000;
284 const patch = (value % 10_000) / 100;
285285 os.version_range.semver.min = .{ .major = major, .minor = minor, .patch = patch };
286286 os.version_range.semver.max = os.version_range.semver.min;
287287 },
......@@ -292,7 +292,7 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
292292 // m = minor; odd-numbers indicate current dev branch
293293 // p = patch
294294 const major = value / 100_000;
295 const minor = value % 100_000 / 100;
295 const minor = (value % 100_000) / 100;
296296 const patch = value % 100;
297297 os.version_range.semver.min = .{ .major = major, .minor = minor, .patch = patch };
298298 os.version_range.semver.max = os.version_range.semver.min;
lib/std/zig/system/windows.zig+2-2
......@@ -25,7 +25,7 @@ pub fn detectRuntimeVersion() WindowsVersion {
2525 // `---` `` ``--> Sub-version (Starting from Windows 10 onwards)
2626 // \ `--> Service pack (Always zero in the constants defined)
2727 // `--> OS version (Major & minor)
28 const os_ver: u16 = @as(u16, @intCast(version_info.dwMajorVersion & 0xff)) << 8 |
28 const os_ver: u16 = (@as(u16, @intCast(version_info.dwMajorVersion & 0xff)) << 8) |
2929 @as(u16, @intCast(version_info.dwMinorVersion & 0xff));
3030 const sp_ver: u8 = 0;
3131 const sub_ver: u8 = if (os_ver >= 0x0A00) subver: {
......@@ -40,7 +40,7 @@ pub fn detectRuntimeVersion() WindowsVersion {
4040 break :subver @as(u8, @truncate(last_idx));
4141 } else 0;
4242
43 const version: u32 = @as(u32, os_ver) << 16 | @as(u16, sp_ver) << 8 | sub_ver;
43 const version: u32 = (@as(u32, os_ver) << 16) | (@as(u16, sp_ver) << 8) | sub_ver;
4444
4545 return @as(WindowsVersion, @fromBackingInt(@intCast(version)));
4646}
src/Air.zig+1-1
......@@ -1505,7 +1505,7 @@ pub const ShuffleTwoMask = enum(u32) {
15051505 return @fromBackingInt(@intCast(idx << 1));
15061506 }
15071507 pub fn bElem(idx: u32) ShuffleTwoMask {
1508 return @fromBackingInt(@intCast(idx << 1 | 1));
1508 return @fromBackingInt(@intCast((idx << 1) | 1));
15091509 }
15101510 pub const Unwrapped = union(enum) {
15111511 /// The resulting element is this index into the first runtime vector.
src/Compilation.zig+2-2
......@@ -1990,7 +1990,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
19901990 .path = try options.dirs.global_cache.join(arena, &.{zir_sub_dir}),
19911991 };
19921992
1993 const std_mod = options.std_mod orelse Module.create(arena, .{
1993 const std_mod = options.std_mod orelse (Module.create(arena, .{
19941994 .paths = .{
19951995 .root = try .fromRoot(arena, options.dirs, .zig_lib, "std"),
19961996 .root_src_path = "std.zig",
......@@ -2015,7 +2015,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
20152015 error.StackProtectorUnsupportedByTarget => unreachable,
20162016 error.StackProtectorUnavailableWithoutLibC => unreachable,
20172017 error.PatchableFunctionEntryUnsupportedByBackend => unreachable,
2018 };
2018 });
20192019
20202020 const zcu = try arena.create(Zcu);
20212021 zcu.* = .{
src/IncrementalDebugServer.zig+2-2
......@@ -243,7 +243,7 @@ fn handleCommand(zcu: *Zcu, w: *Io.Writer, cmd_str: []const u8, arg_str: []const
243243 for (zcu.incremental_debug_state.types.keys()) |type_ip_index| {
244244 const ty: Type = .fromInterned(type_ip_index);
245245 const ty_name = ty.containerTypeName(ip).fqn.toSlice(ip);
246 const success = switch (@as(u2, @intFromBool(anchor_start)) << 1 | @intFromBool(anchor_end)) {
246 const success = switch ((@as(u2, @intFromBool(anchor_start)) << 1) | @intFromBool(anchor_end)) {
247247 0b00 => std.mem.find(u8, ty_name, query) != null,
248248 0b01 => std.mem.endsWith(u8, ty_name, query),
249249 0b10 => std.mem.startsWith(u8, ty_name, query),
......@@ -264,7 +264,7 @@ fn handleCommand(zcu: *Zcu, w: *Io.Writer, cmd_str: []const u8, arg_str: []const
264264 for (zcu.incremental_debug_state.navs.keys()) |nav_index| {
265265 const nav = ip.getNav(nav_index);
266266 const nav_fqn = nav.fqn.toSlice(ip);
267 const success = switch (@as(u2, @intFromBool(anchor_start)) << 1 | @intFromBool(anchor_end)) {
267 const success = switch ((@as(u2, @intFromBool(anchor_start)) << 1) | @intFromBool(anchor_end)) {
268268 0b00 => std.mem.find(u8, nav_fqn, query) != null,
269269 0b01 => std.mem.endsWith(u8, nav_fqn, query),
270270 0b10 => std.mem.startsWith(u8, nav_fqn, query),
src/InternPool.zig+18-18
......@@ -215,7 +215,7 @@ pub const TrackedInst = extern struct {
215215 };
216216 pub fn unwrap(tracked_inst_index: TrackedInst.Index, ip: *const InternPool) Unwrapped {
217217 return .{
218 .tid = @fromBackingInt(@intCast(@backingInt(tracked_inst_index) >> ip.tid_shift_32 & ip.getTidMask())),
218 .tid = @fromBackingInt(@intCast((@backingInt(tracked_inst_index) >> ip.tid_shift_32) & ip.getTidMask())),
219219 .index = @backingInt(tracked_inst_index) & ip.getIndexMask(u32),
220220 };
221221 }
......@@ -517,7 +517,7 @@ pub const ComptimeUnit = extern struct {
517517 };
518518 fn unwrap(id: Id, ip: *const InternPool) Unwrapped {
519519 return .{
520 .tid = @fromBackingInt(@intCast(@backingInt(id) >> ip.tid_shift_32 & ip.getTidMask())),
520 .tid = @fromBackingInt(@intCast((@backingInt(id) >> ip.tid_shift_32) & ip.getTidMask())),
521521 .index = @backingInt(id) & ip.getIndexMask(u31),
522522 };
523523 }
......@@ -655,7 +655,7 @@ pub const Nav = struct {
655655 };
656656 fn unwrap(nav_index: Nav.Index, ip: *const InternPool) Unwrapped {
657657 return .{
658 .tid = @fromBackingInt(@intCast(@backingInt(nav_index) >> ip.tid_shift_30 & ip.getTidMask())),
658 .tid = @fromBackingInt(@intCast((@backingInt(nav_index) >> ip.tid_shift_30) & ip.getTidMask())),
659659 .index = @backingInt(nav_index) & ip.getIndexMask(u30),
660660 };
661661 }
......@@ -1627,7 +1627,7 @@ pub const MapIndex = enum(u32) {
16271627 };
16281628 fn unwrap(map_index: MapIndex, ip: *const InternPool) Unwrapped {
16291629 return .{
1630 .tid = @fromBackingInt(@intCast(@backingInt(map_index) >> ip.tid_shift_32 & ip.getTidMask())),
1630 .tid = @fromBackingInt(@intCast((@backingInt(map_index) >> ip.tid_shift_32) & ip.getTidMask())),
16311631 .index = @backingInt(map_index) & ip.getIndexMask(u32),
16321632 };
16331633 }
......@@ -1648,14 +1648,14 @@ pub const NamespaceIndex = enum(u32) {
16481648 assert(unwrapped.bucket_index <= ip.getIndexMask(u32) >> Local.namespaces_bucket_width);
16491649 assert(unwrapped.index <= Local.namespaces_bucket_mask);
16501650 return @fromBackingInt(@intCast(@shlExact(@as(u32, @backingInt(unwrapped.tid)), ip.tid_shift_32) |
1651 unwrapped.bucket_index << Local.namespaces_bucket_width |
1651 (unwrapped.bucket_index << Local.namespaces_bucket_width) |
16521652 unwrapped.index));
16531653 }
16541654 };
16551655 fn unwrap(namespace_index: NamespaceIndex, ip: *const InternPool) Unwrapped {
16561656 const index = @backingInt(namespace_index) & ip.getIndexMask(u32);
16571657 return .{
1658 .tid = @fromBackingInt(@intCast(@backingInt(namespace_index) >> ip.tid_shift_32 & ip.getTidMask())),
1658 .tid = @fromBackingInt(@intCast((@backingInt(namespace_index) >> ip.tid_shift_32) & ip.getTidMask())),
16591659 .bucket_index = index >> Local.namespaces_bucket_width,
16601660 .index = index & Local.namespaces_bucket_mask,
16611661 };
......@@ -1696,7 +1696,7 @@ pub const FileIndex = enum(u32) {
16961696 };
16971697 pub fn unwrap(file_index: FileIndex, ip: *const InternPool) Unwrapped {
16981698 return .{
1699 .tid = @fromBackingInt(@intCast(@backingInt(file_index) >> ip.tid_shift_32 & ip.getTidMask())),
1699 .tid = @fromBackingInt(@intCast((@backingInt(file_index) >> ip.tid_shift_32) & ip.getTidMask())),
17001700 .index = @backingInt(file_index) & ip.getIndexMask(u32),
17011701 };
17021702 }
......@@ -1755,7 +1755,7 @@ pub const String = enum(u32) {
17551755 };
17561756 fn unwrap(string: String, ip: *const InternPool) Unwrapped {
17571757 return .{
1758 .tid = @fromBackingInt(@intCast(@backingInt(string) >> ip.tid_shift_32 & ip.getTidMask())),
1758 .tid = @fromBackingInt(@intCast((@backingInt(string) >> ip.tid_shift_32) & ip.getTidMask())),
17591759 .index = @backingInt(string) & ip.getIndexMask(u32),
17601760 };
17611761 }
......@@ -4199,7 +4199,7 @@ pub const Index = enum(u32) {
41994199 };
42004200 pub fn unwrap(index: Index, ip: *const InternPool) Unwrapped {
42014201 return .{
4202 .tid = @fromBackingInt(@intCast(@backingInt(index) >> ip.tid_shift_30 & ip.getTidMask())),
4202 .tid = @fromBackingInt(@intCast((@backingInt(index) >> ip.tid_shift_30) & ip.getTidMask())),
42034203 .index = @backingInt(index) & ip.getIndexMask(u30),
42044204 };
42054205 }
......@@ -6062,7 +6062,7 @@ pub const PtrNav = struct {
60626062 };
60636063 }
60646064 fn byteOffset(data: @This()) u64 {
6065 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
6065 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
60666066 }
60676067};
60686068
......@@ -6080,7 +6080,7 @@ pub const PtrUav = struct {
60806080 };
60816081 }
60826082 fn byteOffset(data: @This()) u64 {
6083 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
6083 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
60846084 }
60856085};
60866086
......@@ -6101,7 +6101,7 @@ pub const PtrUavAligned = struct {
61016101 };
61026102 }
61036103 fn byteOffset(data: @This()) u64 {
6104 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
6104 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
61056105 }
61066106};
61076107
......@@ -6119,7 +6119,7 @@ pub const PtrComptimeAlloc = struct {
61196119 };
61206120 }
61216121 fn byteOffset(data: @This()) u64 {
6122 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
6122 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
61236123 }
61246124};
61256125
......@@ -6137,7 +6137,7 @@ pub const PtrComptimeField = struct {
61376137 };
61386138 }
61396139 fn byteOffset(data: @This()) u64 {
6140 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
6140 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
61416141 }
61426142};
61436143
......@@ -6155,7 +6155,7 @@ pub const PtrBase = struct {
61556155 };
61566156 }
61576157 fn byteOffset(data: @This()) u64 {
6158 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
6158 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
61596159 }
61606160};
61616161
......@@ -6175,7 +6175,7 @@ pub const PtrBaseIndex = struct {
61756175 };
61766176 }
61776177 fn byteOffset(data: @This()) u64 {
6178 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
6178 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
61796179 }
61806180};
61816181
......@@ -6191,7 +6191,7 @@ pub const PtrInt = struct {
61916191 };
61926192 }
61936193 fn byteOffset(data: @This()) u64 {
6194 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;
6194 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
61956195 }
61966196};
61976197
......@@ -12634,7 +12634,7 @@ const PackedCallingConvention = packed struct(u18) {
1263412634 std.lang.CallingConvention.SpirvFragmentOptions => .{
1263512635 .tag = tag,
1263612636 .incoming_stack_alignment = .none,
12637 .extra = @as(u4, @backingInt(pl.depth_assumption)) << 1 | @intFromBool(pl.pixel_centered_integer),
12637 .extra = (@as(u4, @backingInt(pl.depth_assumption)) << 1) | @intFromBool(pl.pixel_centered_integer),
1263812638 },
1263912639 std.lang.CallingConvention.SpirvMeshOptions => .{
1264012640 .tag = tag,
src/Sema.zig+2-2
......@@ -29956,10 +29956,10 @@ fn coerceVarArgParam(
2995629956 if (!uncasted_ty.validateExtern(.param_ty, zcu)) break :int inst;
2995729957 const target = zcu.getTarget();
2995829958 const uncasted_info = uncasted_ty.intInfo(zcu);
29959 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {
29959 if (uncasted_info.bits <= (target.cTypeBitSize(switch (uncasted_info.signedness) {
2996029960 .signed => .int,
2996129961 .unsigned => .uint,
29962 }) orelse break :int inst) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
29962 }) orelse break :int inst)) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
2996329963 .signed => .c_int,
2996429964 .unsigned => .c_uint,
2996529965 }, inst, inst_src);
src/codegen/aarch64/Assemble.zig+2-2
......@@ -164,7 +164,7 @@ const matchers = matchers: {
164164 return @call(.auto, encode, args);
165165 } else if (pattern_token[0] == '<') {
166166 const symbol_name = comptime pattern_token[1 .. std.mem.findScalarPos(u8, pattern_token, 1, '|') orelse
167 pattern_token.len - 1];
167 (pattern_token.len - 1)];
168168 const symbol = @field(Symbol, symbol_name);
169169 const symbol_ptr = &@field(symbols, symbol_name);
170170 const symbol_value = zonCast(SymbolSpec, @field(instruction.symbols, symbol_name), .{}).parse(source_token) orelse {
......@@ -453,7 +453,7 @@ const SymbolSpec = union(enum) {
453453 } else {
454454 const Repr = std.math.FloatRepr(f16);
455455 const repr: Repr = @bitCast(fimm);
456 if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 != 0 or switch (repr.exponent) {
456 if ((repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5)) != 0 or switch (repr.exponent) {
457457 .denormal, .infinite => true,
458458 else => std.math.cast(i3, repr.exponent.unbias() - 1) == null,
459459 }) {
src/codegen/aarch64/Disassemble.zig+4-4
......@@ -31,7 +31,7 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
3131 .unallocated => break :unallocated,
3232 .pc_relative_addressing => |pc_relative_addressing| {
3333 const group = pc_relative_addressing.group;
34 const imm = (@as(i33, group.immhi) << 2 | @as(i33, group.immlo) << 0) + @as(i33, switch (group.op) {
34 const imm = ((@as(i33, group.immhi) << 2) | (@as(i33, group.immlo) << 0)) + @as(i33, switch (group.op) {
3535 .adr => aarch64.encoding.Instruction.size,
3636 .adrp => 0,
3737 });
......@@ -311,7 +311,7 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
311311 .hint => |hint| return writer.print("{f}{s}#0x{x}", .{
312312 fmtCase(.hint, dis.case),
313313 dis.mnemonic_operands_separator,
314 @as(u7, hint.CRm) << 3 | @as(u7, hint.op2) << 0,
314 (@as(u7, hint.CRm) << 3) | (@as(u7, hint.op2) << 0),
315315 }),
316316 else => |decoded| return writer.print("{f}", .{fmtCase(decoded, dis.case)}),
317317 },
......@@ -365,8 +365,8 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
365365 dis.mnemonic_operands_separator,
366366 group.Rt.decode(.{}).general(@fromBackingInt(@intCast(group.b5))).fmtCase(dis.case),
367367 dis.operands_separator,
368 @as(u6, group.b5) << 5 |
369 @as(u6, group.b40) << 0,
368 (@as(u6, group.b5) << 5) |
369 (@as(u6, group.b40) << 0),
370370 dis.operands_separator,
371371 @as(u8, if (imm < 0) '-' else '+'),
372372 @abs(imm) << 2,
src/codegen/aarch64/Mir.zig+3-3
......@@ -208,7 +208,7 @@ fn emitReloc(
208208 };
209209 try atom.addReloc(gpa, .{
210210 .r_offset = offset,
211 .r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(r_type),
211 .r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(r_type),
212212 .r_addend = @bitCast(addend),
213213 }, zo);
214214 } else if (lf.cast(.macho)) |mf| {
......@@ -265,7 +265,7 @@ fn emitReloc(
265265 };
266266 try atom.addReloc(gpa, .{
267267 .r_offset = offset,
268 .r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(r_type),
268 .r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(r_type),
269269 .r_addend = @bitCast(addend),
270270 }, zo);
271271 } else if (lf.cast(.macho)) |mf| {
......@@ -328,7 +328,7 @@ fn emitReloc(
328328 };
329329 try atom.addReloc(gpa, .{
330330 .r_offset = offset,
331 .r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(r_type),
331 .r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(r_type),
332332 .r_addend = @bitCast(addend),
333333 }, zo);
334334 } else if (lf.cast(.macho)) |mf| {
src/codegen/aarch64/Select.zig+4-4
......@@ -8099,7 +8099,7 @@ fn movImmediate(isel: *Select, dst_reg: Register, src_imm: u64) !void {
80998099 .{ .immediate = .{
81008100 .N = @fromBackingInt(@intCast(elem_width >> 6)),
81018101 .immr = hi + mid_masked,
8102 .imms = ((((lo + hi) & smask) | mid_masked) - 1) | -%@as(u6, @truncate(elem_width)) << 1,
8102 .imms = ((((lo + hi) & smask) | mid_masked) - 1) | (-%@as(u6, @truncate(elem_width)) << 1),
81038103 } },
81048104 ));
81058105 }
......@@ -10831,7 +10831,7 @@ pub const Value = struct {
1083110831 if (feat_fp16) {
1083210832 const Repr = std.math.FloatRepr(f16);
1083310833 const repr: Repr = @bitCast(imm);
10834 if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 == 0 and switch (repr.exponent) {
10834 if (repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5) == 0 and switch (repr.exponent) {
1083510835 .denormal, .infinite => false,
1083610836 else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,
1083710837 }) break :free try isel.emit(.fmov(mat.ra.h(), .{ .immediate = imm }));
......@@ -10855,7 +10855,7 @@ pub const Value = struct {
1085510855 } };
1085610856 const Repr = std.math.FloatRepr(f32);
1085710857 const repr: Repr = @bitCast(imm);
10858 if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 == 0 and switch (repr.exponent) {
10858 if (repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5) == 0 and switch (repr.exponent) {
1085910859 .denormal, .infinite => false,
1086010860 else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,
1086110861 }) break :free try isel.emit(.fmov(mat.ra.s(), .{ .immediate = @floatCast(imm) }));
......@@ -10878,7 +10878,7 @@ pub const Value = struct {
1087810878 } };
1087910879 const Repr = std.math.FloatRepr(f64);
1088010880 const repr: Repr = @bitCast(imm);
10881 if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 == 0 and switch (repr.exponent) {
10881 if (repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5) == 0 and switch (repr.exponent) {
1088210882 .denormal, .infinite => false,
1088310883 else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,
1088410884 }) break :free try isel.emit(.fmov(mat.ra.d(), .{ .immediate = @floatCast(imm) }));
src/codegen/aarch64/encoding.zig+19-19
......@@ -11886,9 +11886,9 @@ pub const Instruction = packed union {
1188611886 .cmode = switch (arrangement) {
1188711887 else => unreachable,
1188811888 .@"4h", .@"8h" => @as(u3, 0b100) |
11889 @as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,
11889 (@as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
1189011890 .@"2s", .@"4s" => @as(u3, 0b000) |
11891 @as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,
11891 (@as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
1189211892 },
1189311893 .imm3 = @intCast(shifted_immediate.immediate >> 5),
1189411894 .Q = arrangement.size(),
......@@ -12384,7 +12384,7 @@ pub const Instruction = packed union {
1238412384 .dup = .{
1238512385 .Rd = d.alias.encode(.{ .V = true }),
1238612386 .Rn = n.alias.encode(.{ .V = true }),
12387 .imm5 = @shlExact(@as(u5, n.format.element.index) << 1 | @as(u5, 0b1), @backingInt(elem_size)),
12387 .imm5 = @shlExact((@as(u5, n.format.element.index) << 1) | @as(u5, 0b1), @backingInt(elem_size)),
1238812388 },
1238912389 } } };
1239012390 },
......@@ -12400,7 +12400,7 @@ pub const Instruction = packed union {
1240012400 .Rd = d.alias.encode(.{ .V = true }),
1240112401 .Rn = n.alias.encode(.{ .V = true }),
1240212402 .imm4 = .element,
12403 .imm5 = @shlExact(@as(u5, element.index) << 1 | @as(u5, 0b1), @backingInt(elem_size)),
12403 .imm5 = @shlExact((@as(u5, element.index) << 1) | @as(u5, 0b1), @backingInt(elem_size)),
1240412404 .Q = arrangement.size(),
1240512405 },
1240612406 } } };
......@@ -14195,7 +14195,7 @@ pub const Instruction = packed union {
1419514195 .Rd = d.alias.encode(.{ .V = true }),
1419614196 .Rn = n.alias.encode(.{ .V = true }),
1419714197 .imm4 = .{ .element = element.index << @intCast(@backingInt(elem_size)) },
14198 .imm5 = (@as(u5, d.format.element.index) << 1 | @as(u5, 0b1) << 0) << @backingInt(elem_size),
14198 .imm5 = ((@as(u5, d.format.element.index) << 1) | (@as(u5, 0b1) << 0)) << @backingInt(elem_size),
1419914199 .op = .element,
1420014200 },
1420114201 } } };
......@@ -14211,7 +14211,7 @@ pub const Instruction = packed union {
1421114211 .Rd = d.alias.encode(.{ .V = true }),
1421214212 .Rn = n.alias.encode(.{}),
1421314213 .imm4 = .{ .general = .general },
14214 .imm5 = (@as(u5, d.format.element.index) << 1 | @as(u5, 0b1) << 0) << @backingInt(elem_size),
14214 .imm5 = ((@as(u5, d.format.element.index) << 1) | (@as(u5, 0b1) << 0)) << @backingInt(elem_size),
1421514215 .op = .general,
1421614216 },
1421714217 } } };
......@@ -15072,16 +15072,16 @@ pub const Instruction = packed union {
1507215072 .lsl => |amount| switch (arrangement) {
1507315073 else => unreachable,
1507415074 .@"8b", .@"16b" => @as(u4, 0b1110) |
15075 @as(u4, @as(u0, @intCast(@shrExact(amount, 3)))) << 1,
15075 (@as(u4, @as(u0, @intCast(@shrExact(amount, 3)))) << 1),
1507615076 .@"4h", .@"8h" => @as(u4, 0b1000) |
15077 @as(u4, @as(u1, @intCast(@shrExact(amount, 3)))) << 1,
15077 (@as(u4, @as(u1, @intCast(@shrExact(amount, 3)))) << 1),
1507815078 .@"2s", .@"4s" => @as(u4, 0b0000) |
15079 @as(u4, @as(u2, @intCast(@shrExact(amount, 3)))) << 1,
15079 (@as(u4, @as(u2, @intCast(@shrExact(amount, 3)))) << 1),
1508015080 },
1508115081 .msl => |amount| switch (arrangement) {
1508215082 else => unreachable,
1508315083 .@"2s", .@"4s" => @as(u4, 0b1100) |
15084 @as(u4, @as(u1, @intCast(@shrExact(amount, 3) - 1))) << 0,
15084 (@as(u4, @as(u1, @intCast(@shrExact(amount, 3) - 1))) << 0),
1508515085 },
1508615086 .replicate => switch (arrangement) {
1508715087 else => unreachable,
......@@ -15345,9 +15345,9 @@ pub const Instruction = packed union {
1534515345 .cmode = switch (arrangement) {
1534615346 else => unreachable,
1534715347 .@"4h", .@"8h" => @as(u3, 0b100) |
15348 @as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,
15348 (@as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
1534915349 .@"2s", .@"4s" => @as(u3, 0b000) |
15350 @as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,
15350 (@as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
1535115351 },
1535215352 .imm3 = @intCast(shifted_immediate.immediate >> 5),
1535315353 .Q = arrangement.size(),
......@@ -15660,9 +15660,9 @@ pub const Instruction = packed union {
1566015660 .Rn = n.alias.encode(.{ .V = true }),
1566115661 .imm5 = switch (vs) {
1566215662 else => unreachable,
15663 .byte => @as(u5, @as(u4, @intCast(n.format.element.index))) << 1 | @as(u5, 0b1) << 0,
15664 .half => @as(u5, @as(u3, @intCast(n.format.element.index))) << 2 | @as(u5, 0b10) << 0,
15665 .single => @as(u5, @as(u2, @intCast(n.format.element.index))) << 3 | @as(u5, 0b100) << 0,
15663 .byte => (@as(u5, @as(u4, @intCast(n.format.element.index))) << 1) | (@as(u5, 0b1) << 0),
15664 .half => (@as(u5, @as(u3, @intCast(n.format.element.index))) << 2) | (@as(u5, 0b10) << 0),
15665 .single => (@as(u5, @as(u2, @intCast(n.format.element.index))) << 3) | (@as(u5, 0b100) << 0),
1566615666 },
1566715667 .Q = sf,
1566815668 },
......@@ -16492,10 +16492,10 @@ pub const Instruction = packed union {
1649216492 .Rn = n.alias.encode(.{ .V = true }),
1649316493 .imm5 = switch (vs) {
1649416494 else => unreachable,
16495 .byte => @as(u5, @as(u4, @intCast(n.format.element.index))) << 1 | @as(u5, 0b1) << 0,
16496 .half => @as(u5, @as(u3, @intCast(n.format.element.index))) << 2 | @as(u5, 0b10) << 0,
16497 .single => @as(u5, @as(u2, @intCast(n.format.element.index))) << 3 | @as(u5, 0b100) << 0,
16498 .double => @as(u5, @as(u1, @intCast(n.format.element.index))) << 4 | @as(u5, 0b1000) << 0,
16495 .byte => (@as(u5, @as(u4, @intCast(n.format.element.index))) << 1) | (@as(u5, 0b1) << 0),
16496 .half => (@as(u5, @as(u3, @intCast(n.format.element.index))) << 2) | (@as(u5, 0b10) << 0),
16497 .single => (@as(u5, @as(u2, @intCast(n.format.element.index))) << 3) | (@as(u5, 0b100) << 0),
16498 .double => (@as(u5, @as(u1, @intCast(n.format.element.index))) << 4) | (@as(u5, 0b1000) << 0),
1649916499 },
1650016500 .Q = sf,
1650116501 },
src/codegen/loongarch/Mir.zig+1-1
......@@ -181,7 +181,7 @@ fn emitReloc(
181181 const atom = zo.symbol(@backingInt(atom_index)).atom(ef).?;
182182 try atom.addReloc(zcu.gpa, .{
183183 .r_offset = offset,
184 .r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(reloc_type),
184 .r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(reloc_type),
185185 .r_addend = @bitCast(addend),
186186 }, zo);
187187 } else unreachable;
src/codegen/riscv64/CodeGen.zig+2-2
......@@ -1764,7 +1764,7 @@ fn finishAir(
17641764) !void {
17651765 const tomb_bits = func.liveness.getTombBits(inst);
17661766 for (0.., operands) |op_index, op| {
1767 if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;
1767 if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
17681768 if (func.reused_operands.isSet(op_index)) continue;
17691769 try func.processDeath(op.toIndexAllowNone() orelse continue);
17701770 }
......@@ -6272,7 +6272,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void {
62726272 "";
62736273
62746274 op.* = switch (args.items[
6275 arg_map.get(op_str["%[".len .. mod_index orelse op_str.len - "]".len]) orelse
6275 arg_map.get(op_str["%[".len .. mod_index orelse (op_str.len - "]".len)]) orelse
62766276 return func.fail("no matching constraint: '{s}'", .{op_str})
62776277 ]) {
62786278 .lea_symbol => |sym_off| if (mem.eql(u8, modifier, "plt")) blk: {
src/codegen/riscv64/encoding.zig+2-2
......@@ -582,8 +582,8 @@ pub const Instruction = union(Lir.Format) {
582582
583583 .opcode = opcode,
584584 .funct3 = @backingInt(amo.width),
585 .funct7 = @as(u7, amo.funct5) << 2 |
586 @as(u7, @intFromBool(ops[3].barrier == .rl)) << 1 |
585 .funct7 = (@as(u7, amo.funct5) << 2) |
586 (@as(u7, @intFromBool(ops[3].barrier == .rl)) << 1) |
587587 @as(u7, @intFromBool(ops[4].barrier == .aq)),
588588 },
589589 else => unreachable,
src/codegen/sparc64/CodeGen.zig+2-2
......@@ -3475,11 +3475,11 @@ fn finishAirBookkeeping(self: *Self) void {
34753475fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Air.Liveness.bpi - 1]Air.Inst.Ref) void {
34763476 const tomb_bits = self.liveness.getTombBits(inst);
34773477 for (0.., operands) |op_index, op| {
3478 if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;
3478 if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
34793479 if (self.reused_operands.isSet(op_index)) continue;
34803480 self.processDeath(op.toIndexAllowNone() orelse continue);
34813481 }
3482 if (tomb_bits & 1 << (Air.Liveness.bpi - 1) == 0) {
3482 if (tomb_bits & (1 << (Air.Liveness.bpi - 1)) == 0) {
34833483 log.debug("%{d} => {}", .{ inst, result });
34843484 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
34853485 branch.inst_table.putAssumeCapacityNoClobber(inst, result);
src/codegen/spirv/CodeGen.zig+1-1
......@@ -1191,7 +1191,7 @@ fn constInt(cg: *CodeGen, ty: Type, value: anytype) !Id {
11911191 const truncated_value = if (backing_bits == 64)
11921192 value64
11931193 else
1194 value64 & (@as(u64, 1) << @intCast(backing_bits)) - 1;
1194 value64 & ((@as(u64, 1) << @intCast(backing_bits)) - 1);
11951195
11961196 break :blk switch (backing_bits) {
11971197 1...32 => .{ .uint32 = @truncate(truncated_value) },
src/codegen/x86_64/CodeGen.zig+17-17
......@@ -173255,7 +173255,7 @@ fn finishAir(
173255173255) !void {
173256173256 const tomb_bits = self.liveness.getTombBits(inst);
173257173257 for (0.., operands) |op_index, op| {
173258 if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;
173258 if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
173259173259 if (self.reused_operands.isSet(op_index)) continue;
173260173260 try self.processDeath(op.toIndexAllowNone() orelse continue, .{});
173261173261 }
......@@ -176321,7 +176321,7 @@ fn lowerSwitchBr(
176321176321 const unsigned_condition_ty = try cg.pt.intType(.unsigned, cg.intInfo(condition_ty).?.bits);
176322176322
176323176323 const ExpectedContents = extern struct {
176324 liveness_deaths: [1 << 8 | 1]Air.Inst.Index,
176324 liveness_deaths: [(1 << 8) | 1]Air.Inst.Index,
176325176325 bigint_limbs: [std.math.big.int.calcTwosCompLimbCount(1 << 10)]std.math.big.Limb,
176326176326 relocs: [1 << 6]Mir.Inst.Index,
176327176327 };
......@@ -177310,7 +177310,7 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
177310177310 else
177311177311 "";
177312177312 op.* = switch (args[
177313 arg_map.get(op_str["%[".len .. colon orelse op_str.len - "]".len]) orelse
177313 arg_map.get(op_str["%[".len .. colon orelse (op_str.len - "]".len)]) orelse
177314177314 return self.fail("no matching constraint: '{s}'", .{op_str})
177315177315 ]) {
177316177316 .immediate => |imm| if (std.mem.eql(u8, modifier, "") or
......@@ -177454,7 +177454,7 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
177454177454 else
177455177455 "";
177456177456 break :disp switch (args[
177457 arg_map.get(op_str["%[".len .. colon orelse open - "]".len]) orelse
177457 arg_map.get(op_str["%[".len .. colon orelse (open - "]".len)]) orelse
177458177458 return self.fail("no matching constraint: '{s}'", .{op_str})
177459177459 ]) {
177460177460 .immediate => |imm| if (std.mem.eql(u8, modifier, "") or
......@@ -179566,7 +179566,7 @@ fn atomicOp(
179566179566 };
179567179567 defer if (mem_lock) |lock| self.register_manager.unlockReg(lock);
179568179568
179569 const use_sse = rmw_op orelse .Xchg != .Xchg and val_ty.isRuntimeFloat();
179569 const use_sse = (rmw_op orelse .Xchg) != .Xchg and val_ty.isRuntimeFloat();
179570179570 const strat: enum { lock, loop, libcall } = if (use_sse) .loop else switch (rmw_op orelse .Xchg) {
179571179571 .Xchg,
179572179572 .Add,
......@@ -179626,7 +179626,7 @@ fn atomicOp(
179626179626
179627179627 try self.asmRegisterMemory(.{ ._, .mov }, registerAlias(.rax, val_abi_size), ptr_mem);
179628179628 const loop: Mir.Inst.Index = @intCast(self.mir_instructions.len);
179629 if (!use_sse and rmw_op orelse .Xchg != .Xchg) {
179629 if (!use_sse and (rmw_op orelse .Xchg) != .Xchg) {
179630179630 try self.genSetReg(tmp_reg, val_ty, .{ .register = .rax }, .{});
179631179631 }
179632179632 if (rmw_op) |op| if (use_sse) {
......@@ -188852,7 +188852,7 @@ const Temp = struct {
188852188852 for (0.., op_refs, op_temps) |op_index, op_ref, op_temp| {
188853188853 if (op_temp.index == temp.index) continue;
188854188854 if (op_temp.tracking(cg).short != .dead) try op_temp.die(cg);
188855 if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;
188855 if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
188856188856 if (cg.reused_operands.isSet(op_index)) continue;
188857188857 try cg.processDeath(op_ref.toIndexAllowNone() orelse continue, .{});
188858188858 }
......@@ -188914,7 +188914,7 @@ const Temp = struct {
188914188914 }
188915188915 for (0.., op_refs, op_temps) |op_index, op_ref, op_temp| {
188916188916 if (op_temp.index != temp.index) continue;
188917 if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;
188917 if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
188918188918 if (cg.reused_operands.isSet(op_index)) continue;
188919188919 try cg.processDeath(op_ref.toIndexAllowNone() orelse continue, .{});
188920188920 }
......@@ -190115,9 +190115,9 @@ const Select = struct {
190115190115 (@as(u64, std.math.maxInt(u64)) >> @intCast(res_scalar_info.bits - scalar_info.bits))),
190116190116 .@"0x1p63_mem" => switch (res_scalar_info.bits) {
190117190117 else => unreachable,
190118 16 => @as(i64, @as(i16, @bitCast(@as(f16, 0x1p63)))) << 64 - 16,
190119 32 => @as(i64, @as(i32, @bitCast(@as(f32, 0x1p63)))) << 64 - 32,
190120 64 => @as(i64, @as(i64, @bitCast(@as(f64, 0x1p63)))) << 64 - 64,
190118 16 => @as(i64, @as(i16, @bitCast(@as(f16, 0x1p63)))) << (64 - 16),
190119 32 => @as(i64, @as(i32, @bitCast(@as(f32, 0x1p63)))) << (64 - 32),
190120 64 => @as(i64, @as(i64, @bitCast(@as(f64, 0x1p63)))) << (64 - 64),
190121190121 },
190122190122 };
190123190123 const shift: u6 = @intCast(64 - res_scalar_info.bits);
......@@ -191516,8 +191516,8 @@ const Select = struct {
191516191516 @as(SignedImm, @intCast(s.cg.nonBoolScalarBitSize(op.flags.base.ref.typeOf(s)))),
191517191517 .log2_src0_elem_size => @intCast(std.math.log2(Select.Operand.Ref.src0.typeOf(s).indexableElem(s.cg.pt.zcu).abiSize(s.cg.pt.zcu))),
191518191518 .elem_mask => @as(u8, std.math.maxInt(u8)) >> @intCast(
191519 8 - ((s.cg.unalignedSize(op.flags.base.ref.typeOf(s)) - 1) %
191520 @divExact(op.flags.base.size.bitSize(s.cg.target), 8) + 1 >>
191519 8 - (((s.cg.unalignedSize(op.flags.base.ref.typeOf(s)) - 1) %
191520 @divExact(op.flags.base.size.bitSize(s.cg.target), 8) + 1) >>
191521191521 op.flags.index.scale.toLog2()),
191522191522 ),
191523191523 inline .smin, .smax, .umax, .smin_shr_src1, .smax_shr_src1, .umax_shr_src1 => |adjust| switch (op.flags.base.size) {
......@@ -191546,7 +191546,7 @@ const Select = struct {
191546191546 },
191547191547 .repeat => switch (SignedImm) {
191548191548 else => unreachable,
191549 i64 => return @as(i64, op.imm) << 32 | @as(u32, @bitCast(op.imm)),
191549 i64 => return (@as(i64, op.imm) << 32) | @as(u32, @bitCast(op.imm)),
191550191550 },
191551191551 };
191552191552 const rhs = op.flags.adjust.rhs.toLog2();
......@@ -191557,10 +191557,10 @@ const Select = struct {
191557191557 break :op_res op_res[0];
191558191558 },
191559191559 .div => @shrExact(lhs, rhs),
191560 .div_8_down => lhs >> 3 & @as(SignedImm, -1) << rhs,
191560 .div_8_down => (lhs >> 3) & (@as(SignedImm, -1) << rhs),
191561191561 .rem_8_mul => lhs & ((@as(SignedImm, 8) << rhs) - 1),
191562 .up_2_mul => ((lhs - 1) & @as(SignedImm, -2) << rhs) + (@as(SignedImm, 2) << rhs),
191563 .up_32_mul => ((lhs - 1) & @as(SignedImm, -32) << rhs) + (@as(SignedImm, 32) << rhs),
191562 .up_2_mul => ((lhs - 1) & (@as(SignedImm, -2) << rhs)) + (@as(SignedImm, 2) << rhs),
191563 .up_32_mul => ((lhs - 1) & (@as(SignedImm, -32) << rhs)) + (@as(SignedImm, 32) << rhs),
191564191564 };
191565191565 const disp: SignedImm = @bitCast(@as(UnsignedImm, @as(u32, @bitCast(op.imm))));
191566191566 return switch (op.flags.adjust.sign) {
src/codegen/x86_64/Disassembler.zig+1-1
......@@ -378,7 +378,7 @@ fn parseEncoding(dis: *Disassembler, prefixes: Prefixes) !?Encoding {
378378}
379379
380380fn parseGpRegister(low_enc: u3, is_extended: bool, rex: Rex, bit_size: u64) Register {
381 const reg_id: u4 = @as(u4, @intCast(@intFromBool(is_extended))) << 3 | low_enc;
381 const reg_id: u4 = (@as(u4, @intCast(@intFromBool(is_extended))) << 3) | low_enc;
382382 const reg = @as(Register, @fromBackingInt(@intCast(reg_id))).toBitSize(bit_size);
383383 return switch (reg) {
384384 .spl => if (rex.present or rex.isSet()) .spl else .ah,
src/codegen/x86_64/Emit.zig+6-6
......@@ -694,13 +694,13 @@ pub fn emitMir(emit: *Emit) Error!void {
694694
695695 for (emit.table_relocs.items) |table_reloc| try atom.addReloc(gpa, .{
696696 .r_offset = table_reloc.source_offset,
697 .r_info = @as(u64, @backingInt(emit.atom_id)) << 32 | @backingInt(std.elf.R_X86_64.@"32S"),
697 .r_info = (@as(u64, @backingInt(emit.atom_id)) << 32) | @backingInt(std.elf.R_X86_64.@"32S"),
698698 .r_addend = @as(i64, table_offset) + table_reloc.target_offset,
699699 }, zo);
700700 for (emit.lower.mir.table) |entry| {
701701 try atom.addReloc(gpa, .{
702702 .r_offset = table_offset,
703 .r_info = @as(u64, @backingInt(emit.atom_id)) << 32 | @backingInt(std.elf.R_X86_64.@"64"),
703 .r_info = (@as(u64, @backingInt(emit.atom_id)) << 32) | @backingInt(std.elf.R_X86_64.@"64"),
704704 .r_addend = emit.code_offset_mapping.items[entry],
705705 }, zo);
706706 table_offset += ptr_size;
......@@ -812,7 +812,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
812812 .PC32;
813813 try atom.addReloc(gpa, .{
814814 .r_offset = end_offset - 4,
815 .r_info = @as(u64, @backingInt(target.symbol)) << 32 | @backingInt(r_type),
815 .r_info = (@as(u64, @backingInt(target.symbol)) << 32) | @backingInt(r_type),
816816 .r_addend = if (emit.pic) reloc.off - 4 else reloc.off,
817817 }, zo);
818818 } else if (emit.bin_file.cast(.macho)) |macho_file| {
......@@ -854,7 +854,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
854854 const r_type: std.elf.R_X86_64 = .PLT32;
855855 try atom.addReloc(gpa, .{
856856 .r_offset = end_offset - 4,
857 .r_info = @as(u64, @backingInt(target.symbol)) << 32 | @backingInt(r_type),
857 .r_info = (@as(u64, @backingInt(target.symbol)) << 32) | @backingInt(r_type),
858858 .r_addend = reloc.off - 4,
859859 }, zo);
860860 } else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(
......@@ -894,7 +894,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
894894 const r_type: std.elf.R_X86_64 = if (emit.pic) .TLSLD else unreachable;
895895 try atom.addReloc(gpa, .{
896896 .r_offset = end_offset - 4,
897 .r_info = @as(u64, @backingInt(target_symbol)) << 32 | @backingInt(r_type),
897 .r_info = (@as(u64, @backingInt(target_symbol)) << 32) | @backingInt(r_type),
898898 .r_addend = reloc.off - 4,
899899 }, zo);
900900 } else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(
......@@ -912,7 +912,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
912912 const r_type: std.elf.R_X86_64 = if (emit.pic) .DTPOFF32 else .TPOFF32;
913913 try atom.addReloc(gpa, .{
914914 .r_offset = end_offset - 4,
915 .r_info = @as(u64, @backingInt(target.symbol)) << 32 | @backingInt(r_type),
915 .r_info = (@as(u64, @backingInt(target.symbol)) << 32) | @backingInt(r_type),
916916 .r_addend = reloc.off,
917917 }, zo);
918918 } else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(
src/codegen/x86_64/Mir.zig+1-1
......@@ -1949,7 +1949,7 @@ pub const Memory = struct {
19491949 assert(mem.info.base == .reg);
19501950 return encoder.Instruction.Memory.initMoffs(
19511951 @fromBackingInt(@intCast(mem.base)),
1952 @as(u64, mem.extra) << 32 | mem.off,
1952 (@as(u64, mem.extra) << 32) | mem.off,
19531953 );
19541954 },
19551955 }
src/codegen/x86_64/bits.zig+1-1
......@@ -664,7 +664,7 @@ pub const Register = enum(u8) {
664664 .general_purpose, .gphi => if (reg.isExtended())
665665 reg.enc()
666666 else
667 @as(u3, @truncate(@as(u24, 0o54673120) >> @as(u5, reg.enc()) * 3)),
667 @as(u3, @truncate(@as(u24, 0o54673120) >> (@as(u5, reg.enc()) * 3))),
668668 .sse => 17 + @as(u6, reg.enc()),
669669 .x87 => 33 + @as(u6, reg.enc()),
670670 .mmx => 41 + @as(u6, reg.enc()),
src/codegen/x86_64/encoder.zig+14-14
......@@ -844,25 +844,25 @@ fn Encoder(comptime opts: Options) type {
844844 try self.w.writeByte(0b1100_0100);
845845
846846 try self.w.writeByte(
847 @as(u8, ~@intFromBool(fields.r)) << 7 |
848 @as(u8, ~@intFromBool(fields.x)) << 6 |
849 @as(u8, ~@intFromBool(fields.b)) << 5 |
850 @as(u8, @backingInt(fields.m)) << 0,
847 (@as(u8, ~@intFromBool(fields.r)) << 7) |
848 (@as(u8, ~@intFromBool(fields.x)) << 6) |
849 (@as(u8, ~@intFromBool(fields.b)) << 5) |
850 (@as(u8, @backingInt(fields.m)) << 0),
851851 );
852852
853853 try self.w.writeByte(
854 @as(u8, @intFromBool(fields.w)) << 7 |
855 @as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3 |
856 @as(u8, @intFromBool(fields.l)) << 2 |
857 @as(u8, @backingInt(fields.p)) << 0,
854 (@as(u8, @intFromBool(fields.w)) << 7) |
855 (@as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3) |
856 (@as(u8, @intFromBool(fields.l)) << 2) |
857 (@as(u8, @backingInt(fields.p)) << 0),
858858 );
859859 } else {
860860 try self.w.writeByte(0b1100_0101);
861861 try self.w.writeByte(
862 @as(u8, ~@intFromBool(fields.r)) << 7 |
863 @as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3 |
864 @as(u8, @intFromBool(fields.l)) << 2 |
865 @as(u8, @backingInt(fields.p)) << 0,
862 (@as(u8, ~@intFromBool(fields.r)) << 7) |
863 (@as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3) |
864 (@as(u8, @intFromBool(fields.l)) << 2) |
865 (@as(u8, @backingInt(fields.p)) << 0),
866866 );
867867 }
868868 }
......@@ -910,7 +910,7 @@ fn Encoder(comptime opts: Options) type {
910910 ///
911911 /// Remember to add a REX prefix byte if reg or rm are extended!
912912 pub fn modRm(self: Self, mod: u2, reg_or_opx: u3, rm: u3) !void {
913 try self.w.writeByte(@as(u8, mod) << 6 | @as(u8, reg_or_opx) << 3 | rm);
913 try self.w.writeByte((@as(u8, mod) << 6) | (@as(u8, reg_or_opx) << 3) | rm);
914914 }
915915
916916 /// Construct a ModR/M byte using direct r/m addressing
......@@ -996,7 +996,7 @@ fn Encoder(comptime opts: Options) type {
996996 ///
997997 /// Remember to add a REX prefix byte if index or base are extended!
998998 pub fn sib(self: Self, scale: u2, index: u3, base: u3) !void {
999 try self.w.writeByte(@as(u8, scale) << 6 | @as(u8, index) << 3 | base);
999 try self.w.writeByte((@as(u8, scale) << 6) | (@as(u8, index) << 3) | base);
10001000 }
10011001
10021002 /// Construct a SIB byte with scale * index + base, no frills.
src/fmt.zig+94-2
......@@ -41,6 +41,7 @@ const Fmt = struct {
4141 out_buffer: std.Io.Writer.Allocating,
4242 stdout_writer: *Io.File.Writer,
4343 stats: ?*Stats,
44 fix_precedence: bool,
4445
4546 const SeenMap = std.AutoHashMap(Io.File.INode, void);
4647};
......@@ -66,6 +67,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
6667 var check_ast_flag = false;
6768 var force_zon = false;
6869 var enable_stats = false;
70 var fix_precedence = false;
6971
7072 var input_files = std.array_list.Managed([]const u8).init(gpa);
7173 defer input_files.deinit();
......@@ -107,6 +109,8 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
107109 try excluded_files.append(next_arg);
108110 } else if (mem.eql(u8, arg, "--zon")) {
109111 force_zon = true;
112 } else if (mem.eql(u8, arg, "--upgrade")) {
113 fix_precedence = true;
110114 } else {
111115 fatal("unrecognized parameter: {q}", .{arg});
112116 }
......@@ -198,6 +202,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
198202 .out_buffer = .init(gpa),
199203 .stdout_writer = &stdout_writer,
200204 .stats = null,
205 .fix_precedence = fix_precedence,
201206 };
202207 defer fmt.seen.deinit();
203208 defer fmt.out_buffer.deinit();
......@@ -323,7 +328,8 @@ fn fmtPathDir(
323328
324329 if (mem.startsWith(u8, entry.name, ".")) continue;
325330
326 if (is_dir or entry.kind == .file and (mem.endsWith(u8, entry.name, ".zig") or mem.endsWith(u8, entry.name, ".zon"))) {
331 const is_zig_or_zon = entry.kind == .file and (mem.endsWith(u8, entry.name, ".zig") or mem.endsWith(u8, entry.name, ".zon"));
332 if (is_dir or is_zig_or_zon) {
327333 const full_path = try fs.path.join(fmt.gpa, &[_][]const u8{ file_path, entry.name });
328334 defer fmt.gpa.free(full_path);
329335
......@@ -384,6 +390,92 @@ fn fmtPathFile(
384390 var tree = try std.zig.Ast.parse(gpa, source_code, .{ .mode = mode });
385391 defer tree.deinit(gpa);
386392
393 var fixups: std.zig.Ast.Render.Fixups = .{};
394 defer fixups.deinit(gpa);
395
396 fix: {
397 if (!fmt.fix_precedence) break :fix;
398
399 var operators_to_fix: std.AutoHashMapUnmanaged(std.zig.Ast.TokenIndex, void) = .empty;
400 defer operators_to_fix.deinit(gpa);
401
402 // Gather ambiguous operator precedence error tokens for quick lookup later
403 var remaining_errors: usize = tree.errors.len;
404 for (tree.errors) |err| {
405 switch (err.tag) {
406 .hint_operator_precedence_left => {
407 try operators_to_fix.put(gpa, err.token - @as(u32, @intCast(err.extra.offset)), {});
408 remaining_errors -= 1;
409 },
410 .hint_operator_precedence_right => {
411 try operators_to_fix.put(gpa, err.token, {});
412 remaining_errors -= 1;
413 },
414 .ambiguous_operator_precedence,
415 .illegal_chained_operators,
416 .previous_ambiguous_operator,
417 => remaining_errors -= 1,
418 else => continue,
419 }
420 }
421
422 if (operators_to_fix.count() == 0) break :fix;
423
424 // Build a new error list without the ambiguous operator precedence errors/notes
425 var fixed_errors: std.ArrayList(std.zig.Ast.Error) = try .initCapacity(gpa, remaining_errors);
426 for (tree.errors) |err| {
427 switch (err.tag) {
428 .ambiguous_operator_precedence,
429 .illegal_chained_operators,
430 .previous_ambiguous_operator,
431 .hint_operator_precedence_left,
432 .hint_operator_precedence_right,
433 => continue,
434 else => {
435 fixed_errors.appendAssumeCapacity(err);
436 },
437 }
438 }
439 gpa.free(tree.errors);
440 tree.errors = fixed_errors.toOwnedSliceAssert();
441
442 // Find the nodes we need to add parens to and add them to the list
443 for (tree.nodes.items(.tag), 0..) |tag, i| {
444 switch (tag) {
445 .merge_error_sets,
446 .mul,
447 .div,
448 .mod,
449 .mul_wrap,
450 .mul_sat,
451 .add,
452 .sub,
453 .array_cat,
454 .add_wrap,
455 .sub_wrap,
456 .add_sat,
457 .sub_sat,
458 .shl,
459 .shl_sat,
460 .shr,
461 .bit_and,
462 .bit_xor,
463 .bit_or,
464 .@"orelse",
465 .@"catch",
466 .bool_and,
467 .bool_or,
468 => {
469 const main_tok = tree.nodes.get(i).main_token;
470 if (operators_to_fix.contains(main_tok)) {
471 try fixups.insert_parentheses.put(gpa, @fromBackingInt(@intCast(i)), {});
472 }
473 },
474 else => {},
475 }
476 }
477 }
478
387479 if (tree.errors.len != 0) {
388480 try std.zig.printAstErrorsToStderr(gpa, io, tree, file_path, fmt.color);
389481 fmt.any_error = true;
......@@ -491,7 +583,7 @@ fn fmtPathFile(
491583 fmt.out_buffer.clearRetainingCapacity();
492584 try fmt.out_buffer.ensureTotalCapacity(source_code.len);
493585
494 tree.render(gpa, &fmt.out_buffer.writer, .{}) catch |err| switch (err) {
586 tree.render(gpa, &fmt.out_buffer.writer, fixups) catch |err| switch (err) {
495587 error.WriteFailed, error.OutOfMemory => return error.OutOfMemory,
496588 };
497589 if (!mem.eql(u8, fmt.out_buffer.written(), source_code)) {
src/link/Dwarf.zig+3-3
......@@ -697,7 +697,7 @@ const Unit = struct {
697697 fw.writeByte(DW.LNS.extended_op) catch unreachable;
698698 const extended_op_bytes = fw.end;
699699 var op_len_bytes: u5 = 1;
700 while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) {
700 while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << (7 * op_len_bytes))) {
701701 .lt => break fw.writeUleb128(len - extended_op_bytes - op_len_bytes) catch unreachable,
702702 .eq => {
703703 // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte
......@@ -893,7 +893,7 @@ const Entry = struct {
893893 fw.writeUleb128(try dwarf.refAbbrevCode(.pad_n)) catch unreachable;
894894 const abbrev_code_bytes = fw.end;
895895 var block_len_bytes: u5 = 1;
896 while (true) switch (std.math.order(len - abbrev_code_bytes - block_len_bytes, @as(u32, 1) << 7 * block_len_bytes)) {
896 while (true) switch (std.math.order(len - abbrev_code_bytes - block_len_bytes, @as(u32, 1) << (7 * block_len_bytes))) {
897897 .lt => break fw.writeUleb128(len - abbrev_code_bytes - block_len_bytes) catch unreachable,
898898 .eq => {
899899 // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte
......@@ -915,7 +915,7 @@ const Entry = struct {
915915 fw.writeByte(DW.LNS.extended_op) catch unreachable;
916916 const extended_op_bytes = fw.end;
917917 var op_len_bytes: u5 = 1;
918 while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) {
918 while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << (7 * op_len_bytes))) {
919919 .lt => break fw.writeUleb128(len - extended_op_bytes - op_len_bytes) catch unreachable,
920920 .eq => {
921921 // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte
src/link/Dwarf2.zig+2-2
......@@ -1891,7 +1891,7 @@ pub fn genDebugInfoPadding(dwarf: *Dwarf, di_w: *std.Io.Writer, size: u64) std.I
18911891 var block_len_size: u5 = 1;
18921892 while (true) switch (std.math.order(
18931893 size - abbrev_code_size - block_len_size,
1894 @as(u64, 1) << 7 * block_len_size,
1894 @as(u64, 1) << (7 * block_len_size),
18951895 )) {
18961896 .lt => break try di_w.writeUleb128(size - abbrev_code_size - block_len_size),
18971897 .eq => {
......@@ -2023,7 +2023,7 @@ pub fn genDebugLinePadding(dl_w: *std.Io.Writer, size: u64) std.Io.Writer.Error!
20232023 var op_len_size: u5 = 1;
20242024 while (true) switch (std.math.order(
20252025 size - extended_op_size - op_len_size,
2026 @as(u64, 1) << 7 * op_len_size,
2026 @as(u64, 1) << (7 * op_len_size),
20272027 )) {
20282028 .lt => break try dl_w.writeUleb128(size - extended_op_size - op_len_size),
20292029 .eq => {
src/link/Elf2.zig+4-4
......@@ -7694,11 +7694,11 @@ fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) (Load
76947694 {
76957695 break :load_object;
76967696 }
7697 const member = header.name() orelse member: {
7698 const strtab_offset = header.nameOffset() catch |err| switch (err) {
7697 const member = header.name() orelse (member: {
7698 const strtab_offset = (header.nameOffset() catch |err| switch (err) {
76997699 error.Overflow => break :member error.Overflow,
77007700 error.InvalidCharacter => break :load_object,
7701 } orelse break :load_object;
7701 }) orelse break :load_object;
77027702 const strtab_written = strtab.written();
77037703 if (strtab_offset > strtab_written.len) break :member error.Overflow;
77047704 const member = std.mem.sliceTo(strtab_written[strtab_offset..], '\n');
......@@ -7708,7 +7708,7 @@ fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) (Load
77087708 member;
77097709 } catch |err| switch (err) {
77107710 error.Overflow => return diags.failParse(path, "bad member name offset", .{}),
7711 };
7711 });
77127712 try elf.loadObject(path, member, fr, .{ .offset = offset, .size = size });
77137713 }
77147714 try fr.seekTo(std.mem.alignForward(u64, offset + size, 2));
src/link/MachO/UnwindInfo.zig+1-1
......@@ -228,7 +228,7 @@ pub fn generate(info: *UnwindInfo, macho_file: *MachO) !void {
228228 if (next.getAtomAddress(macho_file) >= range_start_max) {
229229 break;
230230 } else if (info.getCommonEncoding(next.enc) != null or
231 page.getPageEncoding(next.enc) != null and !is_dwarf)
231 (page.getPageEncoding(next.enc) != null and !is_dwarf))
232232 {
233233 i += 1;
234234 space_left -= 1;
src/link/MachO/load_commands.zig+2-2
......@@ -266,8 +266,8 @@ pub fn writeDylibIdLC(macho_file: *MachO, writer: *Writer) !void {
266266 try writeDylibLC(.{
267267 .cmd = .ID_DYLIB,
268268 .name = install_name,
269 .current_version = @as(u32, @intCast(curr.major << 16 | curr.minor << 8 | curr.patch)),
270 .compatibility_version = @as(u32, @intCast(compat.major << 16 | compat.minor << 8 | compat.patch)),
269 .current_version = @as(u32, @intCast((curr.major << 16) | (curr.minor << 8) | curr.patch)),
270 .compatibility_version = @as(u32, @intCast((compat.major << 16) | (compat.minor << 8) | compat.patch)),
271271 }, writer);
272272}
273273
src/link/Wasm/Flush.zig+1-1
......@@ -1128,7 +1128,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {
11281128 // indirect function table elements
11291129 const table_index: u32 = @intCast(
11301130 wasm.table_imports.getIndex(wasm.preloaded_strings.__indirect_function_table) orelse
1131 wasm.table_imports.entries.len + wasm.tables.getIndex(.__indirect_function_table).?,
1131 (wasm.table_imports.entries.len + wasm.tables.getIndex(.__indirect_function_table).?),
11321132 );
11331133 // passive with implicit 0-index table or set table index manually
11341134 const flags: u32 = if (table_index == 0) 0x0 else 0x02;
src/link/riscv.zig+2-2
......@@ -90,8 +90,8 @@ fn bitSlice(
9090 value: anytype,
9191 comptime high: comptime_int,
9292 comptime low: comptime_int,
93) std.math.IntFittingRange(0, 1 << high - low) {
94 return @truncate((value >> low) & (1 << (high - low + 1)) - 1);
93) std.math.IntFittingRange(0, 1 << (high - low)) {
94 return @truncate((value >> low) & ((1 << (high - low + 1)) - 1));
9595}
9696
9797pub const Eflags = packed struct(u32) {
src/main.zig+1-1
......@@ -3524,7 +3524,7 @@ fn buildOutputType(
35243524 };
35253525
35263526 const thread_limit = @min(
3527 @max(n_jobs orelse std.Thread.getCpuCount() catch 1, 1),
3527 @max(n_jobs orelse (std.Thread.getCpuCount() catch 1), 1),
35283528 std.math.maxInt(Zcu.PerThread.IdBacking),
35293529 );
35303530 try setThreadLimit(arena, thread_limit);
test/Runner.zig+4-4
......@@ -811,7 +811,7 @@ pub const DelimitedReader = struct {
811811 const d: *DelimitedReader = @fieldParentPtr("interface", r);
812812 const block = try d.unlimited.peekGreedy(d.delimiter.len);
813813 d.remaining = .limited(std.mem.findPos(u8, block, d.remaining.toInt().?, d.delimiter) orelse
814 block.len - d.delimiter.len + 1);
814 (block.len - d.delimiter.len + 1));
815815 if (d.remaining == .nothing) return error.EndOfStream;
816816 const n = try d.unlimited.stream(w, limit.min(d.remaining));
817817 d.remaining = d.remaining.subtract(n).?;
......@@ -821,7 +821,7 @@ pub const DelimitedReader = struct {
821821 const d: *DelimitedReader = @fieldParentPtr("interface", r);
822822 const block = try d.unlimited.peekGreedy(d.delimiter.len);
823823 d.remaining = .limited(std.mem.findPos(u8, block, d.remaining.toInt().?, d.delimiter) orelse
824 block.len - d.delimiter.len + 1);
824 (block.len - d.delimiter.len + 1));
825825 if (d.remaining == .nothing) return error.EndOfStream;
826826 const n = try d.unlimited.discard(limit.min(d.remaining));
827827 d.remaining = d.remaining.subtract(n).?;
......@@ -1397,9 +1397,9 @@ fn handleCommand(
13971397 return update.fail("compiler failed to send terminating error_bundle", .{});
13981398 },
13991399 }
1400 assert(contents_r.discardRemaining() catch |err| switch (err) {
1400 assert((contents_r.discardRemaining() catch |err| switch (err) {
14011401 error.ReadFailed => return error.ContentsReadFailed,
1402 } == 0);
1402 }) == 0);
14031403 switch (cmd) {
14041404 .todo, .skip => {},
14051405 else => update.allow_skip = false,
test/behavior/bitcast.zig+1-1
......@@ -470,7 +470,7 @@ test "@bitCast of packed struct with void field and multiple integers" {
470470 fn doTheTest(x: u8, y: u8) !void {
471471 const foo = @as(@This(), .{ .x = x, .v = {}, .y = y });
472472 const as_int: u16 = @bitCast(foo);
473 try expect(as_int == @as(u16, y) << 8 | x);
473 try expect(as_int == (@as(u16, y) << 8) | x);
474474 }
475475 };
476476 try S.doTheTest(123, 45);
test/behavior/error.zig+1-1
......@@ -209,7 +209,7 @@ fn testErrorSetType() !void {
209209
210210 const a: MyErrSet!i32 = 5678;
211211 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
212 try expect(b catch error.OutOfMemory == error.OutOfMemory);
212 try expect((b catch error.OutOfMemory) == error.OutOfMemory);
213213
214214 if (a) |value| try expect(value == 5678) else |err| switch (err) {
215215 error.OutOfMemory => unreachable,
test/behavior/math.zig+3-3
......@@ -49,10 +49,10 @@ fn testThreeExprInARow(f: bool, t: bool) !void {
4949 try assertFalse(1 | 2 | 4 != 7);
5050 try assertFalse(3 ^ 6 ^ 8 != 13);
5151 try assertFalse(7 & 14 & 28 != 4);
52 try assertFalse(9 << 1 << 2 != 9 << 3);
53 try assertFalse(90 >> 1 >> 2 != 90 >> 3);
52 try assertFalse((9 << 1) << 2 != 9 << 3);
53 try assertFalse((90 >> 1) >> 2 != 90 >> 3);
5454 try assertFalse(100 - 1 + 1000 != 1099);
55 try assertFalse(5 * 4 / 2 % 3 != 1);
55 try assertFalse((5 * 4 / 2) % 3 != 1);
5656 try assertFalse(@as(i32, @as(i32, 5)) != 5);
5757 try assertFalse(!!false);
5858 try assertFalse(@as(i32, 7) != --(@as(i32, 7)));
test/behavior/try.zig+3-3
......@@ -186,9 +186,9 @@ test "try ptr propagation mutate" {
186186 res1.* += 1;
187187 res2.* += 1;
188188
189 try expect(f0 catch unreachable == 1);
190 try expect(f1 catch unreachable == 2);
191 try expect(f2 catch unreachable == 3);
189 try expect((f0 catch unreachable) == 1);
190 try expect((f1 catch unreachable) == 2);
191 try expect((f2 catch unreachable) == 3);
192192
193193 try expect(res0.* == 1);
194194 try expect(res1.* == 2);
test/behavior/x86_64/binary.zig+2-2
......@@ -5503,7 +5503,7 @@ inline fn shrExact(comptime Type: type, lhs: Type, rhs: Type) Type {
55035503 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
55045504 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
55055505 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs;
5506 return @shrExact(lhs >> final_rhs << final_rhs, final_rhs);
5506 return @shrExact((lhs >> final_rhs) << final_rhs, final_rhs);
55075507}
55085508test shrExact {
55095509 const test_shr_exact = binary(shrExact, .{});
......@@ -5527,7 +5527,7 @@ inline fn shlExactUnsafe(comptime Type: type, lhs: Type, rhs: Type) Type {
55275527 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
55285528 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
55295529 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs;
5530 return @shlExact(lhs << final_rhs >> final_rhs, final_rhs);
5530 return @shlExact((lhs << final_rhs) >> final_rhs, final_rhs);
55315531}
55325532test shlExactUnsafe {
55335533 const test_shl_exact_unsafe = binary(shlExactUnsafe, .{});
test/behavior/x86_64/cast.zig+4-4
......@@ -14502,15 +14502,15 @@ inline fn intCast(comptime Result: type, comptime Type: type, rhs: Type, comptim
1450214502 // TODO: if (bits == 0) rhs else rhs >> bits,
1450314503 .shift => |bits| if (bits == 0) rhs else switch (@typeInfo(Type)) {
1450414504 .int => if (ct_rhs < 0)
14505 rhs | imin(Type) >> bits
14505 rhs | (imin(Type) >> bits)
1450614506 else
14507 rhs & imax(Type) >> bits,
14508 .vector => rhs | @select(
14507 rhs & (imax(Type) >> bits),
14508 .vector => (rhs | @select(
1450914509 Scalar(Type),
1451014510 ct_rhs < @as(Type, @splat(0)),
1451114511 @as(Type, @splat(imin(Scalar(Type)) >> bits)),
1451214512 @as(Type, @splat(0)),
14513 ) & ~@select(
14513 )) & ~@select(
1451414514 Scalar(Type),
1451514515 ct_rhs >= @as(Type, @splat(0)),
1451614516 @as(Type, @splat(imin(Scalar(Type)) >> bits)),
tools/doctest.zig+1-1
......@@ -225,7 +225,7 @@ fn printOutput(
225225 if (mem.startsWith(u8, triple, "wasm32") or
226226 mem.startsWith(u8, triple, "riscv64-linux") or
227227 (mem.startsWith(u8, triple, "x86_64-linux") and
228 builtin.os.tag != .linux or builtin.cpu.arch != .x86_64))
228 (builtin.os.tag != .linux or builtin.cpu.arch != .x86_64)))
229229 {
230230 // skip execution
231231 break :code_block;
tools/loongarch/OpcodeDesc.zig+2-2
......@@ -95,10 +95,10 @@ pub const Format = struct {
9595 const index: Slot.Index = try .parse(&reader);
9696 const length = try takeInteger(u5, &reader);
9797 const post_proc = post_proc: {
98 if ('p' == reader.peekByte() catch |err| switch (err) {
98 if ('p' == (reader.peekByte() catch |err| switch (err) {
9999 error.EndOfStream => ' ',
100100 else => return err,
101 }) {
101 })) {
102102 reader.toss(1);
103103 break :post_proc try Slot.PostProcess.parse(&reader);
104104 } else break :post_proc Slot.PostProcess.none;