| author | |
| committer | |
| log | b5b634e4e8a2a1fe32fba50ccd175257b4213936 |
| tree | 4eed625db81dd4d6907e386084df36ec3ac85687 |
| parent | efdc94c10712f610e7de5e49fd9cd6f88b4bbbae |
| parent | 02f5d2673f1bb21e7329acdd664fed565ecd4317 |
259 files changed, 2499 insertions(+), 1299 deletions(-)
doc/docgen.zig+1-1| ... | @@ -239,7 +239,7 @@ const Tokenizer = struct { | ... | @@ -239,7 +239,7 @@ const Tokenizer = struct { |
| 239 | .line_start = 0, | 239 | .line_start = 0, |
| 240 | .line_end = 0, | 240 | .line_end = 0, |
| 241 | }; | 241 | }; |
| 242 | for (self.buffer) |c, i| { | 242 | for (self.buffer, 0..) |c, i| { |
| 243 | if (i == token.start) { | 243 | if (i == token.start) { |
| 244 | loc.line_end = i; | 244 | loc.line_end = i; |
| 245 | while (loc.line_end < self.buffer.len and self.buffer[loc.line_end] != '\n') : (loc.line_end += 1) {} | 245 | while (loc.line_end < self.buffer.len and self.buffer[loc.line_end] != '\n') : (loc.line_end += 1) {} |
doc/langref.html.in+19-18| ... | @@ -2367,7 +2367,7 @@ test "iterate over an array" { | ... | @@ -2367,7 +2367,7 @@ test "iterate over an array" { |
| 2367 | var some_integers: [100]i32 = undefined; | 2367 | var some_integers: [100]i32 = undefined; |
| 2368 | 2368 | ||
| 2369 | test "modify an array" { | 2369 | test "modify an array" { |
| 2370 | for (some_integers) |*item, i| { | 2370 | for (&some_integers, 0..) |*item, i| { |
| 2371 | item.* = @intCast(i32, i); | 2371 | item.* = @intCast(i32, i); |
| 2372 | } | 2372 | } |
| 2373 | try expect(some_integers[10] == 10); | 2373 | try expect(some_integers[10] == 10); |
| ... | @@ -2408,7 +2408,7 @@ comptime { | ... | @@ -2408,7 +2408,7 @@ comptime { |
| 2408 | // use compile-time code to initialize an array | 2408 | // use compile-time code to initialize an array |
| 2409 | var fancy_array = init: { | 2409 | var fancy_array = init: { |
| 2410 | var initial_value: [10]Point = undefined; | 2410 | var initial_value: [10]Point = undefined; |
| 2411 | for (initial_value) |*pt, i| { | 2411 | for (&initial_value, 0..) |*pt, i| { |
| 2412 | pt.* = Point{ | 2412 | pt.* = Point{ |
| 2413 | .x = @intCast(i32, i), | 2413 | .x = @intCast(i32, i), |
| 2414 | .y = @intCast(i32, i) * 2, | 2414 | .y = @intCast(i32, i) * 2, |
| ... | @@ -2461,8 +2461,8 @@ test "multidimensional arrays" { | ... | @@ -2461,8 +2461,8 @@ test "multidimensional arrays" { |
| 2461 | try expect(mat4x4[1][1] == 1.0); | 2461 | try expect(mat4x4[1][1] == 1.0); |
| 2462 | 2462 | ||
| 2463 | // Here we iterate with for loops. | 2463 | // Here we iterate with for loops. |
| 2464 | for (mat4x4) |row, row_index| { | 2464 | for (mat4x4, 0..) |row, row_index| { |
| 2465 | for (row) |cell, column_index| { | 2465 | for (row, 0..) |cell, column_index| { |
| 2466 | if (row_index == column_index) { | 2466 | if (row_index == column_index) { |
| 2467 | try expect(cell == 1.0); | 2467 | try expect(cell == 1.0); |
| 2468 | } | 2468 | } |
| ... | @@ -3579,7 +3579,7 @@ test "tuple" { | ... | @@ -3579,7 +3579,7 @@ test "tuple" { |
| 3579 | } ++ .{false} ** 2; | 3579 | } ++ .{false} ** 2; |
| 3580 | try expect(values[0] == 1234); | 3580 | try expect(values[0] == 1234); |
| 3581 | try expect(values[4] == false); | 3581 | try expect(values[4] == false); |
| 3582 | inline for (values) |v, i| { | 3582 | inline for (values, 0..) |v, i| { |
| 3583 | if (i != 2) continue; | 3583 | if (i != 2) continue; |
| 3584 | try expect(v); | 3584 | try expect(v); |
| 3585 | } | 3585 | } |
| ... | @@ -4659,10 +4659,10 @@ test "for basics" { | ... | @@ -4659,10 +4659,10 @@ test "for basics" { |
| 4659 | } | 4659 | } |
| 4660 | try expect(sum == 20); | 4660 | try expect(sum == 20); |
| 4661 | 4661 | ||
| 4662 | // To access the index of iteration, specify a second capture value. | 4662 | // To access the index of iteration, specify a second condition as well |
| 4663 | // This is zero-indexed. | 4663 | // as a second capture value. |
| 4664 | var sum2: i32 = 0; | 4664 | var sum2: i32 = 0; |
| 4665 | for (items) |_, i| { | 4665 | for (items, 0..) |_, i| { |
| 4666 | try expect(@TypeOf(i) == usize); | 4666 | try expect(@TypeOf(i) == usize); |
| 4667 | sum2 += @intCast(i32, i); | 4667 | sum2 += @intCast(i32, i); |
| 4668 | } | 4668 | } |
| ... | @@ -4674,7 +4674,7 @@ test "for reference" { | ... | @@ -4674,7 +4674,7 @@ test "for reference" { |
| 4674 | 4674 | ||
| 4675 | // Iterate over the slice by reference by | 4675 | // Iterate over the slice by reference by |
| 4676 | // specifying that the capture value is a pointer. | 4676 | // specifying that the capture value is a pointer. |
| 4677 | for (items) |*value| { | 4677 | for (&items) |*value| { |
| 4678 | value.* += 1; | 4678 | value.* += 1; |
| 4679 | } | 4679 | } |
| 4680 | 4680 | ||
| ... | @@ -5659,7 +5659,7 @@ fn genFoos(allocator: Allocator, num: usize) ![]Foo { | ... | @@ -5659,7 +5659,7 @@ fn genFoos(allocator: Allocator, num: usize) ![]Foo { |
| 5659 | var foos = try allocator.alloc(Foo, num); | 5659 | var foos = try allocator.alloc(Foo, num); |
| 5660 | errdefer allocator.free(foos); | 5660 | errdefer allocator.free(foos); |
| 5661 | 5661 | ||
| 5662 | for(foos) |*foo, i| { | 5662 | for (foos, 0..) |*foo, i| { |
| 5663 | foo.data = try allocator.create(u32); | 5663 | foo.data = try allocator.create(u32); |
| 5664 | // This errdefer does not last between iterations | 5664 | // This errdefer does not last between iterations |
| 5665 | errdefer allocator.destroy(foo.data); | 5665 | errdefer allocator.destroy(foo.data); |
| ... | @@ -5700,14 +5700,14 @@ fn genFoos(allocator: Allocator, num: usize) ![]Foo { | ... | @@ -5700,14 +5700,14 @@ fn genFoos(allocator: Allocator, num: usize) ![]Foo { |
| 5700 | // Used to track how many foos have been initialized | 5700 | // Used to track how many foos have been initialized |
| 5701 | // (including their data being allocated) | 5701 | // (including their data being allocated) |
| 5702 | var num_allocated: usize = 0; | 5702 | var num_allocated: usize = 0; |
| 5703 | errdefer for(foos[0..num_allocated]) |foo| { | 5703 | errdefer for (foos[0..num_allocated]) |foo| { |
| 5704 | allocator.destroy(foo.data); | 5704 | allocator.destroy(foo.data); |
| 5705 | }; | 5705 | }; |
| 5706 | for(foos) |*foo, i| { | 5706 | for (foos, 0..) |*foo, i| { |
| 5707 | foo.data = try allocator.create(u32); | 5707 | foo.data = try allocator.create(u32); |
| 5708 | num_allocated += 1; | 5708 | num_allocated += 1; |
| 5709 | 5709 | ||
| 5710 | if(i >= 3) return error.TooManyFoos; | 5710 | if (i >= 3) return error.TooManyFoos; |
| 5711 | 5711 | ||
| 5712 | foo.data.* = try getData(); | 5712 | foo.data.* = try getData(); |
| 5713 | } | 5713 | } |
| ... | @@ -7265,7 +7265,7 @@ const Writer = struct { | ... | @@ -7265,7 +7265,7 @@ const Writer = struct { |
| 7265 | comptime var state = State.start; | 7265 | comptime var state = State.start; |
| 7266 | comptime var next_arg: usize = 0; | 7266 | comptime var next_arg: usize = 0; |
| 7267 | 7267 | ||
| 7268 | inline for (format) |c, i| { | 7268 | inline for (format, 0..) |c, i| { |
| 7269 | switch (state) { | 7269 | switch (state) { |
| 7270 | State.start => switch (c) { | 7270 | State.start => switch (c) { |
| 7271 | '{' => { | 7271 | '{' => { |
| ... | @@ -8629,7 +8629,7 @@ test "integer cast panic" { | ... | @@ -8629,7 +8629,7 @@ test "integer cast panic" { |
| 8629 | This function is a low level intrinsic with no safety mechanisms. Most code | 8629 | This function is a low level intrinsic with no safety mechanisms. Most code |
| 8630 | should not use this function, instead using something like this: | 8630 | should not use this function, instead using something like this: |
| 8631 | </p> | 8631 | </p> |
| 8632 | <pre>{#syntax#}for (source[0..byte_count]) |b, i| dest[i] = b;{#endsyntax#}</pre> | 8632 | <pre>{#syntax#}for (dest, source[0..byte_count]) |*d, s| d.* = s;{#endsyntax#}</pre> |
| 8633 | <p> | 8633 | <p> |
| 8634 | The optimizer is intelligent enough to turn the above snippet into a memcpy. | 8634 | The optimizer is intelligent enough to turn the above snippet into a memcpy. |
| 8635 | </p> | 8635 | </p> |
| ... | @@ -11116,7 +11116,7 @@ pub fn main() !void { | ... | @@ -11116,7 +11116,7 @@ pub fn main() !void { |
| 11116 | const args = try std.process.argsAlloc(gpa); | 11116 | const args = try std.process.argsAlloc(gpa); |
| 11117 | defer std.process.argsFree(gpa, args); | 11117 | defer std.process.argsFree(gpa, args); |
| 11118 | 11118 | ||
| 11119 | for (args) |arg, i| { | 11119 | for (args, 0..) |arg, i| { |
| 11120 | std.debug.print("{}: {s}\n", .{ i, arg }); | 11120 | std.debug.print("{}: {s}\n", .{ i, arg }); |
| 11121 | } | 11121 | } |
| 11122 | } | 11122 | } |
| ... | @@ -11142,7 +11142,7 @@ pub fn main() !void { | ... | @@ -11142,7 +11142,7 @@ pub fn main() !void { |
| 11142 | 11142 | ||
| 11143 | const preopens = try fs.wasi.preopensAlloc(arena); | 11143 | const preopens = try fs.wasi.preopensAlloc(arena); |
| 11144 | 11144 | ||
| 11145 | for (preopens.names) |preopen, i| { | 11145 | for (preopens.names, 0..) |preopen, i| { |
| 11146 | std.debug.print("{}: {s}\n", .{ i, preopen }); | 11146 | std.debug.print("{}: {s}\n", .{ i, preopen }); |
| 11147 | } | 11147 | } |
| 11148 | } | 11148 | } |
| ... | @@ -11551,7 +11551,8 @@ fn readU32Be() u32 {} | ... | @@ -11551,7 +11551,8 @@ fn readU32Be() u32 {} |
| 11551 | </p> | 11551 | </p> |
| 11552 | <p> | 11552 | <p> |
| 11553 | Each LF may be immediately preceded by a single CR (byte value 0x0d, code point U+000d, {#syntax#}'\r'{#endsyntax#}) | 11553 | Each LF may be immediately preceded by a single CR (byte value 0x0d, code point U+000d, {#syntax#}'\r'{#endsyntax#}) |
| 11554 | to form a Windows style line ending, but this is discouraged. | 11554 | to form a Windows style line ending, but this is discouraged. Note that in mulitline strings, CRLF sequences will |
| 11555 | be encoded as LF when compiled into a zig program. | ||
| 11555 | A CR in any other context is not allowed. | 11556 | A CR in any other context is not allowed. |
| 11556 | </p> | 11557 | </p> |
| 11557 | <p> | 11558 | <p> |
lib/compiler_rt/README.md+4| ... | @@ -260,6 +260,8 @@ Integer and Float Operations | ... | @@ -260,6 +260,8 @@ Integer and Float Operations |
| 260 | | ✓ | __gedf2 | f64 | f64 | i32 | .. | | 260 | | ✓ | __gedf2 | f64 | f64 | i32 | .. | |
| 261 | | ✓ | __getf2 | f128 | f128 | i32 | .. | | 261 | | ✓ | __getf2 | f128 | f128 | i32 | .. | |
| 262 | | ✓ | __gexf2 | f80 | f80 | i32 | .. | | 262 | | ✓ | __gexf2 | f80 | f80 | i32 | .. | |
| 263 | | ✓ | __aeabi_fcmpge | f32 | f32 | i32 | .. ARM | | ||
| 264 | | ✓ | __aeabi_dcmpge | f64 | f64 | i32 | .. ARM | | ||
| 263 | | ✓ | __gekf2 | f128 | f128 | i32 | .. PPC | | 265 | | ✓ | __gekf2 | f128 | f128 | i32 | .. PPC | |
| 264 | | ✓ | _Qp_fge |*f128 |*f128 | bool | .. SPARC | | 266 | | ✓ | _Qp_fge |*f128 |*f128 | bool | .. SPARC | |
| 265 | | ✓ | __lthf2 | f16 | f16 | i32 | `(a!=Nan) and (b!=Nan) and (a<b) -> output<0` | | 267 | | ✓ | __lthf2 | f16 | f16 | i32 | `(a!=Nan) and (b!=Nan) and (a<b) -> output<0` | |
| ... | @@ -285,6 +287,8 @@ Integer and Float Operations | ... | @@ -285,6 +287,8 @@ Integer and Float Operations |
| 285 | | ✓ | __gtdf2 | f64 | f64 | i32 | .. | | 287 | | ✓ | __gtdf2 | f64 | f64 | i32 | .. | |
| 286 | | ✓ | __gttf2 | f128 | f128 | i32 | .. | | 288 | | ✓ | __gttf2 | f128 | f128 | i32 | .. | |
| 287 | | ✓ | __gtxf2 | f80 | f80 | i32 | .. | | 289 | | ✓ | __gtxf2 | f80 | f80 | i32 | .. | |
| 290 | | ✓ | __aeabi_fcmpgt | f32 | f32 | i32 | .. ARM | | ||
| 291 | | ✓ | __aeabi_dcmpgt | f64 | f64 | i32 | .. ARM | | ||
| 288 | | ✓ | __gtkf2 | f128 | f128 | i32 | .. PPC | | 292 | | ✓ | __gtkf2 | f128 | f128 | i32 | .. PPC | |
| 289 | | ✓ | _Qp_fgt |*f128 |*f128 | bool | .. SPARC | | 293 | | ✓ | _Qp_fgt |*f128 |*f128 | bool | .. SPARC | |
| 290 | | | | | | | **Float Arithmetic** | | 294 | | | | | | | **Float Arithmetic** | |
lib/compiler_rt/atomics.zig+1-1| ... | @@ -151,7 +151,7 @@ fn __atomic_compare_exchange( | ... | @@ -151,7 +151,7 @@ fn __atomic_compare_exchange( |
| 151 | _ = failure; | 151 | _ = failure; |
| 152 | var sl = spinlocks.get(@ptrToInt(ptr)); | 152 | var sl = spinlocks.get(@ptrToInt(ptr)); |
| 153 | defer sl.release(); | 153 | defer sl.release(); |
| 154 | for (ptr[0..size]) |b, i| { | 154 | for (ptr[0..size], 0..) |b, i| { |
| 155 | if (expected[i] != b) break; | 155 | if (expected[i] != b) break; |
| 156 | } else { | 156 | } else { |
| 157 | // The two objects, ptr and expected, are equal | 157 | // The two objects, ptr and expected, are equal |
lib/compiler_rt/comparedf2_test.zig+2-2| ... | @@ -94,8 +94,8 @@ fn generateVector(comptime a: f64, comptime b: f64) TestVector { | ... | @@ -94,8 +94,8 @@ fn generateVector(comptime a: f64, comptime b: f64) TestVector { |
| 94 | const test_vectors = init: { | 94 | const test_vectors = init: { |
| 95 | @setEvalBranchQuota(10000); | 95 | @setEvalBranchQuota(10000); |
| 96 | var vectors: [arguments.len * arguments.len]TestVector = undefined; | 96 | var vectors: [arguments.len * arguments.len]TestVector = undefined; |
| 97 | for (arguments[0..]) |arg_i, i| { | 97 | for (arguments[0..], 0..) |arg_i, i| { |
| 98 | for (arguments[0..]) |arg_j, j| { | 98 | for (arguments[0..], 0..) |arg_j, j| { |
| 99 | vectors[(i * arguments.len) + j] = generateVector(arg_i, arg_j); | 99 | vectors[(i * arguments.len) + j] = generateVector(arg_i, arg_j); |
| 100 | } | 100 | } |
| 101 | } | 101 | } |
lib/compiler_rt/comparesf2_test.zig+2-2| ... | @@ -94,8 +94,8 @@ fn generateVector(comptime a: f32, comptime b: f32) TestVector { | ... | @@ -94,8 +94,8 @@ fn generateVector(comptime a: f32, comptime b: f32) TestVector { |
| 94 | const test_vectors = init: { | 94 | const test_vectors = init: { |
| 95 | @setEvalBranchQuota(10000); | 95 | @setEvalBranchQuota(10000); |
| 96 | var vectors: [arguments.len * arguments.len]TestVector = undefined; | 96 | var vectors: [arguments.len * arguments.len]TestVector = undefined; |
| 97 | for (arguments[0..]) |arg_i, i| { | 97 | for (arguments[0..], 0..) |arg_i, i| { |
| 98 | for (arguments[0..]) |arg_j, j| { | 98 | for (arguments[0..], 0..) |arg_j, j| { |
| 99 | vectors[(i * arguments.len) + j] = generateVector(arg_i, arg_j); | 99 | vectors[(i * arguments.len) + j] = generateVector(arg_i, arg_j); |
| 100 | } | 100 | } |
| 101 | } | 101 | } |
lib/compiler_rt/gehf2.zig-8| ... | @@ -21,11 +21,3 @@ pub fn __gehf2(a: f16, b: f16) callconv(.C) i32 { | ... | @@ -21,11 +21,3 @@ pub fn __gehf2(a: f16, b: f16) callconv(.C) i32 { |
| 21 | pub fn __gthf2(a: f16, b: f16) callconv(.C) i32 { | 21 | pub fn __gthf2(a: f16, b: f16) callconv(.C) i32 { |
| 22 | return __gehf2(a, b); | 22 | return __gehf2(a, b); |
| 23 | } | 23 | } |
| 24 | |||
| 25 | fn __aeabi_fcmpge(a: f16, b: f16) callconv(.AAPCS) i32 { | ||
| 26 | return @boolToInt(comparef.cmpf2(f16, comparef.GE, a, b) != .Less); | ||
| 27 | } | ||
| 28 | |||
| 29 | fn __aeabi_fcmpgt(a: f16, b: f16) callconv(.AAPCS) i32 { | ||
| 30 | return @boolToInt(comparef.cmpf2(f16, comparef.LE, a, b) == .Greater); | ||
| 31 | } |
lib/std/Build.zig+4-4| ... | @@ -650,7 +650,7 @@ pub fn dupe(self: *Build, bytes: []const u8) []u8 { | ... | @@ -650,7 +650,7 @@ pub fn dupe(self: *Build, bytes: []const u8) []u8 { |
| 650 | /// Duplicates an array of strings without the need to handle out of memory. | 650 | /// Duplicates an array of strings without the need to handle out of memory. |
| 651 | pub fn dupeStrings(self: *Build, strings: []const []const u8) [][]u8 { | 651 | pub fn dupeStrings(self: *Build, strings: []const []const u8) [][]u8 { |
| 652 | const array = self.allocator.alloc([]u8, strings.len) catch @panic("OOM"); | 652 | const array = self.allocator.alloc([]u8, strings.len) catch @panic("OOM"); |
| 653 | for (strings) |s, i| { | 653 | for (strings, 0..) |s, i| { |
| 654 | array[i] = self.dupe(s); | 654 | array[i] = self.dupe(s); |
| 655 | } | 655 | } |
| 656 | return array; | 656 | return array; |
| ... | @@ -1051,7 +1051,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros | ... | @@ -1051,7 +1051,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros |
| 1051 | const all_features = whitelist_cpu.arch.allFeaturesList(); | 1051 | const all_features = whitelist_cpu.arch.allFeaturesList(); |
| 1052 | var populated_cpu_features = whitelist_cpu.model.features; | 1052 | var populated_cpu_features = whitelist_cpu.model.features; |
| 1053 | populated_cpu_features.populateDependencies(all_features); | 1053 | populated_cpu_features.populateDependencies(all_features); |
| 1054 | for (all_features) |feature, i_usize| { | 1054 | for (all_features, 0..) |feature, i_usize| { |
| 1055 | const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize); | 1055 | const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize); |
| 1056 | const in_cpu_set = populated_cpu_features.isEnabled(i); | 1056 | const in_cpu_set = populated_cpu_features.isEnabled(i); |
| 1057 | if (in_cpu_set) { | 1057 | if (in_cpu_set) { |
| ... | @@ -1059,7 +1059,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros | ... | @@ -1059,7 +1059,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros |
| 1059 | } | 1059 | } |
| 1060 | } | 1060 | } |
| 1061 | log.err(" Remove: ", .{}); | 1061 | log.err(" Remove: ", .{}); |
| 1062 | for (all_features) |feature, i_usize| { | 1062 | for (all_features, 0..) |feature, i_usize| { |
| 1063 | const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize); | 1063 | const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize); |
| 1064 | const in_cpu_set = populated_cpu_features.isEnabled(i); | 1064 | const in_cpu_set = populated_cpu_features.isEnabled(i); |
| 1065 | const in_actual_set = selected_cpu.features.isEnabled(i); | 1065 | const in_actual_set = selected_cpu.features.isEnabled(i); |
| ... | @@ -1748,7 +1748,7 @@ pub fn serializeCpu(allocator: Allocator, cpu: std.Target.Cpu) ![]const u8 { | ... | @@ -1748,7 +1748,7 @@ pub fn serializeCpu(allocator: Allocator, cpu: std.Target.Cpu) ![]const u8 { |
| 1748 | var mcpu_buffer = ArrayList(u8).init(allocator); | 1748 | var mcpu_buffer = ArrayList(u8).init(allocator); |
| 1749 | try mcpu_buffer.appendSlice(cpu.model.name); | 1749 | try mcpu_buffer.appendSlice(cpu.model.name); |
| 1750 | 1750 | ||
| 1751 | for (all_features) |feature, i_usize| { | 1751 | for (all_features, 0..) |feature, i_usize| { |
| 1752 | const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize); | 1752 | const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize); |
| 1753 | const in_cpu_set = populated_cpu_features.isEnabled(i); | 1753 | const in_cpu_set = populated_cpu_features.isEnabled(i); |
| 1754 | const in_actual_set = cpu.features.isEnabled(i); | 1754 | const in_actual_set = cpu.features.isEnabled(i); |
lib/std/Build/CompileStep.zig+4-4| ... | @@ -1016,7 +1016,7 @@ pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void { | ... | @@ -1016,7 +1016,7 @@ pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void { |
| 1016 | pub fn setExecCmd(self: *CompileStep, args: []const ?[]const u8) void { | 1016 | pub fn setExecCmd(self: *CompileStep, args: []const ?[]const u8) void { |
| 1017 | assert(self.kind == .@"test"); | 1017 | assert(self.kind == .@"test"); |
| 1018 | const duped_args = self.builder.allocator.alloc(?[]u8, args.len) catch @panic("OOM"); | 1018 | const duped_args = self.builder.allocator.alloc(?[]u8, args.len) catch @panic("OOM"); |
| 1019 | for (args) |arg, i| { | 1019 | for (args, 0..) |arg, i| { |
| 1020 | duped_args[i] = if (arg) |a| self.builder.dupe(a) else null; | 1020 | duped_args[i] = if (arg) |a| self.builder.dupe(a) else null; |
| 1021 | } | 1021 | } |
| 1022 | self.exec_cmd_args = duped_args; | 1022 | self.exec_cmd_args = duped_args; |
| ... | @@ -1040,7 +1040,7 @@ fn appendModuleArgs( | ... | @@ -1040,7 +1040,7 @@ fn appendModuleArgs( |
| 1040 | 1040 | ||
| 1041 | { | 1041 | { |
| 1042 | const keys = module.dependencies.keys(); | 1042 | const keys = module.dependencies.keys(); |
| 1043 | for (module.dependencies.values()) |sub_module, i| { | 1043 | for (module.dependencies.values(), 0..) |sub_module, i| { |
| 1044 | const sub_name = keys[i]; | 1044 | const sub_name = keys[i]; |
| 1045 | try cs.appendModuleArgs(zig_args, sub_name, sub_module); | 1045 | try cs.appendModuleArgs(zig_args, sub_name, sub_module); |
| 1046 | } | 1046 | } |
| ... | @@ -1575,7 +1575,7 @@ fn make(step: *Step) !void { | ... | @@ -1575,7 +1575,7 @@ fn make(step: *Step) !void { |
| 1575 | 1575 | ||
| 1576 | { | 1576 | { |
| 1577 | const keys = self.modules.keys(); | 1577 | const keys = self.modules.keys(); |
| 1578 | for (self.modules.values()) |module, i| { | 1578 | for (self.modules.values(), 0..) |module, i| { |
| 1579 | const name = keys[i]; | 1579 | const name = keys[i]; |
| 1580 | try self.appendModuleArgs(&zig_args, name, module); | 1580 | try self.appendModuleArgs(&zig_args, name, module); |
| 1581 | } | 1581 | } |
| ... | @@ -1750,7 +1750,7 @@ fn make(step: *Step) !void { | ... | @@ -1750,7 +1750,7 @@ fn make(step: *Step) !void { |
| 1750 | const args_to_escape = zig_args.items[2..]; | 1750 | const args_to_escape = zig_args.items[2..]; |
| 1751 | var escaped_args = try ArrayList([]const u8).initCapacity(builder.allocator, args_to_escape.len); | 1751 | var escaped_args = try ArrayList([]const u8).initCapacity(builder.allocator, args_to_escape.len); |
| 1752 | arg_blk: for (args_to_escape) |arg| { | 1752 | arg_blk: for (args_to_escape) |arg| { |
| 1753 | for (arg) |c, arg_idx| { | 1753 | for (arg, 0..) |c, arg_idx| { |
| 1754 | if (c == '\\' or c == '"') { | 1754 | if (c == '\\' or c == '"') { |
| 1755 | // Slow path for arguments that need to be escaped. We'll need to allocate and copy | 1755 | // Slow path for arguments that need to be escaped. We'll need to allocate and copy |
| 1756 | var escaped = try ArrayList(u8).initCapacity(builder.allocator, arg.len + 1); | 1756 | var escaped = try ArrayList(u8).initCapacity(builder.allocator, arg.len + 1); |
lib/std/Build/ConfigHeaderStep.zig+2-2| ... | @@ -350,7 +350,7 @@ fn render_blank( | ... | @@ -350,7 +350,7 @@ fn render_blank( |
| 350 | try output.appendSlice("\n"); | 350 | try output.appendSlice("\n"); |
| 351 | 351 | ||
| 352 | const values = defines.values(); | 352 | const values = defines.values(); |
| 353 | for (defines.keys()) |name, i| { | 353 | for (defines.keys(), 0..) |name, i| { |
| 354 | try renderValueC(output, name, values[i]); | 354 | try renderValueC(output, name, values[i]); |
| 355 | } | 355 | } |
| 356 | 356 | ||
| ... | @@ -361,7 +361,7 @@ fn render_blank( | ... | @@ -361,7 +361,7 @@ fn render_blank( |
| 361 | 361 | ||
| 362 | fn render_nasm(output: *std.ArrayList(u8), defines: std.StringArrayHashMap(Value)) !void { | 362 | fn render_nasm(output: *std.ArrayList(u8), defines: std.StringArrayHashMap(Value)) !void { |
| 363 | const values = defines.values(); | 363 | const values = defines.values(); |
| 364 | for (defines.keys()) |name, i| { | 364 | for (defines.keys(), 0..) |name, i| { |
| 365 | try renderValueNasm(output, name, values[i]); | 365 | try renderValueNasm(output, name, values[i]); |
| 366 | } | 366 | } |
| 367 | } | 367 | } |
lib/std/Build/FmtStep.zig+1-1| ... | @@ -19,7 +19,7 @@ pub fn create(builder: *std.Build, paths: []const []const u8) *FmtStep { | ... | @@ -19,7 +19,7 @@ pub fn create(builder: *std.Build, paths: []const []const u8) *FmtStep { |
| 19 | 19 | ||
| 20 | self.argv[0] = builder.zig_exe; | 20 | self.argv[0] = builder.zig_exe; |
| 21 | self.argv[1] = "fmt"; | 21 | self.argv[1] = "fmt"; |
| 22 | for (paths) |path, i| { | 22 | for (paths, 0..) |path, i| { |
| 23 | self.argv[2 + i] = builder.pathFromRoot(path); | 23 | self.argv[2 + i] = builder.pathFromRoot(path); |
| 24 | } | 24 | } |
| 25 | return self; | 25 | return self; |
lib/std/Build/RunStep.zig+5-4| ... | @@ -188,6 +188,10 @@ fn stdIoActionToBehavior(action: StdIoAction) std.ChildProcess.StdIo { | ... | @@ -188,6 +188,10 @@ fn stdIoActionToBehavior(action: StdIoAction) std.ChildProcess.StdIo { |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | fn needOutputCheck(self: RunStep) bool { | 190 | fn needOutputCheck(self: RunStep) bool { |
| 191 | switch (self.condition) { | ||
| 192 | .always => return false, | ||
| 193 | .output_outdated => {}, | ||
| 194 | } | ||
| 191 | if (self.extra_file_dependencies.len > 0) return true; | 195 | if (self.extra_file_dependencies.len > 0) return true; |
| 192 | 196 | ||
| 193 | for (self.argv.items) |arg| switch (arg) { | 197 | for (self.argv.items) |arg| switch (arg) { |
| ... | @@ -195,10 +199,7 @@ fn needOutputCheck(self: RunStep) bool { | ... | @@ -195,10 +199,7 @@ fn needOutputCheck(self: RunStep) bool { |
| 195 | else => continue, | 199 | else => continue, |
| 196 | }; | 200 | }; |
| 197 | 201 | ||
| 198 | return switch (self.condition) { | 202 | return false; |
| 199 | .always => false, | ||
| 200 | .output_outdated => true, | ||
| 201 | }; | ||
| 202 | } | 203 | } |
| 203 | 204 | ||
| 204 | fn make(step: *Step) !void { | 205 | fn make(step: *Step) !void { |
lib/std/Thread/Condition.zig+6-6| ... | @@ -341,7 +341,7 @@ test "Condition - wait and signal" { | ... | @@ -341,7 +341,7 @@ test "Condition - wait and signal" { |
| 341 | }; | 341 | }; |
| 342 | 342 | ||
| 343 | var multi_wait = MultiWait{}; | 343 | var multi_wait = MultiWait{}; |
| 344 | for (multi_wait.threads) |*t| { | 344 | for (&multi_wait.threads) |*t| { |
| 345 | t.* = try std.Thread.spawn(.{}, MultiWait.run, .{&multi_wait}); | 345 | t.* = try std.Thread.spawn(.{}, MultiWait.run, .{&multi_wait}); |
| 346 | } | 346 | } |
| 347 | 347 | ||
| ... | @@ -389,7 +389,7 @@ test "Condition - signal" { | ... | @@ -389,7 +389,7 @@ test "Condition - signal" { |
| 389 | }; | 389 | }; |
| 390 | 390 | ||
| 391 | var signal_test = SignalTest{}; | 391 | var signal_test = SignalTest{}; |
| 392 | for (signal_test.threads) |*t| { | 392 | for (&signal_test.threads) |*t| { |
| 393 | t.* = try std.Thread.spawn(.{}, SignalTest.run, .{&signal_test}); | 393 | t.* = try std.Thread.spawn(.{}, SignalTest.run, .{&signal_test}); |
| 394 | } | 394 | } |
| 395 | 395 | ||
| ... | @@ -457,7 +457,7 @@ test "Condition - multi signal" { | ... | @@ -457,7 +457,7 @@ test "Condition - multi signal" { |
| 457 | var threads = [_]std.Thread{undefined} ** num_threads; | 457 | var threads = [_]std.Thread{undefined} ** num_threads; |
| 458 | 458 | ||
| 459 | // Create a circle of paddles which hit each other | 459 | // Create a circle of paddles which hit each other |
| 460 | for (threads) |*t, i| { | 460 | for (&threads, 0..) |*t, i| { |
| 461 | const paddle = &paddles[i]; | 461 | const paddle = &paddles[i]; |
| 462 | const hit_to = &paddles[(i + 1) % paddles.len]; | 462 | const hit_to = &paddles[(i + 1) % paddles.len]; |
| 463 | t.* = try std.Thread.spawn(.{}, Paddle.run, .{ paddle, hit_to }); | 463 | t.* = try std.Thread.spawn(.{}, Paddle.run, .{ paddle, hit_to }); |
| ... | @@ -468,7 +468,7 @@ test "Condition - multi signal" { | ... | @@ -468,7 +468,7 @@ test "Condition - multi signal" { |
| 468 | for (threads) |t| t.join(); | 468 | for (threads) |t| t.join(); |
| 469 | 469 | ||
| 470 | // The first paddle will be hit one last time by the last paddle. | 470 | // The first paddle will be hit one last time by the last paddle. |
| 471 | for (paddles) |p, i| { | 471 | for (paddles, 0..) |p, i| { |
| 472 | const expected = @as(u32, num_iterations) + @boolToInt(i == 0); | 472 | const expected = @as(u32, num_iterations) + @boolToInt(i == 0); |
| 473 | try testing.expectEqual(p.value, expected); | 473 | try testing.expectEqual(p.value, expected); |
| 474 | } | 474 | } |
| ... | @@ -513,7 +513,7 @@ test "Condition - broadcasting" { | ... | @@ -513,7 +513,7 @@ test "Condition - broadcasting" { |
| 513 | }; | 513 | }; |
| 514 | 514 | ||
| 515 | var broadcast_test = BroadcastTest{}; | 515 | var broadcast_test = BroadcastTest{}; |
| 516 | for (broadcast_test.threads) |*t| { | 516 | for (&broadcast_test.threads) |*t| { |
| 517 | t.* = try std.Thread.spawn(.{}, BroadcastTest.run, .{&broadcast_test}); | 517 | t.* = try std.Thread.spawn(.{}, BroadcastTest.run, .{&broadcast_test}); |
| 518 | } | 518 | } |
| 519 | 519 | ||
| ... | @@ -584,7 +584,7 @@ test "Condition - broadcasting - wake all threads" { | ... | @@ -584,7 +584,7 @@ test "Condition - broadcasting - wake all threads" { |
| 584 | 584 | ||
| 585 | var broadcast_test = BroadcastTest{}; | 585 | var broadcast_test = BroadcastTest{}; |
| 586 | var thread_id: usize = 1; | 586 | var thread_id: usize = 1; |
| 587 | for (broadcast_test.threads) |*t| { | 587 | for (&broadcast_test.threads) |*t| { |
| 588 | t.* = try std.Thread.spawn(.{}, BroadcastTest.run, .{ &broadcast_test, thread_id }); | 588 | t.* = try std.Thread.spawn(.{}, BroadcastTest.run, .{ &broadcast_test, thread_id }); |
| 589 | thread_id += 1; | 589 | thread_id += 1; |
| 590 | } | 590 | } |
lib/std/Thread/Futex.zig+3-3| ... | @@ -895,7 +895,7 @@ test "Futex - signaling" { | ... | @@ -895,7 +895,7 @@ test "Futex - signaling" { |
| 895 | var threads = [_]std.Thread{undefined} ** num_threads; | 895 | var threads = [_]std.Thread{undefined} ** num_threads; |
| 896 | 896 | ||
| 897 | // Create a circle of paddles which hit each other | 897 | // Create a circle of paddles which hit each other |
| 898 | for (threads) |*t, i| { | 898 | for (&threads, 0..) |*t, i| { |
| 899 | const paddle = &paddles[i]; | 899 | const paddle = &paddles[i]; |
| 900 | const hit_to = &paddles[(i + 1) % paddles.len]; | 900 | const hit_to = &paddles[(i + 1) % paddles.len]; |
| 901 | t.* = try std.Thread.spawn(.{}, Paddle.run, .{ paddle, hit_to }); | 901 | t.* = try std.Thread.spawn(.{}, Paddle.run, .{ paddle, hit_to }); |
| ... | @@ -950,14 +950,14 @@ test "Futex - broadcasting" { | ... | @@ -950,14 +950,14 @@ test "Futex - broadcasting" { |
| 950 | threads: [num_threads]std.Thread = undefined, | 950 | threads: [num_threads]std.Thread = undefined, |
| 951 | 951 | ||
| 952 | fn run(self: *@This()) !void { | 952 | fn run(self: *@This()) !void { |
| 953 | for (self.barriers) |*barrier| { | 953 | for (&self.barriers) |*barrier| { |
| 954 | try barrier.wait(); | 954 | try barrier.wait(); |
| 955 | } | 955 | } |
| 956 | } | 956 | } |
| 957 | }; | 957 | }; |
| 958 | 958 | ||
| 959 | var broadcast = Broadcast{}; | 959 | var broadcast = Broadcast{}; |
| 960 | for (broadcast.threads) |*t| t.* = try std.Thread.spawn(.{}, Broadcast.run, .{&broadcast}); | 960 | for (&broadcast.threads) |*t| t.* = try std.Thread.spawn(.{}, Broadcast.run, .{&broadcast}); |
| 961 | for (broadcast.threads) |t| t.join(); | 961 | for (broadcast.threads) |t| t.join(); |
| 962 | } | 962 | } |
| 963 | 963 |
lib/std/Thread/Mutex.zig+3-3| ... | @@ -245,7 +245,7 @@ const NonAtomicCounter = struct { | ... | @@ -245,7 +245,7 @@ const NonAtomicCounter = struct { |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | fn inc(self: *NonAtomicCounter) void { | 247 | fn inc(self: *NonAtomicCounter) void { |
| 248 | for (@bitCast([2]u64, self.get() + 1)) |v, i| { | 248 | for (@bitCast([2]u64, self.get() + 1), 0..) |v, i| { |
| 249 | @ptrCast(*volatile u64, &self.value[i]).* = v; | 249 | @ptrCast(*volatile u64, &self.value[i]).* = v; |
| 250 | } | 250 | } |
| 251 | } | 251 | } |
| ... | @@ -277,7 +277,7 @@ test "Mutex - many uncontended" { | ... | @@ -277,7 +277,7 @@ test "Mutex - many uncontended" { |
| 277 | }; | 277 | }; |
| 278 | 278 | ||
| 279 | var runners = [_]Runner{.{}} ** num_threads; | 279 | var runners = [_]Runner{.{}} ** num_threads; |
| 280 | for (runners) |*r| r.thread = try Thread.spawn(.{}, Runner.run, .{r}); | 280 | for (&runners) |*r| r.thread = try Thread.spawn(.{}, Runner.run, .{r}); |
| 281 | for (runners) |r| r.thread.join(); | 281 | for (runners) |r| r.thread.join(); |
| 282 | for (runners) |r| try testing.expectEqual(r.counter.get(), num_increments); | 282 | for (runners) |r| try testing.expectEqual(r.counter.get(), num_increments); |
| 283 | } | 283 | } |
| ... | @@ -312,7 +312,7 @@ test "Mutex - many contended" { | ... | @@ -312,7 +312,7 @@ test "Mutex - many contended" { |
| 312 | var runner = Runner{}; | 312 | var runner = Runner{}; |
| 313 | 313 | ||
| 314 | var threads: [num_threads]Thread = undefined; | 314 | var threads: [num_threads]Thread = undefined; |
| 315 | for (threads) |*t| t.* = try Thread.spawn(.{}, Runner.run, .{&runner}); | 315 | for (&threads) |*t| t.* = try Thread.spawn(.{}, Runner.run, .{&runner}); |
| 316 | for (threads) |t| t.join(); | 316 | for (threads) |t| t.join(); |
| 317 | 317 | ||
| 318 | try testing.expectEqual(runner.counter.get(), num_increments * num_threads); | 318 | try testing.expectEqual(runner.counter.get(), num_increments * num_threads); |
lib/std/Thread/ResetEvent.zig+1-1| ... | @@ -274,7 +274,7 @@ test "ResetEvent - broadcast" { | ... | @@ -274,7 +274,7 @@ test "ResetEvent - broadcast" { |
| 274 | var ctx = Context{}; | 274 | var ctx = Context{}; |
| 275 | var threads: [num_threads - 1]std.Thread = undefined; | 275 | var threads: [num_threads - 1]std.Thread = undefined; |
| 276 | 276 | ||
| 277 | for (threads) |*t| t.* = try std.Thread.spawn(.{}, Context.run, .{&ctx}); | 277 | for (&threads) |*t| t.* = try std.Thread.spawn(.{}, Context.run, .{&ctx}); |
| 278 | defer for (threads) |t| t.join(); | 278 | defer for (threads) |t| t.join(); |
| 279 | 279 | ||
| 280 | ctx.run(); | 280 | ctx.run(); |
lib/std/Thread/RwLock.zig+1-1| ... | @@ -364,7 +364,7 @@ test "RwLock - concurrent access" { | ... | @@ -364,7 +364,7 @@ test "RwLock - concurrent access" { |
| 364 | var runner = Runner{}; | 364 | var runner = Runner{}; |
| 365 | var threads: [num_writers + num_readers]std.Thread = undefined; | 365 | var threads: [num_writers + num_readers]std.Thread = undefined; |
| 366 | 366 | ||
| 367 | for (threads[0..num_writers]) |*t, i| t.* = try std.Thread.spawn(.{}, Runner.writer, .{ &runner, i }); | 367 | for (threads[0..num_writers], 0..) |*t, i| t.* = try std.Thread.spawn(.{}, Runner.writer, .{ &runner, i }); |
| 368 | for (threads[num_writers..]) |*t| t.* = try std.Thread.spawn(.{}, Runner.reader, .{&runner}); | 368 | for (threads[num_writers..]) |*t| t.* = try std.Thread.spawn(.{}, Runner.reader, .{&runner}); |
| 369 | 369 | ||
| 370 | for (threads) |t| t.join(); | 370 | for (threads) |t| t.join(); |
lib/std/Thread/Semaphore.zig+1-1| ... | @@ -54,7 +54,7 @@ test "Thread.Semaphore" { | ... | @@ -54,7 +54,7 @@ test "Thread.Semaphore" { |
| 54 | var n: i32 = 0; | 54 | var n: i32 = 0; |
| 55 | var ctx = TestContext{ .sem = &sem, .n = &n }; | 55 | var ctx = TestContext{ .sem = &sem, .n = &n }; |
| 56 | 56 | ||
| 57 | for (threads) |*t| t.* = try std.Thread.spawn(.{}, TestContext.worker, .{&ctx}); | 57 | for (&threads) |*t| t.* = try std.Thread.spawn(.{}, TestContext.worker, .{&ctx}); |
| 58 | for (threads) |t| t.join(); | 58 | for (threads) |t| t.join(); |
| 59 | sem.wait(); | 59 | sem.wait(); |
| 60 | try testing.expect(n == num_threads); | 60 | try testing.expect(n == num_threads); |
lib/std/array_hash_map.zig+10-10| ... | @@ -715,7 +715,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -715,7 +715,7 @@ pub fn ArrayHashMapUnmanaged( |
| 715 | const slice = self.entries.slice(); | 715 | const slice = self.entries.slice(); |
| 716 | const hashes_array = slice.items(.hash); | 716 | const hashes_array = slice.items(.hash); |
| 717 | const keys_array = slice.items(.key); | 717 | const keys_array = slice.items(.key); |
| 718 | for (keys_array) |*item_key, i| { | 718 | for (keys_array, 0..) |*item_key, i| { |
| 719 | if (hashes_array[i] == h and checkedEql(ctx, key, item_key.*, i)) { | 719 | if (hashes_array[i] == h and checkedEql(ctx, key, item_key.*, i)) { |
| 720 | return GetOrPutResult{ | 720 | return GetOrPutResult{ |
| 721 | .key_ptr = item_key, | 721 | .key_ptr = item_key, |
| ... | @@ -946,7 +946,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -946,7 +946,7 @@ pub fn ArrayHashMapUnmanaged( |
| 946 | const slice = self.entries.slice(); | 946 | const slice = self.entries.slice(); |
| 947 | const hashes_array = slice.items(.hash); | 947 | const hashes_array = slice.items(.hash); |
| 948 | const keys_array = slice.items(.key); | 948 | const keys_array = slice.items(.key); |
| 949 | for (keys_array) |*item_key, i| { | 949 | for (keys_array, 0..) |*item_key, i| { |
| 950 | if (hashes_array[i] == h and checkedEql(ctx, key, item_key.*, i)) { | 950 | if (hashes_array[i] == h and checkedEql(ctx, key, item_key.*, i)) { |
| 951 | return i; | 951 | return i; |
| 952 | } | 952 | } |
| ... | @@ -1285,7 +1285,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1285,7 +1285,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1285 | const slice = self.entries.slice(); | 1285 | const slice = self.entries.slice(); |
| 1286 | const hashes_array = if (store_hash) slice.items(.hash) else {}; | 1286 | const hashes_array = if (store_hash) slice.items(.hash) else {}; |
| 1287 | const keys_array = slice.items(.key); | 1287 | const keys_array = slice.items(.key); |
| 1288 | for (keys_array) |*item_key, i| { | 1288 | for (keys_array, 0..) |*item_key, i| { |
| 1289 | const hash_match = if (store_hash) hashes_array[i] == key_hash else true; | 1289 | const hash_match = if (store_hash) hashes_array[i] == key_hash else true; |
| 1290 | if (hash_match and key_ctx.eql(key, item_key.*, i)) { | 1290 | if (hash_match and key_ctx.eql(key, item_key.*, i)) { |
| 1291 | const removed_entry: KV = .{ | 1291 | const removed_entry: KV = .{ |
| ... | @@ -1326,7 +1326,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1326,7 +1326,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1326 | const slice = self.entries.slice(); | 1326 | const slice = self.entries.slice(); |
| 1327 | const hashes_array = if (store_hash) slice.items(.hash) else {}; | 1327 | const hashes_array = if (store_hash) slice.items(.hash) else {}; |
| 1328 | const keys_array = slice.items(.key); | 1328 | const keys_array = slice.items(.key); |
| 1329 | for (keys_array) |*item_key, i| { | 1329 | for (keys_array, 0..) |*item_key, i| { |
| 1330 | const hash_match = if (store_hash) hashes_array[i] == key_hash else true; | 1330 | const hash_match = if (store_hash) hashes_array[i] == key_hash else true; |
| 1331 | if (hash_match and key_ctx.eql(key, item_key.*, i)) { | 1331 | if (hash_match and key_ctx.eql(key, item_key.*, i)) { |
| 1332 | switch (removal_type) { | 1332 | switch (removal_type) { |
| ... | @@ -1634,7 +1634,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1634,7 +1634,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1634 | const items = if (store_hash) slice.items(.hash) else slice.items(.key); | 1634 | const items = if (store_hash) slice.items(.hash) else slice.items(.key); |
| 1635 | const indexes = header.indexes(I); | 1635 | const indexes = header.indexes(I); |
| 1636 | 1636 | ||
| 1637 | entry_loop: for (items) |key, i| { | 1637 | entry_loop: for (items, 0..) |key, i| { |
| 1638 | const h = if (store_hash) key else checkedHash(ctx, key); | 1638 | const h = if (store_hash) key else checkedHash(ctx, key); |
| 1639 | const start_index = safeTruncate(usize, h); | 1639 | const start_index = safeTruncate(usize, h); |
| 1640 | const end_index = start_index +% indexes.len; | 1640 | const end_index = start_index +% indexes.len; |
| ... | @@ -1730,7 +1730,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1730,7 +1730,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1730 | const indexes = header.indexes(I); | 1730 | const indexes = header.indexes(I); |
| 1731 | if (indexes.len == 0) return; | 1731 | if (indexes.len == 0) return; |
| 1732 | var is_empty = false; | 1732 | var is_empty = false; |
| 1733 | for (indexes) |idx, i| { | 1733 | for (indexes, 0..) |idx, i| { |
| 1734 | if (idx.isEmpty()) { | 1734 | if (idx.isEmpty()) { |
| 1735 | is_empty = true; | 1735 | is_empty = true; |
| 1736 | } else { | 1736 | } else { |
| ... | @@ -1826,7 +1826,7 @@ const min_bit_index = 5; | ... | @@ -1826,7 +1826,7 @@ const min_bit_index = 5; |
| 1826 | const max_capacity = (1 << max_bit_index) - 1; | 1826 | const max_capacity = (1 << max_bit_index) - 1; |
| 1827 | const index_capacities = blk: { | 1827 | const index_capacities = blk: { |
| 1828 | var caps: [max_bit_index + 1]u32 = undefined; | 1828 | var caps: [max_bit_index + 1]u32 = undefined; |
| 1829 | for (caps[0..max_bit_index]) |*item, i| { | 1829 | for (caps[0..max_bit_index], 0..) |*item, i| { |
| 1830 | item.* = (1 << i) * 3 / 5; | 1830 | item.* = (1 << i) * 3 / 5; |
| 1831 | } | 1831 | } |
| 1832 | caps[max_bit_index] = max_capacity; | 1832 | caps[max_bit_index] = max_capacity; |
| ... | @@ -2025,7 +2025,7 @@ test "iterator hash map" { | ... | @@ -2025,7 +2025,7 @@ test "iterator hash map" { |
| 2025 | try testing.expect(count == 3); | 2025 | try testing.expect(count == 3); |
| 2026 | try testing.expect(it.next() == null); | 2026 | try testing.expect(it.next() == null); |
| 2027 | 2027 | ||
| 2028 | for (buffer) |_, i| { | 2028 | for (buffer, 0..) |_, i| { |
| 2029 | try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]); | 2029 | try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]); |
| 2030 | } | 2030 | } |
| 2031 | 2031 | ||
| ... | @@ -2037,7 +2037,7 @@ test "iterator hash map" { | ... | @@ -2037,7 +2037,7 @@ test "iterator hash map" { |
| 2037 | if (count >= 2) break; | 2037 | if (count >= 2) break; |
| 2038 | } | 2038 | } |
| 2039 | 2039 | ||
| 2040 | for (buffer[0..2]) |_, i| { | 2040 | for (buffer[0..2], 0..) |_, i| { |
| 2041 | try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]); | 2041 | try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]); |
| 2042 | } | 2042 | } |
| 2043 | 2043 | ||
| ... | @@ -2299,7 +2299,7 @@ test "sort" { | ... | @@ -2299,7 +2299,7 @@ test "sort" { |
| 2299 | map.sort(C{ .keys = map.keys() }); | 2299 | map.sort(C{ .keys = map.keys() }); |
| 2300 | 2300 | ||
| 2301 | var x: i32 = 1; | 2301 | var x: i32 = 1; |
| 2302 | for (map.keys()) |key, i| { | 2302 | for (map.keys(), 0..) |key, i| { |
| 2303 | try testing.expect(key == x); | 2303 | try testing.expect(key == x); |
| 2304 | try testing.expect(map.values()[i] == x * 3); | 2304 | try testing.expect(map.values()[i] == x * 3); |
| 2305 | x += 1; | 2305 | x += 1; |
lib/std/array_list.zig+5-5| ... | @@ -183,7 +183,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { | ... | @@ -183,7 +183,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 183 | mem.copy(T, range, new_items); | 183 | mem.copy(T, range, new_items); |
| 184 | const after_subrange = start + new_items.len; | 184 | const after_subrange = start + new_items.len; |
| 185 | 185 | ||
| 186 | for (self.items[after_range..]) |item, i| { | 186 | for (self.items[after_range..], 0..) |item, i| { |
| 187 | self.items[after_subrange..][i] = item; | 187 | self.items[after_subrange..][i] = item; |
| 188 | } | 188 | } |
| 189 | 189 | ||
| ... | @@ -216,7 +216,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { | ... | @@ -216,7 +216,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 216 | if (newlen == i) return self.pop(); | 216 | if (newlen == i) return self.pop(); |
| 217 | 217 | ||
| 218 | const old_item = self.items[i]; | 218 | const old_item = self.items[i]; |
| 219 | for (self.items[i..newlen]) |*b, j| b.* = self.items[i + 1 + j]; | 219 | for (self.items[i..newlen], 0..) |*b, j| b.* = self.items[i + 1 + j]; |
| 220 | self.items[newlen] = undefined; | 220 | self.items[newlen] = undefined; |
| 221 | self.items.len = newlen; | 221 | self.items.len = newlen; |
| 222 | return old_item; | 222 | return old_item; |
| ... | @@ -666,7 +666,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -666,7 +666,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 666 | if (newlen == i) return self.pop(); | 666 | if (newlen == i) return self.pop(); |
| 667 | 667 | ||
| 668 | const old_item = self.items[i]; | 668 | const old_item = self.items[i]; |
| 669 | for (self.items[i..newlen]) |*b, j| b.* = self.items[i + 1 + j]; | 669 | for (self.items[i..newlen], 0..) |*b, j| b.* = self.items[i + 1 + j]; |
| 670 | self.items[newlen] = undefined; | 670 | self.items[newlen] = undefined; |
| 671 | self.items.len = newlen; | 671 | self.items.len = newlen; |
| 672 | return old_item; | 672 | return old_item; |
| ... | @@ -1069,7 +1069,7 @@ test "std.ArrayList/ArrayListUnmanaged.basic" { | ... | @@ -1069,7 +1069,7 @@ test "std.ArrayList/ArrayListUnmanaged.basic" { |
| 1069 | } | 1069 | } |
| 1070 | } | 1070 | } |
| 1071 | 1071 | ||
| 1072 | for (list.items) |v, i| { | 1072 | for (list.items, 0..) |v, i| { |
| 1073 | try testing.expect(v == @intCast(i32, i + 1)); | 1073 | try testing.expect(v == @intCast(i32, i + 1)); |
| 1074 | } | 1074 | } |
| 1075 | 1075 | ||
| ... | @@ -1119,7 +1119,7 @@ test "std.ArrayList/ArrayListUnmanaged.basic" { | ... | @@ -1119,7 +1119,7 @@ test "std.ArrayList/ArrayListUnmanaged.basic" { |
| 1119 | } | 1119 | } |
| 1120 | } | 1120 | } |
| 1121 | 1121 | ||
| 1122 | for (list.items) |v, i| { | 1122 | for (list.items, 0..) |v, i| { |
| 1123 | try testing.expect(v == @intCast(i32, i + 1)); | 1123 | try testing.expect(v == @intCast(i32, i + 1)); |
| 1124 | } | 1124 | } |
| 1125 | 1125 |
lib/std/ascii.zig+3-3| ... | @@ -272,7 +272,7 @@ test "ASCII character classes" { | ... | @@ -272,7 +272,7 @@ test "ASCII character classes" { |
| 272 | /// Asserts `output.len >= ascii_string.len`. | 272 | /// Asserts `output.len >= ascii_string.len`. |
| 273 | pub fn lowerString(output: []u8, ascii_string: []const u8) []u8 { | 273 | pub fn lowerString(output: []u8, ascii_string: []const u8) []u8 { |
| 274 | std.debug.assert(output.len >= ascii_string.len); | 274 | std.debug.assert(output.len >= ascii_string.len); |
| 275 | for (ascii_string) |c, i| { | 275 | for (ascii_string, 0..) |c, i| { |
| 276 | output[i] = toLower(c); | 276 | output[i] = toLower(c); |
| 277 | } | 277 | } |
| 278 | return output[0..ascii_string.len]; | 278 | return output[0..ascii_string.len]; |
| ... | @@ -301,7 +301,7 @@ test "allocLowerString" { | ... | @@ -301,7 +301,7 @@ test "allocLowerString" { |
| 301 | /// Asserts `output.len >= ascii_string.len`. | 301 | /// Asserts `output.len >= ascii_string.len`. |
| 302 | pub fn upperString(output: []u8, ascii_string: []const u8) []u8 { | 302 | pub fn upperString(output: []u8, ascii_string: []const u8) []u8 { |
| 303 | std.debug.assert(output.len >= ascii_string.len); | 303 | std.debug.assert(output.len >= ascii_string.len); |
| 304 | for (ascii_string) |c, i| { | 304 | for (ascii_string, 0..) |c, i| { |
| 305 | output[i] = toUpper(c); | 305 | output[i] = toUpper(c); |
| 306 | } | 306 | } |
| 307 | return output[0..ascii_string.len]; | 307 | return output[0..ascii_string.len]; |
| ... | @@ -329,7 +329,7 @@ test "allocUpperString" { | ... | @@ -329,7 +329,7 @@ test "allocUpperString" { |
| 329 | /// Compares strings `a` and `b` case-insensitively and returns whether they are equal. | 329 | /// Compares strings `a` and `b` case-insensitively and returns whether they are equal. |
| 330 | pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool { | 330 | pub fn eqlIgnoreCase(a: []const u8, b: []const u8) bool { |
| 331 | if (a.len != b.len) return false; | 331 | if (a.len != b.len) return false; |
| 332 | for (a) |a_c, i| { | 332 | for (a, 0..) |a_c, i| { |
| 333 | if (toLower(a_c) != toLower(b[i])) return false; | 333 | if (toLower(a_c) != toLower(b[i])) return false; |
| 334 | } | 334 | } |
| 335 | return true; | 335 | return true; |
lib/std/atomic/Atomic.zig+6-6| ... | @@ -548,7 +548,7 @@ test "Atomic.bitSet" { | ... | @@ -548,7 +548,7 @@ test "Atomic.bitSet" { |
| 548 | var x = Atomic(Int).init(0); | 548 | var x = Atomic(Int).init(0); |
| 549 | const bit_array = @as([@bitSizeOf(Int)]void, undefined); | 549 | const bit_array = @as([@bitSizeOf(Int)]void, undefined); |
| 550 | 550 | ||
| 551 | for (bit_array) |_, bit_index| { | 551 | for (bit_array, 0..) |_, bit_index| { |
| 552 | const bit = @intCast(std.math.Log2Int(Int), bit_index); | 552 | const bit = @intCast(std.math.Log2Int(Int), bit_index); |
| 553 | const mask = @as(Int, 1) << bit; | 553 | const mask = @as(Int, 1) << bit; |
| 554 | 554 | ||
| ... | @@ -562,7 +562,7 @@ test "Atomic.bitSet" { | ... | @@ -562,7 +562,7 @@ test "Atomic.bitSet" { |
| 562 | try testing.expect(x.load(.SeqCst) & mask != 0); | 562 | try testing.expect(x.load(.SeqCst) & mask != 0); |
| 563 | 563 | ||
| 564 | // all the previous bits should have not changed (still be set) | 564 | // all the previous bits should have not changed (still be set) |
| 565 | for (bit_array[0..bit_index]) |_, prev_bit_index| { | 565 | for (bit_array[0..bit_index], 0..) |_, prev_bit_index| { |
| 566 | const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index); | 566 | const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index); |
| 567 | const prev_mask = @as(Int, 1) << prev_bit; | 567 | const prev_mask = @as(Int, 1) << prev_bit; |
| 568 | try testing.expect(x.load(.SeqCst) & prev_mask != 0); | 568 | try testing.expect(x.load(.SeqCst) & prev_mask != 0); |
| ... | @@ -578,7 +578,7 @@ test "Atomic.bitReset" { | ... | @@ -578,7 +578,7 @@ test "Atomic.bitReset" { |
| 578 | var x = Atomic(Int).init(0); | 578 | var x = Atomic(Int).init(0); |
| 579 | const bit_array = @as([@bitSizeOf(Int)]void, undefined); | 579 | const bit_array = @as([@bitSizeOf(Int)]void, undefined); |
| 580 | 580 | ||
| 581 | for (bit_array) |_, bit_index| { | 581 | for (bit_array, 0..) |_, bit_index| { |
| 582 | const bit = @intCast(std.math.Log2Int(Int), bit_index); | 582 | const bit = @intCast(std.math.Log2Int(Int), bit_index); |
| 583 | const mask = @as(Int, 1) << bit; | 583 | const mask = @as(Int, 1) << bit; |
| 584 | x.storeUnchecked(x.loadUnchecked() | mask); | 584 | x.storeUnchecked(x.loadUnchecked() | mask); |
| ... | @@ -593,7 +593,7 @@ test "Atomic.bitReset" { | ... | @@ -593,7 +593,7 @@ test "Atomic.bitReset" { |
| 593 | try testing.expect(x.load(.SeqCst) & mask == 0); | 593 | try testing.expect(x.load(.SeqCst) & mask == 0); |
| 594 | 594 | ||
| 595 | // all the previous bits should have not changed (still be reset) | 595 | // all the previous bits should have not changed (still be reset) |
| 596 | for (bit_array[0..bit_index]) |_, prev_bit_index| { | 596 | for (bit_array[0..bit_index], 0..) |_, prev_bit_index| { |
| 597 | const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index); | 597 | const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index); |
| 598 | const prev_mask = @as(Int, 1) << prev_bit; | 598 | const prev_mask = @as(Int, 1) << prev_bit; |
| 599 | try testing.expect(x.load(.SeqCst) & prev_mask == 0); | 599 | try testing.expect(x.load(.SeqCst) & prev_mask == 0); |
| ... | @@ -609,7 +609,7 @@ test "Atomic.bitToggle" { | ... | @@ -609,7 +609,7 @@ test "Atomic.bitToggle" { |
| 609 | var x = Atomic(Int).init(0); | 609 | var x = Atomic(Int).init(0); |
| 610 | const bit_array = @as([@bitSizeOf(Int)]void, undefined); | 610 | const bit_array = @as([@bitSizeOf(Int)]void, undefined); |
| 611 | 611 | ||
| 612 | for (bit_array) |_, bit_index| { | 612 | for (bit_array, 0..) |_, bit_index| { |
| 613 | const bit = @intCast(std.math.Log2Int(Int), bit_index); | 613 | const bit = @intCast(std.math.Log2Int(Int), bit_index); |
| 614 | const mask = @as(Int, 1) << bit; | 614 | const mask = @as(Int, 1) << bit; |
| 615 | 615 | ||
| ... | @@ -623,7 +623,7 @@ test "Atomic.bitToggle" { | ... | @@ -623,7 +623,7 @@ test "Atomic.bitToggle" { |
| 623 | try testing.expect(x.load(.SeqCst) & mask == 0); | 623 | try testing.expect(x.load(.SeqCst) & mask == 0); |
| 624 | 624 | ||
| 625 | // all the previous bits should have not changed (still be toggled back) | 625 | // all the previous bits should have not changed (still be toggled back) |
| 626 | for (bit_array[0..bit_index]) |_, prev_bit_index| { | 626 | for (bit_array[0..bit_index], 0..) |_, prev_bit_index| { |
| 627 | const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index); | 627 | const prev_bit = @intCast(std.math.Log2Int(Int), prev_bit_index); |
| 628 | const prev_mask = @as(Int, 1) << prev_bit; | 628 | const prev_mask = @as(Int, 1) << prev_bit; |
| 629 | try testing.expect(x.load(.SeqCst) & prev_mask == 0); | 629 | try testing.expect(x.load(.SeqCst) & prev_mask == 0); |
lib/std/atomic/queue.zig+2-2| ... | @@ -212,11 +212,11 @@ test "std.atomic.Queue" { | ... | @@ -212,11 +212,11 @@ test "std.atomic.Queue" { |
| 212 | try expect(context.queue.isEmpty()); | 212 | try expect(context.queue.isEmpty()); |
| 213 | 213 | ||
| 214 | var putters: [put_thread_count]std.Thread = undefined; | 214 | var putters: [put_thread_count]std.Thread = undefined; |
| 215 | for (putters) |*t| { | 215 | for (&putters) |*t| { |
| 216 | t.* = try std.Thread.spawn(.{}, startPuts, .{&context}); | 216 | t.* = try std.Thread.spawn(.{}, startPuts, .{&context}); |
| 217 | } | 217 | } |
| 218 | var getters: [put_thread_count]std.Thread = undefined; | 218 | var getters: [put_thread_count]std.Thread = undefined; |
| 219 | for (getters) |*t| { | 219 | for (&getters) |*t| { |
| 220 | t.* = try std.Thread.spawn(.{}, startGets, .{&context}); | 220 | t.* = try std.Thread.spawn(.{}, startGets, .{&context}); |
| 221 | } | 221 | } |
| 222 | 222 |
lib/std/atomic/stack.zig+2-2| ... | @@ -117,11 +117,11 @@ test "std.atomic.stack" { | ... | @@ -117,11 +117,11 @@ test "std.atomic.stack" { |
| 117 | } | 117 | } |
| 118 | } else { | 118 | } else { |
| 119 | var putters: [put_thread_count]std.Thread = undefined; | 119 | var putters: [put_thread_count]std.Thread = undefined; |
| 120 | for (putters) |*t| { | 120 | for (&putters) |*t| { |
| 121 | t.* = try std.Thread.spawn(.{}, startPuts, .{&context}); | 121 | t.* = try std.Thread.spawn(.{}, startPuts, .{&context}); |
| 122 | } | 122 | } |
| 123 | var getters: [put_thread_count]std.Thread = undefined; | 123 | var getters: [put_thread_count]std.Thread = undefined; |
| 124 | for (getters) |*t| { | 124 | for (&getters) |*t| { |
| 125 | t.* = try std.Thread.spawn(.{}, startGets, .{&context}); | 125 | t.* = try std.Thread.spawn(.{}, startGets, .{&context}); |
| 126 | } | 126 | } |
| 127 | 127 |
lib/std/base64.zig+3-3| ... | @@ -140,7 +140,7 @@ pub const Base64Decoder = struct { | ... | @@ -140,7 +140,7 @@ pub const Base64Decoder = struct { |
| 140 | }; | 140 | }; |
| 141 | 141 | ||
| 142 | var char_in_alphabet = [_]bool{false} ** 256; | 142 | var char_in_alphabet = [_]bool{false} ** 256; |
| 143 | for (alphabet_chars) |c, i| { | 143 | for (alphabet_chars, 0..) |c, i| { |
| 144 | assert(!char_in_alphabet[c]); | 144 | assert(!char_in_alphabet[c]); |
| 145 | assert(pad_char == null or c != pad_char.?); | 145 | assert(pad_char == null or c != pad_char.?); |
| 146 | 146 | ||
| ... | @@ -185,7 +185,7 @@ pub const Base64Decoder = struct { | ... | @@ -185,7 +185,7 @@ pub const Base64Decoder = struct { |
| 185 | var acc_len: u4 = 0; | 185 | var acc_len: u4 = 0; |
| 186 | var dest_idx: usize = 0; | 186 | var dest_idx: usize = 0; |
| 187 | var leftover_idx: ?usize = null; | 187 | var leftover_idx: ?usize = null; |
| 188 | for (source) |c, src_idx| { | 188 | for (source, 0..) |c, src_idx| { |
| 189 | const d = decoder.char_to_index[c]; | 189 | const d = decoder.char_to_index[c]; |
| 190 | if (d == invalid_char) { | 190 | if (d == invalid_char) { |
| 191 | if (decoder.pad_char == null or c != decoder.pad_char.?) return error.InvalidCharacter; | 191 | if (decoder.pad_char == null or c != decoder.pad_char.?) return error.InvalidCharacter; |
| ... | @@ -258,7 +258,7 @@ pub const Base64DecoderWithIgnore = struct { | ... | @@ -258,7 +258,7 @@ pub const Base64DecoderWithIgnore = struct { |
| 258 | var acc_len: u4 = 0; | 258 | var acc_len: u4 = 0; |
| 259 | var dest_idx: usize = 0; | 259 | var dest_idx: usize = 0; |
| 260 | var leftover_idx: ?usize = null; | 260 | var leftover_idx: ?usize = null; |
| 261 | for (source) |c, src_idx| { | 261 | for (source, 0..) |c, src_idx| { |
| 262 | if (decoder_with_ignore.char_is_ignored[c]) continue; | 262 | if (decoder_with_ignore.char_is_ignored[c]) continue; |
| 263 | const d = decoder.char_to_index[c]; | 263 | const d = decoder.char_to_index[c]; |
| 264 | if (d == Base64Decoder.invalid_char) { | 264 | if (d == Base64Decoder.invalid_char) { |
lib/std/bit_set.zig+8-8| ... | @@ -494,14 +494,14 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { | ... | @@ -494,14 +494,14 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { |
| 494 | /// Flips all bits in this bit set which are present | 494 | /// Flips all bits in this bit set which are present |
| 495 | /// in the toggles bit set. | 495 | /// in the toggles bit set. |
| 496 | pub fn toggleSet(self: *Self, toggles: Self) void { | 496 | pub fn toggleSet(self: *Self, toggles: Self) void { |
| 497 | for (self.masks) |*mask, i| { | 497 | for (&self.masks, 0..) |*mask, i| { |
| 498 | mask.* ^= toggles.masks[i]; | 498 | mask.* ^= toggles.masks[i]; |
| 499 | } | 499 | } |
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | /// Flips every bit in the bit set. | 502 | /// Flips every bit in the bit set. |
| 503 | pub fn toggleAll(self: *Self) void { | 503 | pub fn toggleAll(self: *Self) void { |
| 504 | for (self.masks) |*mask| { | 504 | for (&self.masks) |*mask| { |
| 505 | mask.* = ~mask.*; | 505 | mask.* = ~mask.*; |
| 506 | } | 506 | } |
| 507 | 507 | ||
| ... | @@ -515,7 +515,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { | ... | @@ -515,7 +515,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { |
| 515 | /// result in the first one. Bits in the result are | 515 | /// result in the first one. Bits in the result are |
| 516 | /// set if the corresponding bits were set in either input. | 516 | /// set if the corresponding bits were set in either input. |
| 517 | pub fn setUnion(self: *Self, other: Self) void { | 517 | pub fn setUnion(self: *Self, other: Self) void { |
| 518 | for (self.masks) |*mask, i| { | 518 | for (&self.masks, 0..) |*mask, i| { |
| 519 | mask.* |= other.masks[i]; | 519 | mask.* |= other.masks[i]; |
| 520 | } | 520 | } |
| 521 | } | 521 | } |
| ... | @@ -524,7 +524,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { | ... | @@ -524,7 +524,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { |
| 524 | /// the result in the first one. Bits in the result are | 524 | /// the result in the first one. Bits in the result are |
| 525 | /// set if the corresponding bits were set in both inputs. | 525 | /// set if the corresponding bits were set in both inputs. |
| 526 | pub fn setIntersection(self: *Self, other: Self) void { | 526 | pub fn setIntersection(self: *Self, other: Self) void { |
| 527 | for (self.masks) |*mask, i| { | 527 | for (&self.masks, 0..) |*mask, i| { |
| 528 | mask.* &= other.masks[i]; | 528 | mask.* &= other.masks[i]; |
| 529 | } | 529 | } |
| 530 | } | 530 | } |
| ... | @@ -544,7 +544,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { | ... | @@ -544,7 +544,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { |
| 544 | /// If no bits are set, returns null. | 544 | /// If no bits are set, returns null. |
| 545 | pub fn toggleFirstSet(self: *Self) ?usize { | 545 | pub fn toggleFirstSet(self: *Self) ?usize { |
| 546 | var offset: usize = 0; | 546 | var offset: usize = 0; |
| 547 | const mask = for (self.masks) |*mask| { | 547 | const mask = for (&self.masks) |*mask| { |
| 548 | if (mask.* != 0) break mask; | 548 | if (mask.* != 0) break mask; |
| 549 | offset += @bitSizeOf(MaskInt); | 549 | offset += @bitSizeOf(MaskInt); |
| 550 | } else return null; | 550 | } else return null; |
| ... | @@ -869,7 +869,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -869,7 +869,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 869 | pub fn toggleSet(self: *Self, toggles: Self) void { | 869 | pub fn toggleSet(self: *Self, toggles: Self) void { |
| 870 | assert(toggles.bit_length == self.bit_length); | 870 | assert(toggles.bit_length == self.bit_length); |
| 871 | const num_masks = numMasks(self.bit_length); | 871 | const num_masks = numMasks(self.bit_length); |
| 872 | for (self.masks[0..num_masks]) |*mask, i| { | 872 | for (self.masks[0..num_masks], 0..) |*mask, i| { |
| 873 | mask.* ^= toggles.masks[i]; | 873 | mask.* ^= toggles.masks[i]; |
| 874 | } | 874 | } |
| 875 | } | 875 | } |
| ... | @@ -897,7 +897,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -897,7 +897,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 897 | pub fn setUnion(self: *Self, other: Self) void { | 897 | pub fn setUnion(self: *Self, other: Self) void { |
| 898 | assert(other.bit_length == self.bit_length); | 898 | assert(other.bit_length == self.bit_length); |
| 899 | const num_masks = numMasks(self.bit_length); | 899 | const num_masks = numMasks(self.bit_length); |
| 900 | for (self.masks[0..num_masks]) |*mask, i| { | 900 | for (self.masks[0..num_masks], 0..) |*mask, i| { |
| 901 | mask.* |= other.masks[i]; | 901 | mask.* |= other.masks[i]; |
| 902 | } | 902 | } |
| 903 | } | 903 | } |
| ... | @@ -909,7 +909,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -909,7 +909,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 909 | pub fn setIntersection(self: *Self, other: Self) void { | 909 | pub fn setIntersection(self: *Self, other: Self) void { |
| 910 | assert(other.bit_length == self.bit_length); | 910 | assert(other.bit_length == self.bit_length); |
| 911 | const num_masks = numMasks(self.bit_length); | 911 | const num_masks = numMasks(self.bit_length); |
| 912 | for (self.masks[0..num_masks]) |*mask, i| { | 912 | for (self.masks[0..num_masks], 0..) |*mask, i| { |
| 913 | mask.* &= other.masks[i]; | 913 | mask.* &= other.masks[i]; |
| 914 | } | 914 | } |
| 915 | } | 915 | } |
lib/std/bounded_array.zig+2-2| ... | @@ -169,7 +169,7 @@ pub fn BoundedArray(comptime T: type, comptime buffer_capacity: usize) type { | ... | @@ -169,7 +169,7 @@ pub fn BoundedArray(comptime T: type, comptime buffer_capacity: usize) type { |
| 169 | } else { | 169 | } else { |
| 170 | mem.copy(T, range, new_items); | 170 | mem.copy(T, range, new_items); |
| 171 | const after_subrange = start + new_items.len; | 171 | const after_subrange = start + new_items.len; |
| 172 | for (self.constSlice()[after_range..]) |item, i| { | 172 | for (self.constSlice()[after_range..], 0..) |item, i| { |
| 173 | self.slice()[after_subrange..][i] = item; | 173 | self.slice()[after_subrange..][i] = item; |
| 174 | } | 174 | } |
| 175 | self.len -= len - new_items.len; | 175 | self.len -= len - new_items.len; |
| ... | @@ -197,7 +197,7 @@ pub fn BoundedArray(comptime T: type, comptime buffer_capacity: usize) type { | ... | @@ -197,7 +197,7 @@ pub fn BoundedArray(comptime T: type, comptime buffer_capacity: usize) type { |
| 197 | const newlen = self.len - 1; | 197 | const newlen = self.len - 1; |
| 198 | if (newlen == i) return self.pop(); | 198 | if (newlen == i) return self.pop(); |
| 199 | const old_item = self.get(i); | 199 | const old_item = self.get(i); |
| 200 | for (self.slice()[i..newlen]) |*b, j| b.* = self.get(i + 1 + j); | 200 | for (self.slice()[i..newlen], 0..) |*b, j| b.* = self.get(i + 1 + j); |
| 201 | self.set(newlen, undefined); | 201 | self.set(newlen, undefined); |
| 202 | self.len = newlen; | 202 | self.len = newlen; |
| 203 | return old_item; | 203 | return old_item; |
lib/std/builtin.zig+1| ... | @@ -975,6 +975,7 @@ pub const panic_messages = struct { | ... | @@ -975,6 +975,7 @@ pub const panic_messages = struct { |
| 975 | pub const unwrap_error = "attempt to unwrap error"; | 975 | pub const unwrap_error = "attempt to unwrap error"; |
| 976 | pub const index_out_of_bounds = "index out of bounds"; | 976 | pub const index_out_of_bounds = "index out of bounds"; |
| 977 | pub const start_index_greater_than_end = "start index is larger than end index"; | 977 | pub const start_index_greater_than_end = "start index is larger than end index"; |
| 978 | pub const for_len_mismatch = "for loop over objects with non-equal lengths"; | ||
| 978 | }; | 979 | }; |
| 979 | 980 | ||
| 980 | pub noinline fn returnError(st: *StackTrace) void { | 981 | pub noinline fn returnError(st: *StackTrace) void { |
lib/std/child_process.zig+3-3| ... | @@ -604,7 +604,7 @@ pub const ChildProcess = struct { | ... | @@ -604,7 +604,7 @@ pub const ChildProcess = struct { |
| 604 | const arena = arena_allocator.allocator(); | 604 | const arena = arena_allocator.allocator(); |
| 605 | 605 | ||
| 606 | const argv_buf = try arena.allocSentinel(?[*:0]u8, self.argv.len, null); | 606 | const argv_buf = try arena.allocSentinel(?[*:0]u8, self.argv.len, null); |
| 607 | for (self.argv) |arg, i| argv_buf[i] = (try arena.dupeZ(u8, arg)).ptr; | 607 | for (self.argv, 0..) |arg, i| argv_buf[i] = (try arena.dupeZ(u8, arg)).ptr; |
| 608 | 608 | ||
| 609 | const envp = if (self.env_map) |env_map| m: { | 609 | const envp = if (self.env_map) |env_map| m: { |
| 610 | const envp_buf = try createNullDelimitedEnvMap(arena, env_map); | 610 | const envp_buf = try createNullDelimitedEnvMap(arena, env_map); |
| ... | @@ -712,7 +712,7 @@ pub const ChildProcess = struct { | ... | @@ -712,7 +712,7 @@ pub const ChildProcess = struct { |
| 712 | // Therefore, we do all the allocation for the execve() before the fork(). | 712 | // Therefore, we do all the allocation for the execve() before the fork(). |
| 713 | // This means we must do the null-termination of argv and env vars here. | 713 | // This means we must do the null-termination of argv and env vars here. |
| 714 | const argv_buf = try arena.allocSentinel(?[*:0]u8, self.argv.len, null); | 714 | const argv_buf = try arena.allocSentinel(?[*:0]u8, self.argv.len, null); |
| 715 | for (self.argv) |arg, i| argv_buf[i] = (try arena.dupeZ(u8, arg)).ptr; | 715 | for (self.argv, 0..) |arg, i| argv_buf[i] = (try arena.dupeZ(u8, arg)).ptr; |
| 716 | 716 | ||
| 717 | const envp = m: { | 717 | const envp = m: { |
| 718 | if (self.env_map) |env_map| { | 718 | if (self.env_map) |env_map| { |
| ... | @@ -1424,7 +1424,7 @@ fn windowsCreateCommandLine(allocator: mem.Allocator, argv: []const []const u8) | ... | @@ -1424,7 +1424,7 @@ fn windowsCreateCommandLine(allocator: mem.Allocator, argv: []const []const u8) |
| 1424 | var buf = std.ArrayList(u8).init(allocator); | 1424 | var buf = std.ArrayList(u8).init(allocator); |
| 1425 | defer buf.deinit(); | 1425 | defer buf.deinit(); |
| 1426 | 1426 | ||
| 1427 | for (argv) |arg, arg_i| { | 1427 | for (argv, 0..) |arg, arg_i| { |
| 1428 | if (arg_i != 0) try buf.append(' '); | 1428 | if (arg_i != 0) try buf.append(' '); |
| 1429 | if (mem.indexOfAny(u8, arg, " \t\n\"") == null) { | 1429 | if (mem.indexOfAny(u8, arg, " \t\n\"") == null) { |
| 1430 | try buf.appendSlice(arg); | 1430 | try buf.appendSlice(arg); |
lib/std/coff.zig+1-1| ... | @@ -1223,7 +1223,7 @@ pub const Coff = struct { | ... | @@ -1223,7 +1223,7 @@ pub const Coff = struct { |
| 1223 | pub fn getSectionHeadersAlloc(self: *const Coff, allocator: mem.Allocator) ![]SectionHeader { | 1223 | pub fn getSectionHeadersAlloc(self: *const Coff, allocator: mem.Allocator) ![]SectionHeader { |
| 1224 | const section_headers = self.getSectionHeaders(); | 1224 | const section_headers = self.getSectionHeaders(); |
| 1225 | const out_buff = try allocator.alloc(SectionHeader, section_headers.len); | 1225 | const out_buff = try allocator.alloc(SectionHeader, section_headers.len); |
| 1226 | for (out_buff) |*section_header, i| { | 1226 | for (out_buff, 0..) |*section_header, i| { |
| 1227 | section_header.* = section_headers[i]; | 1227 | section_header.* = section_headers[i]; |
| 1228 | } | 1228 | } |
| 1229 | 1229 |
lib/std/compress/deflate/compressor.zig+5-5| ... | @@ -159,7 +159,7 @@ fn levels(compression: Compression) CompressionLevel { | ... | @@ -159,7 +159,7 @@ fn levels(compression: Compression) CompressionLevel { |
| 159 | fn matchLen(a: []u8, b: []u8, max: u32) u32 { | 159 | fn matchLen(a: []u8, b: []u8, max: u32) u32 { |
| 160 | var bounded_a = a[0..max]; | 160 | var bounded_a = a[0..max]; |
| 161 | var bounded_b = b[0..max]; | 161 | var bounded_b = b[0..max]; |
| 162 | for (bounded_a) |av, i| { | 162 | for (bounded_a, 0..) |av, i| { |
| 163 | if (bounded_b[i] != av) { | 163 | if (bounded_b[i] != av) { |
| 164 | return @intCast(u32, i); | 164 | return @intCast(u32, i); |
| 165 | } | 165 | } |
| ... | @@ -312,14 +312,14 @@ pub fn Compressor(comptime WriterType: anytype) type { | ... | @@ -312,14 +312,14 @@ pub fn Compressor(comptime WriterType: anytype) type { |
| 312 | 312 | ||
| 313 | // Iterate over slices instead of arrays to avoid copying | 313 | // Iterate over slices instead of arrays to avoid copying |
| 314 | // the entire table onto the stack (https://golang.org/issue/18625). | 314 | // the entire table onto the stack (https://golang.org/issue/18625). |
| 315 | for (self.hash_prev) |v, i| { | 315 | for (self.hash_prev, 0..) |v, i| { |
| 316 | if (v > delta) { | 316 | if (v > delta) { |
| 317 | self.hash_prev[i] = @intCast(u32, v - delta); | 317 | self.hash_prev[i] = @intCast(u32, v - delta); |
| 318 | } else { | 318 | } else { |
| 319 | self.hash_prev[i] = 0; | 319 | self.hash_prev[i] = 0; |
| 320 | } | 320 | } |
| 321 | } | 321 | } |
| 322 | for (self.hash_head) |v, i| { | 322 | for (self.hash_head, 0..) |v, i| { |
| 323 | if (v > delta) { | 323 | if (v > delta) { |
| 324 | self.hash_head[i] = @intCast(u32, v - delta); | 324 | self.hash_head[i] = @intCast(u32, v - delta); |
| 325 | } else { | 325 | } else { |
| ... | @@ -391,7 +391,7 @@ pub fn Compressor(comptime WriterType: anytype) type { | ... | @@ -391,7 +391,7 @@ pub fn Compressor(comptime WriterType: anytype) type { |
| 391 | var dst = self.hash_match[0..dst_size]; | 391 | var dst = self.hash_match[0..dst_size]; |
| 392 | _ = self.bulk_hasher(to_check, dst); | 392 | _ = self.bulk_hasher(to_check, dst); |
| 393 | var new_h: u32 = 0; | 393 | var new_h: u32 = 0; |
| 394 | for (dst) |val, i| { | 394 | for (dst, 0..) |val, i| { |
| 395 | var di = i + index; | 395 | var di = i + index; |
| 396 | new_h = val; | 396 | new_h = val; |
| 397 | var hh = &self.hash_head[new_h & hash_mask]; | 397 | var hh = &self.hash_head[new_h & hash_mask]; |
| ... | @@ -1102,7 +1102,7 @@ test "bulkHash4" { | ... | @@ -1102,7 +1102,7 @@ test "bulkHash4" { |
| 1102 | defer testing.allocator.free(dst); | 1102 | defer testing.allocator.free(dst); |
| 1103 | 1103 | ||
| 1104 | _ = bulkHash4(y, dst); | 1104 | _ = bulkHash4(y, dst); |
| 1105 | for (dst) |got, i| { | 1105 | for (dst, 0..) |got, i| { |
| 1106 | var want = hash4(y[i..]); | 1106 | var want = hash4(y[i..]); |
| 1107 | try testing.expectEqual(want, got); | 1107 | try testing.expectEqual(want, got); |
| 1108 | } | 1108 | } |
lib/std/compress/deflate/compressor_test.zig+4-4| ... | @@ -171,7 +171,7 @@ test "deflate/inflate" { | ... | @@ -171,7 +171,7 @@ test "deflate/inflate" { |
| 171 | var large_data_chunk = try testing.allocator.alloc(u8, 100_000); | 171 | var large_data_chunk = try testing.allocator.alloc(u8, 100_000); |
| 172 | defer testing.allocator.free(large_data_chunk); | 172 | defer testing.allocator.free(large_data_chunk); |
| 173 | // fill with random data | 173 | // fill with random data |
| 174 | for (large_data_chunk) |_, i| { | 174 | for (large_data_chunk, 0..) |_, i| { |
| 175 | large_data_chunk[i] = @truncate(u8, i) *% @truncate(u8, i); | 175 | large_data_chunk[i] = @truncate(u8, i) *% @truncate(u8, i); |
| 176 | } | 176 | } |
| 177 | try testToFromWithLimit(large_data_chunk, limits); | 177 | try testToFromWithLimit(large_data_chunk, limits); |
| ... | @@ -205,7 +205,7 @@ test "very long sparse chunk" { | ... | @@ -205,7 +205,7 @@ test "very long sparse chunk" { |
| 205 | n -= cur - s.l; | 205 | n -= cur - s.l; |
| 206 | cur = s.l; | 206 | cur = s.l; |
| 207 | } | 207 | } |
| 208 | for (b[0..n]) |_, i| { | 208 | for (b[0..n], 0..) |_, i| { |
| 209 | if (s.cur + i >= s.l -| (1 << 16)) { | 209 | if (s.cur + i >= s.l -| (1 << 16)) { |
| 210 | b[i] = 1; | 210 | b[i] = 1; |
| 211 | } else { | 211 | } else { |
| ... | @@ -451,7 +451,7 @@ test "inflate reset" { | ... | @@ -451,7 +451,7 @@ test "inflate reset" { |
| 451 | defer compressed_strings[0].deinit(); | 451 | defer compressed_strings[0].deinit(); |
| 452 | defer compressed_strings[1].deinit(); | 452 | defer compressed_strings[1].deinit(); |
| 453 | 453 | ||
| 454 | for (strings) |s, i| { | 454 | for (strings, 0..) |s, i| { |
| 455 | var comp = try compressor( | 455 | var comp = try compressor( |
| 456 | testing.allocator, | 456 | testing.allocator, |
| 457 | compressed_strings[i].writer(), | 457 | compressed_strings[i].writer(), |
| ... | @@ -498,7 +498,7 @@ test "inflate reset dictionary" { | ... | @@ -498,7 +498,7 @@ test "inflate reset dictionary" { |
| 498 | defer compressed_strings[0].deinit(); | 498 | defer compressed_strings[0].deinit(); |
| 499 | defer compressed_strings[1].deinit(); | 499 | defer compressed_strings[1].deinit(); |
| 500 | 500 | ||
| 501 | for (strings) |s, i| { | 501 | for (strings, 0..) |s, i| { |
| 502 | var comp = try compressor( | 502 | var comp = try compressor( |
| 503 | testing.allocator, | 503 | testing.allocator, |
| 504 | compressed_strings[i].writer(), | 504 | compressed_strings[i].writer(), |
lib/std/compress/deflate/decompressor.zig+2-2| ... | @@ -165,7 +165,7 @@ const HuffmanDecoder = struct { | ... | @@ -165,7 +165,7 @@ const HuffmanDecoder = struct { |
| 165 | } | 165 | } |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | for (lengths) |n, li| { | 168 | for (lengths, 0..) |n, li| { |
| 169 | if (n == 0) { | 169 | if (n == 0) { |
| 170 | continue; | 170 | continue; |
| 171 | } | 171 | } |
| ... | @@ -213,7 +213,7 @@ const HuffmanDecoder = struct { | ... | @@ -213,7 +213,7 @@ const HuffmanDecoder = struct { |
| 213 | // Above we've sanity checked that we never overwrote | 213 | // Above we've sanity checked that we never overwrote |
| 214 | // an existing entry. Here we additionally check that | 214 | // an existing entry. Here we additionally check that |
| 215 | // we filled the tables completely. | 215 | // we filled the tables completely. |
| 216 | for (self.chunks) |chunk, i| { | 216 | for (self.chunks, 0..) |chunk, i| { |
| 217 | // As an exception, in the degenerate | 217 | // As an exception, in the degenerate |
| 218 | // single-code case, we allow odd | 218 | // single-code case, we allow odd |
| 219 | // chunks to be missing. | 219 | // chunks to be missing. |
lib/std/compress/deflate/deflate_fast.zig+5-5| ... | @@ -264,7 +264,7 @@ pub const DeflateFast = struct { | ... | @@ -264,7 +264,7 @@ pub const DeflateFast = struct { |
| 264 | var a = src[@intCast(usize, s)..@intCast(usize, s1)]; | 264 | var a = src[@intCast(usize, s)..@intCast(usize, s1)]; |
| 265 | b = b[0..a.len]; | 265 | b = b[0..a.len]; |
| 266 | // Extend the match to be as long as possible. | 266 | // Extend the match to be as long as possible. |
| 267 | for (a) |_, i| { | 267 | for (a, 0..) |_, i| { |
| 268 | if (a[i] != b[i]) { | 268 | if (a[i] != b[i]) { |
| 269 | return @intCast(i32, i); | 269 | return @intCast(i32, i); |
| 270 | } | 270 | } |
| ... | @@ -285,7 +285,7 @@ pub const DeflateFast = struct { | ... | @@ -285,7 +285,7 @@ pub const DeflateFast = struct { |
| 285 | b = b[0..a.len]; | 285 | b = b[0..a.len]; |
| 286 | } | 286 | } |
| 287 | a = a[0..b.len]; | 287 | a = a[0..b.len]; |
| 288 | for (b) |_, i| { | 288 | for (b, 0..) |_, i| { |
| 289 | if (a[i] != b[i]) { | 289 | if (a[i] != b[i]) { |
| 290 | return @intCast(i32, i); | 290 | return @intCast(i32, i); |
| 291 | } | 291 | } |
| ... | @@ -301,7 +301,7 @@ pub const DeflateFast = struct { | ... | @@ -301,7 +301,7 @@ pub const DeflateFast = struct { |
| 301 | // Continue looking for more matches in the current block. | 301 | // Continue looking for more matches in the current block. |
| 302 | a = src[@intCast(usize, s + n)..@intCast(usize, s1)]; | 302 | a = src[@intCast(usize, s + n)..@intCast(usize, s1)]; |
| 303 | b = src[0..a.len]; | 303 | b = src[0..a.len]; |
| 304 | for (a) |_, i| { | 304 | for (a, 0..) |_, i| { |
| 305 | if (a[i] != b[i]) { | 305 | if (a[i] != b[i]) { |
| 306 | return @intCast(i32, i) + n; | 306 | return @intCast(i32, i) + n; |
| 307 | } | 307 | } |
| ... | @@ -330,7 +330,7 @@ pub const DeflateFast = struct { | ... | @@ -330,7 +330,7 @@ pub const DeflateFast = struct { |
| 330 | fn shiftOffsets(self: *Self) void { | 330 | fn shiftOffsets(self: *Self) void { |
| 331 | if (self.prev_len == 0) { | 331 | if (self.prev_len == 0) { |
| 332 | // We have no history; just clear the table. | 332 | // We have no history; just clear the table. |
| 333 | for (self.table) |_, i| { | 333 | for (self.table, 0..) |_, i| { |
| 334 | self.table[i] = TableEntry{ .val = 0, .offset = 0 }; | 334 | self.table[i] = TableEntry{ .val = 0, .offset = 0 }; |
| 335 | } | 335 | } |
| 336 | self.cur = max_match_offset + 1; | 336 | self.cur = max_match_offset + 1; |
| ... | @@ -338,7 +338,7 @@ pub const DeflateFast = struct { | ... | @@ -338,7 +338,7 @@ pub const DeflateFast = struct { |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | // Shift down everything in the table that isn't already too far away. | 340 | // Shift down everything in the table that isn't already too far away. |
| 341 | for (self.table) |_, i| { | 341 | for (self.table, 0..) |_, i| { |
| 342 | var v = self.table[i].offset - self.cur + max_match_offset + 1; | 342 | var v = self.table[i].offset - self.cur + max_match_offset + 1; |
| 343 | if (v < 0) { | 343 | if (v < 0) { |
| 344 | // We want to reset self.cur to max_match_offset + 1, so we need to shift | 344 | // We want to reset self.cur to max_match_offset + 1, so we need to shift |
lib/std/compress/deflate/deflate_fast_test.zig+1-1| ... | @@ -18,7 +18,7 @@ test "best speed" { | ... | @@ -18,7 +18,7 @@ test "best speed" { |
| 18 | var abcabc = try testing.allocator.alloc(u8, 131_072); | 18 | var abcabc = try testing.allocator.alloc(u8, 131_072); |
| 19 | defer testing.allocator.free(abcabc); | 19 | defer testing.allocator.free(abcabc); |
| 20 | 20 | ||
| 21 | for (abcabc) |_, i| { | 21 | for (abcabc, 0..) |_, i| { |
| 22 | abcabc[i] = @intCast(u8, i % 128); | 22 | abcabc[i] = @intCast(u8, i % 128); |
| 23 | } | 23 | } |
| 24 | 24 |
lib/std/compress/deflate/dict_decoder.zig+1-1| ... | @@ -378,7 +378,7 @@ test "dictionary decoder" { | ... | @@ -378,7 +378,7 @@ test "dictionary decoder" { |
| 378 | _ = try want.write("."); | 378 | _ = try want.write("."); |
| 379 | 379 | ||
| 380 | var str = poem; | 380 | var str = poem; |
| 381 | for (poem_refs) |ref, i| { | 381 | for (poem_refs, 0..) |ref, i| { |
| 382 | _ = i; | 382 | _ = i; |
| 383 | if (ref.dist == 0) { | 383 | if (ref.dist == 0) { |
| 384 | try util.writeString(&dd, got, str[0..ref.length]); | 384 | try util.writeString(&dd, got, str[0..ref.length]); |
lib/std/compress/deflate/huffman_bit_writer.zig+6-6| ... | @@ -197,7 +197,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -197,7 +197,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 197 | lit_enc: *hm_code.HuffmanEncoder, | 197 | lit_enc: *hm_code.HuffmanEncoder, |
| 198 | off_enc: *hm_code.HuffmanEncoder, | 198 | off_enc: *hm_code.HuffmanEncoder, |
| 199 | ) void { | 199 | ) void { |
| 200 | for (self.codegen_freq) |_, i| { | 200 | for (self.codegen_freq, 0..) |_, i| { |
| 201 | self.codegen_freq[i] = 0; | 201 | self.codegen_freq[i] = 0; |
| 202 | } | 202 | } |
| 203 | 203 | ||
| ... | @@ -208,12 +208,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -208,12 +208,12 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 208 | var codegen = self.codegen; // cache | 208 | var codegen = self.codegen; // cache |
| 209 | // Copy the concatenated code sizes to codegen. Put a marker at the end. | 209 | // Copy the concatenated code sizes to codegen. Put a marker at the end. |
| 210 | var cgnl = codegen[0..num_literals]; | 210 | var cgnl = codegen[0..num_literals]; |
| 211 | for (cgnl) |_, i| { | 211 | for (cgnl, 0..) |_, i| { |
| 212 | cgnl[i] = @intCast(u8, lit_enc.codes[i].len); | 212 | cgnl[i] = @intCast(u8, lit_enc.codes[i].len); |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | cgnl = codegen[num_literals .. num_literals + num_offsets]; | 215 | cgnl = codegen[num_literals .. num_literals + num_offsets]; |
| 216 | for (cgnl) |_, i| { | 216 | for (cgnl, 0..) |_, i| { |
| 217 | cgnl[i] = @intCast(u8, off_enc.codes[i].len); | 217 | cgnl[i] = @intCast(u8, off_enc.codes[i].len); |
| 218 | } | 218 | } |
| 219 | codegen[num_literals + num_offsets] = bad_code; | 219 | codegen[num_literals + num_offsets] = bad_code; |
| ... | @@ -600,10 +600,10 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -600,10 +600,10 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 600 | var num_literals: u32 = 0; | 600 | var num_literals: u32 = 0; |
| 601 | var num_offsets: u32 = 0; | 601 | var num_offsets: u32 = 0; |
| 602 | 602 | ||
| 603 | for (self.literal_freq) |_, i| { | 603 | for (self.literal_freq, 0..) |_, i| { |
| 604 | self.literal_freq[i] = 0; | 604 | self.literal_freq[i] = 0; |
| 605 | } | 605 | } |
| 606 | for (self.offset_freq) |_, i| { | 606 | for (self.offset_freq, 0..) |_, i| { |
| 607 | self.offset_freq[i] = 0; | 607 | self.offset_freq[i] = 0; |
| 608 | } | 608 | } |
| 609 | 609 | ||
| ... | @@ -691,7 +691,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { | ... | @@ -691,7 +691,7 @@ pub fn HuffmanBitWriter(comptime WriterType: type) type { |
| 691 | } | 691 | } |
| 692 | 692 | ||
| 693 | // Clear histogram | 693 | // Clear histogram |
| 694 | for (self.literal_freq) |_, i| { | 694 | for (self.literal_freq, 0..) |_, i| { |
| 695 | self.literal_freq[i] = 0; | 695 | self.literal_freq[i] = 0; |
| 696 | } | 696 | } |
| 697 | 697 |
lib/std/compress/deflate/huffman_code.zig+5-5| ... | @@ -71,7 +71,7 @@ pub const HuffmanEncoder = struct { | ... | @@ -71,7 +71,7 @@ pub const HuffmanEncoder = struct { |
| 71 | // Number of non-zero literals | 71 | // Number of non-zero literals |
| 72 | var count: u32 = 0; | 72 | var count: u32 = 0; |
| 73 | // Set list to be the set of all non-zero literals and their frequencies | 73 | // Set list to be the set of all non-zero literals and their frequencies |
| 74 | for (freq) |f, i| { | 74 | for (freq, 0..) |f, i| { |
| 75 | if (f != 0) { | 75 | if (f != 0) { |
| 76 | list[count] = LiteralNode{ .literal = @intCast(u16, i), .freq = f }; | 76 | list[count] = LiteralNode{ .literal = @intCast(u16, i), .freq = f }; |
| 77 | count += 1; | 77 | count += 1; |
| ... | @@ -86,7 +86,7 @@ pub const HuffmanEncoder = struct { | ... | @@ -86,7 +86,7 @@ pub const HuffmanEncoder = struct { |
| 86 | if (count <= 2) { | 86 | if (count <= 2) { |
| 87 | // Handle the small cases here, because they are awkward for the general case code. With | 87 | // Handle the small cases here, because they are awkward for the general case code. With |
| 88 | // two or fewer literals, everything has bit length 1. | 88 | // two or fewer literals, everything has bit length 1. |
| 89 | for (list) |node, i| { | 89 | for (list, 0..) |node, i| { |
| 90 | // "list" is in order of increasing literal value. | 90 | // "list" is in order of increasing literal value. |
| 91 | self.codes[node.literal].set(@intCast(u16, i), 1); | 91 | self.codes[node.literal].set(@intCast(u16, i), 1); |
| 92 | } | 92 | } |
| ... | @@ -103,7 +103,7 @@ pub const HuffmanEncoder = struct { | ... | @@ -103,7 +103,7 @@ pub const HuffmanEncoder = struct { |
| 103 | 103 | ||
| 104 | pub fn bitLength(self: *HuffmanEncoder, freq: []u16) u32 { | 104 | pub fn bitLength(self: *HuffmanEncoder, freq: []u16) u32 { |
| 105 | var total: u32 = 0; | 105 | var total: u32 = 0; |
| 106 | for (freq) |f, i| { | 106 | for (freq, 0..) |f, i| { |
| 107 | if (f != 0) { | 107 | if (f != 0) { |
| 108 | total += @intCast(u32, f) * @intCast(u32, self.codes[i].len); | 108 | total += @intCast(u32, f) * @intCast(u32, self.codes[i].len); |
| 109 | } | 109 | } |
| ... | @@ -258,7 +258,7 @@ pub const HuffmanEncoder = struct { | ... | @@ -258,7 +258,7 @@ pub const HuffmanEncoder = struct { |
| 258 | var code = @as(u16, 0); | 258 | var code = @as(u16, 0); |
| 259 | var list = list_arg; | 259 | var list = list_arg; |
| 260 | 260 | ||
| 261 | for (bit_count) |bits, n| { | 261 | for (bit_count, 0..) |bits, n| { |
| 262 | code <<= 1; | 262 | code <<= 1; |
| 263 | if (n == 0 or bits == 0) { | 263 | if (n == 0 or bits == 0) { |
| 264 | continue; | 264 | continue; |
| ... | @@ -340,7 +340,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder { | ... | @@ -340,7 +340,7 @@ pub fn generateFixedLiteralEncoding(allocator: Allocator) !HuffmanEncoder { |
| 340 | pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder { | 340 | pub fn generateFixedOffsetEncoding(allocator: Allocator) !HuffmanEncoder { |
| 341 | var h = try newHuffmanEncoder(allocator, 30); | 341 | var h = try newHuffmanEncoder(allocator, 30); |
| 342 | var codes = h.codes; | 342 | var codes = h.codes; |
| 343 | for (codes) |_, ch| { | 343 | for (codes, 0..) |_, ch| { |
| 344 | codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @intCast(u16, ch), 5), .len = 5 }; | 344 | codes[ch] = HuffCode{ .code = bu.bitReverse(u16, @intCast(u16, ch), 5), .len = 5 }; |
| 345 | } | 345 | } |
| 346 | return h; | 346 | return h; |
lib/std/compress/lzma/decode.zig+1-1| ... | @@ -143,7 +143,7 @@ pub const DecoderState = struct { | ... | @@ -143,7 +143,7 @@ pub const DecoderState = struct { |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | self.lzma_props = new_props; | 145 | self.lzma_props = new_props; |
| 146 | for (self.pos_slot_decoder) |*t| t.reset(); | 146 | for (&self.pos_slot_decoder) |*t| t.reset(); |
| 147 | self.align_decoder.reset(); | 147 | self.align_decoder.reset(); |
| 148 | self.pos_decoders = .{0x400} ** 115; | 148 | self.pos_decoders = .{0x400} ** 115; |
| 149 | self.is_match = .{0x400} ** 192; | 149 | self.is_match = .{0x400} ** 192; |
lib/std/compress/lzma/decode/rangecoder.zig+2-2| ... | @@ -174,8 +174,8 @@ pub const LenDecoder = struct { | ... | @@ -174,8 +174,8 @@ pub const LenDecoder = struct { |
| 174 | pub fn reset(self: *LenDecoder) void { | 174 | pub fn reset(self: *LenDecoder) void { |
| 175 | self.choice = 0x400; | 175 | self.choice = 0x400; |
| 176 | self.choice2 = 0x400; | 176 | self.choice2 = 0x400; |
| 177 | for (self.low_coder) |*t| t.reset(); | 177 | for (&self.low_coder) |*t| t.reset(); |
| 178 | for (self.mid_coder) |*t| t.reset(); | 178 | for (&self.mid_coder) |*t| t.reset(); |
| 179 | self.high_coder.reset(); | 179 | self.high_coder.reset(); |
| 180 | } | 180 | } |
| 181 | }; | 181 | }; |
lib/std/comptime_string_map.zig+1-1| ... | @@ -21,7 +21,7 @@ pub fn ComptimeStringMap(comptime V: type, comptime kvs_list: anytype) type { | ... | @@ -21,7 +21,7 @@ pub fn ComptimeStringMap(comptime V: type, comptime kvs_list: anytype) type { |
| 21 | return a.key.len < b.key.len; | 21 | return a.key.len < b.key.len; |
| 22 | } | 22 | } |
| 23 | }).lenAsc; | 23 | }).lenAsc; |
| 24 | for (kvs_list) |kv, i| { | 24 | for (kvs_list, 0..) |kv, i| { |
| 25 | if (V != void) { | 25 | if (V != void) { |
| 26 | sorted_kvs[i] = .{ .key = kv.@"0", .value = kv.@"1" }; | 26 | sorted_kvs[i] = .{ .key = kv.@"0", .value = kv.@"1" }; |
| 27 | } else { | 27 | } else { |
lib/std/crypto/25519/ed25519.zig+5-5| ... | @@ -344,7 +344,7 @@ pub const Ed25519 = struct { | ... | @@ -344,7 +344,7 @@ pub const Ed25519 = struct { |
| 344 | var a_batch: [count]Curve = undefined; | 344 | var a_batch: [count]Curve = undefined; |
| 345 | var expected_r_batch: [count]Curve = undefined; | 345 | var expected_r_batch: [count]Curve = undefined; |
| 346 | 346 | ||
| 347 | for (signature_batch) |signature, i| { | 347 | for (signature_batch, 0..) |signature, i| { |
| 348 | const r = signature.sig.r; | 348 | const r = signature.sig.r; |
| 349 | const s = signature.sig.s; | 349 | const s = signature.sig.s; |
| 350 | try Curve.scalar.rejectNonCanonical(s); | 350 | try Curve.scalar.rejectNonCanonical(s); |
| ... | @@ -360,7 +360,7 @@ pub const Ed25519 = struct { | ... | @@ -360,7 +360,7 @@ pub const Ed25519 = struct { |
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | var hram_batch: [count]Curve.scalar.CompressedScalar = undefined; | 362 | var hram_batch: [count]Curve.scalar.CompressedScalar = undefined; |
| 363 | for (signature_batch) |signature, i| { | 363 | for (signature_batch, 0..) |signature, i| { |
| 364 | var h = Sha512.init(.{}); | 364 | var h = Sha512.init(.{}); |
| 365 | h.update(&r_batch[i]); | 365 | h.update(&r_batch[i]); |
| 366 | h.update(&signature.public_key.bytes); | 366 | h.update(&signature.public_key.bytes); |
| ... | @@ -371,20 +371,20 @@ pub const Ed25519 = struct { | ... | @@ -371,20 +371,20 @@ pub const Ed25519 = struct { |
| 371 | } | 371 | } |
| 372 | 372 | ||
| 373 | var z_batch: [count]Curve.scalar.CompressedScalar = undefined; | 373 | var z_batch: [count]Curve.scalar.CompressedScalar = undefined; |
| 374 | for (z_batch) |*z| { | 374 | for (&z_batch) |*z| { |
| 375 | crypto.random.bytes(z[0..16]); | 375 | crypto.random.bytes(z[0..16]); |
| 376 | mem.set(u8, z[16..], 0); | 376 | mem.set(u8, z[16..], 0); |
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | var zs_sum = Curve.scalar.zero; | 379 | var zs_sum = Curve.scalar.zero; |
| 380 | for (z_batch) |z, i| { | 380 | for (z_batch, 0..) |z, i| { |
| 381 | const zs = Curve.scalar.mul(z, s_batch[i]); | 381 | const zs = Curve.scalar.mul(z, s_batch[i]); |
| 382 | zs_sum = Curve.scalar.add(zs_sum, zs); | 382 | zs_sum = Curve.scalar.add(zs_sum, zs); |
| 383 | } | 383 | } |
| 384 | zs_sum = Curve.scalar.mul8(zs_sum); | 384 | zs_sum = Curve.scalar.mul8(zs_sum); |
| 385 | 385 | ||
| 386 | var zhs: [count]Curve.scalar.CompressedScalar = undefined; | 386 | var zhs: [count]Curve.scalar.CompressedScalar = undefined; |
| 387 | for (z_batch) |z, i| { | 387 | for (z_batch, 0..) |z, i| { |
| 388 | zhs[i] = Curve.scalar.mul(z, hram_batch[i]); | 388 | zhs[i] = Curve.scalar.mul(z, hram_batch[i]); |
| 389 | } | 389 | } |
| 390 | 390 |
lib/std/crypto/25519/edwards25519.zig+4-4| ... | @@ -161,7 +161,7 @@ pub const Edwards25519 = struct { | ... | @@ -161,7 +161,7 @@ pub const Edwards25519 = struct { |
| 161 | fn slide(s: [32]u8) [2 * 32]i8 { | 161 | fn slide(s: [32]u8) [2 * 32]i8 { |
| 162 | const reduced = if ((s[s.len - 1] & 0x80) == 0) s else scalar.reduce(s); | 162 | const reduced = if ((s[s.len - 1] & 0x80) == 0) s else scalar.reduce(s); |
| 163 | var e: [2 * 32]i8 = undefined; | 163 | var e: [2 * 32]i8 = undefined; |
| 164 | for (reduced) |x, i| { | 164 | for (reduced, 0..) |x, i| { |
| 165 | e[i * 2 + 0] = @as(i8, @truncate(u4, x)); | 165 | e[i * 2 + 0] = @as(i8, @truncate(u4, x)); |
| 166 | e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4)); | 166 | e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4)); |
| 167 | } | 167 | } |
| ... | @@ -308,7 +308,7 @@ pub const Edwards25519 = struct { | ... | @@ -308,7 +308,7 @@ pub const Edwards25519 = struct { |
| 308 | var bpc: [9]Edwards25519 = undefined; | 308 | var bpc: [9]Edwards25519 = undefined; |
| 309 | mem.copy(Edwards25519, bpc[0..], basePointPc[0..bpc.len]); | 309 | mem.copy(Edwards25519, bpc[0..], basePointPc[0..bpc.len]); |
| 310 | 310 | ||
| 311 | for (ps) |p, i| { | 311 | for (ps, 0..) |p, i| { |
| 312 | if (p.is_base) { | 312 | if (p.is_base) { |
| 313 | pcs[i] = bpc; | 313 | pcs[i] = bpc; |
| 314 | } else { | 314 | } else { |
| ... | @@ -317,13 +317,13 @@ pub const Edwards25519 = struct { | ... | @@ -317,13 +317,13 @@ pub const Edwards25519 = struct { |
| 317 | } | 317 | } |
| 318 | } | 318 | } |
| 319 | var es: [count][2 * 32]i8 = undefined; | 319 | var es: [count][2 * 32]i8 = undefined; |
| 320 | for (ss) |s, i| { | 320 | for (ss, 0..) |s, i| { |
| 321 | es[i] = slide(s); | 321 | es[i] = slide(s); |
| 322 | } | 322 | } |
| 323 | var q = Edwards25519.identityElement; | 323 | var q = Edwards25519.identityElement; |
| 324 | var pos: usize = 2 * 32 - 1; | 324 | var pos: usize = 2 * 32 - 1; |
| 325 | while (true) : (pos -= 1) { | 325 | while (true) : (pos -= 1) { |
| 326 | for (es) |e, i| { | 326 | for (es, 0..) |e, i| { |
| 327 | const slot = e[pos]; | 327 | const slot = e[pos]; |
| 328 | if (slot > 0) { | 328 | if (slot > 0) { |
| 329 | q = q.add(pcs[i][@intCast(usize, slot)]); | 329 | q = q.add(pcs[i][@intCast(usize, slot)]); |
lib/std/crypto/Certificate.zig+1-1| ... | @@ -1092,7 +1092,7 @@ pub const rsa = struct { | ... | @@ -1092,7 +1092,7 @@ pub const rsa = struct { |
| 1092 | if (exponent_elem.identifier.tag != .integer) return error.CertificateFieldHasWrongDataType; | 1092 | if (exponent_elem.identifier.tag != .integer) return error.CertificateFieldHasWrongDataType; |
| 1093 | // Skip over meaningless zeroes in the modulus. | 1093 | // Skip over meaningless zeroes in the modulus. |
| 1094 | const modulus_raw = pub_key[modulus_elem.slice.start..modulus_elem.slice.end]; | 1094 | const modulus_raw = pub_key[modulus_elem.slice.start..modulus_elem.slice.end]; |
| 1095 | const modulus_offset = for (modulus_raw) |byte, i| { | 1095 | const modulus_offset = for (modulus_raw, 0..) |byte, i| { |
| 1096 | if (byte != 0) break i; | 1096 | if (byte != 0) break i; |
| 1097 | } else modulus_raw.len; | 1097 | } else modulus_raw.len; |
| 1098 | return .{ | 1098 | return .{ |
lib/std/crypto/aegis.zig+3-3| ... | @@ -170,7 +170,7 @@ pub const Aegis128L = struct { | ... | @@ -170,7 +170,7 @@ pub const Aegis128L = struct { |
| 170 | } | 170 | } |
| 171 | const computed_tag = state.mac(ad.len, m.len); | 171 | const computed_tag = state.mac(ad.len, m.len); |
| 172 | var acc: u8 = 0; | 172 | var acc: u8 = 0; |
| 173 | for (computed_tag) |_, j| { | 173 | for (computed_tag, 0..) |_, j| { |
| 174 | acc |= (computed_tag[j] ^ tag[j]); | 174 | acc |= (computed_tag[j] ^ tag[j]); |
| 175 | } | 175 | } |
| 176 | if (acc != 0) { | 176 | if (acc != 0) { |
| ... | @@ -339,7 +339,7 @@ pub const Aegis256 = struct { | ... | @@ -339,7 +339,7 @@ pub const Aegis256 = struct { |
| 339 | } | 339 | } |
| 340 | const computed_tag = state.mac(ad.len, m.len); | 340 | const computed_tag = state.mac(ad.len, m.len); |
| 341 | var acc: u8 = 0; | 341 | var acc: u8 = 0; |
| 342 | for (computed_tag) |_, j| { | 342 | for (computed_tag, 0..) |_, j| { |
| 343 | acc |= (computed_tag[j] ^ tag[j]); | 343 | acc |= (computed_tag[j] ^ tag[j]); |
| 344 | } | 344 | } |
| 345 | if (acc != 0) { | 345 | if (acc != 0) { |
| ... | @@ -562,7 +562,7 @@ test "Aegis256 test vector 3" { | ... | @@ -562,7 +562,7 @@ test "Aegis256 test vector 3" { |
| 562 | test "Aegis MAC" { | 562 | test "Aegis MAC" { |
| 563 | const key = [_]u8{0x00} ** Aegis128LMac.key_length; | 563 | const key = [_]u8{0x00} ** Aegis128LMac.key_length; |
| 564 | var msg: [64]u8 = undefined; | 564 | var msg: [64]u8 = undefined; |
| 565 | for (msg) |*m, i| { | 565 | for (&msg, 0..) |*m, i| { |
| 566 | m.* = @truncate(u8, i); | 566 | m.* = @truncate(u8, i); |
| 567 | } | 567 | } |
| 568 | const st_init = Aegis128LMac.init(&key); | 568 | const st_init = Aegis128LMac.init(&key); |
lib/std/crypto/aes.zig+4-4| ... | @@ -115,11 +115,11 @@ test "expand 128-bit key" { | ... | @@ -115,11 +115,11 @@ test "expand 128-bit key" { |
| 115 | const dec = Aes128.initDec(key); | 115 | const dec = Aes128.initDec(key); |
| 116 | var exp: [16]u8 = undefined; | 116 | var exp: [16]u8 = undefined; |
| 117 | 117 | ||
| 118 | for (enc.key_schedule.round_keys) |round_key, i| { | 118 | for (enc.key_schedule.round_keys, 0..) |round_key, i| { |
| 119 | _ = try std.fmt.hexToBytes(&exp, exp_enc[i]); | 119 | _ = try std.fmt.hexToBytes(&exp, exp_enc[i]); |
| 120 | try testing.expectEqualSlices(u8, &exp, &round_key.toBytes()); | 120 | try testing.expectEqualSlices(u8, &exp, &round_key.toBytes()); |
| 121 | } | 121 | } |
| 122 | for (dec.key_schedule.round_keys) |round_key, i| { | 122 | for (dec.key_schedule.round_keys, 0..) |round_key, i| { |
| 123 | _ = try std.fmt.hexToBytes(&exp, exp_dec[i]); | 123 | _ = try std.fmt.hexToBytes(&exp, exp_dec[i]); |
| 124 | try testing.expectEqualSlices(u8, &exp, &round_key.toBytes()); | 124 | try testing.expectEqualSlices(u8, &exp, &round_key.toBytes()); |
| 125 | } | 125 | } |
| ... | @@ -154,11 +154,11 @@ test "expand 256-bit key" { | ... | @@ -154,11 +154,11 @@ test "expand 256-bit key" { |
| 154 | const dec = Aes256.initDec(key); | 154 | const dec = Aes256.initDec(key); |
| 155 | var exp: [16]u8 = undefined; | 155 | var exp: [16]u8 = undefined; |
| 156 | 156 | ||
| 157 | for (enc.key_schedule.round_keys) |round_key, i| { | 157 | for (enc.key_schedule.round_keys, 0..) |round_key, i| { |
| 158 | _ = try std.fmt.hexToBytes(&exp, exp_enc[i]); | 158 | _ = try std.fmt.hexToBytes(&exp, exp_enc[i]); |
| 159 | try testing.expectEqualSlices(u8, &exp, &round_key.toBytes()); | 159 | try testing.expectEqualSlices(u8, &exp, &round_key.toBytes()); |
| 160 | } | 160 | } |
| 161 | for (dec.key_schedule.round_keys) |round_key, i| { | 161 | for (dec.key_schedule.round_keys, 0..) |round_key, i| { |
| 162 | _ = try std.fmt.hexToBytes(&exp, exp_dec[i]); | 162 | _ = try std.fmt.hexToBytes(&exp, exp_dec[i]); |
| 163 | try testing.expectEqualSlices(u8, &exp, &round_key.toBytes()); | 163 | try testing.expectEqualSlices(u8, &exp, &round_key.toBytes()); |
| 164 | } | 164 | } |
lib/std/crypto/aes/aesni.zig+2-2| ... | @@ -200,7 +200,7 @@ fn KeySchedule(comptime Aes: type) type { | ... | @@ -200,7 +200,7 @@ fn KeySchedule(comptime Aes: type) type { |
| 200 | fn expand128(t1: *Block) Self { | 200 | fn expand128(t1: *Block) Self { |
| 201 | var round_keys: [11]Block = undefined; | 201 | var round_keys: [11]Block = undefined; |
| 202 | const rcs = [_]u8{ 1, 2, 4, 8, 16, 32, 64, 128, 27, 54 }; | 202 | const rcs = [_]u8{ 1, 2, 4, 8, 16, 32, 64, 128, 27, 54 }; |
| 203 | inline for (rcs) |rc, round| { | 203 | inline for (rcs, 0..) |rc, round| { |
| 204 | round_keys[round] = t1.*; | 204 | round_keys[round] = t1.*; |
| 205 | t1.repr = drc(false, rc, t1.repr, t1.repr); | 205 | t1.repr = drc(false, rc, t1.repr, t1.repr); |
| 206 | } | 206 | } |
| ... | @@ -212,7 +212,7 @@ fn KeySchedule(comptime Aes: type) type { | ... | @@ -212,7 +212,7 @@ fn KeySchedule(comptime Aes: type) type { |
| 212 | var round_keys: [15]Block = undefined; | 212 | var round_keys: [15]Block = undefined; |
| 213 | const rcs = [_]u8{ 1, 2, 4, 8, 16, 32 }; | 213 | const rcs = [_]u8{ 1, 2, 4, 8, 16, 32 }; |
| 214 | round_keys[0] = t1.*; | 214 | round_keys[0] = t1.*; |
| 215 | inline for (rcs) |rc, round| { | 215 | inline for (rcs, 0..) |rc, round| { |
| 216 | round_keys[round * 2 + 1] = t2.*; | 216 | round_keys[round * 2 + 1] = t2.*; |
| 217 | t1.repr = drc(false, rc, t2.repr, t1.repr); | 217 | t1.repr = drc(false, rc, t2.repr, t1.repr); |
| 218 | round_keys[round * 2 + 2] = t1.*; | 218 | round_keys[round * 2 + 2] = t1.*; |
lib/std/crypto/aes/armcrypto.zig+2-2| ... | @@ -250,7 +250,7 @@ fn KeySchedule(comptime Aes: type) type { | ... | @@ -250,7 +250,7 @@ fn KeySchedule(comptime Aes: type) type { |
| 250 | fn expand128(t1: *Block) Self { | 250 | fn expand128(t1: *Block) Self { |
| 251 | var round_keys: [11]Block = undefined; | 251 | var round_keys: [11]Block = undefined; |
| 252 | const rcs = [_]u8{ 1, 2, 4, 8, 16, 32, 64, 128, 27, 54 }; | 252 | const rcs = [_]u8{ 1, 2, 4, 8, 16, 32, 64, 128, 27, 54 }; |
| 253 | inline for (rcs) |rc, round| { | 253 | inline for (rcs, 0..) |rc, round| { |
| 254 | round_keys[round] = t1.*; | 254 | round_keys[round] = t1.*; |
| 255 | t1.repr = drc128(rc, t1.repr); | 255 | t1.repr = drc128(rc, t1.repr); |
| 256 | } | 256 | } |
| ... | @@ -262,7 +262,7 @@ fn KeySchedule(comptime Aes: type) type { | ... | @@ -262,7 +262,7 @@ fn KeySchedule(comptime Aes: type) type { |
| 262 | var round_keys: [15]Block = undefined; | 262 | var round_keys: [15]Block = undefined; |
| 263 | const rcs = [_]u8{ 1, 2, 4, 8, 16, 32 }; | 263 | const rcs = [_]u8{ 1, 2, 4, 8, 16, 32 }; |
| 264 | round_keys[0] = t1.*; | 264 | round_keys[0] = t1.*; |
| 265 | inline for (rcs) |rc, round| { | 265 | inline for (rcs, 0..) |rc, round| { |
| 266 | round_keys[round * 2 + 1] = t2.*; | 266 | round_keys[round * 2 + 1] = t2.*; |
| 267 | t1.repr = drc256(false, rc, t2.repr, t1.repr); | 267 | t1.repr = drc256(false, rc, t2.repr, t1.repr); |
| 268 | round_keys[round * 2 + 2] = t1.*; | 268 | round_keys[round * 2 + 2] = t1.*; |
lib/std/crypto/aes/soft.zig+2-2| ... | @@ -420,7 +420,7 @@ const powx = init: { | ... | @@ -420,7 +420,7 @@ const powx = init: { |
| 420 | var array: [16]u8 = undefined; | 420 | var array: [16]u8 = undefined; |
| 421 | 421 | ||
| 422 | var value = 1; | 422 | var value = 1; |
| 423 | for (array) |*power| { | 423 | for (&array) |*power| { |
| 424 | power.* = value; | 424 | power.* = value; |
| 425 | value = mul(value, 2); | 425 | value = mul(value, 2); |
| 426 | } | 426 | } |
| ... | @@ -471,7 +471,7 @@ fn generateSbox(invert: bool) [256]u8 { | ... | @@ -471,7 +471,7 @@ fn generateSbox(invert: bool) [256]u8 { |
| 471 | fn generateTable(invert: bool) [4][256]u32 { | 471 | fn generateTable(invert: bool) [4][256]u32 { |
| 472 | var table: [4][256]u32 = undefined; | 472 | var table: [4][256]u32 = undefined; |
| 473 | 473 | ||
| 474 | for (generateSbox(invert)) |value, index| { | 474 | for (generateSbox(invert), 0..) |value, index| { |
| 475 | table[0][index] = mul(value, if (invert) 0xb else 0x3); | 475 | table[0][index] = mul(value, if (invert) 0xb else 0x3); |
| 476 | table[0][index] |= math.shl(u32, mul(value, if (invert) 0xd else 0x1), 8); | 476 | table[0][index] |= math.shl(u32, mul(value, if (invert) 0xd else 0x1), 8); |
| 477 | table[0][index] |= math.shl(u32, mul(value, if (invert) 0x9 else 0x1), 16); | 477 | table[0][index] |= math.shl(u32, mul(value, if (invert) 0x9 else 0x1), 16); |
lib/std/crypto/aes_gcm.zig+3-3| ... | @@ -50,7 +50,7 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -50,7 +50,7 @@ fn AesGcm(comptime Aes: anytype) type { |
| 50 | mem.writeIntBig(u64, final_block[8..16], m.len * 8); | 50 | mem.writeIntBig(u64, final_block[8..16], m.len * 8); |
| 51 | mac.update(&final_block); | 51 | mac.update(&final_block); |
| 52 | mac.final(tag); | 52 | mac.final(tag); |
| 53 | for (t) |x, i| { | 53 | for (t, 0..) |x, i| { |
| 54 | tag[i] ^= x; | 54 | tag[i] ^= x; |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| ... | @@ -82,12 +82,12 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -82,12 +82,12 @@ fn AesGcm(comptime Aes: anytype) type { |
| 82 | mac.update(&final_block); | 82 | mac.update(&final_block); |
| 83 | var computed_tag: [Ghash.mac_length]u8 = undefined; | 83 | var computed_tag: [Ghash.mac_length]u8 = undefined; |
| 84 | mac.final(&computed_tag); | 84 | mac.final(&computed_tag); |
| 85 | for (t) |x, i| { | 85 | for (t, 0..) |x, i| { |
| 86 | computed_tag[i] ^= x; | 86 | computed_tag[i] ^= x; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | var acc: u8 = 0; | 89 | var acc: u8 = 0; |
| 90 | for (computed_tag) |_, p| { | 90 | for (computed_tag, 0..) |_, p| { |
| 91 | acc |= (computed_tag[p] ^ tag[p]); | 91 | acc |= (computed_tag[p] ^ tag[p]); |
| 92 | } | 92 | } |
| 93 | if (acc != 0) { | 93 | if (acc != 0) { |
lib/std/crypto/aes_ocb.zig+4-4| ... | @@ -155,7 +155,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -155,7 +155,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 155 | xorWith(&offset, lx.star); | 155 | xorWith(&offset, lx.star); |
| 156 | var pad = offset; | 156 | var pad = offset; |
| 157 | aes_enc_ctx.encrypt(&pad, &pad); | 157 | aes_enc_ctx.encrypt(&pad, &pad); |
| 158 | for (m[i * 16 ..]) |x, j| { | 158 | for (m[i * 16 ..], 0..) |x, j| { |
| 159 | c[i * 16 + j] = pad[j] ^ x; | 159 | c[i * 16 + j] = pad[j] ^ x; |
| 160 | } | 160 | } |
| 161 | var e = [_]u8{0} ** 16; | 161 | var e = [_]u8{0} ** 16; |
| ... | @@ -220,7 +220,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -220,7 +220,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 220 | xorWith(&offset, lx.star); | 220 | xorWith(&offset, lx.star); |
| 221 | var pad = offset; | 221 | var pad = offset; |
| 222 | aes_enc_ctx.encrypt(&pad, &pad); | 222 | aes_enc_ctx.encrypt(&pad, &pad); |
| 223 | for (c[i * 16 ..]) |x, j| { | 223 | for (c[i * 16 ..], 0..) |x, j| { |
| 224 | m[i * 16 + j] = pad[j] ^ x; | 224 | m[i * 16 + j] = pad[j] ^ x; |
| 225 | } | 225 | } |
| 226 | var e = [_]u8{0} ** 16; | 226 | var e = [_]u8{0} ** 16; |
| ... | @@ -242,14 +242,14 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -242,14 +242,14 @@ fn AesOcb(comptime Aes: anytype) type { |
| 242 | 242 | ||
| 243 | inline fn xorBlocks(x: Block, y: Block) Block { | 243 | inline fn xorBlocks(x: Block, y: Block) Block { |
| 244 | var z: Block = x; | 244 | var z: Block = x; |
| 245 | for (z) |*v, i| { | 245 | for (&z, 0..) |*v, i| { |
| 246 | v.* = x[i] ^ y[i]; | 246 | v.* = x[i] ^ y[i]; |
| 247 | } | 247 | } |
| 248 | return z; | 248 | return z; |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | inline fn xorWith(x: *Block, y: Block) void { | 251 | inline fn xorWith(x: *Block, y: Block) void { |
| 252 | for (x) |*v, i| { | 252 | for (x, 0..) |*v, i| { |
| 253 | v.* ^= y[i]; | 253 | v.* ^= y[i]; |
| 254 | } | 254 | } |
| 255 | } | 255 | } |
lib/std/crypto/argon2.zig+7-7| ... | @@ -188,13 +188,13 @@ fn initBlocks( | ... | @@ -188,13 +188,13 @@ fn initBlocks( |
| 188 | 188 | ||
| 189 | mem.writeIntLittle(u32, h0[Blake2b512.digest_length..][0..4], 0); | 189 | mem.writeIntLittle(u32, h0[Blake2b512.digest_length..][0..4], 0); |
| 190 | blake2bLong(&block0, h0); | 190 | blake2bLong(&block0, h0); |
| 191 | for (blocks.items[j + 0]) |*v, i| { | 191 | for (&blocks.items[j + 0], 0..) |*v, i| { |
| 192 | v.* = mem.readIntLittle(u64, block0[i * 8 ..][0..8]); | 192 | v.* = mem.readIntLittle(u64, block0[i * 8 ..][0..8]); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | mem.writeIntLittle(u32, h0[Blake2b512.digest_length..][0..4], 1); | 195 | mem.writeIntLittle(u32, h0[Blake2b512.digest_length..][0..4], 1); |
| 196 | blake2bLong(&block0, h0); | 196 | blake2bLong(&block0, h0); |
| 197 | for (blocks.items[j + 1]) |*v, i| { | 197 | for (&blocks.items[j + 1], 0..) |*v, i| { |
| 198 | v.* = mem.readIntLittle(u64, block0[i * 8 ..][0..8]); | 198 | v.* = mem.readIntLittle(u64, block0[i * 8 ..][0..8]); |
| 199 | } | 199 | } |
| 200 | } | 200 | } |
| ... | @@ -352,7 +352,7 @@ fn processBlockGeneric( | ... | @@ -352,7 +352,7 @@ fn processBlockGeneric( |
| 352 | comptime xor: bool, | 352 | comptime xor: bool, |
| 353 | ) void { | 353 | ) void { |
| 354 | var t: [block_length]u64 = undefined; | 354 | var t: [block_length]u64 = undefined; |
| 355 | for (t) |*v, i| { | 355 | for (&t, 0..) |*v, i| { |
| 356 | v.* = in1[i] ^ in2[i]; | 356 | v.* = in1[i] ^ in2[i]; |
| 357 | } | 357 | } |
| 358 | var i: usize = 0; | 358 | var i: usize = 0; |
| ... | @@ -375,11 +375,11 @@ fn processBlockGeneric( | ... | @@ -375,11 +375,11 @@ fn processBlockGeneric( |
| 375 | } | 375 | } |
| 376 | } | 376 | } |
| 377 | if (xor) { | 377 | if (xor) { |
| 378 | for (t) |v, j| { | 378 | for (t, 0..) |v, j| { |
| 379 | out[j] ^= in1[j] ^ in2[j] ^ v; | 379 | out[j] ^= in1[j] ^ in2[j] ^ v; |
| 380 | } | 380 | } |
| 381 | } else { | 381 | } else { |
| 382 | for (t) |v, j| { | 382 | for (t, 0..) |v, j| { |
| 383 | out[j] = in1[j] ^ in2[j] ^ v; | 383 | out[j] = in1[j] ^ in2[j] ^ v; |
| 384 | } | 384 | } |
| 385 | } | 385 | } |
| ... | @@ -428,12 +428,12 @@ fn finalize( | ... | @@ -428,12 +428,12 @@ fn finalize( |
| 428 | const lanes = memory / threads; | 428 | const lanes = memory / threads; |
| 429 | var lane: u24 = 0; | 429 | var lane: u24 = 0; |
| 430 | while (lane < threads - 1) : (lane += 1) { | 430 | while (lane < threads - 1) : (lane += 1) { |
| 431 | for (blocks.items[(lane * lanes) + lanes - 1]) |v, i| { | 431 | for (blocks.items[(lane * lanes) + lanes - 1], 0..) |v, i| { |
| 432 | blocks.items[memory - 1][i] ^= v; | 432 | blocks.items[memory - 1][i] ^= v; |
| 433 | } | 433 | } |
| 434 | } | 434 | } |
| 435 | var block: [1024]u8 = undefined; | 435 | var block: [1024]u8 = undefined; |
| 436 | for (blocks.items[memory - 1]) |v, i| { | 436 | for (blocks.items[memory - 1], 0..) |v, i| { |
| 437 | mem.writeIntLittle(u64, block[i * 8 ..][0..8], v); | 437 | mem.writeIntLittle(u64, block[i * 8 ..][0..8], v); |
| 438 | } | 438 | } |
| 439 | blake2bLong(out, &block); | 439 | blake2bLong(out, &block); |
lib/std/crypto/ascon.zig+1-1| ... | @@ -74,7 +74,7 @@ pub fn State(comptime endian: builtin.Endian) type { | ... | @@ -74,7 +74,7 @@ pub fn State(comptime endian: builtin.Endian) type { |
| 74 | 74 | ||
| 75 | /// Byte-swap the entire state if the architecture doesn't match the required endianness. | 75 | /// Byte-swap the entire state if the architecture doesn't match the required endianness. |
| 76 | pub fn endianSwap(self: *Self) void { | 76 | pub fn endianSwap(self: *Self) void { |
| 77 | for (self.st) |*w| { | 77 | for (&self.st) |*w| { |
| 78 | w.* = mem.toNative(u64, w.*, endian); | 78 | w.* = mem.toNative(u64, w.*, endian); |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
lib/std/crypto/bcrypt.zig+2-2| ... | @@ -437,7 +437,7 @@ pub fn bcrypt( | ... | @@ -437,7 +437,7 @@ pub fn bcrypt( |
| 437 | } | 437 | } |
| 438 | 438 | ||
| 439 | var ct: [ct_length]u8 = undefined; | 439 | var ct: [ct_length]u8 = undefined; |
| 440 | for (cdata) |c, i| { | 440 | for (cdata, 0..) |c, i| { |
| 441 | mem.writeIntBig(u32, ct[i * 4 ..][0..4], c); | 441 | mem.writeIntBig(u32, ct[i * 4 ..][0..4], c); |
| 442 | } | 442 | } |
| 443 | return ct[0..dk_length].*; | 443 | return ct[0..dk_length].*; |
| ... | @@ -505,7 +505,7 @@ const pbkdf_prf = struct { | ... | @@ -505,7 +505,7 @@ const pbkdf_prf = struct { |
| 505 | 505 | ||
| 506 | // copy out | 506 | // copy out |
| 507 | var out: [32]u8 = undefined; | 507 | var out: [32]u8 = undefined; |
| 508 | for (cdata) |v, i| { | 508 | for (cdata, 0..) |v, i| { |
| 509 | std.mem.writeIntLittle(u32, out[4 * i ..][0..4], v); | 509 | std.mem.writeIntLittle(u32, out[4 * i ..][0..4], v); |
| 510 | } | 510 | } |
| 511 | 511 |
lib/std/crypto/blake2.zig+6-6| ... | @@ -133,7 +133,7 @@ pub fn Blake2s(comptime out_bits: usize) type { | ... | @@ -133,7 +133,7 @@ pub fn Blake2s(comptime out_bits: usize) type { |
| 133 | mem.set(u8, d.buf[d.buf_len..], 0); | 133 | mem.set(u8, d.buf[d.buf_len..], 0); |
| 134 | d.t += d.buf_len; | 134 | d.t += d.buf_len; |
| 135 | d.round(d.buf[0..], true); | 135 | d.round(d.buf[0..], true); |
| 136 | for (d.h) |*x| x.* = mem.nativeToLittle(u32, x.*); | 136 | for (&d.h) |*x| x.* = mem.nativeToLittle(u32, x.*); |
| 137 | mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h)); | 137 | mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h)); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| ... | @@ -141,7 +141,7 @@ pub fn Blake2s(comptime out_bits: usize) type { | ... | @@ -141,7 +141,7 @@ pub fn Blake2s(comptime out_bits: usize) type { |
| 141 | var m: [16]u32 = undefined; | 141 | var m: [16]u32 = undefined; |
| 142 | var v: [16]u32 = undefined; | 142 | var v: [16]u32 = undefined; |
| 143 | 143 | ||
| 144 | for (m) |*r, i| { | 144 | for (&m, 0..) |*r, i| { |
| 145 | r.* = mem.readIntLittle(u32, b[4 * i ..][0..4]); | 145 | r.* = mem.readIntLittle(u32, b[4 * i ..][0..4]); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| ... | @@ -180,7 +180,7 @@ pub fn Blake2s(comptime out_bits: usize) type { | ... | @@ -180,7 +180,7 @@ pub fn Blake2s(comptime out_bits: usize) type { |
| 180 | } | 180 | } |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | for (d.h) |*r, i| { | 183 | for (&d.h, 0..) |*r, i| { |
| 184 | r.* ^= v[i] ^ v[i + 8]; | 184 | r.* ^= v[i] ^ v[i + 8]; |
| 185 | } | 185 | } |
| 186 | } | 186 | } |
| ... | @@ -568,7 +568,7 @@ pub fn Blake2b(comptime out_bits: usize) type { | ... | @@ -568,7 +568,7 @@ pub fn Blake2b(comptime out_bits: usize) type { |
| 568 | mem.set(u8, d.buf[d.buf_len..], 0); | 568 | mem.set(u8, d.buf[d.buf_len..], 0); |
| 569 | d.t += d.buf_len; | 569 | d.t += d.buf_len; |
| 570 | d.round(d.buf[0..], true); | 570 | d.round(d.buf[0..], true); |
| 571 | for (d.h) |*x| x.* = mem.nativeToLittle(u64, x.*); | 571 | for (&d.h) |*x| x.* = mem.nativeToLittle(u64, x.*); |
| 572 | mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h)); | 572 | mem.copy(u8, out[0..], @ptrCast(*[digest_length]u8, &d.h)); |
| 573 | } | 573 | } |
| 574 | 574 | ||
| ... | @@ -576,7 +576,7 @@ pub fn Blake2b(comptime out_bits: usize) type { | ... | @@ -576,7 +576,7 @@ pub fn Blake2b(comptime out_bits: usize) type { |
| 576 | var m: [16]u64 = undefined; | 576 | var m: [16]u64 = undefined; |
| 577 | var v: [16]u64 = undefined; | 577 | var v: [16]u64 = undefined; |
| 578 | 578 | ||
| 579 | for (m) |*r, i| { | 579 | for (&m, 0..) |*r, i| { |
| 580 | r.* = mem.readIntLittle(u64, b[8 * i ..][0..8]); | 580 | r.* = mem.readIntLittle(u64, b[8 * i ..][0..8]); |
| 581 | } | 581 | } |
| 582 | 582 | ||
| ... | @@ -615,7 +615,7 @@ pub fn Blake2b(comptime out_bits: usize) type { | ... | @@ -615,7 +615,7 @@ pub fn Blake2b(comptime out_bits: usize) type { |
| 615 | } | 615 | } |
| 616 | } | 616 | } |
| 617 | 617 | ||
| 618 | for (d.h) |*r, i| { | 618 | for (&d.h, 0..) |*r, i| { |
| 619 | r.* ^= v[i] ^ v[i + 8]; | 619 | r.* ^= v[i] ^ v[i + 8]; |
| 620 | } | 620 | } |
| 621 | } | 621 | } |
lib/std/crypto/blake3.zig+3-3| ... | @@ -192,7 +192,7 @@ const CompressGeneric = struct { | ... | @@ -192,7 +192,7 @@ const CompressGeneric = struct { |
| 192 | for (MSG_SCHEDULE) |schedule| { | 192 | for (MSG_SCHEDULE) |schedule| { |
| 193 | round(&state, block_words, schedule); | 193 | round(&state, block_words, schedule); |
| 194 | } | 194 | } |
| 195 | for (chaining_value) |_, i| { | 195 | for (chaining_value, 0..) |_, i| { |
| 196 | state[i] ^= state[i + 8]; | 196 | state[i] ^= state[i + 8]; |
| 197 | state[i + 8] ^= chaining_value[i]; | 197 | state[i + 8] ^= chaining_value[i]; |
| 198 | } | 198 | } |
| ... | @@ -211,7 +211,7 @@ fn first8Words(words: [16]u32) [8]u32 { | ... | @@ -211,7 +211,7 @@ fn first8Words(words: [16]u32) [8]u32 { |
| 211 | 211 | ||
| 212 | fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 { | 212 | fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 { |
| 213 | var words: [count]u32 = undefined; | 213 | var words: [count]u32 = undefined; |
| 214 | for (words) |*word, i| { | 214 | for (&words, 0..) |*word, i| { |
| 215 | word.* = mem.readIntSliceLittle(u32, bytes[4 * i ..]); | 215 | word.* = mem.readIntSliceLittle(u32, bytes[4 * i ..]); |
| 216 | } | 216 | } |
| 217 | return words; | 217 | return words; |
| ... | @@ -658,7 +658,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void { | ... | @@ -658,7 +658,7 @@ fn testBlake3(hasher: *Blake3, input_len: usize, expected_hex: [262]u8) !void { |
| 658 | 658 | ||
| 659 | // Setup input pattern | 659 | // Setup input pattern |
| 660 | var input_pattern: [251]u8 = undefined; | 660 | var input_pattern: [251]u8 = undefined; |
| 661 | for (input_pattern) |*e, i| e.* = @truncate(u8, i); | 661 | for (&input_pattern, 0..) |*e, i| e.* = @truncate(u8, i); |
| 662 | 662 | ||
| 663 | // Write repeating input pattern to hasher | 663 | // Write repeating input pattern to hasher |
| 664 | var input_counter = input_len; | 664 | var input_counter = input_len; |
lib/std/crypto/chacha20.zig+3-3| ... | @@ -197,7 +197,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type { | ... | @@ -197,7 +197,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type { |
| 197 | 197 | ||
| 198 | fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { | 198 | fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { |
| 199 | var c: [4]u32 = undefined; | 199 | var c: [4]u32 = undefined; |
| 200 | for (c) |_, i| { | 200 | for (c, 0..) |_, i| { |
| 201 | c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]); | 201 | c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]); |
| 202 | } | 202 | } |
| 203 | const ctx = initContext(keyToWords(key), c); | 203 | const ctx = initContext(keyToWords(key), c); |
| ... | @@ -338,7 +338,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { | ... | @@ -338,7 +338,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { |
| 338 | 338 | ||
| 339 | fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { | 339 | fn hchacha20(input: [16]u8, key: [32]u8) [32]u8 { |
| 340 | var c: [4]u32 = undefined; | 340 | var c: [4]u32 = undefined; |
| 341 | for (c) |_, i| { | 341 | for (c, 0..) |_, i| { |
| 342 | c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]); | 342 | c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]); |
| 343 | } | 343 | } |
| 344 | const ctx = initContext(keyToWords(key), c); | 344 | const ctx = initContext(keyToWords(key), c); |
| ... | @@ -543,7 +543,7 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { | ... | @@ -543,7 +543,7 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 543 | mac.final(computedTag[0..]); | 543 | mac.final(computedTag[0..]); |
| 544 | 544 | ||
| 545 | var acc: u8 = 0; | 545 | var acc: u8 = 0; |
| 546 | for (computedTag) |_, i| { | 546 | for (computedTag, 0..) |_, i| { |
| 547 | acc |= computedTag[i] ^ tag[i]; | 547 | acc |= computedTag[i] ^ tag[i]; |
| 548 | } | 548 | } |
| 549 | if (acc != 0) { | 549 | if (acc != 0) { |
lib/std/crypto/cmac.zig+4-4| ... | @@ -46,19 +46,19 @@ pub fn Cmac(comptime BlockCipher: type) type { | ... | @@ -46,19 +46,19 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 46 | const left = block_length - self.pos; | 46 | const left = block_length - self.pos; |
| 47 | var m = msg; | 47 | var m = msg; |
| 48 | if (m.len > left) { | 48 | if (m.len > left) { |
| 49 | for (self.buf[self.pos..]) |*b, i| b.* ^= m[i]; | 49 | for (self.buf[self.pos..], 0..) |*b, i| b.* ^= m[i]; |
| 50 | m = m[left..]; | 50 | m = m[left..]; |
| 51 | self.cipher_ctx.encrypt(&self.buf, &self.buf); | 51 | self.cipher_ctx.encrypt(&self.buf, &self.buf); |
| 52 | self.pos = 0; | 52 | self.pos = 0; |
| 53 | } | 53 | } |
| 54 | while (m.len > block_length) { | 54 | while (m.len > block_length) { |
| 55 | for (self.buf[0..block_length]) |*b, i| b.* ^= m[i]; | 55 | for (self.buf[0..block_length], 0..) |*b, i| b.* ^= m[i]; |
| 56 | m = m[block_length..]; | 56 | m = m[block_length..]; |
| 57 | self.cipher_ctx.encrypt(&self.buf, &self.buf); | 57 | self.cipher_ctx.encrypt(&self.buf, &self.buf); |
| 58 | self.pos = 0; | 58 | self.pos = 0; |
| 59 | } | 59 | } |
| 60 | if (m.len > 0) { | 60 | if (m.len > 0) { |
| 61 | for (self.buf[self.pos..][0..m.len]) |*b, i| b.* ^= m[i]; | 61 | for (self.buf[self.pos..][0..m.len], 0..) |*b, i| b.* ^= m[i]; |
| 62 | self.pos += m.len; | 62 | self.pos += m.len; |
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| ... | @@ -69,7 +69,7 @@ pub fn Cmac(comptime BlockCipher: type) type { | ... | @@ -69,7 +69,7 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 69 | mac = self.k2; | 69 | mac = self.k2; |
| 70 | mac[self.pos] ^= 0x80; | 70 | mac[self.pos] ^= 0x80; |
| 71 | } | 71 | } |
| 72 | for (mac) |*b, i| b.* ^= self.buf[i]; | 72 | for (&mac, 0..) |*b, i| b.* ^= self.buf[i]; |
| 73 | self.cipher_ctx.encrypt(out, &mac); | 73 | self.cipher_ctx.encrypt(out, &mac); |
| 74 | } | 74 | } |
| 75 | 75 |
lib/std/crypto/ghash_polyval.zig+2-2| ... | @@ -320,7 +320,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | ... | @@ -320,7 +320,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 320 | if (st.leftover > 0) { | 320 | if (st.leftover > 0) { |
| 321 | const want = math.min(block_length - st.leftover, mb.len); | 321 | const want = math.min(block_length - st.leftover, mb.len); |
| 322 | const mc = mb[0..want]; | 322 | const mc = mb[0..want]; |
| 323 | for (mc) |x, i| { | 323 | for (mc, 0..) |x, i| { |
| 324 | st.buf[st.leftover + i] = x; | 324 | st.buf[st.leftover + i] = x; |
| 325 | } | 325 | } |
| 326 | mb = mb[want..]; | 326 | mb = mb[want..]; |
| ... | @@ -337,7 +337,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | ... | @@ -337,7 +337,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 337 | mb = mb[want..]; | 337 | mb = mb[want..]; |
| 338 | } | 338 | } |
| 339 | if (mb.len > 0) { | 339 | if (mb.len > 0) { |
| 340 | for (mb) |x, i| { | 340 | for (mb, 0..) |x, i| { |
| 341 | st.buf[st.leftover + i] = x; | 341 | st.buf[st.leftover + i] = x; |
| 342 | } | 342 | } |
| 343 | st.leftover += mb.len; | 343 | st.leftover += mb.len; |
lib/std/crypto/gimli.zig+8-8| ... | @@ -45,7 +45,7 @@ pub const State = struct { | ... | @@ -45,7 +45,7 @@ pub const State = struct { |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | inline fn endianSwap(self: *Self) void { | 47 | inline fn endianSwap(self: *Self) void { |
| 48 | for (self.data) |*w| { | 48 | for (&self.data) |*w| { |
| 49 | w.* = mem.littleToNative(u32, w.*); | 49 | w.* = mem.littleToNative(u32, w.*); |
| 50 | } | 50 | } |
| 51 | } | 51 | } |
| ... | @@ -228,7 +228,7 @@ pub const Hash = struct { | ... | @@ -228,7 +228,7 @@ pub const Hash = struct { |
| 228 | while (in.len > 0) { | 228 | while (in.len > 0) { |
| 229 | const left = State.RATE - self.buf_off; | 229 | const left = State.RATE - self.buf_off; |
| 230 | const ps = math.min(in.len, left); | 230 | const ps = math.min(in.len, left); |
| 231 | for (buf[self.buf_off .. self.buf_off + ps]) |*p, i| { | 231 | for (buf[self.buf_off .. self.buf_off + ps], 0..) |*p, i| { |
| 232 | p.* ^= in[i]; | 232 | p.* ^= in[i]; |
| 233 | } | 233 | } |
| 234 | self.buf_off += ps; | 234 | self.buf_off += ps; |
| ... | @@ -329,12 +329,12 @@ pub const Aead = struct { | ... | @@ -329,12 +329,12 @@ pub const Aead = struct { |
| 329 | // exactly one final non-full block, in the same way as Gimli-Hash. | 329 | // exactly one final non-full block, in the same way as Gimli-Hash. |
| 330 | var data = ad; | 330 | var data = ad; |
| 331 | while (data.len >= State.RATE) : (data = data[State.RATE..]) { | 331 | while (data.len >= State.RATE) : (data = data[State.RATE..]) { |
| 332 | for (buf[0..State.RATE]) |*p, i| { | 332 | for (buf[0..State.RATE], 0..) |*p, i| { |
| 333 | p.* ^= data[i]; | 333 | p.* ^= data[i]; |
| 334 | } | 334 | } |
| 335 | state.permute(); | 335 | state.permute(); |
| 336 | } | 336 | } |
| 337 | for (buf[0..data.len]) |*p, i| { | 337 | for (buf[0..data.len], 0..) |*p, i| { |
| 338 | p.* ^= data[i]; | 338 | p.* ^= data[i]; |
| 339 | } | 339 | } |
| 340 | 340 | ||
| ... | @@ -371,13 +371,13 @@ pub const Aead = struct { | ... | @@ -371,13 +371,13 @@ pub const Aead = struct { |
| 371 | in = in[State.RATE..]; | 371 | in = in[State.RATE..]; |
| 372 | out = out[State.RATE..]; | 372 | out = out[State.RATE..]; |
| 373 | }) { | 373 | }) { |
| 374 | for (in[0..State.RATE]) |v, i| { | 374 | for (in[0..State.RATE], 0..) |v, i| { |
| 375 | buf[i] ^= v; | 375 | buf[i] ^= v; |
| 376 | } | 376 | } |
| 377 | mem.copy(u8, out[0..State.RATE], buf[0..State.RATE]); | 377 | mem.copy(u8, out[0..State.RATE], buf[0..State.RATE]); |
| 378 | state.permute(); | 378 | state.permute(); |
| 379 | } | 379 | } |
| 380 | for (in[0..]) |v, i| { | 380 | for (in[0..], 0..) |v, i| { |
| 381 | buf[i] ^= v; | 381 | buf[i] ^= v; |
| 382 | out[i] = buf[i]; | 382 | out[i] = buf[i]; |
| 383 | } | 383 | } |
| ... | @@ -414,13 +414,13 @@ pub const Aead = struct { | ... | @@ -414,13 +414,13 @@ pub const Aead = struct { |
| 414 | out = out[State.RATE..]; | 414 | out = out[State.RATE..]; |
| 415 | }) { | 415 | }) { |
| 416 | const d = in[0..State.RATE].*; | 416 | const d = in[0..State.RATE].*; |
| 417 | for (d) |v, i| { | 417 | for (d, 0..) |v, i| { |
| 418 | out[i] = buf[i] ^ v; | 418 | out[i] = buf[i] ^ v; |
| 419 | } | 419 | } |
| 420 | mem.copy(u8, buf[0..State.RATE], d[0..State.RATE]); | 420 | mem.copy(u8, buf[0..State.RATE], d[0..State.RATE]); |
| 421 | state.permute(); | 421 | state.permute(); |
| 422 | } | 422 | } |
| 423 | for (buf[0..in.len]) |*p, i| { | 423 | for (buf[0..in.len], 0..) |*p, i| { |
| 424 | const d = in[i]; | 424 | const d = in[i]; |
| 425 | out[i] = p.* ^ d; | 425 | out[i] = p.* ^ d; |
| 426 | p.* = d; | 426 | p.* = d; |
lib/std/crypto/hmac.zig+2-2| ... | @@ -46,11 +46,11 @@ pub fn Hmac(comptime Hash: type) type { | ... | @@ -46,11 +46,11 @@ pub fn Hmac(comptime Hash: type) type { |
| 46 | mem.copy(u8, scratch[0..], key); | 46 | mem.copy(u8, scratch[0..], key); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | for (ctx.o_key_pad) |*b, i| { | 49 | for (&ctx.o_key_pad, 0..) |*b, i| { |
| 50 | b.* = scratch[i] ^ 0x5c; | 50 | b.* = scratch[i] ^ 0x5c; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | for (i_key_pad) |*b, i| { | 53 | for (&i_key_pad, 0..) |*b, i| { |
| 54 | b.* = scratch[i] ^ 0x36; | 54 | b.* = scratch[i] ^ 0x36; |
| 55 | } | 55 | } |
| 56 | 56 |
lib/std/crypto/md5.zig+1-1| ... | @@ -110,7 +110,7 @@ pub const Md5 = struct { | ... | @@ -110,7 +110,7 @@ pub const Md5 = struct { |
| 110 | 110 | ||
| 111 | d.round(d.buf[0..]); | 111 | d.round(d.buf[0..]); |
| 112 | 112 | ||
| 113 | for (d.s) |s, j| { | 113 | for (d.s, 0..) |s, j| { |
| 114 | mem.writeIntLittle(u32, out[4 * j ..][0..4], s); | 114 | mem.writeIntLittle(u32, out[4 * j ..][0..4], s); |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
lib/std/crypto/pbkdf2.zig+1-1| ... | @@ -138,7 +138,7 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com | ... | @@ -138,7 +138,7 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com |
| 138 | mem.copy(u8, prev_block[0..], new_block[0..]); | 138 | mem.copy(u8, prev_block[0..], new_block[0..]); |
| 139 | 139 | ||
| 140 | // F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c | 140 | // F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c |
| 141 | for (dk_block) |_, j| { | 141 | for (dk_block, 0..) |_, j| { |
| 142 | dk_block[j] ^= new_block[j]; | 142 | dk_block[j] ^= new_block[j]; |
| 143 | } | 143 | } |
| 144 | } | 144 | } |
lib/std/crypto/pcurves/common.zig+1-1| ... | @@ -65,7 +65,7 @@ pub fn Field(comptime params: FieldParams) type { | ... | @@ -65,7 +65,7 @@ pub fn Field(comptime params: FieldParams) type { |
| 65 | /// Swap the endianness of an encoded element. | 65 | /// Swap the endianness of an encoded element. |
| 66 | pub fn orderSwap(s: [encoded_length]u8) [encoded_length]u8 { | 66 | pub fn orderSwap(s: [encoded_length]u8) [encoded_length]u8 { |
| 67 | var t = s; | 67 | var t = s; |
| 68 | for (s) |x, i| t[t.len - 1 - i] = x; | 68 | for (s, 0..) |x, i| t[t.len - 1 - i] = x; |
| 69 | return t; | 69 | return t; |
| 70 | } | 70 | } |
| 71 | 71 |
lib/std/crypto/pcurves/p256.zig+1-1| ... | @@ -321,7 +321,7 @@ pub const P256 = struct { | ... | @@ -321,7 +321,7 @@ pub const P256 = struct { |
| 321 | 321 | ||
| 322 | fn slide(s: [32]u8) [2 * 32 + 1]i8 { | 322 | fn slide(s: [32]u8) [2 * 32 + 1]i8 { |
| 323 | var e: [2 * 32 + 1]i8 = undefined; | 323 | var e: [2 * 32 + 1]i8 = undefined; |
| 324 | for (s) |x, i| { | 324 | for (s, 0..) |x, i| { |
| 325 | e[i * 2 + 0] = @as(i8, @truncate(u4, x)); | 325 | e[i * 2 + 0] = @as(i8, @truncate(u4, x)); |
| 326 | e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4)); | 326 | e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4)); |
| 327 | } | 327 | } |
lib/std/crypto/pcurves/p256/scalar.zig+1-1| ... | @@ -187,7 +187,7 @@ const ScalarDouble = struct { | ... | @@ -187,7 +187,7 @@ const ScalarDouble = struct { |
| 187 | 187 | ||
| 188 | var s = s_; | 188 | var s = s_; |
| 189 | if (endian == .Big) { | 189 | if (endian == .Big) { |
| 190 | for (s_) |x, i| s[s.len - 1 - i] = x; | 190 | for (s_, 0..) |x, i| s[s.len - 1 - i] = x; |
| 191 | } | 191 | } |
| 192 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; | 192 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; |
| 193 | { | 193 | { |
lib/std/crypto/pcurves/p384.zig+1-1| ... | @@ -321,7 +321,7 @@ pub const P384 = struct { | ... | @@ -321,7 +321,7 @@ pub const P384 = struct { |
| 321 | 321 | ||
| 322 | fn slide(s: [48]u8) [2 * 48 + 1]i8 { | 322 | fn slide(s: [48]u8) [2 * 48 + 1]i8 { |
| 323 | var e: [2 * 48 + 1]i8 = undefined; | 323 | var e: [2 * 48 + 1]i8 = undefined; |
| 324 | for (s) |x, i| { | 324 | for (s, 0..) |x, i| { |
| 325 | e[i * 2 + 0] = @as(i8, @truncate(u4, x)); | 325 | e[i * 2 + 0] = @as(i8, @truncate(u4, x)); |
| 326 | e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4)); | 326 | e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4)); |
| 327 | } | 327 | } |
lib/std/crypto/pcurves/p384/scalar.zig+1-1| ... | @@ -175,7 +175,7 @@ const ScalarDouble = struct { | ... | @@ -175,7 +175,7 @@ const ScalarDouble = struct { |
| 175 | 175 | ||
| 176 | var s = s_; | 176 | var s = s_; |
| 177 | if (endian == .Big) { | 177 | if (endian == .Big) { |
| 178 | for (s_) |x, i| s[s.len - 1 - i] = x; | 178 | for (s_, 0..) |x, i| s[s.len - 1 - i] = x; |
| 179 | } | 179 | } |
| 180 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero }; | 180 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero }; |
| 181 | { | 181 | { |
lib/std/crypto/pcurves/secp256k1.zig+1-1| ... | @@ -349,7 +349,7 @@ pub const Secp256k1 = struct { | ... | @@ -349,7 +349,7 @@ pub const Secp256k1 = struct { |
| 349 | 349 | ||
| 350 | fn slide(s: [32]u8) [2 * 32 + 1]i8 { | 350 | fn slide(s: [32]u8) [2 * 32 + 1]i8 { |
| 351 | var e: [2 * 32 + 1]i8 = undefined; | 351 | var e: [2 * 32 + 1]i8 = undefined; |
| 352 | for (s) |x, i| { | 352 | for (s, 0..) |x, i| { |
| 353 | e[i * 2 + 0] = @as(i8, @truncate(u4, x)); | 353 | e[i * 2 + 0] = @as(i8, @truncate(u4, x)); |
| 354 | e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4)); | 354 | e[i * 2 + 1] = @as(i8, @truncate(u4, x >> 4)); |
| 355 | } | 355 | } |
lib/std/crypto/pcurves/secp256k1/scalar.zig+1-1| ... | @@ -187,7 +187,7 @@ const ScalarDouble = struct { | ... | @@ -187,7 +187,7 @@ const ScalarDouble = struct { |
| 187 | 187 | ||
| 188 | var s = s_; | 188 | var s = s_; |
| 189 | if (endian == .Big) { | 189 | if (endian == .Big) { |
| 190 | for (s_) |x, i| s[s.len - 1 - i] = x; | 190 | for (s_, 0..) |x, i| s[s.len - 1 - i] = x; |
| 191 | } | 191 | } |
| 192 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; | 192 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; |
| 193 | { | 193 | { |
lib/std/crypto/poly1305.zig+2-2| ... | @@ -82,7 +82,7 @@ pub const Poly1305 = struct { | ... | @@ -82,7 +82,7 @@ pub const Poly1305 = struct { |
| 82 | if (st.leftover > 0) { | 82 | if (st.leftover > 0) { |
| 83 | const want = std.math.min(block_length - st.leftover, mb.len); | 83 | const want = std.math.min(block_length - st.leftover, mb.len); |
| 84 | const mc = mb[0..want]; | 84 | const mc = mb[0..want]; |
| 85 | for (mc) |x, i| { | 85 | for (mc, 0..) |x, i| { |
| 86 | st.buf[st.leftover + i] = x; | 86 | st.buf[st.leftover + i] = x; |
| 87 | } | 87 | } |
| 88 | mb = mb[want..]; | 88 | mb = mb[want..]; |
| ... | @@ -103,7 +103,7 @@ pub const Poly1305 = struct { | ... | @@ -103,7 +103,7 @@ pub const Poly1305 = struct { |
| 103 | 103 | ||
| 104 | // store leftover | 104 | // store leftover |
| 105 | if (mb.len > 0) { | 105 | if (mb.len > 0) { |
| 106 | for (mb) |x, i| { | 106 | for (mb, 0..) |x, i| { |
| 107 | st.buf[st.leftover + i] = x; | 107 | st.buf[st.leftover + i] = x; |
| 108 | } | 108 | } |
| 109 | st.leftover += mb.len; | 109 | st.leftover += mb.len; |
lib/std/crypto/salsa20.zig+4-4| ... | @@ -157,7 +157,7 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { | ... | @@ -157,7 +157,7 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type { |
| 157 | 157 | ||
| 158 | fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { | 158 | fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { |
| 159 | var c: [4]u32 = undefined; | 159 | var c: [4]u32 = undefined; |
| 160 | for (c) |_, i| { | 160 | for (c, 0..) |_, i| { |
| 161 | c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]); | 161 | c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]); |
| 162 | } | 162 | } |
| 163 | const ctx = initContext(keyToWords(key), c); | 163 | const ctx = initContext(keyToWords(key), c); |
| ... | @@ -240,7 +240,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { | ... | @@ -240,7 +240,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | fn hashToBytes(out: *[64]u8, x: BlockVec) void { | 242 | fn hashToBytes(out: *[64]u8, x: BlockVec) void { |
| 243 | for (x) |w, i| { | 243 | for (x, 0..) |w, i| { |
| 244 | mem.writeIntLittle(u32, out[i * 4 ..][0..4], w); | 244 | mem.writeIntLittle(u32, out[i * 4 ..][0..4], w); |
| 245 | } | 245 | } |
| 246 | } | 246 | } |
| ... | @@ -282,7 +282,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { | ... | @@ -282,7 +282,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type { |
| 282 | 282 | ||
| 283 | fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { | 283 | fn hsalsa(input: [16]u8, key: [32]u8) [32]u8 { |
| 284 | var c: [4]u32 = undefined; | 284 | var c: [4]u32 = undefined; |
| 285 | for (c) |_, i| { | 285 | for (c, 0..) |_, i| { |
| 286 | c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]); | 286 | c[i] = mem.readIntLittle(u32, input[4 * i ..][0..4]); |
| 287 | } | 287 | } |
| 288 | const ctx = initContext(keyToWords(key), c); | 288 | const ctx = initContext(keyToWords(key), c); |
| ... | @@ -413,7 +413,7 @@ pub const XSalsa20Poly1305 = struct { | ... | @@ -413,7 +413,7 @@ pub const XSalsa20Poly1305 = struct { |
| 413 | var computedTag: [tag_length]u8 = undefined; | 413 | var computedTag: [tag_length]u8 = undefined; |
| 414 | mac.final(&computedTag); | 414 | mac.final(&computedTag); |
| 415 | var acc: u8 = 0; | 415 | var acc: u8 = 0; |
| 416 | for (computedTag) |_, i| { | 416 | for (computedTag, 0..) |_, i| { |
| 417 | acc |= computedTag[i] ^ tag[i]; | 417 | acc |= computedTag[i] ^ tag[i]; |
| 418 | } | 418 | } |
| 419 | if (acc != 0) { | 419 | if (acc != 0) { |
lib/std/crypto/scrypt.zig+7-7| ... | @@ -31,7 +31,7 @@ fn blockCopy(dst: []align(16) u32, src: []align(16) const u32, n: usize) void { | ... | @@ -31,7 +31,7 @@ fn blockCopy(dst: []align(16) u32, src: []align(16) const u32, n: usize) void { |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | fn blockXor(dst: []align(16) u32, src: []align(16) const u32, n: usize) void { | 33 | fn blockXor(dst: []align(16) u32, src: []align(16) const u32, n: usize) void { |
| 34 | for (src[0 .. n * 16]) |v, i| { | 34 | for (src[0 .. n * 16], 0..) |v, i| { |
| 35 | dst[i] ^= v; | 35 | dst[i] ^= v; |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| ... | @@ -90,7 +90,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) | ... | @@ -90,7 +90,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) |
| 90 | var x = @alignCast(16, xy[0 .. 32 * r]); | 90 | var x = @alignCast(16, xy[0 .. 32 * r]); |
| 91 | var y = @alignCast(16, xy[32 * r ..]); | 91 | var y = @alignCast(16, xy[32 * r ..]); |
| 92 | 92 | ||
| 93 | for (x) |*v1, j| { | 93 | for (x, 0..) |*v1, j| { |
| 94 | v1.* = mem.readIntSliceLittle(u32, b[4 * j ..]); | 94 | v1.* = mem.readIntSliceLittle(u32, b[4 * j ..]); |
| 95 | } | 95 | } |
| 96 | 96 | ||
| ... | @@ -115,7 +115,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) | ... | @@ -115,7 +115,7 @@ fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) |
| 115 | blockMix(&tmp, y, x, r); | 115 | blockMix(&tmp, y, x, r); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | for (x) |v1, j| { | 118 | for (x, 0..) |v1, j| { |
| 119 | mem.writeIntLittle(u32, b[4 * j ..][0..4], v1); | 119 | mem.writeIntLittle(u32, b[4 * j ..][0..4], v1); |
| 120 | } | 120 | } |
| 121 | } | 121 | } |
| ... | @@ -350,7 +350,7 @@ const crypt_format = struct { | ... | @@ -350,7 +350,7 @@ const crypt_format = struct { |
| 350 | 350 | ||
| 351 | fn intDecode(comptime T: type, src: *const [(@bitSizeOf(T) + 5) / 6]u8) !T { | 351 | fn intDecode(comptime T: type, src: *const [(@bitSizeOf(T) + 5) / 6]u8) !T { |
| 352 | var v: T = 0; | 352 | var v: T = 0; |
| 353 | for (src) |x, i| { | 353 | for (src, 0..) |x, i| { |
| 354 | const vi = mem.indexOfScalar(u8, &map64, x) orelse return EncodingError.InvalidEncoding; | 354 | const vi = mem.indexOfScalar(u8, &map64, x) orelse return EncodingError.InvalidEncoding; |
| 355 | v |= @intCast(T, vi) << @intCast(math.Log2Int(T), i * 6); | 355 | v |= @intCast(T, vi) << @intCast(math.Log2Int(T), i * 6); |
| 356 | } | 356 | } |
| ... | @@ -365,10 +365,10 @@ const crypt_format = struct { | ... | @@ -365,10 +365,10 @@ const crypt_format = struct { |
| 365 | } | 365 | } |
| 366 | const leftover = src[i * 4 ..]; | 366 | const leftover = src[i * 4 ..]; |
| 367 | var v: u24 = 0; | 367 | var v: u24 = 0; |
| 368 | for (leftover) |_, j| { | 368 | for (leftover, 0..) |_, j| { |
| 369 | v |= @as(u24, try intDecode(u6, leftover[j..][0..1])) << @intCast(u5, j * 6); | 369 | v |= @as(u24, try intDecode(u6, leftover[j..][0..1])) << @intCast(u5, j * 6); |
| 370 | } | 370 | } |
| 371 | for (dst[i * 3 ..]) |*x, j| { | 371 | for (dst[i * 3 ..], 0..) |*x, j| { |
| 372 | x.* = @truncate(u8, v >> @intCast(u5, j * 8)); | 372 | x.* = @truncate(u8, v >> @intCast(u5, j * 8)); |
| 373 | } | 373 | } |
| 374 | } | 374 | } |
| ... | @@ -381,7 +381,7 @@ const crypt_format = struct { | ... | @@ -381,7 +381,7 @@ const crypt_format = struct { |
| 381 | } | 381 | } |
| 382 | const leftover = src[i * 3 ..]; | 382 | const leftover = src[i * 3 ..]; |
| 383 | var v: u24 = 0; | 383 | var v: u24 = 0; |
| 384 | for (leftover) |x, j| { | 384 | for (leftover, 0..) |x, j| { |
| 385 | v |= @as(u24, x) << @intCast(u5, j * 8); | 385 | v |= @as(u24, x) << @intCast(u5, j * 8); |
| 386 | } | 386 | } |
| 387 | intEncode(dst[i * 4 ..], v); | 387 | intEncode(dst[i * 4 ..], v); |
lib/std/crypto/sha1.zig+1-1| ... | @@ -105,7 +105,7 @@ pub const Sha1 = struct { | ... | @@ -105,7 +105,7 @@ pub const Sha1 = struct { |
| 105 | 105 | ||
| 106 | d.round(d.buf[0..]); | 106 | d.round(d.buf[0..]); |
| 107 | 107 | ||
| 108 | for (d.s) |s, j| { | 108 | for (d.s, 0..) |s, j| { |
| 109 | mem.writeIntBig(u32, out[4 * j ..][0..4], s); | 109 | mem.writeIntBig(u32, out[4 * j ..][0..4], s); |
| 110 | } | 110 | } |
| 111 | } | 111 | } |
lib/std/crypto/sha2.zig+3-3| ... | @@ -175,7 +175,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { | ... | @@ -175,7 +175,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 175 | // May truncate for possible 224 output | 175 | // May truncate for possible 224 output |
| 176 | const rr = d.s[0 .. params.digest_bits / 32]; | 176 | const rr = d.s[0 .. params.digest_bits / 32]; |
| 177 | 177 | ||
| 178 | for (rr) |s, j| { | 178 | for (rr, 0..) |s, j| { |
| 179 | mem.writeIntBig(u32, out[4 * j ..][0..4], s); | 179 | mem.writeIntBig(u32, out[4 * j ..][0..4], s); |
| 180 | } | 180 | } |
| 181 | } | 181 | } |
| ... | @@ -199,7 +199,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { | ... | @@ -199,7 +199,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 199 | 199 | ||
| 200 | fn round(d: *Self, b: *const [64]u8) void { | 200 | fn round(d: *Self, b: *const [64]u8) void { |
| 201 | var s: [64]u32 align(16) = undefined; | 201 | var s: [64]u32 align(16) = undefined; |
| 202 | for (@ptrCast(*align(1) const [16]u32, b)) |*elem, i| { | 202 | for (@ptrCast(*align(1) const [16]u32, b), 0..) |*elem, i| { |
| 203 | s[i] = mem.readIntBig(u32, mem.asBytes(elem)); | 203 | s[i] = mem.readIntBig(u32, mem.asBytes(elem)); |
| 204 | } | 204 | } |
| 205 | 205 | ||
| ... | @@ -665,7 +665,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { | ... | @@ -665,7 +665,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { |
| 665 | // May truncate for possible 384 output | 665 | // May truncate for possible 384 output |
| 666 | const rr = d.s[0 .. params.digest_bits / 64]; | 666 | const rr = d.s[0 .. params.digest_bits / 64]; |
| 667 | 667 | ||
| 668 | for (rr) |s, j| { | 668 | for (rr, 0..) |s, j| { |
| 669 | mem.writeIntBig(u64, out[8 * j ..][0..8], s); | 669 | mem.writeIntBig(u64, out[8 * j ..][0..8], s); |
| 670 | } | 670 | } |
| 671 | } | 671 | } |
lib/std/crypto/sha3.zig+4-4| ... | @@ -43,7 +43,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type { | ... | @@ -43,7 +43,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type { |
| 43 | 43 | ||
| 44 | // absorb | 44 | // absorb |
| 45 | while (len >= rate) { | 45 | while (len >= rate) { |
| 46 | for (d.s[offset .. offset + rate]) |*r, i| | 46 | for (d.s[offset .. offset + rate], 0..) |*r, i| |
| 47 | r.* ^= b[ip..][i]; | 47 | r.* ^= b[ip..][i]; |
| 48 | 48 | ||
| 49 | keccakF(1600, &d.s); | 49 | keccakF(1600, &d.s); |
| ... | @@ -54,7 +54,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type { | ... | @@ -54,7 +54,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type { |
| 54 | offset = 0; | 54 | offset = 0; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | for (d.s[offset .. offset + len]) |*r, i| | 57 | for (d.s[offset .. offset + len], 0..) |*r, i| |
| 58 | r.* ^= b[ip..][i]; | 58 | r.* ^= b[ip..][i]; |
| 59 | 59 | ||
| 60 | d.offset = offset + len; | 60 | d.offset = offset + len; |
| ... | @@ -126,7 +126,7 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void { | ... | @@ -126,7 +126,7 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void { |
| 126 | var t = [_]u64{0} ** 1; | 126 | var t = [_]u64{0} ** 1; |
| 127 | var c = [_]u64{0} ** 5; | 127 | var c = [_]u64{0} ** 5; |
| 128 | 128 | ||
| 129 | for (s) |*r, i| { | 129 | for (&s, 0..) |*r, i| { |
| 130 | r.* = mem.readIntLittle(u64, d[8 * i ..][0..8]); | 130 | r.* = mem.readIntLittle(u64, d[8 * i ..][0..8]); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| ... | @@ -171,7 +171,7 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void { | ... | @@ -171,7 +171,7 @@ fn keccakF(comptime F: usize, d: *[F / 8]u8) void { |
| 171 | s[0] ^= round; | 171 | s[0] ^= round; |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | for (s) |r, i| { | 174 | for (s, 0..) |r, i| { |
| 175 | mem.writeIntLittle(u64, d[8 * i ..][0..8], r); | 175 | mem.writeIntLittle(u64, d[8 * i ..][0..8], r); |
| 176 | } | 176 | } |
| 177 | } | 177 | } |
lib/std/crypto/siphash.zig+3-3| ... | @@ -339,7 +339,7 @@ test "siphash64-2-4 sanity" { | ... | @@ -339,7 +339,7 @@ test "siphash64-2-4 sanity" { |
| 339 | const siphash = SipHash64(2, 4); | 339 | const siphash = SipHash64(2, 4); |
| 340 | 340 | ||
| 341 | var buffer: [64]u8 = undefined; | 341 | var buffer: [64]u8 = undefined; |
| 342 | for (vectors) |vector, i| { | 342 | for (vectors, 0..) |vector, i| { |
| 343 | buffer[i] = @intCast(u8, i); | 343 | buffer[i] = @intCast(u8, i); |
| 344 | 344 | ||
| 345 | var out: [siphash.mac_length]u8 = undefined; | 345 | var out: [siphash.mac_length]u8 = undefined; |
| ... | @@ -419,7 +419,7 @@ test "siphash128-2-4 sanity" { | ... | @@ -419,7 +419,7 @@ test "siphash128-2-4 sanity" { |
| 419 | const siphash = SipHash128(2, 4); | 419 | const siphash = SipHash128(2, 4); |
| 420 | 420 | ||
| 421 | var buffer: [64]u8 = undefined; | 421 | var buffer: [64]u8 = undefined; |
| 422 | for (vectors) |vector, i| { | 422 | for (vectors, 0..) |vector, i| { |
| 423 | buffer[i] = @intCast(u8, i); | 423 | buffer[i] = @intCast(u8, i); |
| 424 | 424 | ||
| 425 | var out: [siphash.mac_length]u8 = undefined; | 425 | var out: [siphash.mac_length]u8 = undefined; |
| ... | @@ -430,7 +430,7 @@ test "siphash128-2-4 sanity" { | ... | @@ -430,7 +430,7 @@ test "siphash128-2-4 sanity" { |
| 430 | 430 | ||
| 431 | test "iterative non-divisible update" { | 431 | test "iterative non-divisible update" { |
| 432 | var buf: [1024]u8 = undefined; | 432 | var buf: [1024]u8 = undefined; |
| 433 | for (buf) |*e, i| { | 433 | for (&buf, 0..) |*e, i| { |
| 434 | e.* = @truncate(u8, i); | 434 | e.* = @truncate(u8, i); |
| 435 | } | 435 | } |
| 436 | 436 |
lib/std/crypto/test.zig+1-1| ... | @@ -13,7 +13,7 @@ pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [ | ... | @@ -13,7 +13,7 @@ pub fn assertEqualHash(comptime Hasher: anytype, comptime expected_hex: *const [ |
| 13 | // Assert `expected` == hex(`input`) where `input` is a bytestring | 13 | // Assert `expected` == hex(`input`) where `input` is a bytestring |
| 14 | pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) !void { | 14 | pub fn assertEqual(comptime expected_hex: [:0]const u8, input: []const u8) !void { |
| 15 | var expected_bytes: [expected_hex.len / 2]u8 = undefined; | 15 | var expected_bytes: [expected_hex.len / 2]u8 = undefined; |
| 16 | for (expected_bytes) |*r, i| { | 16 | for (&expected_bytes, 0..) |*r, i| { |
| 17 | r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable; | 17 | r.* = fmt.parseInt(u8, expected_hex[2 * i .. 2 * i + 2], 16) catch unreachable; |
| 18 | } | 18 | } |
| 19 | 19 |
lib/std/crypto/tls.zig+1-1| ... | @@ -344,7 +344,7 @@ pub inline fn array(comptime elem_size: comptime_int, bytes: anytype) [2 + bytes | ... | @@ -344,7 +344,7 @@ pub inline fn array(comptime elem_size: comptime_int, bytes: anytype) [2 + bytes |
| 344 | pub inline fn enum_array(comptime E: type, comptime tags: []const E) [2 + @sizeOf(E) * tags.len]u8 { | 344 | pub inline fn enum_array(comptime E: type, comptime tags: []const E) [2 + @sizeOf(E) * tags.len]u8 { |
| 345 | assert(@sizeOf(E) == 2); | 345 | assert(@sizeOf(E) == 2); |
| 346 | var result: [tags.len * 2]u8 = undefined; | 346 | var result: [tags.len * 2]u8 = undefined; |
| 347 | for (tags) |elem, i| { | 347 | for (tags, 0..) |elem, i| { |
| 348 | result[i * 2] = @truncate(u8, @enumToInt(elem) >> 8); | 348 | result[i * 2] = @truncate(u8, @enumToInt(elem) >> 8); |
| 349 | result[i * 2 + 1] = @truncate(u8, @enumToInt(elem)); | 349 | result[i * 2 + 1] = @truncate(u8, @enumToInt(elem)); |
| 350 | } | 350 | } |
lib/std/crypto/utils.zig+2-2| ... | @@ -18,7 +18,7 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool { | ... | @@ -18,7 +18,7 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool { |
| 18 | @compileError("Elements to be compared must be integers"); | 18 | @compileError("Elements to be compared must be integers"); |
| 19 | } | 19 | } |
| 20 | var acc = @as(C, 0); | 20 | var acc = @as(C, 0); |
| 21 | for (a) |x, i| { | 21 | for (a, 0..) |x, i| { |
| 22 | acc |= x ^ b[i]; | 22 | acc |= x ^ b[i]; |
| 23 | } | 23 | } |
| 24 | const s = @typeInfo(C).Int.bits; | 24 | const s = @typeInfo(C).Int.bits; |
| ... | @@ -64,7 +64,7 @@ pub fn timingSafeCompare(comptime T: type, a: []const T, b: []const T, endian: E | ... | @@ -64,7 +64,7 @@ pub fn timingSafeCompare(comptime T: type, a: []const T, b: []const T, endian: E |
| 64 | eq &= @truncate(T, (@as(Cext, (x2 ^ x1)) -% 1) >> bits); | 64 | eq &= @truncate(T, (@as(Cext, (x2 ^ x1)) -% 1) >> bits); |
| 65 | } | 65 | } |
| 66 | } else { | 66 | } else { |
| 67 | for (a) |x1, i| { | 67 | for (a, 0..) |x1, i| { |
| 68 | const x2 = b[i]; | 68 | const x2 = b[i]; |
| 69 | gt |= @truncate(T, (@as(Cext, x2) -% @as(Cext, x1)) >> bits) & eq; | 69 | gt |= @truncate(T, (@as(Cext, x2) -% @as(Cext, x1)) >> bits) & eq; |
| 70 | eq &= @truncate(T, (@as(Cext, (x2 ^ x1)) -% 1) >> bits); | 70 | eq &= @truncate(T, (@as(Cext, (x2 ^ x1)) -% 1) >> bits); |
lib/std/crypto/xoodoo.zig+1-1| ... | @@ -66,7 +66,7 @@ pub const State = struct { | ... | @@ -66,7 +66,7 @@ pub const State = struct { |
| 66 | /// XOR bytes into the beginning of the state. | 66 | /// XOR bytes into the beginning of the state. |
| 67 | pub fn addBytes(self: *State, bytes: []const u8) void { | 67 | pub fn addBytes(self: *State, bytes: []const u8) void { |
| 68 | self.endianSwap(); | 68 | self.endianSwap(); |
| 69 | for (self.asBytes()[0..bytes.len]) |*byte, i| { | 69 | for (self.asBytes()[0..bytes.len], 0..) |*byte, i| { |
| 70 | byte.* ^= bytes[i]; | 70 | byte.* ^= bytes[i]; |
| 71 | } | 71 | } |
| 72 | self.endianSwap(); | 72 | self.endianSwap(); |
lib/std/debug.zig+5-5| ... | @@ -213,7 +213,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *std.builtin.StackT | ... | @@ -213,7 +213,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *std.builtin.StackT |
| 213 | var addr_buf_stack: [32]usize = undefined; | 213 | var addr_buf_stack: [32]usize = undefined; |
| 214 | const addr_buf = if (addr_buf_stack.len > addrs.len) addr_buf_stack[0..] else addrs; | 214 | const addr_buf = if (addr_buf_stack.len > addrs.len) addr_buf_stack[0..] else addrs; |
| 215 | const n = walkStackWindows(addr_buf[0..]); | 215 | const n = walkStackWindows(addr_buf[0..]); |
| 216 | const first_index = for (addr_buf[0..n]) |addr, i| { | 216 | const first_index = for (addr_buf[0..n], 0..) |addr, i| { |
| 217 | if (addr == first_addr) { | 217 | if (addr == first_addr) { |
| 218 | break i; | 218 | break i; |
| 219 | } | 219 | } |
| ... | @@ -224,13 +224,13 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *std.builtin.StackT | ... | @@ -224,13 +224,13 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *std.builtin.StackT |
| 224 | const end_index = math.min(first_index + addrs.len, n); | 224 | const end_index = math.min(first_index + addrs.len, n); |
| 225 | const slice = addr_buf[first_index..end_index]; | 225 | const slice = addr_buf[first_index..end_index]; |
| 226 | // We use a for loop here because slice and addrs may alias. | 226 | // We use a for loop here because slice and addrs may alias. |
| 227 | for (slice) |addr, i| { | 227 | for (slice, 0..) |addr, i| { |
| 228 | addrs[i] = addr; | 228 | addrs[i] = addr; |
| 229 | } | 229 | } |
| 230 | stack_trace.index = slice.len; | 230 | stack_trace.index = slice.len; |
| 231 | } else { | 231 | } else { |
| 232 | var it = StackIterator.init(first_address, null); | 232 | var it = StackIterator.init(first_address, null); |
| 233 | for (stack_trace.instruction_addresses) |*addr, i| { | 233 | for (stack_trace.instruction_addresses, 0..) |*addr, i| { |
| 234 | addr.* = it.next() orelse { | 234 | addr.* = it.next() orelse { |
| 235 | stack_trace.index = i; | 235 | stack_trace.index = i; |
| 236 | return; | 236 | return; |
| ... | @@ -621,7 +621,7 @@ pub fn writeCurrentStackTraceWindows( | ... | @@ -621,7 +621,7 @@ pub fn writeCurrentStackTraceWindows( |
| 621 | const n = walkStackWindows(addr_buf[0..]); | 621 | const n = walkStackWindows(addr_buf[0..]); |
| 622 | const addrs = addr_buf[0..n]; | 622 | const addrs = addr_buf[0..n]; |
| 623 | var start_i: usize = if (start_addr) |saddr| blk: { | 623 | var start_i: usize = if (start_addr) |saddr| blk: { |
| 624 | for (addrs) |addr, i| { | 624 | for (addrs, 0..) |addr, i| { |
| 625 | if (addr == saddr) break :blk i; | 625 | if (addr == saddr) break :blk i; |
| 626 | } | 626 | } |
| 627 | return; | 627 | return; |
| ... | @@ -2138,7 +2138,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize | ... | @@ -2138,7 +2138,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize |
| 2138 | ) catch return; | 2138 | ) catch return; |
| 2139 | return; | 2139 | return; |
| 2140 | }; | 2140 | }; |
| 2141 | for (t.addrs[0..end]) |frames_array, i| { | 2141 | for (t.addrs[0..end], 0..) |frames_array, i| { |
| 2142 | stderr.print("{s}:\n", .{t.notes[i]}) catch return; | 2142 | stderr.print("{s}:\n", .{t.notes[i]}) catch return; |
| 2143 | var frames_array_mutable = frames_array; | 2143 | var frames_array_mutable = frames_array; |
| 2144 | const frames = mem.sliceTo(frames_array_mutable[0..], 0); | 2144 | const frames = mem.sliceTo(frames_array_mutable[0..], 0); |
lib/std/dwarf.zig+1-1| ... | @@ -1064,7 +1064,7 @@ pub const DwarfInfo = struct { | ... | @@ -1064,7 +1064,7 @@ pub const DwarfInfo = struct { |
| 1064 | .has_children = table_entry.has_children, | 1064 | .has_children = table_entry.has_children, |
| 1065 | }; | 1065 | }; |
| 1066 | try result.attrs.resize(allocator, table_entry.attrs.items.len); | 1066 | try result.attrs.resize(allocator, table_entry.attrs.items.len); |
| 1067 | for (table_entry.attrs.items) |attr, i| { | 1067 | for (table_entry.attrs.items, 0..) |attr, i| { |
| 1068 | result.attrs.items[i] = Die.Attr{ | 1068 | result.attrs.items[i] = Die.Attr{ |
| 1069 | .id = attr.attr_id, | 1069 | .id = attr.attr_id, |
| 1070 | .value = try parseFormValue( | 1070 | .value = try parseFormValue( |
lib/std/enums.zig+2-2| ... | @@ -35,7 +35,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def | ... | @@ -35,7 +35,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def |
| 35 | pub fn valuesFromFields(comptime E: type, comptime fields: []const EnumField) []const E { | 35 | pub fn valuesFromFields(comptime E: type, comptime fields: []const EnumField) []const E { |
| 36 | comptime { | 36 | comptime { |
| 37 | var result: [fields.len]E = undefined; | 37 | var result: [fields.len]E = undefined; |
| 38 | for (fields) |f, i| { | 38 | for (fields, 0..) |f, i| { |
| 39 | result[i] = @field(E, f.name); | 39 | result[i] = @field(E, f.name); |
| 40 | } | 40 | } |
| 41 | return &result; | 41 | return &result; |
| ... | @@ -1331,7 +1331,7 @@ pub fn EnumIndexer(comptime E: type) type { | ... | @@ -1331,7 +1331,7 @@ pub fn EnumIndexer(comptime E: type) type { |
| 1331 | pub const Key = E; | 1331 | pub const Key = E; |
| 1332 | pub const count = fields_len; | 1332 | pub const count = fields_len; |
| 1333 | pub fn indexOf(e: E) usize { | 1333 | pub fn indexOf(e: E) usize { |
| 1334 | for (keys) |k, i| { | 1334 | for (keys, 0..) |k, i| { |
| 1335 | if (k == e) return i; | 1335 | if (k == e) return i; |
| 1336 | } | 1336 | } |
| 1337 | unreachable; | 1337 | unreachable; |
lib/std/event/loop.zig+2-2| ... | @@ -278,7 +278,7 @@ pub const Loop = struct { | ... | @@ -278,7 +278,7 @@ pub const Loop = struct { |
| 278 | 278 | ||
| 279 | const empty_kevs = &[0]os.Kevent{}; | 279 | const empty_kevs = &[0]os.Kevent{}; |
| 280 | 280 | ||
| 281 | for (self.eventfd_resume_nodes) |*eventfd_node, i| { | 281 | for (self.eventfd_resume_nodes, 0..) |*eventfd_node, i| { |
| 282 | eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{ | 282 | eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{ |
| 283 | .data = ResumeNode.EventFd{ | 283 | .data = ResumeNode.EventFd{ |
| 284 | .base = ResumeNode{ | 284 | .base = ResumeNode{ |
| ... | @@ -343,7 +343,7 @@ pub const Loop = struct { | ... | @@ -343,7 +343,7 @@ pub const Loop = struct { |
| 343 | 343 | ||
| 344 | const empty_kevs = &[0]os.Kevent{}; | 344 | const empty_kevs = &[0]os.Kevent{}; |
| 345 | 345 | ||
| 346 | for (self.eventfd_resume_nodes) |*eventfd_node, i| { | 346 | for (self.eventfd_resume_nodes, 0..) |*eventfd_node, i| { |
| 347 | eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{ | 347 | eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{ |
| 348 | .data = ResumeNode.EventFd{ | 348 | .data = ResumeNode.EventFd{ |
| 349 | .base = ResumeNode{ | 349 | .base = ResumeNode{ |
lib/std/fmt.zig+5-5| ... | @@ -570,7 +570,7 @@ pub fn formatType( | ... | @@ -570,7 +570,7 @@ pub fn formatType( |
| 570 | return writer.writeAll("{ ... }"); | 570 | return writer.writeAll("{ ... }"); |
| 571 | } | 571 | } |
| 572 | try writer.writeAll("{"); | 572 | try writer.writeAll("{"); |
| 573 | inline for (info.fields) |f, i| { | 573 | inline for (info.fields, 0..) |f, i| { |
| 574 | if (i == 0) { | 574 | if (i == 0) { |
| 575 | try writer.writeAll(" "); | 575 | try writer.writeAll(" "); |
| 576 | } else { | 576 | } else { |
| ... | @@ -585,7 +585,7 @@ pub fn formatType( | ... | @@ -585,7 +585,7 @@ pub fn formatType( |
| 585 | return writer.writeAll("{ ... }"); | 585 | return writer.writeAll("{ ... }"); |
| 586 | } | 586 | } |
| 587 | try writer.writeAll("{"); | 587 | try writer.writeAll("{"); |
| 588 | inline for (info.fields) |f, i| { | 588 | inline for (info.fields, 0..) |f, i| { |
| 589 | if (i == 0) { | 589 | if (i == 0) { |
| 590 | try writer.writeAll(" ."); | 590 | try writer.writeAll(" ."); |
| 591 | } else { | 591 | } else { |
| ... | @@ -612,7 +612,7 @@ pub fn formatType( | ... | @@ -612,7 +612,7 @@ pub fn formatType( |
| 612 | } | 612 | } |
| 613 | } | 613 | } |
| 614 | if (comptime std.meta.trait.isZigString(info.child)) { | 614 | if (comptime std.meta.trait.isZigString(info.child)) { |
| 615 | for (value) |item, i| { | 615 | for (value, 0..) |item, i| { |
| 616 | comptime checkTextFmt(actual_fmt); | 616 | comptime checkTextFmt(actual_fmt); |
| 617 | if (i != 0) try formatBuf(", ", options, writer); | 617 | if (i != 0) try formatBuf(", ", options, writer); |
| 618 | try formatBuf(item, options, writer); | 618 | try formatBuf(item, options, writer); |
| ... | @@ -659,7 +659,7 @@ pub fn formatType( | ... | @@ -659,7 +659,7 @@ pub fn formatType( |
| 659 | } | 659 | } |
| 660 | } | 660 | } |
| 661 | try writer.writeAll("{ "); | 661 | try writer.writeAll("{ "); |
| 662 | for (value) |elem, i| { | 662 | for (value, 0..) |elem, i| { |
| 663 | try formatType(elem, actual_fmt, options, writer, max_depth - 1); | 663 | try formatType(elem, actual_fmt, options, writer, max_depth - 1); |
| 664 | if (i != value.len - 1) { | 664 | if (i != value.len - 1) { |
| 665 | try writer.writeAll(", "); | 665 | try writer.writeAll(", "); |
| ... | @@ -684,7 +684,7 @@ pub fn formatType( | ... | @@ -684,7 +684,7 @@ pub fn formatType( |
| 684 | } | 684 | } |
| 685 | } | 685 | } |
| 686 | try writer.writeAll("{ "); | 686 | try writer.writeAll("{ "); |
| 687 | for (value) |elem, i| { | 687 | for (value, 0..) |elem, i| { |
| 688 | try formatType(elem, actual_fmt, options, writer, max_depth - 1); | 688 | try formatType(elem, actual_fmt, options, writer, max_depth - 1); |
| 689 | if (i < value.len - 1) { | 689 | if (i < value.len - 1) { |
| 690 | try writer.writeAll(", "); | 690 | try writer.writeAll(", "); |
lib/std/fmt/parse_float/decimal.zig+1-1| ... | @@ -475,7 +475,7 @@ pub fn Decimal(comptime T: type) type { | ... | @@ -475,7 +475,7 @@ pub fn Decimal(comptime T: type) type { |
| 475 | const x = pow2_to_pow5_table[shift]; | 475 | const x = pow2_to_pow5_table[shift]; |
| 476 | 476 | ||
| 477 | // Compare leading digits of current to check if lexicographically less than cutoff. | 477 | // Compare leading digits of current to check if lexicographically less than cutoff. |
| 478 | for (x.cutoff) |p5, i| { | 478 | for (x.cutoff, 0..) |p5, i| { |
| 479 | if (i >= self.num_digits) { | 479 | if (i >= self.num_digits) { |
| 480 | return x.delta - 1; | 480 | return x.delta - 1; |
| 481 | } else if (self.digits[i] == p5 - '0') { // digits are stored as integers | 481 | } else if (self.digits[i] == p5 - '0') { // digits are stored as integers |
lib/std/fs/path.zig+3-3| ... | @@ -48,7 +48,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn | ... | @@ -48,7 +48,7 @@ fn joinSepMaybeZ(allocator: Allocator, separator: u8, comptime sepPredicate: fn |
| 48 | 48 | ||
| 49 | // Find first non-empty path index. | 49 | // Find first non-empty path index. |
| 50 | const first_path_index = blk: { | 50 | const first_path_index = blk: { |
| 51 | for (paths) |path, index| { | 51 | for (paths, 0..) |path, index| { |
| 52 | if (path.len == 0) continue else break :blk index; | 52 | if (path.len == 0) continue else break :blk index; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| ... | @@ -476,7 +476,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 { | ... | @@ -476,7 +476,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 { |
| 476 | var drive_kind = WindowsPath.Kind.None; | 476 | var drive_kind = WindowsPath.Kind.None; |
| 477 | var have_abs_path = false; | 477 | var have_abs_path = false; |
| 478 | var first_index: usize = 0; | 478 | var first_index: usize = 0; |
| 479 | for (paths) |p, i| { | 479 | for (paths, 0..) |p, i| { |
| 480 | const parsed = windowsParsePath(p); | 480 | const parsed = windowsParsePath(p); |
| 481 | if (parsed.is_abs) { | 481 | if (parsed.is_abs) { |
| 482 | have_abs_path = true; | 482 | have_abs_path = true; |
| ... | @@ -504,7 +504,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 { | ... | @@ -504,7 +504,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 { |
| 504 | first_index = 0; | 504 | first_index = 0; |
| 505 | var correct_disk_designator = false; | 505 | var correct_disk_designator = false; |
| 506 | 506 | ||
| 507 | for (paths) |p, i| { | 507 | for (paths, 0..) |p, i| { |
| 508 | const parsed = windowsParsePath(p); | 508 | const parsed = windowsParsePath(p); |
| 509 | if (parsed.kind != WindowsPath.Kind.None) { | 509 | if (parsed.kind != WindowsPath.Kind.None) { |
| 510 | if (parsed.kind == drive_kind) { | 510 | if (parsed.kind == drive_kind) { |
lib/std/fs/wasi.zig+1-1| ... | @@ -15,7 +15,7 @@ pub const Preopens = struct { | ... | @@ -15,7 +15,7 @@ pub const Preopens = struct { |
| 15 | names: []const []const u8, | 15 | names: []const []const u8, |
| 16 | 16 | ||
| 17 | pub fn find(p: Preopens, name: []const u8) ?os.fd_t { | 17 | pub fn find(p: Preopens, name: []const u8) ?os.fd_t { |
| 18 | for (p.names) |elem_name, i| { | 18 | for (p.names, 0..) |elem_name, i| { |
| 19 | if (mem.eql(u8, elem_name, name)) { | 19 | if (mem.eql(u8, elem_name, name)) { |
| 20 | return @intCast(os.fd_t, i); | 20 | return @intCast(os.fd_t, i); |
| 21 | } | 21 | } |
lib/std/hash/crc.zig+3-3| ... | @@ -35,7 +35,7 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type { | ... | @@ -35,7 +35,7 @@ pub fn Crc(comptime W: type, comptime algorithm: Algorithm(W)) type { |
| 35 | @as(I, algorithm.polynomial) << (@bitSizeOf(I) - @bitSizeOf(W)); | 35 | @as(I, algorithm.polynomial) << (@bitSizeOf(I) - @bitSizeOf(W)); |
| 36 | 36 | ||
| 37 | var table: [256]I = undefined; | 37 | var table: [256]I = undefined; |
| 38 | for (table) |*e, i| { | 38 | for (&table, 0..) |*e, i| { |
| 39 | var crc: I = i; | 39 | var crc: I = i; |
| 40 | if (algorithm.reflect_input) { | 40 | if (algorithm.reflect_input) { |
| 41 | var j: usize = 0; | 41 | var j: usize = 0; |
| ... | @@ -124,7 +124,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type { | ... | @@ -124,7 +124,7 @@ pub fn Crc32WithPoly(comptime poly: Polynomial) type { |
| 124 | @setEvalBranchQuota(20000); | 124 | @setEvalBranchQuota(20000); |
| 125 | var tables: [8][256]u32 = undefined; | 125 | var tables: [8][256]u32 = undefined; |
| 126 | 126 | ||
| 127 | for (tables[0]) |*e, i| { | 127 | for (&tables[0], 0..) |*e, i| { |
| 128 | var crc = @intCast(u32, i); | 128 | var crc = @intCast(u32, i); |
| 129 | var j: usize = 0; | 129 | var j: usize = 0; |
| 130 | while (j < 8) : (j += 1) { | 130 | while (j < 8) : (j += 1) { |
| ... | @@ -217,7 +217,7 @@ pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type { | ... | @@ -217,7 +217,7 @@ pub fn Crc32SmallWithPoly(comptime poly: Polynomial) type { |
| 217 | const lookup_table = block: { | 217 | const lookup_table = block: { |
| 218 | var table: [16]u32 = undefined; | 218 | var table: [16]u32 = undefined; |
| 219 | 219 | ||
| 220 | for (table) |*e, i| { | 220 | for (&table, 0..) |*e, i| { |
| 221 | var crc = @intCast(u32, i * 16); | 221 | var crc = @intCast(u32, i * 16); |
| 222 | var j: usize = 0; | 222 | var j: usize = 0; |
| 223 | while (j < 8) : (j += 1) { | 223 | while (j < 8) : (j += 1) { |
lib/std/hash/wyhash.zig+1-1| ... | @@ -207,7 +207,7 @@ test "test vectors streaming" { | ... | @@ -207,7 +207,7 @@ test "test vectors streaming" { |
| 207 | 207 | ||
| 208 | test "iterative non-divisible update" { | 208 | test "iterative non-divisible update" { |
| 209 | var buf: [8192]u8 = undefined; | 209 | var buf: [8192]u8 = undefined; |
| 210 | for (buf) |*e, i| { | 210 | for (&buf, 0..) |*e, i| { |
| 211 | e.* = @truncate(u8, i); | 211 | e.* = @truncate(u8, i); |
| 212 | } | 212 | } |
| 213 | 213 |
lib/std/hash_map.zig+2-2| ... | @@ -2119,7 +2119,7 @@ test "std.hash_map getOrPutAdapted" { | ... | @@ -2119,7 +2119,7 @@ test "std.hash_map getOrPutAdapted" { |
| 2119 | 2119 | ||
| 2120 | var real_keys: [keys.len]u64 = undefined; | 2120 | var real_keys: [keys.len]u64 = undefined; |
| 2121 | 2121 | ||
| 2122 | inline for (keys) |key_str, i| { | 2122 | inline for (keys, 0..) |key_str, i| { |
| 2123 | const result = try map.getOrPutAdapted(key_str, AdaptedContext{}); | 2123 | const result = try map.getOrPutAdapted(key_str, AdaptedContext{}); |
| 2124 | try testing.expect(!result.found_existing); | 2124 | try testing.expect(!result.found_existing); |
| 2125 | real_keys[i] = std.fmt.parseInt(u64, key_str, 10) catch unreachable; | 2125 | real_keys[i] = std.fmt.parseInt(u64, key_str, 10) catch unreachable; |
| ... | @@ -2129,7 +2129,7 @@ test "std.hash_map getOrPutAdapted" { | ... | @@ -2129,7 +2129,7 @@ test "std.hash_map getOrPutAdapted" { |
| 2129 | 2129 | ||
| 2130 | try testing.expectEqual(map.count(), keys.len); | 2130 | try testing.expectEqual(map.count(), keys.len); |
| 2131 | 2131 | ||
| 2132 | inline for (keys) |key_str, i| { | 2132 | inline for (keys, 0..) |key_str, i| { |
| 2133 | const result = try map.getOrPutAdapted(key_str, AdaptedContext{}); | 2133 | const result = try map.getOrPutAdapted(key_str, AdaptedContext{}); |
| 2134 | try testing.expect(result.found_existing); | 2134 | try testing.expect(result.found_existing); |
| 2135 | try testing.expectEqual(real_keys[i], result.key_ptr.*); | 2135 | try testing.expectEqual(real_keys[i], result.key_ptr.*); |
lib/std/heap.zig+2-2| ... | @@ -724,7 +724,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void { | ... | @@ -724,7 +724,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void { |
| 724 | 724 | ||
| 725 | var slice = try allocator.alloc(*i32, 100); | 725 | var slice = try allocator.alloc(*i32, 100); |
| 726 | try testing.expect(slice.len == 100); | 726 | try testing.expect(slice.len == 100); |
| 727 | for (slice) |*item, i| { | 727 | for (slice, 0..) |*item, i| { |
| 728 | item.* = try allocator.create(i32); | 728 | item.* = try allocator.create(i32); |
| 729 | item.*.* = @intCast(i32, i); | 729 | item.*.* = @intCast(i32, i); |
| 730 | } | 730 | } |
| ... | @@ -732,7 +732,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void { | ... | @@ -732,7 +732,7 @@ pub fn testAllocator(base_allocator: mem.Allocator) !void { |
| 732 | slice = try allocator.realloc(slice, 20000); | 732 | slice = try allocator.realloc(slice, 20000); |
| 733 | try testing.expect(slice.len == 20000); | 733 | try testing.expect(slice.len == 20000); |
| 734 | 734 | ||
| 735 | for (slice[0..100]) |item, i| { | 735 | for (slice[0..100], 0..) |item, i| { |
| 736 | try testing.expect(item.* == @intCast(i32, i)); | 736 | try testing.expect(item.* == @intCast(i32, i)); |
| 737 | allocator.destroy(item); | 737 | allocator.destroy(item); |
| 738 | } | 738 | } |
lib/std/heap/WasmPageAllocator.zig+1-1| ... | @@ -62,7 +62,7 @@ const FreeBlock = struct { | ... | @@ -62,7 +62,7 @@ const FreeBlock = struct { |
| 62 | 62 | ||
| 63 | fn useRecycled(self: FreeBlock, num_pages: usize, log2_align: u8) usize { | 63 | fn useRecycled(self: FreeBlock, num_pages: usize, log2_align: u8) usize { |
| 64 | @setCold(true); | 64 | @setCold(true); |
| 65 | for (self.data) |segment, i| { | 65 | for (self.data, 0..) |segment, i| { |
| 66 | const spills_into_next = @bitCast(i128, segment) < 0; | 66 | const spills_into_next = @bitCast(i128, segment) < 0; |
| 67 | const has_enough_bits = @popCount(segment) >= num_pages; | 67 | const has_enough_bits = @popCount(segment) >= num_pages; |
| 68 | 68 |
lib/std/heap/general_purpose_allocator.zig+1-1| ... | @@ -349,7 +349,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -349,7 +349,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 349 | /// Emits log messages for leaks and then returns whether there were any leaks. | 349 | /// Emits log messages for leaks and then returns whether there were any leaks. |
| 350 | pub fn detectLeaks(self: *Self) bool { | 350 | pub fn detectLeaks(self: *Self) bool { |
| 351 | var leaks = false; | 351 | var leaks = false; |
| 352 | for (self.buckets) |optional_bucket, bucket_i| { | 352 | for (self.buckets, 0..) |optional_bucket, bucket_i| { |
| 353 | const first_bucket = optional_bucket orelse continue; | 353 | const first_bucket = optional_bucket orelse continue; |
| 354 | const size_class = @as(usize, 1) << @intCast(math.Log2Int(usize), bucket_i); | 354 | const size_class = @as(usize, 1) << @intCast(math.Log2Int(usize), bucket_i); |
| 355 | const used_bits_count = usedBitsCount(size_class); | 355 | const used_bits_count = usedBitsCount(size_class); |
lib/std/json.zig+6-6| ... | @@ -1280,7 +1280,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool { | ... | @@ -1280,7 +1280,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool { |
| 1280 | } | 1280 | } |
| 1281 | }, | 1281 | }, |
| 1282 | .Array => { | 1282 | .Array => { |
| 1283 | for (a) |e, i| | 1283 | for (a, 0..) |e, i| |
| 1284 | if (!parsedEqual(e, b[i])) return false; | 1284 | if (!parsedEqual(e, b[i])) return false; |
| 1285 | return true; | 1285 | return true; |
| 1286 | }, | 1286 | }, |
| ... | @@ -1294,7 +1294,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool { | ... | @@ -1294,7 +1294,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool { |
| 1294 | .One => return parsedEqual(a.*, b.*), | 1294 | .One => return parsedEqual(a.*, b.*), |
| 1295 | .Slice => { | 1295 | .Slice => { |
| 1296 | if (a.len != b.len) return false; | 1296 | if (a.len != b.len) return false; |
| 1297 | for (a) |e, i| | 1297 | for (a, 0..) |e, i| |
| 1298 | if (!parsedEqual(e, b[i])) return false; | 1298 | if (!parsedEqual(e, b[i])) return false; |
| 1299 | return true; | 1299 | return true; |
| 1300 | }, | 1300 | }, |
| ... | @@ -1518,7 +1518,7 @@ fn parseInternal( | ... | @@ -1518,7 +1518,7 @@ fn parseInternal( |
| 1518 | var r: T = undefined; | 1518 | var r: T = undefined; |
| 1519 | var fields_seen = [_]bool{false} ** structInfo.fields.len; | 1519 | var fields_seen = [_]bool{false} ** structInfo.fields.len; |
| 1520 | errdefer { | 1520 | errdefer { |
| 1521 | inline for (structInfo.fields) |field, i| { | 1521 | inline for (structInfo.fields, 0..) |field, i| { |
| 1522 | if (fields_seen[i] and !field.is_comptime) { | 1522 | if (fields_seen[i] and !field.is_comptime) { |
| 1523 | parseFree(field.type, @field(r, field.name), options); | 1523 | parseFree(field.type, @field(r, field.name), options); |
| 1524 | } | 1524 | } |
| ... | @@ -1533,7 +1533,7 @@ fn parseInternal( | ... | @@ -1533,7 +1533,7 @@ fn parseInternal( |
| 1533 | var child_options = options; | 1533 | var child_options = options; |
| 1534 | child_options.allow_trailing_data = true; | 1534 | child_options.allow_trailing_data = true; |
| 1535 | var found = false; | 1535 | var found = false; |
| 1536 | inline for (structInfo.fields) |field, i| { | 1536 | inline for (structInfo.fields, 0..) |field, i| { |
| 1537 | // TODO: using switches here segfault the compiler (#2727?) | 1537 | // TODO: using switches here segfault the compiler (#2727?) |
| 1538 | if ((stringToken.escapes == .None and mem.eql(u8, field.name, key_source_slice)) or (stringToken.escapes == .Some and (field.name.len == stringToken.decodedLength() and encodesTo(field.name, key_source_slice)))) { | 1538 | if ((stringToken.escapes == .None and mem.eql(u8, field.name, key_source_slice)) or (stringToken.escapes == .Some and (field.name.len == stringToken.decodedLength() and encodesTo(field.name, key_source_slice)))) { |
| 1539 | // if (switch (stringToken.escapes) { | 1539 | // if (switch (stringToken.escapes) { |
| ... | @@ -1584,7 +1584,7 @@ fn parseInternal( | ... | @@ -1584,7 +1584,7 @@ fn parseInternal( |
| 1584 | else => return error.UnexpectedToken, | 1584 | else => return error.UnexpectedToken, |
| 1585 | } | 1585 | } |
| 1586 | } | 1586 | } |
| 1587 | inline for (structInfo.fields) |field, i| { | 1587 | inline for (structInfo.fields, 0..) |field, i| { |
| 1588 | if (!fields_seen[i]) { | 1588 | if (!fields_seen[i]) { |
| 1589 | if (field.default_value) |default_ptr| { | 1589 | if (field.default_value) |default_ptr| { |
| 1590 | if (!field.is_comptime) { | 1590 | if (!field.is_comptime) { |
| ... | @@ -2367,7 +2367,7 @@ pub fn stringify( | ... | @@ -2367,7 +2367,7 @@ pub fn stringify( |
| 2367 | if (child_options.whitespace) |*whitespace| { | 2367 | if (child_options.whitespace) |*whitespace| { |
| 2368 | whitespace.indent_level += 1; | 2368 | whitespace.indent_level += 1; |
| 2369 | } | 2369 | } |
| 2370 | for (value) |x, i| { | 2370 | for (value, 0..) |x, i| { |
| 2371 | if (i != 0) { | 2371 | if (i != 0) { |
| 2372 | try out_stream.writeByte(','); | 2372 | try out_stream.writeByte(','); |
| 2373 | } | 2373 | } |
lib/std/json/test.zig+1-1| ... | @@ -2717,7 +2717,7 @@ test "string copy option" { | ... | @@ -2717,7 +2717,7 @@ test "string copy option" { |
| 2717 | const copy_addr = &obj_copy.get("noescape").?.String[0]; | 2717 | const copy_addr = &obj_copy.get("noescape").?.String[0]; |
| 2718 | 2718 | ||
| 2719 | var found_nocopy = false; | 2719 | var found_nocopy = false; |
| 2720 | for (input) |_, index| { | 2720 | for (input, 0..) |_, index| { |
| 2721 | try testing.expect(copy_addr != &input[index]); | 2721 | try testing.expect(copy_addr != &input[index]); |
| 2722 | if (nocopy_addr == &input[index]) { | 2722 | if (nocopy_addr == &input[index]) { |
| 2723 | found_nocopy = true; | 2723 | found_nocopy = true; |
lib/std/math/big/int.zig+7-7| ... | @@ -1478,11 +1478,11 @@ pub const Mutable = struct { | ... | @@ -1478,11 +1478,11 @@ pub const Mutable = struct { |
| 1478 | // const x_trailing = std.mem.indexOfScalar(Limb, x.limbs[0..x.len], 0).?; | 1478 | // const x_trailing = std.mem.indexOfScalar(Limb, x.limbs[0..x.len], 0).?; |
| 1479 | // const y_trailing = std.mem.indexOfScalar(Limb, y.limbs[0..y.len], 0).?; | 1479 | // const y_trailing = std.mem.indexOfScalar(Limb, y.limbs[0..y.len], 0).?; |
| 1480 | 1480 | ||
| 1481 | const x_trailing = for (x.limbs[0..x.len]) |xi, i| { | 1481 | const x_trailing = for (x.limbs[0..x.len], 0..) |xi, i| { |
| 1482 | if (xi != 0) break i; | 1482 | if (xi != 0) break i; |
| 1483 | } else unreachable; | 1483 | } else unreachable; |
| 1484 | 1484 | ||
| 1485 | const y_trailing = for (y.limbs[0..y.len]) |yi, i| { | 1485 | const y_trailing = for (y.limbs[0..y.len], 0..) |yi, i| { |
| 1486 | if (yi != 0) break i; | 1486 | if (yi != 0) break i; |
| 1487 | } else unreachable; | 1487 | } else unreachable; |
| 1488 | 1488 | ||
| ... | @@ -2108,7 +2108,7 @@ pub const Const = struct { | ... | @@ -2108,7 +2108,7 @@ pub const Const = struct { |
| 2108 | if (@sizeOf(UT) <= @sizeOf(Limb)) { | 2108 | if (@sizeOf(UT) <= @sizeOf(Limb)) { |
| 2109 | r = @intCast(UT, self.limbs[0]); | 2109 | r = @intCast(UT, self.limbs[0]); |
| 2110 | } else { | 2110 | } else { |
| 2111 | for (self.limbs[0..self.limbs.len]) |_, ri| { | 2111 | for (self.limbs[0..self.limbs.len], 0..) |_, ri| { |
| 2112 | const limb = self.limbs[self.limbs.len - ri - 1]; | 2112 | const limb = self.limbs[self.limbs.len - ri - 1]; |
| 2113 | r <<= limb_bits; | 2113 | r <<= limb_bits; |
| 2114 | r |= limb; | 2114 | r |= limb; |
| ... | @@ -3594,7 +3594,7 @@ fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void { | ... | @@ -3594,7 +3594,7 @@ fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void { |
| 3594 | assert(quo.len >= a.len); | 3594 | assert(quo.len >= a.len); |
| 3595 | 3595 | ||
| 3596 | rem.* = 0; | 3596 | rem.* = 0; |
| 3597 | for (a) |_, ri| { | 3597 | for (a, 0..) |_, ri| { |
| 3598 | const i = a.len - ri - 1; | 3598 | const i = a.len - ri - 1; |
| 3599 | const pdiv = ((@as(DoubleLimb, rem.*) << limb_bits) | a[i]); | 3599 | const pdiv = ((@as(DoubleLimb, rem.*) << limb_bits) | a[i]); |
| 3600 | 3600 | ||
| ... | @@ -3620,7 +3620,7 @@ fn lldiv0p5(quo: []Limb, rem: *Limb, a: []const Limb, b: HalfLimb) void { | ... | @@ -3620,7 +3620,7 @@ fn lldiv0p5(quo: []Limb, rem: *Limb, a: []const Limb, b: HalfLimb) void { |
| 3620 | assert(quo.len >= a.len); | 3620 | assert(quo.len >= a.len); |
| 3621 | 3621 | ||
| 3622 | rem.* = 0; | 3622 | rem.* = 0; |
| 3623 | for (a) |_, ri| { | 3623 | for (a, 0..) |_, ri| { |
| 3624 | const i = a.len - ri - 1; | 3624 | const i = a.len - ri - 1; |
| 3625 | const ai_high = a[i] >> half_limb_bits; | 3625 | const ai_high = a[i] >> half_limb_bits; |
| 3626 | const ai_low = a[i] & ((1 << half_limb_bits) - 1); | 3626 | const ai_low = a[i] & ((1 << half_limb_bits) - 1); |
| ... | @@ -4028,7 +4028,7 @@ fn llsquareBasecase(r: []Limb, x: []const Limb) void { | ... | @@ -4028,7 +4028,7 @@ fn llsquareBasecase(r: []Limb, x: []const Limb) void { |
| 4028 | // - Each mixed-product term appears twice for each column, | 4028 | // - Each mixed-product term appears twice for each column, |
| 4029 | // - Squares are always in the 2k (0 <= k < N) column | 4029 | // - Squares are always in the 2k (0 <= k < N) column |
| 4030 | 4030 | ||
| 4031 | for (x_norm) |v, i| { | 4031 | for (x_norm, 0..) |v, i| { |
| 4032 | // Accumulate all the x[i]*x[j] (with x!=j) products | 4032 | // Accumulate all the x[i]*x[j] (with x!=j) products |
| 4033 | const overflow = llmulLimb(.add, r[2 * i + 1 ..], x_norm[i + 1 ..], v); | 4033 | const overflow = llmulLimb(.add, r[2 * i + 1 ..], x_norm[i + 1 ..], v); |
| 4034 | assert(!overflow); | 4034 | assert(!overflow); |
| ... | @@ -4037,7 +4037,7 @@ fn llsquareBasecase(r: []Limb, x: []const Limb) void { | ... | @@ -4037,7 +4037,7 @@ fn llsquareBasecase(r: []Limb, x: []const Limb) void { |
| 4037 | // Each product appears twice, multiply by 2 | 4037 | // Each product appears twice, multiply by 2 |
| 4038 | llshl(r, r[0 .. 2 * x_norm.len], 1); | 4038 | llshl(r, r[0 .. 2 * x_norm.len], 1); |
| 4039 | 4039 | ||
| 4040 | for (x_norm) |v, i| { | 4040 | for (x_norm, 0..) |v, i| { |
| 4041 | // Compute and add the squares | 4041 | // Compute and add the squares |
| 4042 | const overflow = llmulLimb(.add, r[2 * i ..], x[i .. i + 1], v); | 4042 | const overflow = llmulLimb(.add, r[2 * i ..], x[i .. i + 1], v); |
| 4043 | assert(!overflow); | 4043 | assert(!overflow); |
lib/std/math/big/rational.zig+1-1| ... | @@ -70,7 +70,7 @@ pub const Rational = struct { | ... | @@ -70,7 +70,7 @@ pub const Rational = struct { |
| 70 | start += 1; | 70 | start += 1; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | for (str) |c, i| { | 73 | for (str, 0..) |c, i| { |
| 74 | switch (state) { | 74 | switch (state) { |
| 75 | State.Integer => { | 75 | State.Integer => { |
| 76 | switch (c) { | 76 | switch (c) { |
lib/std/mem.zig+12-12| ... | @@ -169,7 +169,7 @@ test "Allocator.resize" { | ... | @@ -169,7 +169,7 @@ test "Allocator.resize" { |
| 169 | var values = try testing.allocator.alloc(T, 100); | 169 | var values = try testing.allocator.alloc(T, 100); |
| 170 | defer testing.allocator.free(values); | 170 | defer testing.allocator.free(values); |
| 171 | 171 | ||
| 172 | for (values) |*v, i| v.* = @intCast(T, i); | 172 | for (values, 0..) |*v, i| v.* = @intCast(T, i); |
| 173 | if (!testing.allocator.resize(values, values.len + 10)) return error.OutOfMemory; | 173 | if (!testing.allocator.resize(values, values.len + 10)) return error.OutOfMemory; |
| 174 | values = values.ptr[0 .. values.len + 10]; | 174 | values = values.ptr[0 .. values.len + 10]; |
| 175 | try testing.expect(values.len == 110); | 175 | try testing.expect(values.len == 110); |
| ... | @@ -185,7 +185,7 @@ test "Allocator.resize" { | ... | @@ -185,7 +185,7 @@ test "Allocator.resize" { |
| 185 | var values = try testing.allocator.alloc(T, 100); | 185 | var values = try testing.allocator.alloc(T, 100); |
| 186 | defer testing.allocator.free(values); | 186 | defer testing.allocator.free(values); |
| 187 | 187 | ||
| 188 | for (values) |*v, i| v.* = @intToFloat(T, i); | 188 | for (values, 0..) |*v, i| v.* = @intToFloat(T, i); |
| 189 | if (!testing.allocator.resize(values, values.len + 10)) return error.OutOfMemory; | 189 | if (!testing.allocator.resize(values, values.len + 10)) return error.OutOfMemory; |
| 190 | values = values.ptr[0 .. values.len + 10]; | 190 | values = values.ptr[0 .. values.len + 10]; |
| 191 | try testing.expect(values.len == 110); | 191 | try testing.expect(values.len == 110); |
| ... | @@ -201,7 +201,7 @@ pub fn copy(comptime T: type, dest: []T, source: []const T) void { | ... | @@ -201,7 +201,7 @@ pub fn copy(comptime T: type, dest: []T, source: []const T) void { |
| 201 | // this and automatically omit safety checks for loops | 201 | // this and automatically omit safety checks for loops |
| 202 | @setRuntimeSafety(false); | 202 | @setRuntimeSafety(false); |
| 203 | assert(dest.len >= source.len); | 203 | assert(dest.len >= source.len); |
| 204 | for (source) |s, i| | 204 | for (source, 0..) |s, i| |
| 205 | dest[i] = s; | 205 | dest[i] = s; |
| 206 | } | 206 | } |
| 207 | 207 | ||
| ... | @@ -445,7 +445,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T { | ... | @@ -445,7 +445,7 @@ pub fn zeroInit(comptime T: type, init: anytype) T { |
| 445 | 445 | ||
| 446 | var value: T = undefined; | 446 | var value: T = undefined; |
| 447 | 447 | ||
| 448 | inline for (struct_info.fields) |field, i| { | 448 | inline for (struct_info.fields, 0..) |field, i| { |
| 449 | if (field.is_comptime) { | 449 | if (field.is_comptime) { |
| 450 | continue; | 450 | continue; |
| 451 | } | 451 | } |
| ... | @@ -611,7 +611,7 @@ test "lessThan" { | ... | @@ -611,7 +611,7 @@ test "lessThan" { |
| 611 | pub fn eql(comptime T: type, a: []const T, b: []const T) bool { | 611 | pub fn eql(comptime T: type, a: []const T, b: []const T) bool { |
| 612 | if (a.len != b.len) return false; | 612 | if (a.len != b.len) return false; |
| 613 | if (a.ptr == b.ptr) return true; | 613 | if (a.ptr == b.ptr) return true; |
| 614 | for (a) |item, index| { | 614 | for (a, 0..) |item, index| { |
| 615 | if (b[index] != item) return false; | 615 | if (b[index] != item) return false; |
| 616 | } | 616 | } |
| 617 | return true; | 617 | return true; |
| ... | @@ -1261,7 +1261,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) | ... | @@ -1261,7 +1261,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) |
| 1261 | }, | 1261 | }, |
| 1262 | .Little => { | 1262 | .Little => { |
| 1263 | const ShiftType = math.Log2Int(ReturnType); | 1263 | const ShiftType = math.Log2Int(ReturnType); |
| 1264 | for (bytes) |b, index| { | 1264 | for (bytes, 0..) |b, index| { |
| 1265 | result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8)); | 1265 | result = result | (@as(ReturnType, b) << @intCast(ShiftType, index * 8)); |
| 1266 | } | 1266 | } |
| 1267 | }, | 1267 | }, |
| ... | @@ -1328,7 +1328,7 @@ pub fn readVarPackedInt( | ... | @@ -1328,7 +1328,7 @@ pub fn readVarPackedInt( |
| 1328 | }, | 1328 | }, |
| 1329 | .Little => { | 1329 | .Little => { |
| 1330 | int = read_bytes[0] >> bit_shift; | 1330 | int = read_bytes[0] >> bit_shift; |
| 1331 | for (read_bytes[1..]) |elem, i| { | 1331 | for (read_bytes[1..], 0..) |elem, i| { |
| 1332 | int |= (@as(uN, elem) << @intCast(Log2N, (8 * (i + 1) - bit_shift))); | 1332 | int |= (@as(uN, elem) << @intCast(Log2N, (8 * (i + 1) - bit_shift))); |
| 1333 | } | 1333 | } |
| 1334 | }, | 1334 | }, |
| ... | @@ -2907,7 +2907,7 @@ pub fn indexOfMin(comptime T: type, slice: []const T) usize { | ... | @@ -2907,7 +2907,7 @@ pub fn indexOfMin(comptime T: type, slice: []const T) usize { |
| 2907 | assert(slice.len > 0); | 2907 | assert(slice.len > 0); |
| 2908 | var best = slice[0]; | 2908 | var best = slice[0]; |
| 2909 | var index: usize = 0; | 2909 | var index: usize = 0; |
| 2910 | for (slice[1..]) |item, i| { | 2910 | for (slice[1..], 0..) |item, i| { |
| 2911 | if (item < best) { | 2911 | if (item < best) { |
| 2912 | best = item; | 2912 | best = item; |
| 2913 | index = i + 1; | 2913 | index = i + 1; |
| ... | @@ -2928,7 +2928,7 @@ pub fn indexOfMax(comptime T: type, slice: []const T) usize { | ... | @@ -2928,7 +2928,7 @@ pub fn indexOfMax(comptime T: type, slice: []const T) usize { |
| 2928 | assert(slice.len > 0); | 2928 | assert(slice.len > 0); |
| 2929 | var best = slice[0]; | 2929 | var best = slice[0]; |
| 2930 | var index: usize = 0; | 2930 | var index: usize = 0; |
| 2931 | for (slice[1..]) |item, i| { | 2931 | for (slice[1..], 0..) |item, i| { |
| 2932 | if (item > best) { | 2932 | if (item > best) { |
| 2933 | best = item; | 2933 | best = item; |
| 2934 | index = i + 1; | 2934 | index = i + 1; |
| ... | @@ -2952,7 +2952,7 @@ pub fn indexOfMinMax(comptime T: type, slice: []const T) struct { index_min: usi | ... | @@ -2952,7 +2952,7 @@ pub fn indexOfMinMax(comptime T: type, slice: []const T) struct { index_min: usi |
| 2952 | var maxVal = slice[0]; | 2952 | var maxVal = slice[0]; |
| 2953 | var minIdx: usize = 0; | 2953 | var minIdx: usize = 0; |
| 2954 | var maxIdx: usize = 0; | 2954 | var maxIdx: usize = 0; |
| 2955 | for (slice[1..]) |item, i| { | 2955 | for (slice[1..], 0..) |item, i| { |
| 2956 | if (item < minVal) { | 2956 | if (item < minVal) { |
| 2957 | minVal = item; | 2957 | minVal = item; |
| 2958 | minIdx = i + 1; | 2958 | minIdx = i + 1; |
| ... | @@ -3117,7 +3117,7 @@ test "replace" { | ... | @@ -3117,7 +3117,7 @@ test "replace" { |
| 3117 | 3117 | ||
| 3118 | /// Replace all occurences of `needle` with `replacement`. | 3118 | /// Replace all occurences of `needle` with `replacement`. |
| 3119 | pub fn replaceScalar(comptime T: type, slice: []T, needle: T, replacement: T) void { | 3119 | pub fn replaceScalar(comptime T: type, slice: []T, needle: T, replacement: T) void { |
| 3120 | for (slice) |e, i| { | 3120 | for (slice, 0..) |e, i| { |
| 3121 | if (e == needle) { | 3121 | if (e == needle) { |
| 3122 | slice[i] = replacement; | 3122 | slice[i] = replacement; |
| 3123 | } | 3123 | } |
| ... | @@ -3372,7 +3372,7 @@ test "asBytes" { | ... | @@ -3372,7 +3372,7 @@ test "asBytes" { |
| 3372 | try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); | 3372 | try testing.expect(eql(u8, asBytes(&deadbeef), deadbeef_bytes)); |
| 3373 | 3373 | ||
| 3374 | var codeface = @as(u32, 0xC0DEFACE); | 3374 | var codeface = @as(u32, 0xC0DEFACE); |
| 3375 | for (asBytes(&codeface).*) |*b| | 3375 | for (asBytes(&codeface)) |*b| |
| 3376 | b.* = 0; | 3376 | b.* = 0; |
| 3377 | try testing.expect(codeface == 0); | 3377 | try testing.expect(codeface == 0); |
| 3378 | 3378 |
lib/std/meta.zig+14-14| ... | @@ -117,7 +117,7 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T { | ... | @@ -117,7 +117,7 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T { |
| 117 | const kvs = comptime build_kvs: { | 117 | const kvs = comptime build_kvs: { |
| 118 | const EnumKV = struct { []const u8, T }; | 118 | const EnumKV = struct { []const u8, T }; |
| 119 | var kvs_array: [@typeInfo(T).Enum.fields.len]EnumKV = undefined; | 119 | var kvs_array: [@typeInfo(T).Enum.fields.len]EnumKV = undefined; |
| 120 | inline for (@typeInfo(T).Enum.fields) |enumField, i| { | 120 | inline for (@typeInfo(T).Enum.fields, 0..) |enumField, i| { |
| 121 | kvs_array[i] = .{ enumField.name, @field(T, enumField.name) }; | 121 | kvs_array[i] = .{ enumField.name, @field(T, enumField.name) }; |
| 122 | } | 122 | } |
| 123 | break :build_kvs kvs_array[0..]; | 123 | break :build_kvs kvs_array[0..]; |
| ... | @@ -552,7 +552,7 @@ pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 { | ... | @@ -552,7 +552,7 @@ pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 { |
| 552 | comptime { | 552 | comptime { |
| 553 | const fieldInfos = fields(T); | 553 | const fieldInfos = fields(T); |
| 554 | var names: [fieldInfos.len][]const u8 = undefined; | 554 | var names: [fieldInfos.len][]const u8 = undefined; |
| 555 | for (fieldInfos) |field, i| { | 555 | for (fieldInfos, 0..) |field, i| { |
| 556 | names[i] = field.name; | 556 | names[i] = field.name; |
| 557 | } | 557 | } |
| 558 | return &names; | 558 | return &names; |
| ... | @@ -593,7 +593,7 @@ pub fn tags(comptime T: type) *const [fields(T).len]T { | ... | @@ -593,7 +593,7 @@ pub fn tags(comptime T: type) *const [fields(T).len]T { |
| 593 | comptime { | 593 | comptime { |
| 594 | const fieldInfos = fields(T); | 594 | const fieldInfos = fields(T); |
| 595 | var res: [fieldInfos.len]T = undefined; | 595 | var res: [fieldInfos.len]T = undefined; |
| 596 | for (fieldInfos) |field, i| { | 596 | for (fieldInfos, 0..) |field, i| { |
| 597 | res[i] = @field(T, field.name); | 597 | res[i] = @field(T, field.name); |
| 598 | } | 598 | } |
| 599 | return &res; | 599 | return &res; |
| ... | @@ -631,7 +631,7 @@ pub fn FieldEnum(comptime T: type) type { | ... | @@ -631,7 +631,7 @@ pub fn FieldEnum(comptime T: type) type { |
| 631 | 631 | ||
| 632 | if (@typeInfo(T) == .Union) { | 632 | if (@typeInfo(T) == .Union) { |
| 633 | if (@typeInfo(T).Union.tag_type) |tag_type| { | 633 | if (@typeInfo(T).Union.tag_type) |tag_type| { |
| 634 | for (std.enums.values(tag_type)) |v, i| { | 634 | for (std.enums.values(tag_type), 0..) |v, i| { |
| 635 | if (@enumToInt(v) != i) break; // enum values not consecutive | 635 | if (@enumToInt(v) != i) break; // enum values not consecutive |
| 636 | if (!std.mem.eql(u8, @tagName(v), field_infos[i].name)) break; // fields out of order | 636 | if (!std.mem.eql(u8, @tagName(v), field_infos[i].name)) break; // fields out of order |
| 637 | } else { | 637 | } else { |
| ... | @@ -642,7 +642,7 @@ pub fn FieldEnum(comptime T: type) type { | ... | @@ -642,7 +642,7 @@ pub fn FieldEnum(comptime T: type) type { |
| 642 | 642 | ||
| 643 | var enumFields: [field_infos.len]std.builtin.Type.EnumField = undefined; | 643 | var enumFields: [field_infos.len]std.builtin.Type.EnumField = undefined; |
| 644 | var decls = [_]std.builtin.Type.Declaration{}; | 644 | var decls = [_]std.builtin.Type.Declaration{}; |
| 645 | inline for (field_infos) |field, i| { | 645 | inline for (field_infos, 0..) |field, i| { |
| 646 | enumFields[i] = .{ | 646 | enumFields[i] = .{ |
| 647 | .name = field.name, | 647 | .name = field.name, |
| 648 | .value = i, | 648 | .value = i, |
| ... | @@ -672,7 +672,7 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { | ... | @@ -672,7 +672,7 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { |
| 672 | const expected_fields = @typeInfo(expected).Enum.fields; | 672 | const expected_fields = @typeInfo(expected).Enum.fields; |
| 673 | const actual_fields = @typeInfo(actual).Enum.fields; | 673 | const actual_fields = @typeInfo(actual).Enum.fields; |
| 674 | if (expected_fields.len != actual_fields.len) return error.FailedTest; | 674 | if (expected_fields.len != actual_fields.len) return error.FailedTest; |
| 675 | for (expected_fields) |expected_field, i| { | 675 | for (expected_fields, 0..) |expected_field, i| { |
| 676 | const actual_field = actual_fields[i]; | 676 | const actual_field = actual_fields[i]; |
| 677 | try testing.expectEqual(expected_field.value, actual_field.value); | 677 | try testing.expectEqual(expected_field.value, actual_field.value); |
| 678 | try testing.expectEqualStrings(expected_field.name, actual_field.name); | 678 | try testing.expectEqualStrings(expected_field.name, actual_field.name); |
| ... | @@ -682,7 +682,7 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { | ... | @@ -682,7 +682,7 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { |
| 682 | const expected_decls = @typeInfo(expected).Enum.decls; | 682 | const expected_decls = @typeInfo(expected).Enum.decls; |
| 683 | const actual_decls = @typeInfo(actual).Enum.decls; | 683 | const actual_decls = @typeInfo(actual).Enum.decls; |
| 684 | if (expected_decls.len != actual_decls.len) return error.FailedTest; | 684 | if (expected_decls.len != actual_decls.len) return error.FailedTest; |
| 685 | for (expected_decls) |expected_decl, i| { | 685 | for (expected_decls, 0..) |expected_decl, i| { |
| 686 | const actual_decl = actual_decls[i]; | 686 | const actual_decl = actual_decls[i]; |
| 687 | try testing.expectEqual(expected_decl.is_pub, actual_decl.is_pub); | 687 | try testing.expectEqual(expected_decl.is_pub, actual_decl.is_pub); |
| 688 | try testing.expectEqualStrings(expected_decl.name, actual_decl.name); | 688 | try testing.expectEqualStrings(expected_decl.name, actual_decl.name); |
| ... | @@ -716,7 +716,7 @@ pub fn DeclEnum(comptime T: type) type { | ... | @@ -716,7 +716,7 @@ pub fn DeclEnum(comptime T: type) type { |
| 716 | const fieldInfos = std.meta.declarations(T); | 716 | const fieldInfos = std.meta.declarations(T); |
| 717 | var enumDecls: [fieldInfos.len]std.builtin.Type.EnumField = undefined; | 717 | var enumDecls: [fieldInfos.len]std.builtin.Type.EnumField = undefined; |
| 718 | var decls = [_]std.builtin.Type.Declaration{}; | 718 | var decls = [_]std.builtin.Type.Declaration{}; |
| 719 | inline for (fieldInfos) |field, i| { | 719 | inline for (fieldInfos, 0..) |field, i| { |
| 720 | enumDecls[i] = .{ .name = field.name, .value = i }; | 720 | enumDecls[i] = .{ .name = field.name, .value = i }; |
| 721 | } | 721 | } |
| 722 | return @Type(.{ | 722 | return @Type(.{ |
| ... | @@ -870,7 +870,7 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool { | ... | @@ -870,7 +870,7 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool { |
| 870 | }, | 870 | }, |
| 871 | .Array => { | 871 | .Array => { |
| 872 | if (a.len != b.len) return false; | 872 | if (a.len != b.len) return false; |
| 873 | for (a) |e, i| | 873 | for (a, 0..) |e, i| |
| 874 | if (!eql(e, b[i])) return false; | 874 | if (!eql(e, b[i])) return false; |
| 875 | return true; | 875 | return true; |
| 876 | }, | 876 | }, |
| ... | @@ -988,7 +988,7 @@ pub fn intToEnum(comptime EnumTag: type, tag_int: anytype) IntToEnumError!EnumTa | ... | @@ -988,7 +988,7 @@ pub fn intToEnum(comptime EnumTag: type, tag_int: anytype) IntToEnumError!EnumTa |
| 988 | /// Given a type and a name, return the field index according to source order. | 988 | /// Given a type and a name, return the field index according to source order. |
| 989 | /// Returns `null` if the field is not found. | 989 | /// Returns `null` if the field is not found. |
| 990 | pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int { | 990 | pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int { |
| 991 | inline for (fields(T)) |field, i| { | 991 | inline for (fields(T), 0..) |field, i| { |
| 992 | if (mem.eql(u8, field.name, name)) | 992 | if (mem.eql(u8, field.name, name)) |
| 993 | return i; | 993 | return i; |
| 994 | } | 994 | } |
| ... | @@ -1008,7 +1008,7 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De | ... | @@ -1008,7 +1008,7 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De |
| 1008 | comptime { | 1008 | comptime { |
| 1009 | const decls = declarations(Namespace); | 1009 | const decls = declarations(Namespace); |
| 1010 | var array: [decls.len]*const Decl = undefined; | 1010 | var array: [decls.len]*const Decl = undefined; |
| 1011 | for (decls) |decl, i| { | 1011 | for (decls, 0..) |decl, i| { |
| 1012 | array[i] = &@field(Namespace, decl.name); | 1012 | array[i] = &@field(Namespace, decl.name); |
| 1013 | } | 1013 | } |
| 1014 | std.sort.sort(*const Decl, &array, {}, S.declNameLessThan); | 1014 | std.sort.sort(*const Decl, &array, {}, S.declNameLessThan); |
| ... | @@ -1069,7 +1069,7 @@ pub fn ArgsTuple(comptime Function: type) type { | ... | @@ -1069,7 +1069,7 @@ pub fn ArgsTuple(comptime Function: type) type { |
| 1069 | @compileError("Cannot create ArgsTuple for variadic function"); | 1069 | @compileError("Cannot create ArgsTuple for variadic function"); |
| 1070 | 1070 | ||
| 1071 | var argument_field_list: [function_info.params.len]type = undefined; | 1071 | var argument_field_list: [function_info.params.len]type = undefined; |
| 1072 | inline for (function_info.params) |arg, i| { | 1072 | inline for (function_info.params, 0..) |arg, i| { |
| 1073 | const T = arg.type.?; | 1073 | const T = arg.type.?; |
| 1074 | argument_field_list[i] = T; | 1074 | argument_field_list[i] = T; |
| 1075 | } | 1075 | } |
| ... | @@ -1090,7 +1090,7 @@ pub fn Tuple(comptime types: []const type) type { | ... | @@ -1090,7 +1090,7 @@ pub fn Tuple(comptime types: []const type) type { |
| 1090 | 1090 | ||
| 1091 | fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type { | 1091 | fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type { |
| 1092 | var tuple_fields: [types.len]std.builtin.Type.StructField = undefined; | 1092 | var tuple_fields: [types.len]std.builtin.Type.StructField = undefined; |
| 1093 | inline for (types) |T, i| { | 1093 | inline for (types, 0..) |T, i| { |
| 1094 | @setEvalBranchQuota(10_000); | 1094 | @setEvalBranchQuota(10_000); |
| 1095 | var num_buf: [128]u8 = undefined; | 1095 | var num_buf: [128]u8 = undefined; |
| 1096 | tuple_fields[i] = .{ | 1096 | tuple_fields[i] = .{ |
| ... | @@ -1129,7 +1129,7 @@ const TupleTester = struct { | ... | @@ -1129,7 +1129,7 @@ const TupleTester = struct { |
| 1129 | if (expected.len != fields_list.len) | 1129 | if (expected.len != fields_list.len) |
| 1130 | @compileError("Argument count mismatch"); | 1130 | @compileError("Argument count mismatch"); |
| 1131 | 1131 | ||
| 1132 | inline for (fields_list) |fld, i| { | 1132 | inline for (fields_list, 0..) |fld, i| { |
| 1133 | if (expected[i] != fld.type) { | 1133 | if (expected[i] != fld.type) { |
| 1134 | @compileError("Field " ++ fld.name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld.type)); | 1134 | @compileError("Field " ++ fld.name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld.type)); |
| 1135 | } | 1135 | } |
lib/std/meta/trailer_flags.zig+5-5| ... | @@ -21,7 +21,7 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -21,7 +21,7 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 21 | pub const ActiveFields = std.enums.EnumFieldStruct(FieldEnum, bool, false); | 21 | pub const ActiveFields = std.enums.EnumFieldStruct(FieldEnum, bool, false); |
| 22 | pub const FieldValues = blk: { | 22 | pub const FieldValues = blk: { |
| 23 | comptime var fields: [bit_count]Type.StructField = undefined; | 23 | comptime var fields: [bit_count]Type.StructField = undefined; |
| 24 | inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| { | 24 | inline for (@typeInfo(Fields).Struct.fields, 0..) |struct_field, i| { |
| 25 | fields[i] = Type.StructField{ | 25 | fields[i] = Type.StructField{ |
| 26 | .name = struct_field.name, | 26 | .name = struct_field.name, |
| 27 | .type = ?struct_field.type, | 27 | .type = ?struct_field.type, |
| ... | @@ -61,7 +61,7 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -61,7 +61,7 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 61 | /// `fields` is a boolean struct where each active field is set to `true` | 61 | /// `fields` is a boolean struct where each active field is set to `true` |
| 62 | pub fn init(fields: ActiveFields) Self { | 62 | pub fn init(fields: ActiveFields) Self { |
| 63 | var self: Self = .{ .bits = 0 }; | 63 | var self: Self = .{ .bits = 0 }; |
| 64 | inline for (@typeInfo(Fields).Struct.fields) |field, i| { | 64 | inline for (@typeInfo(Fields).Struct.fields, 0..) |field, i| { |
| 65 | if (@field(fields, field.name)) | 65 | if (@field(fields, field.name)) |
| 66 | self.bits |= 1 << i; | 66 | self.bits |= 1 << i; |
| 67 | } | 67 | } |
| ... | @@ -70,7 +70,7 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -70,7 +70,7 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 70 | 70 | ||
| 71 | /// `fields` is a struct with each field set to an optional value | 71 | /// `fields` is a struct with each field set to an optional value |
| 72 | pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void { | 72 | pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void { |
| 73 | inline for (@typeInfo(Fields).Struct.fields) |field, i| { | 73 | inline for (@typeInfo(Fields).Struct.fields, 0..) |field, i| { |
| 74 | if (@field(fields, field.name)) |value| | 74 | if (@field(fields, field.name)) |value| |
| 75 | self.set(p, @intToEnum(FieldEnum, i), value); | 75 | self.set(p, @intToEnum(FieldEnum, i), value); |
| 76 | } | 76 | } |
| ... | @@ -101,7 +101,7 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -101,7 +101,7 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 101 | 101 | ||
| 102 | pub fn offset(self: Self, comptime field: FieldEnum) usize { | 102 | pub fn offset(self: Self, comptime field: FieldEnum) usize { |
| 103 | var off: usize = 0; | 103 | var off: usize = 0; |
| 104 | inline for (@typeInfo(Fields).Struct.fields) |field_info, i| { | 104 | inline for (@typeInfo(Fields).Struct.fields, 0..) |field_info, i| { |
| 105 | const active = (self.bits & (1 << i)) != 0; | 105 | const active = (self.bits & (1 << i)) != 0; |
| 106 | if (i == @enumToInt(field)) { | 106 | if (i == @enumToInt(field)) { |
| 107 | assert(active); | 107 | assert(active); |
| ... | @@ -119,7 +119,7 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -119,7 +119,7 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 119 | 119 | ||
| 120 | pub fn sizeInBytes(self: Self) usize { | 120 | pub fn sizeInBytes(self: Self) usize { |
| 121 | var off: usize = 0; | 121 | var off: usize = 0; |
| 122 | inline for (@typeInfo(Fields).Struct.fields) |field, i| { | 122 | inline for (@typeInfo(Fields).Struct.fields, 0..) |field, i| { |
| 123 | if (@sizeOf(field.type) == 0) | 123 | if (@sizeOf(field.type) == 0) |
| 124 | continue; | 124 | continue; |
| 125 | if ((self.bits & (1 << i)) != 0) { | 125 | if ((self.bits & (1 << i)) != 0) { |
lib/std/multi_array_list.zig+13-13| ... | @@ -82,7 +82,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -82,7 +82,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 82 | alignment: usize, | 82 | alignment: usize, |
| 83 | }; | 83 | }; |
| 84 | var data: [fields.len]Data = undefined; | 84 | var data: [fields.len]Data = undefined; |
| 85 | for (fields) |field_info, i| { | 85 | for (fields, 0..) |field_info, i| { |
| 86 | data[i] = .{ | 86 | data[i] = .{ |
| 87 | .size = @sizeOf(field_info.type), | 87 | .size = @sizeOf(field_info.type), |
| 88 | .size_index = i, | 88 | .size_index = i, |
| ... | @@ -98,7 +98,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -98,7 +98,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 98 | std.sort.sort(Data, &data, {}, Sort.lessThan); | 98 | std.sort.sort(Data, &data, {}, Sort.lessThan); |
| 99 | var sizes_bytes: [fields.len]usize = undefined; | 99 | var sizes_bytes: [fields.len]usize = undefined; |
| 100 | var field_indexes: [fields.len]usize = undefined; | 100 | var field_indexes: [fields.len]usize = undefined; |
| 101 | for (data) |elem, i| { | 101 | for (data, 0..) |elem, i| { |
| 102 | sizes_bytes[i] = elem.size; | 102 | sizes_bytes[i] = elem.size; |
| 103 | field_indexes[i] = elem.size_index; | 103 | field_indexes[i] = elem.size_index; |
| 104 | } | 104 | } |
| ... | @@ -131,7 +131,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -131,7 +131,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 131 | .capacity = self.capacity, | 131 | .capacity = self.capacity, |
| 132 | }; | 132 | }; |
| 133 | var ptr: [*]u8 = self.bytes; | 133 | var ptr: [*]u8 = self.bytes; |
| 134 | for (sizes.bytes) |field_size, i| { | 134 | for (sizes.bytes, 0..) |field_size, i| { |
| 135 | result.ptrs[sizes.fields[i]] = ptr; | 135 | result.ptrs[sizes.fields[i]] = ptr; |
| 136 | ptr += field_size * self.capacity; | 136 | ptr += field_size * self.capacity; |
| 137 | } | 137 | } |
| ... | @@ -148,7 +148,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -148,7 +148,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 148 | /// Overwrite one array element with new data. | 148 | /// Overwrite one array element with new data. |
| 149 | pub fn set(self: *Self, index: usize, elem: S) void { | 149 | pub fn set(self: *Self, index: usize, elem: S) void { |
| 150 | const slices = self.slice(); | 150 | const slices = self.slice(); |
| 151 | inline for (fields) |field_info, i| { | 151 | inline for (fields, 0..) |field_info, i| { |
| 152 | slices.items(@intToEnum(Field, i))[index] = @field(elem, field_info.name); | 152 | slices.items(@intToEnum(Field, i))[index] = @field(elem, field_info.name); |
| 153 | } | 153 | } |
| 154 | } | 154 | } |
| ... | @@ -157,7 +157,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -157,7 +157,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 157 | pub fn get(self: Self, index: usize) S { | 157 | pub fn get(self: Self, index: usize) S { |
| 158 | const slices = self.slice(); | 158 | const slices = self.slice(); |
| 159 | var result: S = undefined; | 159 | var result: S = undefined; |
| 160 | inline for (fields) |field_info, i| { | 160 | inline for (fields, 0..) |field_info, i| { |
| 161 | @field(result, field_info.name) = slices.items(@intToEnum(Field, i))[index]; | 161 | @field(result, field_info.name) = slices.items(@intToEnum(Field, i))[index]; |
| 162 | } | 162 | } |
| 163 | return result; | 163 | return result; |
| ... | @@ -230,7 +230,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -230,7 +230,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 230 | assert(index <= self.len); | 230 | assert(index <= self.len); |
| 231 | self.len += 1; | 231 | self.len += 1; |
| 232 | const slices = self.slice(); | 232 | const slices = self.slice(); |
| 233 | inline for (fields) |field_info, field_index| { | 233 | inline for (fields, 0..) |field_info, field_index| { |
| 234 | const field_slice = slices.items(@intToEnum(Field, field_index)); | 234 | const field_slice = slices.items(@intToEnum(Field, field_index)); |
| 235 | var i: usize = self.len - 1; | 235 | var i: usize = self.len - 1; |
| 236 | while (i > index) : (i -= 1) { | 236 | while (i > index) : (i -= 1) { |
| ... | @@ -245,7 +245,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -245,7 +245,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 245 | /// retain list ordering. | 245 | /// retain list ordering. |
| 246 | pub fn swapRemove(self: *Self, index: usize) void { | 246 | pub fn swapRemove(self: *Self, index: usize) void { |
| 247 | const slices = self.slice(); | 247 | const slices = self.slice(); |
| 248 | inline for (fields) |_, i| { | 248 | inline for (fields, 0..) |_, i| { |
| 249 | const field_slice = slices.items(@intToEnum(Field, i)); | 249 | const field_slice = slices.items(@intToEnum(Field, i)); |
| 250 | field_slice[index] = field_slice[self.len - 1]; | 250 | field_slice[index] = field_slice[self.len - 1]; |
| 251 | field_slice[self.len - 1] = undefined; | 251 | field_slice[self.len - 1] = undefined; |
| ... | @@ -257,7 +257,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -257,7 +257,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 257 | /// after it to preserve order. | 257 | /// after it to preserve order. |
| 258 | pub fn orderedRemove(self: *Self, index: usize) void { | 258 | pub fn orderedRemove(self: *Self, index: usize) void { |
| 259 | const slices = self.slice(); | 259 | const slices = self.slice(); |
| 260 | inline for (fields) |_, field_index| { | 260 | inline for (fields, 0..) |_, field_index| { |
| 261 | const field_slice = slices.items(@intToEnum(Field, field_index)); | 261 | const field_slice = slices.items(@intToEnum(Field, field_index)); |
| 262 | var i = index; | 262 | var i = index; |
| 263 | while (i < self.len - 1) : (i += 1) { | 263 | while (i < self.len - 1) : (i += 1) { |
| ... | @@ -293,7 +293,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -293,7 +293,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 293 | capacityInBytes(new_len), | 293 | capacityInBytes(new_len), |
| 294 | ) catch { | 294 | ) catch { |
| 295 | const self_slice = self.slice(); | 295 | const self_slice = self.slice(); |
| 296 | inline for (fields) |field_info, i| { | 296 | inline for (fields, 0..) |field_info, i| { |
| 297 | if (@sizeOf(field_info.type) != 0) { | 297 | if (@sizeOf(field_info.type) != 0) { |
| 298 | const field = @intToEnum(Field, i); | 298 | const field = @intToEnum(Field, i); |
| 299 | const dest_slice = self_slice.items(field)[new_len..]; | 299 | const dest_slice = self_slice.items(field)[new_len..]; |
| ... | @@ -315,7 +315,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -315,7 +315,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 315 | self.len = new_len; | 315 | self.len = new_len; |
| 316 | const self_slice = self.slice(); | 316 | const self_slice = self.slice(); |
| 317 | const other_slice = other.slice(); | 317 | const other_slice = other.slice(); |
| 318 | inline for (fields) |field_info, i| { | 318 | inline for (fields, 0..) |field_info, i| { |
| 319 | if (@sizeOf(field_info.type) != 0) { | 319 | if (@sizeOf(field_info.type) != 0) { |
| 320 | const field = @intToEnum(Field, i); | 320 | const field = @intToEnum(Field, i); |
| 321 | mem.copy(field_info.type, other_slice.items(field), self_slice.items(field)); | 321 | mem.copy(field_info.type, other_slice.items(field), self_slice.items(field)); |
| ... | @@ -376,7 +376,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -376,7 +376,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 376 | }; | 376 | }; |
| 377 | const self_slice = self.slice(); | 377 | const self_slice = self.slice(); |
| 378 | const other_slice = other.slice(); | 378 | const other_slice = other.slice(); |
| 379 | inline for (fields) |field_info, i| { | 379 | inline for (fields, 0..) |field_info, i| { |
| 380 | if (@sizeOf(field_info.type) != 0) { | 380 | if (@sizeOf(field_info.type) != 0) { |
| 381 | const field = @intToEnum(Field, i); | 381 | const field = @intToEnum(Field, i); |
| 382 | mem.copy(field_info.type, other_slice.items(field), self_slice.items(field)); | 382 | mem.copy(field_info.type, other_slice.items(field), self_slice.items(field)); |
| ... | @@ -395,7 +395,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -395,7 +395,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 395 | result.len = self.len; | 395 | result.len = self.len; |
| 396 | const self_slice = self.slice(); | 396 | const self_slice = self.slice(); |
| 397 | const result_slice = result.slice(); | 397 | const result_slice = result.slice(); |
| 398 | inline for (fields) |field_info, i| { | 398 | inline for (fields, 0..) |field_info, i| { |
| 399 | if (@sizeOf(field_info.type) != 0) { | 399 | if (@sizeOf(field_info.type) != 0) { |
| 400 | const field = @intToEnum(Field, i); | 400 | const field = @intToEnum(Field, i); |
| 401 | mem.copy(field_info.type, result_slice.items(field), self_slice.items(field)); | 401 | mem.copy(field_info.type, result_slice.items(field), self_slice.items(field)); |
| ... | @@ -412,7 +412,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -412,7 +412,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 412 | slice: Slice, | 412 | slice: Slice, |
| 413 | 413 | ||
| 414 | pub fn swap(sc: @This(), a_index: usize, b_index: usize) void { | 414 | pub fn swap(sc: @This(), a_index: usize, b_index: usize) void { |
| 415 | inline for (fields) |field_info, i| { | 415 | inline for (fields, 0..) |field_info, i| { |
| 416 | if (@sizeOf(field_info.type) != 0) { | 416 | if (@sizeOf(field_info.type) != 0) { |
| 417 | const field = @intToEnum(Field, i); | 417 | const field = @intToEnum(Field, i); |
| 418 | const ptr = sc.slice.items(field); | 418 | const ptr = sc.slice.items(field); |
lib/std/net.zig+7-7| ... | @@ -325,7 +325,7 @@ pub const Ip6Address = extern struct { | ... | @@ -325,7 +325,7 @@ pub const Ip6Address = extern struct { |
| 325 | var index: u8 = 0; | 325 | var index: u8 = 0; |
| 326 | var scope_id = false; | 326 | var scope_id = false; |
| 327 | var abbrv = false; | 327 | var abbrv = false; |
| 328 | for (buf) |c, i| { | 328 | for (buf, 0..) |c, i| { |
| 329 | if (scope_id) { | 329 | if (scope_id) { |
| 330 | if (c >= '0' and c <= '9') { | 330 | if (c >= '0' and c <= '9') { |
| 331 | const digit = c - '0'; | 331 | const digit = c - '0'; |
| ... | @@ -444,7 +444,7 @@ pub const Ip6Address = extern struct { | ... | @@ -444,7 +444,7 @@ pub const Ip6Address = extern struct { |
| 444 | var scope_id_value: [os.IFNAMESIZE - 1]u8 = undefined; | 444 | var scope_id_value: [os.IFNAMESIZE - 1]u8 = undefined; |
| 445 | var scope_id_index: usize = 0; | 445 | var scope_id_index: usize = 0; |
| 446 | 446 | ||
| 447 | for (buf) |c, i| { | 447 | for (buf, 0..) |c, i| { |
| 448 | if (scope_id) { | 448 | if (scope_id) { |
| 449 | // Handling of percent-encoding should be for an URI library. | 449 | // Handling of percent-encoding should be for an URI library. |
| 450 | if ((c >= '0' and c <= '9') or | 450 | if ((c >= '0' and c <= '9') or |
| ... | @@ -602,7 +602,7 @@ pub const Ip6Address = extern struct { | ... | @@ -602,7 +602,7 @@ pub const Ip6Address = extern struct { |
| 602 | .Big => big_endian_parts.*, | 602 | .Big => big_endian_parts.*, |
| 603 | .Little => blk: { | 603 | .Little => blk: { |
| 604 | var buf: [8]u16 = undefined; | 604 | var buf: [8]u16 = undefined; |
| 605 | for (big_endian_parts) |part, i| { | 605 | for (big_endian_parts, 0..) |part, i| { |
| 606 | buf[i] = mem.bigToNative(u16, part); | 606 | buf[i] = mem.bigToNative(u16, part); |
| 607 | } | 607 | } |
| 608 | break :blk buf; | 608 | break :blk buf; |
| ... | @@ -909,7 +909,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) !*A | ... | @@ -909,7 +909,7 @@ pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) !*A |
| 909 | result.canon_name = try canon.toOwnedSlice(); | 909 | result.canon_name = try canon.toOwnedSlice(); |
| 910 | } | 910 | } |
| 911 | 911 | ||
| 912 | for (lookup_addrs.items) |lookup_addr, i| { | 912 | for (lookup_addrs.items, 0..) |lookup_addr, i| { |
| 913 | result.addrs[i] = lookup_addr.addr; | 913 | result.addrs[i] = lookup_addr.addr; |
| 914 | assert(result.addrs[i].getPort() == port); | 914 | assert(result.addrs[i].getPort() == port); |
| 915 | } | 915 | } |
| ... | @@ -989,7 +989,7 @@ fn linuxLookupName( | ... | @@ -989,7 +989,7 @@ fn linuxLookupName( |
| 989 | // So far the label/precedence table cannot be customized. | 989 | // So far the label/precedence table cannot be customized. |
| 990 | // This implementation is ported from musl libc. | 990 | // This implementation is ported from musl libc. |
| 991 | // A more idiomatic "ziggy" implementation would be welcome. | 991 | // A more idiomatic "ziggy" implementation would be welcome. |
| 992 | for (addrs.items) |*addr, i| { | 992 | for (addrs.items, 0..) |*addr, i| { |
| 993 | var key: i32 = 0; | 993 | var key: i32 = 0; |
| 994 | var sa6: os.sockaddr.in6 = undefined; | 994 | var sa6: os.sockaddr.in6 = undefined; |
| 995 | @memset(@ptrCast([*]u8, &sa6), 0, @sizeOf(os.sockaddr.in6)); | 995 | @memset(@ptrCast([*]u8, &sa6), 0, @sizeOf(os.sockaddr.in6)); |
| ... | @@ -1118,7 +1118,7 @@ const defined_policies = [_]Policy{ | ... | @@ -1118,7 +1118,7 @@ const defined_policies = [_]Policy{ |
| 1118 | }; | 1118 | }; |
| 1119 | 1119 | ||
| 1120 | fn policyOf(a: [16]u8) *const Policy { | 1120 | fn policyOf(a: [16]u8) *const Policy { |
| 1121 | for (defined_policies) |*policy| { | 1121 | for (&defined_policies) |*policy| { |
| 1122 | if (!mem.eql(u8, a[0..policy.len], policy.addr[0..policy.len])) continue; | 1122 | if (!mem.eql(u8, a[0..policy.len], policy.addr[0..policy.len])) continue; |
| 1123 | if ((a[policy.len] & policy.mask) != policy.addr[policy.len]) continue; | 1123 | if ((a[policy.len] & policy.mask) != policy.addr[policy.len]) continue; |
| 1124 | return policy; | 1124 | return policy; |
| ... | @@ -1502,7 +1502,7 @@ fn resMSendRc( | ... | @@ -1502,7 +1502,7 @@ fn resMSendRc( |
| 1502 | try ns_list.resize(rc.ns.items.len); | 1502 | try ns_list.resize(rc.ns.items.len); |
| 1503 | const ns = ns_list.items; | 1503 | const ns = ns_list.items; |
| 1504 | 1504 | ||
| 1505 | for (rc.ns.items) |iplit, i| { | 1505 | for (rc.ns.items, 0..) |iplit, i| { |
| 1506 | ns[i] = iplit.addr; | 1506 | ns[i] = iplit.addr; |
| 1507 | assert(ns[i].getPort() == 53); | 1507 | assert(ns[i].getPort() == 53); |
| 1508 | if (iplit.addr.any.family != os.AF.INET) { | 1508 | if (iplit.addr.any.family != os.AF.INET) { |
lib/std/net/test.zig+1-1| ... | @@ -30,7 +30,7 @@ test "parse and render IPv6 addresses" { | ... | @@ -30,7 +30,7 @@ test "parse and render IPv6 addresses" { |
| 30 | "ff01::fb", | 30 | "ff01::fb", |
| 31 | "::ffff:123.5.123.5", | 31 | "::ffff:123.5.123.5", |
| 32 | }; | 32 | }; |
| 33 | for (ips) |ip, i| { | 33 | for (ips, 0..) |ip, i| { |
| 34 | var addr = net.Address.parseIp6(ip, 0) catch unreachable; | 34 | var addr = net.Address.parseIp6(ip, 0) catch unreachable; |
| 35 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; | 35 | var newIp = std.fmt.bufPrint(buffer[0..], "{}", .{addr}) catch unreachable; |
| 36 | try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3])); | 36 | try std.testing.expect(std.mem.eql(u8, printed[i], newIp[1 .. newIp.len - 3])); |
lib/std/once.zig+1-1| ... | @@ -53,7 +53,7 @@ test "Once executes its function just once" { | ... | @@ -53,7 +53,7 @@ test "Once executes its function just once" { |
| 53 | var threads: [10]std.Thread = undefined; | 53 | var threads: [10]std.Thread = undefined; |
| 54 | defer for (threads) |handle| handle.join(); | 54 | defer for (threads) |handle| handle.join(); |
| 55 | 55 | ||
| 56 | for (threads) |*handle| { | 56 | for (&threads) |*handle| { |
| 57 | handle.* = try std.Thread.spawn(.{}, struct { | 57 | handle.* = try std.Thread.spawn(.{}, struct { |
| 58 | fn thread_fn(x: u8) void { | 58 | fn thread_fn(x: u8) void { |
| 59 | _ = x; | 59 | _ = x; |
lib/std/os/linux.zig+1-1| ... | @@ -1245,7 +1245,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize | ... | @@ -1245,7 +1245,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize |
| 1245 | // see https://www.openwall.com/lists/musl/2014/06/07/5 | 1245 | // see https://www.openwall.com/lists/musl/2014/06/07/5 |
| 1246 | const kvlen = if (vlen > IOV_MAX) IOV_MAX else vlen; // matches kernel | 1246 | const kvlen = if (vlen > IOV_MAX) IOV_MAX else vlen; // matches kernel |
| 1247 | var next_unsent: usize = 0; | 1247 | var next_unsent: usize = 0; |
| 1248 | for (msgvec[0..kvlen]) |*msg, i| { | 1248 | for (msgvec[0..kvlen], 0..) |*msg, i| { |
| 1249 | var size: i32 = 0; | 1249 | var size: i32 = 0; |
| 1250 | const msg_iovlen = @intCast(usize, msg.msg_hdr.msg_iovlen); // kernel side this is treated as unsigned | 1250 | const msg_iovlen = @intCast(usize, msg.msg_hdr.msg_iovlen); // kernel side this is treated as unsigned |
| 1251 | for (msg.msg_hdr.msg_iov[0..msg_iovlen]) |iov| { | 1251 | for (msg.msg_hdr.msg_iov[0..msg_iovlen]) |iov| { |
lib/std/os/uefi/protocols/device_path_protocol.zig+1-1| ... | @@ -61,7 +61,7 @@ pub const DevicePathProtocol = extern struct { | ... | @@ -61,7 +61,7 @@ pub const DevicePathProtocol = extern struct { |
| 61 | // The same as new.getPath(), but not const as we're filling it in. | 61 | // The same as new.getPath(), but not const as we're filling it in. |
| 62 | var ptr = @ptrCast([*:0]align(1) u16, @ptrCast([*]u8, new) + @sizeOf(MediaDevicePath.FilePathDevicePath)); | 62 | var ptr = @ptrCast([*:0]align(1) u16, @ptrCast([*]u8, new) + @sizeOf(MediaDevicePath.FilePathDevicePath)); |
| 63 | 63 | ||
| 64 | for (path) |s, i| | 64 | for (path, 0..) |s, i| |
| 65 | ptr[i] = s; | 65 | ptr[i] = s; |
| 66 | 66 | ||
| 67 | ptr[path.len] = 0; | 67 | ptr[path.len] = 0; |
lib/std/os/windows.zig+1-1| ... | @@ -2858,7 +2858,7 @@ pub const GUID = extern struct { | ... | @@ -2858,7 +2858,7 @@ pub const GUID = extern struct { |
| 2858 | assert(s[18] == '-'); | 2858 | assert(s[18] == '-'); |
| 2859 | assert(s[23] == '-'); | 2859 | assert(s[23] == '-'); |
| 2860 | var bytes: [16]u8 = undefined; | 2860 | var bytes: [16]u8 = undefined; |
| 2861 | for (hex_offsets) |hex_offset, i| { | 2861 | for (hex_offsets, 0..) |hex_offset, i| { |
| 2862 | bytes[i] = (try std.fmt.charToDigit(s[hex_offset], 16)) << 4 | | 2862 | bytes[i] = (try std.fmt.charToDigit(s[hex_offset], 16)) << 4 | |
| 2863 | try std.fmt.charToDigit(s[hex_offset + 1], 16); | 2863 | try std.fmt.charToDigit(s[hex_offset + 1], 16); |
| 2864 | } | 2864 | } |
lib/std/packed_int_array.zig+2-2| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | //! An set of array and slice types that bit-pack integer elements. A normal [12]u3 | 1 | //! A set of array and slice types that bit-pack integer elements. A normal [12]u3 |
| 2 | //! takes up 12 bytes of memory since u3's alignment is 1. PackedArray(u3, 12) only | 2 | //! takes up 12 bytes of memory since u3's alignment is 1. PackedArray(u3, 12) only |
| 3 | //! takes up 4 bytes of memory. | 3 | //! takes up 4 bytes of memory. |
| 4 | 4 | ||
| ... | @@ -215,7 +215,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: Endian, comptim | ... | @@ -215,7 +215,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: Endian, comptim |
| 215 | /// or, more likely, an array literal. | 215 | /// or, more likely, an array literal. |
| 216 | pub fn init(ints: [int_count]Int) Self { | 216 | pub fn init(ints: [int_count]Int) Self { |
| 217 | var self = @as(Self, undefined); | 217 | var self = @as(Self, undefined); |
| 218 | for (ints) |int, i| self.set(i, int); | 218 | for (ints, 0..) |int, i| self.set(i, int); |
| 219 | return self; | 219 | return self; |
| 220 | } | 220 | } |
| 221 | 221 |
lib/std/pdb.zig+1-1| ... | @@ -922,7 +922,7 @@ const Msf = struct { | ... | @@ -922,7 +922,7 @@ const Msf = struct { |
| 922 | } | 922 | } |
| 923 | 923 | ||
| 924 | const streams = try allocator.alloc(MsfStream, stream_count); | 924 | const streams = try allocator.alloc(MsfStream, stream_count); |
| 925 | for (streams) |*stream, i| { | 925 | for (streams, 0..) |*stream, i| { |
| 926 | const size = stream_sizes[i]; | 926 | const size = stream_sizes[i]; |
| 927 | if (size == 0) { | 927 | if (size == 0) { |
| 928 | stream.* = MsfStream{ | 928 | stream.* = MsfStream{ |
lib/std/priority_dequeue.zig+1-1| ... | @@ -430,7 +430,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar | ... | @@ -430,7 +430,7 @@ pub fn PriorityDequeue(comptime T: type, comptime Context: type, comptime compar |
| 430 | const print = std.debug.print; | 430 | const print = std.debug.print; |
| 431 | print("{{ ", .{}); | 431 | print("{{ ", .{}); |
| 432 | print("items: ", .{}); | 432 | print("items: ", .{}); |
| 433 | for (self.items) |e, i| { | 433 | for (self.items, 0..) |e, i| { |
| 434 | if (i >= self.len) break; | 434 | if (i >= self.len) break; |
| 435 | print("{}, ", .{e}); | 435 | print("{}, ", .{e}); |
| 436 | } | 436 | } |
lib/std/priority_queue.zig+1-1| ... | @@ -263,7 +263,7 @@ pub fn PriorityQueue(comptime T: type, comptime Context: type, comptime compareF | ... | @@ -263,7 +263,7 @@ pub fn PriorityQueue(comptime T: type, comptime Context: type, comptime compareF |
| 263 | const print = std.debug.print; | 263 | const print = std.debug.print; |
| 264 | print("{{ ", .{}); | 264 | print("{{ ", .{}); |
| 265 | print("items: ", .{}); | 265 | print("items: ", .{}); |
| 266 | for (self.items) |e, i| { | 266 | for (self.items, 0..) |e, i| { |
| 267 | if (i >= self.len) break; | 267 | if (i >= self.len) break; |
| 268 | print("{}, ", .{e}); | 268 | print("{}, ", .{e}); |
| 269 | } | 269 | } |
lib/std/process.zig+2-2| ... | @@ -874,7 +874,7 @@ pub fn argsAlloc(allocator: Allocator) ![][:0]u8 { | ... | @@ -874,7 +874,7 @@ pub fn argsAlloc(allocator: Allocator) ![][:0]u8 { |
| 874 | mem.copy(u8, result_contents, contents_slice); | 874 | mem.copy(u8, result_contents, contents_slice); |
| 875 | 875 | ||
| 876 | var contents_index: usize = 0; | 876 | var contents_index: usize = 0; |
| 877 | for (slice_sizes) |len, i| { | 877 | for (slice_sizes, 0..) |len, i| { |
| 878 | const new_index = contents_index + len; | 878 | const new_index = contents_index + len; |
| 879 | result_slice_list[i] = result_contents[contents_index..new_index :0]; | 879 | result_slice_list[i] = result_contents[contents_index..new_index :0]; |
| 880 | contents_index = new_index + 1; | 880 | contents_index = new_index + 1; |
| ... | @@ -1148,7 +1148,7 @@ pub fn execve( | ... | @@ -1148,7 +1148,7 @@ pub fn execve( |
| 1148 | const arena = arena_allocator.allocator(); | 1148 | const arena = arena_allocator.allocator(); |
| 1149 | 1149 | ||
| 1150 | const argv_buf = try arena.allocSentinel(?[*:0]u8, argv.len, null); | 1150 | const argv_buf = try arena.allocSentinel(?[*:0]u8, argv.len, null); |
| 1151 | for (argv) |arg, i| argv_buf[i] = (try arena.dupeZ(u8, arg)).ptr; | 1151 | for (argv, 0..) |arg, i| argv_buf[i] = (try arena.dupeZ(u8, arg)).ptr; |
| 1152 | 1152 | ||
| 1153 | const envp = m: { | 1153 | const envp = m: { |
| 1154 | if (env_map) |m| { | 1154 | if (env_map) |m| { |
lib/std/rand.zig+1-1| ... | @@ -414,7 +414,7 @@ pub const Random = struct { | ... | @@ -414,7 +414,7 @@ pub const Random = struct { |
| 414 | std.debug.assert(point < sum); | 414 | std.debug.assert(point < sum); |
| 415 | 415 | ||
| 416 | var accumulator: T = 0; | 416 | var accumulator: T = 0; |
| 417 | for (proportions) |p, index| { | 417 | for (proportions, 0..) |p, index| { |
| 418 | accumulator += p; | 418 | accumulator += p; |
| 419 | if (point < accumulator) return index; | 419 | if (point < accumulator) return index; |
| 420 | } | 420 | } |
lib/std/rand/ziggurat.zig+2-2| ... | @@ -83,13 +83,13 @@ fn ZigTableGen( | ... | @@ -83,13 +83,13 @@ fn ZigTableGen( |
| 83 | tables.x[0] = v / f(r); | 83 | tables.x[0] = v / f(r); |
| 84 | tables.x[1] = r; | 84 | tables.x[1] = r; |
| 85 | 85 | ||
| 86 | for (tables.x[2..256]) |*entry, i| { | 86 | for (tables.x[2..256], 0..) |*entry, i| { |
| 87 | const last = tables.x[2 + i - 1]; | 87 | const last = tables.x[2 + i - 1]; |
| 88 | entry.* = f_inv(v / last + f(last)); | 88 | entry.* = f_inv(v / last + f(last)); |
| 89 | } | 89 | } |
| 90 | tables.x[256] = 0; | 90 | tables.x[256] = 0; |
| 91 | 91 | ||
| 92 | for (tables.f[0..]) |*entry, i| { | 92 | for (tables.f[0..], 0..) |*entry, i| { |
| 93 | entry.* = f(tables.x[i]); | 93 | entry.* = f(tables.x[i]); |
| 94 | } | 94 | } |
| 95 | 95 |
lib/std/simd.zig+1-1| ... | @@ -89,7 +89,7 @@ pub fn VectorCount(comptime VectorType: type) type { | ... | @@ -89,7 +89,7 @@ pub fn VectorCount(comptime VectorType: type) type { |
| 89 | pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) { | 89 | pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) { |
| 90 | comptime { | 90 | comptime { |
| 91 | var out: [len]T = undefined; | 91 | var out: [len]T = undefined; |
| 92 | for (out) |*element, i| { | 92 | for (&out, 0..) |*element, i| { |
| 93 | element.* = switch (@typeInfo(T)) { | 93 | element.* = switch (@typeInfo(T)) { |
| 94 | .Int => @intCast(T, i), | 94 | .Int => @intCast(T, i), |
| 95 | .Float => @intToFloat(T, i), | 95 | .Float => @intToFloat(T, i), |
lib/std/sort.zig+5-5| ... | @@ -1219,9 +1219,9 @@ fn testStableSort() !void { | ... | @@ -1219,9 +1219,9 @@ fn testStableSort() !void { |
| 1219 | IdAndValue{ .id = 2, .value = 0 }, | 1219 | IdAndValue{ .id = 2, .value = 0 }, |
| 1220 | }, | 1220 | }, |
| 1221 | }; | 1221 | }; |
| 1222 | for (cases) |*case| { | 1222 | for (&cases) |*case| { |
| 1223 | insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue); | 1223 | insertionSort(IdAndValue, (case.*)[0..], {}, cmpByValue); |
| 1224 | for (case.*) |item, i| { | 1224 | for (case.*, 0..) |item, i| { |
| 1225 | try testing.expect(item.id == expected[i].id); | 1225 | try testing.expect(item.id == expected[i].id); |
| 1226 | try testing.expect(item.value == expected[i].value); | 1226 | try testing.expect(item.value == expected[i].value); |
| 1227 | } | 1227 | } |
| ... | @@ -1373,7 +1373,7 @@ fn fuzzTest(rng: std.rand.Random) !void { | ... | @@ -1373,7 +1373,7 @@ fn fuzzTest(rng: std.rand.Random) !void { |
| 1373 | var array = try testing.allocator.alloc(IdAndValue, array_size); | 1373 | var array = try testing.allocator.alloc(IdAndValue, array_size); |
| 1374 | defer testing.allocator.free(array); | 1374 | defer testing.allocator.free(array); |
| 1375 | // populate with random data | 1375 | // populate with random data |
| 1376 | for (array) |*item, index| { | 1376 | for (array, 0..) |*item, index| { |
| 1377 | item.id = index; | 1377 | item.id = index; |
| 1378 | item.value = rng.intRangeLessThan(i32, 0, 100); | 1378 | item.value = rng.intRangeLessThan(i32, 0, 100); |
| 1379 | } | 1379 | } |
| ... | @@ -1401,7 +1401,7 @@ pub fn argMin( | ... | @@ -1401,7 +1401,7 @@ pub fn argMin( |
| 1401 | 1401 | ||
| 1402 | var smallest = items[0]; | 1402 | var smallest = items[0]; |
| 1403 | var smallest_index: usize = 0; | 1403 | var smallest_index: usize = 0; |
| 1404 | for (items[1..]) |item, i| { | 1404 | for (items[1..], 0..) |item, i| { |
| 1405 | if (lessThan(context, item, smallest)) { | 1405 | if (lessThan(context, item, smallest)) { |
| 1406 | smallest = item; | 1406 | smallest = item; |
| 1407 | smallest_index = i + 1; | 1407 | smallest_index = i + 1; |
| ... | @@ -1453,7 +1453,7 @@ pub fn argMax( | ... | @@ -1453,7 +1453,7 @@ pub fn argMax( |
| 1453 | 1453 | ||
| 1454 | var biggest = items[0]; | 1454 | var biggest = items[0]; |
| 1455 | var biggest_index: usize = 0; | 1455 | var biggest_index: usize = 0; |
| 1456 | for (items[1..]) |item, i| { | 1456 | for (items[1..], 0..) |item, i| { |
| 1457 | if (lessThan(context, biggest, item)) { | 1457 | if (lessThan(context, biggest, item)) { |
| 1458 | biggest = item; | 1458 | biggest = item; |
| 1459 | biggest_index = i + 1; | 1459 | biggest_index = i + 1; |
lib/std/target.zig+4-4| ... | @@ -725,7 +725,7 @@ pub const Target = struct { | ... | @@ -725,7 +725,7 @@ pub const Target = struct { |
| 725 | /// Adds the specified feature set but not its dependencies. | 725 | /// Adds the specified feature set but not its dependencies. |
| 726 | pub fn addFeatureSet(set: *Set, other_set: Set) void { | 726 | pub fn addFeatureSet(set: *Set, other_set: Set) void { |
| 727 | if (builtin.zig_backend == .stage2_c) { | 727 | if (builtin.zig_backend == .stage2_c) { |
| 728 | for (set.ints) |*int, i| int.* |= other_set.ints[i]; | 728 | for (&set.ints, 0..) |*int, i| int.* |= other_set.ints[i]; |
| 729 | } else { | 729 | } else { |
| 730 | set.ints = @as(@Vector(usize_count, usize), set.ints) | @as(@Vector(usize_count, usize), other_set.ints); | 730 | set.ints = @as(@Vector(usize_count, usize), set.ints) | @as(@Vector(usize_count, usize), other_set.ints); |
| 731 | } | 731 | } |
| ... | @@ -741,7 +741,7 @@ pub const Target = struct { | ... | @@ -741,7 +741,7 @@ pub const Target = struct { |
| 741 | /// Removes the specified feature but not its dependents. | 741 | /// Removes the specified feature but not its dependents. |
| 742 | pub fn removeFeatureSet(set: *Set, other_set: Set) void { | 742 | pub fn removeFeatureSet(set: *Set, other_set: Set) void { |
| 743 | if (builtin.zig_backend == .stage2_c) { | 743 | if (builtin.zig_backend == .stage2_c) { |
| 744 | for (set.ints) |*int, i| int.* &= ~other_set.ints[i]; | 744 | for (&set.ints, 0..) |*int, i| int.* &= ~other_set.ints[i]; |
| 745 | } else { | 745 | } else { |
| 746 | set.ints = @as(@Vector(usize_count, usize), set.ints) & ~@as(@Vector(usize_count, usize), other_set.ints); | 746 | set.ints = @as(@Vector(usize_count, usize), set.ints) & ~@as(@Vector(usize_count, usize), other_set.ints); |
| 747 | } | 747 | } |
| ... | @@ -752,7 +752,7 @@ pub const Target = struct { | ... | @@ -752,7 +752,7 @@ pub const Target = struct { |
| 752 | 752 | ||
| 753 | var old = set.ints; | 753 | var old = set.ints; |
| 754 | while (true) { | 754 | while (true) { |
| 755 | for (all_features_list) |feature, index_usize| { | 755 | for (all_features_list, 0..) |feature, index_usize| { |
| 756 | const index = @intCast(Index, index_usize); | 756 | const index = @intCast(Index, index_usize); |
| 757 | if (set.isEnabled(index)) { | 757 | if (set.isEnabled(index)) { |
| 758 | set.addFeatureSet(feature.dependencies); | 758 | set.addFeatureSet(feature.dependencies); |
| ... | @@ -1350,7 +1350,7 @@ pub const Target = struct { | ... | @@ -1350,7 +1350,7 @@ pub const Target = struct { |
| 1350 | fn allCpusFromDecls(comptime cpus: type) []const *const Cpu.Model { | 1350 | fn allCpusFromDecls(comptime cpus: type) []const *const Cpu.Model { |
| 1351 | const decls = @typeInfo(cpus).Struct.decls; | 1351 | const decls = @typeInfo(cpus).Struct.decls; |
| 1352 | var array: [decls.len]*const Cpu.Model = undefined; | 1352 | var array: [decls.len]*const Cpu.Model = undefined; |
| 1353 | for (decls) |decl, i| { | 1353 | for (decls, 0..) |decl, i| { |
| 1354 | array[i] = &@field(cpus, decl.name); | 1354 | array[i] = &@field(cpus, decl.name); |
| 1355 | } | 1355 | } |
| 1356 | return &array; | 1356 | return &array; |
lib/std/target/aarch64.zig+1-1| ... | @@ -1435,7 +1435,7 @@ pub const all_features = blk: { | ... | @@ -1435,7 +1435,7 @@ pub const all_features = blk: { |
| 1435 | .dependencies = featureSet(&[_]Feature{}), | 1435 | .dependencies = featureSet(&[_]Feature{}), |
| 1436 | }; | 1436 | }; |
| 1437 | const ti = @typeInfo(Feature); | 1437 | const ti = @typeInfo(Feature); |
| 1438 | for (result) |*elem, i| { | 1438 | for (&result, 0..) |*elem, i| { |
| 1439 | elem.index = i; | 1439 | elem.index = i; |
| 1440 | elem.name = ti.Enum.fields[i].name; | 1440 | elem.name = ti.Enum.fields[i].name; |
| 1441 | } | 1441 | } |
lib/std/target/amdgpu.zig+1-1| ... | @@ -1076,7 +1076,7 @@ pub const all_features = blk: { | ... | @@ -1076,7 +1076,7 @@ pub const all_features = blk: { |
| 1076 | .dependencies = featureSet(&[_]Feature{}), | 1076 | .dependencies = featureSet(&[_]Feature{}), |
| 1077 | }; | 1077 | }; |
| 1078 | const ti = @typeInfo(Feature); | 1078 | const ti = @typeInfo(Feature); |
| 1079 | for (result) |*elem, i| { | 1079 | for (&result, 0..) |*elem, i| { |
| 1080 | elem.index = i; | 1080 | elem.index = i; |
| 1081 | elem.name = ti.Enum.fields[i].name; | 1081 | elem.name = ti.Enum.fields[i].name; |
| 1082 | } | 1082 | } |
lib/std/target/arc.zig+1-1| ... | @@ -23,7 +23,7 @@ pub const all_features = blk: { | ... | @@ -23,7 +23,7 @@ pub const all_features = blk: { |
| 23 | .dependencies = featureSet(&[_]Feature{}), | 23 | .dependencies = featureSet(&[_]Feature{}), |
| 24 | }; | 24 | }; |
| 25 | const ti = @typeInfo(Feature); | 25 | const ti = @typeInfo(Feature); |
| 26 | for (result) |*elem, i| { | 26 | for (&result, 0..) |*elem, i| { |
| 27 | elem.index = i; | 27 | elem.index = i; |
| 28 | elem.name = ti.Enum.fields[i].name; | 28 | elem.name = ti.Enum.fields[i].name; |
| 29 | } | 29 | } |
lib/std/target/arm.zig+1-1| ... | @@ -1696,7 +1696,7 @@ pub const all_features = blk: { | ... | @@ -1696,7 +1696,7 @@ pub const all_features = blk: { |
| 1696 | .dependencies = featureSet(&[_]Feature{}), | 1696 | .dependencies = featureSet(&[_]Feature{}), |
| 1697 | }; | 1697 | }; |
| 1698 | const ti = @typeInfo(Feature); | 1698 | const ti = @typeInfo(Feature); |
| 1699 | for (result) |*elem, i| { | 1699 | for (&result, 0..) |*elem, i| { |
| 1700 | elem.index = i; | 1700 | elem.index = i; |
| 1701 | elem.name = ti.Enum.fields[i].name; | 1701 | elem.name = ti.Enum.fields[i].name; |
| 1702 | } | 1702 | } |
lib/std/target/avr.zig+1-1| ... | @@ -339,7 +339,7 @@ pub const all_features = blk: { | ... | @@ -339,7 +339,7 @@ pub const all_features = blk: { |
| 339 | }), | 339 | }), |
| 340 | }; | 340 | }; |
| 341 | const ti = @typeInfo(Feature); | 341 | const ti = @typeInfo(Feature); |
| 342 | for (result) |*elem, i| { | 342 | for (&result, 0..) |*elem, i| { |
| 343 | elem.index = i; | 343 | elem.index = i; |
| 344 | elem.name = ti.Enum.fields[i].name; | 344 | elem.name = ti.Enum.fields[i].name; |
| 345 | } | 345 | } |
lib/std/target/bpf.zig+1-1| ... | @@ -35,7 +35,7 @@ pub const all_features = blk: { | ... | @@ -35,7 +35,7 @@ pub const all_features = blk: { |
| 35 | .dependencies = featureSet(&[_]Feature{}), | 35 | .dependencies = featureSet(&[_]Feature{}), |
| 36 | }; | 36 | }; |
| 37 | const ti = @typeInfo(Feature); | 37 | const ti = @typeInfo(Feature); |
| 38 | for (result) |*elem, i| { | 38 | for (&result, 0..) |*elem, i| { |
| 39 | elem.index = i; | 39 | elem.index = i; |
| 40 | elem.name = ti.Enum.fields[i].name; | 40 | elem.name = ti.Enum.fields[i].name; |
| 41 | } | 41 | } |
lib/std/target/csky.zig+1-1| ... | @@ -416,7 +416,7 @@ pub const all_features = blk: { | ... | @@ -416,7 +416,7 @@ pub const all_features = blk: { |
| 416 | .dependencies = featureSet(&[_]Feature{}), | 416 | .dependencies = featureSet(&[_]Feature{}), |
| 417 | }; | 417 | }; |
| 418 | const ti = @typeInfo(Feature); | 418 | const ti = @typeInfo(Feature); |
| 419 | for (result) |*elem, i| { | 419 | for (&result, 0..) |*elem, i| { |
| 420 | elem.index = i; | 420 | elem.index = i; |
| 421 | elem.name = ti.Enum.fields[i].name; | 421 | elem.name = ti.Enum.fields[i].name; |
| 422 | } | 422 | } |
lib/std/target/hexagon.zig+1-1| ... | @@ -296,7 +296,7 @@ pub const all_features = blk: { | ... | @@ -296,7 +296,7 @@ pub const all_features = blk: { |
| 296 | .dependencies = featureSet(&[_]Feature{}), | 296 | .dependencies = featureSet(&[_]Feature{}), |
| 297 | }; | 297 | }; |
| 298 | const ti = @typeInfo(Feature); | 298 | const ti = @typeInfo(Feature); |
| 299 | for (result) |*elem, i| { | 299 | for (&result, 0..) |*elem, i| { |
| 300 | elem.index = i; | 300 | elem.index = i; |
| 301 | elem.name = ti.Enum.fields[i].name; | 301 | elem.name = ti.Enum.fields[i].name; |
| 302 | } | 302 | } |
lib/std/target/m68k.zig+1-1| ... | @@ -153,7 +153,7 @@ pub const all_features = blk: { | ... | @@ -153,7 +153,7 @@ pub const all_features = blk: { |
| 153 | .dependencies = featureSet(&[_]Feature{}), | 153 | .dependencies = featureSet(&[_]Feature{}), |
| 154 | }; | 154 | }; |
| 155 | const ti = @typeInfo(Feature); | 155 | const ti = @typeInfo(Feature); |
| 156 | for (result) |*elem, i| { | 156 | for (&result, 0..) |*elem, i| { |
| 157 | elem.index = i; | 157 | elem.index = i; |
| 158 | elem.name = ti.Enum.fields[i].name; | 158 | elem.name = ti.Enum.fields[i].name; |
| 159 | } | 159 | } |
lib/std/target/mips.zig+1-1| ... | @@ -387,7 +387,7 @@ pub const all_features = blk: { | ... | @@ -387,7 +387,7 @@ pub const all_features = blk: { |
| 387 | .dependencies = featureSet(&[_]Feature{}), | 387 | .dependencies = featureSet(&[_]Feature{}), |
| 388 | }; | 388 | }; |
| 389 | const ti = @typeInfo(Feature); | 389 | const ti = @typeInfo(Feature); |
| 390 | for (result) |*elem, i| { | 390 | for (&result, 0..) |*elem, i| { |
| 391 | elem.index = i; | 391 | elem.index = i; |
| 392 | elem.name = ti.Enum.fields[i].name; | 392 | elem.name = ti.Enum.fields[i].name; |
| 393 | } | 393 | } |
lib/std/target/msp430.zig+1-1| ... | @@ -41,7 +41,7 @@ pub const all_features = blk: { | ... | @@ -41,7 +41,7 @@ pub const all_features = blk: { |
| 41 | .dependencies = featureSet(&[_]Feature{}), | 41 | .dependencies = featureSet(&[_]Feature{}), |
| 42 | }; | 42 | }; |
| 43 | const ti = @typeInfo(Feature); | 43 | const ti = @typeInfo(Feature); |
| 44 | for (result) |*elem, i| { | 44 | for (&result, 0..) |*elem, i| { |
| 45 | elem.index = i; | 45 | elem.index = i; |
| 46 | elem.name = ti.Enum.fields[i].name; | 46 | elem.name = ti.Enum.fields[i].name; |
| 47 | } | 47 | } |
lib/std/target/nvptx.zig+1-1| ... | @@ -257,7 +257,7 @@ pub const all_features = blk: { | ... | @@ -257,7 +257,7 @@ pub const all_features = blk: { |
| 257 | .dependencies = featureSet(&[_]Feature{}), | 257 | .dependencies = featureSet(&[_]Feature{}), |
| 258 | }; | 258 | }; |
| 259 | const ti = @typeInfo(Feature); | 259 | const ti = @typeInfo(Feature); |
| 260 | for (result) |*elem, i| { | 260 | for (&result, 0..) |*elem, i| { |
| 261 | elem.index = i; | 261 | elem.index = i; |
| 262 | elem.name = ti.Enum.fields[i].name; | 262 | elem.name = ti.Enum.fields[i].name; |
| 263 | } | 263 | } |
lib/std/target/powerpc.zig+1-1| ... | @@ -598,7 +598,7 @@ pub const all_features = blk: { | ... | @@ -598,7 +598,7 @@ pub const all_features = blk: { |
| 598 | }), | 598 | }), |
| 599 | }; | 599 | }; |
| 600 | const ti = @typeInfo(Feature); | 600 | const ti = @typeInfo(Feature); |
| 601 | for (result) |*elem, i| { | 601 | for (&result, 0..) |*elem, i| { |
| 602 | elem.index = i; | 602 | elem.index = i; |
| 603 | elem.name = ti.Enum.fields[i].name; | 603 | elem.name = ti.Enum.fields[i].name; |
| 604 | } | 604 | } |
lib/std/target/riscv.zig+1-1| ... | @@ -736,7 +736,7 @@ pub const all_features = blk: { | ... | @@ -736,7 +736,7 @@ pub const all_features = blk: { |
| 736 | }), | 736 | }), |
| 737 | }; | 737 | }; |
| 738 | const ti = @typeInfo(Feature); | 738 | const ti = @typeInfo(Feature); |
| 739 | for (result) |*elem, i| { | 739 | for (&result, 0..) |*elem, i| { |
| 740 | elem.index = i; | 740 | elem.index = i; |
| 741 | elem.name = ti.Enum.fields[i].name; | 741 | elem.name = ti.Enum.fields[i].name; |
| 742 | } | 742 | } |
lib/std/target/s390x.zig+1-1| ... | @@ -263,7 +263,7 @@ pub const all_features = blk: { | ... | @@ -263,7 +263,7 @@ pub const all_features = blk: { |
| 263 | .dependencies = featureSet(&[_]Feature{}), | 263 | .dependencies = featureSet(&[_]Feature{}), |
| 264 | }; | 264 | }; |
| 265 | const ti = @typeInfo(Feature); | 265 | const ti = @typeInfo(Feature); |
| 266 | for (result) |*elem, i| { | 266 | for (&result, 0..) |*elem, i| { |
| 267 | elem.index = i; | 267 | elem.index = i; |
| 268 | elem.name = ti.Enum.fields[i].name; | 268 | elem.name = ti.Enum.fields[i].name; |
| 269 | } | 269 | } |
lib/std/target/sparc.zig+1-1| ... | @@ -131,7 +131,7 @@ pub const all_features = blk: { | ... | @@ -131,7 +131,7 @@ pub const all_features = blk: { |
| 131 | .dependencies = featureSet(&[_]Feature{}), | 131 | .dependencies = featureSet(&[_]Feature{}), |
| 132 | }; | 132 | }; |
| 133 | const ti = @typeInfo(Feature); | 133 | const ti = @typeInfo(Feature); |
| 134 | for (result) |*elem, i| { | 134 | for (&result, 0..) |*elem, i| { |
| 135 | elem.index = i; | 135 | elem.index = i; |
| 136 | elem.name = ti.Enum.fields[i].name; | 136 | elem.name = ti.Enum.fields[i].name; |
| 137 | } | 137 | } |
lib/std/target/spirv.zig+1-1| ... | @@ -2075,7 +2075,7 @@ pub const all_features = blk: { | ... | @@ -2075,7 +2075,7 @@ pub const all_features = blk: { |
| 2075 | .dependencies = featureSet(&[_]Feature{}), | 2075 | .dependencies = featureSet(&[_]Feature{}), |
| 2076 | }; | 2076 | }; |
| 2077 | const ti = @typeInfo(Feature); | 2077 | const ti = @typeInfo(Feature); |
| 2078 | for (result) |*elem, i| { | 2078 | for (&result, 0..) |*elem, i| { |
| 2079 | elem.index = i; | 2079 | elem.index = i; |
| 2080 | elem.name = ti.Enum.fields[i].name; | 2080 | elem.name = ti.Enum.fields[i].name; |
| 2081 | } | 2081 | } |
lib/std/target/ve.zig+1-1| ... | @@ -23,7 +23,7 @@ pub const all_features = blk: { | ... | @@ -23,7 +23,7 @@ pub const all_features = blk: { |
| 23 | .dependencies = featureSet(&[_]Feature{}), | 23 | .dependencies = featureSet(&[_]Feature{}), |
| 24 | }; | 24 | }; |
| 25 | const ti = @typeInfo(Feature); | 25 | const ti = @typeInfo(Feature); |
| 26 | for (result) |*elem, i| { | 26 | for (&result, 0..) |*elem, i| { |
| 27 | elem.index = i; | 27 | elem.index = i; |
| 28 | elem.name = ti.Enum.fields[i].name; | 28 | elem.name = ti.Enum.fields[i].name; |
| 29 | } | 29 | } |
lib/std/target/wasm.zig+1-1| ... | @@ -89,7 +89,7 @@ pub const all_features = blk: { | ... | @@ -89,7 +89,7 @@ pub const all_features = blk: { |
| 89 | .dependencies = featureSet(&[_]Feature{}), | 89 | .dependencies = featureSet(&[_]Feature{}), |
| 90 | }; | 90 | }; |
| 91 | const ti = @typeInfo(Feature); | 91 | const ti = @typeInfo(Feature); |
| 92 | for (result) |*elem, i| { | 92 | for (&result, 0..) |*elem, i| { |
| 93 | elem.index = i; | 93 | elem.index = i; |
| 94 | elem.name = ti.Enum.fields[i].name; | 94 | elem.name = ti.Enum.fields[i].name; |
| 95 | } | 95 | } |
lib/std/target/x86.zig+1-1| ... | @@ -1101,7 +1101,7 @@ pub const all_features = blk: { | ... | @@ -1101,7 +1101,7 @@ pub const all_features = blk: { |
| 1101 | }), | 1101 | }), |
| 1102 | }; | 1102 | }; |
| 1103 | const ti = @typeInfo(Feature); | 1103 | const ti = @typeInfo(Feature); |
| 1104 | for (result) |*elem, i| { | 1104 | for (&result, 0..) |*elem, i| { |
| 1105 | elem.index = i; | 1105 | elem.index = i; |
| 1106 | elem.name = ti.Enum.fields[i].name; | 1106 | elem.name = ti.Enum.fields[i].name; |
| 1107 | } | 1107 | } |
lib/std/testing.zig+4-4| ... | @@ -384,7 +384,7 @@ fn SliceDiffer(comptime T: type) type { | ... | @@ -384,7 +384,7 @@ fn SliceDiffer(comptime T: type) type { |
| 384 | const Self = @This(); | 384 | const Self = @This(); |
| 385 | 385 | ||
| 386 | pub fn write(self: Self, writer: anytype) !void { | 386 | pub fn write(self: Self, writer: anytype) !void { |
| 387 | for (self.expected) |value, i| { | 387 | for (self.expected, 0..) |value, i| { |
| 388 | var full_index = self.start_index + i; | 388 | var full_index = self.start_index + i; |
| 389 | const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true; | 389 | const diff = if (i < self.actual.len) !std.meta.eql(self.actual[i], value) else true; |
| 390 | if (diff) try self.ttyconf.setColor(writer, .Red); | 390 | if (diff) try self.ttyconf.setColor(writer, .Red); |
| ... | @@ -405,7 +405,7 @@ const BytesDiffer = struct { | ... | @@ -405,7 +405,7 @@ const BytesDiffer = struct { |
| 405 | while (expected_iterator.next()) |chunk| { | 405 | while (expected_iterator.next()) |chunk| { |
| 406 | // to avoid having to calculate diffs twice per chunk | 406 | // to avoid having to calculate diffs twice per chunk |
| 407 | var diffs: std.bit_set.IntegerBitSet(16) = .{ .mask = 0 }; | 407 | var diffs: std.bit_set.IntegerBitSet(16) = .{ .mask = 0 }; |
| 408 | for (chunk) |byte, i| { | 408 | for (chunk, 0..) |byte, i| { |
| 409 | var absolute_byte_index = (expected_iterator.index - chunk.len) + i; | 409 | var absolute_byte_index = (expected_iterator.index - chunk.len) + i; |
| 410 | const diff = if (absolute_byte_index < self.actual.len) self.actual[absolute_byte_index] != byte else true; | 410 | const diff = if (absolute_byte_index < self.actual.len) self.actual[absolute_byte_index] != byte else true; |
| 411 | if (diff) diffs.set(i); | 411 | if (diff) diffs.set(i); |
| ... | @@ -418,7 +418,7 @@ const BytesDiffer = struct { | ... | @@ -418,7 +418,7 @@ const BytesDiffer = struct { |
| 418 | if (chunk.len < 8) missing_columns += 1; | 418 | if (chunk.len < 8) missing_columns += 1; |
| 419 | try writer.writeByteNTimes(' ', missing_columns); | 419 | try writer.writeByteNTimes(' ', missing_columns); |
| 420 | } | 420 | } |
| 421 | for (chunk) |byte, i| { | 421 | for (chunk, 0..) |byte, i| { |
| 422 | const byte_to_print = if (std.ascii.isPrint(byte)) byte else '.'; | 422 | const byte_to_print = if (std.ascii.isPrint(byte)) byte else '.'; |
| 423 | try self.writeByteDiff(writer, "{c}", byte_to_print, diffs.isSet(i)); | 423 | try self.writeByteDiff(writer, "{c}", byte_to_print, diffs.isSet(i)); |
| 424 | } | 424 | } |
| ... | @@ -1059,7 +1059,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime | ... | @@ -1059,7 +1059,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime |
| 1059 | // Setup the tuple that will actually be used with @call (we'll need to insert | 1059 | // Setup the tuple that will actually be used with @call (we'll need to insert |
| 1060 | // the failing allocator in field @"0" before each @call) | 1060 | // the failing allocator in field @"0" before each @call) |
| 1061 | var args: ArgsTuple = undefined; | 1061 | var args: ArgsTuple = undefined; |
| 1062 | inline for (@typeInfo(@TypeOf(extra_args)).Struct.fields) |field, i| { | 1062 | inline for (@typeInfo(@TypeOf(extra_args)).Struct.fields, 0..) |field, i| { |
| 1063 | const arg_i_str = comptime str: { | 1063 | const arg_i_str = comptime str: { |
| 1064 | var str_buf: [100]u8 = undefined; | 1064 | var str_buf: [100]u8 = undefined; |
| 1065 | const args_i = i + 1; | 1065 | const args_i = i + 1; |
lib/std/wasm.zig+2-2| ... | @@ -636,7 +636,7 @@ pub const Type = struct { | ... | @@ -636,7 +636,7 @@ pub const Type = struct { |
| 636 | if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self); | 636 | if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self); |
| 637 | _ = opt; | 637 | _ = opt; |
| 638 | try writer.writeByte('('); | 638 | try writer.writeByte('('); |
| 639 | for (self.params) |param, i| { | 639 | for (self.params, 0..) |param, i| { |
| 640 | try writer.print("{s}", .{@tagName(param)}); | 640 | try writer.print("{s}", .{@tagName(param)}); |
| 641 | if (i + 1 != self.params.len) { | 641 | if (i + 1 != self.params.len) { |
| 642 | try writer.writeAll(", "); | 642 | try writer.writeAll(", "); |
| ... | @@ -646,7 +646,7 @@ pub const Type = struct { | ... | @@ -646,7 +646,7 @@ pub const Type = struct { |
| 646 | if (self.returns.len == 0) { | 646 | if (self.returns.len == 0) { |
| 647 | try writer.writeAll("nil"); | 647 | try writer.writeAll("nil"); |
| 648 | } else { | 648 | } else { |
| 649 | for (self.returns) |return_ty, i| { | 649 | for (self.returns, 0..) |return_ty, i| { |
| 650 | try writer.print("{s}", .{@tagName(return_ty)}); | 650 | try writer.print("{s}", .{@tagName(return_ty)}); |
| 651 | if (i + 1 != self.returns.len) { | 651 | if (i + 1 != self.returns.len) { |
| 652 | try writer.writeAll(", "); | 652 | try writer.writeAll(", "); |
lib/std/zig/Ast.zig+117-20| ... | @@ -136,7 +136,7 @@ pub fn tokenLocation(self: Ast, start_offset: ByteOffset, token_index: TokenInde | ... | @@ -136,7 +136,7 @@ pub fn tokenLocation(self: Ast, start_offset: ByteOffset, token_index: TokenInde |
| 136 | .line_end = self.source.len, | 136 | .line_end = self.source.len, |
| 137 | }; | 137 | }; |
| 138 | const token_start = self.tokens.items(.start)[token_index]; | 138 | const token_start = self.tokens.items(.start)[token_index]; |
| 139 | for (self.source[start_offset..]) |c, i| { | 139 | for (self.source[start_offset..], 0..) |c, i| { |
| 140 | if (i + start_offset == token_start) { | 140 | if (i + start_offset == token_start) { |
| 141 | loc.line_end = i + start_offset; | 141 | loc.line_end = i + start_offset; |
| 142 | while (loc.line_end < self.source.len and self.source[loc.line_end] != '\n') { | 142 | while (loc.line_end < self.source.len and self.source[loc.line_end] != '\n') { |
| ... | @@ -171,7 +171,7 @@ pub fn tokenSlice(tree: Ast, token_index: TokenIndex) []const u8 { | ... | @@ -171,7 +171,7 @@ pub fn tokenSlice(tree: Ast, token_index: TokenIndex) []const u8 { |
| 171 | .index = token_starts[token_index], | 171 | .index = token_starts[token_index], |
| 172 | .pending_invalid_token = null, | 172 | .pending_invalid_token = null, |
| 173 | }; | 173 | }; |
| 174 | const token = tokenizer.next(); | 174 | const token = tokenizer.findTagAtCurrentIndex(token_tag); |
| 175 | assert(token.tag == token_tag); | 175 | assert(token.tag == token_tag); |
| 176 | return tree.source[token.loc.start..token.loc.end]; | 176 | return tree.source[token.loc.start..token.loc.end]; |
| 177 | } | 177 | } |
| ... | @@ -179,7 +179,7 @@ pub fn tokenSlice(tree: Ast, token_index: TokenIndex) []const u8 { | ... | @@ -179,7 +179,7 @@ pub fn tokenSlice(tree: Ast, token_index: TokenIndex) []const u8 { |
| 179 | pub fn extraData(tree: Ast, index: usize, comptime T: type) T { | 179 | pub fn extraData(tree: Ast, index: usize, comptime T: type) T { |
| 180 | const fields = std.meta.fields(T); | 180 | const fields = std.meta.fields(T); |
| 181 | var result: T = undefined; | 181 | var result: T = undefined; |
| 182 | inline for (fields) |field, i| { | 182 | inline for (fields, 0..) |field, i| { |
| 183 | comptime assert(field.type == Node.Index); | 183 | comptime assert(field.type == Node.Index); |
| 184 | @field(result, field.name) = tree.extra_data[index + i]; | 184 | @field(result, field.name) = tree.extra_data[index + i]; |
| 185 | } | 185 | } |
| ... | @@ -386,6 +386,12 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { | ... | @@ -386,6 +386,12 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { |
| 386 | .expected_comma_after_switch_prong => { | 386 | .expected_comma_after_switch_prong => { |
| 387 | return stream.writeAll("expected ',' after switch prong"); | 387 | return stream.writeAll("expected ',' after switch prong"); |
| 388 | }, | 388 | }, |
| 389 | .expected_comma_after_for_operand => { | ||
| 390 | return stream.writeAll("expected ',' after for operand"); | ||
| 391 | }, | ||
| 392 | .expected_comma_after_capture => { | ||
| 393 | return stream.writeAll("expected ',' after for capture"); | ||
| 394 | }, | ||
| 389 | .expected_initializer => { | 395 | .expected_initializer => { |
| 390 | return stream.writeAll("expected field initializer"); | 396 | return stream.writeAll("expected field initializer"); |
| 391 | }, | 397 | }, |
| ... | @@ -420,6 +426,12 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { | ... | @@ -420,6 +426,12 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { |
| 420 | .var_const_decl => { | 426 | .var_const_decl => { |
| 421 | return stream.writeAll("use 'var' or 'const' to declare variable"); | 427 | return stream.writeAll("use 'var' or 'const' to declare variable"); |
| 422 | }, | 428 | }, |
| 429 | .extra_for_capture => { | ||
| 430 | return stream.writeAll("excess for captures"); | ||
| 431 | }, | ||
| 432 | .for_input_not_captured => { | ||
| 433 | return stream.writeAll("for input is not captured"); | ||
| 434 | }, | ||
| 423 | 435 | ||
| 424 | .expected_token => { | 436 | .expected_token => { |
| 425 | const found_tag = token_tags[parse_error.token + @boolToInt(parse_error.token_is_prev)]; | 437 | const found_tag = token_tags[parse_error.token + @boolToInt(parse_error.token_is_prev)]; |
| ... | @@ -568,6 +580,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -568,6 +580,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 568 | .call, | 580 | .call, |
| 569 | .call_comma, | 581 | .call_comma, |
| 570 | .switch_range, | 582 | .switch_range, |
| 583 | .for_range, | ||
| 571 | .error_union, | 584 | .error_union, |
| 572 | => n = datas[n].lhs, | 585 | => n = datas[n].lhs, |
| 573 | 586 | ||
| ... | @@ -845,6 +858,12 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -845,6 +858,12 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 845 | .switch_range, | 858 | .switch_range, |
| 846 | => n = datas[n].rhs, | 859 | => n = datas[n].rhs, |
| 847 | 860 | ||
| 861 | .for_range => if (datas[n].rhs != 0) { | ||
| 862 | n = datas[n].rhs; | ||
| 863 | } else { | ||
| 864 | return main_tokens[n] + end_offset; | ||
| 865 | }, | ||
| 866 | |||
| 848 | .field_access, | 867 | .field_access, |
| 849 | .unwrap_optional, | 868 | .unwrap_optional, |
| 850 | .grouped_expression, | 869 | .grouped_expression, |
| ... | @@ -1263,11 +1282,15 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -1263,11 +1282,15 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 1263 | assert(extra.else_expr != 0); | 1282 | assert(extra.else_expr != 0); |
| 1264 | n = extra.else_expr; | 1283 | n = extra.else_expr; |
| 1265 | }, | 1284 | }, |
| 1266 | .@"if", .@"for" => { | 1285 | .@"if" => { |
| 1267 | const extra = tree.extraData(datas[n].rhs, Node.If); | 1286 | const extra = tree.extraData(datas[n].rhs, Node.If); |
| 1268 | assert(extra.else_expr != 0); | 1287 | assert(extra.else_expr != 0); |
| 1269 | n = extra.else_expr; | 1288 | n = extra.else_expr; |
| 1270 | }, | 1289 | }, |
| 1290 | .@"for" => { | ||
| 1291 | const extra = @bitCast(Node.For, datas[n].rhs); | ||
| 1292 | n = tree.extra_data[datas[n].lhs + extra.inputs + @boolToInt(extra.has_else)]; | ||
| 1293 | }, | ||
| 1271 | .@"suspend" => { | 1294 | .@"suspend" => { |
| 1272 | if (datas[n].lhs != 0) { | 1295 | if (datas[n].lhs != 0) { |
| 1273 | n = datas[n].lhs; | 1296 | n = datas[n].lhs; |
| ... | @@ -1916,26 +1939,28 @@ pub fn whileFull(tree: Ast, node: Node.Index) full.While { | ... | @@ -1916,26 +1939,28 @@ pub fn whileFull(tree: Ast, node: Node.Index) full.While { |
| 1916 | }); | 1939 | }); |
| 1917 | } | 1940 | } |
| 1918 | 1941 | ||
| 1919 | pub fn forSimple(tree: Ast, node: Node.Index) full.While { | 1942 | pub fn forSimple(tree: Ast, node: Node.Index) full.For { |
| 1920 | const data = tree.nodes.items(.data)[node]; | 1943 | const data = &tree.nodes.items(.data)[node]; |
| 1921 | return tree.fullWhileComponents(.{ | 1944 | const inputs: *[1]Node.Index = &data.lhs; |
| 1922 | .while_token = tree.nodes.items(.main_token)[node], | 1945 | return tree.fullForComponents(.{ |
| 1923 | .cond_expr = data.lhs, | 1946 | .for_token = tree.nodes.items(.main_token)[node], |
| 1924 | .cont_expr = 0, | 1947 | .inputs = inputs[0..1], |
| 1925 | .then_expr = data.rhs, | 1948 | .then_expr = data.rhs, |
| 1926 | .else_expr = 0, | 1949 | .else_expr = 0, |
| 1927 | }); | 1950 | }); |
| 1928 | } | 1951 | } |
| 1929 | 1952 | ||
| 1930 | pub fn forFull(tree: Ast, node: Node.Index) full.While { | 1953 | pub fn forFull(tree: Ast, node: Node.Index) full.For { |
| 1931 | const data = tree.nodes.items(.data)[node]; | 1954 | const data = tree.nodes.items(.data)[node]; |
| 1932 | const extra = tree.extraData(data.rhs, Node.If); | 1955 | const extra = @bitCast(Node.For, data.rhs); |
| 1933 | return tree.fullWhileComponents(.{ | 1956 | const inputs = tree.extra_data[data.lhs..][0..extra.inputs]; |
| 1934 | .while_token = tree.nodes.items(.main_token)[node], | 1957 | const then_expr = tree.extra_data[data.lhs + extra.inputs]; |
| 1935 | .cond_expr = data.lhs, | 1958 | const else_expr = if (extra.has_else) tree.extra_data[data.lhs + extra.inputs + 1] else 0; |
| 1936 | .cont_expr = 0, | 1959 | return tree.fullForComponents(.{ |
| 1937 | .then_expr = extra.then_expr, | 1960 | .for_token = tree.nodes.items(.main_token)[node], |
| 1938 | .else_expr = extra.else_expr, | 1961 | .inputs = inputs, |
| 1962 | .then_expr = then_expr, | ||
| 1963 | .else_expr = else_expr, | ||
| 1939 | }); | 1964 | }); |
| 1940 | } | 1965 | } |
| 1941 | 1966 | ||
| ... | @@ -2158,7 +2183,7 @@ fn fullAsmComponents(tree: Ast, info: full.Asm.Components) full.Asm { | ... | @@ -2158,7 +2183,7 @@ fn fullAsmComponents(tree: Ast, info: full.Asm.Components) full.Asm { |
| 2158 | if (token_tags[info.asm_token + 1] == .keyword_volatile) { | 2183 | if (token_tags[info.asm_token + 1] == .keyword_volatile) { |
| 2159 | result.volatile_token = info.asm_token + 1; | 2184 | result.volatile_token = info.asm_token + 1; |
| 2160 | } | 2185 | } |
| 2161 | const outputs_end: usize = for (info.items) |item, i| { | 2186 | const outputs_end: usize = for (info.items, 0..) |item, i| { |
| 2162 | switch (node_tags[item]) { | 2187 | switch (node_tags[item]) { |
| 2163 | .asm_output => continue, | 2188 | .asm_output => continue, |
| 2164 | else => break i, | 2189 | else => break i, |
| ... | @@ -2243,6 +2268,33 @@ fn fullWhileComponents(tree: Ast, info: full.While.Components) full.While { | ... | @@ -2243,6 +2268,33 @@ fn fullWhileComponents(tree: Ast, info: full.While.Components) full.While { |
| 2243 | return result; | 2268 | return result; |
| 2244 | } | 2269 | } |
| 2245 | 2270 | ||
| 2271 | fn fullForComponents(tree: Ast, info: full.For.Components) full.For { | ||
| 2272 | const token_tags = tree.tokens.items(.tag); | ||
| 2273 | var result: full.For = .{ | ||
| 2274 | .ast = info, | ||
| 2275 | .inline_token = null, | ||
| 2276 | .label_token = null, | ||
| 2277 | .payload_token = undefined, | ||
| 2278 | .else_token = undefined, | ||
| 2279 | }; | ||
| 2280 | var tok_i = info.for_token - 1; | ||
| 2281 | if (token_tags[tok_i] == .keyword_inline) { | ||
| 2282 | result.inline_token = tok_i; | ||
| 2283 | tok_i -= 1; | ||
| 2284 | } | ||
| 2285 | if (token_tags[tok_i] == .colon and | ||
| 2286 | token_tags[tok_i - 1] == .identifier) | ||
| 2287 | { | ||
| 2288 | result.label_token = tok_i - 1; | ||
| 2289 | } | ||
| 2290 | const last_cond_token = tree.lastToken(info.inputs[info.inputs.len - 1]); | ||
| 2291 | result.payload_token = last_cond_token + 3 + @boolToInt(token_tags[last_cond_token + 1] == .comma); | ||
| 2292 | if (info.else_expr != 0) { | ||
| 2293 | result.else_token = tree.lastToken(info.then_expr) + 1; | ||
| 2294 | } | ||
| 2295 | return result; | ||
| 2296 | } | ||
| 2297 | |||
| 2246 | fn fullCallComponents(tree: Ast, info: full.Call.Components) full.Call { | 2298 | fn fullCallComponents(tree: Ast, info: full.Call.Components) full.Call { |
| 2247 | const token_tags = tree.tokens.items(.tag); | 2299 | const token_tags = tree.tokens.items(.tag); |
| 2248 | var result: full.Call = .{ | 2300 | var result: full.Call = .{ |
| ... | @@ -2279,6 +2331,12 @@ pub fn fullWhile(tree: Ast, node: Node.Index) ?full.While { | ... | @@ -2279,6 +2331,12 @@ pub fn fullWhile(tree: Ast, node: Node.Index) ?full.While { |
| 2279 | .while_simple => tree.whileSimple(node), | 2331 | .while_simple => tree.whileSimple(node), |
| 2280 | .while_cont => tree.whileCont(node), | 2332 | .while_cont => tree.whileCont(node), |
| 2281 | .@"while" => tree.whileFull(node), | 2333 | .@"while" => tree.whileFull(node), |
| 2334 | else => null, | ||
| 2335 | }; | ||
| 2336 | } | ||
| 2337 | |||
| 2338 | pub fn fullFor(tree: Ast, node: Node.Index) ?full.For { | ||
| 2339 | return switch (tree.nodes.items(.tag)[node]) { | ||
| 2282 | .for_simple => tree.forSimple(node), | 2340 | .for_simple => tree.forSimple(node), |
| 2283 | .@"for" => tree.forFull(node), | 2341 | .@"for" => tree.forFull(node), |
| 2284 | else => null, | 2342 | else => null, |
| ... | @@ -2453,6 +2511,34 @@ pub const full = struct { | ... | @@ -2453,6 +2511,34 @@ pub const full = struct { |
| 2453 | }; | 2511 | }; |
| 2454 | }; | 2512 | }; |
| 2455 | 2513 | ||
| 2514 | pub const For = struct { | ||
| 2515 | ast: Components, | ||
| 2516 | inline_token: ?TokenIndex, | ||
| 2517 | label_token: ?TokenIndex, | ||
| 2518 | payload_token: TokenIndex, | ||
| 2519 | /// Populated only if else_expr != 0. | ||
| 2520 | else_token: TokenIndex, | ||
| 2521 | |||
| 2522 | pub const Components = struct { | ||
| 2523 | for_token: TokenIndex, | ||
| 2524 | inputs: []const Node.Index, | ||
| 2525 | then_expr: Node.Index, | ||
| 2526 | else_expr: Node.Index, | ||
| 2527 | }; | ||
| 2528 | |||
| 2529 | /// TODO: remove this after zig 0.11.0 is tagged. | ||
| 2530 | pub fn isOldSyntax(f: For, token_tags: []const Token.Tag) bool { | ||
| 2531 | if (f.ast.inputs.len != 1) return false; | ||
| 2532 | if (token_tags[f.payload_token + 1] == .comma) return true; | ||
| 2533 | if (token_tags[f.payload_token] == .asterisk and | ||
| 2534 | token_tags[f.payload_token + 2] == .comma) | ||
| 2535 | { | ||
| 2536 | return true; | ||
| 2537 | } | ||
| 2538 | return false; | ||
| 2539 | } | ||
| 2540 | }; | ||
| 2541 | |||
| 2456 | pub const ContainerField = struct { | 2542 | pub const ContainerField = struct { |
| 2457 | comptime_token: ?TokenIndex, | 2543 | comptime_token: ?TokenIndex, |
| 2458 | ast: Components, | 2544 | ast: Components, |
| ... | @@ -2795,6 +2881,8 @@ pub const Error = struct { | ... | @@ -2795,6 +2881,8 @@ pub const Error = struct { |
| 2795 | expected_comma_after_param, | 2881 | expected_comma_after_param, |
| 2796 | expected_comma_after_initializer, | 2882 | expected_comma_after_initializer, |
| 2797 | expected_comma_after_switch_prong, | 2883 | expected_comma_after_switch_prong, |
| 2884 | expected_comma_after_for_operand, | ||
| 2885 | expected_comma_after_capture, | ||
| 2798 | expected_initializer, | 2886 | expected_initializer, |
| 2799 | mismatched_binary_op_whitespace, | 2887 | mismatched_binary_op_whitespace, |
| 2800 | invalid_ampersand_ampersand, | 2888 | invalid_ampersand_ampersand, |
| ... | @@ -2802,6 +2890,8 @@ pub const Error = struct { | ... | @@ -2802,6 +2890,8 @@ pub const Error = struct { |
| 2802 | expected_var_const, | 2890 | expected_var_const, |
| 2803 | wrong_equal_var_decl, | 2891 | wrong_equal_var_decl, |
| 2804 | var_const_decl, | 2892 | var_const_decl, |
| 2893 | extra_for_capture, | ||
| 2894 | for_input_not_captured, | ||
| 2805 | 2895 | ||
| 2806 | zig_style_container, | 2896 | zig_style_container, |
| 2807 | previous_field, | 2897 | previous_field, |
| ... | @@ -3112,8 +3202,10 @@ pub const Node = struct { | ... | @@ -3112,8 +3202,10 @@ pub const Node = struct { |
| 3112 | @"while", | 3202 | @"while", |
| 3113 | /// `for (lhs) rhs`. | 3203 | /// `for (lhs) rhs`. |
| 3114 | for_simple, | 3204 | for_simple, |
| 3115 | /// `for (lhs) a else b`. `if_list[rhs]`. | 3205 | /// `for (lhs[0..inputs]) lhs[inputs + 1] else lhs[inputs + 2]`. `For[rhs]`. |
| 3116 | @"for", | 3206 | @"for", |
| 3207 | /// `lhs..rhs`. | ||
| 3208 | for_range, | ||
| 3117 | /// `if (lhs) rhs`. | 3209 | /// `if (lhs) rhs`. |
| 3118 | /// `if (lhs) |a| rhs`. | 3210 | /// `if (lhs) |a| rhs`. |
| 3119 | if_simple, | 3211 | if_simple, |
| ... | @@ -3369,6 +3461,11 @@ pub const Node = struct { | ... | @@ -3369,6 +3461,11 @@ pub const Node = struct { |
| 3369 | then_expr: Index, | 3461 | then_expr: Index, |
| 3370 | }; | 3462 | }; |
| 3371 | 3463 | ||
| 3464 | pub const For = packed struct(u32) { | ||
| 3465 | inputs: u31, | ||
| 3466 | has_else: bool, | ||
| 3467 | }; | ||
| 3468 | |||
| 3372 | pub const FnProtoOne = struct { | 3469 | pub const FnProtoOne = struct { |
| 3373 | /// Populated if there is exactly 1 parameter. Otherwise there are 0 parameters. | 3470 | /// Populated if there is exactly 1 parameter. Otherwise there are 0 parameters. |
| 3374 | param: Index, | 3471 | param: Index, |
lib/std/zig/CrossTarget.zig+1-1| ... | @@ -317,7 +317,7 @@ pub fn parse(args: ParseOptions) !CrossTarget { | ... | @@ -317,7 +317,7 @@ pub fn parse(args: ParseOptions) !CrossTarget { |
| 317 | index += 1; | 317 | index += 1; |
| 318 | } | 318 | } |
| 319 | const feature_name = cpu_features[start..index]; | 319 | const feature_name = cpu_features[start..index]; |
| 320 | for (all_features) |feature, feat_index_usize| { | 320 | for (all_features, 0..) |feature, feat_index_usize| { |
| 321 | const feat_index = @intCast(Target.Cpu.Feature.Set.Index, feat_index_usize); | 321 | const feat_index = @intCast(Target.Cpu.Feature.Set.Index, feat_index_usize); |
| 322 | if (mem.eql(u8, feature_name, feature.name)) { | 322 | if (mem.eql(u8, feature_name, feature.name)) { |
| 323 | set.addFeature(feat_index); | 323 | set.addFeature(feat_index); |
lib/std/zig/Parse.zig+139-57| ... | @@ -104,6 +104,8 @@ fn warnMsg(p: *Parse, msg: Ast.Error) error{OutOfMemory}!void { | ... | @@ -104,6 +104,8 @@ fn warnMsg(p: *Parse, msg: Ast.Error) error{OutOfMemory}!void { |
| 104 | .expected_comma_after_param, | 104 | .expected_comma_after_param, |
| 105 | .expected_comma_after_initializer, | 105 | .expected_comma_after_initializer, |
| 106 | .expected_comma_after_switch_prong, | 106 | .expected_comma_after_switch_prong, |
| 107 | .expected_comma_after_for_operand, | ||
| 108 | .expected_comma_after_capture, | ||
| 107 | .expected_semi_or_else, | 109 | .expected_semi_or_else, |
| 108 | .expected_semi_or_lbrace, | 110 | .expected_semi_or_lbrace, |
| 109 | .expected_token, | 111 | .expected_token, |
| ... | @@ -1149,22 +1151,18 @@ fn parseLoopStatement(p: *Parse) !Node.Index { | ... | @@ -1149,22 +1151,18 @@ fn parseLoopStatement(p: *Parse) !Node.Index { |
| 1149 | return p.fail(.expected_inlinable); | 1151 | return p.fail(.expected_inlinable); |
| 1150 | } | 1152 | } |
| 1151 | 1153 | ||
| 1152 | /// ForPrefix <- KEYWORD_for LPAREN Expr RPAREN PtrIndexPayload | ||
| 1153 | /// | ||
| 1154 | /// ForStatement | 1154 | /// ForStatement |
| 1155 | /// <- ForPrefix BlockExpr ( KEYWORD_else Statement )? | 1155 | /// <- ForPrefix BlockExpr ( KEYWORD_else Statement )? |
| 1156 | /// / ForPrefix AssignExpr ( SEMICOLON / KEYWORD_else Statement ) | 1156 | /// / ForPrefix AssignExpr ( SEMICOLON / KEYWORD_else Statement ) |
| 1157 | fn parseForStatement(p: *Parse) !Node.Index { | 1157 | fn parseForStatement(p: *Parse) !Node.Index { |
| 1158 | const for_token = p.eatToken(.keyword_for) orelse return null_node; | 1158 | const for_token = p.eatToken(.keyword_for) orelse return null_node; |
| 1159 | _ = try p.expectToken(.l_paren); | ||
| 1160 | const array_expr = try p.expectExpr(); | ||
| 1161 | _ = try p.expectToken(.r_paren); | ||
| 1162 | const found_payload = try p.parsePtrIndexPayload(); | ||
| 1163 | if (found_payload == 0) try p.warn(.expected_loop_payload); | ||
| 1164 | 1159 | ||
| 1165 | // TODO propose to change the syntax so that semicolons are always required | 1160 | const scratch_top = p.scratch.items.len; |
| 1166 | // inside while statements, even if there is an `else`. | 1161 | defer p.scratch.shrinkRetainingCapacity(scratch_top); |
| 1162 | const inputs = try p.forPrefix(); | ||
| 1163 | |||
| 1167 | var else_required = false; | 1164 | var else_required = false; |
| 1165 | var seen_semicolon = false; | ||
| 1168 | const then_expr = blk: { | 1166 | const then_expr = blk: { |
| 1169 | const block_expr = try p.parseBlockExpr(); | 1167 | const block_expr = try p.parseBlockExpr(); |
| 1170 | if (block_expr != 0) break :blk block_expr; | 1168 | if (block_expr != 0) break :blk block_expr; |
| ... | @@ -1173,39 +1171,40 @@ fn parseForStatement(p: *Parse) !Node.Index { | ... | @@ -1173,39 +1171,40 @@ fn parseForStatement(p: *Parse) !Node.Index { |
| 1173 | return p.fail(.expected_block_or_assignment); | 1171 | return p.fail(.expected_block_or_assignment); |
| 1174 | } | 1172 | } |
| 1175 | if (p.eatToken(.semicolon)) |_| { | 1173 | if (p.eatToken(.semicolon)) |_| { |
| 1176 | return p.addNode(.{ | 1174 | seen_semicolon = true; |
| 1177 | .tag = .for_simple, | 1175 | break :blk assign_expr; |
| 1178 | .main_token = for_token, | ||
| 1179 | .data = .{ | ||
| 1180 | .lhs = array_expr, | ||
| 1181 | .rhs = assign_expr, | ||
| 1182 | }, | ||
| 1183 | }); | ||
| 1184 | } | 1176 | } |
| 1185 | else_required = true; | 1177 | else_required = true; |
| 1186 | break :blk assign_expr; | 1178 | break :blk assign_expr; |
| 1187 | }; | 1179 | }; |
| 1188 | _ = p.eatToken(.keyword_else) orelse { | 1180 | var has_else = false; |
| 1189 | if (else_required) { | 1181 | if (!seen_semicolon and p.eatToken(.keyword_else) != null) { |
| 1190 | try p.warn(.expected_semi_or_else); | 1182 | try p.scratch.append(p.gpa, then_expr); |
| 1191 | } | 1183 | const else_stmt = try p.expectStatement(false); |
| 1184 | try p.scratch.append(p.gpa, else_stmt); | ||
| 1185 | has_else = true; | ||
| 1186 | } else if (inputs == 1) { | ||
| 1187 | if (else_required) try p.warn(.expected_semi_or_else); | ||
| 1192 | return p.addNode(.{ | 1188 | return p.addNode(.{ |
| 1193 | .tag = .for_simple, | 1189 | .tag = .for_simple, |
| 1194 | .main_token = for_token, | 1190 | .main_token = for_token, |
| 1195 | .data = .{ | 1191 | .data = .{ |
| 1196 | .lhs = array_expr, | 1192 | .lhs = p.scratch.items[scratch_top], |
| 1197 | .rhs = then_expr, | 1193 | .rhs = then_expr, |
| 1198 | }, | 1194 | }, |
| 1199 | }); | 1195 | }); |
| 1200 | }; | 1196 | } else { |
| 1197 | if (else_required) try p.warn(.expected_semi_or_else); | ||
| 1198 | try p.scratch.append(p.gpa, then_expr); | ||
| 1199 | } | ||
| 1201 | return p.addNode(.{ | 1200 | return p.addNode(.{ |
| 1202 | .tag = .@"for", | 1201 | .tag = .@"for", |
| 1203 | .main_token = for_token, | 1202 | .main_token = for_token, |
| 1204 | .data = .{ | 1203 | .data = .{ |
| 1205 | .lhs = array_expr, | 1204 | .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start, |
| 1206 | .rhs = try p.addExtra(Node.If{ | 1205 | .rhs = @bitCast(u32, Node.For{ |
| 1207 | .then_expr = then_expr, | 1206 | .inputs = @intCast(u31, inputs), |
| 1208 | .else_expr = try p.expectStatement(false), | 1207 | .has_else = has_else, |
| 1209 | }), | 1208 | }), |
| 1210 | }, | 1209 | }, |
| 1211 | }); | 1210 | }); |
| ... | @@ -2056,42 +2055,121 @@ fn parseBlock(p: *Parse) !Node.Index { | ... | @@ -2056,42 +2055,121 @@ fn parseBlock(p: *Parse) !Node.Index { |
| 2056 | } | 2055 | } |
| 2057 | } | 2056 | } |
| 2058 | 2057 | ||
| 2059 | /// ForPrefix <- KEYWORD_for LPAREN Expr RPAREN PtrIndexPayload | ||
| 2060 | /// | ||
| 2061 | /// ForExpr <- ForPrefix Expr (KEYWORD_else Expr)? | 2058 | /// ForExpr <- ForPrefix Expr (KEYWORD_else Expr)? |
| 2062 | fn parseForExpr(p: *Parse) !Node.Index { | 2059 | fn parseForExpr(p: *Parse) !Node.Index { |
| 2063 | const for_token = p.eatToken(.keyword_for) orelse return null_node; | 2060 | const for_token = p.eatToken(.keyword_for) orelse return null_node; |
| 2064 | _ = try p.expectToken(.l_paren); | 2061 | |
| 2065 | const array_expr = try p.expectExpr(); | 2062 | const scratch_top = p.scratch.items.len; |
| 2066 | _ = try p.expectToken(.r_paren); | 2063 | defer p.scratch.shrinkRetainingCapacity(scratch_top); |
| 2067 | const found_payload = try p.parsePtrIndexPayload(); | 2064 | const inputs = try p.forPrefix(); |
| 2068 | if (found_payload == 0) try p.warn(.expected_loop_payload); | ||
| 2069 | 2065 | ||
| 2070 | const then_expr = try p.expectExpr(); | 2066 | const then_expr = try p.expectExpr(); |
| 2071 | _ = p.eatToken(.keyword_else) orelse { | 2067 | var has_else = false; |
| 2068 | if (p.eatToken(.keyword_else)) |_| { | ||
| 2069 | try p.scratch.append(p.gpa, then_expr); | ||
| 2070 | const else_expr = try p.expectExpr(); | ||
| 2071 | try p.scratch.append(p.gpa, else_expr); | ||
| 2072 | has_else = true; | ||
| 2073 | } else if (inputs == 1) { | ||
| 2072 | return p.addNode(.{ | 2074 | return p.addNode(.{ |
| 2073 | .tag = .for_simple, | 2075 | .tag = .for_simple, |
| 2074 | .main_token = for_token, | 2076 | .main_token = for_token, |
| 2075 | .data = .{ | 2077 | .data = .{ |
| 2076 | .lhs = array_expr, | 2078 | .lhs = p.scratch.items[scratch_top], |
| 2077 | .rhs = then_expr, | 2079 | .rhs = then_expr, |
| 2078 | }, | 2080 | }, |
| 2079 | }); | 2081 | }); |
| 2080 | }; | 2082 | } else { |
| 2081 | const else_expr = try p.expectExpr(); | 2083 | try p.scratch.append(p.gpa, then_expr); |
| 2084 | } | ||
| 2082 | return p.addNode(.{ | 2085 | return p.addNode(.{ |
| 2083 | .tag = .@"for", | 2086 | .tag = .@"for", |
| 2084 | .main_token = for_token, | 2087 | .main_token = for_token, |
| 2085 | .data = .{ | 2088 | .data = .{ |
| 2086 | .lhs = array_expr, | 2089 | .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start, |
| 2087 | .rhs = try p.addExtra(Node.If{ | 2090 | .rhs = @bitCast(u32, Node.For{ |
| 2088 | .then_expr = then_expr, | 2091 | .inputs = @intCast(u31, inputs), |
| 2089 | .else_expr = else_expr, | 2092 | .has_else = has_else, |
| 2090 | }), | 2093 | }), |
| 2091 | }, | 2094 | }, |
| 2092 | }); | 2095 | }); |
| 2093 | } | 2096 | } |
| 2094 | 2097 | ||
| 2098 | /// ForPrefix <- KEYWORD_for LPAREN ForInput (COMMA ForInput)* COMMA? RPAREN ForPayload | ||
| 2099 | /// | ||
| 2100 | /// ForInput <- Expr (DOT2 Expr?)? | ||
| 2101 | /// | ||
| 2102 | /// ForPayload <- PIPE ASTERISK? IDENTIFIER (COMMA ASTERISK? IDENTIFIER)* PIPE | ||
| 2103 | fn forPrefix(p: *Parse) Error!usize { | ||
| 2104 | const start = p.scratch.items.len; | ||
| 2105 | _ = try p.expectToken(.l_paren); | ||
| 2106 | |||
| 2107 | while (true) { | ||
| 2108 | var input = try p.expectExpr(); | ||
| 2109 | if (p.eatToken(.ellipsis2)) |ellipsis| { | ||
| 2110 | input = try p.addNode(.{ | ||
| 2111 | .tag = .for_range, | ||
| 2112 | .main_token = ellipsis, | ||
| 2113 | .data = .{ | ||
| 2114 | .lhs = input, | ||
| 2115 | .rhs = try p.parseExpr(), | ||
| 2116 | }, | ||
| 2117 | }); | ||
| 2118 | } | ||
| 2119 | |||
| 2120 | try p.scratch.append(p.gpa, input); | ||
| 2121 | switch (p.token_tags[p.tok_i]) { | ||
| 2122 | .comma => p.tok_i += 1, | ||
| 2123 | .r_paren => { | ||
| 2124 | p.tok_i += 1; | ||
| 2125 | break; | ||
| 2126 | }, | ||
| 2127 | .colon, .r_brace, .r_bracket => return p.failExpected(.r_paren), | ||
| 2128 | // Likely just a missing comma; give error but continue parsing. | ||
| 2129 | else => try p.warn(.expected_comma_after_for_operand), | ||
| 2130 | } | ||
| 2131 | if (p.eatToken(.r_paren)) |_| break; | ||
| 2132 | } | ||
| 2133 | const inputs = p.scratch.items.len - start; | ||
| 2134 | |||
| 2135 | _ = p.eatToken(.pipe) orelse { | ||
| 2136 | try p.warn(.expected_loop_payload); | ||
| 2137 | return inputs; | ||
| 2138 | }; | ||
| 2139 | |||
| 2140 | var warned_excess = false; | ||
| 2141 | var captures: u32 = 0; | ||
| 2142 | while (true) { | ||
| 2143 | _ = p.eatToken(.asterisk); | ||
| 2144 | const identifier = try p.expectToken(.identifier); | ||
| 2145 | captures += 1; | ||
| 2146 | if (!warned_excess and inputs == 1 and captures == 2) { | ||
| 2147 | // TODO remove the above condition after 0.11.0 release. this silences | ||
| 2148 | // the error so that zig fmt can fix it. | ||
| 2149 | } else if (captures > inputs and !warned_excess) { | ||
| 2150 | try p.warnMsg(.{ .tag = .extra_for_capture, .token = identifier }); | ||
| 2151 | warned_excess = true; | ||
| 2152 | } | ||
| 2153 | switch (p.token_tags[p.tok_i]) { | ||
| 2154 | .comma => p.tok_i += 1, | ||
| 2155 | .pipe => { | ||
| 2156 | p.tok_i += 1; | ||
| 2157 | break; | ||
| 2158 | }, | ||
| 2159 | // Likely just a missing comma; give error but continue parsing. | ||
| 2160 | else => try p.warn(.expected_comma_after_capture), | ||
| 2161 | } | ||
| 2162 | if (p.eatToken(.pipe)) |_| break; | ||
| 2163 | } | ||
| 2164 | |||
| 2165 | if (captures < inputs) { | ||
| 2166 | const index = p.scratch.items.len - captures; | ||
| 2167 | const input = p.nodes.items(.main_token)[p.scratch.items[index]]; | ||
| 2168 | try p.warnMsg(.{ .tag = .for_input_not_captured, .token = input }); | ||
| 2169 | } | ||
| 2170 | return inputs; | ||
| 2171 | } | ||
| 2172 | |||
| 2095 | /// WhilePrefix <- KEYWORD_while LPAREN Expr RPAREN PtrPayload? WhileContinueExpr? | 2173 | /// WhilePrefix <- KEYWORD_while LPAREN Expr RPAREN PtrPayload? WhileContinueExpr? |
| 2096 | /// | 2174 | /// |
| 2097 | /// WhileExpr <- WhilePrefix Expr (KEYWORD_else Payload? Expr)? | 2175 | /// WhileExpr <- WhilePrefix Expr (KEYWORD_else Payload? Expr)? |
| ... | @@ -2752,37 +2830,41 @@ fn expectPrimaryTypeExpr(p: *Parse) !Node.Index { | ... | @@ -2752,37 +2830,41 @@ fn expectPrimaryTypeExpr(p: *Parse) !Node.Index { |
| 2752 | return node; | 2830 | return node; |
| 2753 | } | 2831 | } |
| 2754 | 2832 | ||
| 2755 | /// ForPrefix <- KEYWORD_for LPAREN Expr RPAREN PtrIndexPayload | ||
| 2756 | /// | ||
| 2757 | /// ForTypeExpr <- ForPrefix TypeExpr (KEYWORD_else TypeExpr)? | 2833 | /// ForTypeExpr <- ForPrefix TypeExpr (KEYWORD_else TypeExpr)? |
| 2758 | fn parseForTypeExpr(p: *Parse) !Node.Index { | 2834 | fn parseForTypeExpr(p: *Parse) !Node.Index { |
| 2759 | const for_token = p.eatToken(.keyword_for) orelse return null_node; | 2835 | const for_token = p.eatToken(.keyword_for) orelse return null_node; |
| 2760 | _ = try p.expectToken(.l_paren); | 2836 | |
| 2761 | const array_expr = try p.expectExpr(); | 2837 | const scratch_top = p.scratch.items.len; |
| 2762 | _ = try p.expectToken(.r_paren); | 2838 | defer p.scratch.shrinkRetainingCapacity(scratch_top); |
| 2763 | const found_payload = try p.parsePtrIndexPayload(); | 2839 | const inputs = try p.forPrefix(); |
| 2764 | if (found_payload == 0) try p.warn(.expected_loop_payload); | ||
| 2765 | 2840 | ||
| 2766 | const then_expr = try p.expectTypeExpr(); | 2841 | const then_expr = try p.expectTypeExpr(); |
| 2767 | _ = p.eatToken(.keyword_else) orelse { | 2842 | var has_else = false; |
| 2843 | if (p.eatToken(.keyword_else)) |_| { | ||
| 2844 | try p.scratch.append(p.gpa, then_expr); | ||
| 2845 | const else_expr = try p.expectTypeExpr(); | ||
| 2846 | try p.scratch.append(p.gpa, else_expr); | ||
| 2847 | has_else = true; | ||
| 2848 | } else if (inputs == 1) { | ||
| 2768 | return p.addNode(.{ | 2849 | return p.addNode(.{ |
| 2769 | .tag = .for_simple, | 2850 | .tag = .for_simple, |
| 2770 | .main_token = for_token, | 2851 | .main_token = for_token, |
| 2771 | .data = .{ | 2852 | .data = .{ |
| 2772 | .lhs = array_expr, | 2853 | .lhs = p.scratch.items[scratch_top], |
| 2773 | .rhs = then_expr, | 2854 | .rhs = then_expr, |
| 2774 | }, | 2855 | }, |
| 2775 | }); | 2856 | }); |
| 2776 | }; | 2857 | } else { |
| 2777 | const else_expr = try p.expectTypeExpr(); | 2858 | try p.scratch.append(p.gpa, then_expr); |
| 2859 | } | ||
| 2778 | return p.addNode(.{ | 2860 | return p.addNode(.{ |
| 2779 | .tag = .@"for", | 2861 | .tag = .@"for", |
| 2780 | .main_token = for_token, | 2862 | .main_token = for_token, |
| 2781 | .data = .{ | 2863 | .data = .{ |
| 2782 | .lhs = array_expr, | 2864 | .lhs = (try p.listToSpan(p.scratch.items[scratch_top..])).start, |
| 2783 | .rhs = try p.addExtra(Node.If{ | 2865 | .rhs = @bitCast(u32, Node.For{ |
| 2784 | .then_expr = then_expr, | 2866 | .inputs = @intCast(u31, inputs), |
| 2785 | .else_expr = else_expr, | 2867 | .has_else = has_else, |
| 2786 | }), | 2868 | }), |
| 2787 | }, | 2869 | }, |
| 2788 | }); | 2870 | }); |
lib/std/zig/fmt.zig+1-1| ... | @@ -25,7 +25,7 @@ pub fn fmtId(bytes: []const u8) std.fmt.Formatter(formatId) { | ... | @@ -25,7 +25,7 @@ pub fn fmtId(bytes: []const u8) std.fmt.Formatter(formatId) { |
| 25 | pub fn isValidId(bytes: []const u8) bool { | 25 | pub fn isValidId(bytes: []const u8) bool { |
| 26 | if (bytes.len == 0) return false; | 26 | if (bytes.len == 0) return false; |
| 27 | if (mem.eql(u8, bytes, "_")) return false; | 27 | if (mem.eql(u8, bytes, "_")) return false; |
| 28 | for (bytes) |c, i| { | 28 | for (bytes, 0..) |c, i| { |
| 29 | switch (c) { | 29 | switch (c) { |
| 30 | '_', 'a'...'z', 'A'...'Z' => {}, | 30 | '_', 'a'...'z', 'A'...'Z' => {}, |
| 31 | '0'...'9' => if (i == 0) return false, | 31 | '0'...'9' => if (i == 0) return false, |
lib/std/zig/parser_test.zig+59-12| ... | @@ -1,3 +1,23 @@ | ... | @@ -1,3 +1,23 @@ |
| 1 | // TODO: remove this after zig 0.11.0 is released | ||
| 2 | test "zig fmt: transform old for loop syntax to new" { | ||
| 3 | try testTransform( | ||
| 4 | \\fn foo() void { | ||
| 5 | \\ for (a) |b, i| { | ||
| 6 | \\ _ = b; _ = i; | ||
| 7 | \\ } | ||
| 8 | \\} | ||
| 9 | \\ | ||
| 10 | , | ||
| 11 | \\fn foo() void { | ||
| 12 | \\ for (a, 0..) |b, i| { | ||
| 13 | \\ _ = b; | ||
| 14 | \\ _ = i; | ||
| 15 | \\ } | ||
| 16 | \\} | ||
| 17 | \\ | ||
| 18 | ); | ||
| 19 | } | ||
| 20 | |||
| 1 | test "zig fmt: tuple struct" { | 21 | test "zig fmt: tuple struct" { |
| 2 | try testCanonical( | 22 | try testCanonical( |
| 3 | \\const T = struct { | 23 | \\const T = struct { |
| ... | @@ -3457,11 +3477,11 @@ test "zig fmt: for" { | ... | @@ -3457,11 +3477,11 @@ test "zig fmt: for" { |
| 3457 | \\ for (a) |*v| | 3477 | \\ for (a) |*v| |
| 3458 | \\ continue; | 3478 | \\ continue; |
| 3459 | \\ | 3479 | \\ |
| 3460 | \\ for (a) |v, i| { | 3480 | \\ for (a, 0..) |v, i| { |
| 3461 | \\ continue; | 3481 | \\ continue; |
| 3462 | \\ } | 3482 | \\ } |
| 3463 | \\ | 3483 | \\ |
| 3464 | \\ for (a) |v, i| | 3484 | \\ for (a, 0..) |v, i| |
| 3465 | \\ continue; | 3485 | \\ continue; |
| 3466 | \\ | 3486 | \\ |
| 3467 | \\ for (a) |b| switch (b) { | 3487 | \\ for (a) |b| switch (b) { |
| ... | @@ -3469,17 +3489,24 @@ test "zig fmt: for" { | ... | @@ -3469,17 +3489,24 @@ test "zig fmt: for" { |
| 3469 | \\ d => {}, | 3489 | \\ d => {}, |
| 3470 | \\ }; | 3490 | \\ }; |
| 3471 | \\ | 3491 | \\ |
| 3472 | \\ const res = for (a) |v, i| { | 3492 | \\ const res = for (a, 0..) |v, i| { |
| 3473 | \\ break v; | 3493 | \\ break v; |
| 3474 | \\ } else { | 3494 | \\ } else { |
| 3475 | \\ unreachable; | 3495 | \\ unreachable; |
| 3476 | \\ }; | 3496 | \\ }; |
| 3477 | \\ | 3497 | \\ |
| 3478 | \\ var num: usize = 0; | 3498 | \\ var num: usize = 0; |
| 3479 | \\ inline for (a) |v, i| { | 3499 | \\ inline for (a, 0..1) |v, i| { |
| 3480 | \\ num += v; | 3500 | \\ num += v; |
| 3481 | \\ num += i; | 3501 | \\ num += i; |
| 3482 | \\ } | 3502 | \\ } |
| 3503 | \\ | ||
| 3504 | \\ for (a, b) | | ||
| 3505 | \\ long_name, | ||
| 3506 | \\ another_long_name, | ||
| 3507 | \\ | { | ||
| 3508 | \\ continue; | ||
| 3509 | \\ } | ||
| 3483 | \\} | 3510 | \\} |
| 3484 | \\ | 3511 | \\ |
| 3485 | ); | 3512 | ); |
| ... | @@ -3499,6 +3526,26 @@ test "zig fmt: for" { | ... | @@ -3499,6 +3526,26 @@ test "zig fmt: for" { |
| 3499 | \\} | 3526 | \\} |
| 3500 | \\ | 3527 | \\ |
| 3501 | ); | 3528 | ); |
| 3529 | |||
| 3530 | try testTransform( | ||
| 3531 | \\test "fix for" { | ||
| 3532 | \\ for (a, b, c,) |long, another, third,| {} | ||
| 3533 | \\} | ||
| 3534 | \\ | ||
| 3535 | , | ||
| 3536 | \\test "fix for" { | ||
| 3537 | \\ for ( | ||
| 3538 | \\ a, | ||
| 3539 | \\ b, | ||
| 3540 | \\ c, | ||
| 3541 | \\ ) | | ||
| 3542 | \\ long, | ||
| 3543 | \\ another, | ||
| 3544 | \\ third, | ||
| 3545 | \\ | {} | ||
| 3546 | \\} | ||
| 3547 | \\ | ||
| 3548 | ); | ||
| 3502 | } | 3549 | } |
| 3503 | 3550 | ||
| 3504 | test "zig fmt: for if" { | 3551 | test "zig fmt: for if" { |
| ... | @@ -4358,7 +4405,7 @@ test "zig fmt: hex literals with underscore separators" { | ... | @@ -4358,7 +4405,7 @@ test "zig fmt: hex literals with underscore separators" { |
| 4358 | try testTransform( | 4405 | try testTransform( |
| 4359 | \\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 { | 4406 | \\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 { |
| 4360 | \\ var c: [1_000]u64 = [1]u64{ 0xFFFF_FFFF_FFFF_FFFF}**1_000; | 4407 | \\ var c: [1_000]u64 = [1]u64{ 0xFFFF_FFFF_FFFF_FFFF}**1_000; |
| 4361 | \\ for (c [ 1_0 .. ]) |_, i| { | 4408 | \\ for (c [ 1_0 .. ], 0..) |_, i| { |
| 4362 | \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; | 4409 | \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; |
| 4363 | \\ } | 4410 | \\ } |
| 4364 | \\ return c; | 4411 | \\ return c; |
| ... | @@ -4368,7 +4415,7 @@ test "zig fmt: hex literals with underscore separators" { | ... | @@ -4368,7 +4415,7 @@ test "zig fmt: hex literals with underscore separators" { |
| 4368 | , | 4415 | , |
| 4369 | \\pub fn orMask(a: [1_000]u64, b: [1_000]u64) [1_000]u64 { | 4416 | \\pub fn orMask(a: [1_000]u64, b: [1_000]u64) [1_000]u64 { |
| 4370 | \\ var c: [1_000]u64 = [1]u64{0xFFFF_FFFF_FFFF_FFFF} ** 1_000; | 4417 | \\ var c: [1_000]u64 = [1]u64{0xFFFF_FFFF_FFFF_FFFF} ** 1_000; |
| 4371 | \\ for (c[1_0..]) |_, i| { | 4418 | \\ for (c[1_0..], 0..) |_, i| { |
| 4372 | \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; | 4419 | \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; |
| 4373 | \\ } | 4420 | \\ } |
| 4374 | \\ return c; | 4421 | \\ return c; |
| ... | @@ -4880,10 +4927,10 @@ test "zig fmt: remove trailing whitespace after doc comment" { | ... | @@ -4880,10 +4927,10 @@ test "zig fmt: remove trailing whitespace after doc comment" { |
| 4880 | test "zig fmt: for loop with ptr payload and index" { | 4927 | test "zig fmt: for loop with ptr payload and index" { |
| 4881 | try testCanonical( | 4928 | try testCanonical( |
| 4882 | \\test { | 4929 | \\test { |
| 4883 | \\ for (self.entries.items) |*item, i| {} | 4930 | \\ for (self.entries.items, 0..) |*item, i| {} |
| 4884 | \\ for (self.entries.items) |*item, i| | 4931 | \\ for (self.entries.items, 0..) |*item, i| |
| 4885 | \\ a = b; | 4932 | \\ a = b; |
| 4886 | \\ for (self.entries.items) |*item, i| a = b; | 4933 | \\ for (self.entries.items, 0..) |*item, i| a = b; |
| 4887 | \\} | 4934 | \\} |
| 4888 | \\ | 4935 | \\ |
| 4889 | ); | 4936 | ); |
| ... | @@ -5471,7 +5518,7 @@ test "zig fmt: canonicalize symbols (primitive types)" { | ... | @@ -5471,7 +5518,7 @@ test "zig fmt: canonicalize symbols (primitive types)" { |
| 5471 | \\ _ = @"void": { | 5518 | \\ _ = @"void": { |
| 5472 | \\ break :@"void"; | 5519 | \\ break :@"void"; |
| 5473 | \\ }; | 5520 | \\ }; |
| 5474 | \\ for ("hi") |@"u3", @"i4"| { | 5521 | \\ for ("hi", 0..) |@"u3", @"i4"| { |
| 5475 | \\ _ = @"u3"; | 5522 | \\ _ = @"u3"; |
| 5476 | \\ _ = @"i4"; | 5523 | \\ _ = @"i4"; |
| 5477 | \\ } | 5524 | \\ } |
| ... | @@ -5523,7 +5570,7 @@ test "zig fmt: canonicalize symbols (primitive types)" { | ... | @@ -5523,7 +5570,7 @@ test "zig fmt: canonicalize symbols (primitive types)" { |
| 5523 | \\ _ = void: { | 5570 | \\ _ = void: { |
| 5524 | \\ break :void; | 5571 | \\ break :void; |
| 5525 | \\ }; | 5572 | \\ }; |
| 5526 | \\ for ("hi") |@"u3", @"i4"| { | 5573 | \\ for ("hi", 0..) |@"u3", @"i4"| { |
| 5527 | \\ _ = @"u3"; | 5574 | \\ _ = @"u3"; |
| 5528 | \\ _ = @"i4"; | 5575 | \\ _ = @"i4"; |
| 5529 | \\ } | 5576 | \\ } |
| ... | @@ -6131,7 +6178,7 @@ fn testError(source: [:0]const u8, expected_errors: []const Error) !void { | ... | @@ -6131,7 +6178,7 @@ fn testError(source: [:0]const u8, expected_errors: []const Error) !void { |
| 6131 | std.debug.print("errors found: {any}\n", .{tree.errors}); | 6178 | std.debug.print("errors found: {any}\n", .{tree.errors}); |
| 6132 | return err; | 6179 | return err; |
| 6133 | }; | 6180 | }; |
| 6134 | for (expected_errors) |expected, i| { | 6181 | for (expected_errors, 0..) |expected, i| { |
| 6135 | try std.testing.expectEqual(expected, tree.errors[i].tag); | 6182 | try std.testing.expectEqual(expected, tree.errors[i].tag); |
| 6136 | } | 6183 | } |
| 6137 | } | 6184 | } |
lib/std/zig/render.zig+157-32| ... | @@ -353,6 +353,16 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, | ... | @@ -353,6 +353,16 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, |
| 353 | try renderToken(ais, tree, main_tokens[node], .none); | 353 | try renderToken(ais, tree, main_tokens[node], .none); |
| 354 | return renderExpression(gpa, ais, tree, infix.rhs, space); | 354 | return renderExpression(gpa, ais, tree, infix.rhs, space); |
| 355 | }, | 355 | }, |
| 356 | .for_range => { | ||
| 357 | const infix = datas[node]; | ||
| 358 | try renderExpression(gpa, ais, tree, infix.lhs, .none); | ||
| 359 | if (infix.rhs != 0) { | ||
| 360 | try renderToken(ais, tree, main_tokens[node], .none); | ||
| 361 | return renderExpression(gpa, ais, tree, infix.rhs, space); | ||
| 362 | } else { | ||
| 363 | return renderToken(ais, tree, main_tokens[node], space); | ||
| 364 | } | ||
| 365 | }, | ||
| 356 | 366 | ||
| 357 | .add, | 367 | .add, |
| 358 | .add_wrap, | 368 | .add_wrap, |
| ... | @@ -694,9 +704,11 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, | ... | @@ -694,9 +704,11 @@ fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, |
| 694 | .while_simple, | 704 | .while_simple, |
| 695 | .while_cont, | 705 | .while_cont, |
| 696 | .@"while", | 706 | .@"while", |
| 707 | => return renderWhile(gpa, ais, tree, tree.fullWhile(node).?, space), | ||
| 708 | |||
| 697 | .for_simple, | 709 | .for_simple, |
| 698 | .@"for", | 710 | .@"for", |
| 699 | => return renderWhile(gpa, ais, tree, tree.fullWhile(node).?, space), | 711 | => return renderFor(gpa, ais, tree, tree.fullFor(node).?, space), |
| 700 | 712 | ||
| 701 | .if_simple, | 713 | .if_simple, |
| 702 | .@"if", | 714 | .@"if", |
| ... | @@ -1054,10 +1066,9 @@ fn renderIf(gpa: Allocator, ais: *Ais, tree: Ast, if_node: Ast.full.If, space: S | ... | @@ -1054,10 +1066,9 @@ fn renderIf(gpa: Allocator, ais: *Ais, tree: Ast, if_node: Ast.full.If, space: S |
| 1054 | }, space); | 1066 | }, space); |
| 1055 | } | 1067 | } |
| 1056 | 1068 | ||
| 1057 | /// Note that this function is additionally used to render if and for expressions, with | 1069 | /// Note that this function is additionally used to render if expressions, with |
| 1058 | /// respective values set to null. | 1070 | /// respective values set to null. |
| 1059 | fn renderWhile(gpa: Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While, space: Space) Error!void { | 1071 | fn renderWhile(gpa: Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While, space: Space) Error!void { |
| 1060 | const node_tags = tree.nodes.items(.tag); | ||
| 1061 | const token_tags = tree.tokens.items(.tag); | 1072 | const token_tags = tree.tokens.items(.tag); |
| 1062 | 1073 | ||
| 1063 | if (while_node.label_token) |label| { | 1074 | if (while_node.label_token) |label| { |
| ... | @@ -1108,9 +1119,34 @@ fn renderWhile(gpa: Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While, | ... | @@ -1108,9 +1119,34 @@ fn renderWhile(gpa: Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While, |
| 1108 | last_prefix_token = tree.lastToken(while_node.ast.cont_expr) + 1; // rparen | 1119 | last_prefix_token = tree.lastToken(while_node.ast.cont_expr) + 1; // rparen |
| 1109 | } | 1120 | } |
| 1110 | 1121 | ||
| 1111 | const then_expr_is_block = nodeIsBlock(node_tags[while_node.ast.then_expr]); | 1122 | try renderThenElse( |
| 1123 | gpa, | ||
| 1124 | ais, | ||
| 1125 | tree, | ||
| 1126 | last_prefix_token, | ||
| 1127 | while_node.ast.then_expr, | ||
| 1128 | while_node.else_token, | ||
| 1129 | while_node.error_token, | ||
| 1130 | while_node.ast.else_expr, | ||
| 1131 | space, | ||
| 1132 | ); | ||
| 1133 | } | ||
| 1134 | |||
| 1135 | fn renderThenElse( | ||
| 1136 | gpa: Allocator, | ||
| 1137 | ais: *Ais, | ||
| 1138 | tree: Ast, | ||
| 1139 | last_prefix_token: Ast.TokenIndex, | ||
| 1140 | then_expr: Ast.Node.Index, | ||
| 1141 | else_token: Ast.TokenIndex, | ||
| 1142 | maybe_error_token: ?Ast.TokenIndex, | ||
| 1143 | else_expr: Ast.Node.Index, | ||
| 1144 | space: Space, | ||
| 1145 | ) Error!void { | ||
| 1146 | const node_tags = tree.nodes.items(.tag); | ||
| 1147 | const then_expr_is_block = nodeIsBlock(node_tags[then_expr]); | ||
| 1112 | const indent_then_expr = !then_expr_is_block and | 1148 | const indent_then_expr = !then_expr_is_block and |
| 1113 | !tree.tokensOnSameLine(last_prefix_token, tree.firstToken(while_node.ast.then_expr)); | 1149 | !tree.tokensOnSameLine(last_prefix_token, tree.firstToken(then_expr)); |
| 1114 | if (indent_then_expr or (then_expr_is_block and ais.isLineOverIndented())) { | 1150 | if (indent_then_expr or (then_expr_is_block and ais.isLineOverIndented())) { |
| 1115 | ais.pushIndentNextLine(); | 1151 | ais.pushIndentNextLine(); |
| 1116 | try renderToken(ais, tree, last_prefix_token, .newline); | 1152 | try renderToken(ais, tree, last_prefix_token, .newline); |
| ... | @@ -1119,45 +1155,126 @@ fn renderWhile(gpa: Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While, | ... | @@ -1119,45 +1155,126 @@ fn renderWhile(gpa: Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While, |
| 1119 | try renderToken(ais, tree, last_prefix_token, .space); | 1155 | try renderToken(ais, tree, last_prefix_token, .space); |
| 1120 | } | 1156 | } |
| 1121 | 1157 | ||
| 1122 | if (while_node.ast.else_expr != 0) { | 1158 | if (else_expr != 0) { |
| 1123 | if (indent_then_expr) { | 1159 | if (indent_then_expr) { |
| 1124 | ais.pushIndent(); | 1160 | ais.pushIndent(); |
| 1125 | try renderExpression(gpa, ais, tree, while_node.ast.then_expr, .newline); | 1161 | try renderExpression(gpa, ais, tree, then_expr, .newline); |
| 1126 | ais.popIndent(); | 1162 | ais.popIndent(); |
| 1127 | } else { | 1163 | } else { |
| 1128 | try renderExpression(gpa, ais, tree, while_node.ast.then_expr, .space); | 1164 | try renderExpression(gpa, ais, tree, then_expr, .space); |
| 1129 | } | 1165 | } |
| 1130 | 1166 | ||
| 1131 | var last_else_token = while_node.else_token; | 1167 | var last_else_token = else_token; |
| 1132 | 1168 | ||
| 1133 | if (while_node.error_token) |error_token| { | 1169 | if (maybe_error_token) |error_token| { |
| 1134 | try renderToken(ais, tree, while_node.else_token, .space); // else | 1170 | try renderToken(ais, tree, else_token, .space); // else |
| 1135 | try renderToken(ais, tree, error_token - 1, .none); // | | 1171 | try renderToken(ais, tree, error_token - 1, .none); // | |
| 1136 | try renderIdentifier(ais, tree, error_token, .none, .preserve_when_shadowing); // identifier | 1172 | try renderIdentifier(ais, tree, error_token, .none, .preserve_when_shadowing); // identifier |
| 1137 | last_else_token = error_token + 1; // | | 1173 | last_else_token = error_token + 1; // | |
| 1138 | } | 1174 | } |
| 1139 | 1175 | ||
| 1140 | const indent_else_expr = indent_then_expr and | 1176 | const indent_else_expr = indent_then_expr and |
| 1141 | !nodeIsBlock(node_tags[while_node.ast.else_expr]) and | 1177 | !nodeIsBlock(node_tags[else_expr]) and |
| 1142 | !nodeIsIfForWhileSwitch(node_tags[while_node.ast.else_expr]); | 1178 | !nodeIsIfForWhileSwitch(node_tags[else_expr]); |
| 1143 | if (indent_else_expr) { | 1179 | if (indent_else_expr) { |
| 1144 | ais.pushIndentNextLine(); | 1180 | ais.pushIndentNextLine(); |
| 1145 | try renderToken(ais, tree, last_else_token, .newline); | 1181 | try renderToken(ais, tree, last_else_token, .newline); |
| 1146 | ais.popIndent(); | 1182 | ais.popIndent(); |
| 1147 | try renderExpressionIndented(gpa, ais, tree, while_node.ast.else_expr, space); | 1183 | try renderExpressionIndented(gpa, ais, tree, else_expr, space); |
| 1148 | } else { | 1184 | } else { |
| 1149 | try renderToken(ais, tree, last_else_token, .space); | 1185 | try renderToken(ais, tree, last_else_token, .space); |
| 1150 | try renderExpression(gpa, ais, tree, while_node.ast.else_expr, space); | 1186 | try renderExpression(gpa, ais, tree, else_expr, space); |
| 1151 | } | 1187 | } |
| 1152 | } else { | 1188 | } else { |
| 1153 | if (indent_then_expr) { | 1189 | if (indent_then_expr) { |
| 1154 | try renderExpressionIndented(gpa, ais, tree, while_node.ast.then_expr, space); | 1190 | try renderExpressionIndented(gpa, ais, tree, then_expr, space); |
| 1155 | } else { | 1191 | } else { |
| 1156 | try renderExpression(gpa, ais, tree, while_node.ast.then_expr, space); | 1192 | try renderExpression(gpa, ais, tree, then_expr, space); |
| 1157 | } | 1193 | } |
| 1158 | } | 1194 | } |
| 1159 | } | 1195 | } |
| 1160 | 1196 | ||
| 1197 | fn renderFor(gpa: Allocator, ais: *Ais, tree: Ast, for_node: Ast.full.For, space: Space) Error!void { | ||
| 1198 | const token_tags = tree.tokens.items(.tag); | ||
| 1199 | |||
| 1200 | if (for_node.label_token) |label| { | ||
| 1201 | try renderIdentifier(ais, tree, label, .none, .eagerly_unquote); // label | ||
| 1202 | try renderToken(ais, tree, label + 1, .space); // : | ||
| 1203 | } | ||
| 1204 | |||
| 1205 | if (for_node.inline_token) |inline_token| { | ||
| 1206 | try renderToken(ais, tree, inline_token, .space); // inline | ||
| 1207 | } | ||
| 1208 | |||
| 1209 | try renderToken(ais, tree, for_node.ast.for_token, .space); // if/for/while | ||
| 1210 | |||
| 1211 | const lparen = for_node.ast.for_token + 1; | ||
| 1212 | try renderParamList(gpa, ais, tree, lparen, for_node.ast.inputs, .space); | ||
| 1213 | |||
| 1214 | // TODO remove this after zig 0.11.0 | ||
| 1215 | if (for_node.isOldSyntax(token_tags)) { | ||
| 1216 | // old: for (a) |b, c| {} | ||
| 1217 | // new: for (a, 0..) |b, c| {} | ||
| 1218 | const array_list = ais.underlying_writer.context; // abstractions? who needs 'em! | ||
| 1219 | if (mem.endsWith(u8, array_list.items, ") ")) { | ||
| 1220 | array_list.items.len -= 2; | ||
| 1221 | try array_list.appendSlice(", 0..) "); | ||
| 1222 | } | ||
| 1223 | } | ||
| 1224 | |||
| 1225 | var cur = for_node.payload_token; | ||
| 1226 | const pipe = std.mem.indexOfScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?; | ||
| 1227 | if (token_tags[pipe - 1] == .comma) { | ||
| 1228 | ais.pushIndentNextLine(); | ||
| 1229 | try renderToken(ais, tree, cur - 1, .newline); // | | ||
| 1230 | while (true) { | ||
| 1231 | if (token_tags[cur] == .asterisk) { | ||
| 1232 | try renderToken(ais, tree, cur, .none); // * | ||
| 1233 | cur += 1; | ||
| 1234 | } | ||
| 1235 | try renderIdentifier(ais, tree, cur, .none, .preserve_when_shadowing); // identifier | ||
| 1236 | cur += 1; | ||
| 1237 | if (token_tags[cur] == .comma) { | ||
| 1238 | try renderToken(ais, tree, cur, .newline); // , | ||
| 1239 | cur += 1; | ||
| 1240 | } | ||
| 1241 | if (token_tags[cur] == .pipe) { | ||
| 1242 | break; | ||
| 1243 | } | ||
| 1244 | } | ||
| 1245 | ais.popIndent(); | ||
| 1246 | } else { | ||
| 1247 | try renderToken(ais, tree, cur - 1, .none); // | | ||
| 1248 | while (true) { | ||
| 1249 | if (token_tags[cur] == .asterisk) { | ||
| 1250 | try renderToken(ais, tree, cur, .none); // * | ||
| 1251 | cur += 1; | ||
| 1252 | } | ||
| 1253 | try renderIdentifier(ais, tree, cur, .none, .preserve_when_shadowing); // identifier | ||
| 1254 | cur += 1; | ||
| 1255 | if (token_tags[cur] == .comma) { | ||
| 1256 | try renderToken(ais, tree, cur, .space); // , | ||
| 1257 | cur += 1; | ||
| 1258 | } | ||
| 1259 | if (token_tags[cur] == .pipe) { | ||
| 1260 | break; | ||
| 1261 | } | ||
| 1262 | } | ||
| 1263 | } | ||
| 1264 | |||
| 1265 | try renderThenElse( | ||
| 1266 | gpa, | ||
| 1267 | ais, | ||
| 1268 | tree, | ||
| 1269 | cur, | ||
| 1270 | for_node.ast.then_expr, | ||
| 1271 | for_node.else_token, | ||
| 1272 | null, | ||
| 1273 | for_node.ast.else_expr, | ||
| 1274 | space, | ||
| 1275 | ); | ||
| 1276 | } | ||
| 1277 | |||
| 1161 | fn renderContainerField( | 1278 | fn renderContainerField( |
| 1162 | gpa: Allocator, | 1279 | gpa: Allocator, |
| 1163 | ais: *Ais, | 1280 | ais: *Ais, |
| ... | @@ -1290,7 +1407,7 @@ fn renderBuiltinCall( | ... | @@ -1290,7 +1407,7 @@ fn renderBuiltinCall( |
| 1290 | // Render all on one line, no trailing comma. | 1407 | // Render all on one line, no trailing comma. |
| 1291 | try renderToken(ais, tree, builtin_token + 1, .none); // ( | 1408 | try renderToken(ais, tree, builtin_token + 1, .none); // ( |
| 1292 | 1409 | ||
| 1293 | for (params) |param_node, i| { | 1410 | for (params, 0..) |param_node, i| { |
| 1294 | const first_param_token = tree.firstToken(param_node); | 1411 | const first_param_token = tree.firstToken(param_node); |
| 1295 | if (token_tags[first_param_token] == .multiline_string_literal_line or | 1412 | if (token_tags[first_param_token] == .multiline_string_literal_line or |
| 1296 | hasSameLineComment(tree, first_param_token - 1)) | 1413 | hasSameLineComment(tree, first_param_token - 1)) |
| ... | @@ -1622,7 +1739,7 @@ fn renderBlock( | ... | @@ -1622,7 +1739,7 @@ fn renderBlock( |
| 1622 | try renderToken(ais, tree, lbrace, .none); | 1739 | try renderToken(ais, tree, lbrace, .none); |
| 1623 | } else { | 1740 | } else { |
| 1624 | try renderToken(ais, tree, lbrace, .newline); | 1741 | try renderToken(ais, tree, lbrace, .newline); |
| 1625 | for (statements) |stmt, i| { | 1742 | for (statements, 0..) |stmt, i| { |
| 1626 | if (i != 0) try renderExtraNewline(ais, tree, stmt); | 1743 | if (i != 0) try renderExtraNewline(ais, tree, stmt); |
| 1627 | switch (node_tags[stmt]) { | 1744 | switch (node_tags[stmt]) { |
| 1628 | .global_var_decl, | 1745 | .global_var_decl, |
| ... | @@ -1785,7 +1902,7 @@ fn renderArrayInit( | ... | @@ -1785,7 +1902,7 @@ fn renderArrayInit( |
| 1785 | const section_end = sec_end: { | 1902 | const section_end = sec_end: { |
| 1786 | var this_line_first_expr: usize = 0; | 1903 | var this_line_first_expr: usize = 0; |
| 1787 | var this_line_size = rowSize(tree, row_exprs, rbrace); | 1904 | var this_line_size = rowSize(tree, row_exprs, rbrace); |
| 1788 | for (row_exprs) |expr, i| { | 1905 | for (row_exprs, 0..) |expr, i| { |
| 1789 | // Ignore comment on first line of this section. | 1906 | // Ignore comment on first line of this section. |
| 1790 | if (i == 0) continue; | 1907 | if (i == 0) continue; |
| 1791 | const expr_last_token = tree.lastToken(expr); | 1908 | const expr_last_token = tree.lastToken(expr); |
| ... | @@ -1824,7 +1941,7 @@ fn renderArrayInit( | ... | @@ -1824,7 +1941,7 @@ fn renderArrayInit( |
| 1824 | var column_counter: usize = 0; | 1941 | var column_counter: usize = 0; |
| 1825 | var single_line = true; | 1942 | var single_line = true; |
| 1826 | var contains_newline = false; | 1943 | var contains_newline = false; |
| 1827 | for (section_exprs) |expr, i| { | 1944 | for (section_exprs, 0..) |expr, i| { |
| 1828 | const start = sub_expr_buffer.items.len; | 1945 | const start = sub_expr_buffer.items.len; |
| 1829 | sub_expr_buffer_starts[i] = start; | 1946 | sub_expr_buffer_starts[i] = start; |
| 1830 | 1947 | ||
| ... | @@ -1866,7 +1983,7 @@ fn renderArrayInit( | ... | @@ -1866,7 +1983,7 @@ fn renderArrayInit( |
| 1866 | 1983 | ||
| 1867 | // Render exprs in current section. | 1984 | // Render exprs in current section. |
| 1868 | column_counter = 0; | 1985 | column_counter = 0; |
| 1869 | for (section_exprs) |expr, i| { | 1986 | for (section_exprs, 0..) |expr, i| { |
| 1870 | const start = sub_expr_buffer_starts[i]; | 1987 | const start = sub_expr_buffer_starts[i]; |
| 1871 | const end = sub_expr_buffer_starts[i + 1]; | 1988 | const end = sub_expr_buffer_starts[i + 1]; |
| 1872 | const expr_text = sub_expr_buffer.items[start..end]; | 1989 | const expr_text = sub_expr_buffer.items[start..end]; |
| ... | @@ -2023,7 +2140,7 @@ fn renderContainerDecl( | ... | @@ -2023,7 +2140,7 @@ fn renderContainerDecl( |
| 2023 | if (token_tags[lbrace + 1] == .container_doc_comment) { | 2140 | if (token_tags[lbrace + 1] == .container_doc_comment) { |
| 2024 | try renderContainerDocComments(ais, tree, lbrace + 1); | 2141 | try renderContainerDocComments(ais, tree, lbrace + 1); |
| 2025 | } | 2142 | } |
| 2026 | for (container_decl.ast.members) |member, i| { | 2143 | for (container_decl.ast.members, 0..) |member, i| { |
| 2027 | if (i != 0) try renderExtraNewline(ais, tree, member); | 2144 | if (i != 0) try renderExtraNewline(ais, tree, member); |
| 2028 | switch (tree.nodes.items(.tag)[member]) { | 2145 | switch (tree.nodes.items(.tag)[member]) { |
| 2029 | // For container fields, ensure a trailing comma is added if necessary. | 2146 | // For container fields, ensure a trailing comma is added if necessary. |
| ... | @@ -2109,7 +2226,7 @@ fn renderAsm( | ... | @@ -2109,7 +2226,7 @@ fn renderAsm( |
| 2109 | try renderToken(ais, tree, colon1, .space); // : | 2226 | try renderToken(ais, tree, colon1, .space); // : |
| 2110 | 2227 | ||
| 2111 | ais.pushIndent(); | 2228 | ais.pushIndent(); |
| 2112 | for (asm_node.outputs) |asm_output, i| { | 2229 | for (asm_node.outputs, 0..) |asm_output, i| { |
| 2113 | if (i + 1 < asm_node.outputs.len) { | 2230 | if (i + 1 < asm_node.outputs.len) { |
| 2114 | const next_asm_output = asm_node.outputs[i + 1]; | 2231 | const next_asm_output = asm_node.outputs[i + 1]; |
| 2115 | try renderAsmOutput(gpa, ais, tree, asm_output, .none); | 2232 | try renderAsmOutput(gpa, ais, tree, asm_output, .none); |
| ... | @@ -2141,7 +2258,7 @@ fn renderAsm( | ... | @@ -2141,7 +2258,7 @@ fn renderAsm( |
| 2141 | } else colon3: { | 2258 | } else colon3: { |
| 2142 | try renderToken(ais, tree, colon2, .space); // : | 2259 | try renderToken(ais, tree, colon2, .space); // : |
| 2143 | ais.pushIndent(); | 2260 | ais.pushIndent(); |
| 2144 | for (asm_node.inputs) |asm_input, i| { | 2261 | for (asm_node.inputs, 0..) |asm_input, i| { |
| 2145 | if (i + 1 < asm_node.inputs.len) { | 2262 | if (i + 1 < asm_node.inputs.len) { |
| 2146 | const next_asm_input = asm_node.inputs[i + 1]; | 2263 | const next_asm_input = asm_node.inputs[i + 1]; |
| 2147 | try renderAsmInput(gpa, ais, tree, asm_input, .none); | 2264 | try renderAsmInput(gpa, ais, tree, asm_input, .none); |
| ... | @@ -2206,15 +2323,23 @@ fn renderCall( | ... | @@ -2206,15 +2323,23 @@ fn renderCall( |
| 2206 | call: Ast.full.Call, | 2323 | call: Ast.full.Call, |
| 2207 | space: Space, | 2324 | space: Space, |
| 2208 | ) Error!void { | 2325 | ) Error!void { |
| 2209 | const token_tags = tree.tokens.items(.tag); | ||
| 2210 | |||
| 2211 | if (call.async_token) |async_token| { | 2326 | if (call.async_token) |async_token| { |
| 2212 | try renderToken(ais, tree, async_token, .space); | 2327 | try renderToken(ais, tree, async_token, .space); |
| 2213 | } | 2328 | } |
| 2214 | try renderExpression(gpa, ais, tree, call.ast.fn_expr, .none); | 2329 | try renderExpression(gpa, ais, tree, call.ast.fn_expr, .none); |
| 2330 | try renderParamList(gpa, ais, tree, call.ast.lparen, call.ast.params, space); | ||
| 2331 | } | ||
| 2332 | |||
| 2333 | fn renderParamList( | ||
| 2334 | gpa: Allocator, | ||
| 2335 | ais: *Ais, | ||
| 2336 | tree: Ast, | ||
| 2337 | lparen: Ast.TokenIndex, | ||
| 2338 | params: []const Ast.Node.Index, | ||
| 2339 | space: Space, | ||
| 2340 | ) Error!void { | ||
| 2341 | const token_tags = tree.tokens.items(.tag); | ||
| 2215 | 2342 | ||
| 2216 | const lparen = call.ast.lparen; | ||
| 2217 | const params = call.ast.params; | ||
| 2218 | if (params.len == 0) { | 2343 | if (params.len == 0) { |
| 2219 | ais.pushIndentNextLine(); | 2344 | ais.pushIndentNextLine(); |
| 2220 | try renderToken(ais, tree, lparen, .none); | 2345 | try renderToken(ais, tree, lparen, .none); |
| ... | @@ -2227,7 +2352,7 @@ fn renderCall( | ... | @@ -2227,7 +2352,7 @@ fn renderCall( |
| 2227 | if (token_tags[after_last_param_tok] == .comma) { | 2352 | if (token_tags[after_last_param_tok] == .comma) { |
| 2228 | ais.pushIndentNextLine(); | 2353 | ais.pushIndentNextLine(); |
| 2229 | try renderToken(ais, tree, lparen, .newline); // ( | 2354 | try renderToken(ais, tree, lparen, .newline); // ( |
| 2230 | for (params) |param_node, i| { | 2355 | for (params, 0..) |param_node, i| { |
| 2231 | if (i + 1 < params.len) { | 2356 | if (i + 1 < params.len) { |
| 2232 | try renderExpression(gpa, ais, tree, param_node, .none); | 2357 | try renderExpression(gpa, ais, tree, param_node, .none); |
| 2233 | 2358 | ||
| ... | @@ -2252,7 +2377,7 @@ fn renderCall( | ... | @@ -2252,7 +2377,7 @@ fn renderCall( |
| 2252 | 2377 | ||
| 2253 | try renderToken(ais, tree, lparen, .none); // ( | 2378 | try renderToken(ais, tree, lparen, .none); // ( |
| 2254 | 2379 | ||
| 2255 | for (params) |param_node, i| { | 2380 | for (params, 0..) |param_node, i| { |
| 2256 | const first_param_token = tree.firstToken(param_node); | 2381 | const first_param_token = tree.firstToken(param_node); |
| 2257 | if (token_tags[first_param_token] == .multiline_string_literal_line or | 2382 | if (token_tags[first_param_token] == .multiline_string_literal_line or |
| 2258 | hasSameLineComment(tree, first_param_token - 1)) | 2383 | hasSameLineComment(tree, first_param_token - 1)) |
| ... | @@ -2890,7 +3015,7 @@ fn rowSize(tree: Ast, exprs: []const Ast.Node.Index, rtoken: Ast.TokenIndex) usi | ... | @@ -2890,7 +3015,7 @@ fn rowSize(tree: Ast, exprs: []const Ast.Node.Index, rtoken: Ast.TokenIndex) usi |
| 2890 | } | 3015 | } |
| 2891 | 3016 | ||
| 2892 | var count: usize = 1; | 3017 | var count: usize = 1; |
| 2893 | for (exprs) |expr, i| { | 3018 | for (exprs, 0..) |expr, i| { |
| 2894 | if (i + 1 < exprs.len) { | 3019 | if (i + 1 < exprs.len) { |
| 2895 | const expr_last_token = tree.lastToken(expr) + 1; | 3020 | const expr_last_token = tree.lastToken(expr) + 1; |
| 2896 | if (!tree.tokensOnSameLine(expr_last_token, tree.firstToken(exprs[i + 1]))) return count; | 3021 | if (!tree.tokensOnSameLine(expr_last_token, tree.firstToken(exprs[i + 1]))) return count; |
lib/std/zig/system/NativeTargetInfo.zig+1-1| ... | @@ -273,7 +273,7 @@ fn detectAbiAndDynamicLinker( | ... | @@ -273,7 +273,7 @@ fn detectAbiAndDynamicLinker( |
| 273 | assert(@enumToInt(Target.Abi.none) == 0); | 273 | assert(@enumToInt(Target.Abi.none) == 0); |
| 274 | const fields = std.meta.fields(Target.Abi)[1..]; | 274 | const fields = std.meta.fields(Target.Abi)[1..]; |
| 275 | var array: [fields.len]Target.Abi = undefined; | 275 | var array: [fields.len]Target.Abi = undefined; |
| 276 | inline for (fields) |field, i| { | 276 | inline for (fields, 0..) |field, i| { |
| 277 | array[i] = @field(Target.Abi, field.name); | 277 | array[i] = @field(Target.Abi, field.name); |
| 278 | } | 278 | } |
| 279 | break :blk array; | 279 | break :blk array; |
lib/std/zig/system/linux.zig+1-1| ... | @@ -223,7 +223,7 @@ const ArmCpuinfoImpl = struct { | ... | @@ -223,7 +223,7 @@ const ArmCpuinfoImpl = struct { |
| 223 | }; | 223 | }; |
| 224 | 224 | ||
| 225 | var known_models: [self.cores.len]?*const Target.Cpu.Model = undefined; | 225 | var known_models: [self.cores.len]?*const Target.Cpu.Model = undefined; |
| 226 | for (self.cores[0..self.core_no]) |core, i| { | 226 | for (self.cores[0..self.core_no], 0..) |core, i| { |
| 227 | known_models[i] = cpu_models.isKnown(.{ | 227 | known_models[i] = cpu_models.isKnown(.{ |
| 228 | .architecture = core.architecture, | 228 | .architecture = core.architecture, |
| 229 | .implementer = core.implementer, | 229 | .implementer = core.implementer, |
lib/std/zig/system/windows.zig+3-3| ... | @@ -34,7 +34,7 @@ pub fn detectRuntimeVersion() WindowsVersion { | ... | @@ -34,7 +34,7 @@ pub fn detectRuntimeVersion() WindowsVersion { |
| 34 | // checking the build number against a known set of | 34 | // checking the build number against a known set of |
| 35 | // values | 35 | // values |
| 36 | var last_idx: usize = 0; | 36 | var last_idx: usize = 0; |
| 37 | for (WindowsVersion.known_win10_build_numbers) |build, i| { | 37 | for (WindowsVersion.known_win10_build_numbers, 0..) |build, i| { |
| 38 | if (version_info.dwBuildNumber >= build) | 38 | if (version_info.dwBuildNumber >= build) |
| 39 | last_idx = i; | 39 | last_idx = i; |
| 40 | } | 40 | } |
| ... | @@ -92,7 +92,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void { | ... | @@ -92,7 +92,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void { |
| 92 | 92 | ||
| 93 | var tmp_bufs: [fields_info.len][max_value_len]u8 align(@alignOf(std.os.windows.UNICODE_STRING)) = undefined; | 93 | var tmp_bufs: [fields_info.len][max_value_len]u8 align(@alignOf(std.os.windows.UNICODE_STRING)) = undefined; |
| 94 | 94 | ||
| 95 | inline for (fields_info) |field, i| { | 95 | inline for (fields_info, 0..) |field, i| { |
| 96 | const ctx: *anyopaque = blk: { | 96 | const ctx: *anyopaque = blk: { |
| 97 | switch (@field(args, field.name).value_type) { | 97 | switch (@field(args, field.name).value_type) { |
| 98 | REG.SZ, | 98 | REG.SZ, |
| ... | @@ -153,7 +153,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void { | ... | @@ -153,7 +153,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void { |
| 153 | ); | 153 | ); |
| 154 | switch (res) { | 154 | switch (res) { |
| 155 | .SUCCESS => { | 155 | .SUCCESS => { |
| 156 | inline for (fields_info) |field, i| switch (@field(args, field.name).value_type) { | 156 | inline for (fields_info, 0..) |field, i| switch (@field(args, field.name).value_type) { |
| 157 | REG.SZ, | 157 | REG.SZ, |
| 158 | REG.EXPAND_SZ, | 158 | REG.EXPAND_SZ, |
| 159 | REG.MULTI_SZ, | 159 | REG.MULTI_SZ, |
lib/std/zig/tokenizer.zig+45-5| ... | @@ -406,6 +406,38 @@ pub const Tokenizer = struct { | ... | @@ -406,6 +406,38 @@ pub const Tokenizer = struct { |
| 406 | saw_at_sign, | 406 | saw_at_sign, |
| 407 | }; | 407 | }; |
| 408 | 408 | ||
| 409 | /// This is a workaround to the fact that the tokenizer can queue up | ||
| 410 | /// 'pending_invalid_token's when parsing literals, which means that we need | ||
| 411 | /// to scan from the start of the current line to find a matching tag - just | ||
| 412 | /// in case it was an invalid character generated during literal | ||
| 413 | /// tokenization. Ideally this processing of this would be pushed to the AST | ||
| 414 | /// parser or another later stage, both to give more useful error messages | ||
| 415 | /// with that extra context and in order to be able to remove this | ||
| 416 | /// workaround. | ||
| 417 | pub fn findTagAtCurrentIndex(self: *Tokenizer, tag: Token.Tag) Token { | ||
| 418 | if (tag == .invalid) { | ||
| 419 | const target_index = self.index; | ||
| 420 | var starting_index = target_index; | ||
| 421 | while (starting_index > 0) { | ||
| 422 | if (self.buffer[starting_index] == '\n') { | ||
| 423 | break; | ||
| 424 | } | ||
| 425 | starting_index -= 1; | ||
| 426 | } | ||
| 427 | |||
| 428 | self.index = starting_index; | ||
| 429 | while (self.index <= target_index or self.pending_invalid_token != null) { | ||
| 430 | const result = self.next(); | ||
| 431 | if (result.loc.start == target_index and result.tag == tag) { | ||
| 432 | return result; | ||
| 433 | } | ||
| 434 | } | ||
| 435 | unreachable; | ||
| 436 | } else { | ||
| 437 | return self.next(); | ||
| 438 | } | ||
| 439 | } | ||
| 440 | |||
| 409 | pub fn next(self: *Tokenizer) Token { | 441 | pub fn next(self: *Tokenizer) Token { |
| 410 | if (self.pending_invalid_token) |token| { | 442 | if (self.pending_invalid_token) |token| { |
| 411 | self.pending_invalid_token = null; | 443 | self.pending_invalid_token = null; |
| ... | @@ -1127,7 +1159,7 @@ pub const Tokenizer = struct { | ... | @@ -1127,7 +1159,7 @@ pub const Tokenizer = struct { |
| 1127 | state = .start; | 1159 | state = .start; |
| 1128 | result.loc.start = self.index + 1; | 1160 | result.loc.start = self.index + 1; |
| 1129 | }, | 1161 | }, |
| 1130 | '\t', '\r' => state = .line_comment, | 1162 | '\t' => state = .line_comment, |
| 1131 | else => { | 1163 | else => { |
| 1132 | state = .line_comment; | 1164 | state = .line_comment; |
| 1133 | self.checkLiteralCharacter(); | 1165 | self.checkLiteralCharacter(); |
| ... | @@ -1141,7 +1173,7 @@ pub const Tokenizer = struct { | ... | @@ -1141,7 +1173,7 @@ pub const Tokenizer = struct { |
| 1141 | result.tag = .doc_comment; | 1173 | result.tag = .doc_comment; |
| 1142 | break; | 1174 | break; |
| 1143 | }, | 1175 | }, |
| 1144 | '\t', '\r' => { | 1176 | '\t' => { |
| 1145 | state = .doc_comment; | 1177 | state = .doc_comment; |
| 1146 | result.tag = .doc_comment; | 1178 | result.tag = .doc_comment; |
| 1147 | }, | 1179 | }, |
| ... | @@ -1163,12 +1195,12 @@ pub const Tokenizer = struct { | ... | @@ -1163,12 +1195,12 @@ pub const Tokenizer = struct { |
| 1163 | state = .start; | 1195 | state = .start; |
| 1164 | result.loc.start = self.index + 1; | 1196 | result.loc.start = self.index + 1; |
| 1165 | }, | 1197 | }, |
| 1166 | '\t', '\r' => {}, | 1198 | '\t' => {}, |
| 1167 | else => self.checkLiteralCharacter(), | 1199 | else => self.checkLiteralCharacter(), |
| 1168 | }, | 1200 | }, |
| 1169 | .doc_comment => switch (c) { | 1201 | .doc_comment => switch (c) { |
| 1170 | 0, '\n' => break, | 1202 | 0, '\n' => break, |
| 1171 | '\t', '\r' => {}, | 1203 | '\t' => {}, |
| 1172 | else => self.checkLiteralCharacter(), | 1204 | else => self.checkLiteralCharacter(), |
| 1173 | }, | 1205 | }, |
| 1174 | .int => switch (c) { | 1206 | .int => switch (c) { |
| ... | @@ -1239,7 +1271,15 @@ pub const Tokenizer = struct { | ... | @@ -1239,7 +1271,15 @@ pub const Tokenizer = struct { |
| 1239 | fn getInvalidCharacterLength(self: *Tokenizer) u3 { | 1271 | fn getInvalidCharacterLength(self: *Tokenizer) u3 { |
| 1240 | const c0 = self.buffer[self.index]; | 1272 | const c0 = self.buffer[self.index]; |
| 1241 | if (std.ascii.isASCII(c0)) { | 1273 | if (std.ascii.isASCII(c0)) { |
| 1242 | if (std.ascii.isControl(c0)) { | 1274 | if (c0 == '\r') { |
| 1275 | if (self.index + 1 < self.buffer.len and self.buffer[self.index + 1] == '\n') { | ||
| 1276 | // Carriage returns are *only* allowed just before a linefeed as part of a CRLF pair, otherwise | ||
| 1277 | // they constitute an illegal byte! | ||
| 1278 | return 0; | ||
| 1279 | } else { | ||
| 1280 | return 1; | ||
| 1281 | } | ||
| 1282 | } else if (std.ascii.isControl(c0)) { | ||
| 1243 | // ascii control codes are never allowed | 1283 | // ascii control codes are never allowed |
| 1244 | // (note that \n was checked before we got here) | 1284 | // (note that \n was checked before we got here) |
| 1245 | return 1; | 1285 | return 1; |
lib/test_runner.zig+1-1| ... | @@ -33,7 +33,7 @@ pub fn main() void { | ... | @@ -33,7 +33,7 @@ pub fn main() void { |
| 33 | async_frame_buffer = &[_]u8{}; | 33 | async_frame_buffer = &[_]u8{}; |
| 34 | 34 | ||
| 35 | var leaks: usize = 0; | 35 | var leaks: usize = 0; |
| 36 | for (test_fn_list) |test_fn, i| { | 36 | for (test_fn_list, 0..) |test_fn, i| { |
| 37 | std.testing.allocator_instance = .{}; | 37 | std.testing.allocator_instance = .{}; |
| 38 | defer { | 38 | defer { |
| 39 | if (std.testing.allocator_instance.deinit()) { | 39 | if (std.testing.allocator_instance.deinit()) { |
src/AstGen.zig+205-80| ... | @@ -518,6 +518,7 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins | ... | @@ -518,6 +518,7 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins |
| 518 | .error_union, | 518 | .error_union, |
| 519 | .merge_error_sets, | 519 | .merge_error_sets, |
| 520 | .switch_range, | 520 | .switch_range, |
| 521 | .for_range, | ||
| 521 | .@"await", | 522 | .@"await", |
| 522 | .bit_not, | 523 | .bit_not, |
| 523 | .negation, | 524 | .negation, |
| ... | @@ -646,6 +647,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -646,6 +647,8 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 646 | .asm_output => unreachable, // Handled in `asmExpr`. | 647 | .asm_output => unreachable, // Handled in `asmExpr`. |
| 647 | .asm_input => unreachable, // Handled in `asmExpr`. | 648 | .asm_input => unreachable, // Handled in `asmExpr`. |
| 648 | 649 | ||
| 650 | .for_range => unreachable, // Handled in `forExpr`. | ||
| 651 | |||
| 649 | .assign => { | 652 | .assign => { |
| 650 | try assign(gz, scope, node); | 653 | try assign(gz, scope, node); |
| 651 | return rvalue(gz, ri, .void_value, node); | 654 | return rvalue(gz, ri, .void_value, node); |
| ... | @@ -834,7 +837,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -834,7 +837,7 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 834 | .@"while", | 837 | .@"while", |
| 835 | => return whileExpr(gz, scope, ri.br(), node, tree.fullWhile(node).?, false), | 838 | => return whileExpr(gz, scope, ri.br(), node, tree.fullWhile(node).?, false), |
| 836 | 839 | ||
| 837 | .for_simple, .@"for" => return forExpr(gz, scope, ri.br(), node, tree.fullWhile(node).?, false), | 840 | .for_simple, .@"for" => return forExpr(gz, scope, ri.br(), node, tree.fullFor(node).?, false), |
| 838 | 841 | ||
| 839 | .slice_open => { | 842 | .slice_open => { |
| 840 | const lhs = try expr(gz, scope, .{ .rl = .ref }, node_datas[node].lhs); | 843 | const lhs = try expr(gz, scope, .{ .rl = .ref }, node_datas[node].lhs); |
| ... | @@ -1502,7 +1505,7 @@ fn arrayInitExprInner( | ... | @@ -1502,7 +1505,7 @@ fn arrayInitExprInner( |
| 1502 | extra_index += 1; | 1505 | extra_index += 1; |
| 1503 | } | 1506 | } |
| 1504 | 1507 | ||
| 1505 | for (elements) |elem_init, i| { | 1508 | for (elements, 0..) |elem_init, i| { |
| 1506 | const ri = if (elem_ty != .none) | 1509 | const ri = if (elem_ty != .none) |
| 1507 | ResultInfo{ .rl = .{ .coerced_ty = elem_ty } } | 1510 | ResultInfo{ .rl = .{ .coerced_ty = elem_ty } } |
| 1508 | else if (array_ty_inst != .none and nodeMayNeedMemoryLocation(astgen.tree, elem_init, true)) ri: { | 1511 | else if (array_ty_inst != .none and nodeMayNeedMemoryLocation(astgen.tree, elem_init, true)) ri: { |
| ... | @@ -1559,7 +1562,7 @@ fn arrayInitExprRlPtrInner( | ... | @@ -1559,7 +1562,7 @@ fn arrayInitExprRlPtrInner( |
| 1559 | }); | 1562 | }); |
| 1560 | var extra_index = try reserveExtra(astgen, elements.len); | 1563 | var extra_index = try reserveExtra(astgen, elements.len); |
| 1561 | 1564 | ||
| 1562 | for (elements) |elem_init, i| { | 1565 | for (elements, 0..) |elem_init, i| { |
| 1563 | const elem_ptr = try gz.addPlNode(.elem_ptr_imm, elem_init, Zir.Inst.ElemPtrImm{ | 1566 | const elem_ptr = try gz.addPlNode(.elem_ptr_imm, elem_init, Zir.Inst.ElemPtrImm{ |
| 1564 | .ptr = result_ptr, | 1567 | .ptr = result_ptr, |
| 1565 | .index = @intCast(u32, i), | 1568 | .index = @intCast(u32, i), |
| ... | @@ -2342,7 +2345,7 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod | ... | @@ -2342,7 +2345,7 @@ fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const Ast.Nod |
| 2342 | .@"while", => _ = try whileExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.fullWhile(inner_node).?, true), | 2345 | .@"while", => _ = try whileExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.fullWhile(inner_node).?, true), |
| 2343 | 2346 | ||
| 2344 | .for_simple, | 2347 | .for_simple, |
| 2345 | .@"for", => _ = try forExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.fullWhile(inner_node).?, true), | 2348 | .@"for", => _ = try forExpr(gz, scope, .{ .rl = .discard }, inner_node, tree.fullFor(inner_node).?, true), |
| 2346 | 2349 | ||
| 2347 | else => noreturn_src_node = try unusedResultExpr(gz, scope, inner_node), | 2350 | else => noreturn_src_node = try unusedResultExpr(gz, scope, inner_node), |
| 2348 | // zig fmt: on | 2351 | // zig fmt: on |
| ... | @@ -2397,6 +2400,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As | ... | @@ -2397,6 +2400,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2397 | .add, | 2400 | .add, |
| 2398 | .addwrap, | 2401 | .addwrap, |
| 2399 | .add_sat, | 2402 | .add_sat, |
| 2403 | .add_unsafe, | ||
| 2400 | .param, | 2404 | .param, |
| 2401 | .param_comptime, | 2405 | .param_comptime, |
| 2402 | .param_anytype, | 2406 | .param_anytype, |
| ... | @@ -2595,6 +2599,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As | ... | @@ -2595,6 +2599,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2595 | .field_base_ptr, | 2599 | .field_base_ptr, |
| 2596 | .ret_ptr, | 2600 | .ret_ptr, |
| 2597 | .ret_type, | 2601 | .ret_type, |
| 2602 | .for_len, | ||
| 2598 | .@"try", | 2603 | .@"try", |
| 2599 | .try_ptr, | 2604 | .try_ptr, |
| 2600 | //.try_inline, | 2605 | //.try_inline, |
| ... | @@ -6282,7 +6287,7 @@ fn forExpr( | ... | @@ -6282,7 +6287,7 @@ fn forExpr( |
| 6282 | scope: *Scope, | 6287 | scope: *Scope, |
| 6283 | ri: ResultInfo, | 6288 | ri: ResultInfo, |
| 6284 | node: Ast.Node.Index, | 6289 | node: Ast.Node.Index, |
| 6285 | for_full: Ast.full.While, | 6290 | for_full: Ast.full.For, |
| 6286 | is_statement: bool, | 6291 | is_statement: bool, |
| 6287 | ) InnerError!Zir.Inst.Ref { | 6292 | ) InnerError!Zir.Inst.Ref { |
| 6288 | const astgen = parent_gz.astgen; | 6293 | const astgen = parent_gz.astgen; |
| ... | @@ -6291,22 +6296,41 @@ fn forExpr( | ... | @@ -6291,22 +6296,41 @@ fn forExpr( |
| 6291 | try astgen.checkLabelRedefinition(scope, label_token); | 6296 | try astgen.checkLabelRedefinition(scope, label_token); |
| 6292 | } | 6297 | } |
| 6293 | 6298 | ||
| 6294 | // Set up variables and constants. | ||
| 6295 | const is_inline = parent_gz.force_comptime or for_full.inline_token != null; | 6299 | const is_inline = parent_gz.force_comptime or for_full.inline_token != null; |
| 6296 | const tree = astgen.tree; | 6300 | const tree = astgen.tree; |
| 6297 | const token_tags = tree.tokens.items(.tag); | 6301 | const token_tags = tree.tokens.items(.tag); |
| 6302 | const node_tags = tree.nodes.items(.tag); | ||
| 6303 | const node_data = tree.nodes.items(.data); | ||
| 6304 | const gpa = astgen.gpa; | ||
| 6298 | 6305 | ||
| 6299 | const payload_is_ref = if (for_full.payload_token) |payload_token| | 6306 | // TODO this can be deleted after zig 0.11.0 is released because it |
| 6300 | token_tags[payload_token] == .asterisk | 6307 | // will be caught in the parser. |
| 6301 | else | 6308 | if (for_full.isOldSyntax(token_tags)) { |
| 6302 | false; | 6309 | return astgen.failTokNotes( |
| 6303 | 6310 | for_full.payload_token + 2, | |
| 6304 | try emitDbgNode(parent_gz, for_full.ast.cond_expr); | 6311 | "extra capture in for loop", |
| 6312 | .{}, | ||
| 6313 | &[_]u32{ | ||
| 6314 | try astgen.errNoteTok( | ||
| 6315 | for_full.payload_token + 2, | ||
| 6316 | "run 'zig fmt' to upgrade your code automatically", | ||
| 6317 | .{}, | ||
| 6318 | ), | ||
| 6319 | }, | ||
| 6320 | ); | ||
| 6321 | } | ||
| 6305 | 6322 | ||
| 6306 | const cond_ri: ResultInfo = .{ .rl = if (payload_is_ref) .ref else .none }; | 6323 | // For counters, this is the start value; for indexables, this is the base |
| 6307 | const array_ptr = try expr(parent_gz, scope, cond_ri, for_full.ast.cond_expr); | 6324 | // pointer that can be used with elem_ptr and similar instructions. |
| 6308 | const len = try parent_gz.addUnNode(.indexable_ptr_len, array_ptr, for_full.ast.cond_expr); | 6325 | // Special value `none` means that this is a counter and its start value is |
| 6326 | // zero, indicating that the main index counter can be used directly. | ||
| 6327 | const indexables = try gpa.alloc(Zir.Inst.Ref, for_full.ast.inputs.len); | ||
| 6328 | defer gpa.free(indexables); | ||
| 6329 | // elements of this array can be `none`, indicating no length check. | ||
| 6330 | const lens = try gpa.alloc(Zir.Inst.Ref, for_full.ast.inputs.len); | ||
| 6331 | defer gpa.free(lens); | ||
| 6309 | 6332 | ||
| 6333 | // We will use a single zero-based counter no matter how many indexables there are. | ||
| 6310 | const index_ptr = blk: { | 6334 | const index_ptr = blk: { |
| 6311 | const alloc_tag: Zir.Inst.Tag = if (is_inline) .alloc_comptime_mut else .alloc; | 6335 | const alloc_tag: Zir.Inst.Tag = if (is_inline) .alloc_comptime_mut else .alloc; |
| 6312 | const index_ptr = try parent_gz.addUnNode(alloc_tag, .usize_type, node); | 6336 | const index_ptr = try parent_gz.addUnNode(alloc_tag, .usize_type, node); |
| ... | @@ -6315,22 +6339,95 @@ fn forExpr( | ... | @@ -6315,22 +6339,95 @@ fn forExpr( |
| 6315 | break :blk index_ptr; | 6339 | break :blk index_ptr; |
| 6316 | }; | 6340 | }; |
| 6317 | 6341 | ||
| 6342 | var any_len_checks = false; | ||
| 6343 | |||
| 6344 | { | ||
| 6345 | var capture_token = for_full.payload_token; | ||
| 6346 | for (for_full.ast.inputs, 0..) |input, i_usize| { | ||
| 6347 | const i = @intCast(u32, i_usize); | ||
| 6348 | const capture_is_ref = token_tags[capture_token] == .asterisk; | ||
| 6349 | const ident_tok = capture_token + @boolToInt(capture_is_ref); | ||
| 6350 | const is_discard = mem.eql(u8, tree.tokenSlice(ident_tok), "_"); | ||
| 6351 | |||
| 6352 | if (is_discard and capture_is_ref) { | ||
| 6353 | return astgen.failTok(capture_token, "pointer modifier invalid on discard", .{}); | ||
| 6354 | } | ||
| 6355 | // Skip over the comma, and on to the next capture (or the ending pipe character). | ||
| 6356 | capture_token = ident_tok + 2; | ||
| 6357 | |||
| 6358 | try emitDbgNode(parent_gz, input); | ||
| 6359 | if (node_tags[input] == .for_range) { | ||
| 6360 | if (capture_is_ref) { | ||
| 6361 | return astgen.failTok(ident_tok, "cannot capture reference to range", .{}); | ||
| 6362 | } | ||
| 6363 | const start_node = node_data[input].lhs; | ||
| 6364 | const start_val = try expr(parent_gz, scope, .{ .rl = .none }, start_node); | ||
| 6365 | |||
| 6366 | const end_node = node_data[input].rhs; | ||
| 6367 | const end_val = if (end_node != 0) | ||
| 6368 | try expr(parent_gz, scope, .{ .rl = .none }, node_data[input].rhs) | ||
| 6369 | else | ||
| 6370 | .none; | ||
| 6371 | |||
| 6372 | if (end_val == .none and is_discard) { | ||
| 6373 | return astgen.failTok(ident_tok, "discard of unbounded counter", .{}); | ||
| 6374 | } | ||
| 6375 | |||
| 6376 | const start_is_zero = nodeIsTriviallyZero(tree, start_node); | ||
| 6377 | const range_len = if (end_val == .none or start_is_zero) | ||
| 6378 | end_val | ||
| 6379 | else | ||
| 6380 | try parent_gz.addPlNode(.sub, input, Zir.Inst.Bin{ | ||
| 6381 | .lhs = end_val, | ||
| 6382 | .rhs = start_val, | ||
| 6383 | }); | ||
| 6384 | |||
| 6385 | any_len_checks = any_len_checks or range_len != .none; | ||
| 6386 | indexables[i] = if (start_is_zero) .none else start_val; | ||
| 6387 | lens[i] = range_len; | ||
| 6388 | } else { | ||
| 6389 | const indexable = try expr(parent_gz, scope, .{ .rl = .none }, input); | ||
| 6390 | |||
| 6391 | any_len_checks = true; | ||
| 6392 | indexables[i] = indexable; | ||
| 6393 | lens[i] = indexable; | ||
| 6394 | } | ||
| 6395 | } | ||
| 6396 | } | ||
| 6397 | |||
| 6398 | if (!any_len_checks) { | ||
| 6399 | return astgen.failNode(node, "unbounded for loop", .{}); | ||
| 6400 | } | ||
| 6401 | |||
| 6402 | // We use a dedicated ZIR instruction to assert the lengths to assist with | ||
| 6403 | // nicer error reporting as well as fewer ZIR bytes emitted. | ||
| 6404 | const len: Zir.Inst.Ref = len: { | ||
| 6405 | const lens_len = @intCast(u32, lens.len); | ||
| 6406 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.MultiOp).Struct.fields.len + lens_len); | ||
| 6407 | const len = try parent_gz.addPlNode(.for_len, node, Zir.Inst.MultiOp{ | ||
| 6408 | .operands_len = lens_len, | ||
| 6409 | }); | ||
| 6410 | appendRefsAssumeCapacity(astgen, lens); | ||
| 6411 | break :len len; | ||
| 6412 | }; | ||
| 6413 | |||
| 6318 | const loop_tag: Zir.Inst.Tag = if (is_inline) .block_inline else .loop; | 6414 | const loop_tag: Zir.Inst.Tag = if (is_inline) .block_inline else .loop; |
| 6319 | const loop_block = try parent_gz.makeBlockInst(loop_tag, node); | 6415 | const loop_block = try parent_gz.makeBlockInst(loop_tag, node); |
| 6320 | try parent_gz.instructions.append(astgen.gpa, loop_block); | 6416 | try parent_gz.instructions.append(gpa, loop_block); |
| 6321 | 6417 | ||
| 6322 | var loop_scope = parent_gz.makeSubBlock(scope); | 6418 | var loop_scope = parent_gz.makeSubBlock(scope); |
| 6323 | loop_scope.is_inline = is_inline; | 6419 | loop_scope.is_inline = is_inline; |
| 6324 | loop_scope.setBreakResultInfo(ri); | 6420 | loop_scope.setBreakResultInfo(ri); |
| 6325 | defer loop_scope.unstack(); | 6421 | defer loop_scope.unstack(); |
| 6326 | defer loop_scope.labeled_breaks.deinit(astgen.gpa); | 6422 | defer loop_scope.labeled_breaks.deinit(gpa); |
| 6423 | |||
| 6424 | const index = try loop_scope.addUnNode(.load, index_ptr, node); | ||
| 6327 | 6425 | ||
| 6328 | var cond_scope = parent_gz.makeSubBlock(&loop_scope.base); | 6426 | var cond_scope = parent_gz.makeSubBlock(&loop_scope.base); |
| 6329 | defer cond_scope.unstack(); | 6427 | defer cond_scope.unstack(); |
| 6330 | 6428 | ||
| 6331 | // check condition i < array_expr.len | 6429 | // Check the condition. |
| 6332 | const index = try cond_scope.addUnNode(.load, index_ptr, for_full.ast.cond_expr); | 6430 | const cond = try cond_scope.addPlNode(.cmp_lt, node, Zir.Inst.Bin{ |
| 6333 | const cond = try cond_scope.addPlNode(.cmp_lt, for_full.ast.cond_expr, Zir.Inst.Bin{ | ||
| 6334 | .lhs = index, | 6431 | .lhs = index, |
| 6335 | .rhs = len, | 6432 | .rhs = len, |
| 6336 | }); | 6433 | }); |
| ... | @@ -6341,12 +6438,11 @@ fn forExpr( | ... | @@ -6341,12 +6438,11 @@ fn forExpr( |
| 6341 | const cond_block = try loop_scope.makeBlockInst(block_tag, node); | 6438 | const cond_block = try loop_scope.makeBlockInst(block_tag, node); |
| 6342 | try cond_scope.setBlockBody(cond_block); | 6439 | try cond_scope.setBlockBody(cond_block); |
| 6343 | // cond_block unstacked now, can add new instructions to loop_scope | 6440 | // cond_block unstacked now, can add new instructions to loop_scope |
| 6344 | try loop_scope.instructions.append(astgen.gpa, cond_block); | 6441 | try loop_scope.instructions.append(gpa, cond_block); |
| 6345 | 6442 | ||
| 6346 | // Increment the index variable. | 6443 | // Increment the index variable. |
| 6347 | const index_2 = try loop_scope.addUnNode(.load, index_ptr, for_full.ast.cond_expr); | 6444 | const index_plus_one = try loop_scope.addPlNode(.add_unsafe, node, Zir.Inst.Bin{ |
| 6348 | const index_plus_one = try loop_scope.addPlNode(.add, node, Zir.Inst.Bin{ | 6445 | .lhs = index, |
| 6349 | .lhs = index_2, | ||
| 6350 | .rhs = .one_usize, | 6446 | .rhs = .one_usize, |
| 6351 | }); | 6447 | }); |
| 6352 | _ = try loop_scope.addBin(.store, index_ptr, index_plus_one); | 6448 | _ = try loop_scope.addBin(.store, index_ptr, index_plus_one); |
| ... | @@ -6367,62 +6463,67 @@ fn forExpr( | ... | @@ -6367,62 +6463,67 @@ fn forExpr( |
| 6367 | defer then_scope.unstack(); | 6463 | defer then_scope.unstack(); |
| 6368 | 6464 | ||
| 6369 | try then_scope.addDbgBlockBegin(); | 6465 | try then_scope.addDbgBlockBegin(); |
| 6370 | var payload_val_scope: Scope.LocalVal = undefined; | 6466 | |
| 6371 | var index_scope: Scope.LocalPtr = undefined; | 6467 | const capture_scopes = try gpa.alloc(Scope.LocalVal, for_full.ast.inputs.len); |
| 6468 | defer gpa.free(capture_scopes); | ||
| 6469 | |||
| 6372 | const then_sub_scope = blk: { | 6470 | const then_sub_scope = blk: { |
| 6373 | const payload_token = for_full.payload_token.?; | 6471 | var capture_token = for_full.payload_token; |
| 6374 | const ident = if (token_tags[payload_token] == .asterisk) | 6472 | var capture_sub_scope: *Scope = &then_scope.base; |
| 6375 | payload_token + 1 | 6473 | for (for_full.ast.inputs, 0..) |input, i_usize| { |
| 6376 | else | 6474 | const i = @intCast(u32, i_usize); |
| 6377 | payload_token; | 6475 | const capture_is_ref = token_tags[capture_token] == .asterisk; |
| 6378 | const is_ptr = ident != payload_token; | 6476 | const ident_tok = capture_token + @boolToInt(capture_is_ref); |
| 6379 | const value_name = tree.tokenSlice(ident); | 6477 | const capture_name = tree.tokenSlice(ident_tok); |
| 6380 | var payload_sub_scope: *Scope = undefined; | 6478 | // Skip over the comma, and on to the next capture (or the ending pipe character). |
| 6381 | if (!mem.eql(u8, value_name, "_")) { | 6479 | capture_token = ident_tok + 2; |
| 6382 | const name_str_index = try astgen.identAsString(ident); | 6480 | |
| 6383 | const tag: Zir.Inst.Tag = if (is_ptr) .elem_ptr else .elem_val; | 6481 | if (mem.eql(u8, capture_name, "_")) continue; |
| 6384 | const payload_inst = try then_scope.addPlNode(tag, for_full.ast.cond_expr, Zir.Inst.Bin{ | 6482 | |
| 6385 | .lhs = array_ptr, | 6483 | const name_str_index = try astgen.identAsString(ident_tok); |
| 6386 | .rhs = index, | 6484 | try astgen.detectLocalShadowing(capture_sub_scope, name_str_index, ident_tok, capture_name, .capture); |
| 6387 | }); | 6485 | |
| 6388 | try astgen.detectLocalShadowing(&then_scope.base, name_str_index, ident, value_name, .capture); | 6486 | const capture_inst = inst: { |
| 6389 | payload_val_scope = .{ | 6487 | const is_counter = node_tags[input] == .for_range; |
| 6390 | .parent = &then_scope.base, | 6488 | |
| 6489 | if (indexables[i] == .none) { | ||
| 6490 | // Special case: the main index can be used directly. | ||
| 6491 | assert(is_counter); | ||
| 6492 | assert(!capture_is_ref); | ||
| 6493 | break :inst index; | ||
| 6494 | } | ||
| 6495 | |||
| 6496 | // For counters, we add the index variable to the start value; for | ||
| 6497 | // indexables, we use it as an element index. This is so similar | ||
| 6498 | // that they can share the same code paths, branching only on the | ||
| 6499 | // ZIR tag. | ||
| 6500 | const switch_cond = (@as(u2, @boolToInt(capture_is_ref)) << 1) | @boolToInt(is_counter); | ||
| 6501 | const tag: Zir.Inst.Tag = switch (switch_cond) { | ||
| 6502 | 0b00 => .elem_val, | ||
| 6503 | 0b01 => .add, | ||
| 6504 | 0b10 => .elem_ptr, | ||
| 6505 | 0b11 => unreachable, // compile error emitted already | ||
| 6506 | }; | ||
| 6507 | break :inst try then_scope.addPlNode(tag, input, Zir.Inst.Bin{ | ||
| 6508 | .lhs = indexables[i], | ||
| 6509 | .rhs = index, | ||
| 6510 | }); | ||
| 6511 | }; | ||
| 6512 | |||
| 6513 | capture_scopes[i] = .{ | ||
| 6514 | .parent = capture_sub_scope, | ||
| 6391 | .gen_zir = &then_scope, | 6515 | .gen_zir = &then_scope, |
| 6392 | .name = name_str_index, | 6516 | .name = name_str_index, |
| 6393 | .inst = payload_inst, | 6517 | .inst = capture_inst, |
| 6394 | .token_src = ident, | 6518 | .token_src = ident_tok, |
| 6395 | .id_cat = .capture, | 6519 | .id_cat = .capture, |
| 6396 | }; | 6520 | }; |
| 6397 | try then_scope.addDbgVar(.dbg_var_val, name_str_index, payload_inst); | 6521 | |
| 6398 | payload_sub_scope = &payload_val_scope.base; | 6522 | try then_scope.addDbgVar(.dbg_var_val, name_str_index, capture_inst); |
| 6399 | } else if (is_ptr) { | 6523 | capture_sub_scope = &capture_scopes[i].base; |
| 6400 | return astgen.failTok(payload_token, "pointer modifier invalid on discard", .{}); | ||
| 6401 | } else { | ||
| 6402 | payload_sub_scope = &then_scope.base; | ||
| 6403 | } | 6524 | } |
| 6404 | 6525 | ||
| 6405 | const index_token = if (token_tags[ident + 1] == .comma) | 6526 | break :blk capture_sub_scope; |
| 6406 | ident + 2 | ||
| 6407 | else | ||
| 6408 | break :blk payload_sub_scope; | ||
| 6409 | const token_bytes = tree.tokenSlice(index_token); | ||
| 6410 | if (mem.eql(u8, token_bytes, "_")) { | ||
| 6411 | return astgen.failTok(index_token, "discard of index capture; omit it instead", .{}); | ||
| 6412 | } | ||
| 6413 | const index_name = try astgen.identAsString(index_token); | ||
| 6414 | try astgen.detectLocalShadowing(payload_sub_scope, index_name, index_token, token_bytes, .@"loop index capture"); | ||
| 6415 | index_scope = .{ | ||
| 6416 | .parent = payload_sub_scope, | ||
| 6417 | .gen_zir = &then_scope, | ||
| 6418 | .name = index_name, | ||
| 6419 | .ptr = index_ptr, | ||
| 6420 | .token_src = index_token, | ||
| 6421 | .maybe_comptime = is_inline, | ||
| 6422 | .id_cat = .@"loop index capture", | ||
| 6423 | }; | ||
| 6424 | try then_scope.addDbgVar(.dbg_var_val, index_name, index_ptr); | ||
| 6425 | break :blk &index_scope.base; | ||
| 6426 | }; | 6527 | }; |
| 6427 | 6528 | ||
| 6428 | const then_result = try expr(&then_scope, then_sub_scope, .{ .rl = .none }, for_full.ast.then_expr); | 6529 | const then_result = try expr(&then_scope, then_sub_scope, .{ .rl = .none }, for_full.ast.then_expr); |
| ... | @@ -6879,7 +6980,7 @@ fn switchExpr( | ... | @@ -6879,7 +6980,7 @@ fn switchExpr( |
| 6879 | zir_datas[switch_block].pl_node.payload_index = payload_index; | 6980 | zir_datas[switch_block].pl_node.payload_index = payload_index; |
| 6880 | 6981 | ||
| 6881 | const strat = ri.rl.strategy(&block_scope); | 6982 | const strat = ri.rl.strategy(&block_scope); |
| 6882 | for (payloads.items[case_table_start..case_table_end]) |start_index, i| { | 6983 | for (payloads.items[case_table_start..case_table_end], 0..) |start_index, i| { |
| 6883 | var body_len_index = start_index; | 6984 | var body_len_index = start_index; |
| 6884 | var end_index = start_index; | 6985 | var end_index = start_index; |
| 6885 | const table_index = case_table_start + i; | 6986 | const table_index = case_table_start + i; |
| ... | @@ -7543,7 +7644,7 @@ fn asmExpr( | ... | @@ -7543,7 +7644,7 @@ fn asmExpr( |
| 7543 | 7644 | ||
| 7544 | var output_type_bits: u32 = 0; | 7645 | var output_type_bits: u32 = 0; |
| 7545 | 7646 | ||
| 7546 | for (full.outputs) |output_node, i| { | 7647 | for (full.outputs, 0..) |output_node, i| { |
| 7547 | const symbolic_name = main_tokens[output_node]; | 7648 | const symbolic_name = main_tokens[output_node]; |
| 7548 | const name = try astgen.identAsString(symbolic_name); | 7649 | const name = try astgen.identAsString(symbolic_name); |
| 7549 | const constraint_token = symbolic_name + 2; | 7650 | const constraint_token = symbolic_name + 2; |
| ... | @@ -7580,7 +7681,7 @@ fn asmExpr( | ... | @@ -7580,7 +7681,7 @@ fn asmExpr( |
| 7580 | var inputs_buffer: [32]Zir.Inst.Asm.Input = undefined; | 7681 | var inputs_buffer: [32]Zir.Inst.Asm.Input = undefined; |
| 7581 | const inputs = inputs_buffer[0..full.inputs.len]; | 7682 | const inputs = inputs_buffer[0..full.inputs.len]; |
| 7582 | 7683 | ||
| 7583 | for (full.inputs) |input_node, i| { | 7684 | for (full.inputs, 0..) |input_node, i| { |
| 7584 | const symbolic_name = main_tokens[input_node]; | 7685 | const symbolic_name = main_tokens[input_node]; |
| 7585 | const name = try astgen.identAsString(symbolic_name); | 7686 | const name = try astgen.identAsString(symbolic_name); |
| 7586 | const constraint_token = symbolic_name + 2; | 7687 | const constraint_token = symbolic_name + 2; |
| ... | @@ -7753,7 +7854,7 @@ fn typeOf( | ... | @@ -7753,7 +7854,7 @@ fn typeOf( |
| 7753 | var typeof_scope = gz.makeSubBlock(scope); | 7854 | var typeof_scope = gz.makeSubBlock(scope); |
| 7754 | typeof_scope.force_comptime = false; | 7855 | typeof_scope.force_comptime = false; |
| 7755 | 7856 | ||
| 7756 | for (args) |arg, i| { | 7857 | for (args, 0..) |arg, i| { |
| 7757 | const param_ref = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, arg, node); | 7858 | const param_ref = try reachableExpr(&typeof_scope, &typeof_scope.base, .{ .rl = .none }, arg, node); |
| 7758 | astgen.extra.items[args_index + i] = @enumToInt(param_ref); | 7859 | astgen.extra.items[args_index + i] = @enumToInt(param_ref); |
| 7759 | } | 7860 | } |
| ... | @@ -8901,6 +9002,25 @@ comptime { | ... | @@ -8901,6 +9002,25 @@ comptime { |
| 8901 | } | 9002 | } |
| 8902 | } | 9003 | } |
| 8903 | 9004 | ||
| 9005 | fn nodeIsTriviallyZero(tree: *const Ast, node: Ast.Node.Index) bool { | ||
| 9006 | const node_tags = tree.nodes.items(.tag); | ||
| 9007 | const main_tokens = tree.nodes.items(.main_token); | ||
| 9008 | |||
| 9009 | switch (node_tags[node]) { | ||
| 9010 | .number_literal => { | ||
| 9011 | const ident = main_tokens[node]; | ||
| 9012 | return switch (std.zig.parseNumberLiteral(tree.tokenSlice(ident))) { | ||
| 9013 | .int => |number| switch (number) { | ||
| 9014 | 0 => true, | ||
| 9015 | else => false, | ||
| 9016 | }, | ||
| 9017 | else => false, | ||
| 9018 | }; | ||
| 9019 | }, | ||
| 9020 | else => return false, | ||
| 9021 | } | ||
| 9022 | } | ||
| 9023 | |||
| 8904 | fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_res_ty: bool) bool { | 9024 | fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_res_ty: bool) bool { |
| 8905 | const node_tags = tree.nodes.items(.tag); | 9025 | const node_tags = tree.nodes.items(.tag); |
| 8906 | const node_datas = tree.nodes.items(.data); | 9026 | const node_datas = tree.nodes.items(.data); |
| ... | @@ -9021,6 +9141,7 @@ fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_ | ... | @@ -9021,6 +9141,7 @@ fn nodeMayNeedMemoryLocation(tree: *const Ast, start_node: Ast.Node.Index, have_ |
| 9021 | .mul_wrap, | 9141 | .mul_wrap, |
| 9022 | .mul_sat, | 9142 | .mul_sat, |
| 9023 | .switch_range, | 9143 | .switch_range, |
| 9144 | .for_range, | ||
| 9024 | .field_access, | 9145 | .field_access, |
| 9025 | .sub, | 9146 | .sub, |
| 9026 | .sub_wrap, | 9147 | .sub_wrap, |
| ... | @@ -9310,6 +9431,7 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev | ... | @@ -9310,6 +9431,7 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev |
| 9310 | .mul_wrap, | 9431 | .mul_wrap, |
| 9311 | .mul_sat, | 9432 | .mul_sat, |
| 9312 | .switch_range, | 9433 | .switch_range, |
| 9434 | .for_range, | ||
| 9313 | .sub, | 9435 | .sub, |
| 9314 | .sub_wrap, | 9436 | .sub_wrap, |
| 9315 | .sub_sat, | 9437 | .sub_sat, |
| ... | @@ -9487,6 +9609,7 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In | ... | @@ -9487,6 +9609,7 @@ fn nodeImpliesMoreThanOnePossibleValue(tree: *const Ast, start_node: Ast.Node.In |
| 9487 | .mul_wrap, | 9609 | .mul_wrap, |
| 9488 | .mul_sat, | 9610 | .mul_sat, |
| 9489 | .switch_range, | 9611 | .switch_range, |
| 9612 | .for_range, | ||
| 9490 | .field_access, | 9613 | .field_access, |
| 9491 | .sub, | 9614 | .sub, |
| 9492 | .sub_wrap, | 9615 | .sub_wrap, |
| ... | @@ -9731,6 +9854,7 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { | ... | @@ -9731,6 +9854,7 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool { |
| 9731 | .mul_wrap, | 9854 | .mul_wrap, |
| 9732 | .mul_sat, | 9855 | .mul_sat, |
| 9733 | .switch_range, | 9856 | .switch_range, |
| 9857 | .for_range, | ||
| 9734 | .field_access, | 9858 | .field_access, |
| 9735 | .sub, | 9859 | .sub, |
| 9736 | .sub_wrap, | 9860 | .sub_wrap, |
| ... | @@ -10491,14 +10615,16 @@ fn strLitNodeAsString(astgen: *AstGen, node: Ast.Node.Index) !IndexSlice { | ... | @@ -10491,14 +10615,16 @@ fn strLitNodeAsString(astgen: *AstGen, node: Ast.Node.Index) !IndexSlice { |
| 10491 | var tok_i = start; | 10615 | var tok_i = start; |
| 10492 | { | 10616 | { |
| 10493 | const slice = tree.tokenSlice(tok_i); | 10617 | const slice = tree.tokenSlice(tok_i); |
| 10494 | const line_bytes = slice[2 .. slice.len - 1]; | 10618 | const carriage_return_ending: usize = if (slice[slice.len - 2] == '\r') 2 else 1; |
| 10619 | const line_bytes = slice[2 .. slice.len - carriage_return_ending]; | ||
| 10495 | try string_bytes.appendSlice(gpa, line_bytes); | 10620 | try string_bytes.appendSlice(gpa, line_bytes); |
| 10496 | tok_i += 1; | 10621 | tok_i += 1; |
| 10497 | } | 10622 | } |
| 10498 | // Following lines: each line prepends a newline. | 10623 | // Following lines: each line prepends a newline. |
| 10499 | while (tok_i <= end) : (tok_i += 1) { | 10624 | while (tok_i <= end) : (tok_i += 1) { |
| 10500 | const slice = tree.tokenSlice(tok_i); | 10625 | const slice = tree.tokenSlice(tok_i); |
| 10501 | const line_bytes = slice[2 .. slice.len - 1]; | 10626 | const carriage_return_ending: usize = if (slice[slice.len - 2] == '\r') 2 else 1; |
| 10627 | const line_bytes = slice[2 .. slice.len - carriage_return_ending]; | ||
| 10502 | try string_bytes.ensureUnusedCapacity(gpa, line_bytes.len + 1); | 10628 | try string_bytes.ensureUnusedCapacity(gpa, line_bytes.len + 1); |
| 10503 | string_bytes.appendAssumeCapacity('\n'); | 10629 | string_bytes.appendAssumeCapacity('\n'); |
| 10504 | string_bytes.appendSliceAssumeCapacity(line_bytes); | 10630 | string_bytes.appendSliceAssumeCapacity(line_bytes); |
| ... | @@ -10577,7 +10703,6 @@ const Scope = struct { | ... | @@ -10577,7 +10703,6 @@ const Scope = struct { |
| 10577 | @"function parameter", | 10703 | @"function parameter", |
| 10578 | @"local constant", | 10704 | @"local constant", |
| 10579 | @"local variable", | 10705 | @"local variable", |
| 10580 | @"loop index capture", | ||
| 10581 | @"switch tag capture", | 10706 | @"switch tag capture", |
| 10582 | capture, | 10707 | capture, |
| 10583 | }; | 10708 | }; |
src/Autodoc.zig+8-8| ... | @@ -1647,7 +1647,7 @@ fn walkInstruction( | ... | @@ -1647,7 +1647,7 @@ fn walkInstruction( |
| 1647 | std.debug.assert(operands.len > 0); | 1647 | std.debug.assert(operands.len > 0); |
| 1648 | var array_type = try self.walkRef(file, parent_scope, parent_src, operands[0], false); | 1648 | var array_type = try self.walkRef(file, parent_scope, parent_src, operands[0], false); |
| 1649 | 1649 | ||
| 1650 | for (operands[1..]) |op, idx| { | 1650 | for (operands[1..], 0..) |op, idx| { |
| 1651 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); | 1651 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); |
| 1652 | const expr_index = self.exprs.items.len; | 1652 | const expr_index = self.exprs.items.len; |
| 1653 | try self.exprs.append(self.arena, wr.expr); | 1653 | try self.exprs.append(self.arena, wr.expr); |
| ... | @@ -1665,7 +1665,7 @@ fn walkInstruction( | ... | @@ -1665,7 +1665,7 @@ fn walkInstruction( |
| 1665 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); | 1665 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); |
| 1666 | const array_data = try self.arena.alloc(usize, operands.len); | 1666 | const array_data = try self.arena.alloc(usize, operands.len); |
| 1667 | 1667 | ||
| 1668 | for (operands) |op, idx| { | 1668 | for (operands, 0..) |op, idx| { |
| 1669 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); | 1669 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); |
| 1670 | const expr_index = self.exprs.items.len; | 1670 | const expr_index = self.exprs.items.len; |
| 1671 | try self.exprs.append(self.arena, wr.expr); | 1671 | try self.exprs.append(self.arena, wr.expr); |
| ... | @@ -1686,7 +1686,7 @@ fn walkInstruction( | ... | @@ -1686,7 +1686,7 @@ fn walkInstruction( |
| 1686 | std.debug.assert(operands.len > 0); | 1686 | std.debug.assert(operands.len > 0); |
| 1687 | var array_type = try self.walkRef(file, parent_scope, parent_src, operands[0], false); | 1687 | var array_type = try self.walkRef(file, parent_scope, parent_src, operands[0], false); |
| 1688 | 1688 | ||
| 1689 | for (operands[1..]) |op, idx| { | 1689 | for (operands[1..], 0..) |op, idx| { |
| 1690 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); | 1690 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); |
| 1691 | const expr_index = self.exprs.items.len; | 1691 | const expr_index = self.exprs.items.len; |
| 1692 | try self.exprs.append(self.arena, wr.expr); | 1692 | try self.exprs.append(self.arena, wr.expr); |
| ... | @@ -1715,7 +1715,7 @@ fn walkInstruction( | ... | @@ -1715,7 +1715,7 @@ fn walkInstruction( |
| 1715 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); | 1715 | const operands = file.zir.refSlice(extra.end, extra.data.operands_len); |
| 1716 | const array_data = try self.arena.alloc(usize, operands.len); | 1716 | const array_data = try self.arena.alloc(usize, operands.len); |
| 1717 | 1717 | ||
| 1718 | for (operands) |op, idx| { | 1718 | for (operands, 0..) |op, idx| { |
| 1719 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); | 1719 | const wr = try self.walkRef(file, parent_scope, parent_src, op, false); |
| 1720 | const expr_index = self.exprs.items.len; | 1720 | const expr_index = self.exprs.items.len; |
| 1721 | try self.exprs.append(self.arena, wr.expr); | 1721 | try self.exprs.append(self.arena, wr.expr); |
| ... | @@ -2386,7 +2386,7 @@ fn walkInstruction( | ... | @@ -2386,7 +2386,7 @@ fn walkInstruction( |
| 2386 | const array_data = try self.arena.alloc(usize, args.len); | 2386 | const array_data = try self.arena.alloc(usize, args.len); |
| 2387 | 2387 | ||
| 2388 | var array_type: ?DocData.Expr = null; | 2388 | var array_type: ?DocData.Expr = null; |
| 2389 | for (args) |arg, idx| { | 2389 | for (args, 0..) |arg, idx| { |
| 2390 | const wr = try self.walkRef(file, parent_scope, parent_src, arg, idx == 0); | 2390 | const wr = try self.walkRef(file, parent_scope, parent_src, arg, idx == 0); |
| 2391 | if (idx == 0) { | 2391 | if (idx == 0) { |
| 2392 | array_type = wr.typeRef; | 2392 | array_type = wr.typeRef; |
| ... | @@ -3470,7 +3470,7 @@ fn tryResolveRefPath( | ... | @@ -3470,7 +3470,7 @@ fn tryResolveRefPath( |
| 3470 | } | 3470 | } |
| 3471 | } | 3471 | } |
| 3472 | 3472 | ||
| 3473 | for (self.ast_nodes.items[t_enum.src].fields.?) |ast_node, idx| { | 3473 | for (self.ast_nodes.items[t_enum.src].fields.?, 0..) |ast_node, idx| { |
| 3474 | const name = self.ast_nodes.items[ast_node].name.?; | 3474 | const name = self.ast_nodes.items[ast_node].name.?; |
| 3475 | if (std.mem.eql(u8, name, child_string)) { | 3475 | if (std.mem.eql(u8, name, child_string)) { |
| 3476 | // TODO: should we really create an artificial | 3476 | // TODO: should we really create an artificial |
| ... | @@ -3517,7 +3517,7 @@ fn tryResolveRefPath( | ... | @@ -3517,7 +3517,7 @@ fn tryResolveRefPath( |
| 3517 | } | 3517 | } |
| 3518 | } | 3518 | } |
| 3519 | 3519 | ||
| 3520 | for (self.ast_nodes.items[t_union.src].fields.?) |ast_node, idx| { | 3520 | for (self.ast_nodes.items[t_union.src].fields.?, 0..) |ast_node, idx| { |
| 3521 | const name = self.ast_nodes.items[ast_node].name.?; | 3521 | const name = self.ast_nodes.items[ast_node].name.?; |
| 3522 | if (std.mem.eql(u8, name, child_string)) { | 3522 | if (std.mem.eql(u8, name, child_string)) { |
| 3523 | // TODO: should we really create an artificial | 3523 | // TODO: should we really create an artificial |
| ... | @@ -3564,7 +3564,7 @@ fn tryResolveRefPath( | ... | @@ -3564,7 +3564,7 @@ fn tryResolveRefPath( |
| 3564 | } | 3564 | } |
| 3565 | } | 3565 | } |
| 3566 | 3566 | ||
| 3567 | for (self.ast_nodes.items[t_struct.src].fields.?) |ast_node, idx| { | 3567 | for (self.ast_nodes.items[t_struct.src].fields.?, 0..) |ast_node, idx| { |
| 3568 | const name = self.ast_nodes.items[ast_node].name.?; | 3568 | const name = self.ast_nodes.items[ast_node].name.?; |
| 3569 | if (std.mem.eql(u8, name, child_string)) { | 3569 | if (std.mem.eql(u8, name, child_string)) { |
| 3570 | // TODO: should we really create an artificial | 3570 | // TODO: should we really create an artificial |
src/Compilation.zig+11-11| ... | @@ -641,7 +641,7 @@ pub const AllErrors = struct { | ... | @@ -641,7 +641,7 @@ pub const AllErrors = struct { |
| 641 | } | 641 | } |
| 642 | 642 | ||
| 643 | const reference_trace = try allocator.alloc(Message, module_err_msg.reference_trace.len); | 643 | const reference_trace = try allocator.alloc(Message, module_err_msg.reference_trace.len); |
| 644 | for (reference_trace) |*reference, i| { | 644 | for (reference_trace, 0..) |*reference, i| { |
| 645 | const module_reference = module_err_msg.reference_trace[i]; | 645 | const module_reference = module_err_msg.reference_trace[i]; |
| 646 | if (module_reference.hidden != 0) { | 646 | if (module_reference.hidden != 0) { |
| 647 | reference.* = .{ .plain = .{ .msg = undefined, .count = module_reference.hidden } }; | 647 | reference.* = .{ .plain = .{ .msg = undefined, .count = module_reference.hidden } }; |
| ... | @@ -714,7 +714,7 @@ pub const AllErrors = struct { | ... | @@ -714,7 +714,7 @@ pub const AllErrors = struct { |
| 714 | const block = file.zir.extraData(Zir.Inst.Block, item.data.notes); | 714 | const block = file.zir.extraData(Zir.Inst.Block, item.data.notes); |
| 715 | const body = file.zir.extra[block.end..][0..block.data.body_len]; | 715 | const body = file.zir.extra[block.end..][0..block.data.body_len]; |
| 716 | notes = try arena.alloc(Message, body.len); | 716 | notes = try arena.alloc(Message, body.len); |
| 717 | for (notes) |*note, i| { | 717 | for (notes, 0..) |*note, i| { |
| 718 | const note_item = file.zir.extraData(Zir.Inst.CompileErrors.Item, body[i]); | 718 | const note_item = file.zir.extraData(Zir.Inst.CompileErrors.Item, body[i]); |
| 719 | const msg = file.zir.nullTerminatedString(note_item.data.msg); | 719 | const msg = file.zir.nullTerminatedString(note_item.data.msg); |
| 720 | const span = blk: { | 720 | const span = blk: { |
| ... | @@ -786,7 +786,7 @@ pub const AllErrors = struct { | ... | @@ -786,7 +786,7 @@ pub const AllErrors = struct { |
| 786 | 786 | ||
| 787 | fn dupeList(list: []const Message, arena: Allocator) Allocator.Error![]Message { | 787 | fn dupeList(list: []const Message, arena: Allocator) Allocator.Error![]Message { |
| 788 | const duped_list = try arena.alloc(Message, list.len); | 788 | const duped_list = try arena.alloc(Message, list.len); |
| 789 | for (list) |item, i| { | 789 | for (list, 0..) |item, i| { |
| 790 | duped_list[i] = switch (item) { | 790 | duped_list[i] = switch (item) { |
| 791 | .src => |src| .{ .src = .{ | 791 | .src => |src| .{ .src = .{ |
| 792 | .msg = try arena.dupe(u8, src.msg), | 792 | .msg = try arena.dupe(u8, src.msg), |
| ... | @@ -1441,7 +1441,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1441,7 +1441,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1441 | 1441 | ||
| 1442 | const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: { | 1442 | const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: { |
| 1443 | var buf = std.ArrayList(u8).init(arena); | 1443 | var buf = std.ArrayList(u8).init(arena); |
| 1444 | for (options.target.cpu.arch.allFeaturesList()) |feature, index_usize| { | 1444 | for (options.target.cpu.arch.allFeaturesList(), 0..) |feature, index_usize| { |
| 1445 | const index = @intCast(Target.Cpu.Feature.Set.Index, index_usize); | 1445 | const index = @intCast(Target.Cpu.Feature.Set.Index, index_usize); |
| 1446 | const is_enabled = options.target.cpu.features.isEnabled(index); | 1446 | const is_enabled = options.target.cpu.features.isEnabled(index); |
| 1447 | 1447 | ||
| ... | @@ -1818,7 +1818,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1818,7 +1818,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1818 | var system_libs: std.StringArrayHashMapUnmanaged(SystemLib) = .{}; | 1818 | var system_libs: std.StringArrayHashMapUnmanaged(SystemLib) = .{}; |
| 1819 | errdefer system_libs.deinit(gpa); | 1819 | errdefer system_libs.deinit(gpa); |
| 1820 | try system_libs.ensureTotalCapacity(gpa, options.system_lib_names.len); | 1820 | try system_libs.ensureTotalCapacity(gpa, options.system_lib_names.len); |
| 1821 | for (options.system_lib_names) |lib_name, i| { | 1821 | for (options.system_lib_names, 0..) |lib_name, i| { |
| 1822 | system_libs.putAssumeCapacity(lib_name, options.system_lib_infos[i]); | 1822 | system_libs.putAssumeCapacity(lib_name, options.system_lib_infos[i]); |
| 1823 | } | 1823 | } |
| 1824 | 1824 | ||
| ... | @@ -2880,7 +2880,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { | ... | @@ -2880,7 +2880,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 2880 | } | 2880 | } |
| 2881 | for (self.lld_errors.items) |lld_error| { | 2881 | for (self.lld_errors.items) |lld_error| { |
| 2882 | const notes = try arena_allocator.alloc(AllErrors.Message, lld_error.context_lines.len); | 2882 | const notes = try arena_allocator.alloc(AllErrors.Message, lld_error.context_lines.len); |
| 2883 | for (lld_error.context_lines) |context_line, i| { | 2883 | for (lld_error.context_lines, 0..) |context_line, i| { |
| 2884 | notes[i] = .{ .plain = .{ | 2884 | notes[i] = .{ .plain = .{ |
| 2885 | .msg = try arena_allocator.dupe(u8, context_line), | 2885 | .msg = try arena_allocator.dupe(u8, context_line), |
| 2886 | } }; | 2886 | } }; |
| ... | @@ -3007,7 +3007,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { | ... | @@ -3007,7 +3007,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 3007 | }; | 3007 | }; |
| 3008 | defer self.gpa.free(err_msg.notes); | 3008 | defer self.gpa.free(err_msg.notes); |
| 3009 | 3009 | ||
| 3010 | for (keys[1..]) |key, i| { | 3010 | for (keys[1..], 0..) |key, i| { |
| 3011 | const note_decl = module.declPtr(key); | 3011 | const note_decl = module.declPtr(key); |
| 3012 | err_msg.notes[i] = .{ | 3012 | err_msg.notes[i] = .{ |
| 3013 | .src_loc = note_decl.nodeOffsetSrcLoc(values[i + 1]), | 3013 | .src_loc = note_decl.nodeOffsetSrcLoc(values[i + 1]), |
| ... | @@ -3104,7 +3104,7 @@ pub fn performAllTheWork( | ... | @@ -3104,7 +3104,7 @@ pub fn performAllTheWork( |
| 3104 | const notes = try mod.gpa.alloc(Module.ErrorMsg, file.references.items.len); | 3104 | const notes = try mod.gpa.alloc(Module.ErrorMsg, file.references.items.len); |
| 3105 | errdefer mod.gpa.free(notes); | 3105 | errdefer mod.gpa.free(notes); |
| 3106 | 3106 | ||
| 3107 | for (notes) |*note, i| { | 3107 | for (notes, 0..) |*note, i| { |
| 3108 | errdefer for (notes[0..i]) |*n| n.deinit(mod.gpa); | 3108 | errdefer for (notes[0..i]) |*n| n.deinit(mod.gpa); |
| 3109 | note.* = switch (file.references.items[i]) { | 3109 | note.* = switch (file.references.items[i]) { |
| 3110 | .import => |loc| try Module.ErrorMsg.init( | 3110 | .import => |loc| try Module.ErrorMsg.init( |
| ... | @@ -3740,7 +3740,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult { | ... | @@ -3740,7 +3740,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult { |
| 3740 | const new_argv_with_sentinel = try arena.alloc(?[*:0]const u8, argv.items.len + 1); | 3740 | const new_argv_with_sentinel = try arena.alloc(?[*:0]const u8, argv.items.len + 1); |
| 3741 | new_argv_with_sentinel[argv.items.len] = null; | 3741 | new_argv_with_sentinel[argv.items.len] = null; |
| 3742 | const new_argv = new_argv_with_sentinel[0..argv.items.len :null]; | 3742 | const new_argv = new_argv_with_sentinel[0..argv.items.len :null]; |
| 3743 | for (argv.items) |arg, i| { | 3743 | for (argv.items, 0..) |arg, i| { |
| 3744 | new_argv[i] = try arena.dupeZ(u8, arg); | 3744 | new_argv[i] = try arena.dupeZ(u8, arg); |
| 3745 | } | 3745 | } |
| 3746 | 3746 | ||
| ... | @@ -4382,7 +4382,7 @@ pub fn addCCArgs( | ... | @@ -4382,7 +4382,7 @@ pub fn addCCArgs( |
| 4382 | // It would be really nice if there was a more compact way to communicate this info to Clang. | 4382 | // It would be really nice if there was a more compact way to communicate this info to Clang. |
| 4383 | const all_features_list = target.cpu.arch.allFeaturesList(); | 4383 | const all_features_list = target.cpu.arch.allFeaturesList(); |
| 4384 | try argv.ensureUnusedCapacity(all_features_list.len * 4); | 4384 | try argv.ensureUnusedCapacity(all_features_list.len * 4); |
| 4385 | for (all_features_list) |feature, index_usize| { | 4385 | for (all_features_list, 0..) |feature, index_usize| { |
| 4386 | const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize); | 4386 | const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize); |
| 4387 | const is_enabled = target.cpu.features.isEnabled(index); | 4387 | const is_enabled = target.cpu.features.isEnabled(index); |
| 4388 | 4388 | ||
| ... | @@ -5210,7 +5210,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca | ... | @@ -5210,7 +5210,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca |
| 5210 | std.zig.fmtId(generic_arch_name), | 5210 | std.zig.fmtId(generic_arch_name), |
| 5211 | }); | 5211 | }); |
| 5212 | 5212 | ||
| 5213 | for (target.cpu.arch.allFeaturesList()) |feature, index_usize| { | 5213 | for (target.cpu.arch.allFeaturesList(), 0..) |feature, index_usize| { |
| 5214 | const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize); | 5214 | const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize); |
| 5215 | const is_enabled = target.cpu.features.isEnabled(index); | 5215 | const is_enabled = target.cpu.features.isEnabled(index); |
| 5216 | if (is_enabled) { | 5216 | if (is_enabled) { |
src/Liveness.zig+4-4| ... | @@ -384,7 +384,7 @@ pub fn categorizeOperand( | ... | @@ -384,7 +384,7 @@ pub fn categorizeOperand( |
| 384 | const args = @ptrCast([]const Air.Inst.Ref, air.extra[extra.end..][0..extra.data.args_len]); | 384 | const args = @ptrCast([]const Air.Inst.Ref, air.extra[extra.end..][0..extra.data.args_len]); |
| 385 | if (args.len + 1 <= bpi - 1) { | 385 | if (args.len + 1 <= bpi - 1) { |
| 386 | if (callee == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write); | 386 | if (callee == operand_ref) return matchOperandSmallIndex(l, inst, 0, .write); |
| 387 | for (args) |arg, i| { | 387 | for (args, 0..) |arg, i| { |
| 388 | if (arg == operand_ref) return matchOperandSmallIndex(l, inst, @intCast(OperandInt, i + 1), .write); | 388 | if (arg == operand_ref) return matchOperandSmallIndex(l, inst, @intCast(OperandInt, i + 1), .write); |
| 389 | } | 389 | } |
| 390 | return .write; | 390 | return .write; |
| ... | @@ -436,7 +436,7 @@ pub fn categorizeOperand( | ... | @@ -436,7 +436,7 @@ pub fn categorizeOperand( |
| 436 | const elements = @ptrCast([]const Air.Inst.Ref, air.extra[ty_pl.payload..][0..len]); | 436 | const elements = @ptrCast([]const Air.Inst.Ref, air.extra[ty_pl.payload..][0..len]); |
| 437 | 437 | ||
| 438 | if (elements.len <= bpi - 1) { | 438 | if (elements.len <= bpi - 1) { |
| 439 | for (elements) |elem, i| { | 439 | for (elements, 0..) |elem, i| { |
| 440 | if (elem == operand_ref) return matchOperandSmallIndex(l, inst, @intCast(OperandInt, i), .none); | 440 | if (elem == operand_ref) return matchOperandSmallIndex(l, inst, @intCast(OperandInt, i), .none); |
| 441 | } | 441 | } |
| 442 | return .none; | 442 | return .none; |
| ... | @@ -1272,12 +1272,12 @@ fn analyzeInst( | ... | @@ -1272,12 +1272,12 @@ fn analyzeInst( |
| 1272 | defer for (case_deaths) |*cd| cd.deinit(gpa); | 1272 | defer for (case_deaths) |*cd| cd.deinit(gpa); |
| 1273 | 1273 | ||
| 1274 | var total_deaths: u32 = 0; | 1274 | var total_deaths: u32 = 0; |
| 1275 | for (case_tables) |*ct, i| { | 1275 | for (case_tables, 0..) |*ct, i| { |
| 1276 | total_deaths += ct.count(); | 1276 | total_deaths += ct.count(); |
| 1277 | var it = ct.keyIterator(); | 1277 | var it = ct.keyIterator(); |
| 1278 | while (it.next()) |key| { | 1278 | while (it.next()) |key| { |
| 1279 | const case_death = key.*; | 1279 | const case_death = key.*; |
| 1280 | for (case_tables) |*ct_inner, j| { | 1280 | for (case_tables, 0..) |*ct_inner, j| { |
| 1281 | if (i == j) continue; | 1281 | if (i == j) continue; |
| 1282 | if (!ct_inner.contains(case_death)) { | 1282 | if (!ct_inner.contains(case_death)) { |
| 1283 | // instruction is not referenced in this case | 1283 | // instruction is not referenced in this case |
src/Manifest.zig+1-1| ... | @@ -123,7 +123,7 @@ pub fn hexDigest(digest: [Hash.digest_length]u8) [multihash_len * 2]u8 { | ... | @@ -123,7 +123,7 @@ pub fn hexDigest(digest: [Hash.digest_length]u8) [multihash_len * 2]u8 { |
| 123 | result[2] = hex_charset[Hash.digest_length >> 4]; | 123 | result[2] = hex_charset[Hash.digest_length >> 4]; |
| 124 | result[3] = hex_charset[Hash.digest_length & 15]; | 124 | result[3] = hex_charset[Hash.digest_length & 15]; |
| 125 | 125 | ||
| 126 | for (digest) |byte, i| { | 126 | for (digest, 0..) |byte, i| { |
| 127 | result[4 + i * 2] = hex_charset[byte >> 4]; | 127 | result[4 + i * 2] = hex_charset[byte >> 4]; |
| 128 | result[5 + i * 2] = hex_charset[byte & 15]; | 128 | result[5 + i * 2] = hex_charset[byte & 15]; |
| 129 | } | 129 | } |
src/Module.zig+72-7| ... | @@ -268,7 +268,7 @@ pub const MemoizedCall = struct { | ... | @@ -268,7 +268,7 @@ pub const MemoizedCall = struct { |
| 268 | if (a.func != b.func) return false; | 268 | if (a.func != b.func) return false; |
| 269 | 269 | ||
| 270 | assert(a.args.len == b.args.len); | 270 | assert(a.args.len == b.args.len); |
| 271 | for (a.args) |a_arg, arg_i| { | 271 | for (a.args, 0..) |a_arg, arg_i| { |
| 272 | const b_arg = b.args[arg_i]; | 272 | const b_arg = b.args[arg_i]; |
| 273 | if (!a_arg.eql(b_arg, ctx.module)) { | 273 | if (!a_arg.eql(b_arg, ctx.module)) { |
| 274 | return false; | 274 | return false; |
| ... | @@ -1082,7 +1082,7 @@ pub const Struct = struct { | ... | @@ -1082,7 +1082,7 @@ pub const Struct = struct { |
| 1082 | assert(s.layout == .Packed); | 1082 | assert(s.layout == .Packed); |
| 1083 | assert(s.haveLayout()); | 1083 | assert(s.haveLayout()); |
| 1084 | var bit_sum: u64 = 0; | 1084 | var bit_sum: u64 = 0; |
| 1085 | for (s.fields.values()) |field, i| { | 1085 | for (s.fields.values(), 0..) |field, i| { |
| 1086 | if (i == index) { | 1086 | if (i == index) { |
| 1087 | return @intCast(u16, bit_sum); | 1087 | return @intCast(u16, bit_sum); |
| 1088 | } | 1088 | } |
| ... | @@ -1341,7 +1341,7 @@ pub const Union = struct { | ... | @@ -1341,7 +1341,7 @@ pub const Union = struct { |
| 1341 | assert(u.haveFieldTypes()); | 1341 | assert(u.haveFieldTypes()); |
| 1342 | var most_alignment: u32 = 0; | 1342 | var most_alignment: u32 = 0; |
| 1343 | var most_index: usize = undefined; | 1343 | var most_index: usize = undefined; |
| 1344 | for (u.fields.values()) |field, i| { | 1344 | for (u.fields.values(), 0..) |field, i| { |
| 1345 | if (!field.ty.hasRuntimeBits()) continue; | 1345 | if (!field.ty.hasRuntimeBits()) continue; |
| 1346 | 1346 | ||
| 1347 | const field_align = field.normalAlignment(target); | 1347 | const field_align = field.normalAlignment(target); |
| ... | @@ -1405,7 +1405,7 @@ pub const Union = struct { | ... | @@ -1405,7 +1405,7 @@ pub const Union = struct { |
| 1405 | var payload_size: u64 = 0; | 1405 | var payload_size: u64 = 0; |
| 1406 | var payload_align: u32 = 0; | 1406 | var payload_align: u32 = 0; |
| 1407 | const fields = u.fields.values(); | 1407 | const fields = u.fields.values(); |
| 1408 | for (fields) |field, i| { | 1408 | for (fields, 0..) |field, i| { |
| 1409 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; | 1409 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 1410 | 1410 | ||
| 1411 | const field_align = a: { | 1411 | const field_align = a: { |
| ... | @@ -2462,6 +2462,55 @@ pub const SrcLoc = struct { | ... | @@ -2462,6 +2462,55 @@ pub const SrcLoc = struct { |
| 2462 | }; | 2462 | }; |
| 2463 | return nodeToSpan(tree, src_node); | 2463 | return nodeToSpan(tree, src_node); |
| 2464 | }, | 2464 | }, |
| 2465 | .for_input => |for_input| { | ||
| 2466 | const tree = try src_loc.file_scope.getTree(gpa); | ||
| 2467 | const node = src_loc.declRelativeToNodeIndex(for_input.for_node_offset); | ||
| 2468 | const for_full = tree.fullFor(node).?; | ||
| 2469 | const src_node = for_full.ast.inputs[for_input.input_index]; | ||
| 2470 | return nodeToSpan(tree, src_node); | ||
| 2471 | }, | ||
| 2472 | .for_capture_from_input => |node_off| { | ||
| 2473 | const tree = try src_loc.file_scope.getTree(gpa); | ||
| 2474 | const token_tags = tree.tokens.items(.tag); | ||
| 2475 | const input_node = src_loc.declRelativeToNodeIndex(node_off); | ||
| 2476 | // We have to actually linear scan the whole AST to find the for loop | ||
| 2477 | // that contains this input. | ||
| 2478 | const node_tags = tree.nodes.items(.tag); | ||
| 2479 | for (node_tags, 0..) |node_tag, node_usize| { | ||
| 2480 | const node = @intCast(Ast.Node.Index, node_usize); | ||
| 2481 | switch (node_tag) { | ||
| 2482 | .for_simple, .@"for" => { | ||
| 2483 | const for_full = tree.fullFor(node).?; | ||
| 2484 | for (for_full.ast.inputs, 0..) |input, input_index| { | ||
| 2485 | if (input_node == input) { | ||
| 2486 | var count = input_index; | ||
| 2487 | var tok = for_full.payload_token; | ||
| 2488 | while (true) { | ||
| 2489 | switch (token_tags[tok]) { | ||
| 2490 | .comma => { | ||
| 2491 | count -= 1; | ||
| 2492 | tok += 1; | ||
| 2493 | }, | ||
| 2494 | .identifier => { | ||
| 2495 | if (count == 0) | ||
| 2496 | return tokensToSpan(tree, tok, tok + 1, tok); | ||
| 2497 | tok += 1; | ||
| 2498 | }, | ||
| 2499 | .asterisk => { | ||
| 2500 | if (count == 0) | ||
| 2501 | return tokensToSpan(tree, tok, tok + 2, tok); | ||
| 2502 | tok += 1; | ||
| 2503 | }, | ||
| 2504 | else => unreachable, | ||
| 2505 | } | ||
| 2506 | } | ||
| 2507 | } | ||
| 2508 | } | ||
| 2509 | }, | ||
| 2510 | else => continue, | ||
| 2511 | } | ||
| 2512 | } else unreachable; | ||
| 2513 | }, | ||
| 2465 | .node_offset_bin_lhs => |node_off| { | 2514 | .node_offset_bin_lhs => |node_off| { |
| 2466 | const tree = try src_loc.file_scope.getTree(gpa); | 2515 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2467 | const node = src_loc.declRelativeToNodeIndex(node_off); | 2516 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| ... | @@ -3114,6 +3163,20 @@ pub const LazySrcLoc = union(enum) { | ... | @@ -3114,6 +3163,20 @@ pub const LazySrcLoc = union(enum) { |
| 3114 | /// The source location points to the RHS of an assignment. | 3163 | /// The source location points to the RHS of an assignment. |
| 3115 | /// The Decl is determined contextually. | 3164 | /// The Decl is determined contextually. |
| 3116 | node_offset_store_operand: i32, | 3165 | node_offset_store_operand: i32, |
| 3166 | /// The source location points to a for loop input. | ||
| 3167 | /// The Decl is determined contextually. | ||
| 3168 | for_input: struct { | ||
| 3169 | /// Points to the for loop AST node. | ||
| 3170 | for_node_offset: i32, | ||
| 3171 | /// Picks one of the inputs from the condition. | ||
| 3172 | input_index: u32, | ||
| 3173 | }, | ||
| 3174 | /// The source location points to one of the captures of a for loop, found | ||
| 3175 | /// by taking this AST node index offset from the containing | ||
| 3176 | /// Decl AST node, which points to one of the input nodes of a for loop. | ||
| 3177 | /// Next, navigate to the corresponding capture. | ||
| 3178 | /// The Decl is determined contextually. | ||
| 3179 | for_capture_from_input: i32, | ||
| 3117 | 3180 | ||
| 3118 | pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease; | 3181 | pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease; |
| 3119 | 3182 | ||
| ... | @@ -3200,6 +3263,8 @@ pub const LazySrcLoc = union(enum) { | ... | @@ -3200,6 +3263,8 @@ pub const LazySrcLoc = union(enum) { |
| 3200 | .node_offset_init_ty, | 3263 | .node_offset_init_ty, |
| 3201 | .node_offset_store_ptr, | 3264 | .node_offset_store_ptr, |
| 3202 | .node_offset_store_operand, | 3265 | .node_offset_store_operand, |
| 3266 | .for_input, | ||
| 3267 | .for_capture_from_input, | ||
| 3203 | => .{ | 3268 | => .{ |
| 3204 | .file_scope = decl.getFileScope(), | 3269 | .file_scope = decl.getFileScope(), |
| 3205 | .parent_decl_node = decl.src_node, | 3270 | .parent_decl_node = decl.src_node, |
| ... | @@ -3553,7 +3618,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void { | ... | @@ -3553,7 +3618,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void { |
| 3553 | } | 3618 | } |
| 3554 | if (data_has_safety_tag) { | 3619 | if (data_has_safety_tag) { |
| 3555 | const tags = zir.instructions.items(.tag); | 3620 | const tags = zir.instructions.items(.tag); |
| 3556 | for (zir.instructions.items(.data)) |*data, i| { | 3621 | for (zir.instructions.items(.data), 0..) |*data, i| { |
| 3557 | const union_tag = Zir.Inst.Tag.data_tags[@enumToInt(tags[i])]; | 3622 | const union_tag = Zir.Inst.Tag.data_tags[@enumToInt(tags[i])]; |
| 3558 | const as_struct = @ptrCast(*HackDataLayout, data); | 3623 | const as_struct = @ptrCast(*HackDataLayout, data); |
| 3559 | as_struct.* = .{ | 3624 | as_struct.* = .{ |
| ... | @@ -3740,7 +3805,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void { | ... | @@ -3740,7 +3805,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void { |
| 3740 | @ptrCast([*]const u8, file.zir.instructions.items(.data).ptr); | 3805 | @ptrCast([*]const u8, file.zir.instructions.items(.data).ptr); |
| 3741 | if (data_has_safety_tag) { | 3806 | if (data_has_safety_tag) { |
| 3742 | // The `Data` union has a safety tag but in the file format we store it without. | 3807 | // The `Data` union has a safety tag but in the file format we store it without. |
| 3743 | for (file.zir.instructions.items(.data)) |*data, i| { | 3808 | for (file.zir.instructions.items(.data), 0..) |*data, i| { |
| 3744 | const as_struct = @ptrCast(*const HackDataLayout, data); | 3809 | const as_struct = @ptrCast(*const HackDataLayout, data); |
| 3745 | safety_buffer[i] = as_struct.data; | 3810 | safety_buffer[i] = as_struct.data; |
| 3746 | } | 3811 | } |
| ... | @@ -6293,7 +6358,7 @@ pub fn populateTestFunctions( | ... | @@ -6293,7 +6358,7 @@ pub fn populateTestFunctions( |
| 6293 | // Add a dependency on each test name and function pointer. | 6358 | // Add a dependency on each test name and function pointer. |
| 6294 | try array_decl.dependencies.ensureUnusedCapacity(gpa, test_fn_vals.len * 2); | 6359 | try array_decl.dependencies.ensureUnusedCapacity(gpa, test_fn_vals.len * 2); |
| 6295 | 6360 | ||
| 6296 | for (mod.test_functions.keys()) |test_decl_index, i| { | 6361 | for (mod.test_functions.keys(), 0..) |test_decl_index, i| { |
| 6297 | const test_decl = mod.declPtr(test_decl_index); | 6362 | const test_decl = mod.declPtr(test_decl_index); |
| 6298 | const test_name_slice = mem.sliceTo(test_decl.name, 0); | 6363 | const test_name_slice = mem.sliceTo(test_decl.name, 0); |
| 6299 | const test_name_decl_index = n: { | 6364 | const test_name_decl_index = n: { |
src/Package.zig+1-1| ... | @@ -207,7 +207,7 @@ pub fn fetchAndAddDependencies( | ... | @@ -207,7 +207,7 @@ pub fn fetchAndAddDependencies( |
| 207 | 207 | ||
| 208 | var any_error = false; | 208 | var any_error = false; |
| 209 | const deps_list = manifest.dependencies.values(); | 209 | const deps_list = manifest.dependencies.values(); |
| 210 | for (manifest.dependencies.keys()) |name, i| { | 210 | for (manifest.dependencies.keys(), 0..) |name, i| { |
| 211 | const dep = deps_list[i]; | 211 | const dep = deps_list[i]; |
| 212 | 212 | ||
| 213 | const sub_prefix = try std.fmt.allocPrint(arena, "{s}{s}.", .{ name_prefix, name }); | 213 | const sub_prefix = try std.fmt.allocPrint(arena, "{s}{s}.", .{ name_prefix, name }); |
src/RangeSet.zig+1-1| ... | @@ -79,7 +79,7 @@ pub fn spans(self: *RangeSet, first: Value, last: Value, ty: Type) !bool { | ... | @@ -79,7 +79,7 @@ pub fn spans(self: *RangeSet, first: Value, last: Value, ty: Type) !bool { |
| 79 | const target = self.module.getTarget(); | 79 | const target = self.module.getTarget(); |
| 80 | 80 | ||
| 81 | // look for gaps | 81 | // look for gaps |
| 82 | for (self.ranges.items[1..]) |cur, i| { | 82 | for (self.ranges.items[1..], 0..) |cur, i| { |
| 83 | // i starts counting from the second item. | 83 | // i starts counting from the second item. |
| 84 | const prev = self.ranges.items[i]; | 84 | const prev = self.ranges.items[i]; |
| 85 | 85 |
src/Sema.zig+334-175| ... | @@ -1035,6 +1035,7 @@ fn analyzeBodyInner( | ... | @@ -1035,6 +1035,7 @@ fn analyzeBodyInner( |
| 1035 | .@"await" => try sema.zirAwait(block, inst), | 1035 | .@"await" => try sema.zirAwait(block, inst), |
| 1036 | .array_base_ptr => try sema.zirArrayBasePtr(block, inst), | 1036 | .array_base_ptr => try sema.zirArrayBasePtr(block, inst), |
| 1037 | .field_base_ptr => try sema.zirFieldBasePtr(block, inst), | 1037 | .field_base_ptr => try sema.zirFieldBasePtr(block, inst), |
| 1038 | .for_len => try sema.zirForLen(block, inst), | ||
| 1038 | 1039 | ||
| 1039 | .clz => try sema.zirBitCount(block, inst, .clz, Value.clz), | 1040 | .clz => try sema.zirBitCount(block, inst, .clz, Value.clz), |
| 1040 | .ctz => try sema.zirBitCount(block, inst, .ctz, Value.ctz), | 1041 | .ctz => try sema.zirBitCount(block, inst, .ctz, Value.ctz), |
| ... | @@ -1059,15 +1060,16 @@ fn analyzeBodyInner( | ... | @@ -1059,15 +1060,16 @@ fn analyzeBodyInner( |
| 1059 | .error_set_decl_anon => try sema.zirErrorSetDecl(block, inst, .anon), | 1060 | .error_set_decl_anon => try sema.zirErrorSetDecl(block, inst, .anon), |
| 1060 | .error_set_decl_func => try sema.zirErrorSetDecl(block, inst, .func), | 1061 | .error_set_decl_func => try sema.zirErrorSetDecl(block, inst, .func), |
| 1061 | 1062 | ||
| 1062 | .add => try sema.zirArithmetic(block, inst, .add), | 1063 | .add => try sema.zirArithmetic(block, inst, .add, true), |
| 1063 | .addwrap => try sema.zirArithmetic(block, inst, .addwrap), | 1064 | .addwrap => try sema.zirArithmetic(block, inst, .addwrap, true), |
| 1064 | .add_sat => try sema.zirArithmetic(block, inst, .add_sat), | 1065 | .add_sat => try sema.zirArithmetic(block, inst, .add_sat, true), |
| 1065 | .mul => try sema.zirArithmetic(block, inst, .mul), | 1066 | .add_unsafe=> try sema.zirArithmetic(block, inst, .add_unsafe, false), |
| 1066 | .mulwrap => try sema.zirArithmetic(block, inst, .mulwrap), | 1067 | .mul => try sema.zirArithmetic(block, inst, .mul, true), |
| 1067 | .mul_sat => try sema.zirArithmetic(block, inst, .mul_sat), | 1068 | .mulwrap => try sema.zirArithmetic(block, inst, .mulwrap, true), |
| 1068 | .sub => try sema.zirArithmetic(block, inst, .sub), | 1069 | .mul_sat => try sema.zirArithmetic(block, inst, .mul_sat, true), |
| 1069 | .subwrap => try sema.zirArithmetic(block, inst, .subwrap), | 1070 | .sub => try sema.zirArithmetic(block, inst, .sub, true), |
| 1070 | .sub_sat => try sema.zirArithmetic(block, inst, .sub_sat), | 1071 | .subwrap => try sema.zirArithmetic(block, inst, .subwrap, true), |
| 1072 | .sub_sat => try sema.zirArithmetic(block, inst, .sub_sat, true), | ||
| 1071 | 1073 | ||
| 1072 | .div => try sema.zirDiv(block, inst), | 1074 | .div => try sema.zirDiv(block, inst), |
| 1073 | .div_exact => try sema.zirDivExact(block, inst), | 1075 | .div_exact => try sema.zirDivExact(block, inst), |
| ... | @@ -3377,26 +3379,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3377,26 +3379,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 3377 | else | 3379 | else |
| 3378 | object_ty; | 3380 | object_ty; |
| 3379 | 3381 | ||
| 3380 | if (!array_ty.isIndexable()) { | 3382 | try checkIndexable(sema, block, src, array_ty); |
| 3381 | const msg = msg: { | ||
| 3382 | const msg = try sema.errMsg( | ||
| 3383 | block, | ||
| 3384 | src, | ||
| 3385 | "type '{}' does not support indexing", | ||
| 3386 | .{array_ty.fmt(sema.mod)}, | ||
| 3387 | ); | ||
| 3388 | errdefer msg.destroy(sema.gpa); | ||
| 3389 | try sema.errNote( | ||
| 3390 | block, | ||
| 3391 | src, | ||
| 3392 | msg, | ||
| 3393 | "for loop operand must be an array, slice, tuple, or vector", | ||
| 3394 | .{}, | ||
| 3395 | ); | ||
| 3396 | break :msg msg; | ||
| 3397 | }; | ||
| 3398 | return sema.failWithOwnedErrorMsg(msg); | ||
| 3399 | } | ||
| 3400 | 3383 | ||
| 3401 | return sema.fieldVal(block, src, object, "len", src); | 3384 | return sema.fieldVal(block, src, object, "len", src); |
| 3402 | } | 3385 | } |
| ... | @@ -3819,7 +3802,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -3819,7 +3802,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3819 | const dummy_ptr = try trash_block.addTy(.alloc, mut_final_ptr_ty); | 3802 | const dummy_ptr = try trash_block.addTy(.alloc, mut_final_ptr_ty); |
| 3820 | const empty_trash_count = trash_block.instructions.items.len; | 3803 | const empty_trash_count = trash_block.instructions.items.len; |
| 3821 | 3804 | ||
| 3822 | for (placeholders) |bitcast_inst, i| { | 3805 | for (placeholders, 0..) |bitcast_inst, i| { |
| 3823 | const sub_ptr_ty = sema.typeOf(Air.indexToRef(bitcast_inst)); | 3806 | const sub_ptr_ty = sema.typeOf(Air.indexToRef(bitcast_inst)); |
| 3824 | 3807 | ||
| 3825 | if (mut_final_ptr_ty.eql(sub_ptr_ty, sema.mod)) { | 3808 | if (mut_final_ptr_ty.eql(sub_ptr_ty, sema.mod)) { |
| ... | @@ -3919,6 +3902,121 @@ fn zirFieldBasePtr( | ... | @@ -3919,6 +3902,121 @@ fn zirFieldBasePtr( |
| 3919 | return sema.failWithStructInitNotSupported(block, src, sema.typeOf(start_ptr).childType()); | 3902 | return sema.failWithStructInitNotSupported(block, src, sema.typeOf(start_ptr).childType()); |
| 3920 | } | 3903 | } |
| 3921 | 3904 | ||
| 3905 | fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | ||
| 3906 | const gpa = sema.gpa; | ||
| 3907 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | ||
| 3908 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | ||
| 3909 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); | ||
| 3910 | const src = inst_data.src(); | ||
| 3911 | |||
| 3912 | var len: Air.Inst.Ref = .none; | ||
| 3913 | var len_val: ?Value = null; | ||
| 3914 | var len_idx: u32 = undefined; | ||
| 3915 | var any_runtime = false; | ||
| 3916 | |||
| 3917 | const runtime_arg_lens = try gpa.alloc(Air.Inst.Ref, args.len); | ||
| 3918 | defer gpa.free(runtime_arg_lens); | ||
| 3919 | |||
| 3920 | // First pass to look for comptime values. | ||
| 3921 | for (args, 0..) |zir_arg, i_usize| { | ||
| 3922 | const i = @intCast(u32, i_usize); | ||
| 3923 | runtime_arg_lens[i] = .none; | ||
| 3924 | if (zir_arg == .none) continue; | ||
| 3925 | const object = try sema.resolveInst(zir_arg); | ||
| 3926 | const object_ty = sema.typeOf(object); | ||
| 3927 | // Each arg could be an indexable, or a range, in which case the length | ||
| 3928 | // is passed directly as an integer. | ||
| 3929 | const is_int = switch (object_ty.zigTypeTag()) { | ||
| 3930 | .Int, .ComptimeInt => true, | ||
| 3931 | else => false, | ||
| 3932 | }; | ||
| 3933 | const arg_src: LazySrcLoc = .{ .for_input = .{ | ||
| 3934 | .for_node_offset = inst_data.src_node, | ||
| 3935 | .input_index = i, | ||
| 3936 | } }; | ||
| 3937 | const arg_len_uncoerced = if (is_int) object else l: { | ||
| 3938 | try checkIndexable(sema, block, arg_src, object_ty); | ||
| 3939 | if (!object_ty.indexableHasLen()) continue; | ||
| 3940 | |||
| 3941 | break :l try sema.fieldVal(block, arg_src, object, "len", arg_src); | ||
| 3942 | }; | ||
| 3943 | const arg_len = try sema.coerce(block, Type.usize, arg_len_uncoerced, arg_src); | ||
| 3944 | if (len == .none) { | ||
| 3945 | len = arg_len; | ||
| 3946 | len_idx = i; | ||
| 3947 | } | ||
| 3948 | if (try sema.resolveDefinedValue(block, src, arg_len)) |arg_val| { | ||
| 3949 | if (len_val) |v| { | ||
| 3950 | if (!(try sema.valuesEqual(arg_val, v, Type.usize))) { | ||
| 3951 | const msg = msg: { | ||
| 3952 | const msg = try sema.errMsg(block, src, "non-matching for loop lengths", .{}); | ||
| 3953 | errdefer msg.destroy(gpa); | ||
| 3954 | const a_src: LazySrcLoc = .{ .for_input = .{ | ||
| 3955 | .for_node_offset = inst_data.src_node, | ||
| 3956 | .input_index = len_idx, | ||
| 3957 | } }; | ||
| 3958 | try sema.errNote(block, a_src, msg, "length {} here", .{ | ||
| 3959 | v.fmtValue(Type.usize, sema.mod), | ||
| 3960 | }); | ||
| 3961 | try sema.errNote(block, arg_src, msg, "length {} here", .{ | ||
| 3962 | arg_val.fmtValue(Type.usize, sema.mod), | ||
| 3963 | }); | ||
| 3964 | break :msg msg; | ||
| 3965 | }; | ||
| 3966 | return sema.failWithOwnedErrorMsg(msg); | ||
| 3967 | } | ||
| 3968 | } else { | ||
| 3969 | len = arg_len; | ||
| 3970 | len_val = arg_val; | ||
| 3971 | len_idx = i; | ||
| 3972 | } | ||
| 3973 | continue; | ||
| 3974 | } | ||
| 3975 | runtime_arg_lens[i] = arg_len; | ||
| 3976 | any_runtime = true; | ||
| 3977 | } | ||
| 3978 | |||
| 3979 | if (len == .none) { | ||
| 3980 | const msg = msg: { | ||
| 3981 | const msg = try sema.errMsg(block, src, "unbounded for loop", .{}); | ||
| 3982 | errdefer msg.destroy(gpa); | ||
| 3983 | for (args, 0..) |zir_arg, i_usize| { | ||
| 3984 | const i = @intCast(u32, i_usize); | ||
| 3985 | if (zir_arg == .none) continue; | ||
| 3986 | const object = try sema.resolveInst(zir_arg); | ||
| 3987 | const object_ty = sema.typeOf(object); | ||
| 3988 | // Each arg could be an indexable, or a range, in which case the length | ||
| 3989 | // is passed directly as an integer. | ||
| 3990 | switch (object_ty.zigTypeTag()) { | ||
| 3991 | .Int, .ComptimeInt => continue, | ||
| 3992 | else => {}, | ||
| 3993 | } | ||
| 3994 | const arg_src: LazySrcLoc = .{ .for_input = .{ | ||
| 3995 | .for_node_offset = inst_data.src_node, | ||
| 3996 | .input_index = i, | ||
| 3997 | } }; | ||
| 3998 | try sema.errNote(block, arg_src, msg, "type '{}' has no upper bound", .{ | ||
| 3999 | object_ty.fmt(sema.mod), | ||
| 4000 | }); | ||
| 4001 | } | ||
| 4002 | break :msg msg; | ||
| 4003 | }; | ||
| 4004 | return sema.failWithOwnedErrorMsg(msg); | ||
| 4005 | } | ||
| 4006 | |||
| 4007 | // Now for the runtime checks. | ||
| 4008 | if (any_runtime and block.wantSafety()) { | ||
| 4009 | for (runtime_arg_lens, 0..) |arg_len, i| { | ||
| 4010 | if (arg_len == .none) continue; | ||
| 4011 | if (i == len_idx) continue; | ||
| 4012 | const ok = try block.addBinOp(.cmp_eq, len, arg_len); | ||
| 4013 | try sema.addSafetyCheck(block, ok, .for_len_mismatch); | ||
| 4014 | } | ||
| 4015 | } | ||
| 4016 | |||
| 4017 | return len; | ||
| 4018 | } | ||
| 4019 | |||
| 3922 | fn validateArrayInitTy( | 4020 | fn validateArrayInitTy( |
| 3923 | sema: *Sema, | 4021 | sema: *Sema, |
| 3924 | block: *Block, | 4022 | block: *Block, |
| ... | @@ -4198,7 +4296,7 @@ fn validateStructInit( | ... | @@ -4198,7 +4296,7 @@ fn validateStructInit( |
| 4198 | // In this case the only thing we need to do is evaluate the implicit | 4296 | // In this case the only thing we need to do is evaluate the implicit |
| 4199 | // store instructions for default field values, and report any missing fields. | 4297 | // store instructions for default field values, and report any missing fields. |
| 4200 | // Avoid the cost of the extra machinery for detecting a comptime struct init value. | 4298 | // Avoid the cost of the extra machinery for detecting a comptime struct init value. |
| 4201 | for (found_fields) |field_ptr, i| { | 4299 | for (found_fields, 0..) |field_ptr, i| { |
| 4202 | if (field_ptr != 0) continue; | 4300 | if (field_ptr != 0) continue; |
| 4203 | 4301 | ||
| 4204 | const default_val = struct_ty.structFieldDefaultValue(i); | 4302 | const default_val = struct_ty.structFieldDefaultValue(i); |
| ... | @@ -4264,7 +4362,7 @@ fn validateStructInit( | ... | @@ -4264,7 +4362,7 @@ fn validateStructInit( |
| 4264 | // ends up being comptime-known. | 4362 | // ends up being comptime-known. |
| 4265 | const field_values = try sema.arena.alloc(Value, struct_ty.structFieldCount()); | 4363 | const field_values = try sema.arena.alloc(Value, struct_ty.structFieldCount()); |
| 4266 | 4364 | ||
| 4267 | field: for (found_fields) |field_ptr, i| { | 4365 | field: for (found_fields, 0..) |field_ptr, i| { |
| 4268 | if (field_ptr != 0) { | 4366 | if (field_ptr != 0) { |
| 4269 | // Determine whether the value stored to this pointer is comptime-known. | 4367 | // Determine whether the value stored to this pointer is comptime-known. |
| 4270 | const field_ty = struct_ty.structFieldType(i); | 4368 | const field_ty = struct_ty.structFieldType(i); |
| ... | @@ -4397,7 +4495,7 @@ fn validateStructInit( | ... | @@ -4397,7 +4495,7 @@ fn validateStructInit( |
| 4397 | try sema.resolveStructLayout(struct_ty); | 4495 | try sema.resolveStructLayout(struct_ty); |
| 4398 | 4496 | ||
| 4399 | // Our task is to insert `store` instructions for all the default field values. | 4497 | // Our task is to insert `store` instructions for all the default field values. |
| 4400 | for (found_fields) |field_ptr, i| { | 4498 | for (found_fields, 0..) |field_ptr, i| { |
| 4401 | if (field_ptr != 0) continue; | 4499 | if (field_ptr != 0) continue; |
| 4402 | 4500 | ||
| 4403 | const field_src = init_src; // TODO better source location | 4501 | const field_src = init_src; // TODO better source location |
| ... | @@ -4472,7 +4570,7 @@ fn zirValidateArrayInit( | ... | @@ -4472,7 +4570,7 @@ fn zirValidateArrayInit( |
| 4472 | // any ZIR instructions at comptime; we need to do that here. | 4570 | // any ZIR instructions at comptime; we need to do that here. |
| 4473 | if (array_ty.sentinel()) |sentinel_val| { | 4571 | if (array_ty.sentinel()) |sentinel_val| { |
| 4474 | const array_len_ref = try sema.addIntUnsigned(Type.usize, array_len); | 4572 | const array_len_ref = try sema.addIntUnsigned(Type.usize, array_len); |
| 4475 | const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true); | 4573 | const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true, true); |
| 4476 | const sentinel = try sema.addConstant(array_ty.childType(), sentinel_val); | 4574 | const sentinel = try sema.addConstant(array_ty.childType(), sentinel_val); |
| 4477 | try sema.storePtr2(block, init_src, sentinel_ptr, init_src, sentinel, init_src, .store); | 4575 | try sema.storePtr2(block, init_src, sentinel_ptr, init_src, sentinel, init_src, .store); |
| 4478 | } | 4576 | } |
| ... | @@ -4491,7 +4589,7 @@ fn zirValidateArrayInit( | ... | @@ -4491,7 +4589,7 @@ fn zirValidateArrayInit( |
| 4491 | const air_tags = sema.air_instructions.items(.tag); | 4589 | const air_tags = sema.air_instructions.items(.tag); |
| 4492 | const air_datas = sema.air_instructions.items(.data); | 4590 | const air_datas = sema.air_instructions.items(.data); |
| 4493 | 4591 | ||
| 4494 | outer: for (instrs) |elem_ptr, i| { | 4592 | outer: for (instrs, 0..) |elem_ptr, i| { |
| 4495 | // Determine whether the value stored to this pointer is comptime-known. | 4593 | // Determine whether the value stored to this pointer is comptime-known. |
| 4496 | 4594 | ||
| 4497 | if (array_ty.isTuple()) { | 4595 | if (array_ty.isTuple()) { |
| ... | @@ -5010,7 +5108,7 @@ fn zirCompileLog( | ... | @@ -5010,7 +5108,7 @@ fn zirCompileLog( |
| 5010 | const src_node = extra.data.src_node; | 5108 | const src_node = extra.data.src_node; |
| 5011 | const args = sema.code.refSlice(extra.end, extended.small); | 5109 | const args = sema.code.refSlice(extra.end, extended.small); |
| 5012 | 5110 | ||
| 5013 | for (args) |arg_ref, i| { | 5111 | for (args, 0..) |arg_ref, i| { |
| 5014 | if (i != 0) try writer.print(", ", .{}); | 5112 | if (i != 0) try writer.print(", ", .{}); |
| 5015 | 5113 | ||
| 5016 | const arg = try sema.resolveInst(arg_ref); | 5114 | const arg = try sema.resolveInst(arg_ref); |
| ... | @@ -6228,7 +6326,7 @@ const GenericCallAdapter = struct { | ... | @@ -6228,7 +6326,7 @@ const GenericCallAdapter = struct { |
| 6228 | if (ctx.generic_fn.owner_decl != other_key.generic_owner_decl.unwrap().?) return false; | 6326 | if (ctx.generic_fn.owner_decl != other_key.generic_owner_decl.unwrap().?) return false; |
| 6229 | 6327 | ||
| 6230 | const other_comptime_args = other_key.comptime_args.?; | 6328 | const other_comptime_args = other_key.comptime_args.?; |
| 6231 | for (other_comptime_args[0..ctx.func_ty_info.param_types.len]) |other_arg, i| { | 6329 | for (other_comptime_args[0..ctx.func_ty_info.param_types.len], 0..) |other_arg, i| { |
| 6232 | const this_arg = ctx.args[i]; | 6330 | const this_arg = ctx.args[i]; |
| 6233 | const this_is_comptime = this_arg.val.tag() != .generic_poison; | 6331 | const this_is_comptime = this_arg.val.tag() != .generic_poison; |
| 6234 | const other_is_comptime = other_arg.val.tag() != .generic_poison; | 6332 | const other_is_comptime = other_arg.val.tag() != .generic_poison; |
| ... | @@ -6744,7 +6842,7 @@ fn analyzeCall( | ... | @@ -6744,7 +6842,7 @@ fn analyzeCall( |
| 6744 | assert(!func_ty_info.is_generic); | 6842 | assert(!func_ty_info.is_generic); |
| 6745 | 6843 | ||
| 6746 | const args = try sema.arena.alloc(Air.Inst.Ref, uncasted_args.len); | 6844 | const args = try sema.arena.alloc(Air.Inst.Ref, uncasted_args.len); |
| 6747 | for (uncasted_args) |uncasted_arg, i| { | 6845 | for (uncasted_args, 0..) |uncasted_arg, i| { |
| 6748 | if (i < fn_params_len) { | 6846 | if (i < fn_params_len) { |
| 6749 | const opts: CoerceOpts = .{ .param_src = .{ | 6847 | const opts: CoerceOpts = .{ .param_src = .{ |
| 6750 | .func_inst = func, | 6848 | .func_inst = func, |
| ... | @@ -7519,7 +7617,7 @@ fn resolveGenericInstantiationType( | ... | @@ -7519,7 +7617,7 @@ fn resolveGenericInstantiationType( |
| 7519 | fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void { | 7617 | fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void { |
| 7520 | if (!ty.isSimpleTupleOrAnonStruct()) return; | 7618 | if (!ty.isSimpleTupleOrAnonStruct()) return; |
| 7521 | const tuple = ty.tupleFields(); | 7619 | const tuple = ty.tupleFields(); |
| 7522 | for (tuple.values) |field_val, i| { | 7620 | for (tuple.values, 0..) |field_val, i| { |
| 7523 | try sema.resolveTupleLazyValues(block, src, tuple.types[i]); | 7621 | try sema.resolveTupleLazyValues(block, src, tuple.types[i]); |
| 7524 | if (field_val.tag() == .unreachable_value) continue; | 7622 | if (field_val.tag() == .unreachable_value) continue; |
| 7525 | try sema.resolveLazyValue(field_val); | 7623 | try sema.resolveLazyValue(field_val); |
| ... | @@ -8593,7 +8691,7 @@ fn funcCommon( | ... | @@ -8593,7 +8691,7 @@ fn funcCommon( |
| 8593 | const cc_resolved = cc orelse .Unspecified; | 8691 | const cc_resolved = cc orelse .Unspecified; |
| 8594 | const param_types = try sema.arena.alloc(Type, block.params.items.len); | 8692 | const param_types = try sema.arena.alloc(Type, block.params.items.len); |
| 8595 | const comptime_params = try sema.arena.alloc(bool, block.params.items.len); | 8693 | const comptime_params = try sema.arena.alloc(bool, block.params.items.len); |
| 8596 | for (block.params.items) |param, i| { | 8694 | for (block.params.items, 0..) |param, i| { |
| 8597 | const is_noalias = blk: { | 8695 | const is_noalias = blk: { |
| 8598 | const index = std.math.cast(u5, i) orelse break :blk false; | 8696 | const index = std.math.cast(u5, i) orelse break :blk false; |
| 8599 | break :blk @truncate(u1, noalias_bits >> index) != 0; | 8697 | break :blk @truncate(u1, noalias_bits >> index) != 0; |
| ... | @@ -8702,7 +8800,7 @@ fn funcCommon( | ... | @@ -8702,7 +8800,7 @@ fn funcCommon( |
| 8702 | const tags = sema.code.instructions.items(.tag); | 8800 | const tags = sema.code.instructions.items(.tag); |
| 8703 | const data = sema.code.instructions.items(.data); | 8801 | const data = sema.code.instructions.items(.data); |
| 8704 | const param_body = sema.code.getParamBody(func_inst); | 8802 | const param_body = sema.code.getParamBody(func_inst); |
| 8705 | for (block.params.items) |param, i| { | 8803 | for (block.params.items, 0..) |param, i| { |
| 8706 | if (!param.is_comptime) { | 8804 | if (!param.is_comptime) { |
| 8707 | const param_index = param_body[i]; | 8805 | const param_index = param_body[i]; |
| 8708 | const param_src = switch (tags[param_index]) { | 8806 | const param_src = switch (tags[param_index]) { |
| ... | @@ -9619,7 +9717,7 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9619,7 +9717,7 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9619 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 9717 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 9620 | const array = try sema.resolveInst(extra.lhs); | 9718 | const array = try sema.resolveInst(extra.lhs); |
| 9621 | const elem_index = try sema.resolveInst(extra.rhs); | 9719 | const elem_index = try sema.resolveInst(extra.rhs); |
| 9622 | return sema.elemVal(block, src, array, elem_index, src); | 9720 | return sema.elemVal(block, src, array, elem_index, src, false); |
| 9623 | } | 9721 | } |
| 9624 | 9722 | ||
| 9625 | fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9723 | fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -9632,7 +9730,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -9632,7 +9730,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 9632 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 9730 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 9633 | const array = try sema.resolveInst(extra.lhs); | 9731 | const array = try sema.resolveInst(extra.lhs); |
| 9634 | const elem_index = try sema.resolveInst(extra.rhs); | 9732 | const elem_index = try sema.resolveInst(extra.rhs); |
| 9635 | return sema.elemVal(block, src, array, elem_index, elem_index_src); | 9733 | return sema.elemVal(block, src, array, elem_index, elem_index_src, true); |
| 9636 | } | 9734 | } |
| 9637 | 9735 | ||
| 9638 | fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9736 | fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -9644,7 +9742,22 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9644,7 +9742,22 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9644 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 9742 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 9645 | const array_ptr = try sema.resolveInst(extra.lhs); | 9743 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 9646 | const elem_index = try sema.resolveInst(extra.rhs); | 9744 | const elem_index = try sema.resolveInst(extra.rhs); |
| 9647 | return sema.elemPtr(block, src, array_ptr, elem_index, src, false); | 9745 | const indexable_ty = sema.typeOf(array_ptr); |
| 9746 | if (indexable_ty.zigTypeTag() != .Pointer) { | ||
| 9747 | const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node }; | ||
| 9748 | const msg = msg: { | ||
| 9749 | const msg = try sema.errMsg(block, capture_src, "pointer capture of non pointer type '{}'", .{ | ||
| 9750 | indexable_ty.fmt(sema.mod), | ||
| 9751 | }); | ||
| 9752 | errdefer msg.destroy(sema.gpa); | ||
| 9753 | if (indexable_ty.zigTypeTag() == .Array) { | ||
| 9754 | try sema.errNote(block, src, msg, "consider using '&' here", .{}); | ||
| 9755 | } | ||
| 9756 | break :msg msg; | ||
| 9757 | }; | ||
| 9758 | return sema.failWithOwnedErrorMsg(msg); | ||
| 9759 | } | ||
| 9760 | return sema.elemPtrOneLayerOnly(block, src, array_ptr, elem_index, src, false, false); | ||
| 9648 | } | 9761 | } |
| 9649 | 9762 | ||
| 9650 | fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9763 | fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -9657,7 +9770,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -9657,7 +9770,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 9657 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 9770 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 9658 | const array_ptr = try sema.resolveInst(extra.lhs); | 9771 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 9659 | const elem_index = try sema.resolveInst(extra.rhs); | 9772 | const elem_index = try sema.resolveInst(extra.rhs); |
| 9660 | return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src, false); | 9773 | return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src, false, true); |
| 9661 | } | 9774 | } |
| 9662 | 9775 | ||
| 9663 | fn zirElemPtrImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9776 | fn zirElemPtrImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -9669,7 +9782,7 @@ fn zirElemPtrImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -9669,7 +9782,7 @@ fn zirElemPtrImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 9669 | const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; | 9782 | const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; |
| 9670 | const array_ptr = try sema.resolveInst(extra.ptr); | 9783 | const array_ptr = try sema.resolveInst(extra.ptr); |
| 9671 | const elem_index = try sema.addIntUnsigned(Type.usize, extra.index); | 9784 | const elem_index = try sema.addIntUnsigned(Type.usize, extra.index); |
| 9672 | return sema.elemPtr(block, src, array_ptr, elem_index, src, true); | 9785 | return sema.elemPtr(block, src, array_ptr, elem_index, src, true, true); |
| 9673 | } | 9786 | } |
| 9674 | 9787 | ||
| 9675 | fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9788 | fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -9801,7 +9914,7 @@ fn zirSwitchCapture( | ... | @@ -9801,7 +9914,7 @@ fn zirSwitchCapture( |
| 9801 | const first_field_index = @intCast(u32, operand_ty.unionTagFieldIndex(first_item_val, sema.mod).?); | 9914 | const first_field_index = @intCast(u32, operand_ty.unionTagFieldIndex(first_item_val, sema.mod).?); |
| 9802 | const first_field = union_obj.fields.values()[first_field_index]; | 9915 | const first_field = union_obj.fields.values()[first_field_index]; |
| 9803 | 9916 | ||
| 9804 | for (items[1..]) |item, i| { | 9917 | for (items[1..], 0..) |item, i| { |
| 9805 | const item_ref = try sema.resolveInst(item); | 9918 | const item_ref = try sema.resolveInst(item); |
| 9806 | // Previous switch validation ensured this will succeed | 9919 | // Previous switch validation ensured this will succeed |
| 9807 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref, "") catch unreachable; | 9920 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref, "") catch unreachable; |
| ... | @@ -10131,7 +10244,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10131,7 +10244,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10131 | const items = sema.code.refSlice(extra_index, items_len); | 10244 | const items = sema.code.refSlice(extra_index, items_len); |
| 10132 | extra_index += items_len + body_len; | 10245 | extra_index += items_len + body_len; |
| 10133 | 10246 | ||
| 10134 | for (items) |item_ref, item_i| { | 10247 | for (items, 0..) |item_ref, item_i| { |
| 10135 | try sema.validateSwitchItemEnum( | 10248 | try sema.validateSwitchItemEnum( |
| 10136 | block, | 10249 | block, |
| 10137 | seen_enum_fields, | 10250 | seen_enum_fields, |
| ... | @@ -10165,7 +10278,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10165,7 +10278,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10165 | .{}, | 10278 | .{}, |
| 10166 | ); | 10279 | ); |
| 10167 | errdefer msg.destroy(sema.gpa); | 10280 | errdefer msg.destroy(sema.gpa); |
| 10168 | for (seen_enum_fields) |seen_src, i| { | 10281 | for (seen_enum_fields, 0..) |seen_src, i| { |
| 10169 | if (seen_src != null) continue; | 10282 | if (seen_src != null) continue; |
| 10170 | 10283 | ||
| 10171 | const field_name = operand_ty.enumFieldName(i); | 10284 | const field_name = operand_ty.enumFieldName(i); |
| ... | @@ -10227,7 +10340,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10227,7 +10340,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10227 | const items = sema.code.refSlice(extra_index, items_len); | 10340 | const items = sema.code.refSlice(extra_index, items_len); |
| 10228 | extra_index += items_len + body_len; | 10341 | extra_index += items_len + body_len; |
| 10229 | 10342 | ||
| 10230 | for (items) |item_ref, item_i| { | 10343 | for (items, 0..) |item_ref, item_i| { |
| 10231 | try sema.validateSwitchItemError( | 10344 | try sema.validateSwitchItemError( |
| 10232 | block, | 10345 | block, |
| 10233 | &seen_errors, | 10346 | &seen_errors, |
| ... | @@ -10369,7 +10482,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10369,7 +10482,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10369 | const items = sema.code.refSlice(extra_index, items_len); | 10482 | const items = sema.code.refSlice(extra_index, items_len); |
| 10370 | extra_index += items_len; | 10483 | extra_index += items_len; |
| 10371 | 10484 | ||
| 10372 | for (items) |item_ref, item_i| { | 10485 | for (items, 0..) |item_ref, item_i| { |
| 10373 | try sema.validateSwitchItem( | 10486 | try sema.validateSwitchItem( |
| 10374 | block, | 10487 | block, |
| 10375 | &range_set, | 10488 | &range_set, |
| ... | @@ -10464,7 +10577,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10464,7 +10577,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10464 | const items = sema.code.refSlice(extra_index, items_len); | 10577 | const items = sema.code.refSlice(extra_index, items_len); |
| 10465 | extra_index += items_len + body_len; | 10578 | extra_index += items_len + body_len; |
| 10466 | 10579 | ||
| 10467 | for (items) |item_ref, item_i| { | 10580 | for (items, 0..) |item_ref, item_i| { |
| 10468 | try sema.validateSwitchItemBool( | 10581 | try sema.validateSwitchItemBool( |
| 10469 | block, | 10582 | block, |
| 10470 | &true_count, | 10583 | &true_count, |
| ... | @@ -10548,7 +10661,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10548,7 +10661,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10548 | const items = sema.code.refSlice(extra_index, items_len); | 10661 | const items = sema.code.refSlice(extra_index, items_len); |
| 10549 | extra_index += items_len + body_len; | 10662 | extra_index += items_len + body_len; |
| 10550 | 10663 | ||
| 10551 | for (items) |item_ref, item_i| { | 10664 | for (items, 0..) |item_ref, item_i| { |
| 10552 | try sema.validateSwitchItemSparse( | 10665 | try sema.validateSwitchItemSparse( |
| 10553 | block, | 10666 | block, |
| 10554 | &seen_values, | 10667 | &seen_values, |
| ... | @@ -10859,7 +10972,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10859,7 +10972,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10859 | } | 10972 | } |
| 10860 | } | 10973 | } |
| 10861 | 10974 | ||
| 10862 | for (items) |item_ref, item_i| { | 10975 | for (items, 0..) |item_ref, item_i| { |
| 10863 | cases_len += 1; | 10976 | cases_len += 1; |
| 10864 | 10977 | ||
| 10865 | const item = try sema.resolveInst(item_ref); | 10978 | const item = try sema.resolveInst(item_ref); |
| ... | @@ -11045,7 +11158,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -11045,7 +11158,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 11045 | operand_ty.fmt(sema.mod), | 11158 | operand_ty.fmt(sema.mod), |
| 11046 | }); | 11159 | }); |
| 11047 | } | 11160 | } |
| 11048 | for (seen_enum_fields) |f, i| { | 11161 | for (seen_enum_fields, 0..) |f, i| { |
| 11049 | if (f != null) continue; | 11162 | if (f != null) continue; |
| 11050 | cases_len += 1; | 11163 | cases_len += 1; |
| 11051 | 11164 | ||
| ... | @@ -11188,7 +11301,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -11188,7 +11301,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 11188 | } | 11301 | } |
| 11189 | 11302 | ||
| 11190 | const analyze_body = if (union_originally and !special.is_inline) | 11303 | const analyze_body = if (union_originally and !special.is_inline) |
| 11191 | for (seen_enum_fields) |seen_field, index| { | 11304 | for (seen_enum_fields, 0..) |seen_field, index| { |
| 11192 | if (seen_field != null) continue; | 11305 | if (seen_field != null) continue; |
| 11193 | const union_obj = maybe_union_ty.cast(Type.Payload.Union).?.data; | 11306 | const union_obj = maybe_union_ty.cast(Type.Payload.Union).?.data; |
| 11194 | const field_ty = union_obj.fields.values()[index].ty; | 11307 | const field_ty = union_obj.fields.values()[index].ty; |
| ... | @@ -12168,7 +12281,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -12168,7 +12281,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 12168 | const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen()); | 12281 | const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen()); |
| 12169 | var elem_val_buf: Value.ElemValueBuffer = undefined; | 12282 | var elem_val_buf: Value.ElemValueBuffer = undefined; |
| 12170 | const elems = try sema.arena.alloc(Value, vec_len); | 12283 | const elems = try sema.arena.alloc(Value, vec_len); |
| 12171 | for (elems) |*elem, i| { | 12284 | for (elems, 0..) |*elem, i| { |
| 12172 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_val_buf); | 12285 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_val_buf); |
| 12173 | elem.* = try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod); | 12286 | elem.* = try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod); |
| 12174 | } | 12287 | } |
| ... | @@ -12434,14 +12547,14 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12434,14 +12547,14 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12434 | while (elem_i < lhs_len) : (elem_i += 1) { | 12547 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 12435 | const elem_index = try sema.addIntUnsigned(Type.usize, elem_i); | 12548 | const elem_index = try sema.addIntUnsigned(Type.usize, elem_i); |
| 12436 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | 12549 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 12437 | const init = try sema.elemVal(block, lhs_src, lhs, elem_index, src); | 12550 | const init = try sema.elemVal(block, lhs_src, lhs, elem_index, src, true); |
| 12438 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); | 12551 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); |
| 12439 | } | 12552 | } |
| 12440 | while (elem_i < result_len) : (elem_i += 1) { | 12553 | while (elem_i < result_len) : (elem_i += 1) { |
| 12441 | const elem_index = try sema.addIntUnsigned(Type.usize, elem_i); | 12554 | const elem_index = try sema.addIntUnsigned(Type.usize, elem_i); |
| 12442 | const rhs_index = try sema.addIntUnsigned(Type.usize, elem_i - lhs_len); | 12555 | const rhs_index = try sema.addIntUnsigned(Type.usize, elem_i - lhs_len); |
| 12443 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | 12556 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 12444 | const init = try sema.elemVal(block, rhs_src, rhs, rhs_index, src); | 12557 | const init = try sema.elemVal(block, rhs_src, rhs, rhs_index, src, true); |
| 12445 | try sema.storePtr2(block, src, elem_ptr, src, init, rhs_src, .store); | 12558 | try sema.storePtr2(block, src, elem_ptr, src, init, rhs_src, .store); |
| 12446 | } | 12559 | } |
| 12447 | if (res_sent_val) |sent_val| { | 12560 | if (res_sent_val) |sent_val| { |
| ... | @@ -12459,12 +12572,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12459,12 +12572,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12459 | var elem_i: usize = 0; | 12572 | var elem_i: usize = 0; |
| 12460 | while (elem_i < lhs_len) : (elem_i += 1) { | 12573 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 12461 | const index = try sema.addIntUnsigned(Type.usize, elem_i); | 12574 | const index = try sema.addIntUnsigned(Type.usize, elem_i); |
| 12462 | const init = try sema.elemVal(block, lhs_src, lhs, index, src); | 12575 | const init = try sema.elemVal(block, lhs_src, lhs, index, src, true); |
| 12463 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, lhs_src); | 12576 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, lhs_src); |
| 12464 | } | 12577 | } |
| 12465 | while (elem_i < result_len) : (elem_i += 1) { | 12578 | while (elem_i < result_len) : (elem_i += 1) { |
| 12466 | const index = try sema.addIntUnsigned(Type.usize, elem_i - lhs_len); | 12579 | const index = try sema.addIntUnsigned(Type.usize, elem_i - lhs_len); |
| 12467 | const init = try sema.elemVal(block, rhs_src, rhs, index, src); | 12580 | const init = try sema.elemVal(block, rhs_src, rhs, index, src, true); |
| 12468 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, rhs_src); | 12581 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, rhs_src); |
| 12469 | } | 12582 | } |
| 12470 | } | 12583 | } |
| ... | @@ -12684,7 +12797,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12684,7 +12797,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12684 | elem_i += 1; | 12797 | elem_i += 1; |
| 12685 | const lhs_index = try sema.addIntUnsigned(Type.usize, lhs_i); | 12798 | const lhs_index = try sema.addIntUnsigned(Type.usize, lhs_i); |
| 12686 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | 12799 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 12687 | const init = try sema.elemVal(block, lhs_src, lhs, lhs_index, src); | 12800 | const init = try sema.elemVal(block, lhs_src, lhs, lhs_index, src, true); |
| 12688 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); | 12801 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); |
| 12689 | } | 12802 | } |
| 12690 | } | 12803 | } |
| ... | @@ -12704,7 +12817,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12704,7 +12817,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12704 | var lhs_i: usize = 0; | 12817 | var lhs_i: usize = 0; |
| 12705 | while (lhs_i < lhs_len) : (lhs_i += 1) { | 12818 | while (lhs_i < lhs_len) : (lhs_i += 1) { |
| 12706 | const lhs_index = try sema.addIntUnsigned(Type.usize, lhs_i); | 12819 | const lhs_index = try sema.addIntUnsigned(Type.usize, lhs_i); |
| 12707 | const init = try sema.elemVal(block, lhs_src, lhs, lhs_index, src); | 12820 | const init = try sema.elemVal(block, lhs_src, lhs, lhs_index, src, true); |
| 12708 | element_refs[elem_i] = init; | 12821 | element_refs[elem_i] = init; |
| 12709 | elem_i += 1; | 12822 | elem_i += 1; |
| 12710 | } | 12823 | } |
| ... | @@ -12776,6 +12889,7 @@ fn zirArithmetic( | ... | @@ -12776,6 +12889,7 @@ fn zirArithmetic( |
| 12776 | block: *Block, | 12889 | block: *Block, |
| 12777 | inst: Zir.Inst.Index, | 12890 | inst: Zir.Inst.Index, |
| 12778 | zir_tag: Zir.Inst.Tag, | 12891 | zir_tag: Zir.Inst.Tag, |
| 12892 | safety: bool, | ||
| 12779 | ) CompileError!Air.Inst.Ref { | 12893 | ) CompileError!Air.Inst.Ref { |
| 12780 | const tracy = trace(@src()); | 12894 | const tracy = trace(@src()); |
| 12781 | defer tracy.end(); | 12895 | defer tracy.end(); |
| ... | @@ -12788,7 +12902,7 @@ fn zirArithmetic( | ... | @@ -12788,7 +12902,7 @@ fn zirArithmetic( |
| 12788 | const lhs = try sema.resolveInst(extra.lhs); | 12902 | const lhs = try sema.resolveInst(extra.lhs); |
| 12789 | const rhs = try sema.resolveInst(extra.rhs); | 12903 | const rhs = try sema.resolveInst(extra.rhs); |
| 12790 | 12904 | ||
| 12791 | return sema.analyzeArithmetic(block, zir_tag, lhs, rhs, sema.src, lhs_src, rhs_src, true); | 12905 | return sema.analyzeArithmetic(block, zir_tag, lhs, rhs, sema.src, lhs_src, rhs_src, safety); |
| 12792 | } | 12906 | } |
| 12793 | 12907 | ||
| 12794 | fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 12908 | fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -13612,7 +13726,7 @@ fn intRem( | ... | @@ -13612,7 +13726,7 @@ fn intRem( |
| 13612 | ) CompileError!Value { | 13726 | ) CompileError!Value { |
| 13613 | if (ty.zigTypeTag() == .Vector) { | 13727 | if (ty.zigTypeTag() == .Vector) { |
| 13614 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 13728 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 13615 | for (result_data) |*scalar, i| { | 13729 | for (result_data, 0..) |*scalar, i| { |
| 13616 | var lhs_buf: Value.ElemValueBuffer = undefined; | 13730 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 13617 | var rhs_buf: Value.ElemValueBuffer = undefined; | 13731 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 13618 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); | 13732 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); |
| ... | @@ -14139,7 +14253,7 @@ fn analyzeArithmetic( | ... | @@ -14139,7 +14253,7 @@ fn analyzeArithmetic( |
| 14139 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); | 14253 | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 14140 | const rs: struct { src: LazySrcLoc, air_tag: Air.Inst.Tag } = rs: { | 14254 | const rs: struct { src: LazySrcLoc, air_tag: Air.Inst.Tag } = rs: { |
| 14141 | switch (zir_tag) { | 14255 | switch (zir_tag) { |
| 14142 | .add => { | 14256 | .add, .add_unsafe => { |
| 14143 | // For integers:intAddSat | 14257 | // For integers:intAddSat |
| 14144 | // If either of the operands are zero, then the other operand is | 14258 | // If either of the operands are zero, then the other operand is |
| 14145 | // returned, even if it is undefined. | 14259 | // returned, even if it is undefined. |
| ... | @@ -14722,7 +14836,7 @@ fn zirAsm( | ... | @@ -14722,7 +14836,7 @@ fn zirAsm( |
| 14722 | const outputs = try sema.arena.alloc(ConstraintName, outputs_len); | 14836 | const outputs = try sema.arena.alloc(ConstraintName, outputs_len); |
| 14723 | var expr_ty = Air.Inst.Ref.void_type; | 14837 | var expr_ty = Air.Inst.Ref.void_type; |
| 14724 | 14838 | ||
| 14725 | for (out_args) |*arg, out_i| { | 14839 | for (out_args, 0..) |*arg, out_i| { |
| 14726 | const output = sema.code.extraData(Zir.Inst.Asm.Output, extra_i); | 14840 | const output = sema.code.extraData(Zir.Inst.Asm.Output, extra_i); |
| 14727 | extra_i = output.end; | 14841 | extra_i = output.end; |
| 14728 | 14842 | ||
| ... | @@ -14749,7 +14863,7 @@ fn zirAsm( | ... | @@ -14749,7 +14863,7 @@ fn zirAsm( |
| 14749 | const args = try sema.arena.alloc(Air.Inst.Ref, inputs_len); | 14863 | const args = try sema.arena.alloc(Air.Inst.Ref, inputs_len); |
| 14750 | const inputs = try sema.arena.alloc(ConstraintName, inputs_len); | 14864 | const inputs = try sema.arena.alloc(ConstraintName, inputs_len); |
| 14751 | 14865 | ||
| 14752 | for (args) |*arg, arg_i| { | 14866 | for (args, 0..) |*arg, arg_i| { |
| 14753 | const input = sema.code.extraData(Zir.Inst.Asm.Input, extra_i); | 14867 | const input = sema.code.extraData(Zir.Inst.Asm.Input, extra_i); |
| 14754 | extra_i = input.end; | 14868 | extra_i = input.end; |
| 14755 | 14869 | ||
| ... | @@ -15473,7 +15587,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15473,7 +15587,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15473 | defer params_anon_decl.deinit(); | 15587 | defer params_anon_decl.deinit(); |
| 15474 | 15588 | ||
| 15475 | const param_vals = try params_anon_decl.arena().alloc(Value, info.param_types.len); | 15589 | const param_vals = try params_anon_decl.arena().alloc(Value, info.param_types.len); |
| 15476 | for (param_vals) |*param_val, i| { | 15590 | for (param_vals, 0..) |*param_val, i| { |
| 15477 | const param_ty = info.param_types[i]; | 15591 | const param_ty = info.param_types[i]; |
| 15478 | const is_generic = param_ty.tag() == .generic_poison; | 15592 | const is_generic = param_ty.tag() == .generic_poison; |
| 15479 | const param_ty_val = if (is_generic) | 15593 | const param_ty_val = if (is_generic) |
| ... | @@ -15717,7 +15831,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15717,7 +15831,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15717 | const error_field_vals: ?[]Value = if (ty.isAnyError()) null else blk: { | 15831 | const error_field_vals: ?[]Value = if (ty.isAnyError()) null else blk: { |
| 15718 | const names = ty.errorSetNames(); | 15832 | const names = ty.errorSetNames(); |
| 15719 | const vals = try fields_anon_decl.arena().alloc(Value, names.len); | 15833 | const vals = try fields_anon_decl.arena().alloc(Value, names.len); |
| 15720 | for (vals) |*field_val, i| { | 15834 | for (vals, 0..) |*field_val, i| { |
| 15721 | const name = names[i]; | 15835 | const name = names[i]; |
| 15722 | const name_val = v: { | 15836 | const name_val = v: { |
| 15723 | var anon_decl = try block.startAnonDecl(); | 15837 | var anon_decl = try block.startAnonDecl(); |
| ... | @@ -15819,7 +15933,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15819,7 +15933,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15819 | const enum_fields = ty.enumFields(); | 15933 | const enum_fields = ty.enumFields(); |
| 15820 | const enum_field_vals = try fields_anon_decl.arena().alloc(Value, enum_fields.count()); | 15934 | const enum_field_vals = try fields_anon_decl.arena().alloc(Value, enum_fields.count()); |
| 15821 | 15935 | ||
| 15822 | for (enum_field_vals) |*field_val, i| { | 15936 | for (enum_field_vals, 0..) |*field_val, i| { |
| 15823 | var tag_val_payload: Value.Payload.U32 = .{ | 15937 | var tag_val_payload: Value.Payload.U32 = .{ |
| 15824 | .base = .{ .tag = .enum_field_index }, | 15938 | .base = .{ .tag = .enum_field_index }, |
| 15825 | .data = @intCast(u32, i), | 15939 | .data = @intCast(u32, i), |
| ... | @@ -15916,7 +16030,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15916,7 +16030,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15916 | const union_fields = union_ty.unionFields(); | 16030 | const union_fields = union_ty.unionFields(); |
| 15917 | const union_field_vals = try fields_anon_decl.arena().alloc(Value, union_fields.count()); | 16031 | const union_field_vals = try fields_anon_decl.arena().alloc(Value, union_fields.count()); |
| 15918 | 16032 | ||
| 15919 | for (union_field_vals) |*field_val, i| { | 16033 | for (union_field_vals, 0..) |*field_val, i| { |
| 15920 | const field = union_fields.values()[i]; | 16034 | const field = union_fields.values()[i]; |
| 15921 | const name = union_fields.keys()[i]; | 16035 | const name = union_fields.keys()[i]; |
| 15922 | const name_val = v: { | 16036 | const name_val = v: { |
| ... | @@ -16025,7 +16139,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16025,7 +16139,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16025 | const tuple = struct_ty.tupleFields(); | 16139 | const tuple = struct_ty.tupleFields(); |
| 16026 | const field_types = tuple.types; | 16140 | const field_types = tuple.types; |
| 16027 | const struct_field_vals = try fields_anon_decl.arena().alloc(Value, field_types.len); | 16141 | const struct_field_vals = try fields_anon_decl.arena().alloc(Value, field_types.len); |
| 16028 | for (struct_field_vals) |*struct_field_val, i| { | 16142 | for (struct_field_vals, 0..) |*struct_field_val, i| { |
| 16029 | const field_ty = field_types[i]; | 16143 | const field_ty = field_types[i]; |
| 16030 | const name_val = v: { | 16144 | const name_val = v: { |
| 16031 | var anon_decl = try block.startAnonDecl(); | 16145 | var anon_decl = try block.startAnonDecl(); |
| ... | @@ -16069,7 +16183,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -16069,7 +16183,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16069 | const struct_fields = struct_ty.structFields(); | 16183 | const struct_fields = struct_ty.structFields(); |
| 16070 | const struct_field_vals = try fields_anon_decl.arena().alloc(Value, struct_fields.count()); | 16184 | const struct_field_vals = try fields_anon_decl.arena().alloc(Value, struct_fields.count()); |
| 16071 | 16185 | ||
| 16072 | for (struct_field_vals) |*field_val, i| { | 16186 | for (struct_field_vals, 0..) |*field_val, i| { |
| 16073 | const field = struct_fields.values()[i]; | 16187 | const field = struct_fields.values()[i]; |
| 16074 | const name = struct_fields.keys()[i]; | 16188 | const name = struct_fields.keys()[i]; |
| 16075 | const name_val = v: { | 16189 | const name_val = v: { |
| ... | @@ -16408,7 +16522,7 @@ fn zirTypeofPeer( | ... | @@ -16408,7 +16522,7 @@ fn zirTypeofPeer( |
| 16408 | const inst_list = try sema.gpa.alloc(Air.Inst.Ref, args.len); | 16522 | const inst_list = try sema.gpa.alloc(Air.Inst.Ref, args.len); |
| 16409 | defer sema.gpa.free(inst_list); | 16523 | defer sema.gpa.free(inst_list); |
| 16410 | 16524 | ||
| 16411 | for (args) |arg_ref, i| { | 16525 | for (args, 0..) |arg_ref, i| { |
| 16412 | inst_list[i] = try sema.resolveInst(arg_ref); | 16526 | inst_list[i] = try sema.resolveInst(arg_ref); |
| 16413 | } | 16527 | } |
| 16414 | 16528 | ||
| ... | @@ -17519,7 +17633,7 @@ fn finishStructInit( | ... | @@ -17519,7 +17633,7 @@ fn finishStructInit( |
| 17519 | 17633 | ||
| 17520 | if (struct_ty.isAnonStruct()) { | 17634 | if (struct_ty.isAnonStruct()) { |
| 17521 | const struct_obj = struct_ty.castTag(.anon_struct).?.data; | 17635 | const struct_obj = struct_ty.castTag(.anon_struct).?.data; |
| 17522 | for (struct_obj.values) |default_val, i| { | 17636 | for (struct_obj.values, 0..) |default_val, i| { |
| 17523 | if (field_inits[i] != .none) continue; | 17637 | if (field_inits[i] != .none) continue; |
| 17524 | 17638 | ||
| 17525 | if (default_val.tag() == .unreachable_value) { | 17639 | if (default_val.tag() == .unreachable_value) { |
| ... | @@ -17555,7 +17669,7 @@ fn finishStructInit( | ... | @@ -17555,7 +17669,7 @@ fn finishStructInit( |
| 17555 | } | 17669 | } |
| 17556 | } else { | 17670 | } else { |
| 17557 | const struct_obj = struct_ty.castTag(.@"struct").?.data; | 17671 | const struct_obj = struct_ty.castTag(.@"struct").?.data; |
| 17558 | for (struct_obj.fields.values()) |field, i| { | 17672 | for (struct_obj.fields.values(), 0..) |field, i| { |
| 17559 | if (field_inits[i] != .none) continue; | 17673 | if (field_inits[i] != .none) continue; |
| 17560 | 17674 | ||
| 17561 | if (field.default_val.tag() == .unreachable_value) { | 17675 | if (field.default_val.tag() == .unreachable_value) { |
| ... | @@ -17596,7 +17710,7 @@ fn finishStructInit( | ... | @@ -17596,7 +17710,7 @@ fn finishStructInit( |
| 17596 | 17710 | ||
| 17597 | if (is_comptime) { | 17711 | if (is_comptime) { |
| 17598 | const values = try sema.arena.alloc(Value, field_inits.len); | 17712 | const values = try sema.arena.alloc(Value, field_inits.len); |
| 17599 | for (field_inits) |field_init, i| { | 17713 | for (field_inits, 0..) |field_init, i| { |
| 17600 | values[i] = (sema.resolveMaybeUndefVal(field_init) catch unreachable).?; | 17714 | values[i] = (sema.resolveMaybeUndefVal(field_init) catch unreachable).?; |
| 17601 | } | 17715 | } |
| 17602 | const struct_val = try Value.Tag.aggregate.create(sema.arena, values); | 17716 | const struct_val = try Value.Tag.aggregate.create(sema.arena, values); |
| ... | @@ -17611,7 +17725,7 @@ fn finishStructInit( | ... | @@ -17611,7 +17725,7 @@ fn finishStructInit( |
| 17611 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 17725 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 17612 | }); | 17726 | }); |
| 17613 | const alloc = try block.addTy(.alloc, alloc_ty); | 17727 | const alloc = try block.addTy(.alloc, alloc_ty); |
| 17614 | for (field_inits) |field_init, i_usize| { | 17728 | for (field_inits, 0..) |field_init, i_usize| { |
| 17615 | const i = @intCast(u32, i_usize); | 17729 | const i = @intCast(u32, i_usize); |
| 17616 | const field_src = dest_src; | 17730 | const field_src = dest_src; |
| 17617 | const field_ptr = try sema.structFieldPtrByIndex(block, dest_src, alloc, i, field_src, struct_ty, true); | 17731 | const field_ptr = try sema.structFieldPtrByIndex(block, dest_src, alloc, i, field_src, struct_ty, true); |
| ... | @@ -17644,7 +17758,7 @@ fn zirStructInitAnon( | ... | @@ -17644,7 +17758,7 @@ fn zirStructInitAnon( |
| 17644 | const opt_runtime_index = rs: { | 17758 | const opt_runtime_index = rs: { |
| 17645 | var runtime_index: ?usize = null; | 17759 | var runtime_index: ?usize = null; |
| 17646 | var extra_index = extra.end; | 17760 | var extra_index = extra.end; |
| 17647 | for (types) |*field_ty, i| { | 17761 | for (types, 0..) |*field_ty, i| { |
| 17648 | const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index); | 17762 | const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index); |
| 17649 | extra_index = item.end; | 17763 | extra_index = item.end; |
| 17650 | 17764 | ||
| ... | @@ -17718,7 +17832,7 @@ fn zirStructInitAnon( | ... | @@ -17718,7 +17832,7 @@ fn zirStructInitAnon( |
| 17718 | }); | 17832 | }); |
| 17719 | const alloc = try block.addTy(.alloc, alloc_ty); | 17833 | const alloc = try block.addTy(.alloc, alloc_ty); |
| 17720 | var extra_index = extra.end; | 17834 | var extra_index = extra.end; |
| 17721 | for (types) |field_ty, i_usize| { | 17835 | for (types, 0..) |field_ty, i_usize| { |
| 17722 | const i = @intCast(u32, i_usize); | 17836 | const i = @intCast(u32, i_usize); |
| 17723 | const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index); | 17837 | const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index); |
| 17724 | extra_index = item.end; | 17838 | extra_index = item.end; |
| ... | @@ -17740,7 +17854,7 @@ fn zirStructInitAnon( | ... | @@ -17740,7 +17854,7 @@ fn zirStructInitAnon( |
| 17740 | 17854 | ||
| 17741 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, types.len); | 17855 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, types.len); |
| 17742 | var extra_index = extra.end; | 17856 | var extra_index = extra.end; |
| 17743 | for (types) |_, i| { | 17857 | for (types, 0..) |_, i| { |
| 17744 | const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index); | 17858 | const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index); |
| 17745 | extra_index = item.end; | 17859 | extra_index = item.end; |
| 17746 | element_refs[i] = try sema.resolveInst(item.data.init); | 17860 | element_refs[i] = try sema.resolveInst(item.data.init); |
| ... | @@ -17768,7 +17882,7 @@ fn zirArrayInit( | ... | @@ -17768,7 +17882,7 @@ fn zirArrayInit( |
| 17768 | 17882 | ||
| 17769 | const resolved_args = try gpa.alloc(Air.Inst.Ref, args.len - 1 + @boolToInt(sentinel_val != null)); | 17883 | const resolved_args = try gpa.alloc(Air.Inst.Ref, args.len - 1 + @boolToInt(sentinel_val != null)); |
| 17770 | defer gpa.free(resolved_args); | 17884 | defer gpa.free(resolved_args); |
| 17771 | for (args[1..]) |arg, i| { | 17885 | for (args[1..], 0..) |arg, i| { |
| 17772 | const resolved_arg = try sema.resolveInst(arg); | 17886 | const resolved_arg = try sema.resolveInst(arg); |
| 17773 | const elem_ty = if (array_ty.zigTypeTag() == .Struct) | 17887 | const elem_ty = if (array_ty.zigTypeTag() == .Struct) |
| 17774 | array_ty.structFieldType(i) | 17888 | array_ty.structFieldType(i) |
| ... | @@ -17789,7 +17903,7 @@ fn zirArrayInit( | ... | @@ -17789,7 +17903,7 @@ fn zirArrayInit( |
| 17789 | resolved_args[resolved_args.len - 1] = try sema.addConstant(array_ty.elemType2(), some); | 17903 | resolved_args[resolved_args.len - 1] = try sema.addConstant(array_ty.elemType2(), some); |
| 17790 | } | 17904 | } |
| 17791 | 17905 | ||
| 17792 | const opt_runtime_index: ?u32 = for (resolved_args) |arg, i| { | 17906 | const opt_runtime_index: ?u32 = for (resolved_args, 0..) |arg, i| { |
| 17793 | const comptime_known = try sema.isComptimeKnown(arg); | 17907 | const comptime_known = try sema.isComptimeKnown(arg); |
| 17794 | if (!comptime_known) break @intCast(u32, i); | 17908 | if (!comptime_known) break @intCast(u32, i); |
| 17795 | } else null; | 17909 | } else null; |
| ... | @@ -17797,7 +17911,7 @@ fn zirArrayInit( | ... | @@ -17797,7 +17911,7 @@ fn zirArrayInit( |
| 17797 | const runtime_index = opt_runtime_index orelse { | 17911 | const runtime_index = opt_runtime_index orelse { |
| 17798 | const elem_vals = try sema.arena.alloc(Value, resolved_args.len); | 17912 | const elem_vals = try sema.arena.alloc(Value, resolved_args.len); |
| 17799 | 17913 | ||
| 17800 | for (resolved_args) |arg, i| { | 17914 | for (resolved_args, 0..) |arg, i| { |
| 17801 | // We checked that all args are comptime above. | 17915 | // We checked that all args are comptime above. |
| 17802 | elem_vals[i] = (sema.resolveMaybeUndefVal(arg) catch unreachable).?; | 17916 | elem_vals[i] = (sema.resolveMaybeUndefVal(arg) catch unreachable).?; |
| 17803 | } | 17917 | } |
| ... | @@ -17826,7 +17940,7 @@ fn zirArrayInit( | ... | @@ -17826,7 +17940,7 @@ fn zirArrayInit( |
| 17826 | const alloc = try block.addTy(.alloc, alloc_ty); | 17940 | const alloc = try block.addTy(.alloc, alloc_ty); |
| 17827 | 17941 | ||
| 17828 | if (array_ty.isTuple()) { | 17942 | if (array_ty.isTuple()) { |
| 17829 | for (resolved_args) |arg, i| { | 17943 | for (resolved_args, 0..) |arg, i| { |
| 17830 | const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ | 17944 | const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 17831 | .mutable = true, | 17945 | .mutable = true, |
| 17832 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 17946 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| ... | @@ -17848,7 +17962,7 @@ fn zirArrayInit( | ... | @@ -17848,7 +17962,7 @@ fn zirArrayInit( |
| 17848 | }); | 17962 | }); |
| 17849 | const elem_ptr_ty_ref = try sema.addType(elem_ptr_ty); | 17963 | const elem_ptr_ty_ref = try sema.addType(elem_ptr_ty); |
| 17850 | 17964 | ||
| 17851 | for (resolved_args) |arg, i| { | 17965 | for (resolved_args, 0..) |arg, i| { |
| 17852 | const index = try sema.addIntUnsigned(Type.usize, i); | 17966 | const index = try sema.addIntUnsigned(Type.usize, i); |
| 17853 | const elem_ptr = try block.addPtrElemPtrTypeRef(alloc, index, elem_ptr_ty_ref); | 17967 | const elem_ptr = try block.addPtrElemPtrTypeRef(alloc, index, elem_ptr_ty_ref); |
| 17854 | _ = try block.addBinOp(.store, elem_ptr, arg); | 17968 | _ = try block.addBinOp(.store, elem_ptr, arg); |
| ... | @@ -17875,7 +17989,7 @@ fn zirArrayInitAnon( | ... | @@ -17875,7 +17989,7 @@ fn zirArrayInitAnon( |
| 17875 | 17989 | ||
| 17876 | const opt_runtime_src = rs: { | 17990 | const opt_runtime_src = rs: { |
| 17877 | var runtime_src: ?LazySrcLoc = null; | 17991 | var runtime_src: ?LazySrcLoc = null; |
| 17878 | for (operands) |operand, i| { | 17992 | for (operands, 0..) |operand, i| { |
| 17879 | const operand_src = src; // TODO better source location | 17993 | const operand_src = src; // TODO better source location |
| 17880 | const elem = try sema.resolveInst(operand); | 17994 | const elem = try sema.resolveInst(operand); |
| 17881 | types[i] = sema.typeOf(elem); | 17995 | types[i] = sema.typeOf(elem); |
| ... | @@ -17918,7 +18032,7 @@ fn zirArrayInitAnon( | ... | @@ -17918,7 +18032,7 @@ fn zirArrayInitAnon( |
| 17918 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 18032 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 17919 | }); | 18033 | }); |
| 17920 | const alloc = try block.addTy(.alloc, alloc_ty); | 18034 | const alloc = try block.addTy(.alloc, alloc_ty); |
| 17921 | for (operands) |operand, i_usize| { | 18035 | for (operands, 0..) |operand, i_usize| { |
| 17922 | const i = @intCast(u32, i_usize); | 18036 | const i = @intCast(u32, i_usize); |
| 17923 | const field_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ | 18037 | const field_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 17924 | .mutable = true, | 18038 | .mutable = true, |
| ... | @@ -17935,7 +18049,7 @@ fn zirArrayInitAnon( | ... | @@ -17935,7 +18049,7 @@ fn zirArrayInitAnon( |
| 17935 | } | 18049 | } |
| 17936 | 18050 | ||
| 17937 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len); | 18051 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len); |
| 17938 | for (operands) |operand, i| { | 18052 | for (operands, 0..) |operand, i| { |
| 17939 | element_refs[i] = try sema.resolveInst(operand); | 18053 | element_refs[i] = try sema.resolveInst(operand); |
| 17940 | } | 18054 | } |
| 17941 | 18055 | ||
| ... | @@ -18138,7 +18252,7 @@ fn zirUnaryMath( | ... | @@ -18138,7 +18252,7 @@ fn zirUnaryMath( |
| 18138 | 18252 | ||
| 18139 | var elem_buf: Value.ElemValueBuffer = undefined; | 18253 | var elem_buf: Value.ElemValueBuffer = undefined; |
| 18140 | const elems = try sema.arena.alloc(Value, vec_len); | 18254 | const elems = try sema.arena.alloc(Value, vec_len); |
| 18141 | for (elems) |*elem, i| { | 18255 | for (elems, 0..) |*elem, i| { |
| 18142 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf); | 18256 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf); |
| 18143 | elem.* = try eval(elem_val, scalar_ty, sema.arena, sema.mod); | 18257 | elem.* = try eval(elem_val, scalar_ty, sema.arena, sema.mod); |
| 18144 | } | 18258 | } |
| ... | @@ -19142,7 +19256,7 @@ fn reifyStruct( | ... | @@ -19142,7 +19256,7 @@ fn reifyStruct( |
| 19142 | if (layout == .Packed) { | 19256 | if (layout == .Packed) { |
| 19143 | struct_obj.status = .layout_wip; | 19257 | struct_obj.status = .layout_wip; |
| 19144 | 19258 | ||
| 19145 | for (struct_obj.fields.values()) |field, index| { | 19259 | for (struct_obj.fields.values(), 0..) |field, index| { |
| 19146 | sema.resolveTypeLayout(field.ty) catch |err| switch (err) { | 19260 | sema.resolveTypeLayout(field.ty) catch |err| switch (err) { |
| 19147 | error.AnalysisFail => { | 19261 | error.AnalysisFail => { |
| 19148 | const msg = sema.err orelse return err; | 19262 | const msg = sema.err orelse return err; |
| ... | @@ -19771,7 +19885,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19771,7 +19885,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19771 | } | 19885 | } |
| 19772 | var elem_buf: Value.ElemValueBuffer = undefined; | 19886 | var elem_buf: Value.ElemValueBuffer = undefined; |
| 19773 | const elems = try sema.arena.alloc(Value, operand_ty.vectorLen()); | 19887 | const elems = try sema.arena.alloc(Value, operand_ty.vectorLen()); |
| 19774 | for (elems) |*elem, i| { | 19888 | for (elems, 0..) |*elem, i| { |
| 19775 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf); | 19889 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf); |
| 19776 | elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod); | 19890 | elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod); |
| 19777 | } | 19891 | } |
| ... | @@ -19873,7 +19987,7 @@ fn zirBitCount( | ... | @@ -19873,7 +19987,7 @@ fn zirBitCount( |
| 19873 | var elem_buf: Value.ElemValueBuffer = undefined; | 19987 | var elem_buf: Value.ElemValueBuffer = undefined; |
| 19874 | const elems = try sema.arena.alloc(Value, vec_len); | 19988 | const elems = try sema.arena.alloc(Value, vec_len); |
| 19875 | const scalar_ty = operand_ty.scalarType(); | 19989 | const scalar_ty = operand_ty.scalarType(); |
| 19876 | for (elems) |*elem, i| { | 19990 | for (elems, 0..) |*elem, i| { |
| 19877 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf); | 19991 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf); |
| 19878 | const count = comptimeOp(elem_val, scalar_ty, target); | 19992 | const count = comptimeOp(elem_val, scalar_ty, target); |
| 19879 | elem.* = try Value.Tag.int_u64.create(sema.arena, count); | 19993 | elem.* = try Value.Tag.int_u64.create(sema.arena, count); |
| ... | @@ -19942,7 +20056,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19942,7 +20056,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19942 | const vec_len = operand_ty.vectorLen(); | 20056 | const vec_len = operand_ty.vectorLen(); |
| 19943 | var elem_buf: Value.ElemValueBuffer = undefined; | 20057 | var elem_buf: Value.ElemValueBuffer = undefined; |
| 19944 | const elems = try sema.arena.alloc(Value, vec_len); | 20058 | const elems = try sema.arena.alloc(Value, vec_len); |
| 19945 | for (elems) |*elem, i| { | 20059 | for (elems, 0..) |*elem, i| { |
| 19946 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf); | 20060 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf); |
| 19947 | elem.* = try elem_val.byteSwap(operand_ty, target, sema.arena); | 20061 | elem.* = try elem_val.byteSwap(operand_ty, target, sema.arena); |
| 19948 | } | 20062 | } |
| ... | @@ -19991,7 +20105,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -19991,7 +20105,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 19991 | const vec_len = operand_ty.vectorLen(); | 20105 | const vec_len = operand_ty.vectorLen(); |
| 19992 | var elem_buf: Value.ElemValueBuffer = undefined; | 20106 | var elem_buf: Value.ElemValueBuffer = undefined; |
| 19993 | const elems = try sema.arena.alloc(Value, vec_len); | 20107 | const elems = try sema.arena.alloc(Value, vec_len); |
| 19994 | for (elems) |*elem, i| { | 20108 | for (elems, 0..) |*elem, i| { |
| 19995 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf); | 20109 | const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf); |
| 19996 | elem.* = try elem_val.bitReverse(scalar_ty, target, sema.arena); | 20110 | elem.* = try elem_val.bitReverse(scalar_ty, target, sema.arena); |
| 19997 | } | 20111 | } |
| ... | @@ -20060,7 +20174,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 | ... | @@ -20060,7 +20174,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 20060 | .Packed => { | 20174 | .Packed => { |
| 20061 | var bit_sum: u64 = 0; | 20175 | var bit_sum: u64 = 0; |
| 20062 | const fields = ty.structFields(); | 20176 | const fields = ty.structFields(); |
| 20063 | for (fields.values()) |field, i| { | 20177 | for (fields.values(), 0..) |field, i| { |
| 20064 | if (i == field_index) { | 20178 | if (i == field_index) { |
| 20065 | return bit_sum; | 20179 | return bit_sum; |
| 20066 | } | 20180 | } |
| ... | @@ -20997,7 +21111,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -20997,7 +21111,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 20997 | 21111 | ||
| 20998 | var buf: Value.ElemValueBuffer = undefined; | 21112 | var buf: Value.ElemValueBuffer = undefined; |
| 20999 | const elems = try sema.gpa.alloc(Value, vec_len); | 21113 | const elems = try sema.gpa.alloc(Value, vec_len); |
| 21000 | for (elems) |*elem, i| { | 21114 | for (elems, 0..) |*elem, i| { |
| 21001 | const pred_elem_val = pred_val.elemValueBuffer(sema.mod, i, &buf); | 21115 | const pred_elem_val = pred_val.elemValueBuffer(sema.mod, i, &buf); |
| 21002 | const should_choose_a = pred_elem_val.toBool(); | 21116 | const should_choose_a = pred_elem_val.toBool(); |
| 21003 | if (should_choose_a) { | 21117 | if (should_choose_a) { |
| ... | @@ -21347,12 +21461,12 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -21347,12 +21461,12 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 21347 | func = bound_data.func_inst; | 21461 | func = bound_data.func_inst; |
| 21348 | resolved_args = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount() + 1); | 21462 | resolved_args = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount() + 1); |
| 21349 | resolved_args[0] = bound_data.arg0_inst; | 21463 | resolved_args[0] = bound_data.arg0_inst; |
| 21350 | for (resolved_args[1..]) |*resolved, i| { | 21464 | for (resolved_args[1..], 0..) |*resolved, i| { |
| 21351 | resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(u32, i), args_ty); | 21465 | resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(u32, i), args_ty); |
| 21352 | } | 21466 | } |
| 21353 | } else { | 21467 | } else { |
| 21354 | resolved_args = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount()); | 21468 | resolved_args = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount()); |
| 21355 | for (resolved_args) |*resolved, i| { | 21469 | for (resolved_args, 0..) |*resolved, i| { |
| 21356 | resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(u32, i), args_ty); | 21470 | resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(u32, i), args_ty); |
| 21357 | } | 21471 | } |
| 21358 | } | 21472 | } |
| ... | @@ -21507,7 +21621,7 @@ fn analyzeMinMax( | ... | @@ -21507,7 +21621,7 @@ fn analyzeMinMax( |
| 21507 | var lhs_buf: Value.ElemValueBuffer = undefined; | 21621 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 21508 | var rhs_buf: Value.ElemValueBuffer = undefined; | 21622 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 21509 | const elems = try sema.arena.alloc(Value, vec_len); | 21623 | const elems = try sema.arena.alloc(Value, vec_len); |
| 21510 | for (elems) |*elem, i| { | 21624 | for (elems, 0..) |*elem, i| { |
| 21511 | const lhs_elem_val = lhs_val.elemValueBuffer(sema.mod, i, &lhs_buf); | 21625 | const lhs_elem_val = lhs_val.elemValueBuffer(sema.mod, i, &lhs_buf); |
| 21512 | const rhs_elem_val = rhs_val.elemValueBuffer(sema.mod, i, &rhs_buf); | 21626 | const rhs_elem_val = rhs_val.elemValueBuffer(sema.mod, i, &rhs_buf); |
| 21513 | elem.* = opFunc(lhs_elem_val, rhs_elem_val, target); | 21627 | elem.* = opFunc(lhs_elem_val, rhs_elem_val, target); |
| ... | @@ -22404,7 +22518,7 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -22404,7 +22518,7 @@ fn explainWhyTypeIsComptimeInner( |
| 22404 | 22518 | ||
| 22405 | if (ty.castTag(.@"struct")) |payload| { | 22519 | if (ty.castTag(.@"struct")) |payload| { |
| 22406 | const struct_obj = payload.data; | 22520 | const struct_obj = payload.data; |
| 22407 | for (struct_obj.fields.values()) |field, i| { | 22521 | for (struct_obj.fields.values(), 0..) |field, i| { |
| 22408 | const field_src_loc = struct_obj.fieldSrcLoc(sema.mod, .{ | 22522 | const field_src_loc = struct_obj.fieldSrcLoc(sema.mod, .{ |
| 22409 | .index = i, | 22523 | .index = i, |
| 22410 | .range = .type, | 22524 | .range = .type, |
| ... | @@ -22424,7 +22538,7 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -22424,7 +22538,7 @@ fn explainWhyTypeIsComptimeInner( |
| 22424 | 22538 | ||
| 22425 | if (ty.cast(Type.Payload.Union)) |payload| { | 22539 | if (ty.cast(Type.Payload.Union)) |payload| { |
| 22426 | const union_obj = payload.data; | 22540 | const union_obj = payload.data; |
| 22427 | for (union_obj.fields.values()) |field, i| { | 22541 | for (union_obj.fields.values(), 0..) |field, i| { |
| 22428 | const field_src_loc = union_obj.fieldSrcLoc(sema.mod, .{ | 22542 | const field_src_loc = union_obj.fieldSrcLoc(sema.mod, .{ |
| 22429 | .index = i, | 22543 | .index = i, |
| 22430 | .range = .type, | 22544 | .range = .type, |
| ... | @@ -22676,6 +22790,7 @@ pub const PanicId = enum { | ... | @@ -22676,6 +22790,7 @@ pub const PanicId = enum { |
| 22676 | unwrap_error, | 22790 | unwrap_error, |
| 22677 | index_out_of_bounds, | 22791 | index_out_of_bounds, |
| 22678 | start_index_greater_than_end, | 22792 | start_index_greater_than_end, |
| 22793 | for_len_mismatch, | ||
| 22679 | }; | 22794 | }; |
| 22680 | 22795 | ||
| 22681 | fn addSafetyCheck( | 22796 | fn addSafetyCheck( |
| ... | @@ -23694,7 +23809,7 @@ fn structFieldPtrByIndex( | ... | @@ -23694,7 +23809,7 @@ fn structFieldPtrByIndex( |
| 23694 | comptime assert(Type.packed_struct_layout_version == 2); | 23809 | comptime assert(Type.packed_struct_layout_version == 2); |
| 23695 | 23810 | ||
| 23696 | var running_bits: u16 = 0; | 23811 | var running_bits: u16 = 0; |
| 23697 | for (struct_obj.fields.values()) |f, i| { | 23812 | for (struct_obj.fields.values(), 0..) |f, i| { |
| 23698 | if (!(try sema.typeHasRuntimeBits(f.ty))) continue; | 23813 | if (!(try sema.typeHasRuntimeBits(f.ty))) continue; |
| 23699 | 23814 | ||
| 23700 | if (i == field_index) { | 23815 | if (i == field_index) { |
| ... | @@ -24057,6 +24172,7 @@ fn elemPtr( | ... | @@ -24057,6 +24172,7 @@ fn elemPtr( |
| 24057 | elem_index: Air.Inst.Ref, | 24172 | elem_index: Air.Inst.Ref, |
| 24058 | elem_index_src: LazySrcLoc, | 24173 | elem_index_src: LazySrcLoc, |
| 24059 | init: bool, | 24174 | init: bool, |
| 24175 | oob_safety: bool, | ||
| 24060 | ) CompileError!Air.Inst.Ref { | 24176 | ) CompileError!Air.Inst.Ref { |
| 24061 | const indexable_ptr_src = src; // TODO better source location | 24177 | const indexable_ptr_src = src; // TODO better source location |
| 24062 | const indexable_ptr_ty = sema.typeOf(indexable_ptr); | 24178 | const indexable_ptr_ty = sema.typeOf(indexable_ptr); |
| ... | @@ -24065,46 +24181,61 @@ fn elemPtr( | ... | @@ -24065,46 +24181,61 @@ fn elemPtr( |
| 24065 | .Pointer => indexable_ptr_ty.elemType(), | 24181 | .Pointer => indexable_ptr_ty.elemType(), |
| 24066 | else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(sema.mod)}), | 24182 | else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(sema.mod)}), |
| 24067 | }; | 24183 | }; |
| 24068 | if (!indexable_ty.isIndexable()) { | ||
| 24069 | return sema.fail(block, src, "element access of non-indexable type '{}'", .{indexable_ty.fmt(sema.mod)}); | ||
| 24070 | } | ||
| 24071 | |||
| 24072 | switch (indexable_ty.zigTypeTag()) { | 24184 | switch (indexable_ty.zigTypeTag()) { |
| 24073 | .Pointer => { | 24185 | .Array, .Vector => return sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety), |
| 24074 | // In all below cases, we have to deref the ptr operand to get the actual indexable pointer. | ||
| 24075 | const indexable = try sema.analyzeLoad(block, indexable_ptr_src, indexable_ptr, indexable_ptr_src); | ||
| 24076 | switch (indexable_ty.ptrSize()) { | ||
| 24077 | .Slice => return sema.elemPtrSlice(block, src, indexable_ptr_src, indexable, elem_index_src, elem_index), | ||
| 24078 | .Many, .C => { | ||
| 24079 | const maybe_ptr_val = try sema.resolveDefinedValue(block, indexable_ptr_src, indexable); | ||
| 24080 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); | ||
| 24081 | const runtime_src = rs: { | ||
| 24082 | const ptr_val = maybe_ptr_val orelse break :rs indexable_ptr_src; | ||
| 24083 | const index_val = maybe_index_val orelse break :rs elem_index_src; | ||
| 24084 | const index = @intCast(usize, index_val.toUnsignedInt(target)); | ||
| 24085 | const elem_ptr = try ptr_val.elemPtr(indexable_ty, sema.arena, index, sema.mod); | ||
| 24086 | const result_ty = try sema.elemPtrType(indexable_ty, index); | ||
| 24087 | return sema.addConstant(result_ty, elem_ptr); | ||
| 24088 | }; | ||
| 24089 | const result_ty = try sema.elemPtrType(indexable_ty, null); | ||
| 24090 | |||
| 24091 | try sema.requireRuntimeBlock(block, src, runtime_src); | ||
| 24092 | return block.addPtrElemPtr(indexable, elem_index, result_ty); | ||
| 24093 | }, | ||
| 24094 | .One => { | ||
| 24095 | assert(indexable_ty.childType().zigTypeTag() == .Array); // Guaranteed by isIndexable | ||
| 24096 | return sema.elemPtrArray(block, src, indexable_ptr_src, indexable, elem_index_src, elem_index, init); | ||
| 24097 | }, | ||
| 24098 | } | ||
| 24099 | }, | ||
| 24100 | .Array, .Vector => return sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init), | ||
| 24101 | .Struct => { | 24186 | .Struct => { |
| 24102 | // Tuple field access. | 24187 | // Tuple field access. |
| 24103 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); | 24188 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); |
| 24104 | const index = @intCast(u32, index_val.toUnsignedInt(target)); | 24189 | const index = @intCast(u32, index_val.toUnsignedInt(target)); |
| 24105 | return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init); | 24190 | return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init); |
| 24106 | }, | 24191 | }, |
| 24107 | else => unreachable, | 24192 | else => { |
| 24193 | const indexable = try sema.analyzeLoad(block, indexable_ptr_src, indexable_ptr, indexable_ptr_src); | ||
| 24194 | return elemPtrOneLayerOnly(sema, block, src, indexable, elem_index, elem_index_src, init, oob_safety); | ||
| 24195 | }, | ||
| 24196 | } | ||
| 24197 | } | ||
| 24198 | |||
| 24199 | /// Asserts that the type of indexable is pointer. | ||
| 24200 | fn elemPtrOneLayerOnly( | ||
| 24201 | sema: *Sema, | ||
| 24202 | block: *Block, | ||
| 24203 | src: LazySrcLoc, | ||
| 24204 | indexable: Air.Inst.Ref, | ||
| 24205 | elem_index: Air.Inst.Ref, | ||
| 24206 | elem_index_src: LazySrcLoc, | ||
| 24207 | init: bool, | ||
| 24208 | oob_safety: bool, | ||
| 24209 | ) CompileError!Air.Inst.Ref { | ||
| 24210 | const indexable_src = src; // TODO better source location | ||
| 24211 | const indexable_ty = sema.typeOf(indexable); | ||
| 24212 | if (!indexable_ty.isIndexable()) { | ||
| 24213 | return sema.fail(block, src, "element access of non-indexable type '{}'", .{indexable_ty.fmt(sema.mod)}); | ||
| 24214 | } | ||
| 24215 | const target = sema.mod.getTarget(); | ||
| 24216 | |||
| 24217 | switch (indexable_ty.ptrSize()) { | ||
| 24218 | .Slice => return sema.elemPtrSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety), | ||
| 24219 | .Many, .C => { | ||
| 24220 | const maybe_ptr_val = try sema.resolveDefinedValue(block, indexable_src, indexable); | ||
| 24221 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); | ||
| 24222 | const runtime_src = rs: { | ||
| 24223 | const ptr_val = maybe_ptr_val orelse break :rs indexable_src; | ||
| 24224 | const index_val = maybe_index_val orelse break :rs elem_index_src; | ||
| 24225 | const index = @intCast(usize, index_val.toUnsignedInt(target)); | ||
| 24226 | const elem_ptr = try ptr_val.elemPtr(indexable_ty, sema.arena, index, sema.mod); | ||
| 24227 | const result_ty = try sema.elemPtrType(indexable_ty, index); | ||
| 24228 | return sema.addConstant(result_ty, elem_ptr); | ||
| 24229 | }; | ||
| 24230 | const result_ty = try sema.elemPtrType(indexable_ty, null); | ||
| 24231 | |||
| 24232 | try sema.requireRuntimeBlock(block, src, runtime_src); | ||
| 24233 | return block.addPtrElemPtr(indexable, elem_index, result_ty); | ||
| 24234 | }, | ||
| 24235 | .One => { | ||
| 24236 | assert(indexable_ty.childType().zigTypeTag() == .Array); // Guaranteed by isIndexable | ||
| 24237 | return sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety); | ||
| 24238 | }, | ||
| 24108 | } | 24239 | } |
| 24109 | } | 24240 | } |
| 24110 | 24241 | ||
| ... | @@ -24115,6 +24246,7 @@ fn elemVal( | ... | @@ -24115,6 +24246,7 @@ fn elemVal( |
| 24115 | indexable: Air.Inst.Ref, | 24246 | indexable: Air.Inst.Ref, |
| 24116 | elem_index_uncasted: Air.Inst.Ref, | 24247 | elem_index_uncasted: Air.Inst.Ref, |
| 24117 | elem_index_src: LazySrcLoc, | 24248 | elem_index_src: LazySrcLoc, |
| 24249 | oob_safety: bool, | ||
| 24118 | ) CompileError!Air.Inst.Ref { | 24250 | ) CompileError!Air.Inst.Ref { |
| 24119 | const indexable_src = src; // TODO better source location | 24251 | const indexable_src = src; // TODO better source location |
| 24120 | const indexable_ty = sema.typeOf(indexable); | 24252 | const indexable_ty = sema.typeOf(indexable); |
| ... | @@ -24130,7 +24262,7 @@ fn elemVal( | ... | @@ -24130,7 +24262,7 @@ fn elemVal( |
| 24130 | 24262 | ||
| 24131 | switch (indexable_ty.zigTypeTag()) { | 24263 | switch (indexable_ty.zigTypeTag()) { |
| 24132 | .Pointer => switch (indexable_ty.ptrSize()) { | 24264 | .Pointer => switch (indexable_ty.ptrSize()) { |
| 24133 | .Slice => return sema.elemValSlice(block, src, indexable_src, indexable, elem_index_src, elem_index), | 24265 | .Slice => return sema.elemValSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety), |
| 24134 | .Many, .C => { | 24266 | .Many, .C => { |
| 24135 | const maybe_indexable_val = try sema.resolveDefinedValue(block, indexable_src, indexable); | 24267 | const maybe_indexable_val = try sema.resolveDefinedValue(block, indexable_src, indexable); |
| 24136 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); | 24268 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); |
| ... | @@ -24151,14 +24283,14 @@ fn elemVal( | ... | @@ -24151,14 +24283,14 @@ fn elemVal( |
| 24151 | }, | 24283 | }, |
| 24152 | .One => { | 24284 | .One => { |
| 24153 | assert(indexable_ty.childType().zigTypeTag() == .Array); // Guaranteed by isIndexable | 24285 | assert(indexable_ty.childType().zigTypeTag() == .Array); // Guaranteed by isIndexable |
| 24154 | const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false); | 24286 | const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false, oob_safety); |
| 24155 | return sema.analyzeLoad(block, indexable_src, elem_ptr, elem_index_src); | 24287 | return sema.analyzeLoad(block, indexable_src, elem_ptr, elem_index_src); |
| 24156 | }, | 24288 | }, |
| 24157 | }, | 24289 | }, |
| 24158 | .Array => return sema.elemValArray(block, src, indexable_src, indexable, elem_index_src, elem_index), | 24290 | .Array => return sema.elemValArray(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety), |
| 24159 | .Vector => { | 24291 | .Vector => { |
| 24160 | // TODO: If the index is a vector, the result should be a vector. | 24292 | // TODO: If the index is a vector, the result should be a vector. |
| 24161 | return sema.elemValArray(block, src, indexable_src, indexable, elem_index_src, elem_index); | 24293 | return sema.elemValArray(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety); |
| 24162 | }, | 24294 | }, |
| 24163 | .Struct => { | 24295 | .Struct => { |
| 24164 | // Tuple field access. | 24296 | // Tuple field access. |
| ... | @@ -24303,6 +24435,7 @@ fn elemValArray( | ... | @@ -24303,6 +24435,7 @@ fn elemValArray( |
| 24303 | array: Air.Inst.Ref, | 24435 | array: Air.Inst.Ref, |
| 24304 | elem_index_src: LazySrcLoc, | 24436 | elem_index_src: LazySrcLoc, |
| 24305 | elem_index: Air.Inst.Ref, | 24437 | elem_index: Air.Inst.Ref, |
| 24438 | oob_safety: bool, | ||
| 24306 | ) CompileError!Air.Inst.Ref { | 24439 | ) CompileError!Air.Inst.Ref { |
| 24307 | const array_ty = sema.typeOf(array); | 24440 | const array_ty = sema.typeOf(array); |
| 24308 | const array_sent = array_ty.sentinel(); | 24441 | const array_sent = array_ty.sentinel(); |
| ... | @@ -24346,7 +24479,7 @@ fn elemValArray( | ... | @@ -24346,7 +24479,7 @@ fn elemValArray( |
| 24346 | 24479 | ||
| 24347 | const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src; | 24480 | const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src; |
| 24348 | try sema.requireRuntimeBlock(block, src, runtime_src); | 24481 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 24349 | if (block.wantSafety()) { | 24482 | if (oob_safety and block.wantSafety()) { |
| 24350 | // Runtime check is only needed if unable to comptime check | 24483 | // Runtime check is only needed if unable to comptime check |
| 24351 | if (maybe_index_val == null) { | 24484 | if (maybe_index_val == null) { |
| 24352 | const len_inst = try sema.addIntUnsigned(Type.usize, array_len); | 24485 | const len_inst = try sema.addIntUnsigned(Type.usize, array_len); |
| ... | @@ -24366,6 +24499,7 @@ fn elemPtrArray( | ... | @@ -24366,6 +24499,7 @@ fn elemPtrArray( |
| 24366 | elem_index_src: LazySrcLoc, | 24499 | elem_index_src: LazySrcLoc, |
| 24367 | elem_index: Air.Inst.Ref, | 24500 | elem_index: Air.Inst.Ref, |
| 24368 | init: bool, | 24501 | init: bool, |
| 24502 | oob_safety: bool, | ||
| 24369 | ) CompileError!Air.Inst.Ref { | 24503 | ) CompileError!Air.Inst.Ref { |
| 24370 | const target = sema.mod.getTarget(); | 24504 | const target = sema.mod.getTarget(); |
| 24371 | const array_ptr_ty = sema.typeOf(array_ptr); | 24505 | const array_ptr_ty = sema.typeOf(array_ptr); |
| ... | @@ -24409,7 +24543,7 @@ fn elemPtrArray( | ... | @@ -24409,7 +24543,7 @@ fn elemPtrArray( |
| 24409 | try sema.requireRuntimeBlock(block, src, runtime_src); | 24543 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 24410 | 24544 | ||
| 24411 | // Runtime check is only needed if unable to comptime check. | 24545 | // Runtime check is only needed if unable to comptime check. |
| 24412 | if (block.wantSafety() and offset == null) { | 24546 | if (oob_safety and block.wantSafety() and offset == null) { |
| 24413 | const len_inst = try sema.addIntUnsigned(Type.usize, array_len); | 24547 | const len_inst = try sema.addIntUnsigned(Type.usize, array_len); |
| 24414 | const cmp_op: Air.Inst.Tag = if (array_sent) .cmp_lte else .cmp_lt; | 24548 | const cmp_op: Air.Inst.Tag = if (array_sent) .cmp_lte else .cmp_lt; |
| 24415 | try sema.panicIndexOutOfBounds(block, elem_index, len_inst, cmp_op); | 24549 | try sema.panicIndexOutOfBounds(block, elem_index, len_inst, cmp_op); |
| ... | @@ -24426,6 +24560,7 @@ fn elemValSlice( | ... | @@ -24426,6 +24560,7 @@ fn elemValSlice( |
| 24426 | slice: Air.Inst.Ref, | 24560 | slice: Air.Inst.Ref, |
| 24427 | elem_index_src: LazySrcLoc, | 24561 | elem_index_src: LazySrcLoc, |
| 24428 | elem_index: Air.Inst.Ref, | 24562 | elem_index: Air.Inst.Ref, |
| 24563 | oob_safety: bool, | ||
| 24429 | ) CompileError!Air.Inst.Ref { | 24564 | ) CompileError!Air.Inst.Ref { |
| 24430 | const slice_ty = sema.typeOf(slice); | 24565 | const slice_ty = sema.typeOf(slice); |
| 24431 | const slice_sent = slice_ty.sentinel() != null; | 24566 | const slice_sent = slice_ty.sentinel() != null; |
| ... | @@ -24462,7 +24597,7 @@ fn elemValSlice( | ... | @@ -24462,7 +24597,7 @@ fn elemValSlice( |
| 24462 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ty, slice_ty, slice_src); | 24597 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ty, slice_ty, slice_src); |
| 24463 | 24598 | ||
| 24464 | try sema.requireRuntimeBlock(block, src, runtime_src); | 24599 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 24465 | if (block.wantSafety()) { | 24600 | if (oob_safety and block.wantSafety()) { |
| 24466 | const len_inst = if (maybe_slice_val) |slice_val| | 24601 | const len_inst = if (maybe_slice_val) |slice_val| |
| 24467 | try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod)) | 24602 | try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod)) |
| 24468 | else | 24603 | else |
| ... | @@ -24482,6 +24617,7 @@ fn elemPtrSlice( | ... | @@ -24482,6 +24617,7 @@ fn elemPtrSlice( |
| 24482 | slice: Air.Inst.Ref, | 24617 | slice: Air.Inst.Ref, |
| 24483 | elem_index_src: LazySrcLoc, | 24618 | elem_index_src: LazySrcLoc, |
| 24484 | elem_index: Air.Inst.Ref, | 24619 | elem_index: Air.Inst.Ref, |
| 24620 | oob_safety: bool, | ||
| 24485 | ) CompileError!Air.Inst.Ref { | 24621 | ) CompileError!Air.Inst.Ref { |
| 24486 | const target = sema.mod.getTarget(); | 24622 | const target = sema.mod.getTarget(); |
| 24487 | const slice_ty = sema.typeOf(slice); | 24623 | const slice_ty = sema.typeOf(slice); |
| ... | @@ -24519,7 +24655,7 @@ fn elemPtrSlice( | ... | @@ -24519,7 +24655,7 @@ fn elemPtrSlice( |
| 24519 | 24655 | ||
| 24520 | const runtime_src = if (maybe_undef_slice_val != null) elem_index_src else slice_src; | 24656 | const runtime_src = if (maybe_undef_slice_val != null) elem_index_src else slice_src; |
| 24521 | try sema.requireRuntimeBlock(block, src, runtime_src); | 24657 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 24522 | if (block.wantSafety()) { | 24658 | if (oob_safety and block.wantSafety()) { |
| 24523 | const len_inst = len: { | 24659 | const len_inst = len: { |
| 24524 | if (maybe_undef_slice_val) |slice_val| | 24660 | if (maybe_undef_slice_val) |slice_val| |
| 24525 | if (!slice_val.isUndef()) | 24661 | if (!slice_val.isUndef()) |
| ... | @@ -25980,7 +26116,7 @@ fn coerceInMemoryAllowedFns( | ... | @@ -25980,7 +26116,7 @@ fn coerceInMemoryAllowedFns( |
| 25980 | } }; | 26116 | } }; |
| 25981 | } | 26117 | } |
| 25982 | 26118 | ||
| 25983 | for (dest_info.param_types) |dest_param_ty, i| { | 26119 | for (dest_info.param_types, 0..) |dest_param_ty, i| { |
| 25984 | const src_param_ty = src_info.param_types[i]; | 26120 | const src_param_ty = src_info.param_types[i]; |
| 25985 | 26121 | ||
| 25986 | if (dest_info.comptime_params[i] != src_info.comptime_params[i]) { | 26122 | if (dest_info.comptime_params[i] != src_info.comptime_params[i]) { |
| ... | @@ -26224,7 +26360,7 @@ fn storePtr2( | ... | @@ -26224,7 +26360,7 @@ fn storePtr2( |
| 26224 | const elem_src = operand_src; // TODO better source location | 26360 | const elem_src = operand_src; // TODO better source location |
| 26225 | const elem = try sema.tupleField(block, operand_src, uncasted_operand, elem_src, i); | 26361 | const elem = try sema.tupleField(block, operand_src, uncasted_operand, elem_src, i); |
| 26226 | const elem_index = try sema.addIntUnsigned(Type.usize, i); | 26362 | const elem_index = try sema.addIntUnsigned(Type.usize, i); |
| 26227 | const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false); | 26363 | const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false, true); |
| 26228 | try sema.storePtr2(block, src, elem_ptr, elem_src, elem, elem_src, .store); | 26364 | try sema.storePtr2(block, src, elem_ptr, elem_src, elem, elem_src, .store); |
| 26229 | } | 26365 | } |
| 26230 | return; | 26366 | return; |
| ... | @@ -26510,7 +26646,7 @@ fn beginComptimePtrMutation( | ... | @@ -26510,7 +26646,7 @@ fn beginComptimePtrMutation( |
| 26510 | // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted. | 26646 | // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted. |
| 26511 | assert(bytes.len >= dest_len); | 26647 | assert(bytes.len >= dest_len); |
| 26512 | const elems = try arena.alloc(Value, @intCast(usize, dest_len)); | 26648 | const elems = try arena.alloc(Value, @intCast(usize, dest_len)); |
| 26513 | for (elems) |*elem, i| { | 26649 | for (elems, 0..) |*elem, i| { |
| 26514 | elem.* = try Value.Tag.int_u64.create(arena, bytes[i]); | 26650 | elem.* = try Value.Tag.int_u64.create(arena, bytes[i]); |
| 26515 | } | 26651 | } |
| 26516 | 26652 | ||
| ... | @@ -26539,7 +26675,7 @@ fn beginComptimePtrMutation( | ... | @@ -26539,7 +26675,7 @@ fn beginComptimePtrMutation( |
| 26539 | const dest_len = parent.ty.arrayLenIncludingSentinel(); | 26675 | const dest_len = parent.ty.arrayLenIncludingSentinel(); |
| 26540 | const bytes = sema.mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len]; | 26676 | const bytes = sema.mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len]; |
| 26541 | const elems = try arena.alloc(Value, @intCast(usize, dest_len)); | 26677 | const elems = try arena.alloc(Value, @intCast(usize, dest_len)); |
| 26542 | for (bytes) |byte, i| { | 26678 | for (bytes, 0..) |byte, i| { |
| 26543 | elems[i] = try Value.Tag.int_u64.create(arena, byte); | 26679 | elems[i] = try Value.Tag.int_u64.create(arena, byte); |
| 26544 | } | 26680 | } |
| 26545 | if (parent.ty.sentinel()) |sent_val| { | 26681 | if (parent.ty.sentinel()) |sent_val| { |
| ... | @@ -27510,7 +27646,7 @@ fn coerceEnumToUnion( | ... | @@ -27510,7 +27646,7 @@ fn coerceEnumToUnion( |
| 27510 | var msg: ?*Module.ErrorMsg = null; | 27646 | var msg: ?*Module.ErrorMsg = null; |
| 27511 | errdefer if (msg) |some| some.destroy(sema.gpa); | 27647 | errdefer if (msg) |some| some.destroy(sema.gpa); |
| 27512 | 27648 | ||
| 27513 | for (union_obj.fields.values()) |field, i| { | 27649 | for (union_obj.fields.values(), 0..) |field, i| { |
| 27514 | if (field.ty.zigTypeTag() == .NoReturn) { | 27650 | if (field.ty.zigTypeTag() == .NoReturn) { |
| 27515 | const err_msg = msg orelse try sema.errMsg( | 27651 | const err_msg = msg orelse try sema.errMsg( |
| 27516 | block, | 27652 | block, |
| ... | @@ -27669,14 +27805,14 @@ fn coerceArrayLike( | ... | @@ -27669,14 +27805,14 @@ fn coerceArrayLike( |
| 27669 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len); | 27805 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len); |
| 27670 | var runtime_src: ?LazySrcLoc = null; | 27806 | var runtime_src: ?LazySrcLoc = null; |
| 27671 | 27807 | ||
| 27672 | for (element_vals) |*elem, i| { | 27808 | for (element_vals, 0..) |*elem, i| { |
| 27673 | const index_ref = try sema.addConstant( | 27809 | const index_ref = try sema.addConstant( |
| 27674 | Type.usize, | 27810 | Type.usize, |
| 27675 | try Value.Tag.int_u64.create(sema.arena, i), | 27811 | try Value.Tag.int_u64.create(sema.arena, i), |
| 27676 | ); | 27812 | ); |
| 27677 | const src = inst_src; // TODO better source location | 27813 | const src = inst_src; // TODO better source location |
| 27678 | const elem_src = inst_src; // TODO better source location | 27814 | const elem_src = inst_src; // TODO better source location |
| 27679 | const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref); | 27815 | const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref, true); |
| 27680 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); | 27816 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 27681 | element_refs[i] = coerced; | 27817 | element_refs[i] = coerced; |
| 27682 | if (runtime_src == null) { | 27818 | if (runtime_src == null) { |
| ... | @@ -27731,7 +27867,7 @@ fn coerceTupleToArray( | ... | @@ -27731,7 +27867,7 @@ fn coerceTupleToArray( |
| 27731 | const dest_elem_ty = dest_ty.childType(); | 27867 | const dest_elem_ty = dest_ty.childType(); |
| 27732 | 27868 | ||
| 27733 | var runtime_src: ?LazySrcLoc = null; | 27869 | var runtime_src: ?LazySrcLoc = null; |
| 27734 | for (element_vals) |*elem, i_usize| { | 27870 | for (element_vals, 0..) |*elem, i_usize| { |
| 27735 | const i = @intCast(u32, i_usize); | 27871 | const i = @intCast(u32, i_usize); |
| 27736 | if (i_usize == inst_len) { | 27872 | if (i_usize == inst_len) { |
| 27737 | elem.* = dest_ty.sentinel().?; | 27873 | elem.* = dest_ty.sentinel().?; |
| ... | @@ -27860,7 +27996,7 @@ fn coerceTupleToStruct( | ... | @@ -27860,7 +27996,7 @@ fn coerceTupleToStruct( |
| 27860 | var root_msg: ?*Module.ErrorMsg = null; | 27996 | var root_msg: ?*Module.ErrorMsg = null; |
| 27861 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); | 27997 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); |
| 27862 | 27998 | ||
| 27863 | for (field_refs) |*field_ref, i| { | 27999 | for (field_refs, 0..) |*field_ref, i| { |
| 27864 | if (field_ref.* != .none) continue; | 28000 | if (field_ref.* != .none) continue; |
| 27865 | 28001 | ||
| 27866 | const field_name = fields.keys()[i]; | 28002 | const field_name = fields.keys()[i]; |
| ... | @@ -27958,7 +28094,7 @@ fn coerceTupleToTuple( | ... | @@ -27958,7 +28094,7 @@ fn coerceTupleToTuple( |
| 27958 | var root_msg: ?*Module.ErrorMsg = null; | 28094 | var root_msg: ?*Module.ErrorMsg = null; |
| 27959 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); | 28095 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); |
| 27960 | 28096 | ||
| 27961 | for (field_refs) |*field_ref, i| { | 28097 | for (field_refs, 0..) |*field_ref, i| { |
| 27962 | if (field_ref.* != .none) continue; | 28098 | if (field_ref.* != .none) continue; |
| 27963 | 28099 | ||
| 27964 | const default_val = tuple_ty.structFieldDefaultValue(i); | 28100 | const default_val = tuple_ty.structFieldDefaultValue(i); |
| ... | @@ -29334,7 +29470,7 @@ fn resolvePeerTypes( | ... | @@ -29334,7 +29470,7 @@ fn resolvePeerTypes( |
| 29334 | var seen_const = false; | 29470 | var seen_const = false; |
| 29335 | var convert_to_slice = false; | 29471 | var convert_to_slice = false; |
| 29336 | var chosen_i: usize = 0; | 29472 | var chosen_i: usize = 0; |
| 29337 | for (instructions[1..]) |candidate, candidate_i| { | 29473 | for (instructions[1..], 0..) |candidate, candidate_i| { |
| 29338 | const candidate_ty = sema.typeOf(candidate); | 29474 | const candidate_ty = sema.typeOf(candidate); |
| 29339 | const chosen_ty = sema.typeOf(chosen); | 29475 | const chosen_ty = sema.typeOf(chosen); |
| 29340 | 29476 | ||
| ... | @@ -29993,7 +30129,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -29993,7 +30129,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 29993 | }; | 30129 | }; |
| 29994 | 30130 | ||
| 29995 | struct_obj.status = .layout_wip; | 30131 | struct_obj.status = .layout_wip; |
| 29996 | for (struct_obj.fields.values()) |field, i| { | 30132 | for (struct_obj.fields.values(), 0..) |field, i| { |
| 29997 | sema.resolveTypeLayout(field.ty) catch |err| switch (err) { | 30133 | sema.resolveTypeLayout(field.ty) catch |err| switch (err) { |
| 29998 | error.AnalysisFail => { | 30134 | error.AnalysisFail => { |
| 29999 | const msg = sema.err orelse return err; | 30135 | const msg = sema.err orelse return err; |
| ... | @@ -30031,7 +30167,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -30031,7 +30167,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 30031 | break :blk try decl_arena_allocator.alloc(u32, struct_obj.fields.count()); | 30167 | break :blk try decl_arena_allocator.alloc(u32, struct_obj.fields.count()); |
| 30032 | }; | 30168 | }; |
| 30033 | 30169 | ||
| 30034 | for (struct_obj.fields.values()) |field, i| { | 30170 | for (struct_obj.fields.values(), 0..) |field, i| { |
| 30035 | optimized_order[i] = if (field.ty.hasRuntimeBits()) | 30171 | optimized_order[i] = if (field.ty.hasRuntimeBits()) |
| 30036 | @intCast(u32, i) | 30172 | @intCast(u32, i) |
| 30037 | else | 30173 | else |
| ... | @@ -30191,6 +30327,29 @@ fn checkBackingIntType(sema: *Sema, block: *Block, src: LazySrcLoc, backing_int_ | ... | @@ -30191,6 +30327,29 @@ fn checkBackingIntType(sema: *Sema, block: *Block, src: LazySrcLoc, backing_int_ |
| 30191 | } | 30327 | } |
| 30192 | } | 30328 | } |
| 30193 | 30329 | ||
| 30330 | fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, array_ty: Type) !void { | ||
| 30331 | if (!array_ty.isIndexable()) { | ||
| 30332 | const msg = msg: { | ||
| 30333 | const msg = try sema.errMsg( | ||
| 30334 | block, | ||
| 30335 | src, | ||
| 30336 | "type '{}' does not support indexing", | ||
| 30337 | .{array_ty.fmt(sema.mod)}, | ||
| 30338 | ); | ||
| 30339 | errdefer msg.destroy(sema.gpa); | ||
| 30340 | try sema.errNote( | ||
| 30341 | block, | ||
| 30342 | src, | ||
| 30343 | msg, | ||
| 30344 | "for loop operand must be an array, slice, tuple, or vector", | ||
| 30345 | .{}, | ||
| 30346 | ); | ||
| 30347 | break :msg msg; | ||
| 30348 | }; | ||
| 30349 | return sema.failWithOwnedErrorMsg(msg); | ||
| 30350 | } | ||
| 30351 | } | ||
| 30352 | |||
| 30194 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | 30353 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 30195 | const resolved_ty = try sema.resolveTypeFields(ty); | 30354 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 30196 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; | 30355 | const union_obj = resolved_ty.cast(Type.Payload.Union).?.data; |
| ... | @@ -30213,7 +30372,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -30213,7 +30372,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 30213 | }; | 30372 | }; |
| 30214 | 30373 | ||
| 30215 | union_obj.status = .layout_wip; | 30374 | union_obj.status = .layout_wip; |
| 30216 | for (union_obj.fields.values()) |field, i| { | 30375 | for (union_obj.fields.values(), 0..) |field, i| { |
| 30217 | sema.resolveTypeLayout(field.ty) catch |err| switch (err) { | 30376 | sema.resolveTypeLayout(field.ty) catch |err| switch (err) { |
| 30218 | error.AnalysisFail => { | 30377 | error.AnalysisFail => { |
| 30219 | const msg = sema.err orelse return err; | 30378 | const msg = sema.err orelse return err; |
| ... | @@ -30361,7 +30520,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { | ... | @@ -30361,7 +30520,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 30361 | 30520 | ||
| 30362 | .tuple, .anon_struct => { | 30521 | .tuple, .anon_struct => { |
| 30363 | const tuple = ty.tupleFields(); | 30522 | const tuple = ty.tupleFields(); |
| 30364 | for (tuple.types) |field_ty, i| { | 30523 | for (tuple.types, 0..) |field_ty, i| { |
| 30365 | const have_comptime_val = tuple.values[i].tag() != .unreachable_value; | 30524 | const have_comptime_val = tuple.values[i].tag() != .unreachable_value; |
| 30366 | if (!have_comptime_val and try sema.resolveTypeRequiresComptime(field_ty)) { | 30525 | if (!have_comptime_val and try sema.resolveTypeRequiresComptime(field_ty)) { |
| 30367 | return true; | 30526 | return true; |
| ... | @@ -30876,7 +31035,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -30876,7 +31035,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 30876 | // so that init values may depend on type layout. | 31035 | // so that init values may depend on type layout. |
| 30877 | const bodies_index = extra_index; | 31036 | const bodies_index = extra_index; |
| 30878 | 31037 | ||
| 30879 | for (fields) |zir_field, field_i| { | 31038 | for (fields, 0..) |zir_field, field_i| { |
| 30880 | const field_ty: Type = ty: { | 31039 | const field_ty: Type = ty: { |
| 30881 | if (zir_field.type_ref != .none) { | 31040 | if (zir_field.type_ref != .none) { |
| 30882 | break :ty sema.resolveType(&block_scope, .unneeded, zir_field.type_ref) catch |err| switch (err) { | 31041 | break :ty sema.resolveType(&block_scope, .unneeded, zir_field.type_ref) catch |err| switch (err) { |
| ... | @@ -30998,7 +31157,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -30998,7 +31157,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 30998 | 31157 | ||
| 30999 | if (any_inits) { | 31158 | if (any_inits) { |
| 31000 | extra_index = bodies_index; | 31159 | extra_index = bodies_index; |
| 31001 | for (fields) |zir_field, field_i| { | 31160 | for (fields, 0..) |zir_field, field_i| { |
| 31002 | extra_index += zir_field.type_body_len; | 31161 | extra_index += zir_field.type_body_len; |
| 31003 | extra_index += zir_field.align_body_len; | 31162 | extra_index += zir_field.align_body_len; |
| 31004 | if (zir_field.init_body_len > 0) { | 31163 | if (zir_field.init_body_len > 0) { |
| ... | @@ -31718,7 +31877,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -31718,7 +31877,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 31718 | .@"struct" => { | 31877 | .@"struct" => { |
| 31719 | const resolved_ty = try sema.resolveTypeFields(ty); | 31878 | const resolved_ty = try sema.resolveTypeFields(ty); |
| 31720 | const s = resolved_ty.castTag(.@"struct").?.data; | 31879 | const s = resolved_ty.castTag(.@"struct").?.data; |
| 31721 | for (s.fields.values()) |field, i| { | 31880 | for (s.fields.values(), 0..) |field, i| { |
| 31722 | if (field.is_comptime) continue; | 31881 | if (field.is_comptime) continue; |
| 31723 | if (field.ty.eql(resolved_ty, sema.mod)) { | 31882 | if (field.ty.eql(resolved_ty, sema.mod)) { |
| 31724 | const msg = try Module.ErrorMsg.create( | 31883 | const msg = try Module.ErrorMsg.create( |
| ... | @@ -31739,7 +31898,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -31739,7 +31898,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 31739 | 31898 | ||
| 31740 | .tuple, .anon_struct => { | 31899 | .tuple, .anon_struct => { |
| 31741 | const tuple = ty.tupleFields(); | 31900 | const tuple = ty.tupleFields(); |
| 31742 | for (tuple.values) |val, i| { | 31901 | for (tuple.values, 0..) |val, i| { |
| 31743 | const is_comptime = val.tag() != .unreachable_value; | 31902 | const is_comptime = val.tag() != .unreachable_value; |
| 31744 | if (is_comptime) continue; | 31903 | if (is_comptime) continue; |
| 31745 | if ((try sema.typeHasOnePossibleValue(tuple.types[i])) != null) continue; | 31904 | if ((try sema.typeHasOnePossibleValue(tuple.types[i])) != null) continue; |
| ... | @@ -32379,7 +32538,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { | ... | @@ -32379,7 +32538,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 32379 | 32538 | ||
| 32380 | .tuple, .anon_struct => { | 32539 | .tuple, .anon_struct => { |
| 32381 | const tuple = ty.tupleFields(); | 32540 | const tuple = ty.tupleFields(); |
| 32382 | for (tuple.types) |field_ty, i| { | 32541 | for (tuple.types, 0..) |field_ty, i| { |
| 32383 | const have_comptime_val = tuple.values[i].tag() != .unreachable_value; | 32542 | const have_comptime_val = tuple.values[i].tag() != .unreachable_value; |
| 32384 | if (!have_comptime_val and try sema.typeRequiresComptime(field_ty)) { | 32543 | if (!have_comptime_val and try sema.typeRequiresComptime(field_ty)) { |
| 32385 | return true; | 32544 | return true; |
| ... | @@ -32539,7 +32698,7 @@ fn anonStructFieldIndex( | ... | @@ -32539,7 +32698,7 @@ fn anonStructFieldIndex( |
| 32539 | field_src: LazySrcLoc, | 32698 | field_src: LazySrcLoc, |
| 32540 | ) !u32 { | 32699 | ) !u32 { |
| 32541 | const anon_struct = struct_ty.castTag(.anon_struct).?.data; | 32700 | const anon_struct = struct_ty.castTag(.anon_struct).?.data; |
| 32542 | for (anon_struct.names) |name, i| { | 32701 | for (anon_struct.names, 0..) |name, i| { |
| 32543 | if (mem.eql(u8, name, field_name)) { | 32702 | if (mem.eql(u8, name, field_name)) { |
| 32544 | return @intCast(u32, i); | 32703 | return @intCast(u32, i); |
| 32545 | } | 32704 | } |
| ... | @@ -32557,7 +32716,7 @@ fn queueFullTypeResolution(sema: *Sema, ty: Type) !void { | ... | @@ -32557,7 +32716,7 @@ fn queueFullTypeResolution(sema: *Sema, ty: Type) !void { |
| 32557 | fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value { | 32716 | fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value { |
| 32558 | if (ty.zigTypeTag() == .Vector) { | 32717 | if (ty.zigTypeTag() == .Vector) { |
| 32559 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 32718 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 32560 | for (result_data) |*scalar, i| { | 32719 | for (result_data, 0..) |*scalar, i| { |
| 32561 | var lhs_buf: Value.ElemValueBuffer = undefined; | 32720 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 32562 | var rhs_buf: Value.ElemValueBuffer = undefined; | 32721 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 32563 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); | 32722 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); |
| ... | @@ -32615,7 +32774,7 @@ fn intSub( | ... | @@ -32615,7 +32774,7 @@ fn intSub( |
| 32615 | ) !Value { | 32774 | ) !Value { |
| 32616 | if (ty.zigTypeTag() == .Vector) { | 32775 | if (ty.zigTypeTag() == .Vector) { |
| 32617 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 32776 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 32618 | for (result_data) |*scalar, i| { | 32777 | for (result_data, 0..) |*scalar, i| { |
| 32619 | var lhs_buf: Value.ElemValueBuffer = undefined; | 32778 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 32620 | var rhs_buf: Value.ElemValueBuffer = undefined; | 32779 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 32621 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); | 32780 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); |
| ... | @@ -32673,7 +32832,7 @@ fn floatAdd( | ... | @@ -32673,7 +32832,7 @@ fn floatAdd( |
| 32673 | ) !Value { | 32832 | ) !Value { |
| 32674 | if (float_type.zigTypeTag() == .Vector) { | 32833 | if (float_type.zigTypeTag() == .Vector) { |
| 32675 | const result_data = try sema.arena.alloc(Value, float_type.vectorLen()); | 32834 | const result_data = try sema.arena.alloc(Value, float_type.vectorLen()); |
| 32676 | for (result_data) |*scalar, i| { | 32835 | for (result_data, 0..) |*scalar, i| { |
| 32677 | var lhs_buf: Value.ElemValueBuffer = undefined; | 32836 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 32678 | var rhs_buf: Value.ElemValueBuffer = undefined; | 32837 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 32679 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); | 32838 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); |
| ... | @@ -32730,7 +32889,7 @@ fn floatSub( | ... | @@ -32730,7 +32889,7 @@ fn floatSub( |
| 32730 | ) !Value { | 32889 | ) !Value { |
| 32731 | if (float_type.zigTypeTag() == .Vector) { | 32890 | if (float_type.zigTypeTag() == .Vector) { |
| 32732 | const result_data = try sema.arena.alloc(Value, float_type.vectorLen()); | 32891 | const result_data = try sema.arena.alloc(Value, float_type.vectorLen()); |
| 32733 | for (result_data) |*scalar, i| { | 32892 | for (result_data, 0..) |*scalar, i| { |
| 32734 | var lhs_buf: Value.ElemValueBuffer = undefined; | 32893 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 32735 | var rhs_buf: Value.ElemValueBuffer = undefined; | 32894 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 32736 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); | 32895 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); |
| ... | @@ -32788,7 +32947,7 @@ fn intSubWithOverflow( | ... | @@ -32788,7 +32947,7 @@ fn intSubWithOverflow( |
| 32788 | if (ty.zigTypeTag() == .Vector) { | 32947 | if (ty.zigTypeTag() == .Vector) { |
| 32789 | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen()); | 32948 | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 32790 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 32949 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 32791 | for (result_data) |*scalar, i| { | 32950 | for (result_data, 0..) |*scalar, i| { |
| 32792 | var lhs_buf: Value.ElemValueBuffer = undefined; | 32951 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 32793 | var rhs_buf: Value.ElemValueBuffer = undefined; | 32952 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 32794 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); | 32953 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); |
| ... | @@ -32842,7 +33001,7 @@ fn floatToInt( | ... | @@ -32842,7 +33001,7 @@ fn floatToInt( |
| 32842 | if (float_ty.zigTypeTag() == .Vector) { | 33001 | if (float_ty.zigTypeTag() == .Vector) { |
| 32843 | const elem_ty = float_ty.childType(); | 33002 | const elem_ty = float_ty.childType(); |
| 32844 | const result_data = try sema.arena.alloc(Value, float_ty.vectorLen()); | 33003 | const result_data = try sema.arena.alloc(Value, float_ty.vectorLen()); |
| 32845 | for (result_data) |*scalar, i| { | 33004 | for (result_data, 0..) |*scalar, i| { |
| 32846 | var buf: Value.ElemValueBuffer = undefined; | 33005 | var buf: Value.ElemValueBuffer = undefined; |
| 32847 | const elem_val = val.elemValueBuffer(sema.mod, i, &buf); | 33006 | const elem_val = val.elemValueBuffer(sema.mod, i, &buf); |
| 32848 | scalar.* = try sema.floatToIntScalar(block, src, elem_val, elem_ty, int_ty.scalarType()); | 33007 | scalar.* = try sema.floatToIntScalar(block, src, elem_val, elem_ty, int_ty.scalarType()); |
| ... | @@ -33042,7 +33201,7 @@ fn intFitsInType( | ... | @@ -33042,7 +33201,7 @@ fn intFitsInType( |
| 33042 | 33201 | ||
| 33043 | .aggregate => { | 33202 | .aggregate => { |
| 33044 | assert(ty.zigTypeTag() == .Vector); | 33203 | assert(ty.zigTypeTag() == .Vector); |
| 33045 | for (val.castTag(.aggregate).?.data) |elem, i| { | 33204 | for (val.castTag(.aggregate).?.data, 0..) |elem, i| { |
| 33046 | if (!(try sema.intFitsInType(elem, ty.scalarType(), null))) { | 33205 | if (!(try sema.intFitsInType(elem, ty.scalarType(), null))) { |
| 33047 | if (vector_index) |some| some.* = i; | 33206 | if (vector_index) |some| some.* = i; |
| 33048 | return false; | 33207 | return false; |
| ... | @@ -33139,7 +33298,7 @@ fn intAddWithOverflow( | ... | @@ -33139,7 +33298,7 @@ fn intAddWithOverflow( |
| 33139 | if (ty.zigTypeTag() == .Vector) { | 33298 | if (ty.zigTypeTag() == .Vector) { |
| 33140 | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen()); | 33299 | const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 33141 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 33300 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 33142 | for (result_data) |*scalar, i| { | 33301 | for (result_data, 0..) |*scalar, i| { |
| 33143 | var lhs_buf: Value.ElemValueBuffer = undefined; | 33302 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 33144 | var rhs_buf: Value.ElemValueBuffer = undefined; | 33303 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 33145 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); | 33304 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); |
| ... | @@ -33243,7 +33402,7 @@ fn compareVector( | ... | @@ -33243,7 +33402,7 @@ fn compareVector( |
| 33243 | ) !Value { | 33402 | ) !Value { |
| 33244 | assert(ty.zigTypeTag() == .Vector); | 33403 | assert(ty.zigTypeTag() == .Vector); |
| 33245 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); | 33404 | const result_data = try sema.arena.alloc(Value, ty.vectorLen()); |
| 33246 | for (result_data) |*scalar, i| { | 33405 | for (result_data, 0..) |*scalar, i| { |
| 33247 | var lhs_buf: Value.ElemValueBuffer = undefined; | 33406 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 33248 | var rhs_buf: Value.ElemValueBuffer = undefined; | 33407 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 33249 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); | 33408 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); |
src/Zir.zig+25-2| ... | @@ -137,6 +137,8 @@ pub const Inst = struct { | ... | @@ -137,6 +137,8 @@ pub const Inst = struct { |
| 137 | /// Saturating addition. | 137 | /// Saturating addition. |
| 138 | /// Uses the `pl_node` union field. Payload is `Bin`. | 138 | /// Uses the `pl_node` union field. Payload is `Bin`. |
| 139 | add_sat, | 139 | add_sat, |
| 140 | /// The same as `add` except no safety check. | ||
| 141 | add_unsafe, | ||
| 140 | /// Arithmetic subtraction. Asserts no integer overflow. | 142 | /// Arithmetic subtraction. Asserts no integer overflow. |
| 141 | /// Uses the `pl_node` union field. Payload is `Bin`. | 143 | /// Uses the `pl_node` union field. Payload is `Bin`. |
| 142 | sub, | 144 | sub, |
| ... | @@ -382,18 +384,24 @@ pub const Inst = struct { | ... | @@ -382,18 +384,24 @@ pub const Inst = struct { |
| 382 | /// Uses the `pl_node` union field. AST node is a[b] syntax. Payload is `Bin`. | 384 | /// Uses the `pl_node` union field. AST node is a[b] syntax. Payload is `Bin`. |
| 383 | elem_ptr_node, | 385 | elem_ptr_node, |
| 384 | /// Same as `elem_ptr_node` but used only for for loop. | 386 | /// Same as `elem_ptr_node` but used only for for loop. |
| 385 | /// Uses the `pl_node` union field. AST node is the condition of a for loop. Payload is `Bin`. | 387 | /// Uses the `pl_node` union field. AST node is the condition of a for loop. |
| 388 | /// Payload is `Bin`. | ||
| 389 | /// No OOB safety check is emitted. | ||
| 386 | elem_ptr, | 390 | elem_ptr, |
| 387 | /// Same as `elem_ptr_node` except the index is stored immediately rather than | 391 | /// Same as `elem_ptr_node` except the index is stored immediately rather than |
| 388 | /// as a reference to another ZIR instruction. | 392 | /// as a reference to another ZIR instruction. |
| 389 | /// Uses the `pl_node` union field. AST node is an element inside array initialization | 393 | /// Uses the `pl_node` union field. AST node is an element inside array initialization |
| 390 | /// syntax. Payload is `ElemPtrImm`. | 394 | /// syntax. Payload is `ElemPtrImm`. |
| 395 | /// This instruction has a way to set the result type to be a | ||
| 396 | /// single-pointer or a many-pointer. | ||
| 391 | elem_ptr_imm, | 397 | elem_ptr_imm, |
| 392 | /// Given an array, slice, or pointer, returns the element at the provided index. | 398 | /// Given an array, slice, or pointer, returns the element at the provided index. |
| 393 | /// Uses the `pl_node` union field. AST node is a[b] syntax. Payload is `Bin`. | 399 | /// Uses the `pl_node` union field. AST node is a[b] syntax. Payload is `Bin`. |
| 394 | elem_val_node, | 400 | elem_val_node, |
| 395 | /// Same as `elem_val_node` but used only for for loop. | 401 | /// Same as `elem_val_node` but used only for for loop. |
| 396 | /// Uses the `pl_node` union field. AST node is the condition of a for loop. Payload is `Bin`. | 402 | /// Uses the `pl_node` union field. AST node is the condition of a for loop. |
| 403 | /// Payload is `Bin`. | ||
| 404 | /// No OOB safety check is emitted. | ||
| 397 | elem_val, | 405 | elem_val, |
| 398 | /// Emits a compile error if the operand is not `void`. | 406 | /// Emits a compile error if the operand is not `void`. |
| 399 | /// Uses the `un_node` field. | 407 | /// Uses the `un_node` field. |
| ... | @@ -497,6 +505,15 @@ pub const Inst = struct { | ... | @@ -497,6 +505,15 @@ pub const Inst = struct { |
| 497 | /// Sends comptime control flow back to the beginning of the current block. | 505 | /// Sends comptime control flow back to the beginning of the current block. |
| 498 | /// Uses the `node` field. | 506 | /// Uses the `node` field. |
| 499 | repeat_inline, | 507 | repeat_inline, |
| 508 | /// Asserts that all the lengths provided match. Used to build a for loop. | ||
| 509 | /// Return value is the length as a usize. | ||
| 510 | /// Uses the `pl_node` field with payload `MultiOp`. | ||
| 511 | /// There is exactly one item corresponding to each AST node inside the for | ||
| 512 | /// loop condition. Any item may be `none`, indicating an unbounded range. | ||
| 513 | /// Illegal behaviors: | ||
| 514 | /// * If all lengths are unbounded ranges (always a compile error). | ||
| 515 | /// * If any two lengths do not match each other. | ||
| 516 | for_len, | ||
| 500 | /// Merge two error sets into one, `E1 || E2`. | 517 | /// Merge two error sets into one, `E1 || E2`. |
| 501 | /// Uses the `pl_node` field with payload `Bin`. | 518 | /// Uses the `pl_node` field with payload `Bin`. |
| 502 | merge_error_sets, | 519 | merge_error_sets, |
| ... | @@ -1008,6 +1025,7 @@ pub const Inst = struct { | ... | @@ -1008,6 +1025,7 @@ pub const Inst = struct { |
| 1008 | .add, | 1025 | .add, |
| 1009 | .addwrap, | 1026 | .addwrap, |
| 1010 | .add_sat, | 1027 | .add_sat, |
| 1028 | .add_unsafe, | ||
| 1011 | .alloc, | 1029 | .alloc, |
| 1012 | .alloc_mut, | 1030 | .alloc_mut, |
| 1013 | .alloc_comptime_mut, | 1031 | .alloc_comptime_mut, |
| ... | @@ -1242,6 +1260,7 @@ pub const Inst = struct { | ... | @@ -1242,6 +1260,7 @@ pub const Inst = struct { |
| 1242 | .defer_err_code, | 1260 | .defer_err_code, |
| 1243 | .save_err_ret_index, | 1261 | .save_err_ret_index, |
| 1244 | .restore_err_ret_index, | 1262 | .restore_err_ret_index, |
| 1263 | .for_len, | ||
| 1245 | => false, | 1264 | => false, |
| 1246 | 1265 | ||
| 1247 | .@"break", | 1266 | .@"break", |
| ... | @@ -1322,6 +1341,7 @@ pub const Inst = struct { | ... | @@ -1322,6 +1341,7 @@ pub const Inst = struct { |
| 1322 | .add, | 1341 | .add, |
| 1323 | .addwrap, | 1342 | .addwrap, |
| 1324 | .add_sat, | 1343 | .add_sat, |
| 1344 | .add_unsafe, | ||
| 1325 | .alloc, | 1345 | .alloc, |
| 1326 | .alloc_mut, | 1346 | .alloc_mut, |
| 1327 | .alloc_comptime_mut, | 1347 | .alloc_comptime_mut, |
| ... | @@ -1533,6 +1553,7 @@ pub const Inst = struct { | ... | @@ -1533,6 +1553,7 @@ pub const Inst = struct { |
| 1533 | .repeat_inline, | 1553 | .repeat_inline, |
| 1534 | .panic, | 1554 | .panic, |
| 1535 | .panic_comptime, | 1555 | .panic_comptime, |
| 1556 | .for_len, | ||
| 1536 | .@"try", | 1557 | .@"try", |
| 1537 | .try_ptr, | 1558 | .try_ptr, |
| 1538 | //.try_inline, | 1559 | //.try_inline, |
| ... | @@ -1553,6 +1574,7 @@ pub const Inst = struct { | ... | @@ -1553,6 +1574,7 @@ pub const Inst = struct { |
| 1553 | .add = .pl_node, | 1574 | .add = .pl_node, |
| 1554 | .addwrap = .pl_node, | 1575 | .addwrap = .pl_node, |
| 1555 | .add_sat = .pl_node, | 1576 | .add_sat = .pl_node, |
| 1577 | .add_unsafe = .pl_node, | ||
| 1556 | .sub = .pl_node, | 1578 | .sub = .pl_node, |
| 1557 | .subwrap = .pl_node, | 1579 | .subwrap = .pl_node, |
| 1558 | .sub_sat = .pl_node, | 1580 | .sub_sat = .pl_node, |
| ... | @@ -1588,6 +1610,7 @@ pub const Inst = struct { | ... | @@ -1588,6 +1610,7 @@ pub const Inst = struct { |
| 1588 | .@"break" = .@"break", | 1610 | .@"break" = .@"break", |
| 1589 | .break_inline = .@"break", | 1611 | .break_inline = .@"break", |
| 1590 | .check_comptime_control_flow = .un_node, | 1612 | .check_comptime_control_flow = .un_node, |
| 1613 | .for_len = .pl_node, | ||
| 1591 | .call = .pl_node, | 1614 | .call = .pl_node, |
| 1592 | .cmp_lt = .pl_node, | 1615 | .cmp_lt = .pl_node, |
| 1593 | .cmp_lte = .pl_node, | 1616 | .cmp_lte = .pl_node, |
src/arch/aarch64/CodeGen.zig+13-13| ... | @@ -515,7 +515,7 @@ fn gen(self: *Self) !void { | ... | @@ -515,7 +515,7 @@ fn gen(self: *Self) !void { |
| 515 | self.ret_mcv = MCValue{ .stack_offset = stack_offset }; | 515 | self.ret_mcv = MCValue{ .stack_offset = stack_offset }; |
| 516 | } | 516 | } |
| 517 | 517 | ||
| 518 | for (self.args) |*arg, arg_index| { | 518 | for (self.args, 0..) |*arg, arg_index| { |
| 519 | // Copy register arguments to the stack | 519 | // Copy register arguments to the stack |
| 520 | switch (arg.*) { | 520 | switch (arg.*) { |
| 521 | .register => |reg| { | 521 | .register => |reg| { |
| ... | @@ -1633,14 +1633,14 @@ fn allocRegs( | ... | @@ -1633,14 +1633,14 @@ fn allocRegs( |
| 1633 | var reused_read_arg: ?usize = null; | 1633 | var reused_read_arg: ?usize = null; |
| 1634 | 1634 | ||
| 1635 | // Lock all args which are already allocated to registers | 1635 | // Lock all args which are already allocated to registers |
| 1636 | for (read_args) |arg, i| { | 1636 | for (read_args, 0..) |arg, i| { |
| 1637 | const mcv = try arg.bind.resolveToMcv(self); | 1637 | const mcv = try arg.bind.resolveToMcv(self); |
| 1638 | if (mcv == .register) { | 1638 | if (mcv == .register) { |
| 1639 | read_locks[i] = self.register_manager.lockReg(mcv.register); | 1639 | read_locks[i] = self.register_manager.lockReg(mcv.register); |
| 1640 | } | 1640 | } |
| 1641 | } | 1641 | } |
| 1642 | 1642 | ||
| 1643 | for (write_args) |arg, i| { | 1643 | for (write_args, 0..) |arg, i| { |
| 1644 | if (arg.bind == .reg) { | 1644 | if (arg.bind == .reg) { |
| 1645 | write_locks[i] = self.register_manager.lockReg(arg.bind.reg); | 1645 | write_locks[i] = self.register_manager.lockReg(arg.bind.reg); |
| 1646 | } | 1646 | } |
| ... | @@ -1648,7 +1648,7 @@ fn allocRegs( | ... | @@ -1648,7 +1648,7 @@ fn allocRegs( |
| 1648 | 1648 | ||
| 1649 | // Allocate registers for all args which aren't allocated to | 1649 | // Allocate registers for all args which aren't allocated to |
| 1650 | // registers yet | 1650 | // registers yet |
| 1651 | for (read_args) |arg, i| { | 1651 | for (read_args, 0..) |arg, i| { |
| 1652 | const mcv = try arg.bind.resolveToMcv(self); | 1652 | const mcv = try arg.bind.resolveToMcv(self); |
| 1653 | if (mcv == .register) { | 1653 | if (mcv == .register) { |
| 1654 | const raw_reg = mcv.register; | 1654 | const raw_reg = mcv.register; |
| ... | @@ -1672,7 +1672,7 @@ fn allocRegs( | ... | @@ -1672,7 +1672,7 @@ fn allocRegs( |
| 1672 | const raw_reg = arg.bind.reg; | 1672 | const raw_reg = arg.bind.reg; |
| 1673 | arg.reg.* = self.registerAlias(raw_reg, arg.ty); | 1673 | arg.reg.* = self.registerAlias(raw_reg, arg.ty); |
| 1674 | } else { | 1674 | } else { |
| 1675 | reuse_operand: for (read_args) |read_arg, i| { | 1675 | reuse_operand: for (read_args, 0..) |read_arg, i| { |
| 1676 | if (read_arg.bind == .inst) { | 1676 | if (read_arg.bind == .inst) { |
| 1677 | const operand = read_arg.bind.inst; | 1677 | const operand = read_arg.bind.inst; |
| 1678 | const mcv = try self.resolveInst(operand); | 1678 | const mcv = try self.resolveInst(operand); |
| ... | @@ -1694,7 +1694,7 @@ fn allocRegs( | ... | @@ -1694,7 +1694,7 @@ fn allocRegs( |
| 1694 | } | 1694 | } |
| 1695 | } | 1695 | } |
| 1696 | } else { | 1696 | } else { |
| 1697 | for (write_args) |arg, i| { | 1697 | for (write_args, 0..) |arg, i| { |
| 1698 | if (arg.bind == .reg) { | 1698 | if (arg.bind == .reg) { |
| 1699 | const raw_reg = arg.bind.reg; | 1699 | const raw_reg = arg.bind.reg; |
| 1700 | arg.reg.* = self.registerAlias(raw_reg, arg.ty); | 1700 | arg.reg.* = self.registerAlias(raw_reg, arg.ty); |
| ... | @@ -1708,7 +1708,7 @@ fn allocRegs( | ... | @@ -1708,7 +1708,7 @@ fn allocRegs( |
| 1708 | 1708 | ||
| 1709 | // For all read_args which need to be moved from non-register to | 1709 | // For all read_args which need to be moved from non-register to |
| 1710 | // register, perform the move | 1710 | // register, perform the move |
| 1711 | for (read_args) |arg, i| { | 1711 | for (read_args, 0..) |arg, i| { |
| 1712 | if (reused_read_arg) |j| { | 1712 | if (reused_read_arg) |j| { |
| 1713 | // Check whether this read_arg was reused | 1713 | // Check whether this read_arg was reused |
| 1714 | if (i == j) continue; | 1714 | if (i == j) continue; |
| ... | @@ -4267,7 +4267,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier | ... | @@ -4267,7 +4267,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 4267 | // Make space for the arguments passed via the stack | 4267 | // Make space for the arguments passed via the stack |
| 4268 | self.max_end_stack += info.stack_byte_count; | 4268 | self.max_end_stack += info.stack_byte_count; |
| 4269 | 4269 | ||
| 4270 | for (info.args) |mc_arg, arg_i| { | 4270 | for (info.args, 0..) |mc_arg, arg_i| { |
| 4271 | const arg = args[arg_i]; | 4271 | const arg = args[arg_i]; |
| 4272 | const arg_ty = self.air.typeOf(arg); | 4272 | const arg_ty = self.air.typeOf(arg); |
| 4273 | const arg_mcv = try self.resolveInst(args[arg_i]); | 4273 | const arg_mcv = try self.resolveInst(args[arg_i]); |
| ... | @@ -4757,7 +4757,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -4757,7 +4757,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 4757 | const else_slice = else_branch.inst_table.entries.slice(); | 4757 | const else_slice = else_branch.inst_table.entries.slice(); |
| 4758 | const else_keys = else_slice.items(.key); | 4758 | const else_keys = else_slice.items(.key); |
| 4759 | const else_values = else_slice.items(.value); | 4759 | const else_values = else_slice.items(.value); |
| 4760 | for (else_keys) |else_key, else_idx| { | 4760 | for (else_keys, 0..) |else_key, else_idx| { |
| 4761 | const else_value = else_values[else_idx]; | 4761 | const else_value = else_values[else_idx]; |
| 4762 | const canon_mcv = if (saved_then_branch.inst_table.fetchSwapRemove(else_key)) |then_entry| blk: { | 4762 | const canon_mcv = if (saved_then_branch.inst_table.fetchSwapRemove(else_key)) |then_entry| blk: { |
| 4763 | // The instruction's MCValue is overridden in both branches. | 4763 | // The instruction's MCValue is overridden in both branches. |
| ... | @@ -4790,7 +4790,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -4790,7 +4790,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 4790 | const then_slice = saved_then_branch.inst_table.entries.slice(); | 4790 | const then_slice = saved_then_branch.inst_table.entries.slice(); |
| 4791 | const then_keys = then_slice.items(.key); | 4791 | const then_keys = then_slice.items(.key); |
| 4792 | const then_values = then_slice.items(.value); | 4792 | const then_values = then_slice.items(.value); |
| 4793 | for (then_keys) |then_key, then_idx| { | 4793 | for (then_keys, 0..) |then_key, then_idx| { |
| 4794 | const then_value = then_values[then_idx]; | 4794 | const then_value = then_values[then_idx]; |
| 4795 | // We already deleted the items from this table that matched the else_branch. | 4795 | // We already deleted the items from this table that matched the else_branch. |
| 4796 | // So these are all instructions that are only overridden in the then branch. | 4796 | // So these are all instructions that are only overridden in the then branch. |
| ... | @@ -5069,7 +5069,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -5069,7 +5069,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 5069 | const branch_into_prong_relocs = try self.gpa.alloc(u32, items.len); | 5069 | const branch_into_prong_relocs = try self.gpa.alloc(u32, items.len); |
| 5070 | defer self.gpa.free(branch_into_prong_relocs); | 5070 | defer self.gpa.free(branch_into_prong_relocs); |
| 5071 | 5071 | ||
| 5072 | for (items) |item, idx| { | 5072 | for (items, 0..) |item, idx| { |
| 5073 | const cmp_result = try self.cmp(.{ .inst = pl_op.operand }, .{ .inst = item }, condition_ty, .neq); | 5073 | const cmp_result = try self.cmp(.{ .inst = pl_op.operand }, .{ .inst = item }, condition_ty, .neq); |
| 5074 | branch_into_prong_relocs[idx] = try self.condBr(cmp_result); | 5074 | branch_into_prong_relocs[idx] = try self.condBr(cmp_result); |
| 5075 | } | 5075 | } |
| ... | @@ -6373,7 +6373,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -6373,7 +6373,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6373 | } | 6373 | } |
| 6374 | } | 6374 | } |
| 6375 | 6375 | ||
| 6376 | for (param_types) |ty, i| { | 6376 | for (param_types, 0..) |ty, i| { |
| 6377 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); | 6377 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); |
| 6378 | if (param_size == 0) { | 6378 | if (param_size == 0) { |
| 6379 | result.args[i] = .{ .none = {} }; | 6379 | result.args[i] = .{ .none = {} }; |
| ... | @@ -6438,7 +6438,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -6438,7 +6438,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6438 | 6438 | ||
| 6439 | var stack_offset: u32 = 0; | 6439 | var stack_offset: u32 = 0; |
| 6440 | 6440 | ||
| 6441 | for (param_types) |ty, i| { | 6441 | for (param_types, 0..) |ty, i| { |
| 6442 | if (ty.abiSize(self.target.*) > 0) { | 6442 | if (ty.abiSize(self.target.*) > 0) { |
| 6443 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); | 6443 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); |
| 6444 | const param_alignment = ty.abiAlignment(self.target.*); | 6444 | const param_alignment = ty.abiAlignment(self.target.*); |
src/arch/aarch64/Emit.zig+3-3| ... | @@ -80,7 +80,7 @@ pub fn emitMir( | ... | @@ -80,7 +80,7 @@ pub fn emitMir( |
| 80 | try emit.lowerBranches(); | 80 | try emit.lowerBranches(); |
| 81 | 81 | ||
| 82 | // Emit machine code | 82 | // Emit machine code |
| 83 | for (mir_tags) |tag, index| { | 83 | for (mir_tags, 0..) |tag, index| { |
| 84 | const inst = @intCast(u32, index); | 84 | const inst = @intCast(u32, index); |
| 85 | switch (tag) { | 85 | switch (tag) { |
| 86 | .add_immediate => try emit.mirAddSubtractImmediate(inst), | 86 | .add_immediate => try emit.mirAddSubtractImmediate(inst), |
| ... | @@ -323,7 +323,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -323,7 +323,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 323 | // | 323 | // |
| 324 | // TODO optimization opportunity: do this in codegen while | 324 | // TODO optimization opportunity: do this in codegen while |
| 325 | // generating MIR | 325 | // generating MIR |
| 326 | for (mir_tags) |tag, index| { | 326 | for (mir_tags, 0..) |tag, index| { |
| 327 | const inst = @intCast(u32, index); | 327 | const inst = @intCast(u32, index); |
| 328 | if (isBranch(tag)) { | 328 | if (isBranch(tag)) { |
| 329 | const target_inst = emit.branchTarget(inst); | 329 | const target_inst = emit.branchTarget(inst); |
| ... | @@ -368,7 +368,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -368,7 +368,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 368 | all_branches_lowered = true; | 368 | all_branches_lowered = true; |
| 369 | var current_code_offset: usize = 0; | 369 | var current_code_offset: usize = 0; |
| 370 | 370 | ||
| 371 | for (mir_tags) |tag, index| { | 371 | for (mir_tags, 0..) |tag, index| { |
| 372 | const inst = @intCast(u32, index); | 372 | const inst = @intCast(u32, index); |
| 373 | 373 | ||
| 374 | // If this instruction contained in the code offset | 374 | // If this instruction contained in the code offset |
src/arch/arm/CodeGen.zig+13-13| ... | @@ -513,7 +513,7 @@ fn gen(self: *Self) !void { | ... | @@ -513,7 +513,7 @@ fn gen(self: *Self) !void { |
| 513 | self.ret_mcv = MCValue{ .stack_offset = stack_offset }; | 513 | self.ret_mcv = MCValue{ .stack_offset = stack_offset }; |
| 514 | } | 514 | } |
| 515 | 515 | ||
| 516 | for (self.args) |*arg, arg_index| { | 516 | for (self.args, 0..) |*arg, arg_index| { |
| 517 | // Copy register arguments to the stack | 517 | // Copy register arguments to the stack |
| 518 | switch (arg.*) { | 518 | switch (arg.*) { |
| 519 | .register => |reg| { | 519 | .register => |reg| { |
| ... | @@ -3105,14 +3105,14 @@ fn allocRegs( | ... | @@ -3105,14 +3105,14 @@ fn allocRegs( |
| 3105 | var reused_read_arg: ?usize = null; | 3105 | var reused_read_arg: ?usize = null; |
| 3106 | 3106 | ||
| 3107 | // Lock all args which are already allocated to registers | 3107 | // Lock all args which are already allocated to registers |
| 3108 | for (read_args) |arg, i| { | 3108 | for (read_args, 0..) |arg, i| { |
| 3109 | const mcv = try arg.bind.resolveToMcv(self); | 3109 | const mcv = try arg.bind.resolveToMcv(self); |
| 3110 | if (mcv == .register) { | 3110 | if (mcv == .register) { |
| 3111 | read_locks[i] = self.register_manager.lockReg(mcv.register); | 3111 | read_locks[i] = self.register_manager.lockReg(mcv.register); |
| 3112 | } | 3112 | } |
| 3113 | } | 3113 | } |
| 3114 | 3114 | ||
| 3115 | for (write_args) |arg, i| { | 3115 | for (write_args, 0..) |arg, i| { |
| 3116 | if (arg.bind == .reg) { | 3116 | if (arg.bind == .reg) { |
| 3117 | write_locks[i] = self.register_manager.lockReg(arg.bind.reg); | 3117 | write_locks[i] = self.register_manager.lockReg(arg.bind.reg); |
| 3118 | } | 3118 | } |
| ... | @@ -3120,7 +3120,7 @@ fn allocRegs( | ... | @@ -3120,7 +3120,7 @@ fn allocRegs( |
| 3120 | 3120 | ||
| 3121 | // Allocate registers for all args which aren't allocated to | 3121 | // Allocate registers for all args which aren't allocated to |
| 3122 | // registers yet | 3122 | // registers yet |
| 3123 | for (read_args) |arg, i| { | 3123 | for (read_args, 0..) |arg, i| { |
| 3124 | const mcv = try arg.bind.resolveToMcv(self); | 3124 | const mcv = try arg.bind.resolveToMcv(self); |
| 3125 | if (mcv == .register) { | 3125 | if (mcv == .register) { |
| 3126 | arg.reg.* = mcv.register; | 3126 | arg.reg.* = mcv.register; |
| ... | @@ -3141,7 +3141,7 @@ fn allocRegs( | ... | @@ -3141,7 +3141,7 @@ fn allocRegs( |
| 3141 | if (arg.bind == .reg) { | 3141 | if (arg.bind == .reg) { |
| 3142 | arg.reg.* = arg.bind.reg; | 3142 | arg.reg.* = arg.bind.reg; |
| 3143 | } else { | 3143 | } else { |
| 3144 | reuse_operand: for (read_args) |read_arg, i| { | 3144 | reuse_operand: for (read_args, 0..) |read_arg, i| { |
| 3145 | if (read_arg.bind == .inst) { | 3145 | if (read_arg.bind == .inst) { |
| 3146 | const operand = read_arg.bind.inst; | 3146 | const operand = read_arg.bind.inst; |
| 3147 | const mcv = try self.resolveInst(operand); | 3147 | const mcv = try self.resolveInst(operand); |
| ... | @@ -3161,7 +3161,7 @@ fn allocRegs( | ... | @@ -3161,7 +3161,7 @@ fn allocRegs( |
| 3161 | } | 3161 | } |
| 3162 | } | 3162 | } |
| 3163 | } else { | 3163 | } else { |
| 3164 | for (write_args) |arg, i| { | 3164 | for (write_args, 0..) |arg, i| { |
| 3165 | if (arg.bind == .reg) { | 3165 | if (arg.bind == .reg) { |
| 3166 | arg.reg.* = arg.bind.reg; | 3166 | arg.reg.* = arg.bind.reg; |
| 3167 | } else { | 3167 | } else { |
| ... | @@ -3173,7 +3173,7 @@ fn allocRegs( | ... | @@ -3173,7 +3173,7 @@ fn allocRegs( |
| 3173 | 3173 | ||
| 3174 | // For all read_args which need to be moved from non-register to | 3174 | // For all read_args which need to be moved from non-register to |
| 3175 | // register, perform the move | 3175 | // register, perform the move |
| 3176 | for (read_args) |arg, i| { | 3176 | for (read_args, 0..) |arg, i| { |
| 3177 | if (reused_read_arg) |j| { | 3177 | if (reused_read_arg) |j| { |
| 3178 | // Check whether this read_arg was reused | 3178 | // Check whether this read_arg was reused |
| 3179 | if (i == j) continue; | 3179 | if (i == j) continue; |
| ... | @@ -4217,7 +4217,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier | ... | @@ -4217,7 +4217,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 4217 | // Make space for the arguments passed via the stack | 4217 | // Make space for the arguments passed via the stack |
| 4218 | self.max_end_stack += info.stack_byte_count; | 4218 | self.max_end_stack += info.stack_byte_count; |
| 4219 | 4219 | ||
| 4220 | for (info.args) |mc_arg, arg_i| { | 4220 | for (info.args, 0..) |mc_arg, arg_i| { |
| 4221 | const arg = args[arg_i]; | 4221 | const arg = args[arg_i]; |
| 4222 | const arg_ty = self.air.typeOf(arg); | 4222 | const arg_ty = self.air.typeOf(arg); |
| 4223 | const arg_mcv = try self.resolveInst(args[arg_i]); | 4223 | const arg_mcv = try self.resolveInst(args[arg_i]); |
| ... | @@ -4669,7 +4669,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -4669,7 +4669,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 4669 | const else_slice = else_branch.inst_table.entries.slice(); | 4669 | const else_slice = else_branch.inst_table.entries.slice(); |
| 4670 | const else_keys = else_slice.items(.key); | 4670 | const else_keys = else_slice.items(.key); |
| 4671 | const else_values = else_slice.items(.value); | 4671 | const else_values = else_slice.items(.value); |
| 4672 | for (else_keys) |else_key, else_idx| { | 4672 | for (else_keys, 0..) |else_key, else_idx| { |
| 4673 | const else_value = else_values[else_idx]; | 4673 | const else_value = else_values[else_idx]; |
| 4674 | const canon_mcv = if (saved_then_branch.inst_table.fetchSwapRemove(else_key)) |then_entry| blk: { | 4674 | const canon_mcv = if (saved_then_branch.inst_table.fetchSwapRemove(else_key)) |then_entry| blk: { |
| 4675 | // The instruction's MCValue is overridden in both branches. | 4675 | // The instruction's MCValue is overridden in both branches. |
| ... | @@ -4702,7 +4702,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -4702,7 +4702,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 4702 | const then_slice = saved_then_branch.inst_table.entries.slice(); | 4702 | const then_slice = saved_then_branch.inst_table.entries.slice(); |
| 4703 | const then_keys = then_slice.items(.key); | 4703 | const then_keys = then_slice.items(.key); |
| 4704 | const then_values = then_slice.items(.value); | 4704 | const then_values = then_slice.items(.value); |
| 4705 | for (then_keys) |then_key, then_idx| { | 4705 | for (then_keys, 0..) |then_key, then_idx| { |
| 4706 | const then_value = then_values[then_idx]; | 4706 | const then_value = then_values[then_idx]; |
| 4707 | // We already deleted the items from this table that matched the else_branch. | 4707 | // We already deleted the items from this table that matched the else_branch. |
| 4708 | // So these are all instructions that are only overridden in the then branch. | 4708 | // So these are all instructions that are only overridden in the then branch. |
| ... | @@ -4991,7 +4991,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -4991,7 +4991,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 4991 | const branch_into_prong_relocs = try self.gpa.alloc(u32, items.len); | 4991 | const branch_into_prong_relocs = try self.gpa.alloc(u32, items.len); |
| 4992 | defer self.gpa.free(branch_into_prong_relocs); | 4992 | defer self.gpa.free(branch_into_prong_relocs); |
| 4993 | 4993 | ||
| 4994 | for (items) |item, idx| { | 4994 | for (items, 0..) |item, idx| { |
| 4995 | const cmp_result = try self.cmp(.{ .inst = pl_op.operand }, .{ .inst = item }, condition_ty, .neq); | 4995 | const cmp_result = try self.cmp(.{ .inst = pl_op.operand }, .{ .inst = item }, condition_ty, .neq); |
| 4996 | branch_into_prong_relocs[idx] = try self.condBr(cmp_result); | 4996 | branch_into_prong_relocs[idx] = try self.condBr(cmp_result); |
| 4997 | } | 4997 | } |
| ... | @@ -6296,7 +6296,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -6296,7 +6296,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6296 | } | 6296 | } |
| 6297 | } | 6297 | } |
| 6298 | 6298 | ||
| 6299 | for (param_types) |ty, i| { | 6299 | for (param_types, 0..) |ty, i| { |
| 6300 | if (ty.abiAlignment(self.target.*) == 8) | 6300 | if (ty.abiAlignment(self.target.*) == 8) |
| 6301 | ncrn = std.mem.alignForwardGeneric(usize, ncrn, 2); | 6301 | ncrn = std.mem.alignForwardGeneric(usize, ncrn, 2); |
| 6302 | 6302 | ||
| ... | @@ -6346,7 +6346,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -6346,7 +6346,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6346 | 6346 | ||
| 6347 | var stack_offset: u32 = 0; | 6347 | var stack_offset: u32 = 0; |
| 6348 | 6348 | ||
| 6349 | for (param_types) |ty, i| { | 6349 | for (param_types, 0..) |ty, i| { |
| 6350 | if (ty.abiSize(self.target.*) > 0) { | 6350 | if (ty.abiSize(self.target.*) > 0) { |
| 6351 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); | 6351 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); |
| 6352 | const param_alignment = ty.abiAlignment(self.target.*); | 6352 | const param_alignment = ty.abiAlignment(self.target.*); |
src/arch/arm/Emit.zig+3-3| ... | @@ -77,7 +77,7 @@ pub fn emitMir( | ... | @@ -77,7 +77,7 @@ pub fn emitMir( |
| 77 | try emit.lowerBranches(); | 77 | try emit.lowerBranches(); |
| 78 | 78 | ||
| 79 | // Emit machine code | 79 | // Emit machine code |
| 80 | for (mir_tags) |tag, index| { | 80 | for (mir_tags, 0..) |tag, index| { |
| 81 | const inst = @intCast(u32, index); | 81 | const inst = @intCast(u32, index); |
| 82 | switch (tag) { | 82 | switch (tag) { |
| 83 | .add => try emit.mirDataProcessing(inst), | 83 | .add => try emit.mirDataProcessing(inst), |
| ... | @@ -239,7 +239,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -239,7 +239,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 239 | // | 239 | // |
| 240 | // TODO optimization opportunity: do this in codegen while | 240 | // TODO optimization opportunity: do this in codegen while |
| 241 | // generating MIR | 241 | // generating MIR |
| 242 | for (mir_tags) |tag, index| { | 242 | for (mir_tags, 0..) |tag, index| { |
| 243 | const inst = @intCast(u32, index); | 243 | const inst = @intCast(u32, index); |
| 244 | if (isBranch(tag)) { | 244 | if (isBranch(tag)) { |
| 245 | const target_inst = emit.branchTarget(inst); | 245 | const target_inst = emit.branchTarget(inst); |
| ... | @@ -284,7 +284,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -284,7 +284,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 284 | all_branches_lowered = true; | 284 | all_branches_lowered = true; |
| 285 | var current_code_offset: usize = 0; | 285 | var current_code_offset: usize = 0; |
| 286 | 286 | ||
| 287 | for (mir_tags) |tag, index| { | 287 | for (mir_tags, 0..) |tag, index| { |
| 288 | const inst = @intCast(u32, index); | 288 | const inst = @intCast(u32, index); |
| 289 | 289 | ||
| 290 | // If this instruction contained in the code offset | 290 | // If this instruction contained in the code offset |
src/arch/arm/bits.zig+2-2| ... | @@ -452,11 +452,11 @@ pub const Instruction = union(enum) { | ... | @@ -452,11 +452,11 @@ pub const Instruction = union(enum) { |
| 452 | const masks = comptime blk: { | 452 | const masks = comptime blk: { |
| 453 | const base_mask: u32 = std.math.maxInt(u8); | 453 | const base_mask: u32 = std.math.maxInt(u8); |
| 454 | var result = [_]u32{0} ** 16; | 454 | var result = [_]u32{0} ** 16; |
| 455 | for (result) |*mask, i| mask.* = std.math.rotr(u32, base_mask, 2 * i); | 455 | for (&result, 0..) |*mask, i| mask.* = std.math.rotr(u32, base_mask, 2 * i); |
| 456 | break :blk result; | 456 | break :blk result; |
| 457 | }; | 457 | }; |
| 458 | 458 | ||
| 459 | return for (masks) |mask, i| { | 459 | return for (masks, 0..) |mask, i| { |
| 460 | if (x & mask == x) { | 460 | if (x & mask == x) { |
| 461 | break Operand{ | 461 | break Operand{ |
| 462 | .immediate = .{ | 462 | .immediate = .{ |
src/arch/riscv64/CodeGen.zig+2-2| ... | @@ -1689,7 +1689,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier | ... | @@ -1689,7 +1689,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 1689 | // Due to incremental compilation, how function calls are generated depends | 1689 | // Due to incremental compilation, how function calls are generated depends |
| 1690 | // on linking. | 1690 | // on linking. |
| 1691 | if (self.bin_file.cast(link.File.Elf)) |elf_file| { | 1691 | if (self.bin_file.cast(link.File.Elf)) |elf_file| { |
| 1692 | for (info.args) |mc_arg, arg_i| { | 1692 | for (info.args, 0..) |mc_arg, arg_i| { |
| 1693 | const arg = args[arg_i]; | 1693 | const arg = args[arg_i]; |
| 1694 | const arg_ty = self.air.typeOf(arg); | 1694 | const arg_ty = self.air.typeOf(arg); |
| 1695 | const arg_mcv = try self.resolveInst(args[arg_i]); | 1695 | const arg_mcv = try self.resolveInst(args[arg_i]); |
| ... | @@ -2727,7 +2727,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -2727,7 +2727,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 2727 | var next_stack_offset: u32 = 0; | 2727 | var next_stack_offset: u32 = 0; |
| 2728 | const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 }; | 2728 | const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 }; |
| 2729 | 2729 | ||
| 2730 | for (param_types) |ty, i| { | 2730 | for (param_types, 0..) |ty, i| { |
| 2731 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); | 2731 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); |
| 2732 | if (param_size <= 8) { | 2732 | if (param_size <= 8) { |
| 2733 | if (next_register < argument_registers.len) { | 2733 | if (next_register < argument_registers.len) { |
src/arch/riscv64/Emit.zig+1-1| ... | @@ -38,7 +38,7 @@ pub fn emitMir( | ... | @@ -38,7 +38,7 @@ pub fn emitMir( |
| 38 | const mir_tags = emit.mir.instructions.items(.tag); | 38 | const mir_tags = emit.mir.instructions.items(.tag); |
| 39 | 39 | ||
| 40 | // Emit machine code | 40 | // Emit machine code |
| 41 | for (mir_tags) |tag, index| { | 41 | for (mir_tags, 0..) |tag, index| { |
| 42 | const inst = @intCast(u32, index); | 42 | const inst = @intCast(u32, index); |
| 43 | switch (tag) { | 43 | switch (tag) { |
| 44 | .add => try emit.mirRType(inst), | 44 | .add => try emit.mirRType(inst), |
src/arch/sparc64/CodeGen.zig+4-4| ... | @@ -1189,7 +1189,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier | ... | @@ -1189,7 +1189,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 1189 | try self.register_manager.getReg(reg, null); | 1189 | try self.register_manager.getReg(reg, null); |
| 1190 | } | 1190 | } |
| 1191 | 1191 | ||
| 1192 | for (info.args) |mc_arg, arg_i| { | 1192 | for (info.args, 0..) |mc_arg, arg_i| { |
| 1193 | const arg = args[arg_i]; | 1193 | const arg = args[arg_i]; |
| 1194 | const arg_ty = self.air.typeOf(arg); | 1194 | const arg_ty = self.air.typeOf(arg); |
| 1195 | const arg_mcv = try self.resolveInst(arg); | 1195 | const arg_mcv = try self.resolveInst(arg); |
| ... | @@ -1450,7 +1450,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -1450,7 +1450,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 1450 | const else_slice = else_branch.inst_table.entries.slice(); | 1450 | const else_slice = else_branch.inst_table.entries.slice(); |
| 1451 | const else_keys = else_slice.items(.key); | 1451 | const else_keys = else_slice.items(.key); |
| 1452 | const else_values = else_slice.items(.value); | 1452 | const else_values = else_slice.items(.value); |
| 1453 | for (else_keys) |else_key, else_idx| { | 1453 | for (else_keys, 0..) |else_key, else_idx| { |
| 1454 | const else_value = else_values[else_idx]; | 1454 | const else_value = else_values[else_idx]; |
| 1455 | const canon_mcv = if (saved_then_branch.inst_table.fetchSwapRemove(else_key)) |then_entry| blk: { | 1455 | const canon_mcv = if (saved_then_branch.inst_table.fetchSwapRemove(else_key)) |then_entry| blk: { |
| 1456 | // The instruction's MCValue is overridden in both branches. | 1456 | // The instruction's MCValue is overridden in both branches. |
| ... | @@ -1484,7 +1484,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -1484,7 +1484,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void { |
| 1484 | const then_slice = saved_then_branch.inst_table.entries.slice(); | 1484 | const then_slice = saved_then_branch.inst_table.entries.slice(); |
| 1485 | const then_keys = then_slice.items(.key); | 1485 | const then_keys = then_slice.items(.key); |
| 1486 | const then_values = then_slice.items(.value); | 1486 | const then_values = then_slice.items(.value); |
| 1487 | for (then_keys) |then_key, then_idx| { | 1487 | for (then_keys, 0..) |then_key, then_idx| { |
| 1488 | const then_value = then_values[then_idx]; | 1488 | const then_value = then_values[then_idx]; |
| 1489 | // We already deleted the items from this table that matched the else_branch. | 1489 | // We already deleted the items from this table that matched the else_branch. |
| 1490 | // So these are all instructions that are only overridden in the then branch. | 1490 | // So these are all instructions that are only overridden in the then branch. |
| ... | @@ -4363,7 +4363,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView) | ... | @@ -4363,7 +4363,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView) |
| 4363 | .callee => abi.c_abi_int_param_regs_callee_view, | 4363 | .callee => abi.c_abi_int_param_regs_callee_view, |
| 4364 | }; | 4364 | }; |
| 4365 | 4365 | ||
| 4366 | for (param_types) |ty, i| { | 4366 | for (param_types, 0..) |ty, i| { |
| 4367 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); | 4367 | const param_size = @intCast(u32, ty.abiSize(self.target.*)); |
| 4368 | if (param_size <= 8) { | 4368 | if (param_size <= 8) { |
| 4369 | if (next_register < argument_registers.len) { | 4369 | if (next_register < argument_registers.len) { |
src/arch/sparc64/Emit.zig+3-3| ... | @@ -69,7 +69,7 @@ pub fn emitMir( | ... | @@ -69,7 +69,7 @@ pub fn emitMir( |
| 69 | try emit.lowerBranches(); | 69 | try emit.lowerBranches(); |
| 70 | 70 | ||
| 71 | // Emit machine code | 71 | // Emit machine code |
| 72 | for (mir_tags) |tag, index| { | 72 | for (mir_tags, 0..) |tag, index| { |
| 73 | const inst = @intCast(u32, index); | 73 | const inst = @intCast(u32, index); |
| 74 | switch (tag) { | 74 | switch (tag) { |
| 75 | .dbg_line => try emit.mirDbgLine(inst), | 75 | .dbg_line => try emit.mirDbgLine(inst), |
| ... | @@ -513,7 +513,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -513,7 +513,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 513 | // | 513 | // |
| 514 | // TODO optimization opportunity: do this in codegen while | 514 | // TODO optimization opportunity: do this in codegen while |
| 515 | // generating MIR | 515 | // generating MIR |
| 516 | for (mir_tags) |tag, index| { | 516 | for (mir_tags, 0..) |tag, index| { |
| 517 | const inst = @intCast(u32, index); | 517 | const inst = @intCast(u32, index); |
| 518 | if (isBranch(tag)) { | 518 | if (isBranch(tag)) { |
| 519 | const target_inst = emit.branchTarget(inst); | 519 | const target_inst = emit.branchTarget(inst); |
| ... | @@ -558,7 +558,7 @@ fn lowerBranches(emit: *Emit) !void { | ... | @@ -558,7 +558,7 @@ fn lowerBranches(emit: *Emit) !void { |
| 558 | all_branches_lowered = true; | 558 | all_branches_lowered = true; |
| 559 | var current_code_offset: usize = 0; | 559 | var current_code_offset: usize = 0; |
| 560 | 560 | ||
| 561 | for (mir_tags) |tag, index| { | 561 | for (mir_tags, 0..) |tag, index| { |
| 562 | const inst = @intCast(u32, index); | 562 | const inst = @intCast(u32, index); |
| 563 | 563 | ||
| 564 | // If this instruction contained in the code offset | 564 | // If this instruction contained in the code offset |
src/arch/wasm/CodeGen.zig+9-9| ... | @@ -1255,7 +1255,7 @@ fn genFunc(func: *CodeGen) InnerError!void { | ... | @@ -1255,7 +1255,7 @@ fn genFunc(func: *CodeGen) InnerError!void { |
| 1255 | // reserve space and insert all prologue instructions at the front of the instruction list | 1255 | // reserve space and insert all prologue instructions at the front of the instruction list |
| 1256 | // We insert them in reserve order as there is no insertSlice in multiArrayList. | 1256 | // We insert them in reserve order as there is no insertSlice in multiArrayList. |
| 1257 | try func.mir_instructions.ensureUnusedCapacity(func.gpa, prologue.items.len); | 1257 | try func.mir_instructions.ensureUnusedCapacity(func.gpa, prologue.items.len); |
| 1258 | for (prologue.items) |_, index| { | 1258 | for (prologue.items, 0..) |_, index| { |
| 1259 | const inst = prologue.items[prologue.items.len - 1 - index]; | 1259 | const inst = prologue.items[prologue.items.len - 1 - index]; |
| 1260 | func.mir_instructions.insertAssumeCapacity(0, inst); | 1260 | func.mir_instructions.insertAssumeCapacity(0, inst); |
| 1261 | } | 1261 | } |
| ... | @@ -3117,7 +3117,7 @@ fn mergeBranch(func: *CodeGen, branch: *const Branch) !void { | ... | @@ -3117,7 +3117,7 @@ fn mergeBranch(func: *CodeGen, branch: *const Branch) !void { |
| 3117 | const target_values = target_slice.items(.value); | 3117 | const target_values = target_slice.items(.value); |
| 3118 | 3118 | ||
| 3119 | try parent.values.ensureUnusedCapacity(func.gpa, branch.values.count()); | 3119 | try parent.values.ensureUnusedCapacity(func.gpa, branch.values.count()); |
| 3120 | for (target_keys) |key, index| { | 3120 | for (target_keys, 0..) |key, index| { |
| 3121 | // TODO: process deaths from branches | 3121 | // TODO: process deaths from branches |
| 3122 | parent.values.putAssumeCapacity(key, target_values[index]); | 3122 | parent.values.putAssumeCapacity(key, target_values[index]); |
| 3123 | } | 3123 | } |
| ... | @@ -3501,7 +3501,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -3501,7 +3501,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3501 | const values = try func.gpa.alloc(CaseValue, items.len); | 3501 | const values = try func.gpa.alloc(CaseValue, items.len); |
| 3502 | errdefer func.gpa.free(values); | 3502 | errdefer func.gpa.free(values); |
| 3503 | 3503 | ||
| 3504 | for (items) |ref, i| { | 3504 | for (items, 0..) |ref, i| { |
| 3505 | const item_val = func.air.value(ref).?; | 3505 | const item_val = func.air.value(ref).?; |
| 3506 | const int_val = func.valueAsI32(item_val, target_ty); | 3506 | const int_val = func.valueAsI32(item_val, target_ty); |
| 3507 | if (lowest_maybe == null or int_val < lowest_maybe.?) { | 3507 | if (lowest_maybe == null or int_val < lowest_maybe.?) { |
| ... | @@ -3561,7 +3561,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -3561,7 +3561,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3561 | while (value <= highest) : (value += 1) { | 3561 | while (value <= highest) : (value += 1) { |
| 3562 | // idx represents the branch we jump to | 3562 | // idx represents the branch we jump to |
| 3563 | const idx = blk: { | 3563 | const idx = blk: { |
| 3564 | for (case_list.items) |case, idx| { | 3564 | for (case_list.items, 0..) |case, idx| { |
| 3565 | for (case.values) |case_value| { | 3565 | for (case.values) |case_value| { |
| 3566 | if (case_value.integer == value) break :blk @intCast(u32, idx); | 3566 | if (case_value.integer == value) break :blk @intCast(u32, idx); |
| 3567 | } | 3567 | } |
| ... | @@ -3588,7 +3588,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -3588,7 +3588,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 3588 | }; | 3588 | }; |
| 3589 | 3589 | ||
| 3590 | try func.branches.ensureUnusedCapacity(func.gpa, case_list.items.len + @boolToInt(has_else_body)); | 3590 | try func.branches.ensureUnusedCapacity(func.gpa, case_list.items.len + @boolToInt(has_else_body)); |
| 3591 | for (case_list.items) |case, index| { | 3591 | for (case_list.items, 0..) |case, index| { |
| 3592 | // when sparse, we use if/else-chain, so emit conditional checks | 3592 | // when sparse, we use if/else-chain, so emit conditional checks |
| 3593 | if (is_sparse) { | 3593 | if (is_sparse) { |
| 3594 | // for single value prong we can emit a simple if | 3594 | // for single value prong we can emit a simple if |
| ... | @@ -4558,7 +4558,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -4558,7 +4558,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4558 | // copy stack pointer into a temporary local, which is | 4558 | // copy stack pointer into a temporary local, which is |
| 4559 | // moved for each element to store each value in the right position. | 4559 | // moved for each element to store each value in the right position. |
| 4560 | const offset = try func.buildPointerOffset(result, 0, .new); | 4560 | const offset = try func.buildPointerOffset(result, 0, .new); |
| 4561 | for (elements) |elem, elem_index| { | 4561 | for (elements, 0..) |elem, elem_index| { |
| 4562 | const elem_val = try func.resolveInst(elem); | 4562 | const elem_val = try func.resolveInst(elem); |
| 4563 | try func.store(offset, elem_val, elem_ty, 0); | 4563 | try func.store(offset, elem_val, elem_ty, 0); |
| 4564 | 4564 | ||
| ... | @@ -4587,7 +4587,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -4587,7 +4587,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4587 | // we ensure a new local is created so it's zero-initialized | 4587 | // we ensure a new local is created so it's zero-initialized |
| 4588 | const result = try func.ensureAllocLocal(backing_type); | 4588 | const result = try func.ensureAllocLocal(backing_type); |
| 4589 | var current_bit: u16 = 0; | 4589 | var current_bit: u16 = 0; |
| 4590 | for (elements) |elem, elem_index| { | 4590 | for (elements, 0..) |elem, elem_index| { |
| 4591 | const field = fields[elem_index]; | 4591 | const field = fields[elem_index]; |
| 4592 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; | 4592 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 4593 | 4593 | ||
| ... | @@ -4623,7 +4623,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -4623,7 +4623,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4623 | else => { | 4623 | else => { |
| 4624 | const result = try func.allocStack(result_ty); | 4624 | const result = try func.allocStack(result_ty); |
| 4625 | const offset = try func.buildPointerOffset(result, 0, .new); // pointer to offset | 4625 | const offset = try func.buildPointerOffset(result, 0, .new); // pointer to offset |
| 4626 | for (elements) |elem, elem_index| { | 4626 | for (elements, 0..) |elem, elem_index| { |
| 4627 | if (result_ty.structFieldValueComptime(elem_index) != null) continue; | 4627 | if (result_ty.structFieldValueComptime(elem_index) != null) continue; |
| 4628 | 4628 | ||
| 4629 | const elem_ty = result_ty.structFieldType(elem_index); | 4629 | const elem_ty = result_ty.structFieldType(elem_index); |
| ... | @@ -6149,7 +6149,7 @@ fn callIntrinsic( | ... | @@ -6149,7 +6149,7 @@ fn callIntrinsic( |
| 6149 | } else WValue{ .none = {} }; | 6149 | } else WValue{ .none = {} }; |
| 6150 | 6150 | ||
| 6151 | // Lower all arguments to the stack before we call our function | 6151 | // Lower all arguments to the stack before we call our function |
| 6152 | for (args) |arg, arg_i| { | 6152 | for (args, 0..) |arg, arg_i| { |
| 6153 | assert(!(want_sret_param and arg == .stack)); | 6153 | assert(!(want_sret_param and arg == .stack)); |
| 6154 | assert(param_types[arg_i].hasRuntimeBitsIgnoreComptime()); | 6154 | assert(param_types[arg_i].hasRuntimeBitsIgnoreComptime()); |
| 6155 | try func.lowerArg(.C, param_types[arg_i], arg); | 6155 | try func.lowerArg(.C, param_types[arg_i], arg); |
src/arch/wasm/Emit.zig+1-1| ... | @@ -44,7 +44,7 @@ pub fn emitMir(emit: *Emit) InnerError!void { | ... | @@ -44,7 +44,7 @@ pub fn emitMir(emit: *Emit) InnerError!void { |
| 44 | // before we emit the function body when lowering MIR | 44 | // before we emit the function body when lowering MIR |
| 45 | try emit.emitLocals(); | 45 | try emit.emitLocals(); |
| 46 | 46 | ||
| 47 | for (mir_tags) |tag, index| { | 47 | for (mir_tags, 0..) |tag, index| { |
| 48 | const inst = @intCast(u32, index); | 48 | const inst = @intCast(u32, index); |
| 49 | switch (tag) { | 49 | switch (tag) { |
| 50 | // block instructions | 50 | // block instructions |
src/arch/x86_64/CodeGen.zig+10-10| ... | @@ -186,7 +186,7 @@ const Branch = struct { | ... | @@ -186,7 +186,7 @@ const Branch = struct { |
| 186 | _ = options; | 186 | _ = options; |
| 187 | comptime assert(unused_format_string.len == 0); | 187 | comptime assert(unused_format_string.len == 0); |
| 188 | try writer.writeAll("Branch {\n"); | 188 | try writer.writeAll("Branch {\n"); |
| 189 | for (ctx.insts) |inst, i| { | 189 | for (ctx.insts, 0..) |inst, i| { |
| 190 | const mcv = ctx.mcvs[i]; | 190 | const mcv = ctx.mcvs[i]; |
| 191 | try writer.print(" %{d} => {}\n", .{ inst, mcv }); | 191 | try writer.print(" %{d} => {}\n", .{ inst, mcv }); |
| 192 | } | 192 | } |
| ... | @@ -3951,7 +3951,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier | ... | @@ -3951,7 +3951,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 3951 | }; | 3951 | }; |
| 3952 | defer if (ret_reg_lock) |lock| self.register_manager.unlockReg(lock); | 3952 | defer if (ret_reg_lock) |lock| self.register_manager.unlockReg(lock); |
| 3953 | 3953 | ||
| 3954 | for (args) |arg, arg_i| { | 3954 | for (args, 0..) |arg, arg_i| { |
| 3955 | const mc_arg = info.args[arg_i]; | 3955 | const mc_arg = info.args[arg_i]; |
| 3956 | const arg_ty = self.air.typeOf(arg); | 3956 | const arg_ty = self.air.typeOf(arg); |
| 3957 | const arg_mcv = try self.resolveInst(args[arg_i]); | 3957 | const arg_mcv = try self.resolveInst(args[arg_i]); |
| ... | @@ -4912,7 +4912,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -4912,7 +4912,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 4912 | var relocs = try self.gpa.alloc(u32, items.len); | 4912 | var relocs = try self.gpa.alloc(u32, items.len); |
| 4913 | defer self.gpa.free(relocs); | 4913 | defer self.gpa.free(relocs); |
| 4914 | 4914 | ||
| 4915 | for (items) |item, item_i| { | 4915 | for (items, 0..) |item, item_i| { |
| 4916 | const item_mcv = try self.resolveInst(item); | 4916 | const item_mcv = try self.resolveInst(item); |
| 4917 | relocs[item_i] = try self.genCondSwitchMir(condition_ty, condition, item_mcv); | 4917 | relocs[item_i] = try self.genCondSwitchMir(condition_ty, condition, item_mcv); |
| 4918 | } | 4918 | } |
| ... | @@ -4974,7 +4974,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -4974,7 +4974,7 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void { |
| 4974 | for (self.branch_stack.items) |bs| { | 4974 | for (self.branch_stack.items) |bs| { |
| 4975 | log.debug("{}", .{bs.fmtDebug()}); | 4975 | log.debug("{}", .{bs.fmtDebug()}); |
| 4976 | } | 4976 | } |
| 4977 | for (branch_stack.items) |bs, i| { | 4977 | for (branch_stack.items, 0..) |bs, i| { |
| 4978 | log.debug("Case-{d} branch: {}", .{ i, bs.fmtDebug() }); | 4978 | log.debug("Case-{d} branch: {}", .{ i, bs.fmtDebug() }); |
| 4979 | } | 4979 | } |
| 4980 | 4980 | ||
| ... | @@ -4999,7 +4999,7 @@ fn canonicaliseBranches(self: *Self, parent_branch: *Branch, canon_branch: *Bran | ... | @@ -4999,7 +4999,7 @@ fn canonicaliseBranches(self: *Self, parent_branch: *Branch, canon_branch: *Bran |
| 4999 | const target_keys = target_slice.items(.key); | 4999 | const target_keys = target_slice.items(.key); |
| 5000 | const target_values = target_slice.items(.value); | 5000 | const target_values = target_slice.items(.value); |
| 5001 | 5001 | ||
| 5002 | for (target_keys) |target_key, target_idx| { | 5002 | for (target_keys, 0..) |target_key, target_idx| { |
| 5003 | const target_value = target_values[target_idx]; | 5003 | const target_value = target_values[target_idx]; |
| 5004 | const canon_mcv = if (canon_branch.inst_table.fetchSwapRemove(target_key)) |canon_entry| blk: { | 5004 | const canon_mcv = if (canon_branch.inst_table.fetchSwapRemove(target_key)) |canon_entry| blk: { |
| 5005 | // The instruction's MCValue is overridden in both branches. | 5005 | // The instruction's MCValue is overridden in both branches. |
| ... | @@ -5032,7 +5032,7 @@ fn canonicaliseBranches(self: *Self, parent_branch: *Branch, canon_branch: *Bran | ... | @@ -5032,7 +5032,7 @@ fn canonicaliseBranches(self: *Self, parent_branch: *Branch, canon_branch: *Bran |
| 5032 | const canon_slice = canon_branch.inst_table.entries.slice(); | 5032 | const canon_slice = canon_branch.inst_table.entries.slice(); |
| 5033 | const canon_keys = canon_slice.items(.key); | 5033 | const canon_keys = canon_slice.items(.key); |
| 5034 | const canon_values = canon_slice.items(.value); | 5034 | const canon_values = canon_slice.items(.value); |
| 5035 | for (canon_keys) |canon_key, canon_idx| { | 5035 | for (canon_keys, 0..) |canon_key, canon_idx| { |
| 5036 | const canon_value = canon_values[canon_idx]; | 5036 | const canon_value = canon_values[canon_idx]; |
| 5037 | // We already deleted the items from this table that matched the target_branch. | 5037 | // We already deleted the items from this table that matched the target_branch. |
| 5038 | // So these are all instructions that are only overridden in the canon branch. | 5038 | // So these are all instructions that are only overridden in the canon branch. |
| ... | @@ -6571,7 +6571,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -6571,7 +6571,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 6571 | switch (result_ty.zigTypeTag()) { | 6571 | switch (result_ty.zigTypeTag()) { |
| 6572 | .Struct => { | 6572 | .Struct => { |
| 6573 | const stack_offset = @intCast(i32, try self.allocMem(inst, abi_size, abi_align)); | 6573 | const stack_offset = @intCast(i32, try self.allocMem(inst, abi_size, abi_align)); |
| 6574 | for (elements) |elem, elem_i| { | 6574 | for (elements, 0..) |elem, elem_i| { |
| 6575 | if (result_ty.structFieldValueComptime(elem_i) != null) continue; // comptime elem | 6575 | if (result_ty.structFieldValueComptime(elem_i) != null) continue; // comptime elem |
| 6576 | 6576 | ||
| 6577 | const elem_ty = result_ty.structFieldType(elem_i); | 6577 | const elem_ty = result_ty.structFieldType(elem_i); |
| ... | @@ -6586,7 +6586,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -6586,7 +6586,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 6586 | const elem_ty = result_ty.childType(); | 6586 | const elem_ty = result_ty.childType(); |
| 6587 | const elem_size = @intCast(u32, elem_ty.abiSize(self.target.*)); | 6587 | const elem_size = @intCast(u32, elem_ty.abiSize(self.target.*)); |
| 6588 | 6588 | ||
| 6589 | for (elements) |elem, elem_i| { | 6589 | for (elements, 0..) |elem, elem_i| { |
| 6590 | const elem_mcv = try self.resolveInst(elem); | 6590 | const elem_mcv = try self.resolveInst(elem); |
| 6591 | const elem_off = @intCast(i32, elem_size * elem_i); | 6591 | const elem_off = @intCast(i32, elem_size * elem_i); |
| 6592 | try self.genSetStack(elem_ty, stack_offset - elem_off, elem_mcv, .{}); | 6592 | try self.genSetStack(elem_ty, stack_offset - elem_off, elem_mcv, .{}); |
| ... | @@ -6963,7 +6963,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -6963,7 +6963,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 6963 | else => 0, | 6963 | else => 0, |
| 6964 | }; | 6964 | }; |
| 6965 | 6965 | ||
| 6966 | for (param_types) |ty, i| { | 6966 | for (param_types, 0..) |ty, i| { |
| 6967 | assert(ty.hasRuntimeBits()); | 6967 | assert(ty.hasRuntimeBits()); |
| 6968 | 6968 | ||
| 6969 | const classes: []const abi.Class = switch (self.target.os.tag) { | 6969 | const classes: []const abi.Class = switch (self.target.os.tag) { |
| ... | @@ -7039,7 +7039,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { | ... | @@ -7039,7 +7039,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues { |
| 7039 | else => 0, | 7039 | else => 0, |
| 7040 | }; | 7040 | }; |
| 7041 | 7041 | ||
| 7042 | for (param_types) |ty, i| { | 7042 | for (param_types, 0..) |ty, i| { |
| 7043 | if (!ty.hasRuntimeBits()) { | 7043 | if (!ty.hasRuntimeBits()) { |
| 7044 | result.args[i] = .{ .none = {} }; | 7044 | result.args[i] = .{ .none = {} }; |
| 7045 | continue; | 7045 | continue; |
src/arch/x86_64/Emit.zig+2-2| ... | @@ -61,7 +61,7 @@ const Reloc = struct { | ... | @@ -61,7 +61,7 @@ const Reloc = struct { |
| 61 | pub fn lowerMir(emit: *Emit) InnerError!void { | 61 | pub fn lowerMir(emit: *Emit) InnerError!void { |
| 62 | const mir_tags = emit.mir.instructions.items(.tag); | 62 | const mir_tags = emit.mir.instructions.items(.tag); |
| 63 | 63 | ||
| 64 | for (mir_tags) |tag, index| { | 64 | for (mir_tags, 0..) |tag, index| { |
| 65 | const inst = @intCast(u32, index); | 65 | const inst = @intCast(u32, index); |
| 66 | try emit.code_offset_mapping.putNoClobber(emit.bin_file.allocator, inst, emit.code.items.len); | 66 | try emit.code_offset_mapping.putNoClobber(emit.bin_file.allocator, inst, emit.code.items.len); |
| 67 | switch (tag) { | 67 | switch (tag) { |
| ... | @@ -1544,7 +1544,7 @@ const OpCode = struct { | ... | @@ -1544,7 +1544,7 @@ const OpCode = struct { |
| 1544 | fn init(comptime in_bytes: []const u8) OpCode { | 1544 | fn init(comptime in_bytes: []const u8) OpCode { |
| 1545 | comptime assert(in_bytes.len <= 3); | 1545 | comptime assert(in_bytes.len <= 3); |
| 1546 | comptime var bytes: [3]u8 = undefined; | 1546 | comptime var bytes: [3]u8 = undefined; |
| 1547 | inline for (in_bytes) |x, i| { | 1547 | inline for (in_bytes, 0..) |x, i| { |
| 1548 | bytes[i] = x; | 1548 | bytes[i] = x; |
| 1549 | } | 1549 | } |
| 1550 | return .{ .bytes = bytes, .count = in_bytes.len }; | 1550 | return .{ .bytes = bytes, .count = in_bytes.len }; |
src/arch/x86_64/Mir.zig+1-1| ... | @@ -535,7 +535,7 @@ pub const RegisterList = struct { | ... | @@ -535,7 +535,7 @@ pub const RegisterList = struct { |
| 535 | const Self = @This(); | 535 | const Self = @This(); |
| 536 | 536 | ||
| 537 | fn getIndexForReg(registers: []const Register, reg: Register) BitSet.MaskInt { | 537 | fn getIndexForReg(registers: []const Register, reg: Register) BitSet.MaskInt { |
| 538 | for (registers) |cpreg, i| { | 538 | for (registers, 0..) |cpreg, i| { |
| 539 | if (reg.id() == cpreg.id()) return @intCast(u32, i); | 539 | if (reg.id() == cpreg.id()) return @intCast(u32, i); |
| 540 | } | 540 | } |
| 541 | unreachable; // register not in input register list! | 541 | unreachable; // register not in input register list! |
src/arch/x86_64/abi.zig+5-5| ... | @@ -335,7 +335,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class { | ... | @@ -335,7 +335,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class { |
| 335 | // "If one of the classes is MEMORY, the whole argument is passed in memory" | 335 | // "If one of the classes is MEMORY, the whole argument is passed in memory" |
| 336 | // "If X87UP is not preceded by X87, the whole argument is passed in memory." | 336 | // "If X87UP is not preceded by X87, the whole argument is passed in memory." |
| 337 | var found_sseup = false; | 337 | var found_sseup = false; |
| 338 | for (result) |item, i| switch (item) { | 338 | for (result, 0..) |item, i| switch (item) { |
| 339 | .memory => return memory_class, | 339 | .memory => return memory_class, |
| 340 | .x87up => if (i == 0 or result[i - 1] != .x87) return memory_class, | 340 | .x87up => if (i == 0 or result[i - 1] != .x87) return memory_class, |
| 341 | .sseup => found_sseup = true, | 341 | .sseup => found_sseup = true, |
| ... | @@ -347,7 +347,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class { | ... | @@ -347,7 +347,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class { |
| 347 | if (ty_size > 16 and (result[0] != .sse or !found_sseup)) return memory_class; | 347 | if (ty_size > 16 and (result[0] != .sse or !found_sseup)) return memory_class; |
| 348 | 348 | ||
| 349 | // "If SSEUP is not preceded by SSE or SSEUP, it is converted to SSE." | 349 | // "If SSEUP is not preceded by SSE or SSEUP, it is converted to SSE." |
| 350 | for (result) |*item, i| { | 350 | for (&result, 0..) |*item, i| { |
| 351 | if (item.* == .sseup) switch (result[i - 1]) { | 351 | if (item.* == .sseup) switch (result[i - 1]) { |
| 352 | .sse, .sseup => continue, | 352 | .sse, .sseup => continue, |
| 353 | else => item.* = .sse, | 353 | else => item.* = .sse, |
| ... | @@ -379,7 +379,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class { | ... | @@ -379,7 +379,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class { |
| 379 | } | 379 | } |
| 380 | // Combine this field with the previous one. | 380 | // Combine this field with the previous one. |
| 381 | const field_class = classifySystemV(field.ty, target, .other); | 381 | const field_class = classifySystemV(field.ty, target, .other); |
| 382 | for (result) |*result_item, i| { | 382 | for (&result, 0..) |*result_item, i| { |
| 383 | const field_item = field_class[i]; | 383 | const field_item = field_class[i]; |
| 384 | // "If both classes are equal, this is the resulting class." | 384 | // "If both classes are equal, this is the resulting class." |
| 385 | if (result_item.* == field_item) { | 385 | if (result_item.* == field_item) { |
| ... | @@ -431,7 +431,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class { | ... | @@ -431,7 +431,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class { |
| 431 | // "If one of the classes is MEMORY, the whole argument is passed in memory" | 431 | // "If one of the classes is MEMORY, the whole argument is passed in memory" |
| 432 | // "If X87UP is not preceded by X87, the whole argument is passed in memory." | 432 | // "If X87UP is not preceded by X87, the whole argument is passed in memory." |
| 433 | var found_sseup = false; | 433 | var found_sseup = false; |
| 434 | for (result) |item, i| switch (item) { | 434 | for (result, 0..) |item, i| switch (item) { |
| 435 | .memory => return memory_class, | 435 | .memory => return memory_class, |
| 436 | .x87up => if (i == 0 or result[i - 1] != .x87) return memory_class, | 436 | .x87up => if (i == 0 or result[i - 1] != .x87) return memory_class, |
| 437 | .sseup => found_sseup = true, | 437 | .sseup => found_sseup = true, |
| ... | @@ -443,7 +443,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class { | ... | @@ -443,7 +443,7 @@ pub fn classifySystemV(ty: Type, target: Target, ctx: Context) [8]Class { |
| 443 | if (ty_size > 16 and (result[0] != .sse or !found_sseup)) return memory_class; | 443 | if (ty_size > 16 and (result[0] != .sse or !found_sseup)) return memory_class; |
| 444 | 444 | ||
| 445 | // "If SSEUP is not preceded by SSE or SSEUP, it is converted to SSE." | 445 | // "If SSEUP is not preceded by SSE or SSEUP, it is converted to SSE." |
| 446 | for (result) |*item, i| { | 446 | for (&result, 0..) |*item, i| { |
| 447 | if (item.* == .sseup) switch (result[i - 1]) { | 447 | if (item.* == .sseup) switch (result[i - 1]) { |
| 448 | .sse, .sseup => continue, | 448 | .sse, .sseup => continue, |
| 449 | else => item.* = .sse, | 449 | else => item.* = .sse, |
src/codegen.zig+2-2| ... | @@ -511,7 +511,7 @@ pub fn generateSymbol( | ... | @@ -511,7 +511,7 @@ pub fn generateSymbol( |
| 511 | try code.resize(current_pos + abi_size); | 511 | try code.resize(current_pos + abi_size); |
| 512 | var bits: u16 = 0; | 512 | var bits: u16 = 0; |
| 513 | 513 | ||
| 514 | for (field_vals) |field_val, index| { | 514 | for (field_vals, 0..) |field_val, index| { |
| 515 | const field_ty = fields[index].ty; | 515 | const field_ty = fields[index].ty; |
| 516 | // pointer may point to a decl which must be marked used | 516 | // pointer may point to a decl which must be marked used |
| 517 | // but can also result in a relocation. Therefore we handle those seperately. | 517 | // but can also result in a relocation. Therefore we handle those seperately. |
| ... | @@ -537,7 +537,7 @@ pub fn generateSymbol( | ... | @@ -537,7 +537,7 @@ pub fn generateSymbol( |
| 537 | 537 | ||
| 538 | const struct_begin = code.items.len; | 538 | const struct_begin = code.items.len; |
| 539 | const field_vals = typed_value.val.castTag(.aggregate).?.data; | 539 | const field_vals = typed_value.val.castTag(.aggregate).?.data; |
| 540 | for (field_vals) |field_val, index| { | 540 | for (field_vals, 0..) |field_val, index| { |
| 541 | const field_ty = typed_value.ty.structFieldType(index); | 541 | const field_ty = typed_value.ty.structFieldType(index); |
| 542 | if (!field_ty.hasRuntimeBits()) continue; | 542 | if (!field_ty.hasRuntimeBits()) continue; |
| 543 | 543 |
src/codegen/c.zig+26-26| ... | @@ -253,7 +253,7 @@ fn formatIdent( | ... | @@ -253,7 +253,7 @@ fn formatIdent( |
| 253 | if (solo and isReservedIdent(ident)) { | 253 | if (solo and isReservedIdent(ident)) { |
| 254 | try writer.writeAll("zig_e_"); | 254 | try writer.writeAll("zig_e_"); |
| 255 | } | 255 | } |
| 256 | for (ident) |c, i| { | 256 | for (ident, 0..) |c, i| { |
| 257 | switch (c) { | 257 | switch (c) { |
| 258 | 'a'...'z', 'A'...'Z', '_' => try writer.writeByte(c), | 258 | 'a'...'z', 'A'...'Z', '_' => try writer.writeByte(c), |
| 259 | '.' => try writer.writeByte('_'), | 259 | '.' => try writer.writeByte('_'), |
| ... | @@ -361,7 +361,7 @@ pub const Function = struct { | ... | @@ -361,7 +361,7 @@ pub const Function = struct { |
| 361 | _ = mutability; | 361 | _ = mutability; |
| 362 | 362 | ||
| 363 | if (f.getFreeLocals().getPtrContext(ty, f.tyHashCtx())) |locals_list| { | 363 | if (f.getFreeLocals().getPtrContext(ty, f.tyHashCtx())) |locals_list| { |
| 364 | for (locals_list.items) |local_index, i| { | 364 | for (locals_list.items, 0..) |local_index, i| { |
| 365 | const local = &f.locals.items[local_index]; | 365 | const local = &f.locals.items[local_index]; |
| 366 | if (local.alignment >= alignment) { | 366 | if (local.alignment >= alignment) { |
| 367 | local.loop_depth = @intCast(LoopDepth, f.free_locals_stack.items.len - 1); | 367 | local.loop_depth = @intCast(LoopDepth, f.free_locals_stack.items.len - 1); |
| ... | @@ -1283,7 +1283,7 @@ pub const DeclGen = struct { | ... | @@ -1283,7 +1283,7 @@ pub const DeclGen = struct { |
| 1283 | 1283 | ||
| 1284 | try writer.writeByte('{'); | 1284 | try writer.writeByte('{'); |
| 1285 | var empty = true; | 1285 | var empty = true; |
| 1286 | for (field_vals) |field_val, field_index| { | 1286 | for (field_vals, 0..) |field_val, field_index| { |
| 1287 | const field_ty = ty.structFieldType(field_index); | 1287 | const field_ty = ty.structFieldType(field_index); |
| 1288 | if (!field_ty.hasRuntimeBits()) continue; | 1288 | if (!field_ty.hasRuntimeBits()) continue; |
| 1289 | 1289 | ||
| ... | @@ -1309,7 +1309,7 @@ pub const DeclGen = struct { | ... | @@ -1309,7 +1309,7 @@ pub const DeclGen = struct { |
| 1309 | const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base); | 1309 | const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base); |
| 1310 | 1310 | ||
| 1311 | var eff_num_fields: usize = 0; | 1311 | var eff_num_fields: usize = 0; |
| 1312 | for (field_vals) |_, index| { | 1312 | for (field_vals, 0..) |_, index| { |
| 1313 | const field_ty = ty.structFieldType(index); | 1313 | const field_ty = ty.structFieldType(index); |
| 1314 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 1314 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 1315 | 1315 | ||
| ... | @@ -1331,7 +1331,7 @@ pub const DeclGen = struct { | ... | @@ -1331,7 +1331,7 @@ pub const DeclGen = struct { |
| 1331 | 1331 | ||
| 1332 | var eff_index: usize = 0; | 1332 | var eff_index: usize = 0; |
| 1333 | var needs_closing_paren = false; | 1333 | var needs_closing_paren = false; |
| 1334 | for (field_vals) |field_val, index| { | 1334 | for (field_vals, 0..) |field_val, index| { |
| 1335 | const field_ty = ty.structFieldType(index); | 1335 | const field_ty = ty.structFieldType(index); |
| 1336 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 1336 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 1337 | 1337 | ||
| ... | @@ -1359,7 +1359,7 @@ pub const DeclGen = struct { | ... | @@ -1359,7 +1359,7 @@ pub const DeclGen = struct { |
| 1359 | try writer.writeByte('('); | 1359 | try writer.writeByte('('); |
| 1360 | // a << a_off | b << b_off | c << c_off | 1360 | // a << a_off | b << b_off | c << c_off |
| 1361 | var empty = true; | 1361 | var empty = true; |
| 1362 | for (field_vals) |field_val, index| { | 1362 | for (field_vals, 0..) |field_val, index| { |
| 1363 | const field_ty = ty.structFieldType(index); | 1363 | const field_ty = ty.structFieldType(index); |
| 1364 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 1364 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 1365 | 1365 | ||
| ... | @@ -1719,7 +1719,7 @@ pub const DeclGen = struct { | ... | @@ -1719,7 +1719,7 @@ pub const DeclGen = struct { |
| 1719 | { | 1719 | { |
| 1720 | const fields = t.tupleFields(); | 1720 | const fields = t.tupleFields(); |
| 1721 | var field_id: usize = 0; | 1721 | var field_id: usize = 0; |
| 1722 | for (fields.types) |field_ty, i| { | 1722 | for (fields.types, 0..) |field_ty, i| { |
| 1723 | if (!field_ty.hasRuntimeBits() or fields.values[i].tag() != .unreachable_value) continue; | 1723 | if (!field_ty.hasRuntimeBits() or fields.values[i].tag() != .unreachable_value) continue; |
| 1724 | 1724 | ||
| 1725 | try buffer.append(' '); | 1725 | try buffer.append(' '); |
| ... | @@ -2130,7 +2130,7 @@ pub const DeclGen = struct { | ... | @@ -2130,7 +2130,7 @@ pub const DeclGen = struct { |
| 2130 | try tuple_storage.ensureTotalCapacity(allocator, t.structFieldCount()); | 2130 | try tuple_storage.ensureTotalCapacity(allocator, t.structFieldCount()); |
| 2131 | 2131 | ||
| 2132 | const fields = t.tupleFields(); | 2132 | const fields = t.tupleFields(); |
| 2133 | for (fields.values) |value, index| | 2133 | for (fields.values, 0..) |value, index| |
| 2134 | if (value.tag() == .unreachable_value) | 2134 | if (value.tag() == .unreachable_value) |
| 2135 | tuple_storage.appendAssumeCapacity(.{ | 2135 | tuple_storage.appendAssumeCapacity(.{ |
| 2136 | .type = fields.types[index], | 2136 | .type = fields.types[index], |
| ... | @@ -2415,7 +2415,7 @@ pub const DeclGen = struct { | ... | @@ -2415,7 +2415,7 @@ pub const DeclGen = struct { |
| 2415 | const name_end = buffer.items.len - "(".len; | 2415 | const name_end = buffer.items.len - "(".len; |
| 2416 | try dg.renderTypeAndName(bw, enum_ty, .{ .identifier = "tag" }, .Const, 0, .Complete); | 2416 | try dg.renderTypeAndName(bw, enum_ty, .{ .identifier = "tag" }, .Const, 0, .Complete); |
| 2417 | try buffer.appendSlice(") {\n switch (tag) {\n"); | 2417 | try buffer.appendSlice(") {\n switch (tag) {\n"); |
| 2418 | for (enum_ty.enumFields().keys()) |name, index| { | 2418 | for (enum_ty.enumFields().keys(), 0..) |name, index| { |
| 2419 | const name_z = try dg.typedefs.allocator.dupeZ(u8, name); | 2419 | const name_z = try dg.typedefs.allocator.dupeZ(u8, name); |
| 2420 | defer dg.typedefs.allocator.free(name_z); | 2420 | defer dg.typedefs.allocator.free(name_z); |
| 2421 | const name_bytes = name_z[0 .. name_z.len + 1]; | 2421 | const name_bytes = name_z[0 .. name_z.len + 1]; |
| ... | @@ -2681,7 +2681,7 @@ pub fn genErrDecls(o: *Object) !void { | ... | @@ -2681,7 +2681,7 @@ pub fn genErrDecls(o: *Object) !void { |
| 2681 | try writer.writeAll("enum {\n"); | 2681 | try writer.writeAll("enum {\n"); |
| 2682 | o.indent_writer.pushIndent(); | 2682 | o.indent_writer.pushIndent(); |
| 2683 | var max_name_len: usize = 0; | 2683 | var max_name_len: usize = 0; |
| 2684 | for (o.dg.module.error_name_list.items) |name, value| { | 2684 | for (o.dg.module.error_name_list.items, 0..) |name, value| { |
| 2685 | max_name_len = std.math.max(name.len, max_name_len); | 2685 | max_name_len = std.math.max(name.len, max_name_len); |
| 2686 | var err_pl = Value.Payload.Error{ .data = .{ .name = name } }; | 2686 | var err_pl = Value.Payload.Error{ .data = .{ .name = name } }; |
| 2687 | try o.dg.renderValue(writer, Type.anyerror, Value.initPayload(&err_pl.base), .Other); | 2687 | try o.dg.renderValue(writer, Type.anyerror, Value.initPayload(&err_pl.base), .Other); |
| ... | @@ -2724,7 +2724,7 @@ pub fn genErrDecls(o: *Object) !void { | ... | @@ -2724,7 +2724,7 @@ pub fn genErrDecls(o: *Object) !void { |
| 2724 | try writer.writeAll("static "); | 2724 | try writer.writeAll("static "); |
| 2725 | try o.dg.renderTypeAndName(writer, name_array_ty, .{ .identifier = name_prefix }, .Const, 0, .Complete); | 2725 | try o.dg.renderTypeAndName(writer, name_array_ty, .{ .identifier = name_prefix }, .Const, 0, .Complete); |
| 2726 | try writer.writeAll(" = {"); | 2726 | try writer.writeAll(" = {"); |
| 2727 | for (o.dg.module.error_name_list.items) |name, value| { | 2727 | for (o.dg.module.error_name_list.items, 0..) |name, value| { |
| 2728 | if (value != 0) try writer.writeByte(','); | 2728 | if (value != 0) try writer.writeByte(','); |
| 2729 | 2729 | ||
| 2730 | var len_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = name.len }; | 2730 | var len_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = name.len }; |
| ... | @@ -2742,7 +2742,7 @@ fn genExports(o: *Object) !void { | ... | @@ -2742,7 +2742,7 @@ fn genExports(o: *Object) !void { |
| 2742 | defer tracy.end(); | 2742 | defer tracy.end(); |
| 2743 | 2743 | ||
| 2744 | const fwd_decl_writer = o.dg.fwd_decl.writer(); | 2744 | const fwd_decl_writer = o.dg.fwd_decl.writer(); |
| 2745 | if (o.dg.module.decl_exports.get(o.dg.decl_index)) |exports| for (exports.items[1..]) |@"export", i| { | 2745 | if (o.dg.module.decl_exports.get(o.dg.decl_index)) |exports| for (exports.items[1..], 0..) |@"export", i| { |
| 2746 | try fwd_decl_writer.writeAll("zig_export("); | 2746 | try fwd_decl_writer.writeAll("zig_export("); |
| 2747 | try o.dg.renderFunctionSignature(fwd_decl_writer, .Forward, @intCast(u32, 1 + i)); | 2747 | try o.dg.renderFunctionSignature(fwd_decl_writer, .Forward, @intCast(u32, 1 + i)); |
| 2748 | try fwd_decl_writer.print(", {s}, {s});\n", .{ | 2748 | try fwd_decl_writer.print(", {s}, {s});\n", .{ |
| ... | @@ -2800,7 +2800,7 @@ pub fn genFunc(f: *Function) !void { | ... | @@ -2800,7 +2800,7 @@ pub fn genFunc(f: *Function) !void { |
| 2800 | // alignment, descending. | 2800 | // alignment, descending. |
| 2801 | const free_locals = f.getFreeLocals(); | 2801 | const free_locals = f.getFreeLocals(); |
| 2802 | const values = f.allocs.values(); | 2802 | const values = f.allocs.values(); |
| 2803 | for (f.allocs.keys()) |local_index, i| { | 2803 | for (f.allocs.keys(), 0..) |local_index, i| { |
| 2804 | if (values[i]) continue; // static | 2804 | if (values[i]) continue; // static |
| 2805 | const local = f.locals.items[local_index]; | 2805 | const local = f.locals.items[local_index]; |
| 2806 | log.debug("inserting local {d} into free_locals", .{local_index}); | 2806 | log.debug("inserting local {d} into free_locals", .{local_index}); |
| ... | @@ -4238,7 +4238,7 @@ fn airCall( | ... | @@ -4238,7 +4238,7 @@ fn airCall( |
| 4238 | 4238 | ||
| 4239 | const resolved_args = try gpa.alloc(CValue, args.len); | 4239 | const resolved_args = try gpa.alloc(CValue, args.len); |
| 4240 | defer gpa.free(resolved_args); | 4240 | defer gpa.free(resolved_args); |
| 4241 | for (args) |arg, i| { | 4241 | for (args, 0..) |arg, i| { |
| 4242 | resolved_args[i] = try f.resolveInst(arg); | 4242 | resolved_args[i] = try f.resolveInst(arg); |
| 4243 | } | 4243 | } |
| 4244 | 4244 | ||
| ... | @@ -4303,7 +4303,7 @@ fn airCall( | ... | @@ -4303,7 +4303,7 @@ fn airCall( |
| 4303 | 4303 | ||
| 4304 | try writer.writeByte('('); | 4304 | try writer.writeByte('('); |
| 4305 | var args_written: usize = 0; | 4305 | var args_written: usize = 0; |
| 4306 | for (args) |arg, arg_i| { | 4306 | for (args, 0..) |arg, arg_i| { |
| 4307 | const ty = f.air.typeOf(arg); | 4307 | const ty = f.air.typeOf(arg); |
| 4308 | if (!ty.hasRuntimeBitsIgnoreComptime()) continue; | 4308 | if (!ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 4309 | if (args_written != 0) { | 4309 | if (args_written != 0) { |
| ... | @@ -5043,7 +5043,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5043,7 +5043,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5043 | extra_i = constraints_extra_begin; | 5043 | extra_i = constraints_extra_begin; |
| 5044 | var locals_index = locals_begin; | 5044 | var locals_index = locals_begin; |
| 5045 | try writer.writeByte(':'); | 5045 | try writer.writeByte(':'); |
| 5046 | for (outputs) |output, index| { | 5046 | for (outputs, 0..) |output, index| { |
| 5047 | const extra_bytes = std.mem.sliceAsBytes(f.air.extra[extra_i..]); | 5047 | const extra_bytes = std.mem.sliceAsBytes(f.air.extra[extra_i..]); |
| 5048 | const constraint = std.mem.sliceTo(extra_bytes, 0); | 5048 | const constraint = std.mem.sliceTo(extra_bytes, 0); |
| 5049 | const name = std.mem.sliceTo(extra_bytes[constraint.len + 1 ..], 0); | 5049 | const name = std.mem.sliceTo(extra_bytes[constraint.len + 1 ..], 0); |
| ... | @@ -5067,7 +5067,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5067,7 +5067,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5067 | try writer.writeByte(')'); | 5067 | try writer.writeByte(')'); |
| 5068 | } | 5068 | } |
| 5069 | try writer.writeByte(':'); | 5069 | try writer.writeByte(':'); |
| 5070 | for (inputs) |input, index| { | 5070 | for (inputs, 0..) |input, index| { |
| 5071 | const extra_bytes = std.mem.sliceAsBytes(f.air.extra[extra_i..]); | 5071 | const extra_bytes = std.mem.sliceAsBytes(f.air.extra[extra_i..]); |
| 5072 | const constraint = std.mem.sliceTo(extra_bytes, 0); | 5072 | const constraint = std.mem.sliceTo(extra_bytes, 0); |
| 5073 | const name = std.mem.sliceTo(extra_bytes[constraint.len + 1 ..], 0); | 5073 | const name = std.mem.sliceTo(extra_bytes[constraint.len + 1 ..], 0); |
| ... | @@ -5426,7 +5426,7 @@ fn structFieldPtr(f: *Function, inst: Air.Inst.Index, struct_ptr_ty: Type, struc | ... | @@ -5426,7 +5426,7 @@ fn structFieldPtr(f: *Function, inst: Air.Inst.Index, struct_ptr_ty: Type, struc |
| 5426 | }; | 5426 | }; |
| 5427 | const field_loc = switch (struct_ty.tag()) { | 5427 | const field_loc = switch (struct_ty.tag()) { |
| 5428 | .@"struct" => switch (struct_ty.containerLayout()) { | 5428 | .@"struct" => switch (struct_ty.containerLayout()) { |
| 5429 | .Auto, .Extern => for (struct_ty.structFields().values()[index..]) |field, offset| { | 5429 | .Auto, .Extern => for (struct_ty.structFields().values()[index..], 0..) |field, offset| { |
| 5430 | if (field.ty.hasRuntimeBitsIgnoreComptime()) break FieldLoc{ .field = .{ | 5430 | if (field.ty.hasRuntimeBitsIgnoreComptime()) break FieldLoc{ .field = .{ |
| 5431 | .identifier = struct_ty.structFieldName(index + offset), | 5431 | .identifier = struct_ty.structFieldName(index + offset), |
| 5432 | } }; | 5432 | } }; |
| ... | @@ -5469,7 +5469,7 @@ fn structFieldPtr(f: *Function, inst: Air.Inst.Index, struct_ptr_ty: Type, struc | ... | @@ -5469,7 +5469,7 @@ fn structFieldPtr(f: *Function, inst: Air.Inst.Index, struct_ptr_ty: Type, struc |
| 5469 | if (tuple.values[index].tag() != .unreachable_value) return CValue.none; | 5469 | if (tuple.values[index].tag() != .unreachable_value) return CValue.none; |
| 5470 | 5470 | ||
| 5471 | var id: usize = 0; | 5471 | var id: usize = 0; |
| 5472 | break :field_name for (tuple.values) |value, i| { | 5472 | break :field_name for (tuple.values, 0..) |value, i| { |
| 5473 | if (value.tag() != .unreachable_value) continue; | 5473 | if (value.tag() != .unreachable_value) continue; |
| 5474 | if (!tuple.types[i].hasRuntimeBitsIgnoreComptime()) continue; | 5474 | if (!tuple.types[i].hasRuntimeBitsIgnoreComptime()) continue; |
| 5475 | if (i >= index) break FieldLoc{ .field = .{ .field = id } }; | 5475 | if (i >= index) break FieldLoc{ .field = .{ .field = id } }; |
| ... | @@ -6687,7 +6687,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6687,7 +6687,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6687 | const gpa = f.object.dg.gpa; | 6687 | const gpa = f.object.dg.gpa; |
| 6688 | const resolved_elements = try gpa.alloc(CValue, elements.len); | 6688 | const resolved_elements = try gpa.alloc(CValue, elements.len); |
| 6689 | defer gpa.free(resolved_elements); | 6689 | defer gpa.free(resolved_elements); |
| 6690 | for (elements) |element, i| { | 6690 | for (elements, 0..) |element, i| { |
| 6691 | resolved_elements[i] = try f.resolveInst(element); | 6691 | resolved_elements[i] = try f.resolveInst(element); |
| 6692 | } | 6692 | } |
| 6693 | { | 6693 | { |
| ... | @@ -6706,7 +6706,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6706,7 +6706,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6706 | switch (inst_ty.zigTypeTag()) { | 6706 | switch (inst_ty.zigTypeTag()) { |
| 6707 | .Array, .Vector => { | 6707 | .Array, .Vector => { |
| 6708 | const elem_ty = inst_ty.childType(); | 6708 | const elem_ty = inst_ty.childType(); |
| 6709 | for (resolved_elements) |element, i| { | 6709 | for (resolved_elements, 0..) |element, i| { |
| 6710 | try f.writeCValue(writer, local, .Other); | 6710 | try f.writeCValue(writer, local, .Other); |
| 6711 | try writer.print("[{d}] = ", .{i}); | 6711 | try writer.print("[{d}] = ", .{i}); |
| 6712 | try f.writeCValue(writer, element, .Other); | 6712 | try f.writeCValue(writer, element, .Other); |
| ... | @@ -6727,7 +6727,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6727,7 +6727,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6727 | try writer.writeAll(")"); | 6727 | try writer.writeAll(")"); |
| 6728 | try writer.writeByte('{'); | 6728 | try writer.writeByte('{'); |
| 6729 | var empty = true; | 6729 | var empty = true; |
| 6730 | for (elements) |element, index| { | 6730 | for (elements, 0..) |element, index| { |
| 6731 | if (inst_ty.structFieldValueComptime(index)) |_| continue; | 6731 | if (inst_ty.structFieldValueComptime(index)) |_| continue; |
| 6732 | 6732 | ||
| 6733 | if (!empty) try writer.writeAll(", "); | 6733 | if (!empty) try writer.writeAll(", "); |
| ... | @@ -6746,7 +6746,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6746,7 +6746,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6746 | try writer.writeAll("};\n"); | 6746 | try writer.writeAll("};\n"); |
| 6747 | 6747 | ||
| 6748 | var field_id: usize = 0; | 6748 | var field_id: usize = 0; |
| 6749 | for (elements) |element, index| { | 6749 | for (elements, 0..) |element, index| { |
| 6750 | if (inst_ty.structFieldValueComptime(index)) |_| continue; | 6750 | if (inst_ty.structFieldValueComptime(index)) |_| continue; |
| 6751 | 6751 | ||
| 6752 | const element_ty = f.air.typeOf(element); | 6752 | const element_ty = f.air.typeOf(element); |
| ... | @@ -6784,7 +6784,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6784,7 +6784,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6784 | const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base); | 6784 | const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base); |
| 6785 | 6785 | ||
| 6786 | var empty = true; | 6786 | var empty = true; |
| 6787 | for (elements) |_, index| { | 6787 | for (elements, 0..) |_, index| { |
| 6788 | const field_ty = inst_ty.structFieldType(index); | 6788 | const field_ty = inst_ty.structFieldType(index); |
| 6789 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 6789 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 6790 | 6790 | ||
| ... | @@ -6796,7 +6796,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6796,7 +6796,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6796 | empty = false; | 6796 | empty = false; |
| 6797 | } | 6797 | } |
| 6798 | empty = true; | 6798 | empty = true; |
| 6799 | for (resolved_elements) |element, index| { | 6799 | for (resolved_elements, 0..) |element, index| { |
| 6800 | const field_ty = inst_ty.structFieldType(index); | 6800 | const field_ty = inst_ty.structFieldType(index); |
| 6801 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 6801 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 6802 | 6802 | ||
| ... | @@ -7608,7 +7608,7 @@ fn deinitFreeLocalsMap(gpa: mem.Allocator, map: *LocalsMap) void { | ... | @@ -7608,7 +7608,7 @@ fn deinitFreeLocalsMap(gpa: mem.Allocator, map: *LocalsMap) void { |
| 7608 | } | 7608 | } |
| 7609 | 7609 | ||
| 7610 | fn noticeBranchFrees(f: *Function, pre_locals_len: LocalIndex, inst: Air.Inst.Index) !void { | 7610 | fn noticeBranchFrees(f: *Function, pre_locals_len: LocalIndex, inst: Air.Inst.Index) !void { |
| 7611 | for (f.locals.items[pre_locals_len..]) |*local, local_offset| { | 7611 | for (f.locals.items[pre_locals_len..], 0..) |*local, local_offset| { |
| 7612 | const local_index = pre_locals_len + @intCast(LocalIndex, local_offset); | 7612 | const local_index = pre_locals_len + @intCast(LocalIndex, local_offset); |
| 7613 | if (f.allocs.contains(local_index)) continue; // allocs are not freeable | 7613 | if (f.allocs.contains(local_index)) continue; // allocs are not freeable |
| 7614 | 7614 |
src/codegen/llvm.zig+30-30| ... | @@ -605,7 +605,7 @@ pub const Object = struct { | ... | @@ -605,7 +605,7 @@ pub const Object = struct { |
| 605 | defer mod.gpa.free(llvm_errors); | 605 | defer mod.gpa.free(llvm_errors); |
| 606 | 606 | ||
| 607 | llvm_errors[0] = llvm_slice_ty.getUndef(); | 607 | llvm_errors[0] = llvm_slice_ty.getUndef(); |
| 608 | for (llvm_errors[1..]) |*llvm_error, i| { | 608 | for (llvm_errors[1..], 0..) |*llvm_error, i| { |
| 609 | const name = error_name_list[1..][i]; | 609 | const name = error_name_list[1..][i]; |
| 610 | const str_init = self.context.constString(name.ptr, @intCast(c_uint, name.len), .False); | 610 | const str_init = self.context.constString(name.ptr, @intCast(c_uint, name.len), .False); |
| 611 | const str_global = self.llvm_module.addGlobal(str_init.typeOf(), ""); | 611 | const str_global = self.llvm_module.addGlobal(str_init.typeOf(), ""); |
| ... | @@ -696,7 +696,7 @@ pub const Object = struct { | ... | @@ -696,7 +696,7 @@ pub const Object = struct { |
| 696 | object.extern_collisions.clearRetainingCapacity(); | 696 | object.extern_collisions.clearRetainingCapacity(); |
| 697 | 697 | ||
| 698 | const export_keys = mod.decl_exports.keys(); | 698 | const export_keys = mod.decl_exports.keys(); |
| 699 | for (mod.decl_exports.values()) |export_list, i| { | 699 | for (mod.decl_exports.values(), 0..) |export_list, i| { |
| 700 | const decl_index = export_keys[i]; | 700 | const decl_index = export_keys[i]; |
| 701 | const llvm_global = object.decl_map.get(decl_index) orelse continue; | 701 | const llvm_global = object.decl_map.get(decl_index) orelse continue; |
| 702 | for (export_list.items) |exp| { | 702 | for (export_list.items) |exp| { |
| ... | @@ -1081,7 +1081,7 @@ pub const Object = struct { | ... | @@ -1081,7 +1081,7 @@ pub const Object = struct { |
| 1081 | const param_alignment = param_ty.abiAlignment(target); | 1081 | const param_alignment = param_ty.abiAlignment(target); |
| 1082 | const arg_ptr = buildAllocaInner(dg.context, builder, llvm_func, false, param_llvm_ty, param_alignment, target); | 1082 | const arg_ptr = buildAllocaInner(dg.context, builder, llvm_func, false, param_llvm_ty, param_alignment, target); |
| 1083 | const llvm_ty = dg.context.structType(field_types.ptr, @intCast(c_uint, field_types.len), .False); | 1083 | const llvm_ty = dg.context.structType(field_types.ptr, @intCast(c_uint, field_types.len), .False); |
| 1084 | for (field_types) |_, field_i_usize| { | 1084 | for (field_types, 0..) |_, field_i_usize| { |
| 1085 | const field_i = @intCast(c_uint, field_i_usize); | 1085 | const field_i = @intCast(c_uint, field_i_usize); |
| 1086 | const param = llvm_func.getParam(llvm_arg_i); | 1086 | const param = llvm_func.getParam(llvm_arg_i); |
| 1087 | llvm_arg_i += 1; | 1087 | llvm_arg_i += 1; |
| ... | @@ -1500,7 +1500,7 @@ pub const Object = struct { | ... | @@ -1500,7 +1500,7 @@ pub const Object = struct { |
| 1500 | const int_info = ty.intInfo(target); | 1500 | const int_info = ty.intInfo(target); |
| 1501 | assert(int_info.bits != 0); | 1501 | assert(int_info.bits != 0); |
| 1502 | 1502 | ||
| 1503 | for (field_names) |field_name, i| { | 1503 | for (field_names, 0..) |field_name, i| { |
| 1504 | const field_name_z = try gpa.dupeZ(u8, field_name); | 1504 | const field_name_z = try gpa.dupeZ(u8, field_name); |
| 1505 | defer gpa.free(field_name_z); | 1505 | defer gpa.free(field_name_z); |
| 1506 | 1506 | ||
| ... | @@ -1997,7 +1997,7 @@ pub const Object = struct { | ... | @@ -1997,7 +1997,7 @@ pub const Object = struct { |
| 1997 | comptime assert(struct_layout_version == 2); | 1997 | comptime assert(struct_layout_version == 2); |
| 1998 | var offset: u64 = 0; | 1998 | var offset: u64 = 0; |
| 1999 | 1999 | ||
| 2000 | for (tuple.types) |field_ty, i| { | 2000 | for (tuple.types, 0..) |field_ty, i| { |
| 2001 | const field_val = tuple.values[i]; | 2001 | const field_val = tuple.values[i]; |
| 2002 | if (field_val.tag() != .unreachable_value or !field_ty.hasRuntimeBits()) continue; | 2002 | if (field_val.tag() != .unreachable_value or !field_ty.hasRuntimeBits()) continue; |
| 2003 | 2003 | ||
| ... | @@ -2926,7 +2926,7 @@ pub const DeclGen = struct { | ... | @@ -2926,7 +2926,7 @@ pub const DeclGen = struct { |
| 2926 | var offset: u64 = 0; | 2926 | var offset: u64 = 0; |
| 2927 | var big_align: u32 = 0; | 2927 | var big_align: u32 = 0; |
| 2928 | 2928 | ||
| 2929 | for (tuple.types) |field_ty, i| { | 2929 | for (tuple.types, 0..) |field_ty, i| { |
| 2930 | const field_val = tuple.values[i]; | 2930 | const field_val = tuple.values[i]; |
| 2931 | if (field_val.tag() != .unreachable_value or !field_ty.hasRuntimeBits()) continue; | 2931 | if (field_val.tag() != .unreachable_value or !field_ty.hasRuntimeBits()) continue; |
| 2932 | 2932 | ||
| ... | @@ -3437,7 +3437,7 @@ pub const DeclGen = struct { | ... | @@ -3437,7 +3437,7 @@ pub const DeclGen = struct { |
| 3437 | const llvm_elems = try gpa.alloc(*llvm.Value, len); | 3437 | const llvm_elems = try gpa.alloc(*llvm.Value, len); |
| 3438 | defer gpa.free(llvm_elems); | 3438 | defer gpa.free(llvm_elems); |
| 3439 | var need_unnamed = false; | 3439 | var need_unnamed = false; |
| 3440 | for (elem_vals[0..len]) |elem_val, i| { | 3440 | for (elem_vals[0..len], 0..) |elem_val, i| { |
| 3441 | llvm_elems[i] = try dg.lowerValue(.{ .ty = elem_ty, .val = elem_val }); | 3441 | llvm_elems[i] = try dg.lowerValue(.{ .ty = elem_ty, .val = elem_val }); |
| 3442 | need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[i]); | 3442 | need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[i]); |
| 3443 | } | 3443 | } |
| ... | @@ -3623,7 +3623,7 @@ pub const DeclGen = struct { | ... | @@ -3623,7 +3623,7 @@ pub const DeclGen = struct { |
| 3623 | var big_align: u32 = 0; | 3623 | var big_align: u32 = 0; |
| 3624 | var need_unnamed = false; | 3624 | var need_unnamed = false; |
| 3625 | 3625 | ||
| 3626 | for (tuple.types) |field_ty, i| { | 3626 | for (tuple.types, 0..) |field_ty, i| { |
| 3627 | if (tuple.values[i].tag() != .unreachable_value) continue; | 3627 | if (tuple.values[i].tag() != .unreachable_value) continue; |
| 3628 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 3628 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 3629 | 3629 | ||
| ... | @@ -3685,7 +3685,7 @@ pub const DeclGen = struct { | ... | @@ -3685,7 +3685,7 @@ pub const DeclGen = struct { |
| 3685 | comptime assert(Type.packed_struct_layout_version == 2); | 3685 | comptime assert(Type.packed_struct_layout_version == 2); |
| 3686 | var running_int: *llvm.Value = int_llvm_ty.constNull(); | 3686 | var running_int: *llvm.Value = int_llvm_ty.constNull(); |
| 3687 | var running_bits: u16 = 0; | 3687 | var running_bits: u16 = 0; |
| 3688 | for (field_vals) |field_val, i| { | 3688 | for (field_vals, 0..) |field_val, i| { |
| 3689 | const field = fields[i]; | 3689 | const field = fields[i]; |
| 3690 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; | 3690 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 3691 | 3691 | ||
| ... | @@ -3860,7 +3860,7 @@ pub const DeclGen = struct { | ... | @@ -3860,7 +3860,7 @@ pub const DeclGen = struct { |
| 3860 | const elem_ty = tv.ty.elemType(); | 3860 | const elem_ty = tv.ty.elemType(); |
| 3861 | const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len); | 3861 | const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len); |
| 3862 | defer dg.gpa.free(llvm_elems); | 3862 | defer dg.gpa.free(llvm_elems); |
| 3863 | for (llvm_elems) |*elem, i| { | 3863 | for (llvm_elems, 0..) |*elem, i| { |
| 3864 | var byte_payload: Value.Payload.U64 = .{ | 3864 | var byte_payload: Value.Payload.U64 = .{ |
| 3865 | .base = .{ .tag = .int_u64 }, | 3865 | .base = .{ .tag = .int_u64 }, |
| 3866 | .data = bytes[i], | 3866 | .data = bytes[i], |
| ... | @@ -3885,7 +3885,7 @@ pub const DeclGen = struct { | ... | @@ -3885,7 +3885,7 @@ pub const DeclGen = struct { |
| 3885 | const elem_ty = tv.ty.elemType(); | 3885 | const elem_ty = tv.ty.elemType(); |
| 3886 | const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len); | 3886 | const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len); |
| 3887 | defer dg.gpa.free(llvm_elems); | 3887 | defer dg.gpa.free(llvm_elems); |
| 3888 | for (llvm_elems) |*elem, i| { | 3888 | for (llvm_elems, 0..) |*elem, i| { |
| 3889 | elem.* = try dg.lowerValue(.{ .ty = elem_ty, .val = elem_vals[i] }); | 3889 | elem.* = try dg.lowerValue(.{ .ty = elem_ty, .val = elem_vals[i] }); |
| 3890 | } | 3890 | } |
| 3891 | return llvm.constVector( | 3891 | return llvm.constVector( |
| ... | @@ -3918,7 +3918,7 @@ pub const DeclGen = struct { | ... | @@ -3918,7 +3918,7 @@ pub const DeclGen = struct { |
| 3918 | const elem_ty = tv.ty.elemType(); | 3918 | const elem_ty = tv.ty.elemType(); |
| 3919 | const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len); | 3919 | const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len); |
| 3920 | defer dg.gpa.free(llvm_elems); | 3920 | defer dg.gpa.free(llvm_elems); |
| 3921 | for (llvm_elems) |*elem, i| { | 3921 | for (llvm_elems, 0..) |*elem, i| { |
| 3922 | var byte_payload: Value.Payload.U64 = .{ | 3922 | var byte_payload: Value.Payload.U64 = .{ |
| 3923 | .base = .{ .tag = .int_u64 }, | 3923 | .base = .{ .tag = .int_u64 }, |
| 3924 | .data = bytes[i], | 3924 | .data = bytes[i], |
| ... | @@ -4484,7 +4484,7 @@ pub const FuncGen = struct { | ... | @@ -4484,7 +4484,7 @@ pub const FuncGen = struct { |
| 4484 | 4484 | ||
| 4485 | fn genBody(self: *FuncGen, body: []const Air.Inst.Index) Error!void { | 4485 | fn genBody(self: *FuncGen, body: []const Air.Inst.Index) Error!void { |
| 4486 | const air_tags = self.air.instructions.items(.tag); | 4486 | const air_tags = self.air.instructions.items(.tag); |
| 4487 | for (body) |inst, i| { | 4487 | for (body, 0..) |inst, i| { |
| 4488 | const opt_value: ?*llvm.Value = switch (air_tags[inst]) { | 4488 | const opt_value: ?*llvm.Value = switch (air_tags[inst]) { |
| 4489 | // zig fmt: off | 4489 | // zig fmt: off |
| 4490 | .add => try self.airAdd(inst, false), | 4490 | .add => try self.airAdd(inst, false), |
| ... | @@ -4857,7 +4857,7 @@ pub const FuncGen = struct { | ... | @@ -4857,7 +4857,7 @@ pub const FuncGen = struct { |
| 4857 | 4857 | ||
| 4858 | const llvm_ty = self.context.structType(llvm_types.ptr, @intCast(c_uint, llvm_types.len), .False); | 4858 | const llvm_ty = self.context.structType(llvm_types.ptr, @intCast(c_uint, llvm_types.len), .False); |
| 4859 | try llvm_args.ensureUnusedCapacity(it.llvm_types_len); | 4859 | try llvm_args.ensureUnusedCapacity(it.llvm_types_len); |
| 4860 | for (llvm_types) |field_ty, i_usize| { | 4860 | for (llvm_types, 0..) |field_ty, i_usize| { |
| 4861 | const i = @intCast(c_uint, i_usize); | 4861 | const i = @intCast(c_uint, i_usize); |
| 4862 | const field_ptr = self.builder.buildStructGEP(llvm_ty, arg_ptr, i, ""); | 4862 | const field_ptr = self.builder.buildStructGEP(llvm_ty, arg_ptr, i, ""); |
| 4863 | const load_inst = self.builder.buildLoad(field_ty, field_ptr, ""); | 4863 | const load_inst = self.builder.buildLoad(field_ty, field_ptr, ""); |
| ... | @@ -6255,7 +6255,7 @@ pub const FuncGen = struct { | ... | @@ -6255,7 +6255,7 @@ pub const FuncGen = struct { |
| 6255 | var name_map: std.StringArrayHashMapUnmanaged(u16) = .{}; | 6255 | var name_map: std.StringArrayHashMapUnmanaged(u16) = .{}; |
| 6256 | try name_map.ensureUnusedCapacity(arena, max_param_count); | 6256 | try name_map.ensureUnusedCapacity(arena, max_param_count); |
| 6257 | 6257 | ||
| 6258 | for (outputs) |output, i| { | 6258 | for (outputs, 0..) |output, i| { |
| 6259 | const extra_bytes = std.mem.sliceAsBytes(self.air.extra[extra_i..]); | 6259 | const extra_bytes = std.mem.sliceAsBytes(self.air.extra[extra_i..]); |
| 6260 | const constraint = std.mem.sliceTo(std.mem.sliceAsBytes(self.air.extra[extra_i..]), 0); | 6260 | const constraint = std.mem.sliceTo(std.mem.sliceAsBytes(self.air.extra[extra_i..]), 0); |
| 6261 | const name = std.mem.sliceTo(extra_bytes[constraint.len + 1 ..], 0); | 6261 | const name = std.mem.sliceTo(extra_bytes[constraint.len + 1 ..], 0); |
| ... | @@ -6440,7 +6440,7 @@ pub const FuncGen = struct { | ... | @@ -6440,7 +6440,7 @@ pub const FuncGen = struct { |
| 6440 | 6440 | ||
| 6441 | var name_start: usize = undefined; | 6441 | var name_start: usize = undefined; |
| 6442 | var modifier_start: usize = undefined; | 6442 | var modifier_start: usize = undefined; |
| 6443 | for (asm_source) |byte, i| { | 6443 | for (asm_source, 0..) |byte, i| { |
| 6444 | switch (state) { | 6444 | switch (state) { |
| 6445 | .start => switch (byte) { | 6445 | .start => switch (byte) { |
| 6446 | '%' => state = .percent, | 6446 | '%' => state = .percent, |
| ... | @@ -6531,7 +6531,7 @@ pub const FuncGen = struct { | ... | @@ -6531,7 +6531,7 @@ pub const FuncGen = struct { |
| 6531 | .Auto, | 6531 | .Auto, |
| 6532 | "", | 6532 | "", |
| 6533 | ); | 6533 | ); |
| 6534 | for (llvm_param_attrs[0..param_count]) |llvm_elem_ty, i| { | 6534 | for (llvm_param_attrs[0..param_count], 0..) |llvm_elem_ty, i| { |
| 6535 | if (llvm_elem_ty) |llvm_ty| { | 6535 | if (llvm_elem_ty) |llvm_ty| { |
| 6536 | llvm.setCallElemTypeAttr(call, i, llvm_ty); | 6536 | llvm.setCallElemTypeAttr(call, i, llvm_ty); |
| 6537 | } | 6537 | } |
| ... | @@ -6539,7 +6539,7 @@ pub const FuncGen = struct { | ... | @@ -6539,7 +6539,7 @@ pub const FuncGen = struct { |
| 6539 | 6539 | ||
| 6540 | var ret_val = call; | 6540 | var ret_val = call; |
| 6541 | llvm_ret_i = 0; | 6541 | llvm_ret_i = 0; |
| 6542 | for (outputs) |output, i| { | 6542 | for (outputs, 0..) |output, i| { |
| 6543 | if (llvm_ret_indirect[i]) continue; | 6543 | if (llvm_ret_indirect[i]) continue; |
| 6544 | 6544 | ||
| 6545 | const output_value = if (return_count > 1) b: { | 6545 | const output_value = if (return_count > 1) b: { |
| ... | @@ -7421,7 +7421,7 @@ pub const FuncGen = struct { | ... | @@ -7421,7 +7421,7 @@ pub const FuncGen = struct { |
| 7421 | const index_i32 = llvm_i32.constInt(i, .False); | 7421 | const index_i32 = llvm_i32.constInt(i, .False); |
| 7422 | 7422 | ||
| 7423 | var args: [3]*llvm.Value = undefined; | 7423 | var args: [3]*llvm.Value = undefined; |
| 7424 | for (args_vectors) |arg_vector, k| { | 7424 | for (args_vectors, 0..) |arg_vector, k| { |
| 7425 | args[k] = self.builder.buildExtractElement(arg_vector, index_i32, ""); | 7425 | args[k] = self.builder.buildExtractElement(arg_vector, index_i32, ""); |
| 7426 | } | 7426 | } |
| 7427 | const result_elem = self.builder.buildCall(llvm_fn.globalGetValueType(), llvm_fn, &args, args_len, .C, .Auto, ""); | 7427 | const result_elem = self.builder.buildCall(llvm_fn.globalGetValueType(), llvm_fn, &args, args_len, .C, .Auto, ""); |
| ... | @@ -8790,7 +8790,7 @@ pub const FuncGen = struct { | ... | @@ -8790,7 +8790,7 @@ pub const FuncGen = struct { |
| 8790 | const tag_int_value = fn_val.getParam(0); | 8790 | const tag_int_value = fn_val.getParam(0); |
| 8791 | const switch_instr = self.builder.buildSwitch(tag_int_value, unnamed_block, @intCast(c_uint, fields.count())); | 8791 | const switch_instr = self.builder.buildSwitch(tag_int_value, unnamed_block, @intCast(c_uint, fields.count())); |
| 8792 | 8792 | ||
| 8793 | for (fields.keys()) |_, field_index| { | 8793 | for (fields.keys(), 0..) |_, field_index| { |
| 8794 | const this_tag_int_value = int: { | 8794 | const this_tag_int_value = int: { |
| 8795 | var tag_val_payload: Value.Payload.U32 = .{ | 8795 | var tag_val_payload: Value.Payload.U32 = .{ |
| 8796 | .base = .{ .tag = .enum_field_index }, | 8796 | .base = .{ .tag = .enum_field_index }, |
| ... | @@ -8879,7 +8879,7 @@ pub const FuncGen = struct { | ... | @@ -8879,7 +8879,7 @@ pub const FuncGen = struct { |
| 8879 | usize_llvm_ty.constNull(), usize_llvm_ty.constNull(), | 8879 | usize_llvm_ty.constNull(), usize_llvm_ty.constNull(), |
| 8880 | }; | 8880 | }; |
| 8881 | 8881 | ||
| 8882 | for (fields.keys()) |name, field_index| { | 8882 | for (fields.keys(), 0..) |name, field_index| { |
| 8883 | const str_init = self.context.constString(name.ptr, @intCast(c_uint, name.len), .False); | 8883 | const str_init = self.context.constString(name.ptr, @intCast(c_uint, name.len), .False); |
| 8884 | const str_init_llvm_ty = str_init.typeOf(); | 8884 | const str_init_llvm_ty = str_init.typeOf(); |
| 8885 | const str_global = self.dg.object.llvm_module.addGlobal(str_init_llvm_ty, ""); | 8885 | const str_global = self.dg.object.llvm_module.addGlobal(str_init_llvm_ty, ""); |
| ... | @@ -9003,7 +9003,7 @@ pub const FuncGen = struct { | ... | @@ -9003,7 +9003,7 @@ pub const FuncGen = struct { |
| 9003 | 9003 | ||
| 9004 | const llvm_i32 = self.context.intType(32); | 9004 | const llvm_i32 = self.context.intType(32); |
| 9005 | 9005 | ||
| 9006 | for (values) |*val, i| { | 9006 | for (values, 0..) |*val, i| { |
| 9007 | var buf: Value.ElemValueBuffer = undefined; | 9007 | var buf: Value.ElemValueBuffer = undefined; |
| 9008 | const elem = mask.elemValueBuffer(self.dg.module, i, &buf); | 9008 | const elem = mask.elemValueBuffer(self.dg.module, i, &buf); |
| 9009 | if (elem.isUndef()) { | 9009 | if (elem.isUndef()) { |
| ... | @@ -9185,7 +9185,7 @@ pub const FuncGen = struct { | ... | @@ -9185,7 +9185,7 @@ pub const FuncGen = struct { |
| 9185 | const llvm_u32 = self.context.intType(32); | 9185 | const llvm_u32 = self.context.intType(32); |
| 9186 | 9186 | ||
| 9187 | var vector = llvm_result_ty.getUndef(); | 9187 | var vector = llvm_result_ty.getUndef(); |
| 9188 | for (elements) |elem, i| { | 9188 | for (elements, 0..) |elem, i| { |
| 9189 | const index_u32 = llvm_u32.constInt(i, .False); | 9189 | const index_u32 = llvm_u32.constInt(i, .False); |
| 9190 | const llvm_elem = try self.resolveInst(elem); | 9190 | const llvm_elem = try self.resolveInst(elem); |
| 9191 | vector = self.builder.buildInsertElement(vector, llvm_elem, index_u32, ""); | 9191 | vector = self.builder.buildInsertElement(vector, llvm_elem, index_u32, ""); |
| ... | @@ -9202,7 +9202,7 @@ pub const FuncGen = struct { | ... | @@ -9202,7 +9202,7 @@ pub const FuncGen = struct { |
| 9202 | comptime assert(Type.packed_struct_layout_version == 2); | 9202 | comptime assert(Type.packed_struct_layout_version == 2); |
| 9203 | var running_int: *llvm.Value = int_llvm_ty.constNull(); | 9203 | var running_int: *llvm.Value = int_llvm_ty.constNull(); |
| 9204 | var running_bits: u16 = 0; | 9204 | var running_bits: u16 = 0; |
| 9205 | for (elements) |elem, i| { | 9205 | for (elements, 0..) |elem, i| { |
| 9206 | const field = fields[i]; | 9206 | const field = fields[i]; |
| 9207 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; | 9207 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 9208 | 9208 | ||
| ... | @@ -9234,7 +9234,7 @@ pub const FuncGen = struct { | ... | @@ -9234,7 +9234,7 @@ pub const FuncGen = struct { |
| 9234 | const alloca_inst = self.buildAlloca(llvm_result_ty, result_ty.abiAlignment(target)); | 9234 | const alloca_inst = self.buildAlloca(llvm_result_ty, result_ty.abiAlignment(target)); |
| 9235 | 9235 | ||
| 9236 | var indices: [2]*llvm.Value = .{ llvm_u32.constNull(), undefined }; | 9236 | var indices: [2]*llvm.Value = .{ llvm_u32.constNull(), undefined }; |
| 9237 | for (elements) |elem, i| { | 9237 | for (elements, 0..) |elem, i| { |
| 9238 | if (result_ty.structFieldValueComptime(i) != null) continue; | 9238 | if (result_ty.structFieldValueComptime(i) != null) continue; |
| 9239 | 9239 | ||
| 9240 | const llvm_elem = try self.resolveInst(elem); | 9240 | const llvm_elem = try self.resolveInst(elem); |
| ... | @@ -9255,7 +9255,7 @@ pub const FuncGen = struct { | ... | @@ -9255,7 +9255,7 @@ pub const FuncGen = struct { |
| 9255 | return alloca_inst; | 9255 | return alloca_inst; |
| 9256 | } else { | 9256 | } else { |
| 9257 | var result = llvm_result_ty.getUndef(); | 9257 | var result = llvm_result_ty.getUndef(); |
| 9258 | for (elements) |elem, i| { | 9258 | for (elements, 0..) |elem, i| { |
| 9259 | if (result_ty.structFieldValueComptime(i) != null) continue; | 9259 | if (result_ty.structFieldValueComptime(i) != null) continue; |
| 9260 | 9260 | ||
| 9261 | const llvm_elem = try self.resolveInst(elem); | 9261 | const llvm_elem = try self.resolveInst(elem); |
| ... | @@ -9280,7 +9280,7 @@ pub const FuncGen = struct { | ... | @@ -9280,7 +9280,7 @@ pub const FuncGen = struct { |
| 9280 | }; | 9280 | }; |
| 9281 | const elem_ptr_ty = Type.initPayload(&elem_ptr_payload.base); | 9281 | const elem_ptr_ty = Type.initPayload(&elem_ptr_payload.base); |
| 9282 | 9282 | ||
| 9283 | for (elements) |elem, i| { | 9283 | for (elements, 0..) |elem, i| { |
| 9284 | const indices: [2]*llvm.Value = .{ | 9284 | const indices: [2]*llvm.Value = .{ |
| 9285 | llvm_usize.constNull(), | 9285 | llvm_usize.constNull(), |
| 9286 | llvm_usize.constInt(@intCast(c_uint, i), .False), | 9286 | llvm_usize.constInt(@intCast(c_uint, i), .False), |
| ... | @@ -9919,7 +9919,7 @@ pub const FuncGen = struct { | ... | @@ -9919,7 +9919,7 @@ pub const FuncGen = struct { |
| 9919 | }; | 9919 | }; |
| 9920 | const array_elements = [_]*llvm.Value{ request, a1, a2, a3, a4, a5 }; | 9920 | const array_elements = [_]*llvm.Value{ request, a1, a2, a3, a4, a5 }; |
| 9921 | const zero = usize_llvm_ty.constInt(0, .False); | 9921 | const zero = usize_llvm_ty.constInt(0, .False); |
| 9922 | for (array_elements) |elem, i| { | 9922 | for (array_elements, 0..) |elem, i| { |
| 9923 | const indexes = [_]*llvm.Value{ | 9923 | const indexes = [_]*llvm.Value{ |
| 9924 | zero, usize_llvm_ty.constInt(@intCast(c_uint, i), .False), | 9924 | zero, usize_llvm_ty.constInt(@intCast(c_uint, i), .False), |
| 9925 | }; | 9925 | }; |
| ... | @@ -10341,7 +10341,7 @@ fn llvmFieldIndex( | ... | @@ -10341,7 +10341,7 @@ fn llvmFieldIndex( |
| 10341 | if (ty.isSimpleTupleOrAnonStruct()) { | 10341 | if (ty.isSimpleTupleOrAnonStruct()) { |
| 10342 | const tuple = ty.tupleFields(); | 10342 | const tuple = ty.tupleFields(); |
| 10343 | var llvm_field_index: c_uint = 0; | 10343 | var llvm_field_index: c_uint = 0; |
| 10344 | for (tuple.types) |field_ty, i| { | 10344 | for (tuple.types, 0..) |field_ty, i| { |
| 10345 | if (tuple.values[i].tag() != .unreachable_value or !field_ty.hasRuntimeBits()) continue; | 10345 | if (tuple.values[i].tag() != .unreachable_value or !field_ty.hasRuntimeBits()) continue; |
| 10346 | 10346 | ||
| 10347 | const field_align = field_ty.abiAlignment(target); | 10347 | const field_align = field_ty.abiAlignment(target); |
| ... | @@ -10952,7 +10952,7 @@ fn isByRef(ty: Type) bool { | ... | @@ -10952,7 +10952,7 @@ fn isByRef(ty: Type) bool { |
| 10952 | if (ty.isSimpleTupleOrAnonStruct()) { | 10952 | if (ty.isSimpleTupleOrAnonStruct()) { |
| 10953 | const tuple = ty.tupleFields(); | 10953 | const tuple = ty.tupleFields(); |
| 10954 | var count: usize = 0; | 10954 | var count: usize = 0; |
| 10955 | for (tuple.values) |field_val, i| { | 10955 | for (tuple.values, 0..) |field_val, i| { |
| 10956 | if (field_val.tag() != .unreachable_value or !tuple.types[i].hasRuntimeBits()) continue; | 10956 | if (field_val.tag() != .unreachable_value or !tuple.types[i].hasRuntimeBits()) continue; |
| 10957 | 10957 | ||
| 10958 | count += 1; | 10958 | count += 1; |
src/codegen/spirv.zig+2-2| ... | @@ -418,7 +418,7 @@ pub const DeclGen = struct { | ... | @@ -418,7 +418,7 @@ pub const DeclGen = struct { |
| 418 | 418 | ||
| 419 | const elem_refs = try self.gpa.alloc(IdRef, vector_len); | 419 | const elem_refs = try self.gpa.alloc(IdRef, vector_len); |
| 420 | defer self.gpa.free(elem_refs); | 420 | defer self.gpa.free(elem_refs); |
| 421 | for (elem_refs) |*elem, i| { | 421 | for (elem_refs, 0..) |*elem, i| { |
| 422 | elem.* = try self.genConstant(elem_ty, elem_vals[i]); | 422 | elem.* = try self.genConstant(elem_ty, elem_vals[i]); |
| 423 | } | 423 | } |
| 424 | try section.emit(self.spv.gpa, .OpConstantComposite, .{ | 424 | try section.emit(self.spv.gpa, .OpConstantComposite, .{ |
| ... | @@ -498,7 +498,7 @@ pub const DeclGen = struct { | ... | @@ -498,7 +498,7 @@ pub const DeclGen = struct { |
| 498 | return self.fail("VarArgs functions are unsupported for SPIR-V", .{}); | 498 | return self.fail("VarArgs functions are unsupported for SPIR-V", .{}); |
| 499 | 499 | ||
| 500 | const param_types = try self.spv.arena.alloc(SpvType.Ref, ty.fnParamLen()); | 500 | const param_types = try self.spv.arena.alloc(SpvType.Ref, ty.fnParamLen()); |
| 501 | for (param_types) |*param, i| { | 501 | for (param_types, 0..) |*param, i| { |
| 502 | param.* = try self.resolveType(ty.fnParamType(i)); | 502 | param.* = try self.resolveType(ty.fnParamType(i)); |
| 503 | } | 503 | } |
| 504 | 504 |
src/codegen/spirv/Assembler.zig+1-1| ... | @@ -392,7 +392,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue { | ... | @@ -392,7 +392,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue { |
| 392 | .OpTypeFunction => blk: { | 392 | .OpTypeFunction => blk: { |
| 393 | const param_operands = operands[2..]; | 393 | const param_operands = operands[2..]; |
| 394 | const param_types = try self.spv.arena.alloc(SpvType.Ref, param_operands.len); | 394 | const param_types = try self.spv.arena.alloc(SpvType.Ref, param_operands.len); |
| 395 | for (param_types) |*param, i| { | 395 | for (param_types, 0..) |*param, i| { |
| 396 | param.* = try self.resolveTypeRef(param_operands[i].ref_id); | 396 | param.* = try self.resolveTypeRef(param_operands[i].ref_id); |
| 397 | } | 397 | } |
| 398 | const payload = try self.spv.arena.create(SpvType.Payload.Function); | 398 | const payload = try self.spv.arena.create(SpvType.Payload.Function); |
src/codegen/spirv/Module.zig+2-2| ... | @@ -161,7 +161,7 @@ pub fn flush(self: Module, file: std.fs.File) !void { | ... | @@ -161,7 +161,7 @@ pub fn flush(self: Module, file: std.fs.File) !void { |
| 161 | 161 | ||
| 162 | var iovc_buffers: [buffers.len]std.os.iovec_const = undefined; | 162 | var iovc_buffers: [buffers.len]std.os.iovec_const = undefined; |
| 163 | var file_size: u64 = 0; | 163 | var file_size: u64 = 0; |
| 164 | for (iovc_buffers) |*iovc, i| { | 164 | for (&iovc_buffers, 0..) |*iovc, i| { |
| 165 | // Note, since spir-v supports both little and big endian we can ignore byte order here and | 165 | // Note, since spir-v supports both little and big endian we can ignore byte order here and |
| 166 | // just treat the words as a sequence of bytes. | 166 | // just treat the words as a sequence of bytes. |
| 167 | const bytes = std.mem.sliceAsBytes(buffers[i]); | 167 | const bytes = std.mem.sliceAsBytes(buffers[i]); |
| ... | @@ -389,7 +389,7 @@ fn decorateStruct(self: *Module, target: IdRef, info: *const Type.Payload.Struct | ... | @@ -389,7 +389,7 @@ fn decorateStruct(self: *Module, target: IdRef, info: *const Type.Payload.Struct |
| 389 | // Decorations for the struct members. | 389 | // Decorations for the struct members. |
| 390 | const extra = info.member_decoration_extra; | 390 | const extra = info.member_decoration_extra; |
| 391 | var extra_i: u32 = 0; | 391 | var extra_i: u32 = 0; |
| 392 | for (info.members) |member, i| { | 392 | for (info.members, 0..) |member, i| { |
| 393 | const d = member.decorations; | 393 | const d = member.decorations; |
| 394 | const index = @intCast(Word, i); | 394 | const index = @intCast(Word, i); |
| 395 | switch (d.matrix_layout) { | 395 | switch (d.matrix_layout) { |
src/codegen/spirv/Section.zig+1-1| ... | @@ -195,7 +195,7 @@ fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDe | ... | @@ -195,7 +195,7 @@ fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDe |
| 195 | 195 | ||
| 196 | fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void { | 196 | fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void { |
| 197 | var mask: Word = 0; | 197 | var mask: Word = 0; |
| 198 | inline for (@typeInfo(Operand).Struct.fields) |field, bit| { | 198 | inline for (@typeInfo(Operand).Struct.fields, 0..) |field, bit| { |
| 199 | switch (@typeInfo(field.type)) { | 199 | switch (@typeInfo(field.type)) { |
| 200 | .Optional => if (@field(operand, field.name) != null) { | 200 | .Optional => if (@field(operand, field.name) != null) { |
| 201 | mask |= 1 << @intCast(u5, bit); | 201 | mask |= 1 << @intCast(u5, bit); |
src/codegen/spirv/type.zig+1-1| ... | @@ -98,7 +98,7 @@ pub const Type = extern union { | ... | @@ -98,7 +98,7 @@ pub const Type = extern union { |
| 98 | const struct_b = b.payload(.@"struct"); | 98 | const struct_b = b.payload(.@"struct"); |
| 99 | if (struct_a.members.len != struct_b.members.len) | 99 | if (struct_a.members.len != struct_b.members.len) |
| 100 | return false; | 100 | return false; |
| 101 | for (struct_a.members) |mem_a, i| { | 101 | for (struct_a.members, 0..) |mem_a, i| { |
| 102 | if (!std.meta.eql(mem_a, struct_b.members[i])) | 102 | if (!std.meta.eql(mem_a, struct_b.members[i])) |
| 103 | return false; | 103 | return false; |
| 104 | } | 104 | } |
src/glibc.zig+3-3| ... | @@ -698,7 +698,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void { | ... | @@ -698,7 +698,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void { |
| 698 | const metadata = try loadMetaData(comp.gpa, abilists_contents); | 698 | const metadata = try loadMetaData(comp.gpa, abilists_contents); |
| 699 | defer metadata.destroy(comp.gpa); | 699 | defer metadata.destroy(comp.gpa); |
| 700 | 700 | ||
| 701 | const target_targ_index = for (metadata.all_targets) |targ, i| { | 701 | const target_targ_index = for (metadata.all_targets, 0..) |targ, i| { |
| 702 | if (targ.arch == target.cpu.arch and | 702 | if (targ.arch == target.cpu.arch and |
| 703 | targ.os == target.os.tag and | 703 | targ.os == target.os.tag and |
| 704 | targ.abi == target.abi) | 704 | targ.abi == target.abi) |
| ... | @@ -709,7 +709,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void { | ... | @@ -709,7 +709,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void { |
| 709 | unreachable; // target_util.available_libcs prevents us from getting here | 709 | unreachable; // target_util.available_libcs prevents us from getting here |
| 710 | }; | 710 | }; |
| 711 | 711 | ||
| 712 | const target_ver_index = for (metadata.all_versions) |ver, i| { | 712 | const target_ver_index = for (metadata.all_versions, 0..) |ver, i| { |
| 713 | switch (ver.order(target_version)) { | 713 | switch (ver.order(target_version)) { |
| 714 | .eq => break i, | 714 | .eq => break i, |
| 715 | .lt => continue, | 715 | .lt => continue, |
| ... | @@ -743,7 +743,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void { | ... | @@ -743,7 +743,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void { |
| 743 | var stubs_asm = std.ArrayList(u8).init(comp.gpa); | 743 | var stubs_asm = std.ArrayList(u8).init(comp.gpa); |
| 744 | defer stubs_asm.deinit(); | 744 | defer stubs_asm.deinit(); |
| 745 | 745 | ||
| 746 | for (libs) |lib, lib_i| { | 746 | for (libs, 0..) |lib, lib_i| { |
| 747 | stubs_asm.shrinkRetainingCapacity(0); | 747 | stubs_asm.shrinkRetainingCapacity(0); |
| 748 | try stubs_asm.appendSlice(".text\n"); | 748 | try stubs_asm.appendSlice(".text\n"); |
| 749 | 749 |
src/libc_installation.zig+3-3| ... | @@ -66,7 +66,7 @@ pub const LibCInstallation = struct { | ... | @@ -66,7 +66,7 @@ pub const LibCInstallation = struct { |
| 66 | var line_it = std.mem.split(u8, line, "="); | 66 | var line_it = std.mem.split(u8, line, "="); |
| 67 | const name = line_it.first(); | 67 | const name = line_it.first(); |
| 68 | const value = line_it.rest(); | 68 | const value = line_it.rest(); |
| 69 | inline for (fields) |field, i| { | 69 | inline for (fields, 0..) |field, i| { |
| 70 | if (std.mem.eql(u8, name, field.name)) { | 70 | if (std.mem.eql(u8, name, field.name)) { |
| 71 | found_keys[i].found = true; | 71 | found_keys[i].found = true; |
| 72 | if (value.len == 0) { | 72 | if (value.len == 0) { |
| ... | @@ -79,7 +79,7 @@ pub const LibCInstallation = struct { | ... | @@ -79,7 +79,7 @@ pub const LibCInstallation = struct { |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | inline for (fields) |field, i| { | 82 | inline for (fields, 0..) |field, i| { |
| 83 | if (!found_keys[i].found) { | 83 | if (!found_keys[i].found) { |
| 84 | log.err("missing field: {s}\n", .{field.name}); | 84 | log.err("missing field: {s}\n", .{field.name}); |
| 85 | return error.ParseError; | 85 | return error.ParseError; |
| ... | @@ -640,7 +640,7 @@ fn printVerboseInvocation( | ... | @@ -640,7 +640,7 @@ fn printVerboseInvocation( |
| 640 | } else { | 640 | } else { |
| 641 | std.debug.print("Zig attempted to find the path to native system libc headers by executing this command:\n", .{}); | 641 | std.debug.print("Zig attempted to find the path to native system libc headers by executing this command:\n", .{}); |
| 642 | } | 642 | } |
| 643 | for (argv) |arg, i| { | 643 | for (argv, 0..) |arg, i| { |
| 644 | if (i != 0) std.debug.print(" ", .{}); | 644 | if (i != 0) std.debug.print(" ", .{}); |
| 645 | std.debug.print("{s}", .{arg}); | 645 | std.debug.print("{s}", .{arg}); |
| 646 | } | 646 | } |
src/libunwind.zig+1-1| ... | @@ -34,7 +34,7 @@ pub fn buildStaticLib(comp: *Compilation) !void { | ... | @@ -34,7 +34,7 @@ pub fn buildStaticLib(comp: *Compilation) !void { |
| 34 | .basename = basename, | 34 | .basename = basename, |
| 35 | }; | 35 | }; |
| 36 | var c_source_files: [unwind_src_list.len]Compilation.CSourceFile = undefined; | 36 | var c_source_files: [unwind_src_list.len]Compilation.CSourceFile = undefined; |
| 37 | for (unwind_src_list) |unwind_src, i| { | 37 | for (unwind_src_list, 0..) |unwind_src, i| { |
| 38 | var cflags = std.ArrayList([]const u8).init(arena); | 38 | var cflags = std.ArrayList([]const u8).init(arena); |
| 39 | 39 | ||
| 40 | switch (Compilation.classifyFileExt(unwind_src)) { | 40 | switch (Compilation.classifyFileExt(unwind_src)) { |
src/link/Coff.zig+3-3| ... | @@ -486,7 +486,7 @@ fn growSectionVM(self: *Coff, sect_id: u32, needed_size: u32) !void { | ... | @@ -486,7 +486,7 @@ fn growSectionVM(self: *Coff, sect_id: u32, needed_size: u32) !void { |
| 486 | 486 | ||
| 487 | // TODO: enforce order by increasing VM addresses in self.sections container. | 487 | // TODO: enforce order by increasing VM addresses in self.sections container. |
| 488 | // This is required by the loader anyhow as far as I can tell. | 488 | // This is required by the loader anyhow as far as I can tell. |
| 489 | for (self.sections.items(.header)[sect_id + 1 ..]) |*next_header, next_sect_id| { | 489 | for (self.sections.items(.header)[sect_id + 1 ..], 0..) |*next_header, next_sect_id| { |
| 490 | const maybe_last_atom_index = self.sections.items(.last_atom_index)[sect_id + 1 + next_sect_id]; | 490 | const maybe_last_atom_index = self.sections.items(.last_atom_index)[sect_id + 1 + next_sect_id]; |
| 491 | next_header.virtual_address += diff; | 491 | next_header.virtual_address += diff; |
| 492 | 492 | ||
| ... | @@ -2191,7 +2191,7 @@ fn logSymtab(self: *Coff) void { | ... | @@ -2191,7 +2191,7 @@ fn logSymtab(self: *Coff) void { |
| 2191 | 2191 | ||
| 2192 | log.debug("symtab:", .{}); | 2192 | log.debug("symtab:", .{}); |
| 2193 | log.debug(" object(null)", .{}); | 2193 | log.debug(" object(null)", .{}); |
| 2194 | for (self.locals.items) |*sym, sym_id| { | 2194 | for (self.locals.items, 0..) |*sym, sym_id| { |
| 2195 | const where = if (sym.section_number == .UNDEFINED) "ord" else "sect"; | 2195 | const where = if (sym.section_number == .UNDEFINED) "ord" else "sect"; |
| 2196 | const def_index: u16 = switch (sym.section_number) { | 2196 | const def_index: u16 = switch (sym.section_number) { |
| 2197 | .UNDEFINED => 0, // TODO | 2197 | .UNDEFINED => 0, // TODO |
| ... | @@ -2216,7 +2216,7 @@ fn logSymtab(self: *Coff) void { | ... | @@ -2216,7 +2216,7 @@ fn logSymtab(self: *Coff) void { |
| 2216 | } | 2216 | } |
| 2217 | 2217 | ||
| 2218 | log.debug("GOT entries:", .{}); | 2218 | log.debug("GOT entries:", .{}); |
| 2219 | for (self.got_entries.items) |entry, i| { | 2219 | for (self.got_entries.items, 0..) |entry, i| { |
| 2220 | const got_sym = self.getSymbol(.{ .sym_index = entry.sym_index, .file = null }); | 2220 | const got_sym = self.getSymbol(.{ .sym_index = entry.sym_index, .file = null }); |
| 2221 | const target_sym = self.getSymbol(entry.target); | 2221 | const target_sym = self.getSymbol(entry.target); |
| 2222 | if (target_sym.section_number == .UNDEFINED) { | 2222 | if (target_sym.section_number == .UNDEFINED) { |
src/link/Dwarf.zig+5-5| ... | @@ -339,7 +339,7 @@ pub const DeclState = struct { | ... | @@ -339,7 +339,7 @@ pub const DeclState = struct { |
| 339 | try dbg_info_buffer.writer().print("{}\x00", .{ty.fmt(module)}); | 339 | try dbg_info_buffer.writer().print("{}\x00", .{ty.fmt(module)}); |
| 340 | 340 | ||
| 341 | const fields = ty.tupleFields(); | 341 | const fields = ty.tupleFields(); |
| 342 | for (fields.types) |field, field_index| { | 342 | for (fields.types, 0..) |field, field_index| { |
| 343 | // DW.AT.member | 343 | // DW.AT.member |
| 344 | try dbg_info_buffer.append(@enumToInt(AbbrevKind.struct_member)); | 344 | try dbg_info_buffer.append(@enumToInt(AbbrevKind.struct_member)); |
| 345 | // DW.AT.name, DW.FORM.string | 345 | // DW.AT.name, DW.FORM.string |
| ... | @@ -367,7 +367,7 @@ pub const DeclState = struct { | ... | @@ -367,7 +367,7 @@ pub const DeclState = struct { |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | const fields = ty.structFields(); | 369 | const fields = ty.structFields(); |
| 370 | for (fields.keys()) |field_name, field_index| { | 370 | for (fields.keys(), 0..) |field_name, field_index| { |
| 371 | const field = fields.get(field_name).?; | 371 | const field = fields.get(field_name).?; |
| 372 | if (!field.ty.hasRuntimeBits()) continue; | 372 | if (!field.ty.hasRuntimeBits()) continue; |
| 373 | // DW.AT.member | 373 | // DW.AT.member |
| ... | @@ -409,7 +409,7 @@ pub const DeclState = struct { | ... | @@ -409,7 +409,7 @@ pub const DeclState = struct { |
| 409 | .enum_numbered => ty.castTag(.enum_numbered).?.data.values, | 409 | .enum_numbered => ty.castTag(.enum_numbered).?.data.values, |
| 410 | else => unreachable, | 410 | else => unreachable, |
| 411 | }; | 411 | }; |
| 412 | for (fields.keys()) |field_name, field_i| { | 412 | for (fields.keys(), 0..) |field_name, field_i| { |
| 413 | // DW.AT.enumerator | 413 | // DW.AT.enumerator |
| 414 | try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2 + @sizeOf(u64)); | 414 | try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2 + @sizeOf(u64)); |
| 415 | dbg_info_buffer.appendAssumeCapacity(@enumToInt(AbbrevKind.enum_variant)); | 415 | dbg_info_buffer.appendAssumeCapacity(@enumToInt(AbbrevKind.enum_variant)); |
| ... | @@ -2252,14 +2252,14 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void { | ... | @@ -2252,14 +2252,14 @@ pub fn writeDbgLineHeader(self: *Dwarf) !void { |
| 2252 | 1, // `DW.LNS.set_isa` | 2252 | 1, // `DW.LNS.set_isa` |
| 2253 | }); | 2253 | }); |
| 2254 | 2254 | ||
| 2255 | for (paths.dirs) |dir, i| { | 2255 | for (paths.dirs, 0..) |dir, i| { |
| 2256 | log.debug("adding new include dir at {d} of '{s}'", .{ i + 1, dir }); | 2256 | log.debug("adding new include dir at {d} of '{s}'", .{ i + 1, dir }); |
| 2257 | di_buf.appendSliceAssumeCapacity(dir); | 2257 | di_buf.appendSliceAssumeCapacity(dir); |
| 2258 | di_buf.appendAssumeCapacity(0); | 2258 | di_buf.appendAssumeCapacity(0); |
| 2259 | } | 2259 | } |
| 2260 | di_buf.appendAssumeCapacity(0); // include directories sentinel | 2260 | di_buf.appendAssumeCapacity(0); // include directories sentinel |
| 2261 | 2261 | ||
| 2262 | for (paths.files) |file, i| { | 2262 | for (paths.files, 0..) |file, i| { |
| 2263 | const dir_index = paths.files_dirs_indexes[i]; | 2263 | const dir_index = paths.files_dirs_indexes[i]; |
| 2264 | log.debug("adding new file name at {d} of '{s}' referencing directory {d}", .{ i + 1, file, dir_index + 1 }); | 2264 | log.debug("adding new file name at {d} of '{s}' referencing directory {d}", .{ i + 1, file, dir_index + 1 }); |
| 2265 | di_buf.appendSliceAssumeCapacity(file); | 2265 | di_buf.appendSliceAssumeCapacity(file); |
src/link/Elf.zig+9-9| ... | @@ -1126,7 +1126,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1126,7 +1126,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1126 | const buf = try gpa.alloc(elf.Elf32_Phdr, self.program_headers.items.len); | 1126 | const buf = try gpa.alloc(elf.Elf32_Phdr, self.program_headers.items.len); |
| 1127 | defer gpa.free(buf); | 1127 | defer gpa.free(buf); |
| 1128 | 1128 | ||
| 1129 | for (buf) |*phdr, i| { | 1129 | for (buf, 0..) |*phdr, i| { |
| 1130 | phdr.* = progHeaderTo32(self.program_headers.items[i]); | 1130 | phdr.* = progHeaderTo32(self.program_headers.items[i]); |
| 1131 | if (foreign_endian) { | 1131 | if (foreign_endian) { |
| 1132 | mem.byteSwapAllFields(elf.Elf32_Phdr, phdr); | 1132 | mem.byteSwapAllFields(elf.Elf32_Phdr, phdr); |
| ... | @@ -1138,7 +1138,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1138,7 +1138,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1138 | const buf = try gpa.alloc(elf.Elf64_Phdr, self.program_headers.items.len); | 1138 | const buf = try gpa.alloc(elf.Elf64_Phdr, self.program_headers.items.len); |
| 1139 | defer gpa.free(buf); | 1139 | defer gpa.free(buf); |
| 1140 | 1140 | ||
| 1141 | for (buf) |*phdr, i| { | 1141 | for (buf, 0..) |*phdr, i| { |
| 1142 | phdr.* = self.program_headers.items[i]; | 1142 | phdr.* = self.program_headers.items[i]; |
| 1143 | if (foreign_endian) { | 1143 | if (foreign_endian) { |
| 1144 | mem.byteSwapAllFields(elf.Elf64_Phdr, phdr); | 1144 | mem.byteSwapAllFields(elf.Elf64_Phdr, phdr); |
| ... | @@ -1193,7 +1193,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1193,7 +1193,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1193 | const buf = try gpa.alloc(elf.Elf32_Shdr, slice.len); | 1193 | const buf = try gpa.alloc(elf.Elf32_Shdr, slice.len); |
| 1194 | defer gpa.free(buf); | 1194 | defer gpa.free(buf); |
| 1195 | 1195 | ||
| 1196 | for (buf) |*shdr, i| { | 1196 | for (buf, 0..) |*shdr, i| { |
| 1197 | shdr.* = sectHeaderTo32(slice.items(.shdr)[i]); | 1197 | shdr.* = sectHeaderTo32(slice.items(.shdr)[i]); |
| 1198 | log.debug("writing section {?s}: {}", .{ self.shstrtab.get(shdr.sh_name), shdr.* }); | 1198 | log.debug("writing section {?s}: {}", .{ self.shstrtab.get(shdr.sh_name), shdr.* }); |
| 1199 | if (foreign_endian) { | 1199 | if (foreign_endian) { |
| ... | @@ -1207,7 +1207,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1207,7 +1207,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1207 | const buf = try gpa.alloc(elf.Elf64_Shdr, slice.len); | 1207 | const buf = try gpa.alloc(elf.Elf64_Shdr, slice.len); |
| 1208 | defer gpa.free(buf); | 1208 | defer gpa.free(buf); |
| 1209 | 1209 | ||
| 1210 | for (buf) |*shdr, i| { | 1210 | for (buf, 0..) |*shdr, i| { |
| 1211 | shdr.* = slice.items(.shdr)[i]; | 1211 | shdr.* = slice.items(.shdr)[i]; |
| 1212 | log.debug("writing section {?s}: {}", .{ self.shstrtab.get(shdr.sh_name), shdr.* }); | 1212 | log.debug("writing section {?s}: {}", .{ self.shstrtab.get(shdr.sh_name), shdr.* }); |
| 1213 | if (foreign_endian) { | 1213 | if (foreign_endian) { |
| ... | @@ -1732,7 +1732,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v | ... | @@ -1732,7 +1732,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v |
| 1732 | argv.appendAssumeCapacity("--as-needed"); | 1732 | argv.appendAssumeCapacity("--as-needed"); |
| 1733 | var as_needed = true; | 1733 | var as_needed = true; |
| 1734 | 1734 | ||
| 1735 | for (system_libs) |link_lib, i| { | 1735 | for (system_libs, 0..) |link_lib, i| { |
| 1736 | const lib_as_needed = !system_libs_values[i].needed; | 1736 | const lib_as_needed = !system_libs_values[i].needed; |
| 1737 | switch ((@as(u2, @boolToInt(lib_as_needed)) << 1) | @boolToInt(as_needed)) { | 1737 | switch ((@as(u2, @boolToInt(lib_as_needed)) << 1) | @boolToInt(as_needed)) { |
| 1738 | 0b00, 0b11 => {}, | 1738 | 0b00, 0b11 => {}, |
| ... | @@ -2909,7 +2909,7 @@ fn writeAllGlobalSymbols(self: *Elf) !void { | ... | @@ -2909,7 +2909,7 @@ fn writeAllGlobalSymbols(self: *Elf) !void { |
| 2909 | const buf = try self.base.allocator.alloc(elf.Elf32_Sym, self.global_symbols.items.len); | 2909 | const buf = try self.base.allocator.alloc(elf.Elf32_Sym, self.global_symbols.items.len); |
| 2910 | defer self.base.allocator.free(buf); | 2910 | defer self.base.allocator.free(buf); |
| 2911 | 2911 | ||
| 2912 | for (buf) |*sym, i| { | 2912 | for (buf, 0..) |*sym, i| { |
| 2913 | const global = self.global_symbols.items[i]; | 2913 | const global = self.global_symbols.items[i]; |
| 2914 | sym.* = .{ | 2914 | sym.* = .{ |
| 2915 | .st_name = global.st_name, | 2915 | .st_name = global.st_name, |
| ... | @@ -2929,7 +2929,7 @@ fn writeAllGlobalSymbols(self: *Elf) !void { | ... | @@ -2929,7 +2929,7 @@ fn writeAllGlobalSymbols(self: *Elf) !void { |
| 2929 | const buf = try self.base.allocator.alloc(elf.Elf64_Sym, self.global_symbols.items.len); | 2929 | const buf = try self.base.allocator.alloc(elf.Elf64_Sym, self.global_symbols.items.len); |
| 2930 | defer self.base.allocator.free(buf); | 2930 | defer self.base.allocator.free(buf); |
| 2931 | 2931 | ||
| 2932 | for (buf) |*sym, i| { | 2932 | for (buf, 0..) |*sym, i| { |
| 2933 | const global = self.global_symbols.items[i]; | 2933 | const global = self.global_symbols.items[i]; |
| 2934 | sym.* = .{ | 2934 | sym.* = .{ |
| 2935 | .st_name = global.st_name, | 2935 | .st_name = global.st_name, |
| ... | @@ -3238,11 +3238,11 @@ const CsuObjects = struct { | ... | @@ -3238,11 +3238,11 @@ const CsuObjects = struct { |
| 3238 | 3238 | ||
| 3239 | fn logSymtab(self: Elf) void { | 3239 | fn logSymtab(self: Elf) void { |
| 3240 | log.debug("locals:", .{}); | 3240 | log.debug("locals:", .{}); |
| 3241 | for (self.local_symbols.items) |sym, id| { | 3241 | for (self.local_symbols.items, 0..) |sym, id| { |
| 3242 | log.debug(" {d}: {?s}: @{x} in {d}", .{ id, self.shstrtab.get(sym.st_name), sym.st_value, sym.st_shndx }); | 3242 | log.debug(" {d}: {?s}: @{x} in {d}", .{ id, self.shstrtab.get(sym.st_name), sym.st_value, sym.st_shndx }); |
| 3243 | } | 3243 | } |
| 3244 | log.debug("globals:", .{}); | 3244 | log.debug("globals:", .{}); |
| 3245 | for (self.global_symbols.items) |sym, id| { | 3245 | for (self.global_symbols.items, 0..) |sym, id| { |
| 3246 | log.debug(" {d}: {?s}: @{x} in {d}", .{ id, self.shstrtab.get(sym.st_name), sym.st_value, sym.st_shndx }); | 3246 | log.debug(" {d}: {?s}: @{x} in {d}", .{ id, self.shstrtab.get(sym.st_name), sym.st_value, sym.st_shndx }); |
| 3247 | } | 3247 | } |
| 3248 | } | 3248 | } |
src/link/MachO.zig+18-18| ... | @@ -962,7 +962,7 @@ pub fn parseLibs( | ... | @@ -962,7 +962,7 @@ pub fn parseLibs( |
| 962 | syslibroot: ?[]const u8, | 962 | syslibroot: ?[]const u8, |
| 963 | dependent_libs: anytype, | 963 | dependent_libs: anytype, |
| 964 | ) !void { | 964 | ) !void { |
| 965 | for (lib_names) |lib, i| { | 965 | for (lib_names, 0..) |lib, i| { |
| 966 | const lib_info = lib_infos[i]; | 966 | const lib_info = lib_infos[i]; |
| 967 | log.debug("parsing lib path '{s}'", .{lib}); | 967 | log.debug("parsing lib path '{s}'", .{lib}); |
| 968 | if (try self.parseDylib(lib, dependent_libs, .{ | 968 | if (try self.parseDylib(lib, dependent_libs, .{ |
| ... | @@ -1584,7 +1584,7 @@ pub fn resolveSymbolsInDylibs(self: *MachO) !void { | ... | @@ -1584,7 +1584,7 @@ pub fn resolveSymbolsInDylibs(self: *MachO) !void { |
| 1584 | const sym = self.getSymbolPtr(global); | 1584 | const sym = self.getSymbolPtr(global); |
| 1585 | const sym_name = self.getSymbolName(global); | 1585 | const sym_name = self.getSymbolName(global); |
| 1586 | 1586 | ||
| 1587 | for (self.dylibs.items) |dylib, id| { | 1587 | for (self.dylibs.items, 0..) |dylib, id| { |
| 1588 | if (!dylib.symbols.contains(sym_name)) continue; | 1588 | if (!dylib.symbols.contains(sym_name)) continue; |
| 1589 | 1589 | ||
| 1590 | const dylib_id = @intCast(u16, id); | 1590 | const dylib_id = @intCast(u16, id); |
| ... | @@ -1686,7 +1686,7 @@ pub fn resolveDyldStubBinder(self: *MachO) !void { | ... | @@ -1686,7 +1686,7 @@ pub fn resolveDyldStubBinder(self: *MachO) !void { |
| 1686 | gop.value_ptr.* = sym_loc; | 1686 | gop.value_ptr.* = sym_loc; |
| 1687 | const global = gop.value_ptr.*; | 1687 | const global = gop.value_ptr.*; |
| 1688 | 1688 | ||
| 1689 | for (self.dylibs.items) |dylib, id| { | 1689 | for (self.dylibs.items, 0..) |dylib, id| { |
| 1690 | if (!dylib.symbols.contains(sym_name)) continue; | 1690 | if (!dylib.symbols.contains(sym_name)) continue; |
| 1691 | 1691 | ||
| 1692 | const dylib_id = @intCast(u16, id); | 1692 | const dylib_id = @intCast(u16, id); |
| ... | @@ -2852,7 +2852,7 @@ fn moveSectionInVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void | ... | @@ -2852,7 +2852,7 @@ fn moveSectionInVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void |
| 2852 | }); | 2852 | }); |
| 2853 | 2853 | ||
| 2854 | // TODO: enforce order by increasing VM addresses in self.sections container. | 2854 | // TODO: enforce order by increasing VM addresses in self.sections container. |
| 2855 | for (self.sections.items(.header)[sect_id + 1 ..]) |*next_header, next_sect_id| { | 2855 | for (self.sections.items(.header)[sect_id + 1 ..], 0..) |*next_header, next_sect_id| { |
| 2856 | const index = @intCast(u8, sect_id + 1 + next_sect_id); | 2856 | const index = @intCast(u8, sect_id + 1 + next_sect_id); |
| 2857 | const next_segment = self.getSegmentPtr(index); | 2857 | const next_segment = self.getSegmentPtr(index); |
| 2858 | next_header.addr += diff; | 2858 | next_header.addr += diff; |
| ... | @@ -3082,7 +3082,7 @@ pub fn initSection(self: *MachO, segname: []const u8, sectname: []const u8, opts | ... | @@ -3082,7 +3082,7 @@ pub fn initSection(self: *MachO, segname: []const u8, sectname: []const u8, opts |
| 3082 | fn insertSection(self: *MachO, segment_index: u8, header: macho.section_64) !u8 { | 3082 | fn insertSection(self: *MachO, segment_index: u8, header: macho.section_64) !u8 { |
| 3083 | const precedence = getSectionPrecedence(header); | 3083 | const precedence = getSectionPrecedence(header); |
| 3084 | const indexes = self.getSectionIndexes(segment_index); | 3084 | const indexes = self.getSectionIndexes(segment_index); |
| 3085 | const insertion_index = for (self.sections.items(.header)[indexes.start..indexes.end]) |hdr, i| { | 3085 | const insertion_index = for (self.sections.items(.header)[indexes.start..indexes.end], 0..) |hdr, i| { |
| 3086 | if (getSectionPrecedence(hdr) > precedence) break @intCast(u8, i + indexes.start); | 3086 | if (getSectionPrecedence(hdr) > precedence) break @intCast(u8, i + indexes.start); |
| 3087 | } else indexes.end; | 3087 | } else indexes.end; |
| 3088 | log.debug("inserting section '{s},{s}' at index {d}", .{ | 3088 | log.debug("inserting section '{s},{s}' at index {d}", .{ |
| ... | @@ -3133,7 +3133,7 @@ pub fn getGlobalSymbol(self: *MachO, name: []const u8) !u32 { | ... | @@ -3133,7 +3133,7 @@ pub fn getGlobalSymbol(self: *MachO, name: []const u8) !u32 { |
| 3133 | } | 3133 | } |
| 3134 | 3134 | ||
| 3135 | fn writeSegmentHeaders(self: *MachO, writer: anytype) !void { | 3135 | fn writeSegmentHeaders(self: *MachO, writer: anytype) !void { |
| 3136 | for (self.segments.items) |seg, i| { | 3136 | for (self.segments.items, 0..) |seg, i| { |
| 3137 | const indexes = self.getSectionIndexes(@intCast(u8, i)); | 3137 | const indexes = self.getSectionIndexes(@intCast(u8, i)); |
| 3138 | try writer.writeStruct(seg); | 3138 | try writer.writeStruct(seg); |
| 3139 | for (self.sections.items(.header)[indexes.start..indexes.end]) |header| { | 3139 | for (self.sections.items(.header)[indexes.start..indexes.end]) |header| { |
| ... | @@ -3147,7 +3147,7 @@ fn writeLinkeditSegmentData(self: *MachO) !void { | ... | @@ -3147,7 +3147,7 @@ fn writeLinkeditSegmentData(self: *MachO) !void { |
| 3147 | seg.filesize = 0; | 3147 | seg.filesize = 0; |
| 3148 | seg.vmsize = 0; | 3148 | seg.vmsize = 0; |
| 3149 | 3149 | ||
| 3150 | for (self.segments.items) |segment, id| { | 3150 | for (self.segments.items, 0..) |segment, id| { |
| 3151 | if (self.linkedit_segment_cmd_index.? == @intCast(u8, id)) continue; | 3151 | if (self.linkedit_segment_cmd_index.? == @intCast(u8, id)) continue; |
| 3152 | if (seg.vmaddr < segment.vmaddr + segment.vmsize) { | 3152 | if (seg.vmaddr < segment.vmaddr + segment.vmsize) { |
| 3153 | seg.vmaddr = mem.alignForwardGeneric(u64, segment.vmaddr + segment.vmsize, self.page_size); | 3153 | seg.vmaddr = mem.alignForwardGeneric(u64, segment.vmaddr + segment.vmsize, self.page_size); |
| ... | @@ -3167,7 +3167,7 @@ fn collectRebaseData(self: *MachO, rebase: *Rebase) !void { | ... | @@ -3167,7 +3167,7 @@ fn collectRebaseData(self: *MachO, rebase: *Rebase) !void { |
| 3167 | const gpa = self.base.allocator; | 3167 | const gpa = self.base.allocator; |
| 3168 | const slice = self.sections.slice(); | 3168 | const slice = self.sections.slice(); |
| 3169 | 3169 | ||
| 3170 | for (self.rebases.keys()) |atom_index, i| { | 3170 | for (self.rebases.keys(), 0..) |atom_index, i| { |
| 3171 | const atom = self.getAtom(atom_index); | 3171 | const atom = self.getAtom(atom_index); |
| 3172 | log.debug(" ATOM(%{?d}, '{s}')", .{ atom.getSymbolIndex(), atom.getName(self) }); | 3172 | log.debug(" ATOM(%{?d}, '{s}')", .{ atom.getSymbolIndex(), atom.getName(self) }); |
| 3173 | 3173 | ||
| ... | @@ -3197,7 +3197,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { | ... | @@ -3197,7 +3197,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void { |
| 3197 | const gpa = self.base.allocator; | 3197 | const gpa = self.base.allocator; |
| 3198 | const slice = self.sections.slice(); | 3198 | const slice = self.sections.slice(); |
| 3199 | 3199 | ||
| 3200 | for (raw_bindings.keys()) |atom_index, i| { | 3200 | for (raw_bindings.keys(), 0..) |atom_index, i| { |
| 3201 | const atom = self.getAtom(atom_index); | 3201 | const atom = self.getAtom(atom_index); |
| 3202 | log.debug(" ATOM(%{?d}, '{s}')", .{ atom.getSymbolIndex(), atom.getName(self) }); | 3202 | log.debug(" ATOM(%{?d}, '{s}')", .{ atom.getSymbolIndex(), atom.getName(self) }); |
| 3203 | 3203 | ||
| ... | @@ -3417,7 +3417,7 @@ fn writeSymtab(self: *MachO) !SymtabCtx { | ... | @@ -3417,7 +3417,7 @@ fn writeSymtab(self: *MachO) !SymtabCtx { |
| 3417 | var locals = std.ArrayList(macho.nlist_64).init(gpa); | 3417 | var locals = std.ArrayList(macho.nlist_64).init(gpa); |
| 3418 | defer locals.deinit(); | 3418 | defer locals.deinit(); |
| 3419 | 3419 | ||
| 3420 | for (self.locals.items) |sym, sym_id| { | 3420 | for (self.locals.items, 0..) |sym, sym_id| { |
| 3421 | if (sym.n_strx == 0) continue; // no name, skip | 3421 | if (sym.n_strx == 0) continue; // no name, skip |
| 3422 | const sym_loc = SymbolWithLoc{ .sym_index = @intCast(u32, sym_id), .file = null }; | 3422 | const sym_loc = SymbolWithLoc{ .sym_index = @intCast(u32, sym_id), .file = null }; |
| 3423 | if (self.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip | 3423 | if (self.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip |
| ... | @@ -3736,7 +3736,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 { | ... | @@ -3736,7 +3736,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 { |
| 3736 | } | 3736 | } |
| 3737 | 3737 | ||
| 3738 | fn getSegmentByName(self: MachO, segname: []const u8) ?u8 { | 3738 | fn getSegmentByName(self: MachO, segname: []const u8) ?u8 { |
| 3739 | for (self.segments.items) |seg, i| { | 3739 | for (self.segments.items, 0..) |seg, i| { |
| 3740 | if (mem.eql(u8, segname, seg.segName())) return @intCast(u8, i); | 3740 | if (mem.eql(u8, segname, seg.segName())) return @intCast(u8, i); |
| 3741 | } else return null; | 3741 | } else return null; |
| 3742 | } | 3742 | } |
| ... | @@ -3758,7 +3758,7 @@ pub fn getLinkeditSegmentPtr(self: *MachO) *macho.segment_command_64 { | ... | @@ -3758,7 +3758,7 @@ pub fn getLinkeditSegmentPtr(self: *MachO) *macho.segment_command_64 { |
| 3758 | 3758 | ||
| 3759 | pub fn getSectionByName(self: MachO, segname: []const u8, sectname: []const u8) ?u8 { | 3759 | pub fn getSectionByName(self: MachO, segname: []const u8, sectname: []const u8) ?u8 { |
| 3760 | // TODO investigate caching with a hashmap | 3760 | // TODO investigate caching with a hashmap |
| 3761 | for (self.sections.items(.header)) |header, i| { | 3761 | for (self.sections.items(.header), 0..) |header, i| { |
| 3762 | if (mem.eql(u8, header.segName(), segname) and mem.eql(u8, header.sectName(), sectname)) | 3762 | if (mem.eql(u8, header.segName(), segname) and mem.eql(u8, header.sectName(), sectname)) |
| 3763 | return @intCast(u8, i); | 3763 | return @intCast(u8, i); |
| 3764 | } else return null; | 3764 | } else return null; |
| ... | @@ -3766,7 +3766,7 @@ pub fn getSectionByName(self: MachO, segname: []const u8, sectname: []const u8) | ... | @@ -3766,7 +3766,7 @@ pub fn getSectionByName(self: MachO, segname: []const u8, sectname: []const u8) |
| 3766 | 3766 | ||
| 3767 | pub fn getSectionIndexes(self: MachO, segment_index: u8) struct { start: u8, end: u8 } { | 3767 | pub fn getSectionIndexes(self: MachO, segment_index: u8) struct { start: u8, end: u8 } { |
| 3768 | var start: u8 = 0; | 3768 | var start: u8 = 0; |
| 3769 | const nsects = for (self.segments.items) |seg, i| { | 3769 | const nsects = for (self.segments.items, 0..) |seg, i| { |
| 3770 | if (i == segment_index) break @intCast(u8, seg.nsects); | 3770 | if (i == segment_index) break @intCast(u8, seg.nsects); |
| 3771 | start += @intCast(u8, seg.nsects); | 3771 | start += @intCast(u8, seg.nsects); |
| 3772 | } else 0; | 3772 | } else 0; |
| ... | @@ -4160,7 +4160,7 @@ pub fn findFirst(comptime T: type, haystack: []align(1) const T, start: usize, p | ... | @@ -4160,7 +4160,7 @@ pub fn findFirst(comptime T: type, haystack: []align(1) const T, start: usize, p |
| 4160 | 4160 | ||
| 4161 | pub fn logSections(self: *MachO) void { | 4161 | pub fn logSections(self: *MachO) void { |
| 4162 | log.debug("sections:", .{}); | 4162 | log.debug("sections:", .{}); |
| 4163 | for (self.sections.items(.header)) |header, i| { | 4163 | for (self.sections.items(.header), 0..) |header, i| { |
| 4164 | log.debug(" sect({d}): {s},{s} @{x}, sizeof({x})", .{ | 4164 | log.debug(" sect({d}): {s},{s} @{x}, sizeof({x})", .{ |
| 4165 | i + 1, | 4165 | i + 1, |
| 4166 | header.segName(), | 4166 | header.segName(), |
| ... | @@ -4197,7 +4197,7 @@ pub fn logSymtab(self: *MachO) void { | ... | @@ -4197,7 +4197,7 @@ pub fn logSymtab(self: *MachO) void { |
| 4197 | var buf: [4]u8 = undefined; | 4197 | var buf: [4]u8 = undefined; |
| 4198 | 4198 | ||
| 4199 | log.debug("symtab:", .{}); | 4199 | log.debug("symtab:", .{}); |
| 4200 | for (self.locals.items) |sym, sym_id| { | 4200 | for (self.locals.items, 0..) |sym, sym_id| { |
| 4201 | const where = if (sym.undf() and !sym.tentative()) "ord" else "sect"; | 4201 | const where = if (sym.undf() and !sym.tentative()) "ord" else "sect"; |
| 4202 | const def_index = if (sym.undf() and !sym.tentative()) | 4202 | const def_index = if (sym.undf() and !sym.tentative()) |
| 4203 | @divTrunc(sym.n_desc, macho.N_SYMBOL_RESOLVER) | 4203 | @divTrunc(sym.n_desc, macho.N_SYMBOL_RESOLVER) |
| ... | @@ -4220,7 +4220,7 @@ pub fn logSymtab(self: *MachO) void { | ... | @@ -4220,7 +4220,7 @@ pub fn logSymtab(self: *MachO) void { |
| 4220 | } | 4220 | } |
| 4221 | 4221 | ||
| 4222 | log.debug("GOT entries:", .{}); | 4222 | log.debug("GOT entries:", .{}); |
| 4223 | for (self.got_entries.items) |entry, i| { | 4223 | for (self.got_entries.items, 0..) |entry, i| { |
| 4224 | const atom_sym = entry.getSymbol(self); | 4224 | const atom_sym = entry.getSymbol(self); |
| 4225 | const target_sym = self.getSymbol(entry.target); | 4225 | const target_sym = self.getSymbol(entry.target); |
| 4226 | if (target_sym.undf()) { | 4226 | if (target_sym.undf()) { |
| ... | @@ -4241,7 +4241,7 @@ pub fn logSymtab(self: *MachO) void { | ... | @@ -4241,7 +4241,7 @@ pub fn logSymtab(self: *MachO) void { |
| 4241 | } | 4241 | } |
| 4242 | 4242 | ||
| 4243 | log.debug("stubs entries:", .{}); | 4243 | log.debug("stubs entries:", .{}); |
| 4244 | for (self.stubs.items) |entry, i| { | 4244 | for (self.stubs.items, 0..) |entry, i| { |
| 4245 | const target_sym = self.getSymbol(entry.target); | 4245 | const target_sym = self.getSymbol(entry.target); |
| 4246 | const atom_sym = entry.getSymbol(self); | 4246 | const atom_sym = entry.getSymbol(self); |
| 4247 | assert(target_sym.undf()); | 4247 | assert(target_sym.undf()); |
| ... | @@ -4257,7 +4257,7 @@ pub fn logAtoms(self: *MachO) void { | ... | @@ -4257,7 +4257,7 @@ pub fn logAtoms(self: *MachO) void { |
| 4257 | log.debug("atoms:", .{}); | 4257 | log.debug("atoms:", .{}); |
| 4258 | 4258 | ||
| 4259 | const slice = self.sections.slice(); | 4259 | const slice = self.sections.slice(); |
| 4260 | for (slice.items(.last_atom_index)) |last_atom_index, i| { | 4260 | for (slice.items(.last_atom_index), 0..) |last_atom_index, i| { |
| 4261 | var atom_index = last_atom_index orelse continue; | 4261 | var atom_index = last_atom_index orelse continue; |
| 4262 | const header = slice.items(.header)[i]; | 4262 | const header = slice.items(.header)[i]; |
| 4263 | 4263 |
src/link/MachO/DebugSymbols.zig+4-4| ... | @@ -383,7 +383,7 @@ fn finalizeDwarfSegment(self: *DebugSymbols, macho_file: *MachO) void { | ... | @@ -383,7 +383,7 @@ fn finalizeDwarfSegment(self: *DebugSymbols, macho_file: *MachO) void { |
| 383 | fn writeSegmentHeaders(self: *DebugSymbols, macho_file: *MachO, writer: anytype) !void { | 383 | fn writeSegmentHeaders(self: *DebugSymbols, macho_file: *MachO, writer: anytype) !void { |
| 384 | // Write segment/section headers from the binary file first. | 384 | // Write segment/section headers from the binary file first. |
| 385 | const end = macho_file.linkedit_segment_cmd_index.?; | 385 | const end = macho_file.linkedit_segment_cmd_index.?; |
| 386 | for (macho_file.segments.items[0..end]) |seg, i| { | 386 | for (macho_file.segments.items[0..end], 0..) |seg, i| { |
| 387 | const indexes = macho_file.getSectionIndexes(@intCast(u8, i)); | 387 | const indexes = macho_file.getSectionIndexes(@intCast(u8, i)); |
| 388 | var out_seg = seg; | 388 | var out_seg = seg; |
| 389 | out_seg.fileoff = 0; | 389 | out_seg.fileoff = 0; |
| ... | @@ -412,7 +412,7 @@ fn writeSegmentHeaders(self: *DebugSymbols, macho_file: *MachO, writer: anytype) | ... | @@ -412,7 +412,7 @@ fn writeSegmentHeaders(self: *DebugSymbols, macho_file: *MachO, writer: anytype) |
| 412 | } | 412 | } |
| 413 | } | 413 | } |
| 414 | // Next, commit DSYM's __LINKEDIT and __DWARF segments headers. | 414 | // Next, commit DSYM's __LINKEDIT and __DWARF segments headers. |
| 415 | for (self.segments.items) |seg, i| { | 415 | for (self.segments.items, 0..) |seg, i| { |
| 416 | const indexes = self.getSectionIndexes(@intCast(u8, i)); | 416 | const indexes = self.getSectionIndexes(@intCast(u8, i)); |
| 417 | try writer.writeStruct(seg); | 417 | try writer.writeStruct(seg); |
| 418 | for (self.sections.items[indexes.start..indexes.end]) |header| { | 418 | for (self.sections.items[indexes.start..indexes.end]) |header| { |
| ... | @@ -477,7 +477,7 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void { | ... | @@ -477,7 +477,7 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void { |
| 477 | var locals = std.ArrayList(macho.nlist_64).init(gpa); | 477 | var locals = std.ArrayList(macho.nlist_64).init(gpa); |
| 478 | defer locals.deinit(); | 478 | defer locals.deinit(); |
| 479 | 479 | ||
| 480 | for (macho_file.locals.items) |sym, sym_id| { | 480 | for (macho_file.locals.items, 0..) |sym, sym_id| { |
| 481 | if (sym.n_strx == 0) continue; // no name, skip | 481 | if (sym.n_strx == 0) continue; // no name, skip |
| 482 | const sym_loc = MachO.SymbolWithLoc{ .sym_index = @intCast(u32, sym_id), .file = null }; | 482 | const sym_loc = MachO.SymbolWithLoc{ .sym_index = @intCast(u32, sym_id), .file = null }; |
| 483 | if (macho_file.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip | 483 | if (macho_file.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip |
| ... | @@ -547,7 +547,7 @@ fn writeStrtab(self: *DebugSymbols) !void { | ... | @@ -547,7 +547,7 @@ fn writeStrtab(self: *DebugSymbols) !void { |
| 547 | 547 | ||
| 548 | pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start: u8, end: u8 } { | 548 | pub fn getSectionIndexes(self: *DebugSymbols, segment_index: u8) struct { start: u8, end: u8 } { |
| 549 | var start: u8 = 0; | 549 | var start: u8 = 0; |
| 550 | const nsects = for (self.segments.items) |seg, i| { | 550 | const nsects = for (self.segments.items, 0..) |seg, i| { |
| 551 | if (i == segment_index) break @intCast(u8, seg.nsects); | 551 | if (i == segment_index) break @intCast(u8, seg.nsects); |
| 552 | start += @intCast(u8, seg.nsects); | 552 | start += @intCast(u8, seg.nsects); |
| 553 | } else 0; | 553 | } else 0; |
src/link/MachO/Dylib.zig+1-1| ... | @@ -347,7 +347,7 @@ pub fn parseFromStub( | ... | @@ -347,7 +347,7 @@ pub fn parseFromStub( |
| 347 | }); | 347 | }); |
| 348 | defer matcher.deinit(); | 348 | defer matcher.deinit(); |
| 349 | 349 | ||
| 350 | for (lib_stub.inner) |elem, stub_index| { | 350 | for (lib_stub.inner, 0..) |elem, stub_index| { |
| 351 | const is_match = switch (elem) { | 351 | const is_match = switch (elem) { |
| 352 | .v3 => |stub| matcher.matchesArch(stub.archs), | 352 | .v3 => |stub| matcher.matchesArch(stub.archs), |
| 353 | .v4 => |stub| matcher.matchesTarget(stub.targets), | 353 | .v4 => |stub| matcher.matchesTarget(stub.targets), |
src/link/MachO/Object.zig+7-7| ... | @@ -201,7 +201,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) | ... | @@ -201,7 +201,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) |
| 201 | var sorted_all_syms = try std.ArrayList(SymbolAtIndex).initCapacity(allocator, self.in_symtab.?.len); | 201 | var sorted_all_syms = try std.ArrayList(SymbolAtIndex).initCapacity(allocator, self.in_symtab.?.len); |
| 202 | defer sorted_all_syms.deinit(); | 202 | defer sorted_all_syms.deinit(); |
| 203 | 203 | ||
| 204 | for (self.in_symtab.?) |_, index| { | 204 | for (self.in_symtab.?, 0..) |_, index| { |
| 205 | sorted_all_syms.appendAssumeCapacity(.{ .index = @intCast(u32, index) }); | 205 | sorted_all_syms.appendAssumeCapacity(.{ .index = @intCast(u32, index) }); |
| 206 | } | 206 | } |
| 207 | 207 | ||
| ... | @@ -211,7 +211,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) | ... | @@ -211,7 +211,7 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) |
| 211 | // is kind enough to specify the symbols in the correct order. | 211 | // is kind enough to specify the symbols in the correct order. |
| 212 | sort.sort(SymbolAtIndex, sorted_all_syms.items, self, SymbolAtIndex.lessThan); | 212 | sort.sort(SymbolAtIndex, sorted_all_syms.items, self, SymbolAtIndex.lessThan); |
| 213 | 213 | ||
| 214 | for (sorted_all_syms.items) |sym_id, i| { | 214 | for (sorted_all_syms.items, 0..) |sym_id, i| { |
| 215 | const sym = sym_id.getSymbol(self); | 215 | const sym = sym_id.getSymbol(self); |
| 216 | 216 | ||
| 217 | if (sym.sect() and self.source_section_index_lookup[sym.n_sect - 1] == -1) { | 217 | if (sym.sect() and self.source_section_index_lookup[sym.n_sect - 1] == -1) { |
| ... | @@ -380,7 +380,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void { | ... | @@ -380,7 +380,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void { |
| 380 | const gpa = zld.gpa; | 380 | const gpa = zld.gpa; |
| 381 | 381 | ||
| 382 | const sections = self.getSourceSections(); | 382 | const sections = self.getSourceSections(); |
| 383 | for (sections) |sect, id| { | 383 | for (sections, 0..) |sect, id| { |
| 384 | if (sect.isDebug()) continue; | 384 | if (sect.isDebug()) continue; |
| 385 | const out_sect_id = (try zld.getOutputSection(sect)) orelse { | 385 | const out_sect_id = (try zld.getOutputSection(sect)) orelse { |
| 386 | log.debug(" unhandled section '{s},{s}'", .{ sect.segName(), sect.sectName() }); | 386 | log.debug(" unhandled section '{s},{s}'", .{ sect.segName(), sect.sectName() }); |
| ... | @@ -400,7 +400,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void { | ... | @@ -400,7 +400,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void { |
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | if (self.in_symtab == null) { | 402 | if (self.in_symtab == null) { |
| 403 | for (sections) |sect, id| { | 403 | for (sections, 0..) |sect, id| { |
| 404 | if (sect.isDebug()) continue; | 404 | if (sect.isDebug()) continue; |
| 405 | const out_sect_id = (try zld.getOutputSection(sect)) orelse continue; | 405 | const out_sect_id = (try zld.getOutputSection(sect)) orelse continue; |
| 406 | if (sect.size == 0) continue; | 406 | if (sect.size == 0) continue; |
| ... | @@ -446,7 +446,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void { | ... | @@ -446,7 +446,7 @@ pub fn splitRegularSections(self: *Object, zld: *Zld, object_id: u32) !void { |
| 446 | var sorted_sections = try gpa.alloc(SortedSection, sections.len); | 446 | var sorted_sections = try gpa.alloc(SortedSection, sections.len); |
| 447 | defer gpa.free(sorted_sections); | 447 | defer gpa.free(sorted_sections); |
| 448 | 448 | ||
| 449 | for (sections) |sect, id| { | 449 | for (sections, 0..) |sect, id| { |
| 450 | sorted_sections[id] = .{ .header = sect, .id = @intCast(u8, id) }; | 450 | sorted_sections[id] = .{ .header = sect, .id = @intCast(u8, id) }; |
| 451 | } | 451 | } |
| 452 | 452 | ||
| ... | @@ -804,7 +804,7 @@ fn parseUnwindInfo(self: *Object, zld: *Zld, object_id: u32) !void { | ... | @@ -804,7 +804,7 @@ fn parseUnwindInfo(self: *Object, zld: *Zld, object_id: u32) !void { |
| 804 | try self.parseRelocs(gpa, sect_id); | 804 | try self.parseRelocs(gpa, sect_id); |
| 805 | const relocs = self.getRelocs(sect_id); | 805 | const relocs = self.getRelocs(sect_id); |
| 806 | 806 | ||
| 807 | for (unwind_records) |record, record_id| { | 807 | for (unwind_records, 0..) |record, record_id| { |
| 808 | const offset = record_id * @sizeOf(macho.compact_unwind_entry); | 808 | const offset = record_id * @sizeOf(macho.compact_unwind_entry); |
| 809 | const rel_pos = filterRelocs( | 809 | const rel_pos = filterRelocs( |
| 810 | relocs, | 810 | relocs, |
| ... | @@ -857,7 +857,7 @@ pub fn getSourceSectionByName(self: Object, segname: []const u8, sectname: []con | ... | @@ -857,7 +857,7 @@ pub fn getSourceSectionByName(self: Object, segname: []const u8, sectname: []con |
| 857 | 857 | ||
| 858 | pub fn getSourceSectionIndexByName(self: Object, segname: []const u8, sectname: []const u8) ?u8 { | 858 | pub fn getSourceSectionIndexByName(self: Object, segname: []const u8, sectname: []const u8) ?u8 { |
| 859 | const sections = self.getSourceSections(); | 859 | const sections = self.getSourceSections(); |
| 860 | for (sections) |sect, i| { | 860 | for (sections, 0..) |sect, i| { |
| 861 | if (mem.eql(u8, segname, sect.segName()) and mem.eql(u8, sectname, sect.sectName())) | 861 | if (mem.eql(u8, segname, sect.segName()) and mem.eql(u8, sectname, sect.sectName())) |
| 862 | return @intCast(u8, i); | 862 | return @intCast(u8, i); |
| 863 | } else return null; | 863 | } else return null; |
src/link/MachO/UnwindInfo.zig+8-8| ... | @@ -126,7 +126,7 @@ const Page = struct { | ... | @@ -126,7 +126,7 @@ const Page = struct { |
| 126 | ctx.page.start + ctx.page.count, | 126 | ctx.page.start + ctx.page.count, |
| 127 | }); | 127 | }); |
| 128 | try writer.print(" encodings (count = {d})\n", .{ctx.page.page_encodings_count}); | 128 | try writer.print(" encodings (count = {d})\n", .{ctx.page.page_encodings_count}); |
| 129 | for (ctx.page.page_encodings[0..ctx.page.page_encodings_count]) |record_id, i| { | 129 | for (ctx.page.page_encodings[0..ctx.page.page_encodings_count], 0..) |record_id, i| { |
| 130 | const record = ctx.info.records.items[record_id]; | 130 | const record = ctx.info.records.items[record_id]; |
| 131 | const enc = record.compactUnwindEncoding; | 131 | const enc = record.compactUnwindEncoding; |
| 132 | try writer.print(" {d}: 0x{x:0>8}\n", .{ ctx.info.common_encodings_count + i, enc }); | 132 | try writer.print(" {d}: 0x{x:0>8}\n", .{ ctx.info.common_encodings_count + i, enc }); |
| ... | @@ -205,7 +205,7 @@ pub fn scanRelocs(zld: *Zld) !void { | ... | @@ -205,7 +205,7 @@ pub fn scanRelocs(zld: *Zld) !void { |
| 205 | if (zld.getSectionByName("__TEXT", "__unwind_info") == null) return; | 205 | if (zld.getSectionByName("__TEXT", "__unwind_info") == null) return; |
| 206 | 206 | ||
| 207 | const cpu_arch = zld.options.target.cpu.arch; | 207 | const cpu_arch = zld.options.target.cpu.arch; |
| 208 | for (zld.objects.items) |*object, object_id| { | 208 | for (zld.objects.items, 0..) |*object, object_id| { |
| 209 | const unwind_records = object.getUnwindRecords(); | 209 | const unwind_records = object.getUnwindRecords(); |
| 210 | for (object.exec_atoms.items) |atom_index| { | 210 | for (object.exec_atoms.items) |atom_index| { |
| 211 | const record_id = object.unwind_records_lookup.get(atom_index) orelse continue; | 211 | const record_id = object.unwind_records_lookup.get(atom_index) orelse continue; |
| ... | @@ -244,7 +244,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void { | ... | @@ -244,7 +244,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void { |
| 244 | defer atom_indexes.deinit(); | 244 | defer atom_indexes.deinit(); |
| 245 | 245 | ||
| 246 | // TODO handle dead stripping | 246 | // TODO handle dead stripping |
| 247 | for (zld.objects.items) |*object, object_id| { | 247 | for (zld.objects.items, 0..) |*object, object_id| { |
| 248 | log.debug("collecting unwind records in {s} ({d})", .{ object.name, object_id }); | 248 | log.debug("collecting unwind records in {s} ({d})", .{ object.name, object_id }); |
| 249 | const unwind_records = object.getUnwindRecords(); | 249 | const unwind_records = object.getUnwindRecords(); |
| 250 | 250 | ||
| ... | @@ -335,7 +335,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void { | ... | @@ -335,7 +335,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void { |
| 335 | try info.records_lookup.ensureTotalCapacity(info.gpa, @intCast(u32, atom_indexes.items.len)); | 335 | try info.records_lookup.ensureTotalCapacity(info.gpa, @intCast(u32, atom_indexes.items.len)); |
| 336 | 336 | ||
| 337 | var maybe_prev: ?macho.compact_unwind_entry = null; | 337 | var maybe_prev: ?macho.compact_unwind_entry = null; |
| 338 | for (records.items) |record, i| { | 338 | for (records.items, 0..) |record, i| { |
| 339 | const record_id = blk: { | 339 | const record_id = blk: { |
| 340 | if (maybe_prev) |prev| { | 340 | if (maybe_prev) |prev| { |
| 341 | const is_dwarf = UnwindEncoding.isDwarf(record.compactUnwindEncoding, cpu_arch); | 341 | const is_dwarf = UnwindEncoding.isDwarf(record.compactUnwindEncoding, cpu_arch); |
| ... | @@ -483,7 +483,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void { | ... | @@ -483,7 +483,7 @@ pub fn collect(info: *UnwindInfo, zld: *Zld) !void { |
| 483 | 483 | ||
| 484 | // Save indices of records requiring LSDA relocation | 484 | // Save indices of records requiring LSDA relocation |
| 485 | try info.lsdas_lookup.ensureTotalCapacity(info.gpa, @intCast(u32, info.records.items.len)); | 485 | try info.lsdas_lookup.ensureTotalCapacity(info.gpa, @intCast(u32, info.records.items.len)); |
| 486 | for (info.records.items) |rec, i| { | 486 | for (info.records.items, 0..) |rec, i| { |
| 487 | info.lsdas_lookup.putAssumeCapacityNoClobber(@intCast(RecordIndex, i), @intCast(u32, info.lsdas.items.len)); | 487 | info.lsdas_lookup.putAssumeCapacityNoClobber(@intCast(RecordIndex, i), @intCast(u32, info.lsdas.items.len)); |
| 488 | if (rec.lsda == 0) continue; | 488 | if (rec.lsda == 0) continue; |
| 489 | try info.lsdas.append(info.gpa, @intCast(RecordIndex, i)); | 489 | try info.lsdas.append(info.gpa, @intCast(RecordIndex, i)); |
| ... | @@ -556,7 +556,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void { | ... | @@ -556,7 +556,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void { |
| 556 | const cpu_arch = zld.options.target.cpu.arch; | 556 | const cpu_arch = zld.options.target.cpu.arch; |
| 557 | 557 | ||
| 558 | log.debug("Personalities:", .{}); | 558 | log.debug("Personalities:", .{}); |
| 559 | for (info.personalities[0..info.personalities_count]) |target, i| { | 559 | for (info.personalities[0..info.personalities_count], 0..) |target, i| { |
| 560 | const atom_index = zld.getGotAtomIndexForSymbol(target).?; | 560 | const atom_index = zld.getGotAtomIndexForSymbol(target).?; |
| 561 | const atom = zld.getAtom(atom_index); | 561 | const atom = zld.getAtom(atom_index); |
| 562 | const sym = zld.getSymbol(atom.getSymbolWithLoc()); | 562 | const sym = zld.getSymbol(atom.getSymbolWithLoc()); |
| ... | @@ -581,7 +581,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void { | ... | @@ -581,7 +581,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void { |
| 581 | } | 581 | } |
| 582 | } | 582 | } |
| 583 | 583 | ||
| 584 | for (info.records.items) |record, i| { | 584 | for (info.records.items, 0..) |record, i| { |
| 585 | log.debug("Unwind record at offset 0x{x}", .{i * @sizeOf(macho.compact_unwind_entry)}); | 585 | log.debug("Unwind record at offset 0x{x}", .{i * @sizeOf(macho.compact_unwind_entry)}); |
| 586 | log.debug(" start: 0x{x}", .{record.rangeStart}); | 586 | log.debug(" start: 0x{x}", .{record.rangeStart}); |
| 587 | log.debug(" length: 0x{x}", .{record.rangeLength}); | 587 | log.debug(" length: 0x{x}", .{record.rangeLength}); |
| ... | @@ -621,7 +621,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void { | ... | @@ -621,7 +621,7 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void { |
| 621 | const pages_base_offset = @intCast(u32, size - (info.pages.items.len * second_level_page_bytes)); | 621 | const pages_base_offset = @intCast(u32, size - (info.pages.items.len * second_level_page_bytes)); |
| 622 | const lsda_base_offset = @intCast(u32, pages_base_offset - | 622 | const lsda_base_offset = @intCast(u32, pages_base_offset - |
| 623 | (info.lsdas.items.len * @sizeOf(macho.unwind_info_section_header_lsda_index_entry))); | 623 | (info.lsdas.items.len * @sizeOf(macho.unwind_info_section_header_lsda_index_entry))); |
| 624 | for (info.pages.items) |page, i| { | 624 | for (info.pages.items, 0..) |page, i| { |
| 625 | assert(page.count > 0); | 625 | assert(page.count > 0); |
| 626 | const first_entry = info.records.items[page.start]; | 626 | const first_entry = info.records.items[page.start]; |
| 627 | try writer.writeStruct(macho.unwind_info_section_header_index_entry{ | 627 | try writer.writeStruct(macho.unwind_info_section_header_index_entry{ |
src/link/MachO/dead_strip.zig+1-1| ... | @@ -238,7 +238,7 @@ fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable) !void { | ... | @@ -238,7 +238,7 @@ fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable) !void { |
| 238 | } | 238 | } |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | for (zld.objects.items) |_, object_id| { | 241 | for (zld.objects.items, 0..) |_, object_id| { |
| 242 | // Traverse unwind and eh_frame records noting if the source symbol has been marked, and if so, | 242 | // Traverse unwind and eh_frame records noting if the source symbol has been marked, and if so, |
| 243 | // marking all references as live. | 243 | // marking all references as live. |
| 244 | try markUnwindRecords(zld, @intCast(u32, object_id), alive); | 244 | try markUnwindRecords(zld, @intCast(u32, object_id), alive); |
src/link/MachO/dyld_info/Rebase.zig+1-1| ... | @@ -45,7 +45,7 @@ pub fn finalize(rebase: *Rebase, gpa: Allocator) !void { | ... | @@ -45,7 +45,7 @@ pub fn finalize(rebase: *Rebase, gpa: Allocator) !void { |
| 45 | 45 | ||
| 46 | var start: usize = 0; | 46 | var start: usize = 0; |
| 47 | var seg_id: ?u8 = null; | 47 | var seg_id: ?u8 = null; |
| 48 | for (rebase.entries.items) |entry, i| { | 48 | for (rebase.entries.items, 0..) |entry, i| { |
| 49 | if (seg_id != null and seg_id.? == entry.segment_id) continue; | 49 | if (seg_id != null and seg_id.? == entry.segment_id) continue; |
| 50 | try finalizeSegment(rebase.entries.items[start..i], writer); | 50 | try finalizeSegment(rebase.entries.items[start..i], writer); |
| 51 | seg_id = entry.segment_id; | 51 | seg_id = entry.segment_id; |
src/link/MachO/dyld_info/bind.zig+1-1| ... | @@ -51,7 +51,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type { | ... | @@ -51,7 +51,7 @@ pub fn Bind(comptime Ctx: type, comptime Target: type) type { |
| 51 | 51 | ||
| 52 | var start: usize = 0; | 52 | var start: usize = 0; |
| 53 | var seg_id: ?u8 = null; | 53 | var seg_id: ?u8 = null; |
| 54 | for (self.entries.items) |entry, i| { | 54 | for (self.entries.items, 0..) |entry, i| { |
| 55 | if (seg_id != null and seg_id.? == entry.segment_id) continue; | 55 | if (seg_id != null and seg_id.? == entry.segment_id) continue; |
| 56 | try finalizeSegment(self.entries.items[start..i], ctx, writer); | 56 | try finalizeSegment(self.entries.items[start..i], ctx, writer); |
| 57 | seg_id = entry.segment_id; | 57 | seg_id = entry.segment_id; |
src/link/MachO/eh_frame.zig+4-4| ... | @@ -16,7 +16,7 @@ const Zld = @import("zld.zig").Zld; | ... | @@ -16,7 +16,7 @@ const Zld = @import("zld.zig").Zld; |
| 16 | pub fn scanRelocs(zld: *Zld) !void { | 16 | pub fn scanRelocs(zld: *Zld) !void { |
| 17 | const gpa = zld.gpa; | 17 | const gpa = zld.gpa; |
| 18 | 18 | ||
| 19 | for (zld.objects.items) |*object, object_id| { | 19 | for (zld.objects.items, 0..) |*object, object_id| { |
| 20 | var cies = std.AutoHashMap(u32, void).init(gpa); | 20 | var cies = std.AutoHashMap(u32, void).init(gpa); |
| 21 | defer cies.deinit(); | 21 | defer cies.deinit(); |
| 22 | 22 | ||
| ... | @@ -108,7 +108,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void { | ... | @@ -108,7 +108,7 @@ pub fn write(zld: *Zld, unwind_info: *UnwindInfo) !void { |
| 108 | 108 | ||
| 109 | var eh_frame_offset: u32 = 0; | 109 | var eh_frame_offset: u32 = 0; |
| 110 | 110 | ||
| 111 | for (zld.objects.items) |*object, object_id| { | 111 | for (zld.objects.items, 0..) |*object, object_id| { |
| 112 | try eh_records.ensureUnusedCapacity(2 * @intCast(u32, object.exec_atoms.items.len)); | 112 | try eh_records.ensureUnusedCapacity(2 * @intCast(u32, object.exec_atoms.items.len)); |
| 113 | 113 | ||
| 114 | var cies = std.AutoHashMap(u32, u32).init(gpa); | 114 | var cies = std.AutoHashMap(u32, u32).init(gpa); |
| ... | @@ -407,7 +407,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { | ... | @@ -407,7 +407,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 407 | var creader = std.io.countingReader(stream.reader()); | 407 | var creader = std.io.countingReader(stream.reader()); |
| 408 | const reader = creader.reader(); | 408 | const reader = creader.reader(); |
| 409 | 409 | ||
| 410 | for (aug_str) |ch, i| switch (ch) { | 410 | for (aug_str, 0..) |ch, i| switch (ch) { |
| 411 | 'z' => if (i > 0) { | 411 | 'z' => if (i > 0) { |
| 412 | return error.BadDwarfCfi; | 412 | return error.BadDwarfCfi; |
| 413 | } else { | 413 | } else { |
| ... | @@ -467,7 +467,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { | ... | @@ -467,7 +467,7 @@ pub fn EhFrameRecord(comptime is_mutable: bool) type { |
| 467 | var creader = std.io.countingReader(stream.reader()); | 467 | var creader = std.io.countingReader(stream.reader()); |
| 468 | const reader = creader.reader(); | 468 | const reader = creader.reader(); |
| 469 | 469 | ||
| 470 | for (aug_str) |ch, i| switch (ch) { | 470 | for (aug_str, 0..) |ch, i| switch (ch) { |
| 471 | 'z' => if (i > 0) { | 471 | 'z' => if (i > 0) { |
| 472 | return error.BadDwarfCfi; | 472 | return error.BadDwarfCfi; |
| 473 | } else { | 473 | } else { |
src/link/MachO/thunks.zig+1-1| ... | @@ -329,7 +329,7 @@ fn createThunkAtom(zld: *Zld) !AtomIndex { | ... | @@ -329,7 +329,7 @@ fn createThunkAtom(zld: *Zld) !AtomIndex { |
| 329 | fn getThunkIndex(zld: *Zld, atom_index: AtomIndex) ?ThunkIndex { | 329 | fn getThunkIndex(zld: *Zld, atom_index: AtomIndex) ?ThunkIndex { |
| 330 | const atom = zld.getAtom(atom_index); | 330 | const atom = zld.getAtom(atom_index); |
| 331 | const sym = zld.getSymbol(atom.getSymbolWithLoc()); | 331 | const sym = zld.getSymbol(atom.getSymbolWithLoc()); |
| 332 | for (zld.thunks.items) |thunk, i| { | 332 | for (zld.thunks.items, 0..) |thunk, i| { |
| 333 | if (thunk.len == 0) continue; | 333 | if (thunk.len == 0) continue; |
| 334 | 334 | ||
| 335 | const thunk_atom_index = thunk.getStartAtomIndex(); | 335 | const thunk_atom_index = thunk.getStartAtomIndex(); |
src/link/MachO/zld.zig+31-31| ... | @@ -321,7 +321,7 @@ pub const Zld = struct { | ... | @@ -321,7 +321,7 @@ pub const Zld = struct { |
| 321 | syslibroot: ?[]const u8, | 321 | syslibroot: ?[]const u8, |
| 322 | dependent_libs: anytype, | 322 | dependent_libs: anytype, |
| 323 | ) !void { | 323 | ) !void { |
| 324 | for (lib_names) |lib, i| { | 324 | for (lib_names, 0..) |lib, i| { |
| 325 | const lib_info = lib_infos[i]; | 325 | const lib_info = lib_infos[i]; |
| 326 | log.debug("parsing lib path '{s}'", .{lib}); | 326 | log.debug("parsing lib path '{s}'", .{lib}); |
| 327 | if (try self.parseDylib(lib, dependent_libs, .{ | 327 | if (try self.parseDylib(lib, dependent_libs, .{ |
| ... | @@ -1092,7 +1092,7 @@ pub const Zld = struct { | ... | @@ -1092,7 +1092,7 @@ pub const Zld = struct { |
| 1092 | const sym = self.getSymbolPtr(global); | 1092 | const sym = self.getSymbolPtr(global); |
| 1093 | const sym_name = self.getSymbolName(global); | 1093 | const sym_name = self.getSymbolName(global); |
| 1094 | 1094 | ||
| 1095 | for (self.dylibs.items) |dylib, id| { | 1095 | for (self.dylibs.items, 0..) |dylib, id| { |
| 1096 | if (!dylib.symbols.contains(sym_name)) continue; | 1096 | if (!dylib.symbols.contains(sym_name)) continue; |
| 1097 | 1097 | ||
| 1098 | const dylib_id = @intCast(u16, id); | 1098 | const dylib_id = @intCast(u16, id); |
| ... | @@ -1223,7 +1223,7 @@ pub const Zld = struct { | ... | @@ -1223,7 +1223,7 @@ pub const Zld = struct { |
| 1223 | const global = SymbolWithLoc{ .sym_index = sym_index }; | 1223 | const global = SymbolWithLoc{ .sym_index = sym_index }; |
| 1224 | try self.globals.append(gpa, global); | 1224 | try self.globals.append(gpa, global); |
| 1225 | 1225 | ||
| 1226 | for (self.dylibs.items) |dylib, id| { | 1226 | for (self.dylibs.items, 0..) |dylib, id| { |
| 1227 | if (!dylib.symbols.contains(sym_name)) continue; | 1227 | if (!dylib.symbols.contains(sym_name)) continue; |
| 1228 | 1228 | ||
| 1229 | const dylib_id = @intCast(u16, id); | 1229 | const dylib_id = @intCast(u16, id); |
| ... | @@ -1311,7 +1311,7 @@ pub const Zld = struct { | ... | @@ -1311,7 +1311,7 @@ pub const Zld = struct { |
| 1311 | }); | 1311 | }); |
| 1312 | } | 1312 | } |
| 1313 | 1313 | ||
| 1314 | for (self.sections.items(.header)) |header, sect_id| { | 1314 | for (self.sections.items(.header), 0..) |header, sect_id| { |
| 1315 | if (header.size == 0) continue; // empty section | 1315 | if (header.size == 0) continue; // empty section |
| 1316 | 1316 | ||
| 1317 | const segname = header.segName(); | 1317 | const segname = header.segName(); |
| ... | @@ -1385,7 +1385,7 @@ pub const Zld = struct { | ... | @@ -1385,7 +1385,7 @@ pub const Zld = struct { |
| 1385 | const gpa = self.gpa; | 1385 | const gpa = self.gpa; |
| 1386 | const slice = self.sections.slice(); | 1386 | const slice = self.sections.slice(); |
| 1387 | 1387 | ||
| 1388 | for (slice.items(.first_atom_index)) |first_atom_index, sect_id| { | 1388 | for (slice.items(.first_atom_index), 0..) |first_atom_index, sect_id| { |
| 1389 | const header = slice.items(.header)[sect_id]; | 1389 | const header = slice.items(.header)[sect_id]; |
| 1390 | var atom_index = first_atom_index; | 1390 | var atom_index = first_atom_index; |
| 1391 | 1391 | ||
| ... | @@ -1525,7 +1525,7 @@ pub const Zld = struct { | ... | @@ -1525,7 +1525,7 @@ pub const Zld = struct { |
| 1525 | 1525 | ||
| 1526 | fn calcSectionSizes(self: *Zld) !void { | 1526 | fn calcSectionSizes(self: *Zld) !void { |
| 1527 | const slice = self.sections.slice(); | 1527 | const slice = self.sections.slice(); |
| 1528 | for (slice.items(.header)) |*header, sect_id| { | 1528 | for (slice.items(.header), 0..) |*header, sect_id| { |
| 1529 | if (header.size == 0) continue; | 1529 | if (header.size == 0) continue; |
| 1530 | if (self.requiresThunks()) { | 1530 | if (self.requiresThunks()) { |
| 1531 | if (header.isCode() and !(header.type() == macho.S_SYMBOL_STUBS) and !mem.eql(u8, header.sectName(), "__stub_helper")) continue; | 1531 | if (header.isCode() and !(header.type() == macho.S_SYMBOL_STUBS) and !mem.eql(u8, header.sectName(), "__stub_helper")) continue; |
| ... | @@ -1556,7 +1556,7 @@ pub const Zld = struct { | ... | @@ -1556,7 +1556,7 @@ pub const Zld = struct { |
| 1556 | } | 1556 | } |
| 1557 | 1557 | ||
| 1558 | if (self.requiresThunks()) { | 1558 | if (self.requiresThunks()) { |
| 1559 | for (slice.items(.header)) |header, sect_id| { | 1559 | for (slice.items(.header), 0..) |header, sect_id| { |
| 1560 | if (!header.isCode()) continue; | 1560 | if (!header.isCode()) continue; |
| 1561 | if (header.type() == macho.S_SYMBOL_STUBS) continue; | 1561 | if (header.type() == macho.S_SYMBOL_STUBS) continue; |
| 1562 | if (mem.eql(u8, header.sectName(), "__stub_helper")) continue; | 1562 | if (mem.eql(u8, header.sectName(), "__stub_helper")) continue; |
| ... | @@ -1568,7 +1568,7 @@ pub const Zld = struct { | ... | @@ -1568,7 +1568,7 @@ pub const Zld = struct { |
| 1568 | } | 1568 | } |
| 1569 | 1569 | ||
| 1570 | fn allocateSegments(self: *Zld) !void { | 1570 | fn allocateSegments(self: *Zld) !void { |
| 1571 | for (self.segments.items) |*segment, segment_index| { | 1571 | for (self.segments.items, 0..) |*segment, segment_index| { |
| 1572 | const is_text_segment = mem.eql(u8, segment.segName(), "__TEXT"); | 1572 | const is_text_segment = mem.eql(u8, segment.segName(), "__TEXT"); |
| 1573 | const base_size = if (is_text_segment) try load_commands.calcMinHeaderPad(self.gpa, self.options, .{ | 1573 | const base_size = if (is_text_segment) try load_commands.calcMinHeaderPad(self.gpa, self.options, .{ |
| 1574 | .segments = self.segments.items, | 1574 | .segments = self.segments.items, |
| ... | @@ -1606,7 +1606,7 @@ pub const Zld = struct { | ... | @@ -1606,7 +1606,7 @@ pub const Zld = struct { |
| 1606 | var start = init_size; | 1606 | var start = init_size; |
| 1607 | 1607 | ||
| 1608 | const slice = self.sections.slice(); | 1608 | const slice = self.sections.slice(); |
| 1609 | for (slice.items(.header)[indexes.start..indexes.end]) |*header, sect_id| { | 1609 | for (slice.items(.header)[indexes.start..indexes.end], 0..) |*header, sect_id| { |
| 1610 | const alignment = try math.powi(u32, 2, header.@"align"); | 1610 | const alignment = try math.powi(u32, 2, header.@"align"); |
| 1611 | const start_aligned = mem.alignForwardGeneric(u64, start, alignment); | 1611 | const start_aligned = mem.alignForwardGeneric(u64, start, alignment); |
| 1612 | const n_sect = @intCast(u8, indexes.start + sect_id + 1); | 1612 | const n_sect = @intCast(u8, indexes.start + sect_id + 1); |
| ... | @@ -1750,7 +1750,7 @@ pub const Zld = struct { | ... | @@ -1750,7 +1750,7 @@ pub const Zld = struct { |
| 1750 | } | 1750 | } |
| 1751 | 1751 | ||
| 1752 | fn writeSegmentHeaders(self: *Zld, writer: anytype) !void { | 1752 | fn writeSegmentHeaders(self: *Zld, writer: anytype) !void { |
| 1753 | for (self.segments.items) |seg, i| { | 1753 | for (self.segments.items, 0..) |seg, i| { |
| 1754 | const indexes = self.getSectionIndexes(@intCast(u8, i)); | 1754 | const indexes = self.getSectionIndexes(@intCast(u8, i)); |
| 1755 | var out_seg = seg; | 1755 | var out_seg = seg; |
| 1756 | out_seg.cmdsize = @sizeOf(macho.segment_command_64); | 1756 | out_seg.cmdsize = @sizeOf(macho.segment_command_64); |
| ... | @@ -1852,7 +1852,7 @@ pub const Zld = struct { | ... | @@ -1852,7 +1852,7 @@ pub const Zld = struct { |
| 1852 | } | 1852 | } |
| 1853 | 1853 | ||
| 1854 | // Finally, unpack the rest. | 1854 | // Finally, unpack the rest. |
| 1855 | for (slice.items(.header)) |header, sect_id| { | 1855 | for (slice.items(.header), 0..) |header, sect_id| { |
| 1856 | switch (header.type()) { | 1856 | switch (header.type()) { |
| 1857 | macho.S_LITERAL_POINTERS, | 1857 | macho.S_LITERAL_POINTERS, |
| 1858 | macho.S_REGULAR, | 1858 | macho.S_REGULAR, |
| ... | @@ -1989,7 +1989,7 @@ pub const Zld = struct { | ... | @@ -1989,7 +1989,7 @@ pub const Zld = struct { |
| 1989 | 1989 | ||
| 1990 | // Finally, unpack the rest. | 1990 | // Finally, unpack the rest. |
| 1991 | const slice = self.sections.slice(); | 1991 | const slice = self.sections.slice(); |
| 1992 | for (slice.items(.header)) |header, sect_id| { | 1992 | for (slice.items(.header), 0..) |header, sect_id| { |
| 1993 | switch (header.type()) { | 1993 | switch (header.type()) { |
| 1994 | macho.S_LITERAL_POINTERS, | 1994 | macho.S_LITERAL_POINTERS, |
| 1995 | macho.S_REGULAR, | 1995 | macho.S_REGULAR, |
| ... | @@ -2710,7 +2710,7 @@ pub const Zld = struct { | ... | @@ -2710,7 +2710,7 @@ pub const Zld = struct { |
| 2710 | const amt = try self.file.preadAll(locals_buf, self.symtab_cmd.symoff); | 2710 | const amt = try self.file.preadAll(locals_buf, self.symtab_cmd.symoff); |
| 2711 | if (amt != locals_buf.len) return error.InputOutput; | 2711 | if (amt != locals_buf.len) return error.InputOutput; |
| 2712 | 2712 | ||
| 2713 | const istab: usize = for (locals) |local, i| { | 2713 | const istab: usize = for (locals, 0..) |local, i| { |
| 2714 | if (local.stab()) break i; | 2714 | if (local.stab()) break i; |
| 2715 | } else locals.len; | 2715 | } else locals.len; |
| 2716 | const nstabs = locals.len - istab; | 2716 | const nstabs = locals.len - istab; |
| ... | @@ -2897,7 +2897,7 @@ pub const Zld = struct { | ... | @@ -2897,7 +2897,7 @@ pub const Zld = struct { |
| 2897 | } | 2897 | } |
| 2898 | 2898 | ||
| 2899 | fn getSegmentByName(self: Zld, segname: []const u8) ?u8 { | 2899 | fn getSegmentByName(self: Zld, segname: []const u8) ?u8 { |
| 2900 | for (self.segments.items) |seg, i| { | 2900 | for (self.segments.items, 0..) |seg, i| { |
| 2901 | if (mem.eql(u8, segname, seg.segName())) return @intCast(u8, i); | 2901 | if (mem.eql(u8, segname, seg.segName())) return @intCast(u8, i); |
| 2902 | } else return null; | 2902 | } else return null; |
| 2903 | } | 2903 | } |
| ... | @@ -2921,7 +2921,7 @@ pub const Zld = struct { | ... | @@ -2921,7 +2921,7 @@ pub const Zld = struct { |
| 2921 | 2921 | ||
| 2922 | pub fn getSectionByName(self: Zld, segname: []const u8, sectname: []const u8) ?u8 { | 2922 | pub fn getSectionByName(self: Zld, segname: []const u8, sectname: []const u8) ?u8 { |
| 2923 | // TODO investigate caching with a hashmap | 2923 | // TODO investigate caching with a hashmap |
| 2924 | for (self.sections.items(.header)) |header, i| { | 2924 | for (self.sections.items(.header), 0..) |header, i| { |
| 2925 | if (mem.eql(u8, header.segName(), segname) and mem.eql(u8, header.sectName(), sectname)) | 2925 | if (mem.eql(u8, header.segName(), segname) and mem.eql(u8, header.sectName(), sectname)) |
| 2926 | return @intCast(u8, i); | 2926 | return @intCast(u8, i); |
| 2927 | } else return null; | 2927 | } else return null; |
| ... | @@ -2929,7 +2929,7 @@ pub const Zld = struct { | ... | @@ -2929,7 +2929,7 @@ pub const Zld = struct { |
| 2929 | 2929 | ||
| 2930 | pub fn getSectionIndexes(self: Zld, segment_index: u8) struct { start: u8, end: u8 } { | 2930 | pub fn getSectionIndexes(self: Zld, segment_index: u8) struct { start: u8, end: u8 } { |
| 2931 | var start: u8 = 0; | 2931 | var start: u8 = 0; |
| 2932 | const nsects = for (self.segments.items) |seg, i| { | 2932 | const nsects = for (self.segments.items, 0..) |seg, i| { |
| 2933 | if (i == segment_index) break @intCast(u8, seg.nsects); | 2933 | if (i == segment_index) break @intCast(u8, seg.nsects); |
| 2934 | start += @intCast(u8, seg.nsects); | 2934 | start += @intCast(u8, seg.nsects); |
| 2935 | } else 0; | 2935 | } else 0; |
| ... | @@ -3220,7 +3220,7 @@ pub const Zld = struct { | ... | @@ -3220,7 +3220,7 @@ pub const Zld = struct { |
| 3220 | 3220 | ||
| 3221 | fn logSegments(self: *Zld) void { | 3221 | fn logSegments(self: *Zld) void { |
| 3222 | log.debug("segments:", .{}); | 3222 | log.debug("segments:", .{}); |
| 3223 | for (self.segments.items) |segment, i| { | 3223 | for (self.segments.items, 0..) |segment, i| { |
| 3224 | log.debug(" segment({d}): {s} @{x} ({x}), sizeof({x})", .{ | 3224 | log.debug(" segment({d}): {s} @{x} ({x}), sizeof({x})", .{ |
| 3225 | i, | 3225 | i, |
| 3226 | segment.segName(), | 3226 | segment.segName(), |
| ... | @@ -3233,7 +3233,7 @@ pub const Zld = struct { | ... | @@ -3233,7 +3233,7 @@ pub const Zld = struct { |
| 3233 | 3233 | ||
| 3234 | fn logSections(self: *Zld) void { | 3234 | fn logSections(self: *Zld) void { |
| 3235 | log.debug("sections:", .{}); | 3235 | log.debug("sections:", .{}); |
| 3236 | for (self.sections.items(.header)) |header, i| { | 3236 | for (self.sections.items(.header), 0..) |header, i| { |
| 3237 | log.debug(" sect({d}): {s},{s} @{x} ({x}), sizeof({x})", .{ | 3237 | log.debug(" sect({d}): {s},{s} @{x} ({x}), sizeof({x})", .{ |
| 3238 | i + 1, | 3238 | i + 1, |
| 3239 | header.segName(), | 3239 | header.segName(), |
| ... | @@ -3271,10 +3271,10 @@ pub const Zld = struct { | ... | @@ -3271,10 +3271,10 @@ pub const Zld = struct { |
| 3271 | const scoped_log = std.log.scoped(.symtab); | 3271 | const scoped_log = std.log.scoped(.symtab); |
| 3272 | 3272 | ||
| 3273 | scoped_log.debug("locals:", .{}); | 3273 | scoped_log.debug("locals:", .{}); |
| 3274 | for (self.objects.items) |object, id| { | 3274 | for (self.objects.items, 0..) |object, id| { |
| 3275 | scoped_log.debug(" object({d}): {s}", .{ id, object.name }); | 3275 | scoped_log.debug(" object({d}): {s}", .{ id, object.name }); |
| 3276 | if (object.in_symtab == null) continue; | 3276 | if (object.in_symtab == null) continue; |
| 3277 | for (object.symtab) |sym, sym_id| { | 3277 | for (object.symtab, 0..) |sym, sym_id| { |
| 3278 | mem.set(u8, &buf, '_'); | 3278 | mem.set(u8, &buf, '_'); |
| 3279 | scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{ | 3279 | scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{ |
| 3280 | sym_id, | 3280 | sym_id, |
| ... | @@ -3286,7 +3286,7 @@ pub const Zld = struct { | ... | @@ -3286,7 +3286,7 @@ pub const Zld = struct { |
| 3286 | } | 3286 | } |
| 3287 | } | 3287 | } |
| 3288 | scoped_log.debug(" object(-1)", .{}); | 3288 | scoped_log.debug(" object(-1)", .{}); |
| 3289 | for (self.locals.items) |sym, sym_id| { | 3289 | for (self.locals.items, 0..) |sym, sym_id| { |
| 3290 | if (sym.undf()) continue; | 3290 | if (sym.undf()) continue; |
| 3291 | scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{ | 3291 | scoped_log.debug(" %{d}: {s} @{x} in sect({d}), {s}", .{ |
| 3292 | sym_id, | 3292 | sym_id, |
| ... | @@ -3298,7 +3298,7 @@ pub const Zld = struct { | ... | @@ -3298,7 +3298,7 @@ pub const Zld = struct { |
| 3298 | } | 3298 | } |
| 3299 | 3299 | ||
| 3300 | scoped_log.debug("exports:", .{}); | 3300 | scoped_log.debug("exports:", .{}); |
| 3301 | for (self.globals.items) |global, i| { | 3301 | for (self.globals.items, 0..) |global, i| { |
| 3302 | const sym = self.getSymbol(global); | 3302 | const sym = self.getSymbol(global); |
| 3303 | if (sym.undf()) continue; | 3303 | if (sym.undf()) continue; |
| 3304 | if (sym.n_desc == N_DEAD) continue; | 3304 | if (sym.n_desc == N_DEAD) continue; |
| ... | @@ -3313,7 +3313,7 @@ pub const Zld = struct { | ... | @@ -3313,7 +3313,7 @@ pub const Zld = struct { |
| 3313 | } | 3313 | } |
| 3314 | 3314 | ||
| 3315 | scoped_log.debug("imports:", .{}); | 3315 | scoped_log.debug("imports:", .{}); |
| 3316 | for (self.globals.items) |global, i| { | 3316 | for (self.globals.items, 0..) |global, i| { |
| 3317 | const sym = self.getSymbol(global); | 3317 | const sym = self.getSymbol(global); |
| 3318 | if (!sym.undf()) continue; | 3318 | if (!sym.undf()) continue; |
| 3319 | if (sym.n_desc == N_DEAD) continue; | 3319 | if (sym.n_desc == N_DEAD) continue; |
| ... | @@ -3328,7 +3328,7 @@ pub const Zld = struct { | ... | @@ -3328,7 +3328,7 @@ pub const Zld = struct { |
| 3328 | } | 3328 | } |
| 3329 | 3329 | ||
| 3330 | scoped_log.debug("GOT entries:", .{}); | 3330 | scoped_log.debug("GOT entries:", .{}); |
| 3331 | for (self.got_entries.items) |entry, i| { | 3331 | for (self.got_entries.items, 0..) |entry, i| { |
| 3332 | const atom_sym = entry.getAtomSymbol(self); | 3332 | const atom_sym = entry.getAtomSymbol(self); |
| 3333 | const target_sym = entry.getTargetSymbol(self); | 3333 | const target_sym = entry.getTargetSymbol(self); |
| 3334 | const target_sym_name = entry.getTargetSymbolName(self); | 3334 | const target_sym_name = entry.getTargetSymbolName(self); |
| ... | @@ -3350,7 +3350,7 @@ pub const Zld = struct { | ... | @@ -3350,7 +3350,7 @@ pub const Zld = struct { |
| 3350 | } | 3350 | } |
| 3351 | 3351 | ||
| 3352 | scoped_log.debug("__thread_ptrs entries:", .{}); | 3352 | scoped_log.debug("__thread_ptrs entries:", .{}); |
| 3353 | for (self.tlv_ptr_entries.items) |entry, i| { | 3353 | for (self.tlv_ptr_entries.items, 0..) |entry, i| { |
| 3354 | const atom_sym = entry.getAtomSymbol(self); | 3354 | const atom_sym = entry.getAtomSymbol(self); |
| 3355 | const target_sym = entry.getTargetSymbol(self); | 3355 | const target_sym = entry.getTargetSymbol(self); |
| 3356 | const target_sym_name = entry.getTargetSymbolName(self); | 3356 | const target_sym_name = entry.getTargetSymbolName(self); |
| ... | @@ -3363,7 +3363,7 @@ pub const Zld = struct { | ... | @@ -3363,7 +3363,7 @@ pub const Zld = struct { |
| 3363 | } | 3363 | } |
| 3364 | 3364 | ||
| 3365 | scoped_log.debug("stubs entries:", .{}); | 3365 | scoped_log.debug("stubs entries:", .{}); |
| 3366 | for (self.stubs.items) |entry, i| { | 3366 | for (self.stubs.items, 0..) |entry, i| { |
| 3367 | const atom_sym = entry.getAtomSymbol(self); | 3367 | const atom_sym = entry.getAtomSymbol(self); |
| 3368 | const target_sym = entry.getTargetSymbol(self); | 3368 | const target_sym = entry.getTargetSymbol(self); |
| 3369 | const target_sym_name = entry.getTargetSymbolName(self); | 3369 | const target_sym_name = entry.getTargetSymbolName(self); |
| ... | @@ -3376,9 +3376,9 @@ pub const Zld = struct { | ... | @@ -3376,9 +3376,9 @@ pub const Zld = struct { |
| 3376 | } | 3376 | } |
| 3377 | 3377 | ||
| 3378 | scoped_log.debug("thunks:", .{}); | 3378 | scoped_log.debug("thunks:", .{}); |
| 3379 | for (self.thunks.items) |thunk, i| { | 3379 | for (self.thunks.items, 0..) |thunk, i| { |
| 3380 | scoped_log.debug(" thunk({d})", .{i}); | 3380 | scoped_log.debug(" thunk({d})", .{i}); |
| 3381 | for (thunk.lookup.keys()) |target, j| { | 3381 | for (thunk.lookup.keys(), 0..) |target, j| { |
| 3382 | const target_sym = self.getSymbol(target); | 3382 | const target_sym = self.getSymbol(target); |
| 3383 | const atom = self.getAtom(thunk.lookup.get(target).?); | 3383 | const atom = self.getAtom(thunk.lookup.get(target).?); |
| 3384 | const atom_sym = self.getSymbol(atom.getSymbolWithLoc()); | 3384 | const atom_sym = self.getSymbol(atom.getSymbolWithLoc()); |
| ... | @@ -3395,7 +3395,7 @@ pub const Zld = struct { | ... | @@ -3395,7 +3395,7 @@ pub const Zld = struct { |
| 3395 | fn logAtoms(self: *Zld) void { | 3395 | fn logAtoms(self: *Zld) void { |
| 3396 | log.debug("atoms:", .{}); | 3396 | log.debug("atoms:", .{}); |
| 3397 | const slice = self.sections.slice(); | 3397 | const slice = self.sections.slice(); |
| 3398 | for (slice.items(.first_atom_index)) |first_atom_index, sect_id| { | 3398 | for (slice.items(.first_atom_index), 0..) |first_atom_index, sect_id| { |
| 3399 | var atom_index = first_atom_index; | 3399 | var atom_index = first_atom_index; |
| 3400 | if (atom_index == 0) continue; | 3400 | if (atom_index == 0) continue; |
| 3401 | 3401 | ||
| ... | @@ -3980,7 +3980,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr | ... | @@ -3980,7 +3980,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr |
| 3980 | .unresolved = std.AutoArrayHashMap(u32, void).init(arena), | 3980 | .unresolved = std.AutoArrayHashMap(u32, void).init(arena), |
| 3981 | }; | 3981 | }; |
| 3982 | 3982 | ||
| 3983 | for (zld.objects.items) |_, object_id| { | 3983 | for (zld.objects.items, 0..) |_, object_id| { |
| 3984 | try zld.resolveSymbolsInObject(@intCast(u32, object_id), &resolver); | 3984 | try zld.resolveSymbolsInObject(@intCast(u32, object_id), &resolver); |
| 3985 | } | 3985 | } |
| 3986 | 3986 | ||
| ... | @@ -4010,7 +4010,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr | ... | @@ -4010,7 +4010,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr |
| 4010 | zld.entry_index = global_index; | 4010 | zld.entry_index = global_index; |
| 4011 | } | 4011 | } |
| 4012 | 4012 | ||
| 4013 | for (zld.objects.items) |*object, object_id| { | 4013 | for (zld.objects.items, 0..) |*object, object_id| { |
| 4014 | try object.splitIntoAtoms(&zld, @intCast(u32, object_id)); | 4014 | try object.splitIntoAtoms(&zld, @intCast(u32, object_id)); |
| 4015 | } | 4015 | } |
| 4016 | 4016 |
src/link/SpirV.zig+2-2| ... | @@ -298,7 +298,7 @@ fn cloneAir(air: Air, gpa: Allocator, air_arena: Allocator) !Air { | ... | @@ -298,7 +298,7 @@ fn cloneAir(air: Air, gpa: Allocator, air_arena: Allocator) !Air { |
| 298 | const values = try gpa.alloc(Value, air.values.len); | 298 | const values = try gpa.alloc(Value, air.values.len); |
| 299 | errdefer gpa.free(values); | 299 | errdefer gpa.free(values); |
| 300 | 300 | ||
| 301 | for (values) |*value, i| { | 301 | for (values, 0..) |*value, i| { |
| 302 | value.* = try air.values[i].copy(air_arena); | 302 | value.* = try air.values[i].copy(air_arena); |
| 303 | } | 303 | } |
| 304 | 304 | ||
| ... | @@ -308,7 +308,7 @@ fn cloneAir(air: Air, gpa: Allocator, air_arena: Allocator) !Air { | ... | @@ -308,7 +308,7 @@ fn cloneAir(air: Air, gpa: Allocator, air_arena: Allocator) !Air { |
| 308 | const air_tags = instructions.items(.tag); | 308 | const air_tags = instructions.items(.tag); |
| 309 | const air_datas = instructions.items(.data); | 309 | const air_datas = instructions.items(.data); |
| 310 | 310 | ||
| 311 | for (air_tags) |tag, i| { | 311 | for (air_tags, 0..) |tag, i| { |
| 312 | switch (tag) { | 312 | switch (tag) { |
| 313 | .alloc, .ret_ptr, .const_ty => air_datas[i].ty = try air_datas[i].ty.copy(air_arena), | 313 | .alloc, .ret_ptr, .const_ty => air_datas[i].ty = try air_datas[i].ty.copy(air_arena), |
| 314 | else => {}, | 314 | else => {}, |
src/link/Wasm.zig+10-10| ... | @@ -590,7 +590,7 @@ fn resolveSymbolsInObject(wasm: *Wasm, object_index: u16) !void { | ... | @@ -590,7 +590,7 @@ fn resolveSymbolsInObject(wasm: *Wasm, object_index: u16) !void { |
| 590 | const object: Object = wasm.objects.items[object_index]; | 590 | const object: Object = wasm.objects.items[object_index]; |
| 591 | log.debug("Resolving symbols in object: '{s}'", .{object.name}); | 591 | log.debug("Resolving symbols in object: '{s}'", .{object.name}); |
| 592 | 592 | ||
| 593 | for (object.symtable) |symbol, i| { | 593 | for (object.symtable, 0..) |symbol, i| { |
| 594 | const sym_index = @intCast(u32, i); | 594 | const sym_index = @intCast(u32, i); |
| 595 | const location: SymbolLoc = .{ | 595 | const location: SymbolLoc = .{ |
| 596 | .file = object_index, | 596 | .file = object_index, |
| ... | @@ -794,7 +794,7 @@ fn validateFeatures( | ... | @@ -794,7 +794,7 @@ fn validateFeatures( |
| 794 | 794 | ||
| 795 | // extract all the used, disallowed and required features from each | 795 | // extract all the used, disallowed and required features from each |
| 796 | // linked object file so we can test them. | 796 | // linked object file so we can test them. |
| 797 | for (wasm.objects.items) |object, object_index| { | 797 | for (wasm.objects.items, 0..) |object, object_index| { |
| 798 | for (object.features) |feature| { | 798 | for (object.features) |feature| { |
| 799 | const value = @intCast(u16, object_index) << 1 | @as(u1, 1); | 799 | const value = @intCast(u16, object_index) << 1 | @as(u1, 1); |
| 800 | switch (feature.prefix) { | 800 | switch (feature.prefix) { |
| ... | @@ -815,7 +815,7 @@ fn validateFeatures( | ... | @@ -815,7 +815,7 @@ fn validateFeatures( |
| 815 | // when we infer the features, we allow each feature found in the 'used' set | 815 | // when we infer the features, we allow each feature found in the 'used' set |
| 816 | // and insert it into the 'allowed' set. When features are not inferred, | 816 | // and insert it into the 'allowed' set. When features are not inferred, |
| 817 | // we validate that a used feature is allowed. | 817 | // we validate that a used feature is allowed. |
| 818 | for (used) |used_set, used_index| { | 818 | for (used, 0..) |used_set, used_index| { |
| 819 | const is_enabled = @truncate(u1, used_set) != 0; | 819 | const is_enabled = @truncate(u1, used_set) != 0; |
| 820 | if (infer) { | 820 | if (infer) { |
| 821 | allowed[used_index] = is_enabled; | 821 | allowed[used_index] = is_enabled; |
| ... | @@ -849,7 +849,7 @@ fn validateFeatures( | ... | @@ -849,7 +849,7 @@ fn validateFeatures( |
| 849 | } | 849 | } |
| 850 | 850 | ||
| 851 | // validate the linked object file has each required feature | 851 | // validate the linked object file has each required feature |
| 852 | for (required) |required_feature, feature_index| { | 852 | for (required, 0..) |required_feature, feature_index| { |
| 853 | const is_required = @truncate(u1, required_feature) != 0; | 853 | const is_required = @truncate(u1, required_feature) != 0; |
| 854 | if (is_required and !object_used_features[feature_index]) { | 854 | if (is_required and !object_used_features[feature_index]) { |
| 855 | log.err("feature '{s}' is required but not used in linked object", .{(@intToEnum(types.Feature.Tag, feature_index)).toString()}); | 855 | log.err("feature '{s}' is required but not used in linked object", .{(@intToEnum(types.Feature.Tag, feature_index)).toString()}); |
| ... | @@ -1818,7 +1818,7 @@ fn sortDataSegments(wasm: *Wasm) !void { | ... | @@ -1818,7 +1818,7 @@ fn sortDataSegments(wasm: *Wasm) !void { |
| 1818 | /// original functions and their types. We need to know the type to verify it doesn't | 1818 | /// original functions and their types. We need to know the type to verify it doesn't |
| 1819 | /// contain any parameters. | 1819 | /// contain any parameters. |
| 1820 | fn setupInitFunctions(wasm: *Wasm) !void { | 1820 | fn setupInitFunctions(wasm: *Wasm) !void { |
| 1821 | for (wasm.objects.items) |object, file_index| { | 1821 | for (wasm.objects.items, 0..) |object, file_index| { |
| 1822 | try wasm.init_funcs.ensureUnusedCapacity(wasm.base.allocator, object.init_funcs.len); | 1822 | try wasm.init_funcs.ensureUnusedCapacity(wasm.base.allocator, object.init_funcs.len); |
| 1823 | for (object.init_funcs) |init_func| { | 1823 | for (object.init_funcs) |init_func| { |
| 1824 | const symbol = object.symtable[init_func.symbol_index]; | 1824 | const symbol = object.symtable[init_func.symbol_index]; |
| ... | @@ -2717,7 +2717,7 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l | ... | @@ -2717,7 +2717,7 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l |
| 2717 | 2717 | ||
| 2718 | try wasm.parseInputFiles(positionals.items); | 2718 | try wasm.parseInputFiles(positionals.items); |
| 2719 | 2719 | ||
| 2720 | for (wasm.objects.items) |_, object_index| { | 2720 | for (wasm.objects.items, 0..) |_, object_index| { |
| 2721 | try wasm.resolveSymbolsInObject(@intCast(u16, object_index)); | 2721 | try wasm.resolveSymbolsInObject(@intCast(u16, object_index)); |
| 2722 | } | 2722 | } |
| 2723 | 2723 | ||
| ... | @@ -2732,7 +2732,7 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l | ... | @@ -2732,7 +2732,7 @@ fn linkWithZld(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) l |
| 2732 | try wasm.setupStart(); | 2732 | try wasm.setupStart(); |
| 2733 | try wasm.setupImports(); | 2733 | try wasm.setupImports(); |
| 2734 | 2734 | ||
| 2735 | for (wasm.objects.items) |*object, object_index| { | 2735 | for (wasm.objects.items, 0..) |*object, object_index| { |
| 2736 | try object.parseIntoAtoms(gpa, @intCast(u16, object_index), wasm); | 2736 | try object.parseIntoAtoms(gpa, @intCast(u16, object_index), wasm); |
| 2737 | } | 2737 | } |
| 2738 | 2738 | ||
| ... | @@ -2801,7 +2801,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod | ... | @@ -2801,7 +2801,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod |
| 2801 | 2801 | ||
| 2802 | try wasm.parseInputFiles(positionals.items); | 2802 | try wasm.parseInputFiles(positionals.items); |
| 2803 | 2803 | ||
| 2804 | for (wasm.objects.items) |_, object_index| { | 2804 | for (wasm.objects.items, 0..) |_, object_index| { |
| 2805 | try wasm.resolveSymbolsInObject(@intCast(u16, object_index)); | 2805 | try wasm.resolveSymbolsInObject(@intCast(u16, object_index)); |
| 2806 | } | 2806 | } |
| 2807 | 2807 | ||
| ... | @@ -2850,7 +2850,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod | ... | @@ -2850,7 +2850,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod |
| 2850 | } | 2850 | } |
| 2851 | } | 2851 | } |
| 2852 | 2852 | ||
| 2853 | for (wasm.objects.items) |*object, object_index| { | 2853 | for (wasm.objects.items, 0..) |*object, object_index| { |
| 2854 | try object.parseIntoAtoms(wasm.base.allocator, @intCast(u16, object_index), wasm); | 2854 | try object.parseIntoAtoms(wasm.base.allocator, @intCast(u16, object_index), wasm); |
| 2855 | } | 2855 | } |
| 2856 | 2856 | ||
| ... | @@ -3362,7 +3362,7 @@ fn emitFeaturesSection(binary_bytes: *std.ArrayList(u8), enabled_features: []con | ... | @@ -3362,7 +3362,7 @@ fn emitFeaturesSection(binary_bytes: *std.ArrayList(u8), enabled_features: []con |
| 3362 | try writer.writeAll(target_features); | 3362 | try writer.writeAll(target_features); |
| 3363 | 3363 | ||
| 3364 | try leb.writeULEB128(writer, features_count); | 3364 | try leb.writeULEB128(writer, features_count); |
| 3365 | for (enabled_features) |enabled, feature_index| { | 3365 | for (enabled_features, 0..) |enabled, feature_index| { |
| 3366 | if (enabled) { | 3366 | if (enabled) { |
| 3367 | const feature: types.Feature = .{ .prefix = .used, .tag = @intToEnum(types.Feature.Tag, feature_index) }; | 3367 | const feature: types.Feature = .{ .prefix = .used, .tag = @intToEnum(types.Feature.Tag, feature_index) }; |
| 3368 | try leb.writeULEB128(writer, @enumToInt(feature.prefix)); | 3368 | try leb.writeULEB128(writer, @enumToInt(feature.prefix)); |
src/link/Wasm/Object.zig+2-2| ... | @@ -882,7 +882,7 @@ pub fn parseIntoAtoms(object: *Object, gpa: Allocator, object_index: u16, wasm_b | ... | @@ -882,7 +882,7 @@ pub fn parseIntoAtoms(object: *Object, gpa: Allocator, object_index: u16, wasm_b |
| 882 | list.deinit(); | 882 | list.deinit(); |
| 883 | } else symbol_for_segment.deinit(); | 883 | } else symbol_for_segment.deinit(); |
| 884 | 884 | ||
| 885 | for (object.symtable) |symbol, symbol_index| { | 885 | for (object.symtable, 0..) |symbol, symbol_index| { |
| 886 | switch (symbol.tag) { | 886 | switch (symbol.tag) { |
| 887 | .function, .data, .section => if (!symbol.isUndefined()) { | 887 | .function, .data, .section => if (!symbol.isUndefined()) { |
| 888 | const gop = try symbol_for_segment.getOrPut(.{ .kind = symbol.tag, .index = symbol.index }); | 888 | const gop = try symbol_for_segment.getOrPut(.{ .kind = symbol.tag, .index = symbol.index }); |
| ... | @@ -896,7 +896,7 @@ pub fn parseIntoAtoms(object: *Object, gpa: Allocator, object_index: u16, wasm_b | ... | @@ -896,7 +896,7 @@ pub fn parseIntoAtoms(object: *Object, gpa: Allocator, object_index: u16, wasm_b |
| 896 | } | 896 | } |
| 897 | } | 897 | } |
| 898 | 898 | ||
| 899 | for (object.relocatable_data) |relocatable_data, index| { | 899 | for (object.relocatable_data, 0..) |relocatable_data, index| { |
| 900 | const final_index = (try wasm_bin.getMatchingSegment(object_index, @intCast(u32, index))) orelse { | 900 | const final_index = (try wasm_bin.getMatchingSegment(object_index, @intCast(u32, index))) orelse { |
| 901 | continue; // found unknown section, so skip parsing into atom as we do not know how to handle it. | 901 | continue; // found unknown section, so skip parsing into atom as we do not know how to handle it. |
| 902 | }; | 902 | }; |
src/link/tapi.zig+2-2| ... | @@ -124,7 +124,7 @@ pub const LibStub = struct { | ... | @@ -124,7 +124,7 @@ pub const LibStub = struct { |
| 124 | log.debug("trying to parse as []TbdV4", .{}); | 124 | log.debug("trying to parse as []TbdV4", .{}); |
| 125 | const inner = lib_stub.yaml.parse([]TbdV4) catch break :err; | 125 | const inner = lib_stub.yaml.parse([]TbdV4) catch break :err; |
| 126 | var out = try lib_stub.yaml.arena.allocator().alloc(Tbd, inner.len); | 126 | var out = try lib_stub.yaml.arena.allocator().alloc(Tbd, inner.len); |
| 127 | for (inner) |doc, i| { | 127 | for (inner, 0..) |doc, i| { |
| 128 | out[i] = .{ .v4 = doc }; | 128 | out[i] = .{ .v4 = doc }; |
| 129 | } | 129 | } |
| 130 | break :blk out; | 130 | break :blk out; |
| ... | @@ -142,7 +142,7 @@ pub const LibStub = struct { | ... | @@ -142,7 +142,7 @@ pub const LibStub = struct { |
| 142 | log.debug("trying to parse as []TbdV3", .{}); | 142 | log.debug("trying to parse as []TbdV3", .{}); |
| 143 | const inner = lib_stub.yaml.parse([]TbdV3) catch break :err; | 143 | const inner = lib_stub.yaml.parse([]TbdV3) catch break :err; |
| 144 | var out = try lib_stub.yaml.arena.allocator().alloc(Tbd, inner.len); | 144 | var out = try lib_stub.yaml.arena.allocator().alloc(Tbd, inner.len); |
| 145 | for (inner) |doc, i| { | 145 | for (inner, 0..) |doc, i| { |
| 146 | out[i] = .{ .v3 = doc }; | 146 | out[i] = .{ .v3 = doc }; |
| 147 | } | 147 | } |
| 148 | break :blk out; | 148 | break :blk out; |
src/link/tapi/yaml.zig+7-7| ... | @@ -84,7 +84,7 @@ pub const Value = union(ValueType) { | ... | @@ -84,7 +84,7 @@ pub const Value = union(ValueType) { |
| 84 | 84 | ||
| 85 | const first = list[0]; | 85 | const first = list[0]; |
| 86 | if (first.is_compound()) { | 86 | if (first.is_compound()) { |
| 87 | for (list) |elem, i| { | 87 | for (list, 0..) |elem, i| { |
| 88 | try writer.writeByteNTimes(' ', args.indentation); | 88 | try writer.writeByteNTimes(' ', args.indentation); |
| 89 | try writer.writeAll("- "); | 89 | try writer.writeAll("- "); |
| 90 | try elem.stringify(writer, .{ | 90 | try elem.stringify(writer, .{ |
| ... | @@ -99,7 +99,7 @@ pub const Value = union(ValueType) { | ... | @@ -99,7 +99,7 @@ pub const Value = union(ValueType) { |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | try writer.writeAll("[ "); | 101 | try writer.writeAll("[ "); |
| 102 | for (list) |elem, i| { | 102 | for (list, 0..) |elem, i| { |
| 103 | try elem.stringify(writer, args); | 103 | try elem.stringify(writer, args); |
| 104 | if (i < len - 1) { | 104 | if (i < len - 1) { |
| 105 | try writer.writeAll(", "); | 105 | try writer.writeAll(", "); |
| ... | @@ -112,7 +112,7 @@ pub const Value = union(ValueType) { | ... | @@ -112,7 +112,7 @@ pub const Value = union(ValueType) { |
| 112 | const len = keys.len; | 112 | const len = keys.len; |
| 113 | if (len == 0) return; | 113 | if (len == 0) return; |
| 114 | 114 | ||
| 115 | for (keys) |key, i| { | 115 | for (keys, 0..) |key, i| { |
| 116 | if (!args.should_inline_first_key or i != 0) { | 116 | if (!args.should_inline_first_key or i != 0) { |
| 117 | try writer.writeByteNTimes(' ', args.indentation); | 117 | try writer.writeByteNTimes(' ', args.indentation); |
| 118 | } | 118 | } |
| ... | @@ -292,7 +292,7 @@ pub const Yaml = struct { | ... | @@ -292,7 +292,7 @@ pub const Yaml = struct { |
| 292 | switch (@typeInfo(T)) { | 292 | switch (@typeInfo(T)) { |
| 293 | .Array => |info| { | 293 | .Array => |info| { |
| 294 | var parsed: T = undefined; | 294 | var parsed: T = undefined; |
| 295 | for (self.docs.items) |doc, i| { | 295 | for (self.docs.items, 0..) |doc, i| { |
| 296 | parsed[i] = try self.parseValue(info.child, doc); | 296 | parsed[i] = try self.parseValue(info.child, doc); |
| 297 | } | 297 | } |
| 298 | return parsed; | 298 | return parsed; |
| ... | @@ -301,7 +301,7 @@ pub const Yaml = struct { | ... | @@ -301,7 +301,7 @@ pub const Yaml = struct { |
| 301 | switch (info.size) { | 301 | switch (info.size) { |
| 302 | .Slice => { | 302 | .Slice => { |
| 303 | var parsed = try self.arena.allocator().alloc(info.child, self.docs.items.len); | 303 | var parsed = try self.arena.allocator().alloc(info.child, self.docs.items.len); |
| 304 | for (self.docs.items) |doc, i| { | 304 | for (self.docs.items, 0..) |doc, i| { |
| 305 | parsed[i] = try self.parseValue(info.child, doc); | 305 | parsed[i] = try self.parseValue(info.child, doc); |
| 306 | } | 306 | } |
| 307 | return parsed; | 307 | return parsed; |
| ... | @@ -393,7 +393,7 @@ pub const Yaml = struct { | ... | @@ -393,7 +393,7 @@ pub const Yaml = struct { |
| 393 | } | 393 | } |
| 394 | 394 | ||
| 395 | var parsed = try arena.alloc(ptr_info.child, value.list.len); | 395 | var parsed = try arena.alloc(ptr_info.child, value.list.len); |
| 396 | for (value.list) |elem, i| { | 396 | for (value.list, 0..) |elem, i| { |
| 397 | parsed[i] = try self.parseValue(ptr_info.child, elem); | 397 | parsed[i] = try self.parseValue(ptr_info.child, elem); |
| 398 | } | 398 | } |
| 399 | return parsed; | 399 | return parsed; |
| ... | @@ -407,7 +407,7 @@ pub const Yaml = struct { | ... | @@ -407,7 +407,7 @@ pub const Yaml = struct { |
| 407 | if (array_info.len != list.len) return error.ArraySizeMismatch; | 407 | if (array_info.len != list.len) return error.ArraySizeMismatch; |
| 408 | 408 | ||
| 409 | var parsed: T = undefined; | 409 | var parsed: T = undefined; |
| 410 | for (list) |elem, i| { | 410 | for (list, 0..) |elem, i| { |
| 411 | parsed[i] = try self.parseValue(array_info.child, elem); | 411 | parsed[i] = try self.parseValue(array_info.child, elem); |
| 412 | } | 412 | } |
| 413 | 413 |
src/main.zig+3-3| ... | @@ -3684,10 +3684,10 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool) !void | ... | @@ -3684,10 +3684,10 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool) !void |
| 3684 | const new_argv_with_sentinel = try arena.alloc(?[*:0]const u8, clang_args_len + 1); | 3684 | const new_argv_with_sentinel = try arena.alloc(?[*:0]const u8, clang_args_len + 1); |
| 3685 | new_argv_with_sentinel[clang_args_len] = null; | 3685 | new_argv_with_sentinel[clang_args_len] = null; |
| 3686 | const new_argv = new_argv_with_sentinel[0..clang_args_len :null]; | 3686 | const new_argv = new_argv_with_sentinel[0..clang_args_len :null]; |
| 3687 | for (argv.items) |arg, i| { | 3687 | for (argv.items, 0..) |arg, i| { |
| 3688 | new_argv[i] = try arena.dupeZ(u8, arg); | 3688 | new_argv[i] = try arena.dupeZ(u8, arg); |
| 3689 | } | 3689 | } |
| 3690 | for (c_source_file.extra_flags) |arg, i| { | 3690 | for (c_source_file.extra_flags, 0..) |arg, i| { |
| 3691 | new_argv[argv.items.len + i] = try arena.dupeZ(u8, arg); | 3691 | new_argv[argv.items.len + i] = try arena.dupeZ(u8, arg); |
| 3692 | } | 3692 | } |
| 3693 | 3693 | ||
| ... | @@ -4816,7 +4816,7 @@ extern "c" fn ZigLlvmAr_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int; | ... | @@ -4816,7 +4816,7 @@ extern "c" fn ZigLlvmAr_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int; |
| 4816 | 4816 | ||
| 4817 | fn argsCopyZ(alloc: Allocator, args: []const []const u8) ![:null]?[*:0]u8 { | 4817 | fn argsCopyZ(alloc: Allocator, args: []const []const u8) ![:null]?[*:0]u8 { |
| 4818 | var argv = try alloc.allocSentinel(?[*:0]u8, args.len, null); | 4818 | var argv = try alloc.allocSentinel(?[*:0]u8, args.len, null); |
| 4819 | for (args) |arg, i| { | 4819 | for (args, 0..) |arg, i| { |
| 4820 | argv[i] = try alloc.dupeZ(u8, arg); // TODO If there was an argsAllocZ we could avoid this allocation. | 4820 | argv[i] = try alloc.dupeZ(u8, arg); // TODO If there was an argsAllocZ we could avoid this allocation. |
| 4821 | } | 4821 | } |
| 4822 | return argv; | 4822 | return argv; |
src/mingw.zig+2-2| ... | @@ -72,7 +72,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { | ... | @@ -72,7 +72,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 72 | 72 | ||
| 73 | .mingw32_lib => { | 73 | .mingw32_lib => { |
| 74 | var c_source_files: [mingw32_lib_deps.len]Compilation.CSourceFile = undefined; | 74 | var c_source_files: [mingw32_lib_deps.len]Compilation.CSourceFile = undefined; |
| 75 | for (mingw32_lib_deps) |dep, i| { | 75 | for (mingw32_lib_deps, 0..) |dep, i| { |
| 76 | var args = std.ArrayList([]const u8).init(arena); | 76 | var args = std.ArrayList([]const u8).init(arena); |
| 77 | try args.appendSlice(&[_][]const u8{ | 77 | try args.appendSlice(&[_][]const u8{ |
| 78 | "-DHAVE_CONFIG_H", | 78 | "-DHAVE_CONFIG_H", |
| ... | @@ -236,7 +236,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { | ... | @@ -236,7 +236,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 236 | }), | 236 | }), |
| 237 | }); | 237 | }); |
| 238 | var c_source_files: [uuid_src.len]Compilation.CSourceFile = undefined; | 238 | var c_source_files: [uuid_src.len]Compilation.CSourceFile = undefined; |
| 239 | for (uuid_src) |dep, i| { | 239 | for (uuid_src, 0..) |dep, i| { |
| 240 | c_source_files[i] = .{ | 240 | c_source_files[i] = .{ |
| 241 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 241 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 242 | "libc", "mingw", "libsrc", dep, | 242 | "libc", "mingw", "libsrc", dep, |
src/objcopy.zig+1-1| ... | @@ -312,7 +312,7 @@ const BinaryElfOutput = struct { | ... | @@ -312,7 +312,7 @@ const BinaryElfOutput = struct { |
| 312 | 312 | ||
| 313 | std.sort.sort(*BinaryElfSegment, self.segments.items, {}, segmentSortCompare); | 313 | std.sort.sort(*BinaryElfSegment, self.segments.items, {}, segmentSortCompare); |
| 314 | 314 | ||
| 315 | for (self.segments.items) |firstSegment, i| { | 315 | for (self.segments.items, 0..) |firstSegment, i| { |
| 316 | if (firstSegment.firstSection) |firstSection| { | 316 | if (firstSegment.firstSection) |firstSection| { |
| 317 | const diff = firstSection.elfOffset - firstSegment.elfOffset; | 317 | const diff = firstSection.elfOffset - firstSegment.elfOffset; |
| 318 | 318 |
src/print_air.zig+8-8| ... | @@ -68,7 +68,7 @@ const Writer = struct { | ... | @@ -68,7 +68,7 @@ const Writer = struct { |
| 68 | indent: usize, | 68 | indent: usize, |
| 69 | 69 | ||
| 70 | fn writeAllConstants(w: *Writer, s: anytype) @TypeOf(s).Error!void { | 70 | fn writeAllConstants(w: *Writer, s: anytype) @TypeOf(s).Error!void { |
| 71 | for (w.air.instructions.items(.tag)) |tag, i| { | 71 | for (w.air.instructions.items(.tag), 0..) |tag, i| { |
| 72 | const inst = @intCast(u32, i); | 72 | const inst = @intCast(u32, i); |
| 73 | switch (tag) { | 73 | switch (tag) { |
| 74 | .constant, .const_ty => { | 74 | .constant, .const_ty => { |
| ... | @@ -388,7 +388,7 @@ const Writer = struct { | ... | @@ -388,7 +388,7 @@ const Writer = struct { |
| 388 | 388 | ||
| 389 | try w.writeType(s, vector_ty); | 389 | try w.writeType(s, vector_ty); |
| 390 | try s.writeAll(", ["); | 390 | try s.writeAll(", ["); |
| 391 | for (elements) |elem, i| { | 391 | for (elements, 0..) |elem, i| { |
| 392 | if (i != 0) try s.writeAll(", "); | 392 | if (i != 0) try s.writeAll(", "); |
| 393 | try w.writeOperand(s, inst, i, elem); | 393 | try w.writeOperand(s, inst, i, elem); |
| 394 | } | 394 | } |
| ... | @@ -682,7 +682,7 @@ const Writer = struct { | ... | @@ -682,7 +682,7 @@ const Writer = struct { |
| 682 | const args = @ptrCast([]const Air.Inst.Ref, w.air.extra[extra.end..][0..extra.data.args_len]); | 682 | const args = @ptrCast([]const Air.Inst.Ref, w.air.extra[extra.end..][0..extra.data.args_len]); |
| 683 | try w.writeOperand(s, inst, 0, pl_op.operand); | 683 | try w.writeOperand(s, inst, 0, pl_op.operand); |
| 684 | try s.writeAll(", ["); | 684 | try s.writeAll(", ["); |
| 685 | for (args) |arg, i| { | 685 | for (args, 0..) |arg, i| { |
| 686 | if (i != 0) try s.writeAll(", "); | 686 | if (i != 0) try s.writeAll(", "); |
| 687 | try w.writeOperand(s, inst, 1 + i, arg); | 687 | try w.writeOperand(s, inst, 1 + i, arg); |
| 688 | } | 688 | } |
| ... | @@ -743,7 +743,7 @@ const Writer = struct { | ... | @@ -743,7 +743,7 @@ const Writer = struct { |
| 743 | 743 | ||
| 744 | if (liveness_condbr.then_deaths.len != 0) { | 744 | if (liveness_condbr.then_deaths.len != 0) { |
| 745 | try s.writeByteNTimes(' ', w.indent); | 745 | try s.writeByteNTimes(' ', w.indent); |
| 746 | for (liveness_condbr.then_deaths) |operand, i| { | 746 | for (liveness_condbr.then_deaths, 0..) |operand, i| { |
| 747 | if (i != 0) try s.writeAll(" "); | 747 | if (i != 0) try s.writeAll(" "); |
| 748 | try s.print("%{d}!", .{operand}); | 748 | try s.print("%{d}!", .{operand}); |
| 749 | } | 749 | } |
| ... | @@ -756,7 +756,7 @@ const Writer = struct { | ... | @@ -756,7 +756,7 @@ const Writer = struct { |
| 756 | 756 | ||
| 757 | if (liveness_condbr.else_deaths.len != 0) { | 757 | if (liveness_condbr.else_deaths.len != 0) { |
| 758 | try s.writeByteNTimes(' ', w.indent); | 758 | try s.writeByteNTimes(' ', w.indent); |
| 759 | for (liveness_condbr.else_deaths) |operand, i| { | 759 | for (liveness_condbr.else_deaths, 0..) |operand, i| { |
| 760 | if (i != 0) try s.writeAll(" "); | 760 | if (i != 0) try s.writeAll(" "); |
| 761 | try s.print("%{d}!", .{operand}); | 761 | try s.print("%{d}!", .{operand}); |
| 762 | } | 762 | } |
| ... | @@ -790,7 +790,7 @@ const Writer = struct { | ... | @@ -790,7 +790,7 @@ const Writer = struct { |
| 790 | extra_index = case.end + case.data.items_len + case_body.len; | 790 | extra_index = case.end + case.data.items_len + case_body.len; |
| 791 | 791 | ||
| 792 | try s.writeAll(", ["); | 792 | try s.writeAll(", ["); |
| 793 | for (items) |item, item_i| { | 793 | for (items, 0..) |item, item_i| { |
| 794 | if (item_i != 0) try s.writeAll(", "); | 794 | if (item_i != 0) try s.writeAll(", "); |
| 795 | try w.writeInstRef(s, item, false); | 795 | try w.writeInstRef(s, item, false); |
| 796 | } | 796 | } |
| ... | @@ -800,7 +800,7 @@ const Writer = struct { | ... | @@ -800,7 +800,7 @@ const Writer = struct { |
| 800 | const deaths = liveness.deaths[case_i]; | 800 | const deaths = liveness.deaths[case_i]; |
| 801 | if (deaths.len != 0) { | 801 | if (deaths.len != 0) { |
| 802 | try s.writeByteNTimes(' ', w.indent); | 802 | try s.writeByteNTimes(' ', w.indent); |
| 803 | for (deaths) |operand, i| { | 803 | for (deaths, 0..) |operand, i| { |
| 804 | if (i != 0) try s.writeAll(" "); | 804 | if (i != 0) try s.writeAll(" "); |
| 805 | try s.print("%{d}!", .{operand}); | 805 | try s.print("%{d}!", .{operand}); |
| 806 | } | 806 | } |
| ... | @@ -821,7 +821,7 @@ const Writer = struct { | ... | @@ -821,7 +821,7 @@ const Writer = struct { |
| 821 | const deaths = liveness.deaths[liveness.deaths.len - 1]; | 821 | const deaths = liveness.deaths[liveness.deaths.len - 1]; |
| 822 | if (deaths.len != 0) { | 822 | if (deaths.len != 0) { |
| 823 | try s.writeByteNTimes(' ', w.indent); | 823 | try s.writeByteNTimes(' ', w.indent); |
| 824 | for (deaths) |operand, i| { | 824 | for (deaths, 0..) |operand, i| { |
| 825 | if (i != 0) try s.writeAll(" "); | 825 | if (i != 0) try s.writeAll(" "); |
| 826 | try s.print("%{d}!", .{operand}); | 826 | try s.print("%{d}!", .{operand}); |
| 827 | } | 827 | } |
src/print_targets.zig+2-2| ... | @@ -99,7 +99,7 @@ pub fn cmdTargets( | ... | @@ -99,7 +99,7 @@ pub fn cmdTargets( |
| 99 | for (arch.allCpuModels()) |model| { | 99 | for (arch.allCpuModels()) |model| { |
| 100 | try jws.objectField(model.name); | 100 | try jws.objectField(model.name); |
| 101 | try jws.beginArray(); | 101 | try jws.beginArray(); |
| 102 | for (arch.allFeaturesList()) |feature, i| { | 102 | for (arch.allFeaturesList(), 0..) |feature, i| { |
| 103 | if (model.features.isEnabled(@intCast(u8, i))) { | 103 | if (model.features.isEnabled(@intCast(u8, i))) { |
| 104 | try jws.arrayElem(); | 104 | try jws.arrayElem(); |
| 105 | try jws.emitString(feature.name); | 105 | try jws.emitString(feature.name); |
| ... | @@ -145,7 +145,7 @@ pub fn cmdTargets( | ... | @@ -145,7 +145,7 @@ pub fn cmdTargets( |
| 145 | { | 145 | { |
| 146 | try jws.objectField("features"); | 146 | try jws.objectField("features"); |
| 147 | try jws.beginArray(); | 147 | try jws.beginArray(); |
| 148 | for (native_target.cpu.arch.allFeaturesList()) |feature, i_usize| { | 148 | for (native_target.cpu.arch.allFeaturesList(), 0..) |feature, i_usize| { |
| 149 | const index = @intCast(Target.Cpu.Feature.Set.Index, i_usize); | 149 | const index = @intCast(Target.Cpu.Feature.Set.Index, i_usize); |
| 150 | if (cpu.features.isEnabled(index)) { | 150 | if (cpu.features.isEnabled(index)) { |
| 151 | try jws.arrayElem(); | 151 | try jws.arrayElem(); |
src/print_zir.zig+23-7| ... | @@ -296,6 +296,7 @@ const Writer = struct { | ... | @@ -296,6 +296,7 @@ const Writer = struct { |
| 296 | .add, | 296 | .add, |
| 297 | .addwrap, | 297 | .addwrap, |
| 298 | .add_sat, | 298 | .add_sat, |
| 299 | .add_unsafe, | ||
| 299 | .array_cat, | 300 | .array_cat, |
| 300 | .array_mul, | 301 | .array_mul, |
| 301 | .mul, | 302 | .mul, |
| ... | @@ -355,6 +356,8 @@ const Writer = struct { | ... | @@ -355,6 +356,8 @@ const Writer = struct { |
| 355 | .array_type, | 356 | .array_type, |
| 356 | => try self.writePlNodeBin(stream, inst), | 357 | => try self.writePlNodeBin(stream, inst), |
| 357 | 358 | ||
| 359 | .for_len => try self.writePlNodeMultiOp(stream, inst), | ||
| 360 | |||
| 358 | .elem_ptr_imm => try self.writeElemPtrImm(stream, inst), | 361 | .elem_ptr_imm => try self.writeElemPtrImm(stream, inst), |
| 359 | 362 | ||
| 360 | .@"export" => try self.writePlNodeExport(stream, inst), | 363 | .@"export" => try self.writePlNodeExport(stream, inst), |
| ... | @@ -868,6 +871,19 @@ const Writer = struct { | ... | @@ -868,6 +871,19 @@ const Writer = struct { |
| 868 | try self.writeSrc(stream, inst_data.src()); | 871 | try self.writeSrc(stream, inst_data.src()); |
| 869 | } | 872 | } |
| 870 | 873 | ||
| 874 | fn writePlNodeMultiOp(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | ||
| 875 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; | ||
| 876 | const extra = self.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | ||
| 877 | const args = self.code.refSlice(extra.end, extra.data.operands_len); | ||
| 878 | try stream.writeAll("{"); | ||
| 879 | for (args, 0..) |arg, i| { | ||
| 880 | if (i != 0) try stream.writeAll(", "); | ||
| 881 | try self.writeInstRef(stream, arg); | ||
| 882 | } | ||
| 883 | try stream.writeAll("}) "); | ||
| 884 | try self.writeSrc(stream, inst_data.src()); | ||
| 885 | } | ||
| 886 | |||
| 871 | fn writeElemPtrImm(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | 887 | fn writeElemPtrImm(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
| 872 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; | 888 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; |
| 873 | const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; | 889 | const extra = self.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; |
| ... | @@ -1053,7 +1069,7 @@ const Writer = struct { | ... | @@ -1053,7 +1069,7 @@ const Writer = struct { |
| 1053 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); | 1069 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); |
| 1054 | const operands = self.code.refSlice(extra.end, extended.small); | 1070 | const operands = self.code.refSlice(extra.end, extended.small); |
| 1055 | 1071 | ||
| 1056 | for (operands) |operand, i| { | 1072 | for (operands, 0..) |operand, i| { |
| 1057 | if (i != 0) try stream.writeAll(", "); | 1073 | if (i != 0) try stream.writeAll(", "); |
| 1058 | try self.writeInstRef(stream, operand); | 1074 | try self.writeInstRef(stream, operand); |
| 1059 | } | 1075 | } |
| ... | @@ -1377,7 +1393,7 @@ const Writer = struct { | ... | @@ -1377,7 +1393,7 @@ const Writer = struct { |
| 1377 | try stream.writeAll("{\n"); | 1393 | try stream.writeAll("{\n"); |
| 1378 | self.indent += 2; | 1394 | self.indent += 2; |
| 1379 | 1395 | ||
| 1380 | for (fields) |field, i| { | 1396 | for (fields, 0..) |field, i| { |
| 1381 | try self.writeDocComment(stream, field.doc_comment_index); | 1397 | try self.writeDocComment(stream, field.doc_comment_index); |
| 1382 | try stream.writeByteNTimes(' ', self.indent); | 1398 | try stream.writeByteNTimes(' ', self.indent); |
| 1383 | try self.writeFlag(stream, "comptime ", field.is_comptime); | 1399 | try self.writeFlag(stream, "comptime ", field.is_comptime); |
| ... | @@ -1944,7 +1960,7 @@ const Writer = struct { | ... | @@ -1944,7 +1960,7 @@ const Writer = struct { |
| 1944 | try stream.writeByteNTimes(' ', self.indent); | 1960 | try stream.writeByteNTimes(' ', self.indent); |
| 1945 | if (is_inline) try stream.writeAll("inline "); | 1961 | if (is_inline) try stream.writeAll("inline "); |
| 1946 | 1962 | ||
| 1947 | for (items) |item_ref, item_i| { | 1963 | for (items, 0..) |item_ref, item_i| { |
| 1948 | if (item_i != 0) try stream.writeAll(", "); | 1964 | if (item_i != 0) try stream.writeAll(", "); |
| 1949 | try self.writeInstRef(stream, item_ref); | 1965 | try self.writeInstRef(stream, item_ref); |
| 1950 | } | 1966 | } |
| ... | @@ -2260,7 +2276,7 @@ const Writer = struct { | ... | @@ -2260,7 +2276,7 @@ const Writer = struct { |
| 2260 | try self.writeBracedBody(stream, body); | 2276 | try self.writeBracedBody(stream, body); |
| 2261 | try stream.writeAll(",["); | 2277 | try stream.writeAll(",["); |
| 2262 | const args = self.code.refSlice(extra.end, extended.small); | 2278 | const args = self.code.refSlice(extra.end, extended.small); |
| 2263 | for (args) |arg, i| { | 2279 | for (args, 0..) |arg, i| { |
| 2264 | if (i != 0) try stream.writeAll(", "); | 2280 | if (i != 0) try stream.writeAll(", "); |
| 2265 | try self.writeInstRef(stream, arg); | 2281 | try self.writeInstRef(stream, arg); |
| 2266 | } | 2282 | } |
| ... | @@ -2319,7 +2335,7 @@ const Writer = struct { | ... | @@ -2319,7 +2335,7 @@ const Writer = struct { |
| 2319 | 2335 | ||
| 2320 | try self.writeInstRef(stream, args[0]); | 2336 | try self.writeInstRef(stream, args[0]); |
| 2321 | try stream.writeAll("{"); | 2337 | try stream.writeAll("{"); |
| 2322 | for (args[1..]) |arg, i| { | 2338 | for (args[1..], 0..) |arg, i| { |
| 2323 | if (i != 0) try stream.writeAll(", "); | 2339 | if (i != 0) try stream.writeAll(", "); |
| 2324 | try self.writeInstRef(stream, arg); | 2340 | try self.writeInstRef(stream, arg); |
| 2325 | } | 2341 | } |
| ... | @@ -2334,7 +2350,7 @@ const Writer = struct { | ... | @@ -2334,7 +2350,7 @@ const Writer = struct { |
| 2334 | const args = self.code.refSlice(extra.end, extra.data.operands_len); | 2350 | const args = self.code.refSlice(extra.end, extra.data.operands_len); |
| 2335 | 2351 | ||
| 2336 | try stream.writeAll("{"); | 2352 | try stream.writeAll("{"); |
| 2337 | for (args) |arg, i| { | 2353 | for (args, 0..) |arg, i| { |
| 2338 | if (i != 0) try stream.writeAll(", "); | 2354 | if (i != 0) try stream.writeAll(", "); |
| 2339 | try self.writeInstRef(stream, arg); | 2355 | try self.writeInstRef(stream, arg); |
| 2340 | } | 2356 | } |
| ... | @@ -2354,7 +2370,7 @@ const Writer = struct { | ... | @@ -2354,7 +2370,7 @@ const Writer = struct { |
| 2354 | try stream.writeAll(", "); | 2370 | try stream.writeAll(", "); |
| 2355 | 2371 | ||
| 2356 | try stream.writeAll(".{"); | 2372 | try stream.writeAll(".{"); |
| 2357 | for (elems) |elem, i| { | 2373 | for (elems, 0..) |elem, i| { |
| 2358 | if (i != 0) try stream.writeAll(", "); | 2374 | if (i != 0) try stream.writeAll(", "); |
| 2359 | try self.writeInstRef(stream, elem); | 2375 | try self.writeInstRef(stream, elem); |
| 2360 | } | 2376 | } |
src/register_manager.zig+3-3| ... | @@ -82,7 +82,7 @@ pub fn RegisterManager( | ... | @@ -82,7 +82,7 @@ pub fn RegisterManager( |
| 82 | comptime registers: []const Register, | 82 | comptime registers: []const Register, |
| 83 | reg: Register, | 83 | reg: Register, |
| 84 | ) ?std.math.IntFittingRange(0, registers.len - 1) { | 84 | ) ?std.math.IntFittingRange(0, registers.len - 1) { |
| 85 | inline for (tracked_registers) |cpreg, i| { | 85 | inline for (tracked_registers, 0..) |cpreg, i| { |
| 86 | if (reg.id() == cpreg.id()) return i; | 86 | if (reg.id() == cpreg.id()) return i; |
| 87 | } | 87 | } |
| 88 | return null; | 88 | return null; |
| ... | @@ -153,7 +153,7 @@ pub fn RegisterManager( | ... | @@ -153,7 +153,7 @@ pub fn RegisterManager( |
| 153 | regs: [count]Register, | 153 | regs: [count]Register, |
| 154 | ) [count]RegisterLock { | 154 | ) [count]RegisterLock { |
| 155 | var buf: [count]RegisterLock = undefined; | 155 | var buf: [count]RegisterLock = undefined; |
| 156 | for (regs) |reg, i| { | 156 | for (regs, 0..) |reg, i| { |
| 157 | buf[i] = self.lockRegAssumeUnused(reg); | 157 | buf[i] = self.lockRegAssumeUnused(reg); |
| 158 | } | 158 | } |
| 159 | return buf; | 159 | return buf; |
| ... | @@ -207,7 +207,7 @@ pub fn RegisterManager( | ... | @@ -207,7 +207,7 @@ pub fn RegisterManager( |
| 207 | } | 207 | } |
| 208 | assert(i == count); | 208 | assert(i == count); |
| 209 | 209 | ||
| 210 | for (regs) |reg, j| { | 210 | for (regs, 0..) |reg, j| { |
| 211 | self.markRegAllocated(reg); | 211 | self.markRegAllocated(reg); |
| 212 | 212 | ||
| 213 | if (insts[j]) |inst| { | 213 | if (insts[j]) |inst| { |
src/test.zig+5-5| ... | @@ -664,7 +664,7 @@ pub const TestContext = struct { | ... | @@ -664,7 +664,7 @@ pub const TestContext = struct { |
| 664 | errors: []const []const u8, | 664 | errors: []const []const u8, |
| 665 | ) void { | 665 | ) void { |
| 666 | var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch @panic("out of memory"); | 666 | var array = self.updates.allocator.alloc(ErrorMsg, errors.len) catch @panic("out of memory"); |
| 667 | for (errors) |err_msg_line, i| { | 667 | for (errors, 0..) |err_msg_line, i| { |
| 668 | if (std.mem.startsWith(u8, err_msg_line, "error: ")) { | 668 | if (std.mem.startsWith(u8, err_msg_line, "error: ")) { |
| 669 | array[i] = .{ | 669 | array[i] = .{ |
| 670 | .plain = .{ | 670 | .plain = .{ |
| ... | @@ -1558,7 +1558,7 @@ pub const TestContext = struct { | ... | @@ -1558,7 +1558,7 @@ pub const TestContext = struct { |
| 1558 | }); | 1558 | }); |
| 1559 | defer comp.destroy(); | 1559 | defer comp.destroy(); |
| 1560 | 1560 | ||
| 1561 | update: for (case.updates.items) |update, update_index| { | 1561 | update: for (case.updates.items, 0..) |update, update_index| { |
| 1562 | var update_node = root_node.start(update.name, 3); | 1562 | var update_node = root_node.start(update.name, 3); |
| 1563 | update_node.activate(); | 1563 | update_node.activate(); |
| 1564 | defer update_node.end(); | 1564 | defer update_node.end(); |
| ... | @@ -1631,7 +1631,7 @@ pub const TestContext = struct { | ... | @@ -1631,7 +1631,7 @@ pub const TestContext = struct { |
| 1631 | defer notes_to_check.deinit(); | 1631 | defer notes_to_check.deinit(); |
| 1632 | 1632 | ||
| 1633 | for (actual_errors.list) |actual_error| { | 1633 | for (actual_errors.list) |actual_error| { |
| 1634 | for (case_error_list) |case_msg, i| { | 1634 | for (case_error_list, 0..) |case_msg, i| { |
| 1635 | if (handled_errors[i]) continue; | 1635 | if (handled_errors[i]) continue; |
| 1636 | 1636 | ||
| 1637 | const ex_tag: std.meta.Tag(@TypeOf(case_msg)) = case_msg; | 1637 | const ex_tag: std.meta.Tag(@TypeOf(case_msg)) = case_msg; |
| ... | @@ -1702,7 +1702,7 @@ pub const TestContext = struct { | ... | @@ -1702,7 +1702,7 @@ pub const TestContext = struct { |
| 1702 | } | 1702 | } |
| 1703 | } | 1703 | } |
| 1704 | while (notes_to_check.popOrNull()) |note| { | 1704 | while (notes_to_check.popOrNull()) |note| { |
| 1705 | for (case_error_list) |case_msg, i| { | 1705 | for (case_error_list, 0..) |case_msg, i| { |
| 1706 | const ex_tag: std.meta.Tag(@TypeOf(case_msg)) = case_msg; | 1706 | const ex_tag: std.meta.Tag(@TypeOf(case_msg)) = case_msg; |
| 1707 | switch (note.*) { | 1707 | switch (note.*) { |
| 1708 | .src => |actual_msg| { | 1708 | .src => |actual_msg| { |
| ... | @@ -1752,7 +1752,7 @@ pub const TestContext = struct { | ... | @@ -1752,7 +1752,7 @@ pub const TestContext = struct { |
| 1752 | } | 1752 | } |
| 1753 | } | 1753 | } |
| 1754 | 1754 | ||
| 1755 | for (handled_errors) |handled, i| { | 1755 | for (handled_errors, 0..) |handled, i| { |
| 1756 | if (!handled) { | 1756 | if (!handled) { |
| 1757 | print( | 1757 | print( |
| 1758 | "\nExpected error not found:\n{s}\n{}\n{s}", | 1758 | "\nExpected error not found:\n{s}\n{}\n{s}", |
src/translate_c.zig+7-7| ... | @@ -1423,7 +1423,7 @@ fn transConvertVectorExpr( | ... | @@ -1423,7 +1423,7 @@ fn transConvertVectorExpr( |
| 1423 | } | 1423 | } |
| 1424 | 1424 | ||
| 1425 | const init_list = try c.arena.alloc(Node, num_elements); | 1425 | const init_list = try c.arena.alloc(Node, num_elements); |
| 1426 | for (init_list) |*init, init_index| { | 1426 | for (init_list, 0..) |*init, init_index| { |
| 1427 | const tmp_decl = block_scope.statements.items[init_index]; | 1427 | const tmp_decl = block_scope.statements.items[init_index]; |
| 1428 | const name = tmp_decl.castTag(.var_simple).?.data.name; | 1428 | const name = tmp_decl.castTag(.var_simple).?.data.name; |
| 1429 | init.* = try Tag.identifier.create(c.arena, name); | 1429 | init.* = try Tag.identifier.create(c.arena, name); |
| ... | @@ -1454,7 +1454,7 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE | ... | @@ -1454,7 +1454,7 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE |
| 1454 | 1454 | ||
| 1455 | const init_list = try c.arena.alloc(Node, mask_len); | 1455 | const init_list = try c.arena.alloc(Node, mask_len); |
| 1456 | 1456 | ||
| 1457 | for (init_list) |*init, i| { | 1457 | for (init_list, 0..) |*init, i| { |
| 1458 | const index_expr = try transExprCoercing(c, scope, expr.getExpr(@intCast(c_uint, i + 2)), .used); | 1458 | const index_expr = try transExprCoercing(c, scope, expr.getExpr(@intCast(c_uint, i + 2)), .used); |
| 1459 | const converted_index = try Tag.helpers_shuffle_vector_index.create(c.arena, .{ .lhs = index_expr, .rhs = vector_len }); | 1459 | const converted_index = try Tag.helpers_shuffle_vector_index.create(c.arena, .{ .lhs = index_expr, .rhs = vector_len }); |
| 1460 | init.* = converted_index; | 1460 | init.* = converted_index; |
| ... | @@ -2686,7 +2686,7 @@ fn transInitListExprArray( | ... | @@ -2686,7 +2686,7 @@ fn transInitListExprArray( |
| 2686 | const init_node = if (init_count != 0) blk: { | 2686 | const init_node = if (init_count != 0) blk: { |
| 2687 | const init_list = try c.arena.alloc(Node, init_count); | 2687 | const init_list = try c.arena.alloc(Node, init_count); |
| 2688 | 2688 | ||
| 2689 | for (init_list) |*init, i| { | 2689 | for (init_list, 0..) |*init, i| { |
| 2690 | const elem_expr = expr.getInit(@intCast(c_uint, i)); | 2690 | const elem_expr = expr.getInit(@intCast(c_uint, i)); |
| 2691 | init.* = try transExprCoercing(c, scope, elem_expr, .used); | 2691 | init.* = try transExprCoercing(c, scope, elem_expr, .used); |
| 2692 | } | 2692 | } |
| ... | @@ -2760,7 +2760,7 @@ fn transInitListExprVector( | ... | @@ -2760,7 +2760,7 @@ fn transInitListExprVector( |
| 2760 | } | 2760 | } |
| 2761 | 2761 | ||
| 2762 | const init_list = try c.arena.alloc(Node, num_elements); | 2762 | const init_list = try c.arena.alloc(Node, num_elements); |
| 2763 | for (init_list) |*init, init_index| { | 2763 | for (init_list, 0..) |*init, init_index| { |
| 2764 | if (init_index < init_count) { | 2764 | if (init_index < init_count) { |
| 2765 | const tmp_decl = block_scope.statements.items[init_index]; | 2765 | const tmp_decl = block_scope.statements.items[init_index]; |
| 2766 | const name = tmp_decl.castTag(.var_simple).?.data.name; | 2766 | const name = tmp_decl.castTag(.var_simple).?.data.name; |
| ... | @@ -4649,7 +4649,7 @@ fn transCreateNodeMacroFn(c: *Context, name: []const u8, ref: Node, proto_alias: | ... | @@ -4649,7 +4649,7 @@ fn transCreateNodeMacroFn(c: *Context, name: []const u8, ref: Node, proto_alias: |
| 4649 | 4649 | ||
| 4650 | const unwrap_expr = try Tag.unwrap.create(c.arena, init); | 4650 | const unwrap_expr = try Tag.unwrap.create(c.arena, init); |
| 4651 | const args = try c.arena.alloc(Node, fn_params.items.len); | 4651 | const args = try c.arena.alloc(Node, fn_params.items.len); |
| 4652 | for (fn_params.items) |param, i| { | 4652 | for (fn_params.items, 0..) |param, i| { |
| 4653 | args[i] = try Tag.identifier.create(c.arena, param.name.?); | 4653 | args[i] = try Tag.identifier.create(c.arena, param.name.?); |
| 4654 | } | 4654 | } |
| 4655 | const call_expr = try Tag.call.create(c.arena, .{ | 4655 | const call_expr = try Tag.call.create(c.arena, .{ |
| ... | @@ -5293,7 +5293,7 @@ const PatternList = struct { | ... | @@ -5293,7 +5293,7 @@ const PatternList = struct { |
| 5293 | 5293 | ||
| 5294 | fn init(allocator: mem.Allocator) Error!PatternList { | 5294 | fn init(allocator: mem.Allocator) Error!PatternList { |
| 5295 | const patterns = try allocator.alloc(Pattern, templates.len); | 5295 | const patterns = try allocator.alloc(Pattern, templates.len); |
| 5296 | for (templates) |template, i| { | 5296 | for (templates, 0..) |template, i| { |
| 5297 | try patterns[i].init(allocator, template); | 5297 | try patterns[i].init(allocator, template); |
| 5298 | } | 5298 | } |
| 5299 | return PatternList{ .patterns = patterns }; | 5299 | return PatternList{ .patterns = patterns }; |
| ... | @@ -5778,7 +5778,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node { | ... | @@ -5778,7 +5778,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node { |
| 5778 | 5778 | ||
| 5779 | fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 { | 5779 | fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 { |
| 5780 | var source = m.slice(); | 5780 | var source = m.slice(); |
| 5781 | for (source) |c, i| { | 5781 | for (source, 0..) |c, i| { |
| 5782 | if (c == '\"' or c == '\'') { | 5782 | if (c == '\"' or c == '\'') { |
| 5783 | source = source[i..]; | 5783 | source = source[i..]; |
| 5784 | break; | 5784 | break; |
src/translate_c/ast.zig+11-11| ... | @@ -1765,7 +1765,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { | ... | @@ -1765,7 +1765,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 1765 | _ = try c.addToken(.l_brace, "{"); | 1765 | _ = try c.addToken(.l_brace, "{"); |
| 1766 | var cases = try c.gpa.alloc(NodeIndex, payload.cases.len); | 1766 | var cases = try c.gpa.alloc(NodeIndex, payload.cases.len); |
| 1767 | defer c.gpa.free(cases); | 1767 | defer c.gpa.free(cases); |
| 1768 | for (payload.cases) |case, i| { | 1768 | for (payload.cases, 0..) |case, i| { |
| 1769 | cases[i] = try renderNode(c, case); | 1769 | cases[i] = try renderNode(c, case); |
| 1770 | _ = try c.addToken(.comma, ","); | 1770 | _ = try c.addToken(.comma, ","); |
| 1771 | } | 1771 | } |
| ... | @@ -1800,7 +1800,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { | ... | @@ -1800,7 +1800,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 1800 | var items = try c.gpa.alloc(NodeIndex, std.math.max(payload.cases.len, 1)); | 1800 | var items = try c.gpa.alloc(NodeIndex, std.math.max(payload.cases.len, 1)); |
| 1801 | defer c.gpa.free(items); | 1801 | defer c.gpa.free(items); |
| 1802 | items[0] = 0; | 1802 | items[0] = 0; |
| 1803 | for (payload.cases) |item, i| { | 1803 | for (payload.cases, 0..) |item, i| { |
| 1804 | if (i != 0) _ = try c.addToken(.comma, ","); | 1804 | if (i != 0) _ = try c.addToken(.comma, ","); |
| 1805 | items[i] = try renderNode(c, item); | 1805 | items[i] = try renderNode(c, item); |
| 1806 | } | 1806 | } |
| ... | @@ -1950,7 +1950,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { | ... | @@ -1950,7 +1950,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 1950 | defer c.gpa.free(inits); | 1950 | defer c.gpa.free(inits); |
| 1951 | inits[0] = 0; | 1951 | inits[0] = 0; |
| 1952 | inits[1] = 0; | 1952 | inits[1] = 0; |
| 1953 | for (payload) |init, i| { | 1953 | for (payload, 0..) |init, i| { |
| 1954 | if (i != 0) _ = try c.addToken(.comma, ","); | 1954 | if (i != 0) _ = try c.addToken(.comma, ","); |
| 1955 | inits[i] = try renderNode(c, init); | 1955 | inits[i] = try renderNode(c, init); |
| 1956 | } | 1956 | } |
| ... | @@ -1984,7 +1984,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { | ... | @@ -1984,7 +1984,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 1984 | defer c.gpa.free(inits); | 1984 | defer c.gpa.free(inits); |
| 1985 | inits[0] = 0; | 1985 | inits[0] = 0; |
| 1986 | inits[1] = 0; | 1986 | inits[1] = 0; |
| 1987 | for (payload) |init, i| { | 1987 | for (payload, 0..) |init, i| { |
| 1988 | _ = try c.addToken(.period, "."); | 1988 | _ = try c.addToken(.period, "."); |
| 1989 | _ = try c.addIdentifier(init.name); | 1989 | _ = try c.addIdentifier(init.name); |
| 1990 | _ = try c.addToken(.equal, "="); | 1990 | _ = try c.addToken(.equal, "="); |
| ... | @@ -2022,7 +2022,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { | ... | @@ -2022,7 +2022,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 2022 | var inits = try c.gpa.alloc(NodeIndex, std.math.max(payload.inits.len, 1)); | 2022 | var inits = try c.gpa.alloc(NodeIndex, std.math.max(payload.inits.len, 1)); |
| 2023 | defer c.gpa.free(inits); | 2023 | defer c.gpa.free(inits); |
| 2024 | inits[0] = 0; | 2024 | inits[0] = 0; |
| 2025 | for (payload.inits) |init, i| { | 2025 | for (payload.inits, 0..) |init, i| { |
| 2026 | _ = try c.addToken(.period, "."); | 2026 | _ = try c.addToken(.period, "."); |
| 2027 | _ = try c.addIdentifier(init.name); | 2027 | _ = try c.addIdentifier(init.name); |
| 2028 | _ = try c.addToken(.equal, "="); | 2028 | _ = try c.addToken(.equal, "="); |
| ... | @@ -2080,7 +2080,7 @@ fn renderRecord(c: *Context, node: Node) !NodeIndex { | ... | @@ -2080,7 +2080,7 @@ fn renderRecord(c: *Context, node: Node) !NodeIndex { |
| 2080 | members[0] = 0; | 2080 | members[0] = 0; |
| 2081 | members[1] = 0; | 2081 | members[1] = 0; |
| 2082 | 2082 | ||
| 2083 | for (payload.fields) |field, i| { | 2083 | for (payload.fields, 0..) |field, i| { |
| 2084 | const name_tok = try c.addTokenFmt(.identifier, "{s}", .{std.zig.fmtId(field.name)}); | 2084 | const name_tok = try c.addTokenFmt(.identifier, "{s}", .{std.zig.fmtId(field.name)}); |
| 2085 | _ = try c.addToken(.colon, ":"); | 2085 | _ = try c.addToken(.colon, ":"); |
| 2086 | const type_expr = try renderNode(c, field.type); | 2086 | const type_expr = try renderNode(c, field.type); |
| ... | @@ -2116,10 +2116,10 @@ fn renderRecord(c: *Context, node: Node) !NodeIndex { | ... | @@ -2116,10 +2116,10 @@ fn renderRecord(c: *Context, node: Node) !NodeIndex { |
| 2116 | }); | 2116 | }); |
| 2117 | _ = try c.addToken(.comma, ","); | 2117 | _ = try c.addToken(.comma, ","); |
| 2118 | } | 2118 | } |
| 2119 | for (payload.variables) |variable, i| { | 2119 | for (payload.variables, 0..) |variable, i| { |
| 2120 | members[payload.fields.len + i] = try renderNode(c, variable); | 2120 | members[payload.fields.len + i] = try renderNode(c, variable); |
| 2121 | } | 2121 | } |
| 2122 | for (payload.functions) |function, i| { | 2122 | for (payload.functions, 0..) |function, i| { |
| 2123 | members[payload.fields.len + num_vars + i] = try renderNode(c, function); | 2123 | members[payload.fields.len + num_vars + i] = try renderNode(c, function); |
| 2124 | } | 2124 | } |
| 2125 | _ = try c.addToken(.r_brace, "}"); | 2125 | _ = try c.addToken(.r_brace, "}"); |
| ... | @@ -2171,7 +2171,7 @@ fn renderArrayInit(c: *Context, lhs: NodeIndex, inits: []const Node) !NodeIndex | ... | @@ -2171,7 +2171,7 @@ fn renderArrayInit(c: *Context, lhs: NodeIndex, inits: []const Node) !NodeIndex |
| 2171 | var rendered = try c.gpa.alloc(NodeIndex, std.math.max(inits.len, 1)); | 2171 | var rendered = try c.gpa.alloc(NodeIndex, std.math.max(inits.len, 1)); |
| 2172 | defer c.gpa.free(rendered); | 2172 | defer c.gpa.free(rendered); |
| 2173 | rendered[0] = 0; | 2173 | rendered[0] = 0; |
| 2174 | for (inits) |init, i| { | 2174 | for (inits, 0..) |init, i| { |
| 2175 | rendered[i] = try renderNode(c, init); | 2175 | rendered[i] = try renderNode(c, init); |
| 2176 | _ = try c.addToken(.comma, ","); | 2176 | _ = try c.addToken(.comma, ","); |
| 2177 | } | 2177 | } |
| ... | @@ -2539,7 +2539,7 @@ fn renderCall(c: *Context, lhs: NodeIndex, args: []const Node) !NodeIndex { | ... | @@ -2539,7 +2539,7 @@ fn renderCall(c: *Context, lhs: NodeIndex, args: []const Node) !NodeIndex { |
| 2539 | var rendered = try c.gpa.alloc(NodeIndex, args.len); | 2539 | var rendered = try c.gpa.alloc(NodeIndex, args.len); |
| 2540 | defer c.gpa.free(rendered); | 2540 | defer c.gpa.free(rendered); |
| 2541 | 2541 | ||
| 2542 | for (args) |arg, i| { | 2542 | for (args, 0..) |arg, i| { |
| 2543 | if (i != 0) _ = try c.addToken(.comma, ","); | 2543 | if (i != 0) _ = try c.addToken(.comma, ","); |
| 2544 | rendered[i] = try renderNode(c, arg); | 2544 | rendered[i] = try renderNode(c, arg); |
| 2545 | } | 2545 | } |
| ... | @@ -2879,7 +2879,7 @@ fn renderParams(c: *Context, params: []Payload.Param, is_var_args: bool) !std.Ar | ... | @@ -2879,7 +2879,7 @@ fn renderParams(c: *Context, params: []Payload.Param, is_var_args: bool) !std.Ar |
| 2879 | var rendered = try std.ArrayList(NodeIndex).initCapacity(c.gpa, std.math.max(params.len, 1)); | 2879 | var rendered = try std.ArrayList(NodeIndex).initCapacity(c.gpa, std.math.max(params.len, 1)); |
| 2880 | errdefer rendered.deinit(); | 2880 | errdefer rendered.deinit(); |
| 2881 | 2881 | ||
| 2882 | for (params) |param, i| { | 2882 | for (params, 0..) |param, i| { |
| 2883 | if (i != 0) _ = try c.addToken(.comma, ","); | 2883 | if (i != 0) _ = try c.addToken(.comma, ","); |
| 2884 | if (param.is_noalias) _ = try c.addToken(.keyword_noalias, "noalias"); | 2884 | if (param.is_noalias) _ = try c.addToken(.keyword_noalias, "noalias"); |
| 2885 | if (param.name) |some| { | 2885 | if (param.name) |some| { |
src/type.zig+45-32| ... | @@ -628,7 +628,7 @@ pub const Type = extern union { | ... | @@ -628,7 +628,7 @@ pub const Type = extern union { |
| 628 | const a_set = a.errorSetNames(); | 628 | const a_set = a.errorSetNames(); |
| 629 | const b_set = b.errorSetNames(); | 629 | const b_set = b.errorSetNames(); |
| 630 | if (a_set.len != b_set.len) return false; | 630 | if (a_set.len != b_set.len) return false; |
| 631 | for (a_set) |a_item, i| { | 631 | for (a_set, 0..) |a_item, i| { |
| 632 | const b_item = b_set[i]; | 632 | const b_item = b_set[i]; |
| 633 | if (!std.mem.eql(u8, a_item, b_item)) return false; | 633 | if (!std.mem.eql(u8, a_item, b_item)) return false; |
| 634 | } | 634 | } |
| ... | @@ -675,7 +675,7 @@ pub const Type = extern union { | ... | @@ -675,7 +675,7 @@ pub const Type = extern union { |
| 675 | if (a_info.param_types.len != b_info.param_types.len) | 675 | if (a_info.param_types.len != b_info.param_types.len) |
| 676 | return false; | 676 | return false; |
| 677 | 677 | ||
| 678 | for (a_info.param_types) |a_param_ty, i| { | 678 | for (a_info.param_types, 0..) |a_param_ty, i| { |
| 679 | const b_param_ty = b_info.param_types[i]; | 679 | const b_param_ty = b_info.param_types[i]; |
| 680 | if (a_info.comptime_params[i] != b_info.comptime_params[i]) | 680 | if (a_info.comptime_params[i] != b_info.comptime_params[i]) |
| 681 | return false; | 681 | return false; |
| ... | @@ -824,12 +824,12 @@ pub const Type = extern union { | ... | @@ -824,12 +824,12 @@ pub const Type = extern union { |
| 824 | 824 | ||
| 825 | if (a_tuple.types.len != b_tuple.types.len) return false; | 825 | if (a_tuple.types.len != b_tuple.types.len) return false; |
| 826 | 826 | ||
| 827 | for (a_tuple.types) |a_ty, i| { | 827 | for (a_tuple.types, 0..) |a_ty, i| { |
| 828 | const b_ty = b_tuple.types[i]; | 828 | const b_ty = b_tuple.types[i]; |
| 829 | if (!eql(a_ty, b_ty, mod)) return false; | 829 | if (!eql(a_ty, b_ty, mod)) return false; |
| 830 | } | 830 | } |
| 831 | 831 | ||
| 832 | for (a_tuple.values) |a_val, i| { | 832 | for (a_tuple.values, 0..) |a_val, i| { |
| 833 | const ty = a_tuple.types[i]; | 833 | const ty = a_tuple.types[i]; |
| 834 | const b_val = b_tuple.values[i]; | 834 | const b_val = b_tuple.values[i]; |
| 835 | if (a_val.tag() == .unreachable_value) { | 835 | if (a_val.tag() == .unreachable_value) { |
| ... | @@ -855,17 +855,17 @@ pub const Type = extern union { | ... | @@ -855,17 +855,17 @@ pub const Type = extern union { |
| 855 | 855 | ||
| 856 | if (a_struct_obj.types.len != b_struct_obj.types.len) return false; | 856 | if (a_struct_obj.types.len != b_struct_obj.types.len) return false; |
| 857 | 857 | ||
| 858 | for (a_struct_obj.names) |a_name, i| { | 858 | for (a_struct_obj.names, 0..) |a_name, i| { |
| 859 | const b_name = b_struct_obj.names[i]; | 859 | const b_name = b_struct_obj.names[i]; |
| 860 | if (!std.mem.eql(u8, a_name, b_name)) return false; | 860 | if (!std.mem.eql(u8, a_name, b_name)) return false; |
| 861 | } | 861 | } |
| 862 | 862 | ||
| 863 | for (a_struct_obj.types) |a_ty, i| { | 863 | for (a_struct_obj.types, 0..) |a_ty, i| { |
| 864 | const b_ty = b_struct_obj.types[i]; | 864 | const b_ty = b_struct_obj.types[i]; |
| 865 | if (!eql(a_ty, b_ty, mod)) return false; | 865 | if (!eql(a_ty, b_ty, mod)) return false; |
| 866 | } | 866 | } |
| 867 | 867 | ||
| 868 | for (a_struct_obj.values) |a_val, i| { | 868 | for (a_struct_obj.values, 0..) |a_val, i| { |
| 869 | const ty = a_struct_obj.types[i]; | 869 | const ty = a_struct_obj.types[i]; |
| 870 | const b_val = b_struct_obj.values[i]; | 870 | const b_val = b_struct_obj.values[i]; |
| 871 | if (a_val.tag() == .unreachable_value) { | 871 | if (a_val.tag() == .unreachable_value) { |
| ... | @@ -1073,7 +1073,7 @@ pub const Type = extern union { | ... | @@ -1073,7 +1073,7 @@ pub const Type = extern union { |
| 1073 | std.hash.autoHash(hasher, fn_info.noalias_bits); | 1073 | std.hash.autoHash(hasher, fn_info.noalias_bits); |
| 1074 | 1074 | ||
| 1075 | std.hash.autoHash(hasher, fn_info.param_types.len); | 1075 | std.hash.autoHash(hasher, fn_info.param_types.len); |
| 1076 | for (fn_info.param_types) |param_ty, i| { | 1076 | for (fn_info.param_types, 0..) |param_ty, i| { |
| 1077 | std.hash.autoHash(hasher, fn_info.paramIsComptime(i)); | 1077 | std.hash.autoHash(hasher, fn_info.paramIsComptime(i)); |
| 1078 | if (param_ty.tag() == .generic_poison) continue; | 1078 | if (param_ty.tag() == .generic_poison) continue; |
| 1079 | hashWithHasher(param_ty, hasher, mod); | 1079 | hashWithHasher(param_ty, hasher, mod); |
| ... | @@ -1175,7 +1175,7 @@ pub const Type = extern union { | ... | @@ -1175,7 +1175,7 @@ pub const Type = extern union { |
| 1175 | const tuple = ty.tupleFields(); | 1175 | const tuple = ty.tupleFields(); |
| 1176 | std.hash.autoHash(hasher, tuple.types.len); | 1176 | std.hash.autoHash(hasher, tuple.types.len); |
| 1177 | 1177 | ||
| 1178 | for (tuple.types) |field_ty, i| { | 1178 | for (tuple.types, 0..) |field_ty, i| { |
| 1179 | hashWithHasher(field_ty, hasher, mod); | 1179 | hashWithHasher(field_ty, hasher, mod); |
| 1180 | const field_val = tuple.values[i]; | 1180 | const field_val = tuple.values[i]; |
| 1181 | if (field_val.tag() == .unreachable_value) continue; | 1181 | if (field_val.tag() == .unreachable_value) continue; |
| ... | @@ -1187,7 +1187,7 @@ pub const Type = extern union { | ... | @@ -1187,7 +1187,7 @@ pub const Type = extern union { |
| 1187 | std.hash.autoHash(hasher, std.builtin.TypeId.Struct); | 1187 | std.hash.autoHash(hasher, std.builtin.TypeId.Struct); |
| 1188 | std.hash.autoHash(hasher, struct_obj.types.len); | 1188 | std.hash.autoHash(hasher, struct_obj.types.len); |
| 1189 | 1189 | ||
| 1190 | for (struct_obj.types) |field_ty, i| { | 1190 | for (struct_obj.types, 0..) |field_ty, i| { |
| 1191 | const field_name = struct_obj.names[i]; | 1191 | const field_name = struct_obj.names[i]; |
| 1192 | const field_val = struct_obj.values[i]; | 1192 | const field_val = struct_obj.values[i]; |
| 1193 | hasher.update(field_name); | 1193 | hasher.update(field_name); |
| ... | @@ -1403,10 +1403,10 @@ pub const Type = extern union { | ... | @@ -1403,10 +1403,10 @@ pub const Type = extern union { |
| 1403 | const payload = self.castTag(.tuple).?.data; | 1403 | const payload = self.castTag(.tuple).?.data; |
| 1404 | const types = try allocator.alloc(Type, payload.types.len); | 1404 | const types = try allocator.alloc(Type, payload.types.len); |
| 1405 | const values = try allocator.alloc(Value, payload.values.len); | 1405 | const values = try allocator.alloc(Value, payload.values.len); |
| 1406 | for (payload.types) |ty, i| { | 1406 | for (payload.types, 0..) |ty, i| { |
| 1407 | types[i] = try ty.copy(allocator); | 1407 | types[i] = try ty.copy(allocator); |
| 1408 | } | 1408 | } |
| 1409 | for (payload.values) |val, i| { | 1409 | for (payload.values, 0..) |val, i| { |
| 1410 | values[i] = try val.copy(allocator); | 1410 | values[i] = try val.copy(allocator); |
| 1411 | } | 1411 | } |
| 1412 | return Tag.tuple.create(allocator, .{ | 1412 | return Tag.tuple.create(allocator, .{ |
| ... | @@ -1419,13 +1419,13 @@ pub const Type = extern union { | ... | @@ -1419,13 +1419,13 @@ pub const Type = extern union { |
| 1419 | const names = try allocator.alloc([]const u8, payload.names.len); | 1419 | const names = try allocator.alloc([]const u8, payload.names.len); |
| 1420 | const types = try allocator.alloc(Type, payload.types.len); | 1420 | const types = try allocator.alloc(Type, payload.types.len); |
| 1421 | const values = try allocator.alloc(Value, payload.values.len); | 1421 | const values = try allocator.alloc(Value, payload.values.len); |
| 1422 | for (payload.names) |name, i| { | 1422 | for (payload.names, 0..) |name, i| { |
| 1423 | names[i] = try allocator.dupe(u8, name); | 1423 | names[i] = try allocator.dupe(u8, name); |
| 1424 | } | 1424 | } |
| 1425 | for (payload.types) |ty, i| { | 1425 | for (payload.types, 0..) |ty, i| { |
| 1426 | types[i] = try ty.copy(allocator); | 1426 | types[i] = try ty.copy(allocator); |
| 1427 | } | 1427 | } |
| 1428 | for (payload.values) |val, i| { | 1428 | for (payload.values, 0..) |val, i| { |
| 1429 | values[i] = try val.copy(allocator); | 1429 | values[i] = try val.copy(allocator); |
| 1430 | } | 1430 | } |
| 1431 | return Tag.anon_struct.create(allocator, .{ | 1431 | return Tag.anon_struct.create(allocator, .{ |
| ... | @@ -1437,7 +1437,7 @@ pub const Type = extern union { | ... | @@ -1437,7 +1437,7 @@ pub const Type = extern union { |
| 1437 | .function => { | 1437 | .function => { |
| 1438 | const payload = self.castTag(.function).?.data; | 1438 | const payload = self.castTag(.function).?.data; |
| 1439 | const param_types = try allocator.alloc(Type, payload.param_types.len); | 1439 | const param_types = try allocator.alloc(Type, payload.param_types.len); |
| 1440 | for (payload.param_types) |param_ty, i| { | 1440 | for (payload.param_types, 0..) |param_ty, i| { |
| 1441 | param_types[i] = try param_ty.copy(allocator); | 1441 | param_types[i] = try param_ty.copy(allocator); |
| 1442 | } | 1442 | } |
| 1443 | const other_comptime_params = payload.comptime_params[0..payload.param_types.len]; | 1443 | const other_comptime_params = payload.comptime_params[0..payload.param_types.len]; |
| ... | @@ -1678,7 +1678,7 @@ pub const Type = extern union { | ... | @@ -1678,7 +1678,7 @@ pub const Type = extern union { |
| 1678 | .function => { | 1678 | .function => { |
| 1679 | const payload = ty.castTag(.function).?.data; | 1679 | const payload = ty.castTag(.function).?.data; |
| 1680 | try writer.writeAll("fn("); | 1680 | try writer.writeAll("fn("); |
| 1681 | for (payload.param_types) |param_type, i| { | 1681 | for (payload.param_types, 0..) |param_type, i| { |
| 1682 | if (i != 0) try writer.writeAll(", "); | 1682 | if (i != 0) try writer.writeAll(", "); |
| 1683 | try param_type.dump("", .{}, writer); | 1683 | try param_type.dump("", .{}, writer); |
| 1684 | } | 1684 | } |
| ... | @@ -1739,7 +1739,7 @@ pub const Type = extern union { | ... | @@ -1739,7 +1739,7 @@ pub const Type = extern union { |
| 1739 | .tuple => { | 1739 | .tuple => { |
| 1740 | const tuple = ty.castTag(.tuple).?.data; | 1740 | const tuple = ty.castTag(.tuple).?.data; |
| 1741 | try writer.writeAll("tuple{"); | 1741 | try writer.writeAll("tuple{"); |
| 1742 | for (tuple.types) |field_ty, i| { | 1742 | for (tuple.types, 0..) |field_ty, i| { |
| 1743 | if (i != 0) try writer.writeAll(", "); | 1743 | if (i != 0) try writer.writeAll(", "); |
| 1744 | const val = tuple.values[i]; | 1744 | const val = tuple.values[i]; |
| 1745 | if (val.tag() != .unreachable_value) { | 1745 | if (val.tag() != .unreachable_value) { |
| ... | @@ -1756,7 +1756,7 @@ pub const Type = extern union { | ... | @@ -1756,7 +1756,7 @@ pub const Type = extern union { |
| 1756 | .anon_struct => { | 1756 | .anon_struct => { |
| 1757 | const anon_struct = ty.castTag(.anon_struct).?.data; | 1757 | const anon_struct = ty.castTag(.anon_struct).?.data; |
| 1758 | try writer.writeAll("struct{"); | 1758 | try writer.writeAll("struct{"); |
| 1759 | for (anon_struct.types) |field_ty, i| { | 1759 | for (anon_struct.types, 0..) |field_ty, i| { |
| 1760 | if (i != 0) try writer.writeAll(", "); | 1760 | if (i != 0) try writer.writeAll(", "); |
| 1761 | const val = anon_struct.values[i]; | 1761 | const val = anon_struct.values[i]; |
| 1762 | if (val.tag() != .unreachable_value) { | 1762 | if (val.tag() != .unreachable_value) { |
| ... | @@ -1892,7 +1892,7 @@ pub const Type = extern union { | ... | @@ -1892,7 +1892,7 @@ pub const Type = extern union { |
| 1892 | .error_set => { | 1892 | .error_set => { |
| 1893 | const names = ty.castTag(.error_set).?.data.names.keys(); | 1893 | const names = ty.castTag(.error_set).?.data.names.keys(); |
| 1894 | try writer.writeAll("error{"); | 1894 | try writer.writeAll("error{"); |
| 1895 | for (names) |name, i| { | 1895 | for (names, 0..) |name, i| { |
| 1896 | if (i != 0) try writer.writeByte(','); | 1896 | if (i != 0) try writer.writeByte(','); |
| 1897 | try writer.writeAll(name); | 1897 | try writer.writeAll(name); |
| 1898 | } | 1898 | } |
| ... | @@ -1908,7 +1908,7 @@ pub const Type = extern union { | ... | @@ -1908,7 +1908,7 @@ pub const Type = extern union { |
| 1908 | .error_set_merged => { | 1908 | .error_set_merged => { |
| 1909 | const names = ty.castTag(.error_set_merged).?.data.keys(); | 1909 | const names = ty.castTag(.error_set_merged).?.data.keys(); |
| 1910 | try writer.writeAll("error{"); | 1910 | try writer.writeAll("error{"); |
| 1911 | for (names) |name, i| { | 1911 | for (names, 0..) |name, i| { |
| 1912 | if (i != 0) try writer.writeByte(','); | 1912 | if (i != 0) try writer.writeByte(','); |
| 1913 | try writer.writeAll(name); | 1913 | try writer.writeAll(name); |
| 1914 | } | 1914 | } |
| ... | @@ -2063,7 +2063,7 @@ pub const Type = extern union { | ... | @@ -2063,7 +2063,7 @@ pub const Type = extern union { |
| 2063 | .function => { | 2063 | .function => { |
| 2064 | const fn_info = ty.fnInfo(); | 2064 | const fn_info = ty.fnInfo(); |
| 2065 | try writer.writeAll("fn("); | 2065 | try writer.writeAll("fn("); |
| 2066 | for (fn_info.param_types) |param_ty, i| { | 2066 | for (fn_info.param_types, 0..) |param_ty, i| { |
| 2067 | if (i != 0) try writer.writeAll(", "); | 2067 | if (i != 0) try writer.writeAll(", "); |
| 2068 | if (fn_info.paramIsComptime(i)) { | 2068 | if (fn_info.paramIsComptime(i)) { |
| 2069 | try writer.writeAll("comptime "); | 2069 | try writer.writeAll("comptime "); |
| ... | @@ -2137,7 +2137,7 @@ pub const Type = extern union { | ... | @@ -2137,7 +2137,7 @@ pub const Type = extern union { |
| 2137 | const tuple = ty.castTag(.tuple).?.data; | 2137 | const tuple = ty.castTag(.tuple).?.data; |
| 2138 | 2138 | ||
| 2139 | try writer.writeAll("tuple{"); | 2139 | try writer.writeAll("tuple{"); |
| 2140 | for (tuple.types) |field_ty, i| { | 2140 | for (tuple.types, 0..) |field_ty, i| { |
| 2141 | if (i != 0) try writer.writeAll(", "); | 2141 | if (i != 0) try writer.writeAll(", "); |
| 2142 | const val = tuple.values[i]; | 2142 | const val = tuple.values[i]; |
| 2143 | if (val.tag() != .unreachable_value) { | 2143 | if (val.tag() != .unreachable_value) { |
| ... | @@ -2154,7 +2154,7 @@ pub const Type = extern union { | ... | @@ -2154,7 +2154,7 @@ pub const Type = extern union { |
| 2154 | const anon_struct = ty.castTag(.anon_struct).?.data; | 2154 | const anon_struct = ty.castTag(.anon_struct).?.data; |
| 2155 | 2155 | ||
| 2156 | try writer.writeAll("struct{"); | 2156 | try writer.writeAll("struct{"); |
| 2157 | for (anon_struct.types) |field_ty, i| { | 2157 | for (anon_struct.types, 0..) |field_ty, i| { |
| 2158 | if (i != 0) try writer.writeAll(", "); | 2158 | if (i != 0) try writer.writeAll(", "); |
| 2159 | const val = anon_struct.values[i]; | 2159 | const val = anon_struct.values[i]; |
| 2160 | if (val.tag() != .unreachable_value) { | 2160 | if (val.tag() != .unreachable_value) { |
| ... | @@ -2253,7 +2253,7 @@ pub const Type = extern union { | ... | @@ -2253,7 +2253,7 @@ pub const Type = extern union { |
| 2253 | .error_set => { | 2253 | .error_set => { |
| 2254 | const names = ty.castTag(.error_set).?.data.names.keys(); | 2254 | const names = ty.castTag(.error_set).?.data.names.keys(); |
| 2255 | try writer.writeAll("error{"); | 2255 | try writer.writeAll("error{"); |
| 2256 | for (names) |name, i| { | 2256 | for (names, 0..) |name, i| { |
| 2257 | if (i != 0) try writer.writeByte(','); | 2257 | if (i != 0) try writer.writeByte(','); |
| 2258 | try writer.writeAll(name); | 2258 | try writer.writeAll(name); |
| 2259 | } | 2259 | } |
| ... | @@ -2266,7 +2266,7 @@ pub const Type = extern union { | ... | @@ -2266,7 +2266,7 @@ pub const Type = extern union { |
| 2266 | .error_set_merged => { | 2266 | .error_set_merged => { |
| 2267 | const names = ty.castTag(.error_set_merged).?.data.keys(); | 2267 | const names = ty.castTag(.error_set_merged).?.data.keys(); |
| 2268 | try writer.writeAll("error{"); | 2268 | try writer.writeAll("error{"); |
| 2269 | for (names) |name, i| { | 2269 | for (names, 0..) |name, i| { |
| 2270 | if (i != 0) try writer.writeByte(','); | 2270 | if (i != 0) try writer.writeByte(','); |
| 2271 | try writer.writeAll(name); | 2271 | try writer.writeAll(name); |
| 2272 | } | 2272 | } |
| ... | @@ -2568,7 +2568,7 @@ pub const Type = extern union { | ... | @@ -2568,7 +2568,7 @@ pub const Type = extern union { |
| 2568 | 2568 | ||
| 2569 | .tuple, .anon_struct => { | 2569 | .tuple, .anon_struct => { |
| 2570 | const tuple = ty.tupleFields(); | 2570 | const tuple = ty.tupleFields(); |
| 2571 | for (tuple.types) |field_ty, i| { | 2571 | for (tuple.types, 0..) |field_ty, i| { |
| 2572 | const val = tuple.values[i]; | 2572 | const val = tuple.values[i]; |
| 2573 | if (val.tag() != .unreachable_value) continue; // comptime field | 2573 | if (val.tag() != .unreachable_value) continue; // comptime field |
| 2574 | if (try field_ty.hasRuntimeBitsAdvanced(ignore_comptime_only, strat)) return true; | 2574 | if (try field_ty.hasRuntimeBitsAdvanced(ignore_comptime_only, strat)) return true; |
| ... | @@ -3125,7 +3125,7 @@ pub const Type = extern union { | ... | @@ -3125,7 +3125,7 @@ pub const Type = extern union { |
| 3125 | .tuple, .anon_struct => { | 3125 | .tuple, .anon_struct => { |
| 3126 | const tuple = ty.tupleFields(); | 3126 | const tuple = ty.tupleFields(); |
| 3127 | var big_align: u32 = 0; | 3127 | var big_align: u32 = 0; |
| 3128 | for (tuple.types) |field_ty, i| { | 3128 | for (tuple.types, 0..) |field_ty, i| { |
| 3129 | const val = tuple.values[i]; | 3129 | const val = tuple.values[i]; |
| 3130 | if (val.tag() != .unreachable_value) continue; // comptime field | 3130 | if (val.tag() != .unreachable_value) continue; // comptime field |
| 3131 | if (!(field_ty.hasRuntimeBits())) continue; | 3131 | if (!(field_ty.hasRuntimeBits())) continue; |
| ... | @@ -5044,7 +5044,7 @@ pub const Type = extern union { | ... | @@ -5044,7 +5044,7 @@ pub const Type = extern union { |
| 5044 | 5044 | ||
| 5045 | .tuple, .anon_struct => { | 5045 | .tuple, .anon_struct => { |
| 5046 | const tuple = ty.tupleFields(); | 5046 | const tuple = ty.tupleFields(); |
| 5047 | for (tuple.values) |val, i| { | 5047 | for (tuple.values, 0..) |val, i| { |
| 5048 | const is_comptime = val.tag() != .unreachable_value; | 5048 | const is_comptime = val.tag() != .unreachable_value; |
| 5049 | if (is_comptime) continue; | 5049 | if (is_comptime) continue; |
| 5050 | if (tuple.types[i].onePossibleValue() != null) continue; | 5050 | if (tuple.types[i].onePossibleValue() != null) continue; |
| ... | @@ -5256,7 +5256,7 @@ pub const Type = extern union { | ... | @@ -5256,7 +5256,7 @@ pub const Type = extern union { |
| 5256 | 5256 | ||
| 5257 | .tuple, .anon_struct => { | 5257 | .tuple, .anon_struct => { |
| 5258 | const tuple = ty.tupleFields(); | 5258 | const tuple = ty.tupleFields(); |
| 5259 | for (tuple.types) |field_ty, i| { | 5259 | for (tuple.types, 0..) |field_ty, i| { |
| 5260 | const have_comptime_val = tuple.values[i].tag() != .unreachable_value; | 5260 | const have_comptime_val = tuple.values[i].tag() != .unreachable_value; |
| 5261 | if (!have_comptime_val and field_ty.comptimeOnly()) return true; | 5261 | if (!have_comptime_val and field_ty.comptimeOnly()) return true; |
| 5262 | } | 5262 | } |
| ... | @@ -5326,6 +5326,19 @@ pub const Type = extern union { | ... | @@ -5326,6 +5326,19 @@ pub const Type = extern union { |
| 5326 | }; | 5326 | }; |
| 5327 | } | 5327 | } |
| 5328 | 5328 | ||
| 5329 | pub fn indexableHasLen(ty: Type) bool { | ||
| 5330 | return switch (ty.zigTypeTag()) { | ||
| 5331 | .Array, .Vector => true, | ||
| 5332 | .Pointer => switch (ty.ptrSize()) { | ||
| 5333 | .Many, .C => false, | ||
| 5334 | .Slice => true, | ||
| 5335 | .One => ty.elemType().zigTypeTag() == .Array, | ||
| 5336 | }, | ||
| 5337 | .Struct => ty.isTuple(), | ||
| 5338 | else => false, | ||
| 5339 | }; | ||
| 5340 | } | ||
| 5341 | |||
| 5329 | /// Returns null if the type has no namespace. | 5342 | /// Returns null if the type has no namespace. |
| 5330 | pub fn getNamespace(self: Type) ?*Module.Namespace { | 5343 | pub fn getNamespace(self: Type) ?*Module.Namespace { |
| 5331 | return switch (self.tag()) { | 5344 | return switch (self.tag()) { |
| ... | @@ -5740,7 +5753,7 @@ pub const Type = extern union { | ... | @@ -5740,7 +5753,7 @@ pub const Type = extern union { |
| 5740 | var bit_offset: u16 = undefined; | 5753 | var bit_offset: u16 = undefined; |
| 5741 | var elem_size_bits: u16 = undefined; | 5754 | var elem_size_bits: u16 = undefined; |
| 5742 | var running_bits: u16 = 0; | 5755 | var running_bits: u16 = 0; |
| 5743 | for (struct_obj.fields.values()) |f, i| { | 5756 | for (struct_obj.fields.values(), 0..) |f, i| { |
| 5744 | if (!f.ty.hasRuntimeBits()) continue; | 5757 | if (!f.ty.hasRuntimeBits()) continue; |
| 5745 | 5758 | ||
| 5746 | const field_bits = @intCast(u16, f.ty.bitSize(target)); | 5759 | const field_bits = @intCast(u16, f.ty.bitSize(target)); |
| ... | @@ -5821,7 +5834,7 @@ pub const Type = extern union { | ... | @@ -5821,7 +5834,7 @@ pub const Type = extern union { |
| 5821 | var offset: u64 = 0; | 5834 | var offset: u64 = 0; |
| 5822 | var big_align: u32 = 0; | 5835 | var big_align: u32 = 0; |
| 5823 | 5836 | ||
| 5824 | for (tuple.types) |field_ty, i| { | 5837 | for (tuple.types, 0..) |field_ty, i| { |
| 5825 | const field_val = tuple.values[i]; | 5838 | const field_val = tuple.values[i]; |
| 5826 | if (field_val.tag() != .unreachable_value or !field_ty.hasRuntimeBits()) { | 5839 | if (field_val.tag() != .unreachable_value or !field_ty.hasRuntimeBits()) { |
| 5827 | // comptime field | 5840 | // comptime field |
src/value.zig+75-56| ... | @@ -614,7 +614,7 @@ pub const Value = extern union { | ... | @@ -614,7 +614,7 @@ pub const Value = extern union { |
| 614 | .base = payload.base, | 614 | .base = payload.base, |
| 615 | .data = try arena.alloc(Value, payload.data.len), | 615 | .data = try arena.alloc(Value, payload.data.len), |
| 616 | }; | 616 | }; |
| 617 | for (new_payload.data) |*elem, i| { | 617 | for (new_payload.data, 0..) |*elem, i| { |
| 618 | elem.* = try payload.data[i].copy(arena); | 618 | elem.* = try payload.data[i].copy(arena); |
| 619 | } | 619 | } |
| 620 | return Value{ .ptr_otherwise = &new_payload.base }; | 620 | return Value{ .ptr_otherwise = &new_payload.base }; |
| ... | @@ -891,7 +891,7 @@ pub const Value = extern union { | ... | @@ -891,7 +891,7 @@ pub const Value = extern union { |
| 891 | fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 { | 891 | fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 { |
| 892 | const result = try allocator.alloc(u8, @intCast(usize, len)); | 892 | const result = try allocator.alloc(u8, @intCast(usize, len)); |
| 893 | var elem_value_buf: ElemValueBuffer = undefined; | 893 | var elem_value_buf: ElemValueBuffer = undefined; |
| 894 | for (result) |*elem, i| { | 894 | for (result, 0..) |*elem, i| { |
| 895 | const elem_val = val.elemValueBuffer(mod, i, &elem_value_buf); | 895 | const elem_val = val.elemValueBuffer(mod, i, &elem_value_buf); |
| 896 | elem.* = @intCast(u8, elem_val.toUnsignedInt(mod.getTarget())); | 896 | elem.* = @intCast(u8, elem_val.toUnsignedInt(mod.getTarget())); |
| 897 | } | 897 | } |
| ... | @@ -1282,7 +1282,7 @@ pub const Value = extern union { | ... | @@ -1282,7 +1282,7 @@ pub const Value = extern union { |
| 1282 | .int_i64 => @bitCast(u64, int_val.castTag(.int_i64).?.data), | 1282 | .int_i64 => @bitCast(u64, int_val.castTag(.int_i64).?.data), |
| 1283 | else => unreachable, | 1283 | else => unreachable, |
| 1284 | }; | 1284 | }; |
| 1285 | for (buffer[0..byte_count]) |_, i| switch (endian) { | 1285 | for (buffer[0..byte_count], 0..) |_, i| switch (endian) { |
| 1286 | .Little => buffer[i] = @truncate(u8, (int >> @intCast(u6, (8 * i)))), | 1286 | .Little => buffer[i] = @truncate(u8, (int >> @intCast(u6, (8 * i)))), |
| 1287 | .Big => buffer[byte_count - i - 1] = @truncate(u8, (int >> @intCast(u6, (8 * i)))), | 1287 | .Big => buffer[byte_count - i - 1] = @truncate(u8, (int >> @intCast(u6, (8 * i)))), |
| 1288 | }; | 1288 | }; |
| ... | @@ -1324,7 +1324,7 @@ pub const Value = extern union { | ... | @@ -1324,7 +1324,7 @@ pub const Value = extern union { |
| 1324 | .Extern => { | 1324 | .Extern => { |
| 1325 | const fields = ty.structFields().values(); | 1325 | const fields = ty.structFields().values(); |
| 1326 | const field_vals = val.castTag(.aggregate).?.data; | 1326 | const field_vals = val.castTag(.aggregate).?.data; |
| 1327 | for (fields) |field, i| { | 1327 | for (fields, 0..) |field, i| { |
| 1328 | const off = @intCast(usize, ty.structFieldOffset(i, target)); | 1328 | const off = @intCast(usize, ty.structFieldOffset(i, target)); |
| 1329 | writeToMemory(field_vals[i], field.ty, mod, buffer[off..]); | 1329 | writeToMemory(field_vals[i], field.ty, mod, buffer[off..]); |
| 1330 | } | 1330 | } |
| ... | @@ -1340,6 +1340,14 @@ pub const Value = extern union { | ... | @@ -1340,6 +1340,14 @@ pub const Value = extern union { |
| 1340 | const int = mod.global_error_set.get(val.castTag(.@"error").?.data.name).?; | 1340 | const int = mod.global_error_set.get(val.castTag(.@"error").?.data.name).?; |
| 1341 | std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @intCast(Int, int), endian); | 1341 | std.mem.writeInt(Int, buffer[0..@sizeOf(Int)], @intCast(Int, int), endian); |
| 1342 | }, | 1342 | }, |
| 1343 | .Union => switch (ty.containerLayout()) { | ||
| 1344 | .Auto => unreachable, | ||
| 1345 | .Extern => @panic("TODO implement writeToMemory for extern unions"), | ||
| 1346 | .Packed => { | ||
| 1347 | const byte_count = (@intCast(usize, ty.bitSize(target)) + 7) / 8; | ||
| 1348 | writeToPackedMemory(val, ty, mod, buffer[0..byte_count], 0); | ||
| 1349 | }, | ||
| 1350 | }, | ||
| 1343 | else => @panic("TODO implement writeToMemory for more types"), | 1351 | else => @panic("TODO implement writeToMemory for more types"), |
| 1344 | } | 1352 | } |
| 1345 | } | 1353 | } |
| ... | @@ -1423,13 +1431,24 @@ pub const Value = extern union { | ... | @@ -1423,13 +1431,24 @@ pub const Value = extern union { |
| 1423 | var bits: u16 = 0; | 1431 | var bits: u16 = 0; |
| 1424 | const fields = ty.structFields().values(); | 1432 | const fields = ty.structFields().values(); |
| 1425 | const field_vals = val.castTag(.aggregate).?.data; | 1433 | const field_vals = val.castTag(.aggregate).?.data; |
| 1426 | for (fields) |field, i| { | 1434 | for (fields, 0..) |field, i| { |
| 1427 | const field_bits = @intCast(u16, field.ty.bitSize(target)); | 1435 | const field_bits = @intCast(u16, field.ty.bitSize(target)); |
| 1428 | field_vals[i].writeToPackedMemory(field.ty, mod, buffer, bit_offset + bits); | 1436 | field_vals[i].writeToPackedMemory(field.ty, mod, buffer, bit_offset + bits); |
| 1429 | bits += field_bits; | 1437 | bits += field_bits; |
| 1430 | } | 1438 | } |
| 1431 | }, | 1439 | }, |
| 1432 | }, | 1440 | }, |
| 1441 | .Union => switch (ty.containerLayout()) { | ||
| 1442 | .Auto => unreachable, // Sema is supposed to have emitted a compile error already | ||
| 1443 | .Extern => unreachable, // Handled in non-packed writeToMemory | ||
| 1444 | .Packed => { | ||
| 1445 | const field_index = ty.unionTagFieldIndex(val.unionTag(), mod); | ||
| 1446 | const field_type = ty.unionFields().values()[field_index.?].ty; | ||
| 1447 | const field_val = val.fieldValue(field_type, field_index.?); | ||
| 1448 | |||
| 1449 | field_val.writeToPackedMemory(field_type, mod, buffer, bit_offset); | ||
| 1450 | }, | ||
| 1451 | }, | ||
| 1433 | else => @panic("TODO implement writeToPackedMemory for more types"), | 1452 | else => @panic("TODO implement writeToPackedMemory for more types"), |
| 1434 | } | 1453 | } |
| 1435 | } | 1454 | } |
| ... | @@ -1510,7 +1529,7 @@ pub const Value = extern union { | ... | @@ -1510,7 +1529,7 @@ pub const Value = extern union { |
| 1510 | .Extern => { | 1529 | .Extern => { |
| 1511 | const fields = ty.structFields().values(); | 1530 | const fields = ty.structFields().values(); |
| 1512 | const field_vals = try arena.alloc(Value, fields.len); | 1531 | const field_vals = try arena.alloc(Value, fields.len); |
| 1513 | for (fields) |field, i| { | 1532 | for (fields, 0..) |field, i| { |
| 1514 | const off = @intCast(usize, ty.structFieldOffset(i, target)); | 1533 | const off = @intCast(usize, ty.structFieldOffset(i, target)); |
| 1515 | const sz = @intCast(usize, ty.structFieldType(i).abiSize(target)); | 1534 | const sz = @intCast(usize, ty.structFieldType(i).abiSize(target)); |
| 1516 | field_vals[i] = try readFromMemory(field.ty, mod, buffer[off..(off + sz)], arena); | 1535 | field_vals[i] = try readFromMemory(field.ty, mod, buffer[off..(off + sz)], arena); |
| ... | @@ -1598,7 +1617,7 @@ pub const Value = extern union { | ... | @@ -1598,7 +1617,7 @@ pub const Value = extern union { |
| 1598 | 1617 | ||
| 1599 | var bits: u16 = 0; | 1618 | var bits: u16 = 0; |
| 1600 | const elem_bit_size = @intCast(u16, elem_ty.bitSize(target)); | 1619 | const elem_bit_size = @intCast(u16, elem_ty.bitSize(target)); |
| 1601 | for (elems) |_, i| { | 1620 | for (elems, 0..) |_, i| { |
| 1602 | // On big-endian systems, LLVM reverses the element order of vectors by default | 1621 | // On big-endian systems, LLVM reverses the element order of vectors by default |
| 1603 | const tgt_elem_i = if (endian == .Big) elems.len - i - 1 else i; | 1622 | const tgt_elem_i = if (endian == .Big) elems.len - i - 1 else i; |
| 1604 | elems[tgt_elem_i] = try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena); | 1623 | elems[tgt_elem_i] = try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena); |
| ... | @@ -1613,7 +1632,7 @@ pub const Value = extern union { | ... | @@ -1613,7 +1632,7 @@ pub const Value = extern union { |
| 1613 | var bits: u16 = 0; | 1632 | var bits: u16 = 0; |
| 1614 | const fields = ty.structFields().values(); | 1633 | const fields = ty.structFields().values(); |
| 1615 | const field_vals = try arena.alloc(Value, fields.len); | 1634 | const field_vals = try arena.alloc(Value, fields.len); |
| 1616 | for (fields) |field, i| { | 1635 | for (fields, 0..) |field, i| { |
| 1617 | const field_bits = @intCast(u16, field.ty.bitSize(target)); | 1636 | const field_bits = @intCast(u16, field.ty.bitSize(target)); |
| 1618 | field_vals[i] = try readFromPackedMemory(field.ty, mod, buffer, bit_offset + bits, arena); | 1637 | field_vals[i] = try readFromPackedMemory(field.ty, mod, buffer, bit_offset + bits, arena); |
| 1619 | bits += field_bits; | 1638 | bits += field_bits; |
| ... | @@ -2240,7 +2259,7 @@ pub const Value = extern union { | ... | @@ -2240,7 +2259,7 @@ pub const Value = extern union { |
| 2240 | if (ty.isSimpleTupleOrAnonStruct()) { | 2259 | if (ty.isSimpleTupleOrAnonStruct()) { |
| 2241 | const types = ty.tupleFields().types; | 2260 | const types = ty.tupleFields().types; |
| 2242 | assert(types.len == a_field_vals.len); | 2261 | assert(types.len == a_field_vals.len); |
| 2243 | for (types) |field_ty, i| { | 2262 | for (types, 0..) |field_ty, i| { |
| 2244 | if (!(try eqlAdvanced(a_field_vals[i], field_ty, b_field_vals[i], field_ty, mod, opt_sema))) { | 2263 | if (!(try eqlAdvanced(a_field_vals[i], field_ty, b_field_vals[i], field_ty, mod, opt_sema))) { |
| 2245 | return false; | 2264 | return false; |
| 2246 | } | 2265 | } |
| ... | @@ -2251,7 +2270,7 @@ pub const Value = extern union { | ... | @@ -2251,7 +2270,7 @@ pub const Value = extern union { |
| 2251 | if (ty.zigTypeTag() == .Struct) { | 2270 | if (ty.zigTypeTag() == .Struct) { |
| 2252 | const fields = ty.structFields().values(); | 2271 | const fields = ty.structFields().values(); |
| 2253 | assert(fields.len == a_field_vals.len); | 2272 | assert(fields.len == a_field_vals.len); |
| 2254 | for (fields) |field, i| { | 2273 | for (fields, 0..) |field, i| { |
| 2255 | if (!(try eqlAdvanced(a_field_vals[i], field.ty, b_field_vals[i], field.ty, mod, opt_sema))) { | 2274 | if (!(try eqlAdvanced(a_field_vals[i], field.ty, b_field_vals[i], field.ty, mod, opt_sema))) { |
| 2256 | return false; | 2275 | return false; |
| 2257 | } | 2276 | } |
| ... | @@ -2260,7 +2279,7 @@ pub const Value = extern union { | ... | @@ -2260,7 +2279,7 @@ pub const Value = extern union { |
| 2260 | } | 2279 | } |
| 2261 | 2280 | ||
| 2262 | const elem_ty = ty.childType(); | 2281 | const elem_ty = ty.childType(); |
| 2263 | for (a_field_vals) |a_elem, i| { | 2282 | for (a_field_vals, 0..) |a_elem, i| { |
| 2264 | const b_elem = b_field_vals[i]; | 2283 | const b_elem = b_field_vals[i]; |
| 2265 | 2284 | ||
| 2266 | if (!(try eqlAdvanced(a_elem, elem_ty, b_elem, elem_ty, mod, opt_sema))) { | 2285 | if (!(try eqlAdvanced(a_elem, elem_ty, b_elem, elem_ty, mod, opt_sema))) { |
| ... | @@ -2507,7 +2526,7 @@ pub const Value = extern union { | ... | @@ -2507,7 +2526,7 @@ pub const Value = extern union { |
| 2507 | .empty_struct_value => {}, | 2526 | .empty_struct_value => {}, |
| 2508 | .aggregate => { | 2527 | .aggregate => { |
| 2509 | const field_values = val.castTag(.aggregate).?.data; | 2528 | const field_values = val.castTag(.aggregate).?.data; |
| 2510 | for (field_values) |field_val, i| { | 2529 | for (field_values, 0..) |field_val, i| { |
| 2511 | const field_ty = ty.structFieldType(i); | 2530 | const field_ty = ty.structFieldType(i); |
| 2512 | field_val.hash(field_ty, hasher, mod); | 2531 | field_val.hash(field_ty, hasher, mod); |
| 2513 | } | 2532 | } |
| ... | @@ -3209,7 +3228,7 @@ pub const Value = extern union { | ... | @@ -3209,7 +3228,7 @@ pub const Value = extern union { |
| 3209 | const target = mod.getTarget(); | 3228 | const target = mod.getTarget(); |
| 3210 | if (int_ty.zigTypeTag() == .Vector) { | 3229 | if (int_ty.zigTypeTag() == .Vector) { |
| 3211 | const result_data = try arena.alloc(Value, int_ty.vectorLen()); | 3230 | const result_data = try arena.alloc(Value, int_ty.vectorLen()); |
| 3212 | for (result_data) |*scalar, i| { | 3231 | for (result_data, 0..) |*scalar, i| { |
| 3213 | var buf: Value.ElemValueBuffer = undefined; | 3232 | var buf: Value.ElemValueBuffer = undefined; |
| 3214 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 3233 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 3215 | scalar.* = try intToFloatScalar(elem_val, arena, float_ty.scalarType(), target, opt_sema); | 3234 | scalar.* = try intToFloatScalar(elem_val, arena, float_ty.scalarType(), target, opt_sema); |
| ... | @@ -3322,7 +3341,7 @@ pub const Value = extern union { | ... | @@ -3322,7 +3341,7 @@ pub const Value = extern union { |
| 3322 | const target = mod.getTarget(); | 3341 | const target = mod.getTarget(); |
| 3323 | if (ty.zigTypeTag() == .Vector) { | 3342 | if (ty.zigTypeTag() == .Vector) { |
| 3324 | const result_data = try arena.alloc(Value, ty.vectorLen()); | 3343 | const result_data = try arena.alloc(Value, ty.vectorLen()); |
| 3325 | for (result_data) |*scalar, i| { | 3344 | for (result_data, 0..) |*scalar, i| { |
| 3326 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3345 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3327 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3346 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3328 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3347 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3371,7 +3390,7 @@ pub const Value = extern union { | ... | @@ -3371,7 +3390,7 @@ pub const Value = extern union { |
| 3371 | const target = mod.getTarget(); | 3390 | const target = mod.getTarget(); |
| 3372 | if (ty.zigTypeTag() == .Vector) { | 3391 | if (ty.zigTypeTag() == .Vector) { |
| 3373 | const result_data = try arena.alloc(Value, ty.vectorLen()); | 3392 | const result_data = try arena.alloc(Value, ty.vectorLen()); |
| 3374 | for (result_data) |*scalar, i| { | 3393 | for (result_data, 0..) |*scalar, i| { |
| 3375 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3394 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3376 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3395 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3377 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3396 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3420,7 +3439,7 @@ pub const Value = extern union { | ... | @@ -3420,7 +3439,7 @@ pub const Value = extern union { |
| 3420 | if (ty.zigTypeTag() == .Vector) { | 3439 | if (ty.zigTypeTag() == .Vector) { |
| 3421 | const overflowed_data = try arena.alloc(Value, ty.vectorLen()); | 3440 | const overflowed_data = try arena.alloc(Value, ty.vectorLen()); |
| 3422 | const result_data = try arena.alloc(Value, ty.vectorLen()); | 3441 | const result_data = try arena.alloc(Value, ty.vectorLen()); |
| 3423 | for (result_data) |*scalar, i| { | 3442 | for (result_data, 0..) |*scalar, i| { |
| 3424 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3443 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3425 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3444 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3426 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3445 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3482,7 +3501,7 @@ pub const Value = extern union { | ... | @@ -3482,7 +3501,7 @@ pub const Value = extern union { |
| 3482 | ) !Value { | 3501 | ) !Value { |
| 3483 | if (ty.zigTypeTag() == .Vector) { | 3502 | if (ty.zigTypeTag() == .Vector) { |
| 3484 | const result_data = try arena.alloc(Value, ty.vectorLen()); | 3503 | const result_data = try arena.alloc(Value, ty.vectorLen()); |
| 3485 | for (result_data) |*scalar, i| { | 3504 | for (result_data, 0..) |*scalar, i| { |
| 3486 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3505 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3487 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3506 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3488 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3507 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3527,7 +3546,7 @@ pub const Value = extern union { | ... | @@ -3527,7 +3546,7 @@ pub const Value = extern union { |
| 3527 | const target = mod.getTarget(); | 3546 | const target = mod.getTarget(); |
| 3528 | if (ty.zigTypeTag() == .Vector) { | 3547 | if (ty.zigTypeTag() == .Vector) { |
| 3529 | const result_data = try arena.alloc(Value, ty.vectorLen()); | 3548 | const result_data = try arena.alloc(Value, ty.vectorLen()); |
| 3530 | for (result_data) |*scalar, i| { | 3549 | for (result_data, 0..) |*scalar, i| { |
| 3531 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3550 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3532 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3551 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3533 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3552 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3603,7 +3622,7 @@ pub const Value = extern union { | ... | @@ -3603,7 +3622,7 @@ pub const Value = extern union { |
| 3603 | const target = mod.getTarget(); | 3622 | const target = mod.getTarget(); |
| 3604 | if (ty.zigTypeTag() == .Vector) { | 3623 | if (ty.zigTypeTag() == .Vector) { |
| 3605 | const result_data = try arena.alloc(Value, ty.vectorLen()); | 3624 | const result_data = try arena.alloc(Value, ty.vectorLen()); |
| 3606 | for (result_data) |*scalar, i| { | 3625 | for (result_data, 0..) |*scalar, i| { |
| 3607 | var buf: Value.ElemValueBuffer = undefined; | 3626 | var buf: Value.ElemValueBuffer = undefined; |
| 3608 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 3627 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 3609 | scalar.* = try bitwiseNotScalar(elem_val, ty.scalarType(), arena, target); | 3628 | scalar.* = try bitwiseNotScalar(elem_val, ty.scalarType(), arena, target); |
| ... | @@ -3642,7 +3661,7 @@ pub const Value = extern union { | ... | @@ -3642,7 +3661,7 @@ pub const Value = extern union { |
| 3642 | const target = mod.getTarget(); | 3661 | const target = mod.getTarget(); |
| 3643 | if (ty.zigTypeTag() == .Vector) { | 3662 | if (ty.zigTypeTag() == .Vector) { |
| 3644 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 3663 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 3645 | for (result_data) |*scalar, i| { | 3664 | for (result_data, 0..) |*scalar, i| { |
| 3646 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3665 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3647 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3666 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3648 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3667 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3678,7 +3697,7 @@ pub const Value = extern union { | ... | @@ -3678,7 +3697,7 @@ pub const Value = extern union { |
| 3678 | pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value { | 3697 | pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value { |
| 3679 | if (ty.zigTypeTag() == .Vector) { | 3698 | if (ty.zigTypeTag() == .Vector) { |
| 3680 | const result_data = try arena.alloc(Value, ty.vectorLen()); | 3699 | const result_data = try arena.alloc(Value, ty.vectorLen()); |
| 3681 | for (result_data) |*scalar, i| { | 3700 | for (result_data, 0..) |*scalar, i| { |
| 3682 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3701 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3683 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3702 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3684 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3703 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3709,7 +3728,7 @@ pub const Value = extern union { | ... | @@ -3709,7 +3728,7 @@ pub const Value = extern union { |
| 3709 | const target = mod.getTarget(); | 3728 | const target = mod.getTarget(); |
| 3710 | if (ty.zigTypeTag() == .Vector) { | 3729 | if (ty.zigTypeTag() == .Vector) { |
| 3711 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 3730 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 3712 | for (result_data) |*scalar, i| { | 3731 | for (result_data, 0..) |*scalar, i| { |
| 3713 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3732 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3714 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3733 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3715 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3734 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3745,7 +3764,7 @@ pub const Value = extern union { | ... | @@ -3745,7 +3764,7 @@ pub const Value = extern union { |
| 3745 | const target = mod.getTarget(); | 3764 | const target = mod.getTarget(); |
| 3746 | if (ty.zigTypeTag() == .Vector) { | 3765 | if (ty.zigTypeTag() == .Vector) { |
| 3747 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 3766 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 3748 | for (result_data) |*scalar, i| { | 3767 | for (result_data, 0..) |*scalar, i| { |
| 3749 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3768 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3750 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3769 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3751 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3770 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3781,7 +3800,7 @@ pub const Value = extern union { | ... | @@ -3781,7 +3800,7 @@ pub const Value = extern union { |
| 3781 | const target = mod.getTarget(); | 3800 | const target = mod.getTarget(); |
| 3782 | if (ty.zigTypeTag() == .Vector) { | 3801 | if (ty.zigTypeTag() == .Vector) { |
| 3783 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 3802 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 3784 | for (result_data) |*scalar, i| { | 3803 | for (result_data, 0..) |*scalar, i| { |
| 3785 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3804 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3786 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3805 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3787 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3806 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3822,7 +3841,7 @@ pub const Value = extern union { | ... | @@ -3822,7 +3841,7 @@ pub const Value = extern union { |
| 3822 | const target = mod.getTarget(); | 3841 | const target = mod.getTarget(); |
| 3823 | if (ty.zigTypeTag() == .Vector) { | 3842 | if (ty.zigTypeTag() == .Vector) { |
| 3824 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 3843 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 3825 | for (result_data) |*scalar, i| { | 3844 | for (result_data, 0..) |*scalar, i| { |
| 3826 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3845 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3827 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3846 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3828 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3847 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3863,7 +3882,7 @@ pub const Value = extern union { | ... | @@ -3863,7 +3882,7 @@ pub const Value = extern union { |
| 3863 | const target = mod.getTarget(); | 3882 | const target = mod.getTarget(); |
| 3864 | if (ty.zigTypeTag() == .Vector) { | 3883 | if (ty.zigTypeTag() == .Vector) { |
| 3865 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 3884 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 3866 | for (result_data) |*scalar, i| { | 3885 | for (result_data, 0..) |*scalar, i| { |
| 3867 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3886 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3868 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3887 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3869 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3888 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3939,7 +3958,7 @@ pub const Value = extern union { | ... | @@ -3939,7 +3958,7 @@ pub const Value = extern union { |
| 3939 | const target = mod.getTarget(); | 3958 | const target = mod.getTarget(); |
| 3940 | if (float_type.zigTypeTag() == .Vector) { | 3959 | if (float_type.zigTypeTag() == .Vector) { |
| 3941 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 3960 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 3942 | for (result_data) |*scalar, i| { | 3961 | for (result_data, 0..) |*scalar, i| { |
| 3943 | var lhs_buf: Value.ElemValueBuffer = undefined; | 3962 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3944 | var rhs_buf: Value.ElemValueBuffer = undefined; | 3963 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3945 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 3964 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -3986,7 +4005,7 @@ pub const Value = extern union { | ... | @@ -3986,7 +4005,7 @@ pub const Value = extern union { |
| 3986 | const target = mod.getTarget(); | 4005 | const target = mod.getTarget(); |
| 3987 | if (float_type.zigTypeTag() == .Vector) { | 4006 | if (float_type.zigTypeTag() == .Vector) { |
| 3988 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4007 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 3989 | for (result_data) |*scalar, i| { | 4008 | for (result_data, 0..) |*scalar, i| { |
| 3990 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4009 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 3991 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4010 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 3992 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4011 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4033,7 +4052,7 @@ pub const Value = extern union { | ... | @@ -4033,7 +4052,7 @@ pub const Value = extern union { |
| 4033 | const target = mod.getTarget(); | 4052 | const target = mod.getTarget(); |
| 4034 | if (ty.zigTypeTag() == .Vector) { | 4053 | if (ty.zigTypeTag() == .Vector) { |
| 4035 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 4054 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 4036 | for (result_data) |*scalar, i| { | 4055 | for (result_data, 0..) |*scalar, i| { |
| 4037 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4056 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 4038 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4057 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 4039 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4058 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4070,7 +4089,7 @@ pub const Value = extern union { | ... | @@ -4070,7 +4089,7 @@ pub const Value = extern union { |
| 4070 | const target = mod.getTarget(); | 4089 | const target = mod.getTarget(); |
| 4071 | if (ty.zigTypeTag() == .Vector) { | 4090 | if (ty.zigTypeTag() == .Vector) { |
| 4072 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 4091 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 4073 | for (result_data) |*scalar, i| { | 4092 | for (result_data, 0..) |*scalar, i| { |
| 4074 | var buf: Value.ElemValueBuffer = undefined; | 4093 | var buf: Value.ElemValueBuffer = undefined; |
| 4075 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4094 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4076 | scalar.* = try intTruncScalar(elem_val, allocator, signedness, bits, target); | 4095 | scalar.* = try intTruncScalar(elem_val, allocator, signedness, bits, target); |
| ... | @@ -4092,7 +4111,7 @@ pub const Value = extern union { | ... | @@ -4092,7 +4111,7 @@ pub const Value = extern union { |
| 4092 | const target = mod.getTarget(); | 4111 | const target = mod.getTarget(); |
| 4093 | if (ty.zigTypeTag() == .Vector) { | 4112 | if (ty.zigTypeTag() == .Vector) { |
| 4094 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 4113 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 4095 | for (result_data) |*scalar, i| { | 4114 | for (result_data, 0..) |*scalar, i| { |
| 4096 | var buf: Value.ElemValueBuffer = undefined; | 4115 | var buf: Value.ElemValueBuffer = undefined; |
| 4097 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4116 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4098 | var bits_buf: Value.ElemValueBuffer = undefined; | 4117 | var bits_buf: Value.ElemValueBuffer = undefined; |
| ... | @@ -4124,7 +4143,7 @@ pub const Value = extern union { | ... | @@ -4124,7 +4143,7 @@ pub const Value = extern union { |
| 4124 | const target = mod.getTarget(); | 4143 | const target = mod.getTarget(); |
| 4125 | if (ty.zigTypeTag() == .Vector) { | 4144 | if (ty.zigTypeTag() == .Vector) { |
| 4126 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 4145 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 4127 | for (result_data) |*scalar, i| { | 4146 | for (result_data, 0..) |*scalar, i| { |
| 4128 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4147 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 4129 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4148 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 4130 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4149 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4166,7 +4185,7 @@ pub const Value = extern union { | ... | @@ -4166,7 +4185,7 @@ pub const Value = extern union { |
| 4166 | if (ty.zigTypeTag() == .Vector) { | 4185 | if (ty.zigTypeTag() == .Vector) { |
| 4167 | const overflowed_data = try allocator.alloc(Value, ty.vectorLen()); | 4186 | const overflowed_data = try allocator.alloc(Value, ty.vectorLen()); |
| 4168 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 4187 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 4169 | for (result_data) |*scalar, i| { | 4188 | for (result_data, 0..) |*scalar, i| { |
| 4170 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4189 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 4171 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4190 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 4172 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4191 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4224,7 +4243,7 @@ pub const Value = extern union { | ... | @@ -4224,7 +4243,7 @@ pub const Value = extern union { |
| 4224 | const target = mod.getTarget(); | 4243 | const target = mod.getTarget(); |
| 4225 | if (ty.zigTypeTag() == .Vector) { | 4244 | if (ty.zigTypeTag() == .Vector) { |
| 4226 | const result_data = try arena.alloc(Value, ty.vectorLen()); | 4245 | const result_data = try arena.alloc(Value, ty.vectorLen()); |
| 4227 | for (result_data) |*scalar, i| { | 4246 | for (result_data, 0..) |*scalar, i| { |
| 4228 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4247 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 4229 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4248 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 4230 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4249 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4272,7 +4291,7 @@ pub const Value = extern union { | ... | @@ -4272,7 +4291,7 @@ pub const Value = extern union { |
| 4272 | ) !Value { | 4291 | ) !Value { |
| 4273 | if (ty.zigTypeTag() == .Vector) { | 4292 | if (ty.zigTypeTag() == .Vector) { |
| 4274 | const result_data = try arena.alloc(Value, ty.vectorLen()); | 4293 | const result_data = try arena.alloc(Value, ty.vectorLen()); |
| 4275 | for (result_data) |*scalar, i| { | 4294 | for (result_data, 0..) |*scalar, i| { |
| 4276 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4295 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 4277 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4296 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 4278 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4297 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4301,7 +4320,7 @@ pub const Value = extern union { | ... | @@ -4301,7 +4320,7 @@ pub const Value = extern union { |
| 4301 | const target = mod.getTarget(); | 4320 | const target = mod.getTarget(); |
| 4302 | if (ty.zigTypeTag() == .Vector) { | 4321 | if (ty.zigTypeTag() == .Vector) { |
| 4303 | const result_data = try allocator.alloc(Value, ty.vectorLen()); | 4322 | const result_data = try allocator.alloc(Value, ty.vectorLen()); |
| 4304 | for (result_data) |*scalar, i| { | 4323 | for (result_data, 0..) |*scalar, i| { |
| 4305 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4324 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 4306 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4325 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 4307 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4326 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4353,7 +4372,7 @@ pub const Value = extern union { | ... | @@ -4353,7 +4372,7 @@ pub const Value = extern union { |
| 4353 | const target = mod.getTarget(); | 4372 | const target = mod.getTarget(); |
| 4354 | if (float_type.zigTypeTag() == .Vector) { | 4373 | if (float_type.zigTypeTag() == .Vector) { |
| 4355 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4374 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4356 | for (result_data) |*scalar, i| { | 4375 | for (result_data, 0..) |*scalar, i| { |
| 4357 | var buf: Value.ElemValueBuffer = undefined; | 4376 | var buf: Value.ElemValueBuffer = undefined; |
| 4358 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4377 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4359 | scalar.* = try floatNegScalar(elem_val, float_type.scalarType(), arena, target); | 4378 | scalar.* = try floatNegScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -4389,7 +4408,7 @@ pub const Value = extern union { | ... | @@ -4389,7 +4408,7 @@ pub const Value = extern union { |
| 4389 | const target = mod.getTarget(); | 4408 | const target = mod.getTarget(); |
| 4390 | if (float_type.zigTypeTag() == .Vector) { | 4409 | if (float_type.zigTypeTag() == .Vector) { |
| 4391 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4410 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4392 | for (result_data) |*scalar, i| { | 4411 | for (result_data, 0..) |*scalar, i| { |
| 4393 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4412 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 4394 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4413 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 4395 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4414 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4448,7 +4467,7 @@ pub const Value = extern union { | ... | @@ -4448,7 +4467,7 @@ pub const Value = extern union { |
| 4448 | const target = mod.getTarget(); | 4467 | const target = mod.getTarget(); |
| 4449 | if (float_type.zigTypeTag() == .Vector) { | 4468 | if (float_type.zigTypeTag() == .Vector) { |
| 4450 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4469 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4451 | for (result_data) |*scalar, i| { | 4470 | for (result_data, 0..) |*scalar, i| { |
| 4452 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4471 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 4453 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4472 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 4454 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4473 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4507,7 +4526,7 @@ pub const Value = extern union { | ... | @@ -4507,7 +4526,7 @@ pub const Value = extern union { |
| 4507 | const target = mod.getTarget(); | 4526 | const target = mod.getTarget(); |
| 4508 | if (float_type.zigTypeTag() == .Vector) { | 4527 | if (float_type.zigTypeTag() == .Vector) { |
| 4509 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4528 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4510 | for (result_data) |*scalar, i| { | 4529 | for (result_data, 0..) |*scalar, i| { |
| 4511 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4530 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 4512 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4531 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 4513 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4532 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4566,7 +4585,7 @@ pub const Value = extern union { | ... | @@ -4566,7 +4585,7 @@ pub const Value = extern union { |
| 4566 | const target = mod.getTarget(); | 4585 | const target = mod.getTarget(); |
| 4567 | if (float_type.zigTypeTag() == .Vector) { | 4586 | if (float_type.zigTypeTag() == .Vector) { |
| 4568 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4587 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4569 | for (result_data) |*scalar, i| { | 4588 | for (result_data, 0..) |*scalar, i| { |
| 4570 | var lhs_buf: Value.ElemValueBuffer = undefined; | 4589 | var lhs_buf: Value.ElemValueBuffer = undefined; |
| 4571 | var rhs_buf: Value.ElemValueBuffer = undefined; | 4590 | var rhs_buf: Value.ElemValueBuffer = undefined; |
| 4572 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); | 4591 | const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf); |
| ... | @@ -4619,7 +4638,7 @@ pub const Value = extern union { | ... | @@ -4619,7 +4638,7 @@ pub const Value = extern union { |
| 4619 | const target = mod.getTarget(); | 4638 | const target = mod.getTarget(); |
| 4620 | if (float_type.zigTypeTag() == .Vector) { | 4639 | if (float_type.zigTypeTag() == .Vector) { |
| 4621 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4640 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4622 | for (result_data) |*scalar, i| { | 4641 | for (result_data, 0..) |*scalar, i| { |
| 4623 | var buf: Value.ElemValueBuffer = undefined; | 4642 | var buf: Value.ElemValueBuffer = undefined; |
| 4624 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4643 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4625 | scalar.* = try sqrtScalar(elem_val, float_type.scalarType(), arena, target); | 4644 | scalar.* = try sqrtScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -4659,7 +4678,7 @@ pub const Value = extern union { | ... | @@ -4659,7 +4678,7 @@ pub const Value = extern union { |
| 4659 | const target = mod.getTarget(); | 4678 | const target = mod.getTarget(); |
| 4660 | if (float_type.zigTypeTag() == .Vector) { | 4679 | if (float_type.zigTypeTag() == .Vector) { |
| 4661 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4680 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4662 | for (result_data) |*scalar, i| { | 4681 | for (result_data, 0..) |*scalar, i| { |
| 4663 | var buf: Value.ElemValueBuffer = undefined; | 4682 | var buf: Value.ElemValueBuffer = undefined; |
| 4664 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4683 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4665 | scalar.* = try sinScalar(elem_val, float_type.scalarType(), arena, target); | 4684 | scalar.* = try sinScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -4699,7 +4718,7 @@ pub const Value = extern union { | ... | @@ -4699,7 +4718,7 @@ pub const Value = extern union { |
| 4699 | const target = mod.getTarget(); | 4718 | const target = mod.getTarget(); |
| 4700 | if (float_type.zigTypeTag() == .Vector) { | 4719 | if (float_type.zigTypeTag() == .Vector) { |
| 4701 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4720 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4702 | for (result_data) |*scalar, i| { | 4721 | for (result_data, 0..) |*scalar, i| { |
| 4703 | var buf: Value.ElemValueBuffer = undefined; | 4722 | var buf: Value.ElemValueBuffer = undefined; |
| 4704 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4723 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4705 | scalar.* = try cosScalar(elem_val, float_type.scalarType(), arena, target); | 4724 | scalar.* = try cosScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -4739,7 +4758,7 @@ pub const Value = extern union { | ... | @@ -4739,7 +4758,7 @@ pub const Value = extern union { |
| 4739 | const target = mod.getTarget(); | 4758 | const target = mod.getTarget(); |
| 4740 | if (float_type.zigTypeTag() == .Vector) { | 4759 | if (float_type.zigTypeTag() == .Vector) { |
| 4741 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4760 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4742 | for (result_data) |*scalar, i| { | 4761 | for (result_data, 0..) |*scalar, i| { |
| 4743 | var buf: Value.ElemValueBuffer = undefined; | 4762 | var buf: Value.ElemValueBuffer = undefined; |
| 4744 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4763 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4745 | scalar.* = try tanScalar(elem_val, float_type.scalarType(), arena, target); | 4764 | scalar.* = try tanScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -4779,7 +4798,7 @@ pub const Value = extern union { | ... | @@ -4779,7 +4798,7 @@ pub const Value = extern union { |
| 4779 | const target = mod.getTarget(); | 4798 | const target = mod.getTarget(); |
| 4780 | if (float_type.zigTypeTag() == .Vector) { | 4799 | if (float_type.zigTypeTag() == .Vector) { |
| 4781 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4800 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4782 | for (result_data) |*scalar, i| { | 4801 | for (result_data, 0..) |*scalar, i| { |
| 4783 | var buf: Value.ElemValueBuffer = undefined; | 4802 | var buf: Value.ElemValueBuffer = undefined; |
| 4784 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4803 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4785 | scalar.* = try expScalar(elem_val, float_type.scalarType(), arena, target); | 4804 | scalar.* = try expScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -4819,7 +4838,7 @@ pub const Value = extern union { | ... | @@ -4819,7 +4838,7 @@ pub const Value = extern union { |
| 4819 | const target = mod.getTarget(); | 4838 | const target = mod.getTarget(); |
| 4820 | if (float_type.zigTypeTag() == .Vector) { | 4839 | if (float_type.zigTypeTag() == .Vector) { |
| 4821 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4840 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4822 | for (result_data) |*scalar, i| { | 4841 | for (result_data, 0..) |*scalar, i| { |
| 4823 | var buf: Value.ElemValueBuffer = undefined; | 4842 | var buf: Value.ElemValueBuffer = undefined; |
| 4824 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4843 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4825 | scalar.* = try exp2Scalar(elem_val, float_type.scalarType(), arena, target); | 4844 | scalar.* = try exp2Scalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -4859,7 +4878,7 @@ pub const Value = extern union { | ... | @@ -4859,7 +4878,7 @@ pub const Value = extern union { |
| 4859 | const target = mod.getTarget(); | 4878 | const target = mod.getTarget(); |
| 4860 | if (float_type.zigTypeTag() == .Vector) { | 4879 | if (float_type.zigTypeTag() == .Vector) { |
| 4861 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4880 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4862 | for (result_data) |*scalar, i| { | 4881 | for (result_data, 0..) |*scalar, i| { |
| 4863 | var buf: Value.ElemValueBuffer = undefined; | 4882 | var buf: Value.ElemValueBuffer = undefined; |
| 4864 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4883 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4865 | scalar.* = try logScalar(elem_val, float_type.scalarType(), arena, target); | 4884 | scalar.* = try logScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -4899,7 +4918,7 @@ pub const Value = extern union { | ... | @@ -4899,7 +4918,7 @@ pub const Value = extern union { |
| 4899 | const target = mod.getTarget(); | 4918 | const target = mod.getTarget(); |
| 4900 | if (float_type.zigTypeTag() == .Vector) { | 4919 | if (float_type.zigTypeTag() == .Vector) { |
| 4901 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4920 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4902 | for (result_data) |*scalar, i| { | 4921 | for (result_data, 0..) |*scalar, i| { |
| 4903 | var buf: Value.ElemValueBuffer = undefined; | 4922 | var buf: Value.ElemValueBuffer = undefined; |
| 4904 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4923 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4905 | scalar.* = try log2Scalar(elem_val, float_type.scalarType(), arena, target); | 4924 | scalar.* = try log2Scalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -4939,7 +4958,7 @@ pub const Value = extern union { | ... | @@ -4939,7 +4958,7 @@ pub const Value = extern union { |
| 4939 | const target = mod.getTarget(); | 4958 | const target = mod.getTarget(); |
| 4940 | if (float_type.zigTypeTag() == .Vector) { | 4959 | if (float_type.zigTypeTag() == .Vector) { |
| 4941 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 4960 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4942 | for (result_data) |*scalar, i| { | 4961 | for (result_data, 0..) |*scalar, i| { |
| 4943 | var buf: Value.ElemValueBuffer = undefined; | 4962 | var buf: Value.ElemValueBuffer = undefined; |
| 4944 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 4963 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4945 | scalar.* = try log10Scalar(elem_val, float_type.scalarType(), arena, target); | 4964 | scalar.* = try log10Scalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -4979,7 +4998,7 @@ pub const Value = extern union { | ... | @@ -4979,7 +4998,7 @@ pub const Value = extern union { |
| 4979 | const target = mod.getTarget(); | 4998 | const target = mod.getTarget(); |
| 4980 | if (float_type.zigTypeTag() == .Vector) { | 4999 | if (float_type.zigTypeTag() == .Vector) { |
| 4981 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 5000 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 4982 | for (result_data) |*scalar, i| { | 5001 | for (result_data, 0..) |*scalar, i| { |
| 4983 | var buf: Value.ElemValueBuffer = undefined; | 5002 | var buf: Value.ElemValueBuffer = undefined; |
| 4984 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 5003 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 4985 | scalar.* = try fabsScalar(elem_val, float_type.scalarType(), arena, target); | 5004 | scalar.* = try fabsScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -5019,7 +5038,7 @@ pub const Value = extern union { | ... | @@ -5019,7 +5038,7 @@ pub const Value = extern union { |
| 5019 | const target = mod.getTarget(); | 5038 | const target = mod.getTarget(); |
| 5020 | if (float_type.zigTypeTag() == .Vector) { | 5039 | if (float_type.zigTypeTag() == .Vector) { |
| 5021 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 5040 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 5022 | for (result_data) |*scalar, i| { | 5041 | for (result_data, 0..) |*scalar, i| { |
| 5023 | var buf: Value.ElemValueBuffer = undefined; | 5042 | var buf: Value.ElemValueBuffer = undefined; |
| 5024 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 5043 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 5025 | scalar.* = try floorScalar(elem_val, float_type.scalarType(), arena, target); | 5044 | scalar.* = try floorScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -5059,7 +5078,7 @@ pub const Value = extern union { | ... | @@ -5059,7 +5078,7 @@ pub const Value = extern union { |
| 5059 | const target = mod.getTarget(); | 5078 | const target = mod.getTarget(); |
| 5060 | if (float_type.zigTypeTag() == .Vector) { | 5079 | if (float_type.zigTypeTag() == .Vector) { |
| 5061 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 5080 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 5062 | for (result_data) |*scalar, i| { | 5081 | for (result_data, 0..) |*scalar, i| { |
| 5063 | var buf: Value.ElemValueBuffer = undefined; | 5082 | var buf: Value.ElemValueBuffer = undefined; |
| 5064 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 5083 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 5065 | scalar.* = try ceilScalar(elem_val, float_type.scalarType(), arena, target); | 5084 | scalar.* = try ceilScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -5099,7 +5118,7 @@ pub const Value = extern union { | ... | @@ -5099,7 +5118,7 @@ pub const Value = extern union { |
| 5099 | const target = mod.getTarget(); | 5118 | const target = mod.getTarget(); |
| 5100 | if (float_type.zigTypeTag() == .Vector) { | 5119 | if (float_type.zigTypeTag() == .Vector) { |
| 5101 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 5120 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 5102 | for (result_data) |*scalar, i| { | 5121 | for (result_data, 0..) |*scalar, i| { |
| 5103 | var buf: Value.ElemValueBuffer = undefined; | 5122 | var buf: Value.ElemValueBuffer = undefined; |
| 5104 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 5123 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 5105 | scalar.* = try roundScalar(elem_val, float_type.scalarType(), arena, target); | 5124 | scalar.* = try roundScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -5139,7 +5158,7 @@ pub const Value = extern union { | ... | @@ -5139,7 +5158,7 @@ pub const Value = extern union { |
| 5139 | const target = mod.getTarget(); | 5158 | const target = mod.getTarget(); |
| 5140 | if (float_type.zigTypeTag() == .Vector) { | 5159 | if (float_type.zigTypeTag() == .Vector) { |
| 5141 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 5160 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 5142 | for (result_data) |*scalar, i| { | 5161 | for (result_data, 0..) |*scalar, i| { |
| 5143 | var buf: Value.ElemValueBuffer = undefined; | 5162 | var buf: Value.ElemValueBuffer = undefined; |
| 5144 | const elem_val = val.elemValueBuffer(mod, i, &buf); | 5163 | const elem_val = val.elemValueBuffer(mod, i, &buf); |
| 5145 | scalar.* = try truncScalar(elem_val, float_type.scalarType(), arena, target); | 5164 | scalar.* = try truncScalar(elem_val, float_type.scalarType(), arena, target); |
| ... | @@ -5186,7 +5205,7 @@ pub const Value = extern union { | ... | @@ -5186,7 +5205,7 @@ pub const Value = extern union { |
| 5186 | const target = mod.getTarget(); | 5205 | const target = mod.getTarget(); |
| 5187 | if (float_type.zigTypeTag() == .Vector) { | 5206 | if (float_type.zigTypeTag() == .Vector) { |
| 5188 | const result_data = try arena.alloc(Value, float_type.vectorLen()); | 5207 | const result_data = try arena.alloc(Value, float_type.vectorLen()); |
| 5189 | for (result_data) |*scalar, i| { | 5208 | for (result_data, 0..) |*scalar, i| { |
| 5190 | var mulend1_buf: Value.ElemValueBuffer = undefined; | 5209 | var mulend1_buf: Value.ElemValueBuffer = undefined; |
| 5191 | const mulend1_elem = mulend1.elemValueBuffer(mod, i, &mulend1_buf); | 5210 | const mulend1_elem = mulend1.elemValueBuffer(mod, i, &mulend1_buf); |
| 5192 | var mulend2_buf: Value.ElemValueBuffer = undefined; | 5211 | var mulend2_buf: Value.ElemValueBuffer = undefined; |
stage1/zig1.wasm| Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ | |||
test/behavior/array.zig+1-1| ... | @@ -185,7 +185,7 @@ test "nested arrays of strings" { | ... | @@ -185,7 +185,7 @@ test "nested arrays of strings" { |
| 185 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 185 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 186 | 186 | ||
| 187 | const array_of_strings = [_][]const u8{ "hello", "this", "is", "my", "thing" }; | 187 | const array_of_strings = [_][]const u8{ "hello", "this", "is", "my", "thing" }; |
| 188 | for (array_of_strings) |s, i| { | 188 | for (array_of_strings, 0..) |s, i| { |
| 189 | if (i == 0) try expect(mem.eql(u8, s, "hello")); | 189 | if (i == 0) try expect(mem.eql(u8, s, "hello")); |
| 190 | if (i == 1) try expect(mem.eql(u8, s, "this")); | 190 | if (i == 1) try expect(mem.eql(u8, s, "this")); |
| 191 | if (i == 2) try expect(mem.eql(u8, s, "is")); | 191 | if (i == 2) try expect(mem.eql(u8, s, "is")); |
test/behavior/bit_shifting.zig+2-2| ... | @@ -84,14 +84,14 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c | ... | @@ -84,14 +84,14 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c |
| 84 | 84 | ||
| 85 | var table = Table.create(); | 85 | var table = Table.create(); |
| 86 | var node_buffer: [node_count]Table.Node = undefined; | 86 | var node_buffer: [node_count]Table.Node = undefined; |
| 87 | for (node_buffer) |*node, i| { | 87 | for (&node_buffer, 0..) |*node, i| { |
| 88 | const key = @intCast(Key, i); | 88 | const key = @intCast(Key, i); |
| 89 | try expect(table.get(key) == null); | 89 | try expect(table.get(key) == null); |
| 90 | node.init(key, {}); | 90 | node.init(key, {}); |
| 91 | table.put(node); | 91 | table.put(node); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | for (node_buffer) |*node, i| { | 94 | for (&node_buffer, 0..) |*node, i| { |
| 95 | try expect(table.get(@intCast(Key, i)) == node); | 95 | try expect(table.get(@intCast(Key, i)) == node); |
| 96 | } | 96 | } |
| 97 | } | 97 | } |
test/behavior/bugs/1607.zig+1-1| ... | @@ -5,7 +5,7 @@ const builtin = @import("builtin"); | ... | @@ -5,7 +5,7 @@ const builtin = @import("builtin"); |
| 5 | const a = [_]u8{ 1, 2, 3 }; | 5 | const a = [_]u8{ 1, 2, 3 }; |
| 6 | 6 | ||
| 7 | fn checkAddress(s: []const u8) !void { | 7 | fn checkAddress(s: []const u8) !void { |
| 8 | for (s) |*i, j| { | 8 | for (s, 0..) |*i, j| { |
| 9 | try testing.expect(i == &a[j]); | 9 | try testing.expect(i == &a[j]); |
| 10 | } | 10 | } |
| 11 | } | 11 | } |
test/behavior/bugs/920.zig+3-3| ... | @@ -23,13 +23,13 @@ fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, co | ... | @@ -23,13 +23,13 @@ fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, co |
| 23 | tables.x[0] = v / f(r); | 23 | tables.x[0] = v / f(r); |
| 24 | tables.x[1] = r; | 24 | tables.x[1] = r; |
| 25 | 25 | ||
| 26 | for (tables.x[2..256]) |*entry, i| { | 26 | for (tables.x[2..256], 0..) |*entry, i| { |
| 27 | const last = tables.x[2 + i - 1]; | 27 | const last = tables.x[2 + i - 1]; |
| 28 | entry.* = f_inv(v / last + f(last)); | 28 | entry.* = f_inv(v / last + f(last)); |
| 29 | } | 29 | } |
| 30 | tables.x[256] = 0; | 30 | tables.x[256] = 0; |
| 31 | 31 | ||
| 32 | for (tables.f[0..]) |*entry, i| { | 32 | for (tables.f[0..], 0..) |*entry, i| { |
| 33 | entry.* = f(tables.x[i]); | 33 | entry.* = f(tables.x[i]); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| ... | @@ -67,7 +67,7 @@ test "bug 920 fixed" { | ... | @@ -67,7 +67,7 @@ test "bug 920 fixed" { |
| 67 | break :blk ZigTableGen(true, norm_r, norm_v, norm_f, norm_f_inv, norm_zero_case); | 67 | break :blk ZigTableGen(true, norm_r, norm_v, norm_f, norm_f_inv, norm_zero_case); |
| 68 | }; | 68 | }; |
| 69 | 69 | ||
| 70 | for (NormalDist1.f) |_, i| { | 70 | for (NormalDist1.f, 0..) |_, i| { |
| 71 | // Here we use `expectApproxEqAbs` instead of `expectEqual` to account for the small | 71 | // Here we use `expectApproxEqAbs` instead of `expectEqual` to account for the small |
| 72 | // differences in math functions of different libcs. For example, if the compiler | 72 | // differences in math functions of different libcs. For example, if the compiler |
| 73 | // links against glibc, but the target is musl libc, then these values might be | 73 | // links against glibc, but the target is musl libc, then these values might be |
test/behavior/call.zig+1-1| ... | @@ -364,7 +364,7 @@ test "Enum constructed by @Type passed as generic argument" { | ... | @@ -364,7 +364,7 @@ test "Enum constructed by @Type passed as generic argument" { |
| 364 | try expect(@enumToInt(a) == b); | 364 | try expect(@enumToInt(a) == b); |
| 365 | } | 365 | } |
| 366 | }; | 366 | }; |
| 367 | inline for (@typeInfo(S.E).Enum.fields) |_, i| { | 367 | inline for (@typeInfo(S.E).Enum.fields, 0..) |_, i| { |
| 368 | try S.foo(@intToEnum(S.E, i), i); | 368 | try S.foo(@intToEnum(S.E, i), i); |
| 369 | } | 369 | } |
| 370 | } | 370 | } |
test/behavior/comptime_memory.zig+18| ... | @@ -394,3 +394,21 @@ test "accessing reinterpreted memory of parent object" { | ... | @@ -394,3 +394,21 @@ test "accessing reinterpreted memory of parent object" { |
| 394 | try testing.expect(b == expected); | 394 | try testing.expect(b == expected); |
| 395 | } | 395 | } |
| 396 | } | 396 | } |
| 397 | |||
| 398 | test "bitcast packed union to integer" { | ||
| 399 | const U = packed union { | ||
| 400 | x: u1, | ||
| 401 | y: u2, | ||
| 402 | }; | ||
| 403 | |||
| 404 | comptime { | ||
| 405 | const a = U{ .x = 1 }; | ||
| 406 | const b = U{ .y = 2 }; | ||
| 407 | const cast_a = @bitCast(u2, a); | ||
| 408 | const cast_b = @bitCast(u2, b); | ||
| 409 | |||
| 410 | // truncated because the upper bit is garbage memory that we don't care about | ||
| 411 | try testing.expectEqual(@as(u1, 1), @truncate(u1, cast_a)); | ||
| 412 | try testing.expectEqual(@as(u2, 2), cast_b); | ||
| 413 | } | ||
| 414 | } |
test/behavior/const_slice_child.zig+2-2| ... | @@ -26,7 +26,7 @@ fn foo(args: [][]const u8) !void { | ... | @@ -26,7 +26,7 @@ fn foo(args: [][]const u8) !void { |
| 26 | fn bar(argc: usize) !void { | 26 | fn bar(argc: usize) !void { |
| 27 | var args_buffer: [10][]const u8 = undefined; | 27 | var args_buffer: [10][]const u8 = undefined; |
| 28 | const args = args_buffer[0..argc]; | 28 | const args = args_buffer[0..argc]; |
| 29 | for (args) |_, i| { | 29 | for (args, 0..) |_, i| { |
| 30 | const ptr = argv[i]; | 30 | const ptr = argv[i]; |
| 31 | args[i] = ptr[0..strlen(ptr)]; | 31 | args[i] = ptr[0..strlen(ptr)]; |
| 32 | } | 32 | } |
| ... | @@ -41,7 +41,7 @@ fn strlen(ptr: [*]const u8) usize { | ... | @@ -41,7 +41,7 @@ fn strlen(ptr: [*]const u8) usize { |
| 41 | 41 | ||
| 42 | fn streql(a: []const u8, b: []const u8) bool { | 42 | fn streql(a: []const u8, b: []const u8) bool { |
| 43 | if (a.len != b.len) return false; | 43 | if (a.len != b.len) return false; |
| 44 | for (a) |item, index| { | 44 | for (a, 0..) |item, index| { |
| 45 | if (b[index] != item) return false; | 45 | if (b[index] != item) return false; |
| 46 | } | 46 | } |
| 47 | return true; | 47 | return true; |
test/behavior/eval.zig+3-3| ... | @@ -317,7 +317,7 @@ test "create global array with for loop" { | ... | @@ -317,7 +317,7 @@ test "create global array with for loop" { |
| 317 | 317 | ||
| 318 | const global_array = x: { | 318 | const global_array = x: { |
| 319 | var result: [10]usize = undefined; | 319 | var result: [10]usize = undefined; |
| 320 | for (result) |*item, index| { | 320 | for (&result, 0..) |*item, index| { |
| 321 | item.* = index * index; | 321 | item.* = index * index; |
| 322 | } | 322 | } |
| 323 | break :x result; | 323 | break :x result; |
| ... | @@ -447,7 +447,7 @@ test "binary math operator in partially inlined function" { | ... | @@ -447,7 +447,7 @@ test "binary math operator in partially inlined function" { |
| 447 | var s: [4]u32 = undefined; | 447 | var s: [4]u32 = undefined; |
| 448 | var b: [16]u8 = undefined; | 448 | var b: [16]u8 = undefined; |
| 449 | 449 | ||
| 450 | for (b) |*r, i| | 450 | for (&b, 0..) |*r, i| |
| 451 | r.* = @intCast(u8, i + 1); | 451 | r.* = @intCast(u8, i + 1); |
| 452 | 452 | ||
| 453 | copyWithPartialInline(s[0..], b[0..]); | 453 | copyWithPartialInline(s[0..], b[0..]); |
| ... | @@ -915,7 +915,7 @@ test "comptime pointer load through elem_ptr" { | ... | @@ -915,7 +915,7 @@ test "comptime pointer load through elem_ptr" { |
| 915 | 915 | ||
| 916 | comptime { | 916 | comptime { |
| 917 | var array: [10]S = undefined; | 917 | var array: [10]S = undefined; |
| 918 | for (array) |*elem, i| { | 918 | for (&array, 0..) |*elem, i| { |
| 919 | elem.* = .{ | 919 | elem.* = .{ |
| 920 | .x = i, | 920 | .x = i, |
| 921 | }; | 921 | }; |
test/behavior/fn.zig+1-1| ... | @@ -311,7 +311,7 @@ test "function pointers" { | ... | @@ -311,7 +311,7 @@ test "function pointers" { |
| 311 | &fn3, | 311 | &fn3, |
| 312 | &fn4, | 312 | &fn4, |
| 313 | }; | 313 | }; |
| 314 | for (fns) |f, i| { | 314 | for (fns, 0..) |f, i| { |
| 315 | try expect(f() == @intCast(u32, i) + 5); | 315 | try expect(f() == @intCast(u32, i) + 5); |
| 316 | } | 316 | } |
| 317 | } | 317 | } |
test/behavior/for.zig+220-10| ... | @@ -55,9 +55,9 @@ fn testContinueOuter() !void { | ... | @@ -55,9 +55,9 @@ fn testContinueOuter() !void { |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | test "ignore lval with underscore (for loop)" { | 57 | test "ignore lval with underscore (for loop)" { |
| 58 | for ([_]void{}) |_, i| { | 58 | for ([_]void{}, 0..) |_, i| { |
| 59 | _ = i; | 59 | _ = i; |
| 60 | for ([_]void{}) |_, j| { | 60 | for ([_]void{}, 0..) |_, j| { |
| 61 | _ = j; | 61 | _ = j; |
| 62 | break; | 62 | break; |
| 63 | } | 63 | } |
| ... | @@ -81,7 +81,7 @@ test "basic for loop" { | ... | @@ -81,7 +81,7 @@ test "basic for loop" { |
| 81 | buffer[buf_index] = item; | 81 | buffer[buf_index] = item; |
| 82 | buf_index += 1; | 82 | buf_index += 1; |
| 83 | } | 83 | } |
| 84 | for (array) |item, index| { | 84 | for (array, 0..) |item, index| { |
| 85 | _ = item; | 85 | _ = item; |
| 86 | buffer[buf_index] = @intCast(u8, index); | 86 | buffer[buf_index] = @intCast(u8, index); |
| 87 | buf_index += 1; | 87 | buf_index += 1; |
| ... | @@ -91,7 +91,7 @@ test "basic for loop" { | ... | @@ -91,7 +91,7 @@ test "basic for loop" { |
| 91 | buffer[buf_index] = item; | 91 | buffer[buf_index] = item; |
| 92 | buf_index += 1; | 92 | buf_index += 1; |
| 93 | } | 93 | } |
| 94 | for (array_ptr) |item, index| { | 94 | for (array_ptr, 0..) |item, index| { |
| 95 | _ = item; | 95 | _ = item; |
| 96 | buffer[buf_index] = @intCast(u8, index); | 96 | buffer[buf_index] = @intCast(u8, index); |
| 97 | buf_index += 1; | 97 | buf_index += 1; |
| ... | @@ -101,7 +101,7 @@ test "basic for loop" { | ... | @@ -101,7 +101,7 @@ test "basic for loop" { |
| 101 | buffer[buf_index] = item; | 101 | buffer[buf_index] = item; |
| 102 | buf_index += 1; | 102 | buf_index += 1; |
| 103 | } | 103 | } |
| 104 | for (unknown_size) |_, index| { | 104 | for (unknown_size, 0..) |_, index| { |
| 105 | buffer[buf_index] = @intCast(u8, index); | 105 | buffer[buf_index] = @intCast(u8, index); |
| 106 | buf_index += 1; | 106 | buf_index += 1; |
| 107 | } | 107 | } |
| ... | @@ -163,11 +163,11 @@ test "for loop with pointer elem var" { | ... | @@ -163,11 +163,11 @@ test "for loop with pointer elem var" { |
| 163 | mangleString(target[0..]); | 163 | mangleString(target[0..]); |
| 164 | try expect(mem.eql(u8, &target, "bcdefgh")); | 164 | try expect(mem.eql(u8, &target, "bcdefgh")); |
| 165 | 165 | ||
| 166 | for (source) |*c, i| { | 166 | for (source, 0..) |*c, i| { |
| 167 | _ = i; | 167 | _ = i; |
| 168 | try expect(@TypeOf(c) == *const u8); | 168 | try expect(@TypeOf(c) == *const u8); |
| 169 | } | 169 | } |
| 170 | for (target) |*c, i| { | 170 | for (&target, 0..) |*c, i| { |
| 171 | _ = i; | 171 | _ = i; |
| 172 | try expect(@TypeOf(c) == *u8); | 172 | try expect(@TypeOf(c) == *u8); |
| 173 | } | 173 | } |
| ... | @@ -186,7 +186,7 @@ test "for copies its payload" { | ... | @@ -186,7 +186,7 @@ test "for copies its payload" { |
| 186 | const S = struct { | 186 | const S = struct { |
| 187 | fn doTheTest() !void { | 187 | fn doTheTest() !void { |
| 188 | var x = [_]usize{ 1, 2, 3 }; | 188 | var x = [_]usize{ 1, 2, 3 }; |
| 189 | for (x) |value, i| { | 189 | for (x, 0..) |value, i| { |
| 190 | // Modify the original array | 190 | // Modify the original array |
| 191 | x[i] += 99; | 191 | x[i] += 99; |
| 192 | try expect(value == i + 1); | 192 | try expect(value == i + 1); |
| ... | @@ -206,8 +206,8 @@ test "for on slice with allowzero ptr" { | ... | @@ -206,8 +206,8 @@ test "for on slice with allowzero ptr" { |
| 206 | const S = struct { | 206 | const S = struct { |
| 207 | fn doTheTest(slice: []const u8) !void { | 207 | fn doTheTest(slice: []const u8) !void { |
| 208 | var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len]; | 208 | var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len]; |
| 209 | for (ptr) |x, i| try expect(x == i + 1); | 209 | for (ptr, 0..) |x, i| try expect(x == i + 1); |
| 210 | for (ptr) |*x, i| try expect(x.* == i + 1); | 210 | for (ptr, 0..) |*x, i| try expect(x.* == i + 1); |
| 211 | } | 211 | } |
| 212 | }; | 212 | }; |
| 213 | try S.doTheTest(&[_]u8{ 1, 2, 3, 4 }); | 213 | try S.doTheTest(&[_]u8{ 1, 2, 3, 4 }); |
| ... | @@ -249,3 +249,213 @@ test "for loop with else branch" { | ... | @@ -249,3 +249,213 @@ test "for loop with else branch" { |
| 249 | try expect(q == 4); | 249 | try expect(q == 4); |
| 250 | } | 250 | } |
| 251 | } | 251 | } |
| 252 | |||
| 253 | test "count over fixed range" { | ||
| 254 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 255 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 256 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 257 | |||
| 258 | var sum: usize = 0; | ||
| 259 | for (0..6) |i| { | ||
| 260 | sum += i; | ||
| 261 | } | ||
| 262 | |||
| 263 | try expect(sum == 15); | ||
| 264 | } | ||
| 265 | |||
| 266 | test "two counters" { | ||
| 267 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 268 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 269 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 270 | |||
| 271 | var sum: usize = 0; | ||
| 272 | for (0..10, 10..20) |i, j| { | ||
| 273 | sum += 1; | ||
| 274 | try expect(i + 10 == j); | ||
| 275 | } | ||
| 276 | |||
| 277 | try expect(sum == 10); | ||
| 278 | } | ||
| 279 | |||
| 280 | test "1-based counter and ptr to array" { | ||
| 281 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 282 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 283 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 284 | |||
| 285 | var ok: usize = 0; | ||
| 286 | |||
| 287 | for (1..6, "hello") |i, b| { | ||
| 288 | if (i == 1) { | ||
| 289 | try expect(b == 'h'); | ||
| 290 | ok += 1; | ||
| 291 | } | ||
| 292 | if (i == 2) { | ||
| 293 | try expect(b == 'e'); | ||
| 294 | ok += 1; | ||
| 295 | } | ||
| 296 | if (i == 3) { | ||
| 297 | try expect(b == 'l'); | ||
| 298 | ok += 1; | ||
| 299 | } | ||
| 300 | if (i == 4) { | ||
| 301 | try expect(b == 'l'); | ||
| 302 | ok += 1; | ||
| 303 | } | ||
| 304 | if (i == 5) { | ||
| 305 | try expect(b == 'o'); | ||
| 306 | ok += 1; | ||
| 307 | } | ||
| 308 | } | ||
| 309 | |||
| 310 | try expect(ok == 5); | ||
| 311 | } | ||
| 312 | |||
| 313 | test "slice and two counters, one is offset and one is runtime" { | ||
| 314 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 315 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 316 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 317 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 318 | |||
| 319 | const slice: []const u8 = "blah"; | ||
| 320 | var start: usize = 0; | ||
| 321 | |||
| 322 | for (slice, start..4, 1..5) |a, b, c| { | ||
| 323 | if (a == 'b') { | ||
| 324 | try expect(b == 0); | ||
| 325 | try expect(c == 1); | ||
| 326 | } | ||
| 327 | if (a == 'l') { | ||
| 328 | try expect(b == 1); | ||
| 329 | try expect(c == 2); | ||
| 330 | } | ||
| 331 | if (a == 'a') { | ||
| 332 | try expect(b == 2); | ||
| 333 | try expect(c == 3); | ||
| 334 | } | ||
| 335 | if (a == 'h') { | ||
| 336 | try expect(b == 3); | ||
| 337 | try expect(c == 4); | ||
| 338 | } | ||
| 339 | } | ||
| 340 | } | ||
| 341 | |||
| 342 | test "two slices, one captured by-ref" { | ||
| 343 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 344 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 345 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 346 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 347 | |||
| 348 | var buf: [10]u8 = undefined; | ||
| 349 | const slice1: []const u8 = "blah"; | ||
| 350 | const slice2: []u8 = buf[0..4]; | ||
| 351 | |||
| 352 | for (slice1, slice2) |a, *b| { | ||
| 353 | b.* = a; | ||
| 354 | } | ||
| 355 | |||
| 356 | try expect(slice2[0] == 'b'); | ||
| 357 | try expect(slice2[1] == 'l'); | ||
| 358 | try expect(slice2[2] == 'a'); | ||
| 359 | try expect(slice2[3] == 'h'); | ||
| 360 | } | ||
| 361 | |||
| 362 | test "raw pointer and slice" { | ||
| 363 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 364 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 365 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 366 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 367 | |||
| 368 | var buf: [10]u8 = undefined; | ||
| 369 | const slice: []const u8 = "blah"; | ||
| 370 | const ptr: [*]u8 = buf[0..4]; | ||
| 371 | |||
| 372 | for (ptr, slice) |*a, b| { | ||
| 373 | a.* = b; | ||
| 374 | } | ||
| 375 | |||
| 376 | try expect(buf[0] == 'b'); | ||
| 377 | try expect(buf[1] == 'l'); | ||
| 378 | try expect(buf[2] == 'a'); | ||
| 379 | try expect(buf[3] == 'h'); | ||
| 380 | } | ||
| 381 | |||
| 382 | test "raw pointer and counter" { | ||
| 383 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 384 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 385 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 386 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 387 | |||
| 388 | var buf: [10]u8 = undefined; | ||
| 389 | const ptr: [*]u8 = &buf; | ||
| 390 | |||
| 391 | for (ptr, 0..4) |*a, b| { | ||
| 392 | a.* = @intCast(u8, 'A' + b); | ||
| 393 | } | ||
| 394 | |||
| 395 | try expect(buf[0] == 'A'); | ||
| 396 | try expect(buf[1] == 'B'); | ||
| 397 | try expect(buf[2] == 'C'); | ||
| 398 | try expect(buf[3] == 'D'); | ||
| 399 | } | ||
| 400 | |||
| 401 | test "inline for with slice as the comptime-known" { | ||
| 402 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 403 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 404 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 405 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 406 | |||
| 407 | const comptime_slice = "hello"; | ||
| 408 | var runtime_i: usize = 3; | ||
| 409 | |||
| 410 | const S = struct { | ||
| 411 | var ok: usize = 0; | ||
| 412 | fn check(comptime a: u8, b: usize) !void { | ||
| 413 | if (a == 'l') { | ||
| 414 | try expect(b == 3); | ||
| 415 | ok += 1; | ||
| 416 | } else if (a == 'o') { | ||
| 417 | try expect(b == 4); | ||
| 418 | ok += 1; | ||
| 419 | } else { | ||
| 420 | @compileError("fail"); | ||
| 421 | } | ||
| 422 | } | ||
| 423 | }; | ||
| 424 | |||
| 425 | inline for (comptime_slice[3..5], runtime_i..5) |a, b| { | ||
| 426 | try S.check(a, b); | ||
| 427 | } | ||
| 428 | |||
| 429 | try expect(S.ok == 2); | ||
| 430 | } | ||
| 431 | |||
| 432 | test "inline for with counter as the comptime-known" { | ||
| 433 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 434 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 435 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 436 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 437 | |||
| 438 | var runtime_slice = "hello"; | ||
| 439 | var runtime_i: usize = 3; | ||
| 440 | |||
| 441 | const S = struct { | ||
| 442 | var ok: usize = 0; | ||
| 443 | fn check(a: u8, comptime b: usize) !void { | ||
| 444 | if (b == 3) { | ||
| 445 | try expect(a == 'l'); | ||
| 446 | ok += 1; | ||
| 447 | } else if (b == 4) { | ||
| 448 | try expect(a == 'o'); | ||
| 449 | ok += 1; | ||
| 450 | } else { | ||
| 451 | @compileError("fail"); | ||
| 452 | } | ||
| 453 | } | ||
| 454 | }; | ||
| 455 | |||
| 456 | inline for (runtime_slice[runtime_i..5], 3..5) |a, b| { | ||
| 457 | try S.check(a, b); | ||
| 458 | } | ||
| 459 | |||
| 460 | try expect(S.ok == 2); | ||
| 461 | } |
test/behavior/generics.zig+1-1| ... | @@ -325,7 +325,7 @@ test "generic function instantiation non-duplicates" { | ... | @@ -325,7 +325,7 @@ test "generic function instantiation non-duplicates" { |
| 325 | const S = struct { | 325 | const S = struct { |
| 326 | fn copy(comptime T: type, dest: []T, source: []const T) void { | 326 | fn copy(comptime T: type, dest: []T, source: []const T) void { |
| 327 | @export(foo, .{ .name = "test_generic_instantiation_non_dupe" }); | 327 | @export(foo, .{ .name = "test_generic_instantiation_non_dupe" }); |
| 328 | for (source) |s, i| dest[i] = s; | 328 | for (source, 0..) |s, i| dest[i] = s; |
| 329 | } | 329 | } |
| 330 | 330 | ||
| 331 | fn foo() callconv(.C) void {} | 331 | fn foo() callconv(.C) void {} |
test/behavior/lower_strlit_to_vector.zig+1-1| ... | @@ -12,7 +12,7 @@ test "strlit to vector" { | ... | @@ -12,7 +12,7 @@ test "strlit to vector" { |
| 12 | const strlit = "0123456789abcdef0123456789ABCDEF"; | 12 | const strlit = "0123456789abcdef0123456789ABCDEF"; |
| 13 | const vec_from_strlit: @Vector(32, u8) = strlit.*; | 13 | const vec_from_strlit: @Vector(32, u8) = strlit.*; |
| 14 | const arr_from_vec = @as([32]u8, vec_from_strlit); | 14 | const arr_from_vec = @as([32]u8, vec_from_strlit); |
| 15 | for (strlit) |c, i| | 15 | for (strlit, 0..) |c, i| |
| 16 | try std.testing.expect(c == arr_from_vec[i]); | 16 | try std.testing.expect(c == arr_from_vec[i]); |
| 17 | try std.testing.expectEqualSlices(u8, strlit, &arr_from_vec); | 17 | try std.testing.expectEqualSlices(u8, strlit, &arr_from_vec); |
| 18 | } | 18 | } |
test/behavior/math.zig+1-1| ... | @@ -1221,7 +1221,7 @@ test "quad hex float literal parsing accurate" { | ... | @@ -1221,7 +1221,7 @@ test "quad hex float literal parsing accurate" { |
| 1221 | 0xb6a0000000000000, | 1221 | 0xb6a0000000000000, |
| 1222 | }; | 1222 | }; |
| 1223 | 1223 | ||
| 1224 | for (exp2ft) |x, i| { | 1224 | for (exp2ft, 0..) |x, i| { |
| 1225 | try expect(@bitCast(u64, x) == answers[i]); | 1225 | try expect(@bitCast(u64, x) == answers[i]); |
| 1226 | } | 1226 | } |
| 1227 | } | 1227 | } |
test/behavior/slice.zig+2-2| ... | @@ -99,7 +99,7 @@ test "comptime slice of slice preserves comptime var" { | ... | @@ -99,7 +99,7 @@ test "comptime slice of slice preserves comptime var" { |
| 99 | test "slice of type" { | 99 | test "slice of type" { |
| 100 | comptime { | 100 | comptime { |
| 101 | var types_array = [_]type{ i32, f64, type }; | 101 | var types_array = [_]type{ i32, f64, type }; |
| 102 | for (types_array) |T, i| { | 102 | for (types_array, 0..) |T, i| { |
| 103 | switch (i) { | 103 | switch (i) { |
| 104 | 0 => try expect(T == i32), | 104 | 0 => try expect(T == i32), |
| 105 | 1 => try expect(T == f64), | 105 | 1 => try expect(T == f64), |
| ... | @@ -107,7 +107,7 @@ test "slice of type" { | ... | @@ -107,7 +107,7 @@ test "slice of type" { |
| 107 | else => unreachable, | 107 | else => unreachable, |
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | for (types_array[0..]) |T, i| { | 110 | for (types_array[0..], 0..) |T, i| { |
| 111 | switch (i) { | 111 | switch (i) { |
| 112 | 0 => try expect(T == i32), | 112 | 0 => try expect(T == i32), |
| 113 | 1 => try expect(T == f64), | 113 | 1 => try expect(T == f64), |
test/behavior/tuple.zig+1-1| ... | @@ -40,7 +40,7 @@ test "tuple multiplication" { | ... | @@ -40,7 +40,7 @@ test "tuple multiplication" { |
| 40 | { | 40 | { |
| 41 | const t = .{ 1, 2, 3 } ** 4; | 41 | const t = .{ 1, 2, 3 } ** 4; |
| 42 | try expect(@typeInfo(@TypeOf(t)).Struct.fields.len == 12); | 42 | try expect(@typeInfo(@TypeOf(t)).Struct.fields.len == 12); |
| 43 | inline for (t) |x, i| try expect(x == 1 + i % 3); | 43 | inline for (t, 0..) |x, i| try expect(x == 1 + i % 3); |
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | }; | 46 | }; |
test/behavior/vector.zig+11-11| ... | @@ -456,20 +456,20 @@ test "vector division operators" { | ... | @@ -456,20 +456,20 @@ test "vector division operators" { |
| 456 | fn doTheTestDiv(comptime T: type, x: @Vector(4, T), y: @Vector(4, T)) !void { | 456 | fn doTheTestDiv(comptime T: type, x: @Vector(4, T), y: @Vector(4, T)) !void { |
| 457 | if (!comptime std.meta.trait.isSignedInt(T)) { | 457 | if (!comptime std.meta.trait.isSignedInt(T)) { |
| 458 | const d0 = x / y; | 458 | const d0 = x / y; |
| 459 | for (@as([4]T, d0)) |v, i| { | 459 | for (@as([4]T, d0), 0..) |v, i| { |
| 460 | try expect(x[i] / y[i] == v); | 460 | try expect(x[i] / y[i] == v); |
| 461 | } | 461 | } |
| 462 | } | 462 | } |
| 463 | const d1 = @divExact(x, y); | 463 | const d1 = @divExact(x, y); |
| 464 | for (@as([4]T, d1)) |v, i| { | 464 | for (@as([4]T, d1), 0..) |v, i| { |
| 465 | try expect(@divExact(x[i], y[i]) == v); | 465 | try expect(@divExact(x[i], y[i]) == v); |
| 466 | } | 466 | } |
| 467 | const d2 = @divFloor(x, y); | 467 | const d2 = @divFloor(x, y); |
| 468 | for (@as([4]T, d2)) |v, i| { | 468 | for (@as([4]T, d2), 0..) |v, i| { |
| 469 | try expect(@divFloor(x[i], y[i]) == v); | 469 | try expect(@divFloor(x[i], y[i]) == v); |
| 470 | } | 470 | } |
| 471 | const d3 = @divTrunc(x, y); | 471 | const d3 = @divTrunc(x, y); |
| 472 | for (@as([4]T, d3)) |v, i| { | 472 | for (@as([4]T, d3), 0..) |v, i| { |
| 473 | try expect(@divTrunc(x[i], y[i]) == v); | 473 | try expect(@divTrunc(x[i], y[i]) == v); |
| 474 | } | 474 | } |
| 475 | } | 475 | } |
| ... | @@ -477,16 +477,16 @@ test "vector division operators" { | ... | @@ -477,16 +477,16 @@ test "vector division operators" { |
| 477 | fn doTheTestMod(comptime T: type, x: @Vector(4, T), y: @Vector(4, T)) !void { | 477 | fn doTheTestMod(comptime T: type, x: @Vector(4, T), y: @Vector(4, T)) !void { |
| 478 | if ((!comptime std.meta.trait.isSignedInt(T)) and @typeInfo(T) != .Float) { | 478 | if ((!comptime std.meta.trait.isSignedInt(T)) and @typeInfo(T) != .Float) { |
| 479 | const r0 = x % y; | 479 | const r0 = x % y; |
| 480 | for (@as([4]T, r0)) |v, i| { | 480 | for (@as([4]T, r0), 0..) |v, i| { |
| 481 | try expect(x[i] % y[i] == v); | 481 | try expect(x[i] % y[i] == v); |
| 482 | } | 482 | } |
| 483 | } | 483 | } |
| 484 | const r1 = @mod(x, y); | 484 | const r1 = @mod(x, y); |
| 485 | for (@as([4]T, r1)) |v, i| { | 485 | for (@as([4]T, r1), 0..) |v, i| { |
| 486 | try expect(@mod(x[i], y[i]) == v); | 486 | try expect(@mod(x[i], y[i]) == v); |
| 487 | } | 487 | } |
| 488 | const r2 = @rem(x, y); | 488 | const r2 = @rem(x, y); |
| 489 | for (@as([4]T, r2)) |v, i| { | 489 | for (@as([4]T, r2), 0..) |v, i| { |
| 490 | try expect(@rem(x[i], y[i]) == v); | 490 | try expect(@rem(x[i], y[i]) == v); |
| 491 | } | 491 | } |
| 492 | } | 492 | } |
| ... | @@ -538,7 +538,7 @@ test "vector bitwise not operator" { | ... | @@ -538,7 +538,7 @@ test "vector bitwise not operator" { |
| 538 | const S = struct { | 538 | const S = struct { |
| 539 | fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void { | 539 | fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void { |
| 540 | var y = ~x; | 540 | var y = ~x; |
| 541 | for (@as([4]T, y)) |v, i| { | 541 | for (@as([4]T, y), 0..) |v, i| { |
| 542 | try expect(~x[i] == v); | 542 | try expect(~x[i] == v); |
| 543 | } | 543 | } |
| 544 | } | 544 | } |
| ... | @@ -577,11 +577,11 @@ test "vector shift operators" { | ... | @@ -577,11 +577,11 @@ test "vector shift operators" { |
| 577 | var yv = @as(@Vector(N, TY), y); | 577 | var yv = @as(@Vector(N, TY), y); |
| 578 | 578 | ||
| 579 | var z0 = xv >> yv; | 579 | var z0 = xv >> yv; |
| 580 | for (@as([N]TX, z0)) |v, i| { | 580 | for (@as([N]TX, z0), 0..) |v, i| { |
| 581 | try expect(x[i] >> y[i] == v); | 581 | try expect(x[i] >> y[i] == v); |
| 582 | } | 582 | } |
| 583 | var z1 = xv << yv; | 583 | var z1 = xv << yv; |
| 584 | for (@as([N]TX, z1)) |v, i| { | 584 | for (@as([N]TX, z1), 0..) |v, i| { |
| 585 | try expect(x[i] << y[i] == v); | 585 | try expect(x[i] << y[i] == v); |
| 586 | } | 586 | } |
| 587 | } | 587 | } |
| ... | @@ -594,7 +594,7 @@ test "vector shift operators" { | ... | @@ -594,7 +594,7 @@ test "vector shift operators" { |
| 594 | var yv = @as(@Vector(N, TY), y); | 594 | var yv = @as(@Vector(N, TY), y); |
| 595 | 595 | ||
| 596 | var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); | 596 | var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv); |
| 597 | for (@as([N]TX, z)) |v, i| { | 597 | for (@as([N]TX, z), 0..) |v, i| { |
| 598 | const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i]; | 598 | const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i]; |
| 599 | try expect(check == v); | 599 | try expect(check == v); |
| 600 | } | 600 | } |
test/behavior/void.zig+1-1| ... | @@ -22,7 +22,7 @@ test "iterate over a void slice" { | ... | @@ -22,7 +22,7 @@ test "iterate over a void slice" { |
| 22 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 22 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 23 | 23 | ||
| 24 | var j: usize = 0; | 24 | var j: usize = 0; |
| 25 | for (times(10)) |_, i| { | 25 | for (times(10), 0..) |_, i| { |
| 26 | try expect(i == j); | 26 | try expect(i == j); |
| 27 | j += 1; | 27 | j += 1; |
| 28 | } | 28 | } |
test/cases/compile_errors/for.zig created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | export fn a() void { | ||
| 2 | for (0..10, 10..21) |i, j| { | ||
| 3 | _ = i; _ = j; | ||
| 4 | } | ||
| 5 | } | ||
| 6 | export fn b() void { | ||
| 7 | const s1 = "hello"; | ||
| 8 | const s2 = true; | ||
| 9 | for (s1, s2) |i, j| { | ||
| 10 | _ = i; _ = j; | ||
| 11 | } | ||
| 12 | } | ||
| 13 | export fn c() void { | ||
| 14 | var buf: [10]u8 = undefined; | ||
| 15 | for (buf) |*byte| { | ||
| 16 | _ = byte; | ||
| 17 | } | ||
| 18 | } | ||
| 19 | export fn d() void { | ||
| 20 | const x: [*]const u8 = "hello"; | ||
| 21 | const y: [*]const u8 = "world"; | ||
| 22 | for (x, 0.., y) |x1, x2, x3| { | ||
| 23 | _ = x1; _ = x2; _ = x3; | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | // error | ||
| 28 | // backend=stage2 | ||
| 29 | // target=native | ||
| 30 | // | ||
| 31 | // :2:5: error: non-matching for loop lengths | ||
| 32 | // :2:11: note: length 10 here | ||
| 33 | // :2:19: note: length 11 here | ||
| 34 | // :9:14: error: type 'bool' does not support indexing | ||
| 35 | // :9:14: note: for loop operand must be an array, slice, tuple, or vector | ||
| 36 | // :15:16: error: pointer capture of non pointer type '[10]u8' | ||
| 37 | // :15:10: note: consider using '&' here | ||
| 38 | // :22:5: error: unbounded for loop | ||
| 39 | // :22:10: note: type '[*]const u8' has no upper bound | ||
| 40 | // :22:18: note: type '[*]const u8' has no upper bound | ||
test/cases/compile_errors/for_discard_unbounded.zig created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | export fn a() void { | ||
| 2 | for (0..10, 10..) |i, _| { | ||
| 3 | _ = i; | ||
| 4 | } | ||
| 5 | } | ||
| 6 | // error | ||
| 7 | // backend=stage2 | ||
| 8 | // target=native | ||
| 9 | // | ||
| 10 | // :2:27: error: discard of unbounded counter | ||
test/cases/compile_errors/for_empty.zig created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | export fn b() void { | ||
| 2 | for () |i| { | ||
| 3 | _ = i; | ||
| 4 | } | ||
| 5 | } | ||
| 6 | |||
| 7 | // error | ||
| 8 | // backend=stage2 | ||
| 9 | // target=native | ||
| 10 | // | ||
| 11 | // :2:10: error: expected expression, found ')' | ||
test/cases/compile_errors/for_extra_capture.zig created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | export fn b() void { | ||
| 2 | for (0..10) |i, j| { | ||
| 3 | _ = i; _ = j; | ||
| 4 | } | ||
| 5 | } | ||
| 6 | |||
| 7 | // error | ||
| 8 | // backend=stage2 | ||
| 9 | // target=native | ||
| 10 | // | ||
| 11 | // :2:21: error: extra capture in for loop | ||
| 12 | // :2:21: note: run 'zig fmt' to upgrade your code automatically | ||
test/cases/compile_errors/for_extra_condition.zig created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | export fn a() void { | ||
| 2 | for (0..10, 10..20) |i| { | ||
| 3 | _ = i; | ||
| 4 | } | ||
| 5 | } | ||
| 6 | |||
| 7 | // error | ||
| 8 | // backend=stage2 | ||
| 9 | // target=native | ||
| 10 | // | ||
| 11 | // :2:19: error: for input is not captured | ||
test/cases/compile_errors/for_unbounded.zig created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | export fn b() void { | ||
| 2 | for (0..) |i| { | ||
| 3 | _ = i; | ||
| 4 | } | ||
| 5 | } | ||
| 6 | |||
| 7 | // error | ||
| 8 | // backend=stage2 | ||
| 9 | // target=native | ||
| 10 | // | ||
| 11 | // :2:5: error: unbounded for loop | ||
test/cases/compile_errors/invalid_pointer_for_var_type.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | extern fn ext() usize; | 1 | extern fn ext() usize; |
| 2 | var bytes: [ext()]u8 = undefined; | 2 | var bytes: [ext()]u8 = undefined; |
| 3 | export fn f() void { | 3 | export fn f() void { |
| 4 | for (bytes) |*b, i| { | 4 | for (&bytes, 0..) |*b, i| { |
| 5 | b.* = @as(u8, i); | 5 | b.* = @as(u8, i); |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
test/cases/compile_errors/underscore_should_not_be_usable_inside_for.zig+2-2| ... | @@ -1,6 +1,6 @@ | ... | @@ -1,6 +1,6 @@ |
| 1 | export fn returns() void { | 1 | export fn returns() void { |
| 2 | for ([_]void{}) |_, i| { | 2 | for ([_]void{}, 0..) |_, i| { |
| 3 | for ([_]void{}) |_, j| { | 3 | for ([_]void{}, 0..) |_, j| { |
| 4 | return _; | 4 | return _; |
| 5 | } | 5 | } |
| 6 | } | 6 | } |
test/cases/llvm/for_loop.zig+1-1| ... | @@ -11,6 +11,6 @@ pub fn main() void { | ... | @@ -11,6 +11,6 @@ pub fn main() void { |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | // run | 13 | // run |
| 14 | // backend=stage2,llvm | 14 | // backend=llvm |
| 15 | // target=x86_64-linux,x86_64-macos | 15 | // target=x86_64-linux,x86_64-macos |
| 16 | // | 16 | // |
test/cases/safety/for_len_mismatch.zig created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | ||
| 4 | _ = stack_trace; | ||
| 5 | if (std.mem.eql(u8, message, "for loop over objects with non-equal lengths")) { | ||
| 6 | std.process.exit(0); | ||
| 7 | } | ||
| 8 | std.process.exit(1); | ||
| 9 | } | ||
| 10 | |||
| 11 | pub fn main() !void { | ||
| 12 | var runtime_i: usize = 1; | ||
| 13 | var j: usize = 3; | ||
| 14 | var slice = "too long"; | ||
| 15 | for (runtime_i..j, slice) |a, b| { | ||
| 16 | _ = a; | ||
| 17 | _ = b; | ||
| 18 | return error.TestFailed; | ||
| 19 | } | ||
| 20 | return error.TestFailed; | ||
| 21 | } | ||
| 22 | // run | ||
| 23 | // backend=llvm | ||
| 24 | // target=native | ||
test/cases/safety/for_len_mismatch_three.zig created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | ||
| 4 | _ = stack_trace; | ||
| 5 | if (std.mem.eql(u8, message, "for loop over objects with non-equal lengths")) { | ||
| 6 | std.process.exit(0); | ||
| 7 | } | ||
| 8 | std.process.exit(1); | ||
| 9 | } | ||
| 10 | |||
| 11 | pub fn main() !void { | ||
| 12 | var slice: []const u8 = "hello"; | ||
| 13 | for (10..20, slice, 20..30) |a, b, c| { | ||
| 14 | _ = a; | ||
| 15 | _ = b; | ||
| 16 | _ = c; | ||
| 17 | return error.TestFailed; | ||
| 18 | } | ||
| 19 | return error.TestFailed; | ||
| 20 | } | ||
| 21 | // run | ||
| 22 | // backend=llvm | ||
| 23 | // target=native | ||
| 24 | |||
test/cases/variable_shadowing.3.zig+2-2| ... | @@ -1,10 +1,10 @@ | ... | @@ -1,10 +1,10 @@ |
| 1 | pub fn main() void { | 1 | pub fn main() void { |
| 2 | var i = 0; | 2 | var i = 0; |
| 3 | for ("n") |_, i| { | 3 | for ("n", 0..) |_, i| { |
| 4 | } | 4 | } |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | // error | 7 | // error |
| 8 | // | 8 | // |
| 9 | // :3:19: error: loop index capture 'i' shadows local variable from outer scope | 9 | // :3:24: error: capture 'i' shadows local variable from outer scope |
| 10 | // :2:9: note: previous declaration here | 10 | // :2:9: note: previous declaration here |
test/compare_output.zig+10-1| ... | @@ -196,7 +196,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -196,7 +196,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 196 | \\ | 196 | \\ |
| 197 | \\ c.qsort(@ptrCast(?*anyopaque, &array), @intCast(c_ulong, array.len), @sizeOf(i32), compare_fn); | 197 | \\ c.qsort(@ptrCast(?*anyopaque, &array), @intCast(c_ulong, array.len), @sizeOf(i32), compare_fn); |
| 198 | \\ | 198 | \\ |
| 199 | \\ for (array) |item, i| { | 199 | \\ for (array, 0..) |item, i| { |
| 200 | \\ if (item != i) { | 200 | \\ if (item != i) { |
| 201 | \\ c.abort(); | 201 | \\ c.abort(); |
| 202 | \\ } | 202 | \\ } |
| ... | @@ -535,4 +535,13 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -535,4 +535,13 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 535 | \\debug: free - len: 5 | 535 | \\debug: free - len: 5 |
| 536 | \\ | 536 | \\ |
| 537 | ); | 537 | ); |
| 538 | |||
| 539 | cases.add("valid carriage return example", "const io = @import(\"std\").io;\r\n" ++ // Testing CRLF line endings are valid | ||
| 540 | "\r\n" ++ | ||
| 541 | "pub \r fn main() void {\r\n" ++ // Testing isolated carriage return as whitespace is valid | ||
| 542 | " const stdout = io.getStdOut().writer();\r\n" ++ | ||
| 543 | " stdout.print(\\\\A Multiline\r\n" ++ // testing CRLF at end of multiline string line is valid and normalises to \n in the output | ||
| 544 | " \\\\String\r\n" ++ | ||
| 545 | " , .{}) catch unreachable;\r\n" ++ | ||
| 546 | "}\r\n", "A Multiline\nString"); | ||
| 538 | } | 547 | } |
test/compile_errors.zig+10| ... | @@ -174,6 +174,16 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -174,6 +174,16 @@ pub fn addCases(ctx: *TestContext) !void { |
| 174 | }); | 174 | }); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | { | ||
| 178 | const case = ctx.obj("isolated carriage return in multiline string literal", .{}); | ||
| 179 | case.backend = .stage2; | ||
| 180 | |||
| 181 | case.addError("const foo = \\\\\test\r\r rogue carriage return\n;", &[_][]const u8{ | ||
| 182 | ":1:19: error: expected ';' after declaration", | ||
| 183 | ":1:20: note: invalid byte: '\\r'", | ||
| 184 | }); | ||
| 185 | } | ||
| 186 | |||
| 177 | { | 187 | { |
| 178 | const case = ctx.obj("missing semicolon at EOF", .{}); | 188 | const case = ctx.obj("missing semicolon at EOF", .{}); |
| 179 | case.addError( | 189 | case.addError( |
test/standalone/brace_expansion/main.zig+2-2| ... | @@ -29,7 +29,7 @@ fn tokenize(input: []const u8) !ArrayList(Token) { | ... | @@ -29,7 +29,7 @@ fn tokenize(input: []const u8) !ArrayList(Token) { |
| 29 | var tok_begin: usize = undefined; | 29 | var tok_begin: usize = undefined; |
| 30 | var state = State.Start; | 30 | var state = State.Start; |
| 31 | 31 | ||
| 32 | for (input) |b, i| { | 32 | for (input, 0..) |b, i| { |
| 33 | switch (state) { | 33 | switch (state) { |
| 34 | .Start => switch (b) { | 34 | .Start => switch (b) { |
| 35 | 'a'...'z', 'A'...'Z' => { | 35 | 'a'...'z', 'A'...'Z' => { |
| ... | @@ -159,7 +159,7 @@ fn expandString(input: []const u8, output: *ArrayList(u8)) !void { | ... | @@ -159,7 +159,7 @@ fn expandString(input: []const u8, output: *ArrayList(u8)) !void { |
| 159 | try expandNode(root, &result_list); | 159 | try expandNode(root, &result_list); |
| 160 | 160 | ||
| 161 | try output.resize(0); | 161 | try output.resize(0); |
| 162 | for (result_list.items) |buf, i| { | 162 | for (result_list.items, 0..) |buf, i| { |
| 163 | if (i != 0) { | 163 | if (i != 0) { |
| 164 | try output.append(' '); | 164 | try output.append(' '); |
| 165 | } | 165 | } |
test/tests.zig+9-9| ... | @@ -58,14 +58,14 @@ const test_targets = blk: { | ... | @@ -58,14 +58,14 @@ const test_targets = blk: { |
| 58 | .link_libc = true, | 58 | .link_libc = true, |
| 59 | .backend = .stage2_c, | 59 | .backend = .stage2_c, |
| 60 | }, | 60 | }, |
| 61 | .{ | 61 | //.{ |
| 62 | .target = .{ | 62 | // .target = .{ |
| 63 | .cpu_arch = .x86_64, | 63 | // .cpu_arch = .x86_64, |
| 64 | .os_tag = .linux, | 64 | // .os_tag = .linux, |
| 65 | .abi = .none, | 65 | // .abi = .none, |
| 66 | }, | 66 | // }, |
| 67 | .backend = .stage2_x86_64, | 67 | // .backend = .stage2_x86_64, |
| 68 | }, | 68 | //}, |
| 69 | .{ | 69 | .{ |
| 70 | .target = .{ | 70 | .target = .{ |
| 71 | .cpu_arch = .aarch64, | 71 | .cpu_arch = .aarch64, |
| ... | @@ -958,7 +958,7 @@ pub const StackTracesContext = struct { | ... | @@ -958,7 +958,7 @@ pub const StackTracesContext = struct { |
| 958 | // locate delims/anchor | 958 | // locate delims/anchor |
| 959 | const delims = [_][]const u8{ ":", ":", ":", " in ", "(", ")" }; | 959 | const delims = [_][]const u8{ ":", ":", ":", " in ", "(", ")" }; |
| 960 | var marks = [_]usize{0} ** delims.len; | 960 | var marks = [_]usize{0} ** delims.len; |
| 961 | for (delims) |delim, i| { | 961 | for (delims, 0..) |delim, i| { |
| 962 | marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse { | 962 | marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse { |
| 963 | // unexpected pattern: emit raw line and cont | 963 | // unexpected pattern: emit raw line and cont |
| 964 | try buf.appendSlice(line); | 964 | try buf.appendSlice(line); |
tools/gen_spirv_spec.zig+9-9| ... | @@ -251,7 +251,7 @@ fn renderEnumerant(writer: anytype, enumerant: g.Enumerant) !void { | ... | @@ -251,7 +251,7 @@ fn renderEnumerant(writer: anytype, enumerant: g.Enumerant) !void { |
| 251 | .int => |int| try writer.print("{}", .{int}), | 251 | .int => |int| try writer.print("{}", .{int}), |
| 252 | } | 252 | } |
| 253 | try writer.writeAll(", .parameters = &[_]OperandKind{"); | 253 | try writer.writeAll(", .parameters = &[_]OperandKind{"); |
| 254 | for (enumerant.parameters) |param, i| { | 254 | for (enumerant.parameters, 0..) |param, i| { |
| 255 | if (i != 0) | 255 | if (i != 0) |
| 256 | try writer.writeAll(", "); | 256 | try writer.writeAll(", "); |
| 257 | // Note, param.quantifier will always be one. | 257 | // Note, param.quantifier will always be one. |
| ... | @@ -272,7 +272,7 @@ fn renderOpcodes( | ... | @@ -272,7 +272,7 @@ fn renderOpcodes( |
| 272 | var aliases = std.ArrayList(struct { inst: usize, alias: usize }).init(allocator); | 272 | var aliases = std.ArrayList(struct { inst: usize, alias: usize }).init(allocator); |
| 273 | try aliases.ensureTotalCapacity(instructions.len); | 273 | try aliases.ensureTotalCapacity(instructions.len); |
| 274 | 274 | ||
| 275 | for (instructions) |inst, i| { | 275 | for (instructions, 0..) |inst, i| { |
| 276 | if (std.mem.eql(u8, inst.class.?, "@exclude")) { | 276 | if (std.mem.eql(u8, inst.class.?, "@exclude")) { |
| 277 | continue; | 277 | continue; |
| 278 | } | 278 | } |
| ... | @@ -397,7 +397,7 @@ fn renderValueEnum( | ... | @@ -397,7 +397,7 @@ fn renderValueEnum( |
| 397 | var aliases = std.ArrayList(struct { enumerant: usize, alias: usize }).init(allocator); | 397 | var aliases = std.ArrayList(struct { enumerant: usize, alias: usize }).init(allocator); |
| 398 | try aliases.ensureTotalCapacity(enumerants.len); | 398 | try aliases.ensureTotalCapacity(enumerants.len); |
| 399 | 399 | ||
| 400 | for (enumerants) |enumerant, i| { | 400 | for (enumerants, 0..) |enumerant, i| { |
| 401 | const result = enum_map.getOrPutAssumeCapacity(enumerant.value.int); | 401 | const result = enum_map.getOrPutAssumeCapacity(enumerant.value.int); |
| 402 | if (!result.found_existing) { | 402 | if (!result.found_existing) { |
| 403 | result.value_ptr.* = i; | 403 | result.value_ptr.* = i; |
| ... | @@ -468,7 +468,7 @@ fn renderBitEnum( | ... | @@ -468,7 +468,7 @@ fn renderBitEnum( |
| 468 | var aliases = std.ArrayList(struct { flag: usize, alias: u5 }).init(allocator); | 468 | var aliases = std.ArrayList(struct { flag: usize, alias: u5 }).init(allocator); |
| 469 | try aliases.ensureTotalCapacity(enumerants.len); | 469 | try aliases.ensureTotalCapacity(enumerants.len); |
| 470 | 470 | ||
| 471 | for (enumerants) |enumerant, i| { | 471 | for (enumerants, 0..) |enumerant, i| { |
| 472 | if (enumerant.value != .bitflag) return error.InvalidRegistry; | 472 | if (enumerant.value != .bitflag) return error.InvalidRegistry; |
| 473 | const value = try parseHexInt(enumerant.value.bitflag); | 473 | const value = try parseHexInt(enumerant.value.bitflag); |
| 474 | if (value == 0) { | 474 | if (value == 0) { |
| ... | @@ -494,7 +494,7 @@ fn renderBitEnum( | ... | @@ -494,7 +494,7 @@ fn renderBitEnum( |
| 494 | } | 494 | } |
| 495 | } | 495 | } |
| 496 | 496 | ||
| 497 | for (flags_by_bitpos) |maybe_flag_index, bitpos| { | 497 | for (flags_by_bitpos, 0..) |maybe_flag_index, bitpos| { |
| 498 | if (maybe_flag_index) |flag_index| { | 498 | if (maybe_flag_index) |flag_index| { |
| 499 | try writer.print("{}", .{std.zig.fmtId(enumerants[flag_index].enumerant)}); | 499 | try writer.print("{}", .{std.zig.fmtId(enumerants[flag_index].enumerant)}); |
| 500 | } else { | 500 | } else { |
| ... | @@ -521,7 +521,7 @@ fn renderBitEnum( | ... | @@ -521,7 +521,7 @@ fn renderBitEnum( |
| 521 | 521 | ||
| 522 | try writer.print("\npub const Extended = struct {{\n", .{}); | 522 | try writer.print("\npub const Extended = struct {{\n", .{}); |
| 523 | 523 | ||
| 524 | for (flags_by_bitpos) |maybe_flag_index, bitpos| { | 524 | for (flags_by_bitpos, 0..) |maybe_flag_index, bitpos| { |
| 525 | const flag_index = maybe_flag_index orelse { | 525 | const flag_index = maybe_flag_index orelse { |
| 526 | try writer.print("_reserved_bit_{}: bool = false,\n", .{bitpos}); | 526 | try writer.print("_reserved_bit_{}: bool = false,\n", .{bitpos}); |
| 527 | continue; | 527 | continue; |
| ... | @@ -570,7 +570,7 @@ fn renderOperand( | ... | @@ -570,7 +570,7 @@ fn renderOperand( |
| 570 | 570 | ||
| 571 | try writer.writeAll("struct{"); | 571 | try writer.writeAll("struct{"); |
| 572 | 572 | ||
| 573 | for (parameters) |param, j| { | 573 | for (parameters, 0..) |param, j| { |
| 574 | if (j != 0) { | 574 | if (j != 0) { |
| 575 | try writer.writeAll(", "); | 575 | try writer.writeAll(", "); |
| 576 | } | 576 | } |
| ... | @@ -642,7 +642,7 @@ fn renderFieldName(writer: anytype, operands: []const g.Operand, field_index: us | ... | @@ -642,7 +642,7 @@ fn renderFieldName(writer: anytype, operands: []const g.Operand, field_index: us |
| 642 | 642 | ||
| 643 | // Translate to snake case. | 643 | // Translate to snake case. |
| 644 | name_buffer.len = 0; | 644 | name_buffer.len = 0; |
| 645 | for (operand.kind) |c, i| { | 645 | for (operand.kind, 0..) |c, i| { |
| 646 | switch (c) { | 646 | switch (c) { |
| 647 | 'a'...'z', '0'...'9' => try name_buffer.append(c), | 647 | 'a'...'z', '0'...'9' => try name_buffer.append(c), |
| 648 | 'A'...'Z' => if (i > 0 and std.ascii.isLower(operand.kind[i - 1])) { | 648 | 'A'...'Z' => if (i > 0 and std.ascii.isLower(operand.kind[i - 1])) { |
| ... | @@ -658,7 +658,7 @@ fn renderFieldName(writer: anytype, operands: []const g.Operand, field_index: us | ... | @@ -658,7 +658,7 @@ fn renderFieldName(writer: anytype, operands: []const g.Operand, field_index: us |
| 658 | 658 | ||
| 659 | // For fields derived from type name, there could be any amount. | 659 | // For fields derived from type name, there could be any amount. |
| 660 | // Simply check against all other fields, and if another similar one exists, add a number. | 660 | // Simply check against all other fields, and if another similar one exists, add a number. |
| 661 | const need_extra_index = for (operands) |other_operand, i| { | 661 | const need_extra_index = for (operands, 0..) |other_operand, i| { |
| 662 | if (i != field_index and std.mem.eql(u8, operand.kind, other_operand.kind)) { | 662 | if (i != field_index and std.mem.eql(u8, operand.kind, other_operand.kind)) { |
| 663 | break true; | 663 | break true; |
| 664 | } | 664 | } |
tools/gen_stubs.zig+9-9| ... | @@ -45,7 +45,7 @@ const MultiSym = struct { | ... | @@ -45,7 +45,7 @@ const MultiSym = struct { |
| 45 | visib: elf.STV, | 45 | visib: elf.STV, |
| 46 | 46 | ||
| 47 | fn allPresent(ms: MultiSym) bool { | 47 | fn allPresent(ms: MultiSym) bool { |
| 48 | for (arches) |_, i| { | 48 | for (arches, 0..) |_, i| { |
| 49 | if (!ms.present[i]) { | 49 | if (!ms.present[i]) { |
| 50 | return false; | 50 | return false; |
| 51 | } | 51 | } |
| ... | @@ -65,7 +65,7 @@ const MultiSym = struct { | ... | @@ -65,7 +65,7 @@ const MultiSym = struct { |
| 65 | 65 | ||
| 66 | fn commonSize(ms: MultiSym) ?u64 { | 66 | fn commonSize(ms: MultiSym) ?u64 { |
| 67 | var size: ?u64 = null; | 67 | var size: ?u64 = null; |
| 68 | for (arches) |_, i| { | 68 | for (arches, 0..) |_, i| { |
| 69 | if (!ms.present[i]) continue; | 69 | if (!ms.present[i]) continue; |
| 70 | if (size) |s| { | 70 | if (size) |s| { |
| 71 | if (ms.size[i] != s) { | 71 | if (ms.size[i] != s) { |
| ... | @@ -80,7 +80,7 @@ const MultiSym = struct { | ... | @@ -80,7 +80,7 @@ const MultiSym = struct { |
| 80 | 80 | ||
| 81 | fn commonBinding(ms: MultiSym) ?u4 { | 81 | fn commonBinding(ms: MultiSym) ?u4 { |
| 82 | var binding: ?u4 = null; | 82 | var binding: ?u4 = null; |
| 83 | for (arches) |_, i| { | 83 | for (arches, 0..) |_, i| { |
| 84 | if (!ms.present[i]) continue; | 84 | if (!ms.present[i]) continue; |
| 85 | if (binding) |b| { | 85 | if (binding) |b| { |
| 86 | if (ms.binding[i] != b) { | 86 | if (ms.binding[i] != b) { |
| ... | @@ -268,7 +268,7 @@ pub fn main() !void { | ... | @@ -268,7 +268,7 @@ pub fn main() !void { |
| 268 | 268 | ||
| 269 | var prev_section: u16 = std.math.maxInt(u16); | 269 | var prev_section: u16 = std.math.maxInt(u16); |
| 270 | var prev_pp_state: enum { none, ptr32, special } = .none; | 270 | var prev_pp_state: enum { none, ptr32, special } = .none; |
| 271 | for (sym_table.values()) |multi_sym, sym_index| { | 271 | for (sym_table.values(), 0..) |multi_sym, sym_index| { |
| 272 | const name = sym_table.keys()[sym_index]; | 272 | const name = sym_table.keys()[sym_index]; |
| 273 | 273 | ||
| 274 | if (multi_sym.section != prev_section) { | 274 | if (multi_sym.section != prev_section) { |
| ... | @@ -309,7 +309,7 @@ pub fn main() !void { | ... | @@ -309,7 +309,7 @@ pub fn main() !void { |
| 309 | var first = true; | 309 | var first = true; |
| 310 | try stdout.writeAll("#if "); | 310 | try stdout.writeAll("#if "); |
| 311 | 311 | ||
| 312 | for (arches) |arch, i| { | 312 | for (arches, 0..) |arch, i| { |
| 313 | if (multi_sym.present[i]) continue; | 313 | if (multi_sym.present[i]) continue; |
| 314 | 314 | ||
| 315 | if (!first) try stdout.writeAll(" && "); | 315 | if (!first) try stdout.writeAll(" && "); |
| ... | @@ -333,7 +333,7 @@ pub fn main() !void { | ... | @@ -333,7 +333,7 @@ pub fn main() !void { |
| 333 | } else if (multi_sym.isWeak64()) { | 333 | } else if (multi_sym.isWeak64()) { |
| 334 | try stdout.print("WEAK64 {s}\n", .{name}); | 334 | try stdout.print("WEAK64 {s}\n", .{name}); |
| 335 | } else { | 335 | } else { |
| 336 | for (arches) |arch, i| { | 336 | for (arches, 0..) |arch, i| { |
| 337 | log.info("symbol '{s}' binding on {s}: {d}", .{ | 337 | log.info("symbol '{s}' binding on {s}: {d}", .{ |
| 338 | name, @tagName(arch), multi_sym.binding[i], | 338 | name, @tagName(arch), multi_sym.binding[i], |
| 339 | }); | 339 | }); |
| ... | @@ -355,7 +355,7 @@ pub fn main() !void { | ... | @@ -355,7 +355,7 @@ pub fn main() !void { |
| 355 | } else if (multi_sym.isPtr2Size()) { | 355 | } else if (multi_sym.isPtr2Size()) { |
| 356 | try stdout.print(".size {s}, PTR2_SIZE_BYTES\n", .{name}); | 356 | try stdout.print(".size {s}, PTR2_SIZE_BYTES\n", .{name}); |
| 357 | } else { | 357 | } else { |
| 358 | for (arches) |arch, i| { | 358 | for (arches, 0..) |arch, i| { |
| 359 | log.info("symbol '{s}' size on {s}: {d}", .{ | 359 | log.info("symbol '{s}' size on {s}: {d}", .{ |
| 360 | name, @tagName(arch), multi_sym.size[i], | 360 | name, @tagName(arch), multi_sym.size[i], |
| 361 | }); | 361 | }); |
| ... | @@ -415,7 +415,7 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian) | ... | @@ -415,7 +415,7 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian) |
| 415 | 415 | ||
| 416 | // Find the offset of the dynamic symbol table. | 416 | // Find the offset of the dynamic symbol table. |
| 417 | var dynsym_index: u16 = 0; | 417 | var dynsym_index: u16 = 0; |
| 418 | for (shdrs) |shdr, i| { | 418 | for (shdrs, 0..) |shdr, i| { |
| 419 | const sh_name = try arena.dupe(u8, mem.sliceTo(shstrtab[s(shdr.sh_name)..], 0)); | 419 | const sh_name = try arena.dupe(u8, mem.sliceTo(shstrtab[s(shdr.sh_name)..], 0)); |
| 420 | log.debug("found section: {s}", .{sh_name}); | 420 | log.debug("found section: {s}", .{sh_name}); |
| 421 | if (mem.eql(u8, sh_name, ".dynsym")) { | 421 | if (mem.eql(u8, sh_name, ".dynsym")) { |
| ... | @@ -566,7 +566,7 @@ fn archIndex(arch: std.Target.Cpu.Arch) u8 { | ... | @@ -566,7 +566,7 @@ fn archIndex(arch: std.Target.Cpu.Arch) u8 { |
| 566 | } | 566 | } |
| 567 | 567 | ||
| 568 | fn archSetName(arch_set: [arches.len]bool) []const u8 { | 568 | fn archSetName(arch_set: [arches.len]bool) []const u8 { |
| 569 | for (arches) |arch, i| { | 569 | for (arches, 0..) |arch, i| { |
| 570 | if (arch_set[i]) { | 570 | if (arch_set[i]) { |
| 571 | return @tagName(arch); | 571 | return @tagName(arch); |
| 572 | } | 572 | } |
tools/update_clang_options.zig+1-1| ... | @@ -573,7 +573,7 @@ pub fn main() anyerror!void { | ... | @@ -573,7 +573,7 @@ pub fn main() anyerror!void { |
| 573 | const Feature = @field(cpu_targets, decl.name).Feature; | 573 | const Feature = @field(cpu_targets, decl.name).Feature; |
| 574 | const all_features = @field(cpu_targets, decl.name).all_features; | 574 | const all_features = @field(cpu_targets, decl.name).all_features; |
| 575 | 575 | ||
| 576 | for (all_features) |feat, i| { | 576 | for (all_features, 0..) |feat, i| { |
| 577 | const llvm_name = feat.llvm_name orelse continue; | 577 | const llvm_name = feat.llvm_name orelse continue; |
| 578 | const zig_feat = @intToEnum(Feature, i); | 578 | const zig_feat = @intToEnum(Feature, i); |
| 579 | const zig_name = @tagName(zig_feat); | 579 | const zig_name = @tagName(zig_feat); |
tools/update_cpu_features.zig+2-2| ... | @@ -978,7 +978,7 @@ pub fn main() anyerror!void { | ... | @@ -978,7 +978,7 @@ pub fn main() anyerror!void { |
| 978 | } | 978 | } |
| 979 | } else { | 979 | } else { |
| 980 | var threads = try arena.alloc(std.Thread, llvm_targets.len); | 980 | var threads = try arena.alloc(std.Thread, llvm_targets.len); |
| 981 | for (llvm_targets) |llvm_target, i| { | 981 | for (llvm_targets, 0..) |llvm_target, i| { |
| 982 | const job = Job{ | 982 | const job = Job{ |
| 983 | .llvm_tblgen_exe = llvm_tblgen_exe, | 983 | .llvm_tblgen_exe = llvm_tblgen_exe, |
| 984 | .llvm_src_root = llvm_src_root, | 984 | .llvm_src_root = llvm_src_root, |
| ... | @@ -1305,7 +1305,7 @@ fn processOneTarget(job: Job) anyerror!void { | ... | @@ -1305,7 +1305,7 @@ fn processOneTarget(job: Job) anyerror!void { |
| 1305 | } | 1305 | } |
| 1306 | try w.writeAll( | 1306 | try w.writeAll( |
| 1307 | \\ const ti = @typeInfo(Feature); | 1307 | \\ const ti = @typeInfo(Feature); |
| 1308 | \\ for (result) |*elem, i| { | 1308 | \\ for (&result, 0..) |*elem, i| { |
| 1309 | \\ elem.index = i; | 1309 | \\ elem.index = i; |
| 1310 | \\ elem.name = ti.Enum.fields[i].name; | 1310 | \\ elem.name = ti.Enum.fields[i].name; |
| 1311 | \\ } | 1311 | \\ } |
tools/update_crc_catalog.zig+1-1| ... | @@ -116,7 +116,7 @@ pub fn main() anyerror!void { | ... | @@ -116,7 +116,7 @@ pub fn main() anyerror!void { |
| 116 | defer buf.deinit(); | 116 | defer buf.deinit(); |
| 117 | 117 | ||
| 118 | var prev: u8 = 0; | 118 | var prev: u8 = 0; |
| 119 | for (snakecase) |c, i| { | 119 | for (snakecase, 0..) |c, i| { |
| 120 | if (c == '_') { | 120 | if (c == '_') { |
| 121 | // do nothing | 121 | // do nothing |
| 122 | } else if (i == 0) { | 122 | } else if (i == 0) { |
tools/update_spirv_features.zig+2-2| ... | @@ -130,7 +130,7 @@ pub fn main() !void { | ... | @@ -130,7 +130,7 @@ pub fn main() !void { |
| 130 | \\ | 130 | \\ |
| 131 | ); | 131 | ); |
| 132 | 132 | ||
| 133 | for (versions) |ver, i| { | 133 | for (versions, 0..) |ver, i| { |
| 134 | try w.print( | 134 | try w.print( |
| 135 | \\ result[@enumToInt(Feature.v{0}_{1})] = .{{ | 135 | \\ result[@enumToInt(Feature.v{0}_{1})] = .{{ |
| 136 | \\ .llvm_name = null, | 136 | \\ .llvm_name = null, |
| ... | @@ -203,7 +203,7 @@ pub fn main() !void { | ... | @@ -203,7 +203,7 @@ pub fn main() !void { |
| 203 | 203 | ||
| 204 | try w.writeAll( | 204 | try w.writeAll( |
| 205 | \\ const ti = @typeInfo(Feature); | 205 | \\ const ti = @typeInfo(Feature); |
| 206 | \\ for (result) |*elem, i| { | 206 | \\ for (&result, 0..) |*elem, i| { |
| 207 | \\ elem.index = i; | 207 | \\ elem.index = i; |
| 208 | \\ elem.name = ti.Enum.fields[i].name; | 208 | \\ elem.name = ti.Enum.fields[i].name; |
| 209 | \\ } | 209 | \\ } |