authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-21 20:20:48-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-06-21 20:20:48-04:00
logc6844072ce440f581787bf97909261084a9edc6c
treeb0cade24a1ee14777be05644c19d76d158c3ab29
parent8a6de78e0787015153707361a58659834d4c39c2
parent7bebb24838a603a436b58e49ee85110af9e8e05f
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #9047 from g-w1/spider-astgen

stage2 astgen: catch unused vars

226 files changed, 1412 insertions(+), 775 deletions(-)

doc/docgen.zig-12
......@@ -1017,7 +1017,6 @@ fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: anytype, source_token: To
10171017}
10181018
10191019fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8, do_code_tests: bool) !void {
1020 var code_progress_index: usize = 0;
10211020 var progress = Progress{};
10221021 const root_node = try progress.start("Generating docgen examples", toc.nodes.len);
10231022 defer root_node.end();
......@@ -1090,7 +1089,6 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
10901089
10911090 switch (code.id) {
10921091 Code.Id.Exe => |expected_outcome| code_block: {
1093 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ code.name, exe_ext });
10941092 var build_args = std.ArrayList([]const u8).init(allocator);
10951093 defer build_args.deinit();
10961094 try build_args.appendSlice(&[_][]const u8{
......@@ -1361,19 +1359,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
13611359 },
13621360 Code.Id.Obj => |maybe_error_match| {
13631361 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ code.name, obj_ext });
1364 const tmp_obj_file_name = try fs.path.join(
1365 allocator,
1366 &[_][]const u8{ tmp_dir_name, name_plus_obj_ext },
1367 );
13681362 var build_args = std.ArrayList([]const u8).init(allocator);
13691363 defer build_args.deinit();
13701364
1371 const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{s}.h", .{code.name});
1372 const output_h_file_name = try fs.path.join(
1373 allocator,
1374 &[_][]const u8{ tmp_dir_name, name_plus_h_ext },
1375 );
1376
13771365 try build_args.appendSlice(&[_][]const u8{
13781366 zig_exe,
13791367 "build-obj",
lib/std/Progress.zig+1-1
......@@ -295,7 +295,7 @@ fn refreshWithHeldLock(self: *Progress) void {
295295 end += 1;
296296 }
297297
298 _ = file.write(self.output_buffer[0..end]) catch |e| {
298 _ = file.write(self.output_buffer[0..end]) catch {
299299 // Stop trying to write to this file once it errors.
300300 self.terminal = null;
301301 };
lib/std/SemanticVersion.zig+2-1
......@@ -162,6 +162,7 @@ pub fn format(
162162 options: std.fmt.FormatOptions,
163163 out_stream: anytype,
164164) !void {
165 _ = options;
165166 if (fmt.len != 0) @compileError("Unknown format string: '" ++ fmt ++ "'");
166167 try std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
167168 if (self.pre) |pre| try std.fmt.format(out_stream, "-{s}", .{pre});
......@@ -259,7 +260,7 @@ test "SemanticVersion format" {
259260
260261 // Invalid version string that may overflow.
261262 const big_invalid = "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12";
262 if (parse(big_invalid)) |ver| std.debug.panic("expected error, found {}", .{ver}) else |err| {}
263 if (parse(big_invalid)) |ver| std.debug.panic("expected error, found {}", .{ver}) else |_| {}
263264}
264265
265266test "SemanticVersion precedence" {
lib/std/Thread.zig+2-2
......@@ -518,8 +518,8 @@ pub fn cpuCount() CpuCountError!usize {
518518 },
519519 .haiku => {
520520 var count: u32 = undefined;
521 var system_info: os.system_info = undefined;
522 const rc = os.system.get_system_info(&system_info);
521 // var system_info: os.system_info = undefined;
522 // const rc = os.system.get_system_info(&system_info);
523523 count = system_info.cpu_count;
524524 return @intCast(usize, count);
525525 },
lib/std/Thread/Condition.zig+8-2
......@@ -40,12 +40,18 @@ else
4040
4141pub const SingleThreadedCondition = struct {
4242 pub fn wait(cond: *SingleThreadedCondition, mutex: *Mutex) void {
43 _ = cond;
44 _ = mutex;
4345 unreachable; // deadlock detected
4446 }
4547
46 pub fn signal(cond: *SingleThreadedCondition) void {}
48 pub fn signal(cond: *SingleThreadedCondition) void {
49 _ = cond;
50 }
4751
48 pub fn broadcast(cond: *SingleThreadedCondition) void {}
52 pub fn broadcast(cond: *SingleThreadedCondition) void {
53 _ = cond;
54 }
4955};
5056
5157pub const WindowsCondition = struct {
lib/std/Thread/StaticResetEvent.zig+6-1
......@@ -105,6 +105,7 @@ pub const DebugEvent = struct {
105105 }
106106
107107 pub fn timedWait(ev: *DebugEvent, timeout: u64) TimedWaitResult {
108 _ = timeout;
108109 switch (ev.state) {
109110 .unset => return .timed_out,
110111 .set => return .event_set,
......@@ -174,7 +175,10 @@ pub const AtomicEvent = struct {
174175 };
175176
176177 pub const SpinFutex = struct {
177 fn wake(waiters: *u32, wake_count: u32) void {}
178 fn wake(waiters: *u32, wake_count: u32) void {
179 _ = waiters;
180 _ = wake_count;
181 }
178182
179183 fn wait(waiters: *u32, timeout: ?u64) !void {
180184 var timer: time.Timer = undefined;
......@@ -193,6 +197,7 @@ pub const AtomicEvent = struct {
193197
194198 pub const LinuxFutex = struct {
195199 fn wake(waiters: *u32, wake_count: u32) void {
200 _ = wake_count;
196201 const waiting = std.math.maxInt(i32); // wake_count
197202 const ptr = @ptrCast(*const i32, waiters);
198203 const rc = linux.futex_wake(ptr, linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, waiting);
lib/std/array_hash_map.zig+16-9
......@@ -40,9 +40,11 @@ pub fn StringArrayHashMapUnmanaged(comptime V: type) type {
4040
4141pub const StringContext = struct {
4242 pub fn hash(self: @This(), s: []const u8) u32 {
43 _ = self;
4344 return hashString(s);
4445 }
4546 pub fn eql(self: @This(), a: []const u8, b: []const u8) bool {
47 _ = self;
4648 return eqlString(a, b);
4749 }
4850};
......@@ -1324,17 +1326,17 @@ pub fn ArrayHashMapUnmanaged(
13241326 }
13251327 fn removeFromIndexByIndexGeneric(self: *Self, entry_index: usize, ctx: ByIndexContext, header: *IndexHeader, comptime I: type, indexes: []Index(I)) void {
13261328 const slot = self.getSlotByIndex(entry_index, ctx, header, I, indexes);
1327 self.removeSlot(slot, header, I, indexes);
1329 removeSlot(slot, header, I, indexes);
13281330 }
13291331
13301332 fn removeFromIndexByKey(self: *Self, key: anytype, ctx: anytype, header: *IndexHeader, comptime I: type, indexes: []Index(I)) ?usize {
13311333 const slot = self.getSlotByKey(key, ctx, header, I, indexes) orelse return null;
13321334 const removed_entry_index = indexes[slot].entry_index;
1333 self.removeSlot(slot, header, I, indexes);
1335 removeSlot(slot, header, I, indexes);
13341336 return removed_entry_index;
13351337 }
13361338
1337 fn removeSlot(self: *Self, removed_slot: usize, header: *IndexHeader, comptime I: type, indexes: []Index(I)) void {
1339 fn removeSlot(removed_slot: usize, header: *IndexHeader, comptime I: type, indexes: []Index(I)) void {
13381340 const start_index = removed_slot +% 1;
13391341 const end_index = start_index +% indexes.len;
13401342
......@@ -1619,13 +1621,13 @@ pub fn ArrayHashMapUnmanaged(
16191621 if (self.index_header) |header| {
16201622 p("\n", .{});
16211623 switch (header.capacityIndexType()) {
1622 .u8 => self.dumpIndex(header, u8),
1623 .u16 => self.dumpIndex(header, u16),
1624 .u32 => self.dumpIndex(header, u32),
1624 .u8 => dumpIndex(header, u8),
1625 .u16 => dumpIndex(header, u16),
1626 .u32 => dumpIndex(header, u32),
16251627 }
16261628 }
16271629 }
1628 fn dumpIndex(self: Self, header: *IndexHeader, comptime I: type) void {
1630 fn dumpIndex(header: *IndexHeader, comptime I: type) void {
16291631 const p = std.debug.print;
16301632 p(" index len=0x{x} type={}\n", .{ header.length(), header.capacityIndexType() });
16311633 const indexes = header.indexes(I);
......@@ -1918,7 +1920,7 @@ test "iterator hash map" {
19181920 try testing.expect(count == 3);
19191921 try testing.expect(it.next() == null);
19201922
1921 for (buffer) |v, i| {
1923 for (buffer) |_, i| {
19221924 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
19231925 }
19241926
......@@ -1930,7 +1932,7 @@ test "iterator hash map" {
19301932 if (count >= 2) break;
19311933 }
19321934
1933 for (buffer[0..2]) |v, i| {
1935 for (buffer[0..2]) |_, i| {
19341936 try testing.expect(buffer[@intCast(usize, keys[i])] == values[i]);
19351937 }
19361938
......@@ -2154,6 +2156,7 @@ test "compile everything" {
21542156pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {
21552157 return struct {
21562158 fn hash(ctx: Context, key: K) u32 {
2159 _ = ctx;
21572160 return getAutoHashFn(usize, void)({}, @ptrToInt(key));
21582161 }
21592162 }.hash;
......@@ -2162,6 +2165,7 @@ pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context,
21622165pub fn getTrivialEqlFn(comptime K: type, comptime Context: type) (fn (Context, K, K) bool) {
21632166 return struct {
21642167 fn eql(ctx: Context, a: K, b: K) bool {
2168 _ = ctx;
21652169 return a == b;
21662170 }
21672171 }.eql;
......@@ -2177,6 +2181,7 @@ pub fn AutoContext(comptime K: type) type {
21772181pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {
21782182 return struct {
21792183 fn hash(ctx: Context, key: K) u32 {
2184 _ = ctx;
21802185 if (comptime trait.hasUniqueRepresentation(K)) {
21812186 return @truncate(u32, Wyhash.hash(0, std.mem.asBytes(&key)));
21822187 } else {
......@@ -2191,6 +2196,7 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)
21912196pub fn getAutoEqlFn(comptime K: type, comptime Context: type) (fn (Context, K, K) bool) {
21922197 return struct {
21932198 fn eql(ctx: Context, a: K, b: K) bool {
2199 _ = ctx;
21942200 return meta.eql(a, b);
21952201 }
21962202 }.eql;
......@@ -2217,6 +2223,7 @@ pub fn autoEqlIsCheap(comptime K: type) bool {
22172223pub fn getAutoHashStratFn(comptime K: type, comptime Context: type, comptime strategy: std.hash.Strategy) (fn (Context, K) u32) {
22182224 return struct {
22192225 fn hash(ctx: Context, key: K) u32 {
2226 _ = ctx;
22202227 var hasher = Wyhash.init(0);
22212228 std.hash.autoHashStrat(&hasher, key, strategy);
22222229 return @truncate(u32, hasher.final());
lib/std/atomic/Atomic.zig+2
......@@ -232,6 +232,7 @@ test "Atomic.loadUnchecked" {
232232
233233test "Atomic.storeUnchecked" {
234234 inline for (atomicIntTypes()) |Int| {
235 _ = Int;
235236 var x = Atomic(usize).init(5);
236237 x.storeUnchecked(10);
237238 try testing.expectEqual(x.loadUnchecked(), 10);
......@@ -250,6 +251,7 @@ test "Atomic.load" {
250251test "Atomic.store" {
251252 inline for (atomicIntTypes()) |Int| {
252253 inline for (.{ .Unordered, .Monotonic, .Release, .SeqCst }) |ordering| {
254 _ = Int;
253255 var x = Atomic(usize).init(5);
254256 x.store(10, ordering);
255257 try testing.expectEqual(x.load(.SeqCst), 10);
lib/std/base64.zig-5
......@@ -112,9 +112,6 @@ pub const Base64Encoder = struct {
112112 const out_len = encoder.calcSize(source.len);
113113 assert(dest.len >= out_len);
114114
115 const nibbles = source.len / 3;
116 const leftover = source.len - 3 * nibbles;
117
118115 var acc: u12 = 0;
119116 var acc_len: u4 = 0;
120117 var out_idx: usize = 0;
......@@ -223,7 +220,6 @@ pub const Base64Decoder = struct {
223220 if (decoder.pad_char) |pad_char| {
224221 const padding_len = acc_len / 2;
225222 var padding_chars: usize = 0;
226 var i: usize = 0;
227223 for (leftover) |c| {
228224 if (c != pad_char) {
229225 return if (c == Base64Decoder.invalid_char) error.InvalidCharacter else error.InvalidPadding;
......@@ -302,7 +298,6 @@ pub const Base64DecoderWithIgnore = struct {
302298 var leftover = source[leftover_idx.?..];
303299 if (decoder.pad_char) |pad_char| {
304300 var padding_chars: usize = 0;
305 var i: usize = 0;
306301 for (leftover) |c| {
307302 if (decoder_with_ignore.char_is_ignored[c]) continue;
308303 if (c != pad_char) {
lib/std/bit_set.zig+4-2
......@@ -84,6 +84,7 @@ pub fn IntegerBitSet(comptime size: u16) type {
8484
8585 /// Returns the number of bits in this bit set
8686 pub inline fn capacity(self: Self) usize {
87 _ = self;
8788 return bit_length;
8889 }
8990
......@@ -311,6 +312,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
311312
312313 /// Returns the number of bits in this bit set
313314 pub inline fn capacity(self: Self) usize {
315 _ = self;
314316 return bit_length;
315317 }
316318
......@@ -373,7 +375,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type {
373375
374376 /// Flips every bit in the bit set.
375377 pub fn toggleAll(self: *Self) void {
376 for (self.masks) |*mask, i| {
378 for (self.masks) |*mask| {
377379 mask.* = ~mask.*;
378380 }
379381
......@@ -642,7 +644,7 @@ pub const DynamicBitSetUnmanaged = struct {
642644 if (bit_length == 0) return;
643645
644646 const num_masks = numMasks(self.bit_length);
645 for (self.masks[0..num_masks]) |*mask, i| {
647 for (self.masks[0..num_masks]) |*mask| {
646648 mask.* = ~mask.*;
647649 }
648650
lib/std/build.zig+5-2
......@@ -390,6 +390,7 @@ pub const Builder = struct {
390390 }
391391
392392 pub fn version(self: *const Builder, major: u32, minor: u32, patch: u32) LibExeObjStep.SharedLibKind {
393 _ = self;
393394 return .{
394395 .versioned = .{
395396 .major = major,
......@@ -543,7 +544,7 @@ pub const Builder = struct {
543544 return null;
544545 },
545546 .scalar => |s| {
546 const n = std.fmt.parseFloat(T, s) catch |err| {
547 const n = std.fmt.parseFloat(T, s) catch {
547548 warn("Expected -D{s} to be a float of type {s}.\n\n", .{ name, @typeName(T) });
548549 self.markInvalidUserInput();
549550 return null;
......@@ -3129,7 +3130,9 @@ pub const Step = struct {
31293130 self.dependencies.append(other) catch unreachable;
31303131 }
31313132
3132 fn makeNoOp(self: *Step) anyerror!void {}
3133 fn makeNoOp(self: *Step) anyerror!void {
3134 _ = self;
3135 }
31333136
31343137 pub fn cast(step: *Step, comptime T: type) ?*T {
31353138 if (step.id == T.base_id) {
lib/std/build/InstallRawStep.zig+2
......@@ -139,6 +139,7 @@ const BinaryElfOutput = struct {
139139 }
140140
141141 fn segmentSortCompare(context: void, left: *BinaryElfSegment, right: *BinaryElfSegment) bool {
142 _ = context;
142143 if (left.physicalAddress < right.physicalAddress) {
143144 return true;
144145 }
......@@ -149,6 +150,7 @@ const BinaryElfOutput = struct {
149150 }
150151
151152 fn sectionSortCompare(context: void, left: *BinaryElfSection, right: *BinaryElfSection) bool {
153 _ = context;
152154 return left.binaryOffset < right.binaryOffset;
153155 }
154156};
lib/std/builtin.zig+3
......@@ -65,6 +65,8 @@ pub const StackTrace = struct {
6565 options: std.fmt.FormatOptions,
6666 writer: anytype,
6767 ) !void {
68 _ = fmt;
69 _ = options;
6870 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
6971 defer arena.deinit();
7072 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
......@@ -521,6 +523,7 @@ pub const Version = struct {
521523 options: std.fmt.FormatOptions,
522524 out_stream: anytype,
523525 ) !void {
526 _ = options;
524527 if (fmt.len == 0) {
525528 if (self.patch == 0) {
526529 if (self.minor == 0) {
lib/std/c/tokenizer.zig+6-7
......@@ -351,7 +351,6 @@ pub const Tokenizer = struct {
351351 pp_directive: bool = false,
352352
353353 pub fn next(self: *Tokenizer) Token {
354 const start_index = self.index;
355354 var result = Token{
356355 .id = .Eof,
357356 .start = self.index,
......@@ -1380,12 +1379,12 @@ test "operators" {
13801379
13811380test "keywords" {
13821381 try expectTokens(
1383 \\auto break case char const continue default do
1384 \\double else enum extern float for goto if int
1385 \\long register return short signed sizeof static
1386 \\struct switch typedef union unsigned void volatile
1387 \\while _Bool _Complex _Imaginary inline restrict _Alignas
1388 \\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local
1382 \\auto break case char const continue default do
1383 \\double else enum extern float for goto if int
1384 \\long register return short signed sizeof static
1385 \\struct switch typedef union unsigned void volatile
1386 \\while _Bool _Complex _Imaginary inline restrict _Alignas
1387 \\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local
13891388 \\
13901389 , &[_]Token.Id{
13911390 .Keyword_auto,
lib/std/compress/gzip.zig+2
......@@ -62,6 +62,8 @@ pub fn GzipStream(comptime ReaderType: type) type {
6262 const XFL = header[8];
6363 // Operating system where the compression took place
6464 const OS = header[9];
65 _ = XFL;
66 _ = OS;
6567
6668 if (FLG & FEXTRA != 0) {
6769 // Skip the extra data, we could read and expose it to the user
lib/std/compress/zlib.zig+1
......@@ -35,6 +35,7 @@ pub fn ZlibStream(comptime ReaderType: type) type {
3535 const CM = @truncate(u4, header[0]);
3636 const CINFO = @truncate(u4, header[0] >> 4);
3737 const FCHECK = @truncate(u5, header[1]);
38 _ = FCHECK;
3839 const FDICT = @truncate(u1, header[1] >> 5);
3940
4041 if ((@as(u16, header[0]) << 8 | header[1]) % 31 != 0)
lib/std/comptime_string_map.zig+1
......@@ -23,6 +23,7 @@ pub fn ComptimeStringMap(comptime V: type, comptime kvs: anytype) type {
2323 var sorted_kvs: [kvs.len]KV = undefined;
2424 const lenAsc = (struct {
2525 fn lenAsc(context: void, a: KV, b: KV) bool {
26 _ = context;
2627 return a.key.len < b.key.len;
2728 }
2829 }).lenAsc;
lib/std/crypto/25519/ed25519.zig+1-1
......@@ -346,7 +346,7 @@ test "ed25519 test vectors" {
346346 .expected = error.IdentityElement, // 11 - small-order A
347347 },
348348 };
349 for (entries) |entry, i| {
349 for (entries) |entry| {
350350 var msg: [entry.msg_hex.len / 2]u8 = undefined;
351351 _ = try fmt.hexToBytes(&msg, entry.msg_hex);
352352 var public_key: [32]u8 = undefined;
lib/std/crypto/25519/scalar.zig-6
......@@ -330,13 +330,10 @@ pub const Scalar = struct {
330330 const carry9 = z02 >> 56;
331331 const c01 = carry9;
332332 const carry10 = (z12 + c01) >> 56;
333 const t21 = @truncate(u64, z12 + c01) & 0xffffffffffffff;
334333 const c11 = carry10;
335334 const carry11 = (z22 + c11) >> 56;
336 const t22 = @truncate(u64, z22 + c11) & 0xffffffffffffff;
337335 const c21 = carry11;
338336 const carry12 = (z32 + c21) >> 56;
339 const t23 = @truncate(u64, z32 + c21) & 0xffffffffffffff;
340337 const c31 = carry12;
341338 const carry13 = (z42 + c31) >> 56;
342339 const t24 = @truncate(u64, z42 + c31) & 0xffffffffffffff;
......@@ -605,13 +602,10 @@ const ScalarDouble = struct {
605602 const carry0 = z01 >> 56;
606603 const c00 = carry0;
607604 const carry1 = (z11 + c00) >> 56;
608 const t100 = @as(u64, @truncate(u64, z11 + c00)) & 0xffffffffffffff;
609605 const c10 = carry1;
610606 const carry2 = (z21 + c10) >> 56;
611 const t101 = @as(u64, @truncate(u64, z21 + c10)) & 0xffffffffffffff;
612607 const c20 = carry2;
613608 const carry3 = (z31 + c20) >> 56;
614 const t102 = @as(u64, @truncate(u64, z31 + c20)) & 0xffffffffffffff;
615609 const c30 = carry3;
616610 const carry4 = (z41 + c30) >> 56;
617611 const t103 = @as(u64, @truncate(u64, z41 + c30)) & 0xffffffffffffff;
lib/std/crypto/aes/soft.zig-8
......@@ -49,8 +49,6 @@ pub const Block = struct {
4949
5050 /// Encrypt a block with a round key.
5151 pub inline fn encrypt(block: Block, round_key: Block) Block {
52 const src = &block.repr;
53
5452 const s0 = block.repr[0];
5553 const s1 = block.repr[1];
5654 const s2 = block.repr[2];
......@@ -66,8 +64,6 @@ pub const Block = struct {
6664
6765 /// Encrypt a block with the last round key.
6866 pub inline fn encryptLast(block: Block, round_key: Block) Block {
69 const src = &block.repr;
70
7167 const t0 = block.repr[0];
7268 const t1 = block.repr[1];
7369 const t2 = block.repr[2];
......@@ -88,8 +84,6 @@ pub const Block = struct {
8884
8985 /// Decrypt a block with a round key.
9086 pub inline fn decrypt(block: Block, round_key: Block) Block {
91 const src = &block.repr;
92
9387 const s0 = block.repr[0];
9488 const s1 = block.repr[1];
9589 const s2 = block.repr[2];
......@@ -105,8 +99,6 @@ pub const Block = struct {
10599
106100 /// Decrypt a block with the last round key.
107101 pub inline fn decryptLast(block: Block, round_key: Block) Block {
108 const src = &block.repr;
109
110102 const t0 = block.repr[0];
111103 const t1 = block.repr[1];
112104 const t2 = block.repr[2];
lib/std/crypto/aes_gcm.zig-1
......@@ -114,7 +114,6 @@ test "Aes256Gcm - Empty message and no associated data" {
114114 const ad = "";
115115 const m = "";
116116 var c: [m.len]u8 = undefined;
117 var m2: [m.len]u8 = undefined;
118117 var tag: [Aes256Gcm.tag_length]u8 = undefined;
119118
120119 Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);
lib/std/crypto/aes_ocb.zig-1
......@@ -271,7 +271,6 @@ test "AesOcb test vector 1" {
271271 var c: [0]u8 = undefined;
272272 Aes128Ocb.encrypt(&c, &tag, "", "", nonce, k);
273273
274 var expected_c: [c.len]u8 = undefined;
275274 var expected_tag: [tag.len]u8 = undefined;
276275 _ = try hexToBytes(&expected_tag, "785407BFFFC8AD9EDCC5520AC9111EE6");
277276
lib/std/crypto/bcrypt.zig-2
......@@ -48,7 +48,6 @@ const State = struct {
4848 fn expand0(state: *State, key: []const u8) void {
4949 var i: usize = 0;
5050 var j: usize = 0;
51 var t: u32 = undefined;
5251 while (i < state.subkeys.len) : (i += 1) {
5352 state.subkeys[i] ^= toWord(key, &j);
5453 }
......@@ -75,7 +74,6 @@ const State = struct {
7574 fn expand(state: *State, data: []const u8, key: []const u8) void {
7675 var i: usize = 0;
7776 var j: usize = 0;
78 var t: u32 = undefined;
7977 while (i < state.subkeys.len) : (i += 1) {
8078 state.subkeys[i] ^= toWord(key, &j);
8179 }
lib/std/crypto/blake3.zig+1
......@@ -394,6 +394,7 @@ pub const Blake3 = struct {
394394 /// Construct a new `Blake3` for the key derivation function. The context
395395 /// string should be hardcoded, globally unique, and application-specific.
396396 pub fn initKdf(context: []const u8, options: KdfOptions) Blake3 {
397 _ = options;
397398 var context_hasher = Blake3.init_internal(IV, DERIVE_KEY_CONTEXT);
398399 context_hasher.update(context);
399400 var context_key: [KEY_LEN]u8 = undefined;
lib/std/crypto/chacha20.zig-1
......@@ -444,7 +444,6 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {
444444 if (comptime @sizeOf(usize) > 4) {
445445 // A big block is giant: 256 GiB, but we can avoid this limitation
446446 var remaining_blocks: u32 = @intCast(u32, (in.len / big_block));
447 var i: u32 = 0;
448447 while (remaining_blocks > 0) : (remaining_blocks -= 1) {
449448 ChaChaImpl(rounds_nb).chacha20Xor(out[cursor .. cursor + big_block], in[cursor .. cursor + big_block], k, c);
450449 c[1] += 1; // upper 32-bit of counter, generic chacha20Xor() doesn't know about this.
lib/std/crypto/gimli.zig+1
......@@ -219,6 +219,7 @@ pub const Hash = struct {
219219 const Self = @This();
220220
221221 pub fn init(options: Options) Self {
222 _ = options;
222223 return Self{
223224 .state = State{ .data = [_]u32{0} ** (State.BLOCKBYTES / 4) },
224225 .buf_off = 0,
lib/std/crypto/md5.zig+1
......@@ -45,6 +45,7 @@ pub const Md5 = struct {
4545 total_len: u64,
4646
4747 pub fn init(options: Options) Self {
48 _ = options;
4849 return Self{
4950 .s = [_]u32{
5051 0x67452301,
lib/std/crypto/pcurves/p256/scalar.zig+1-1
......@@ -63,7 +63,7 @@ pub fn add(a: CompressedScalar, b: CompressedScalar, endian: builtin.Endian) Non
6363
6464/// Return -s (mod L)
6565pub fn neg(s: CompressedScalar, endian: builtin.Endian) NonCanonicalError!CompressedScalar {
66 return (try Scalar.fromBytes(a, endian)).neg().toBytes(endian);
66 return (try Scalar.fromBytes(s, endian)).neg().toBytes(endian);
6767}
6868
6969/// Return (a-b) (mod L)
lib/std/crypto/sha1.zig+1
......@@ -43,6 +43,7 @@ pub const Sha1 = struct {
4343 total_len: u64 = 0,
4444
4545 pub fn init(options: Options) Self {
46 _ = options;
4647 return Self{
4748 .s = [_]u32{
4849 0x67452301,
lib/std/crypto/sha2.zig+2
......@@ -95,6 +95,7 @@ fn Sha2x32(comptime params: Sha2Params32) type {
9595 total_len: u64 = 0,
9696
9797 pub fn init(options: Options) Self {
98 _ = options;
9899 return Self{
99100 .s = [_]u32{
100101 params.iv0,
......@@ -462,6 +463,7 @@ fn Sha2x64(comptime params: Sha2Params64) type {
462463 total_len: u128 = 0,
463464
464465 pub fn init(options: Options) Self {
466 _ = options;
465467 return Self{
466468 .s = [_]u64{
467469 params.iv0,
lib/std/crypto/sha3.zig+1
......@@ -28,6 +28,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
2828 rate: usize,
2929
3030 pub fn init(options: Options) Self {
31 _ = options;
3132 return Self{ .s = [_]u8{0} ** 200, .offset = 0, .rate = 200 - (bits / 4) };
3233 }
3334
lib/std/crypto/tlcsprng.zig+1-1
......@@ -84,7 +84,7 @@ fn tlsCsprngFill(_: *const std.rand.Random, buffer: []u8) void {
8484 os.MAP_PRIVATE | os.MAP_ANONYMOUS,
8585 -1,
8686 0,
87 ) catch |err| {
87 ) catch {
8888 // Could not allocate memory for the local state, fall back to
8989 // the OS syscall.
9090 return fillWithOsEntropy(buffer);
lib/std/debug.zig+6-1
......@@ -325,6 +325,7 @@ pub fn writeStackTrace(
325325 debug_info: *DebugInfo,
326326 tty_config: TTY.Config,
327327) !void {
328 _ = allocator;
328329 if (builtin.strip_debug_info) return error.MissingDebugInfo;
329330 var frame_index: usize = 0;
330331 var frames_left: usize = std.math.min(stack_trace.index, stack_trace.instruction_addresses.len);
......@@ -680,6 +681,7 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf
680681 try di.coff.loadSections();
681682 if (di.coff.getSection(".debug_info")) |sec| {
682683 // This coff file has embedded DWARF debug info
684 _ = sec;
683685 // TODO: free the section data slices
684686 const debug_info_data = di.coff.getSectionData(".debug_info", allocator) catch null;
685687 const debug_abbrev_data = di.coff.getSectionData(".debug_abbrev", allocator) catch null;
......@@ -896,7 +898,6 @@ fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void {
896898 var buf: [mem.page_size]u8 = undefined;
897899 var line: usize = 1;
898900 var column: usize = 1;
899 var abs_index: usize = 0;
900901 while (true) {
901902 const amt_read = try f.read(buf[0..]);
902903 const slice = buf[0..amt_read];
......@@ -931,6 +932,7 @@ const MachoSymbol = struct {
931932 }
932933
933934 fn addressLessThan(context: void, lhs: MachoSymbol, rhs: MachoSymbol) bool {
935 _ = context;
934936 return lhs.address() < rhs.address();
935937 }
936938};
......@@ -1135,6 +1137,7 @@ pub const DebugInfo = struct {
11351137
11361138 if (os.dl_iterate_phdr(&ctx, anyerror, struct {
11371139 fn callback(info: *os.dl_phdr_info, size: usize, context: *CtxTy) !void {
1140 _ = size;
11381141 // The base address is too high
11391142 if (context.address < info.dlpi_addr)
11401143 return;
......@@ -1190,6 +1193,8 @@ pub const DebugInfo = struct {
11901193 }
11911194
11921195 fn lookupModuleHaiku(self: *DebugInfo, address: usize) !*ModuleDebugInfo {
1196 _ = self;
1197 _ = address;
11931198 @panic("TODO implement lookup module for Haiku");
11941199 }
11951200};
lib/std/dwarf.zig+4-2
......@@ -283,6 +283,7 @@ fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: anytype, endian: bu
283283}
284284
285285fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: bool, endian: builtin.Endian, comptime size: i32) !FormValue {
286 _ = allocator;
286287 // TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here.
287288 // `nosuspend` should be removed from all the function calls once it is fixed.
288289 return FormValue{
......@@ -310,6 +311,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed:
310311
311312// TODO the nosuspends here are workarounds
312313fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: builtin.Endian, size: i32) !FormValue {
314 _ = allocator;
313315 return FormValue{
314316 .Ref = switch (size) {
315317 1 => try nosuspend in_stream.readInt(u8, endian),
......@@ -453,13 +455,13 @@ pub const DwarfInfo = struct {
453455 if (this_die_obj.getAttr(AT_name)) |_| {
454456 const name = try this_die_obj.getAttrString(di, AT_name);
455457 break :x name;
456 } else if (this_die_obj.getAttr(AT_abstract_origin)) |ref| {
458 } else if (this_die_obj.getAttr(AT_abstract_origin)) |_| {
457459 // Follow the DIE it points to and repeat
458460 const ref_offset = try this_die_obj.getAttrRef(AT_abstract_origin);
459461 if (ref_offset > next_offset) return error.InvalidDebugInfo;
460462 try seekable.seekTo(this_unit_offset + ref_offset);
461463 this_die_obj = (try di.parseDie(in, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;
462 } else if (this_die_obj.getAttr(AT_specification)) |ref| {
464 } else if (this_die_obj.getAttr(AT_specification)) |_| {
463465 // Follow the DIE it points to and repeat
464466 const ref_offset = try this_die_obj.getAttrRef(AT_specification);
465467 if (ref_offset > next_offset) return error.InvalidDebugInfo;
lib/std/dynamic_library.zig+2-1
......@@ -66,6 +66,7 @@ pub fn get_DYNAMIC() ?[*]elf.Dyn {
6666}
6767
6868pub fn linkmap_iterator(phdrs: []elf.Phdr) !LinkMap.Iterator {
69 _ = phdrs;
6970 const _DYNAMIC = get_DYNAMIC() orelse {
7071 // No PT_DYNAMIC means this is either a statically-linked program or a
7172 // badly corrupted dynamically-linked one.
......@@ -407,7 +408,7 @@ test "dynamic_library" {
407408 else => return error.SkipZigTest,
408409 };
409410
410 const dynlib = DynLib.open(libname) catch |err| {
411 _ = DynLib.open(libname) catch |err| {
411412 try testing.expect(err == error.FileNotFound);
412413 return;
413414 };
lib/std/enums.zig+9-4
......@@ -18,7 +18,7 @@ const EnumField = std.builtin.TypeInfo.EnumField;
1818pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type {
1919 const StructField = std.builtin.TypeInfo.StructField;
2020 var fields: []const StructField = &[_]StructField{};
21 for (std.meta.fields(E)) |field, i| {
21 for (std.meta.fields(E)) |field| {
2222 fields = fields ++ &[_]StructField{.{
2323 .name = field.name,
2424 .field_type = Data,
......@@ -144,7 +144,7 @@ pub fn directEnumArrayDefault(
144144) [directEnumArrayLen(E, max_unused_slots)]Data {
145145 const len = comptime directEnumArrayLen(E, max_unused_slots);
146146 var result: [len]Data = if (default) |d| [_]Data{d} ** len else undefined;
147 inline for (@typeInfo(@TypeOf(init_values)).Struct.fields) |f, i| {
147 inline for (@typeInfo(@TypeOf(init_values)).Struct.fields) |f| {
148148 const enum_value = @field(E, f.name);
149149 const index = @intCast(usize, @enumToInt(enum_value));
150150 result[index] = @field(init_values, f.name);
......@@ -334,6 +334,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {
334334/// TODO: Once #8169 is fixed, consider switching this param
335335/// back to an optional.
336336pub fn NoExtension(comptime Self: type) type {
337 _ = Self;
337338 return NoExt;
338339}
339340const NoExt = struct {};
......@@ -729,6 +730,7 @@ test "std.enums.ensureIndexer" {
729730}
730731
731732fn ascByValue(ctx: void, comptime a: EnumField, comptime b: EnumField) bool {
733 _ = ctx;
732734 return a.value < b.value;
733735}
734736pub fn EnumIndexer(comptime E: type) type {
......@@ -743,9 +745,11 @@ pub fn EnumIndexer(comptime E: type) type {
743745 pub const Key = E;
744746 pub const count: usize = 0;
745747 pub fn indexOf(e: E) usize {
748 _ = e;
746749 unreachable;
747750 }
748751 pub fn keyForIndex(i: usize) E {
752 _ = i;
749753 unreachable;
750754 }
751755 };
......@@ -753,10 +757,11 @@ pub fn EnumIndexer(comptime E: type) type {
753757 std.sort.sort(EnumField, &fields, {}, ascByValue);
754758 const min = fields[0].value;
755759 const max = fields[fields.len - 1].value;
760 const fields_len = fields.len;
756761 if (max - min == fields.len - 1) {
757762 return struct {
758763 pub const Key = E;
759 pub const count = fields.len;
764 pub const count = fields_len;
760765 pub fn indexOf(e: E) usize {
761766 return @intCast(usize, @enumToInt(e) - min);
762767 }
......@@ -774,7 +779,7 @@ pub fn EnumIndexer(comptime E: type) type {
774779
775780 return struct {
776781 pub const Key = E;
777 pub const count = fields.len;
782 pub const count = fields_len;
778783 pub fn indexOf(e: E) usize {
779784 for (keys) |k, i| {
780785 if (k == e) return i;
lib/std/event/channel.zig-1
......@@ -308,7 +308,6 @@ test "std.event.Channel wraparound" {
308308
309309 // add items to channel and pull them out until
310310 // the buffer wraps around, make sure it doesn't crash.
311 var result: i32 = undefined;
312311 channel.put(5);
313312 try testing.expectEqual(@as(i32, 5), channel.get());
314313 channel.put(6);
lib/std/event/group.zig+1-1
......@@ -130,7 +130,7 @@ test "std.event.Group" {
130130 // TODO this file has bit-rotted. repair it
131131 if (true) return error.SkipZigTest;
132132
133 const handle = async testGroup(std.heap.page_allocator);
133 _ = async testGroup(std.heap.page_allocator);
134134}
135135fn testGroup(allocator: *Allocator) callconv(.Async) void {
136136 var count: usize = 0;
lib/std/event/loop.zig+2-2
......@@ -345,7 +345,7 @@ pub const Loop = struct {
345345 );
346346 errdefer windows.CloseHandle(self.os_data.io_port);
347347
348 for (self.eventfd_resume_nodes) |*eventfd_node, i| {
348 for (self.eventfd_resume_nodes) |*eventfd_node| {
349349 eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{
350350 .data = ResumeNode.EventFd{
351351 .base = ResumeNode{
......@@ -680,7 +680,7 @@ pub const Loop = struct {
680680 fn run(func_args: Args, loop: *Loop, allocator: *mem.Allocator) void {
681681 loop.beginOneEvent();
682682 loop.yield();
683 const result = @call(.{}, func, func_args);
683 @call(.{}, func, func_args); // compile error when called with non-void ret type
684684 suspend {
685685 loop.finishOneEvent();
686686 allocator.destroy(@frame());
lib/std/event/rwlock.zig+1-1
......@@ -225,7 +225,7 @@ test "std.event.RwLock" {
225225 var lock = RwLock.init();
226226 defer lock.deinit();
227227
228 const handle = testLock(std.heap.page_allocator, &lock);
228 _ = testLock(std.heap.page_allocator, &lock);
229229
230230 const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
231231 try testing.expectEqualSlices(i32, expected_result, shared_test_data);
lib/std/fmt.zig+14-4
......@@ -369,6 +369,7 @@ pub fn format(
369369}
370370
371371pub fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @TypeOf(writer).Error!void {
372 _ = options;
372373 const T = @TypeOf(value);
373374
374375 switch (@typeInfo(T)) {
......@@ -553,7 +554,7 @@ pub fn formatType(
553554 .Many, .C => {
554555 if (actual_fmt.len == 0)
555556 @compileError("cannot format pointer without a specifier (i.e. {s} or {*})");
556 if (ptr_info.sentinel) |sentinel| {
557 if (ptr_info.sentinel) |_| {
557558 return formatType(mem.span(value), actual_fmt, options, writer, max_depth);
558559 }
559560 if (ptr_info.child == u8) {
......@@ -741,6 +742,8 @@ fn formatSliceHexImpl(comptime case: Case) type {
741742 options: std.fmt.FormatOptions,
742743 writer: anytype,
743744 ) !void {
745 _ = fmt;
746 _ = options;
744747 var buf: [2]u8 = undefined;
745748
746749 for (bytes) |c| {
......@@ -777,6 +780,8 @@ fn formatSliceEscapeImpl(comptime case: Case) type {
777780 options: std.fmt.FormatOptions,
778781 writer: anytype,
779782 ) !void {
783 _ = fmt;
784 _ = options;
780785 var buf: [4]u8 = undefined;
781786
782787 buf[0] = '\\';
......@@ -820,6 +825,7 @@ fn formatSizeImpl(comptime radix: comptime_int) type {
820825 options: FormatOptions,
821826 writer: anytype,
822827 ) !void {
828 _ = fmt;
823829 if (value == 0) {
824830 return writer.writeAll("0B");
825831 }
......@@ -903,6 +909,7 @@ pub fn formatAsciiChar(
903909 options: FormatOptions,
904910 writer: anytype,
905911) !void {
912 _ = options;
906913 return writer.writeAll(@as(*const [1]u8, &c));
907914}
908915
......@@ -1140,7 +1147,7 @@ pub fn formatFloatHexadecimal(
11401147
11411148 // +1 for the decimal part.
11421149 var buf: [1 + mantissa_digits]u8 = undefined;
1143 const N = formatIntBuf(&buf, mantissa, 16, .lower, .{ .fill = '0', .width = 1 + mantissa_digits });
1150 _ = formatIntBuf(&buf, mantissa, 16, .lower, .{ .fill = '0', .width = 1 + mantissa_digits });
11441151
11451152 try writer.writeAll("0x");
11461153 try writer.writeByte(buf[0]);
......@@ -1362,6 +1369,8 @@ pub fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, case: Case, options
13621369}
13631370
13641371fn formatDuration(ns: u64, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
1372 _ = fmt;
1373 _ = options;
13651374 var ns_remaining = ns;
13661375 inline for (.{
13671376 .{ .ns = 365 * std.time.ns_per_day, .sep = 'y' },
......@@ -2152,6 +2161,7 @@ test "custom" {
21522161 options: FormatOptions,
21532162 writer: anytype,
21542163 ) !void {
2164 _ = options;
21552165 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {
21562166 return std.fmt.format(writer, "({d:.3},{d:.3})", .{ self.x, self.y });
21572167 } else if (comptime std.mem.eql(u8, fmt, "d")) {
......@@ -2162,7 +2172,6 @@ test "custom" {
21622172 }
21632173 };
21642174
2165 var buf1: [32]u8 = undefined;
21662175 var value = Vec2{
21672176 .x = 10.2,
21682177 .y = 2.22,
......@@ -2220,7 +2229,7 @@ test "union" {
22202229 try std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
22212230
22222231 const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});
2223 try std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
2232 try std.testing.expect(mem.eql(u8, eu_result[0..3], "EU@"));
22242233}
22252234
22262235test "enum" {
......@@ -2341,6 +2350,7 @@ test "formatType max_depth" {
23412350 options: FormatOptions,
23422351 writer: anytype,
23432352 ) !void {
2353 _ = options;
23442354 if (fmt.len == 0) {
23452355 return std.fmt.format(writer, "({d:.3},{d:.3})", .{ self.x, self.y });
23462356 } else {
lib/std/fmt/parse_float.zig-1
......@@ -200,7 +200,6 @@ const ParseResult = enum {
200200
201201fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
202202 var digit_index: usize = 0;
203 var negative = false;
204203 var negative_exp = false;
205204 var exponent: i32 = 0;
206205
lib/std/fs.zig+4-3
......@@ -477,7 +477,7 @@ pub const Dir = struct {
477477 }
478478
479479 var stat_info: os.libc_stat = undefined;
480 const rc2 = os.system._kern_read_stat(
480 _ = os.system._kern_read_stat(
481481 self.dir.fd,
482482 &haiku_entry.d_name,
483483 false,
......@@ -1541,7 +1541,7 @@ pub const Dir = struct {
15411541 self: Dir,
15421542 target_path: []const u8,
15431543 sym_link_path: []const u8,
1544 flags: SymLinkFlags,
1544 _: SymLinkFlags,
15451545 ) !void {
15461546 return os.symlinkatWasi(target_path, self.fd, sym_link_path);
15471547 }
......@@ -1879,6 +1879,7 @@ pub const Dir = struct {
18791879 /// * NtDll prefixed
18801880 /// TODO currently this ignores `flags`.
18811881 pub fn accessW(self: Dir, sub_path_w: [*:0]const u16, flags: File.OpenFlags) AccessError!void {
1882 _ = flags;
18821883 return os.faccessatW(self.fd, sub_path_w, 0, 0);
18831884 }
18841885
......@@ -2438,7 +2439,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
24382439 }) catch continue;
24392440
24402441 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;
2441 if (os.realpathZ(&resolved_path_buf, &real_path_buf)) |real_path| {
2442 if (os.realpathZ(resolved_path, &real_path_buf)) |real_path| {
24422443 // found a file, and hope it is the right file
24432444 if (real_path.len > out_buffer.len)
24442445 return error.NameTooLong;
lib/std/fs/path.zig+2-2
......@@ -579,7 +579,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 {
579579 // Now we know the disk designator to use, if any, and what kind it is. And our result
580580 // is big enough to append all the paths to.
581581 var correct_disk_designator = true;
582 for (paths[first_index..]) |p, i| {
582 for (paths[first_index..]) |p| {
583583 const parsed = windowsParsePath(p);
584584
585585 if (parsed.kind != WindowsPath.Kind.None) {
......@@ -660,7 +660,7 @@ pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 {
660660 }
661661 errdefer allocator.free(result);
662662
663 for (paths[first_index..]) |p, i| {
663 for (paths[first_index..]) |p| {
664664 var it = mem.tokenize(p, "/");
665665 while (it.next()) |component| {
666666 if (mem.eql(u8, component, ".")) {
lib/std/fs/test.zig+2
......@@ -541,6 +541,7 @@ test "makePath, put some files in it, deleteTree" {
541541 try tmp.dir.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
542542 try tmp.dir.deleteTree("os_test_tmp");
543543 if (tmp.dir.openDir("os_test_tmp", .{})) |dir| {
544 _ = dir;
544545 @panic("expected error");
545546 } else |err| {
546547 try testing.expect(err == error.FileNotFound);
......@@ -638,6 +639,7 @@ test "access file" {
638639
639640 try tmp.dir.makePath("os_test_tmp");
640641 if (tmp.dir.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{})) |ok| {
642 _ = ok;
641643 @panic("expected error");
642644 } else |err| {
643645 try testing.expect(err == error.FileNotFound);
lib/std/fs/wasi.zig+2
......@@ -36,6 +36,8 @@ pub const PreopenType = union(PreopenTypeTag) {
3636 }
3737
3838 pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype) !void {
39 _ = fmt;
40 _ = options;
3941 try out_stream.print("PreopenType{{ ", .{});
4042 switch (self) {
4143 PreopenType.Dir => |path| try out_stream.print(".Dir = '{}'", .{std.zig.fmtId(path)}),
lib/std/hash/cityhash.zig+1-1
......@@ -353,7 +353,6 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
353353
354354 var key: [256]u8 = undefined;
355355 var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;
356 var final: HashResult = 0;
357356
358357 std.mem.set(u8, &key, 0);
359358 std.mem.set(u8, &hashes_bytes, 0);
......@@ -376,6 +375,7 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
376375}
377376
378377fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
378 _ = seed;
379379 return CityHash32.hash(str);
380380}
381381
lib/std/hash/wyhash.zig-2
......@@ -166,8 +166,6 @@ pub const Wyhash = struct {
166166 }
167167
168168 pub fn final(self: *Wyhash) u64 {
169 const seed = self.state.seed;
170 const rem_len = @intCast(u5, self.buf_len);
171169 const rem_key = self.buf[0..self.buf_len];
172170
173171 return self.state.final(rem_key);
lib/std/hash_map.zig+7-1
......@@ -29,6 +29,7 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)
2929
3030 return struct {
3131 fn hash(ctx: Context, key: K) u64 {
32 _ = ctx;
3233 if (comptime trait.hasUniqueRepresentation(K)) {
3334 return Wyhash.hash(0, std.mem.asBytes(&key));
3435 } else {
......@@ -43,6 +44,7 @@ pub fn getAutoHashFn(comptime K: type, comptime Context: type) (fn (Context, K)
4344pub fn getAutoEqlFn(comptime K: type, comptime Context: type) (fn (Context, K, K) bool) {
4445 return struct {
4546 fn eql(ctx: Context, a: K, b: K) bool {
47 _ = ctx;
4648 return meta.eql(a, b);
4749 }
4850 }.eql;
......@@ -78,9 +80,11 @@ pub fn StringHashMapUnmanaged(comptime V: type) type {
7880
7981pub const StringContext = struct {
8082 pub fn hash(self: @This(), s: []const u8) u64 {
83 _ = self;
8184 return hashString(s);
8285 }
8386 pub fn eql(self: @This(), a: []const u8, b: []const u8) bool {
87 _ = self;
8488 return eqlString(a, b);
8589 }
8690};
......@@ -1809,7 +1813,7 @@ test "std.hash_map getOrPut" {
18091813
18101814 i = 0;
18111815 while (i < 20) : (i += 1) {
1812 var n = try map.getOrPutValue(i, 1);
1816 _ = try map.getOrPutValue(i, 1);
18131817 }
18141818
18151819 i = 0;
......@@ -1887,9 +1891,11 @@ test "std.hash_map clone" {
18871891test "std.hash_map getOrPutAdapted" {
18881892 const AdaptedContext = struct {
18891893 fn eql(self: @This(), adapted_key: []const u8, test_key: u64) bool {
1894 _ = self;
18901895 return std.fmt.parseInt(u64, adapted_key, 10) catch unreachable == test_key;
18911896 }
18921897 fn hash(self: @This(), adapted_key: []const u8) u64 {
1898 _ = self;
18931899 const key = std.fmt.parseInt(u64, adapted_key, 10) catch unreachable;
18941900 return (AutoContext(u64){}).hash(key);
18951901 }
lib/std/heap.zig+30
......@@ -108,6 +108,8 @@ const CAllocator = struct {
108108 len_align: u29,
109109 return_address: usize,
110110 ) error{OutOfMemory}![]u8 {
111 _ = allocator;
112 _ = return_address;
111113 assert(len > 0);
112114 assert(std.math.isPowerOfTwo(alignment));
113115
......@@ -134,6 +136,9 @@ const CAllocator = struct {
134136 len_align: u29,
135137 return_address: usize,
136138 ) Allocator.Error!usize {
139 _ = allocator;
140 _ = buf_align;
141 _ = return_address;
137142 if (new_len == 0) {
138143 alignedFree(buf.ptr);
139144 return 0;
......@@ -178,6 +183,9 @@ fn rawCAlloc(
178183 len_align: u29,
179184 ret_addr: usize,
180185) Allocator.Error![]u8 {
186 _ = self;
187 _ = len_align;
188 _ = ret_addr;
181189 assert(ptr_align <= @alignOf(std.c.max_align_t));
182190 const ptr = @ptrCast([*]u8, c.malloc(len) orelse return error.OutOfMemory);
183191 return ptr[0..len];
......@@ -191,6 +199,9 @@ fn rawCResize(
191199 len_align: u29,
192200 ret_addr: usize,
193201) Allocator.Error!usize {
202 _ = self;
203 _ = old_align;
204 _ = ret_addr;
194205 if (new_len == 0) {
195206 c.free(buf.ptr);
196207 return 0;
......@@ -231,6 +242,8 @@ pub var next_mmap_addr_hint: ?[*]align(mem.page_size) u8 = null;
231242
232243const PageAllocator = struct {
233244 fn alloc(allocator: *Allocator, n: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 {
245 _ = allocator;
246 _ = ra;
234247 assert(n > 0);
235248 const aligned_len = mem.alignForward(n, mem.page_size);
236249
......@@ -334,6 +347,9 @@ const PageAllocator = struct {
334347 len_align: u29,
335348 return_address: usize,
336349 ) Allocator.Error!usize {
350 _ = allocator;
351 _ = buf_align;
352 _ = return_address;
337353 const new_size_aligned = mem.alignForward(new_size, mem.page_size);
338354
339355 if (builtin.os.tag == .windows) {
......@@ -482,6 +498,8 @@ const WasmPageAllocator = struct {
482498 }
483499
484500 fn alloc(allocator: *Allocator, len: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 {
501 _ = allocator;
502 _ = ra;
485503 const page_count = nPages(len);
486504 const page_idx = try allocPages(page_count, alignment);
487505 return @intToPtr([*]u8, page_idx * mem.page_size)[0..alignPageAllocLen(page_count * mem.page_size, len, len_align)];
......@@ -542,6 +560,9 @@ const WasmPageAllocator = struct {
542560 len_align: u29,
543561 return_address: usize,
544562 ) error{OutOfMemory}!usize {
563 _ = allocator;
564 _ = buf_align;
565 _ = return_address;
545566 const aligned_len = mem.alignForward(buf.len, mem.page_size);
546567 if (new_len > aligned_len) return error.OutOfMemory;
547568 const current_n = nPages(aligned_len);
......@@ -588,6 +609,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
588609 len_align: u29,
589610 return_address: usize,
590611 ) error{OutOfMemory}![]u8 {
612 _ = return_address;
591613 const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);
592614
593615 const amt = n + ptr_align - 1 + @sizeOf(usize);
......@@ -622,6 +644,8 @@ pub const HeapAllocator = switch (builtin.os.tag) {
622644 len_align: u29,
623645 return_address: usize,
624646 ) error{OutOfMemory}!usize {
647 _ = buf_align;
648 _ = return_address;
625649 const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);
626650 if (new_size == 0) {
627651 os.windows.HeapFree(self.heap_handle.?, 0, @intToPtr(*c_void, getRecordPtr(buf).*));
......@@ -694,6 +718,8 @@ pub const FixedBufferAllocator = struct {
694718 }
695719
696720 fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 {
721 _ = len_align;
722 _ = ra;
697723 const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);
698724 const adjust_off = mem.alignPointerOffset(self.buffer.ptr + self.end_index, ptr_align) orelse
699725 return error.OutOfMemory;
......@@ -716,6 +742,8 @@ pub const FixedBufferAllocator = struct {
716742 len_align: u29,
717743 return_address: usize,
718744 ) Allocator.Error!usize {
745 _ = buf_align;
746 _ = return_address;
719747 const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator);
720748 assert(self.ownsSlice(buf)); // sanity check
721749
......@@ -766,6 +794,8 @@ pub const ThreadSafeFixedBufferAllocator = blk: {
766794 }
767795
768796 fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 {
797 _ = len_align;
798 _ = ra;
769799 const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator);
770800 var end_index = @atomicLoad(usize, &self.end_index, builtin.AtomicOrder.SeqCst);
771801 while (true) {
lib/std/heap/arena_allocator.zig+5
......@@ -66,6 +66,8 @@ pub const ArenaAllocator = struct {
6666 }
6767
6868 fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 {
69 _ = len_align;
70 _ = ra;
6971 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);
7072
7173 var cur_node = if (self.state.buffer_list.first) |first_node| first_node else try self.createNode(0, n + ptr_align);
......@@ -95,6 +97,9 @@ pub const ArenaAllocator = struct {
9597 }
9698
9799 fn resize(allocator: *Allocator, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) Allocator.Error!usize {
100 _ = buf_align;
101 _ = len_align;
102 _ = ret_addr;
98103 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);
99104
100105 const cur_node = self.state.buffer_list.first orelse return error.OutOfMemory;
lib/std/heap/log_to_writer_allocator.zig+2-2
......@@ -37,9 +37,9 @@ pub fn LogToWriterAllocator(comptime Writer: type) type {
3737 const self = @fieldParentPtr(Self, "allocator", allocator);
3838 self.writer.print("alloc : {}", .{len}) catch {};
3939 const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra);
40 if (result) |buff| {
40 if (result) |_| {
4141 self.writer.print(" success!\n", .{}) catch {};
42 } else |err| {
42 } else |_| {
4343 self.writer.print(" failure!\n", .{}) catch {};
4444 }
4545 return result;
lib/std/heap/logging_allocator.zig+1-1
......@@ -65,7 +65,7 @@ pub fn ScopedLoggingAllocator(
6565 ) error{OutOfMemory}![]u8 {
6666 const self = @fieldParentPtr(Self, "allocator", allocator);
6767 const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra);
68 if (result) |buff| {
68 if (result) |_| {
6969 logHelper(
7070 success_log_level,
7171 "alloc - success - len: {}, ptr_align: {}, len_align: {}",
lib/std/io.zig+1
......@@ -161,6 +161,7 @@ pub const null_writer = @as(NullWriter, .{ .context = {} });
161161
162162const NullWriter = Writer(void, error{}, dummyWrite);
163163fn dummyWrite(context: void, data: []const u8) error{}!usize {
164 _ = context;
164165 return data.len;
165166}
166167
lib/std/io/bit_reader.zig+1-1
......@@ -149,7 +149,7 @@ pub fn BitReader(endian: builtin.Endian, comptime ReaderType: type) type {
149149 var out_bits_total = @as(usize, 0);
150150 //@NOTE: I'm not sure this is a good idea, maybe alignToByte should be forced
151151 if (self.bit_count > 0) {
152 for (buffer) |*b, i| {
152 for (buffer) |*b| {
153153 b.* = try self.readBits(u8, u8_bit_count, &out_bits);
154154 out_bits_total += out_bits;
155155 }
lib/std/io/bit_writer.zig+1-1
......@@ -128,7 +128,7 @@ pub fn BitWriter(endian: builtin.Endian, comptime WriterType: type) type {
128128 pub fn write(self: *Self, buffer: []const u8) Error!usize {
129129 // TODO: I'm not sure this is a good idea, maybe flushBits should be forced
130130 if (self.bit_count > 0) {
131 for (buffer) |b, i|
131 for (buffer) |b|
132132 try self.writeBits(b, u8_bit_count);
133133 return buffer.len;
134134 }
lib/std/json.zig+8-6
......@@ -1221,11 +1221,11 @@ test "json.token premature object close" {
12211221pub fn validate(s: []const u8) bool {
12221222 var p = StreamingParser.init();
12231223
1224 for (s) |c, i| {
1224 for (s) |c| {
12251225 var token1: ?Token = undefined;
12261226 var token2: ?Token = undefined;
12271227
1228 p.feed(c, &token1, &token2) catch |err| {
1228 p.feed(c, &token1, &token2) catch {
12291229 return false;
12301230 };
12311231 }
......@@ -1410,7 +1410,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool {
14101410 if (a == null or b == null) return false;
14111411 return parsedEqual(a.?, b.?);
14121412 },
1413 .Union => |unionInfo| {
1413 .Union => {
14141414 if (info.tag_type) |UnionTag| {
14151415 const tag_a = std.meta.activeTag(a);
14161416 const tag_b = std.meta.activeTag(b);
......@@ -1771,7 +1771,7 @@ fn parseInternal(comptime T: type, token: Token, tokens: *TokenStream, options:
17711771 const source_slice = stringToken.slice(tokens.slice, tokens.i - 1);
17721772 switch (stringToken.escapes) {
17731773 .None => return allocator.dupe(u8, source_slice),
1774 .Some => |some_escapes| {
1774 .Some => {
17751775 const output = try allocator.alloc(u8, stringToken.decodedLength());
17761776 errdefer allocator.free(output);
17771777 try unescapeValidString(output, source_slice);
......@@ -2391,7 +2391,7 @@ pub const Parser = struct {
23912391 const slice = s.slice(input, i);
23922392 switch (s.escapes) {
23932393 .None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice },
2394 .Some => |some_escapes| {
2394 .Some => {
23952395 const output = try allocator.alloc(u8, s.decodedLength());
23962396 errdefer allocator.free(output);
23972397 try unescapeValidString(output, slice);
......@@ -2401,6 +2401,7 @@ pub const Parser = struct {
24012401 }
24022402
24032403 fn parseNumber(p: *Parser, n: std.meta.TagPayload(Token, Token.Number), input: []const u8, i: usize) !Value {
2404 _ = p;
24042405 return if (n.is_integer)
24052406 Value{
24062407 .Integer = std.fmt.parseInt(i64, n.slice(input, i), 10) catch |e| switch (e) {
......@@ -2815,7 +2816,7 @@ pub fn stringify(
28152816 if (child_options.whitespace) |*child_whitespace| {
28162817 child_whitespace.indent_level += 1;
28172818 }
2818 inline for (S.fields) |Field, field_i| {
2819 inline for (S.fields) |Field| {
28192820 // don't include void fields
28202821 if (Field.field_type == void) continue;
28212822
......@@ -3114,6 +3115,7 @@ test "stringify struct with custom stringifier" {
31143115 options: StringifyOptions,
31153116 out_stream: anytype,
31163117 ) !void {
3118 _ = value;
31173119 try out_stream.writeAll("[\"something special\",");
31183120 try stringify(42, options, out_stream);
31193121 try out_stream.writeByte(']');
lib/std/leb128.zig+2-3
......@@ -198,7 +198,7 @@ fn test_read_ileb128_seq(comptime T: type, comptime N: usize, encoded: []const u
198198 var reader = std.io.fixedBufferStream(encoded);
199199 var i: usize = 0;
200200 while (i < N) : (i += 1) {
201 const v1 = try readILEB128(T, reader.reader());
201 _ = try readILEB128(T, reader.reader());
202202 }
203203}
204204
......@@ -206,7 +206,7 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u
206206 var reader = std.io.fixedBufferStream(encoded);
207207 var i: usize = 0;
208208 while (i < N) : (i += 1) {
209 const v1 = try readULEB128(T, reader.reader());
209 _ = try readULEB128(T, reader.reader());
210210 }
211211}
212212
......@@ -309,7 +309,6 @@ fn test_write_leb128(value: anytype) !void {
309309 const B = std.meta.Int(signedness, larger_type_bits);
310310
311311 const bytes_needed = bn: {
312 const S = std.meta.Int(signedness, @sizeOf(T) * 8);
313312 if (@typeInfo(T).Int.bits <= 7) break :bn @as(u16, 1);
314313
315314 const unused_bits = if (value < 0) @clz(T, ~value) else @clz(T, value);
lib/std/linked_list.zig+2-2
......@@ -359,8 +359,8 @@ test "basic TailQueue test" {
359359 }
360360 }
361361
362 var first = list.popFirst(); // {2, 3, 4, 5}
363 var last = list.pop(); // {2, 3, 4}
362 _ = list.popFirst(); // {2, 3, 4, 5}
363 _ = list.pop(); // {2, 3, 4}
364364 list.remove(&three); // {2, 4}
365365
366366 try testing.expect(list.first.?.data == 2);
lib/std/math/big/int.zig+4-2
......@@ -458,6 +458,7 @@ pub const Mutable = struct {
458458 /// If `allocator` is provided, it will be used for temporary storage to improve
459459 /// multiplication performance. `error.OutOfMemory` is handled with a fallback algorithm.
460460 pub fn sqrNoAlias(rma: *Mutable, a: Const, opt_allocator: ?*Allocator) void {
461 _ = opt_allocator;
461462 assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing
462463
463464 mem.set(Limb, rma.limbs, 0);
......@@ -676,6 +677,7 @@ pub const Mutable = struct {
676677 ///
677678 /// `limbs_buffer` is used for temporary storage during the operation.
678679 pub fn gcdNoAlias(rma: *Mutable, x: Const, y: Const, limbs_buffer: *std.ArrayList(Limb)) !void {
680 _ = limbs_buffer;
679681 assert(rma.limbs.ptr != x.limbs.ptr); // illegal aliasing
680682 assert(rma.limbs.ptr != y.limbs.ptr); // illegal aliasing
681683 return gcdLehmer(rma, x, y, allocator);
......@@ -1141,6 +1143,7 @@ pub const Const = struct {
11411143 options: std.fmt.FormatOptions,
11421144 out_stream: anytype,
11431145 ) !void {
1146 _ = options;
11441147 comptime var radix = 10;
11451148 comptime var case: std.fmt.Case = .lower;
11461149
......@@ -1618,6 +1621,7 @@ pub const Managed = struct {
16181621 /// Converts self to a string in the requested base. Memory is allocated from the provided
16191622 /// allocator and not the one present in self.
16201623 pub fn toString(self: Managed, allocator: *Allocator, base: u8, case: std.fmt.Case) ![]u8 {
1624 _ = allocator;
16211625 if (base < 2 or base > 16) return error.InvalidBase;
16221626 return self.toConst().toStringAlloc(self.allocator, base, case);
16231627 }
......@@ -2000,8 +2004,6 @@ fn llmulacc_karatsuba(allocator: *Allocator, r: []Limb, x: []const Limb, y: []co
20002004 } else {
20012005 llsub(j1, y0[0..y0_len], y1[0..y1_len]);
20022006 }
2003 const j0_len = llnormalize(j0);
2004 const j1_len = llnormalize(j1);
20052007 if (x_cmp == y_cmp) {
20062008 mem.set(Limb, tmp[0..length], 0);
20072009 llmulacc(allocator, tmp, j0, j1);
lib/std/math/big/rational.zig-1
......@@ -204,7 +204,6 @@ pub const Rational = struct {
204204 const esize = math.floatExponentBits(T);
205205 const ebias = (1 << (esize - 1)) - 1;
206206 const emin = 1 - ebias;
207 const emax = ebias;
208207
209208 if (self.p.eqZero()) {
210209 return 0;
lib/std/math/complex/ldexp.zig+1-1
......@@ -12,8 +12,8 @@
1212const std = @import("../../std.zig");
1313const debug = std.debug;
1414const math = std.math;
15const cmath = math.complex;
1615const testing = std.testing;
16const cmath = math.complex;
1717const Complex = cmath.Complex;
1818
1919/// Returns exp(z) scaled to avoid overflow.
lib/std/math/expm1.zig-4
......@@ -316,16 +316,12 @@ test "math.expm1_64" {
316316}
317317
318318test "math.expm1_32.special" {
319 const epsilon = 0.000001;
320
321319 try expect(math.isPositiveInf(expm1_32(math.inf(f32))));
322320 try expect(expm1_32(-math.inf(f32)) == -1.0);
323321 try expect(math.isNan(expm1_32(math.nan(f32))));
324322}
325323
326324test "math.expm1_64.special" {
327 const epsilon = 0.000001;
328
329325 try expect(math.isPositiveInf(expm1_64(math.inf(f64))));
330326 try expect(expm1_64(-math.inf(f64)) == -1.0);
331327 try expect(math.isNan(expm1_64(math.nan(f64))));
lib/std/math/modf.zig+2-5
......@@ -12,6 +12,7 @@
1212const std = @import("../std.zig");
1313const math = std.math;
1414const expect = std.testing.expect;
15const expectEqual = std.testing.expectEqual;
1516const maxInt = std.math.maxInt;
1617
1718fn modf_result(comptime T: type) type {
......@@ -131,11 +132,7 @@ test "math.modf" {
131132 const a = modf(@as(f32, 1.0));
132133 const b = modf32(1.0);
133134 // NOTE: No struct comparison on generic return type function? non-named, makes sense, but still.
134 try expect(a.ipart == b.ipart and a.fpart == b.fpart);
135
136 const c = modf(@as(f64, 1.0));
137 const d = modf64(1.0);
138 try expect(a.ipart == b.ipart and a.fpart == b.fpart);
135 try expectEqual(a, b);
139136}
140137
141138test "math.modf32" {
lib/std/mem.zig+5
......@@ -139,6 +139,11 @@ var failAllocator = Allocator{
139139 .resizeFn = Allocator.noResize,
140140};
141141fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29, ra: usize) Allocator.Error![]u8 {
142 _ = self;
143 _ = n;
144 _ = alignment;
145 _ = len_align;
146 _ = ra;
142147 return error.OutOfMemory;
143148}
144149
lib/std/mem/Allocator.zig+4
......@@ -55,6 +55,10 @@ pub fn noResize(
5555 len_align: u29,
5656 ret_addr: usize,
5757) Error!usize {
58 _ = self;
59 _ = buf_align;
60 _ = len_align;
61 _ = ret_addr;
5862 if (new_len > buf.len)
5963 return error.OutOfMemory;
6064 return new_len;
lib/std/meta.zig+1-7
......@@ -654,7 +654,6 @@ pub fn TagPayload(comptime U: type, tag: Tag(U)) type {
654654 try testing.expect(trait.is(.Union)(U));
655655
656656 const info = @typeInfo(U).Union;
657 const tag_info = @typeInfo(Tag(U)).Enum;
658657
659658 inline for (info.fields) |field_info| {
660659 if (comptime mem.eql(u8, field_info.name, @tagName(tag)))
......@@ -757,12 +756,6 @@ test "std.meta.eql" {
757756 .c = "12345".*,
758757 };
759758
760 const s_2 = S{
761 .a = 1,
762 .b = 123.3,
763 .c = "54321".*,
764 };
765
766759 var s_3 = S{
767760 .a = 134,
768761 .b = 123.3,
......@@ -850,6 +843,7 @@ pub const refAllDecls = @compileError("refAllDecls has been moved from std.meta
850843pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const Decl {
851844 const S = struct {
852845 fn declNameLessThan(context: void, lhs: *const Decl, rhs: *const Decl) bool {
846 _ = context;
853847 return mem.lessThan(u8, lhs.name, rhs.name);
854848 }
855849 };
lib/std/meta/trailer_flags.zig+3-3
......@@ -96,18 +96,18 @@ pub fn TrailerFlags(comptime Fields: type) type {
9696 pub fn ptr(self: Self, p: [*]align(@alignOf(Fields)) u8, comptime field: FieldEnum) *Field(field) {
9797 if (@sizeOf(Field(field)) == 0)
9898 return undefined;
99 const off = self.offset(p, field);
99 const off = self.offset(field);
100100 return @ptrCast(*Field(field), @alignCast(@alignOf(Field(field)), p + off));
101101 }
102102
103103 pub fn ptrConst(self: Self, p: [*]align(@alignOf(Fields)) const u8, comptime field: FieldEnum) *const Field(field) {
104104 if (@sizeOf(Field(field)) == 0)
105105 return undefined;
106 const off = self.offset(p, field);
106 const off = self.offset(field);
107107 return @ptrCast(*const Field(field), @alignCast(@alignOf(Field(field)), p + off));
108108 }
109109
110 pub fn offset(self: Self, p: [*]align(@alignOf(Fields)) const u8, comptime field: FieldEnum) usize {
110 pub fn offset(self: Self, comptime field: FieldEnum) usize {
111111 var off: usize = 0;
112112 inline for (@typeInfo(Fields).Struct.fields) |field_info, i| {
113113 const active = (self.bits & (1 << i)) != 0;
lib/std/multi_array_list.zig+3-2
......@@ -92,6 +92,7 @@ pub fn MultiArrayList(comptime S: type) type {
9292 }
9393 const Sort = struct {
9494 fn lessThan(trash: *i32, lhs: Data, rhs: Data) bool {
95 _ = trash;
9596 return lhs.alignment > rhs.alignment;
9697 }
9798 };
......@@ -221,7 +222,7 @@ pub fn MultiArrayList(comptime S: type) type {
221222 /// retain list ordering.
222223 pub fn swapRemove(self: *Self, index: usize) void {
223224 const slices = self.slice();
224 inline for (fields) |field_info, i| {
225 inline for (fields) |_, i| {
225226 const field_slice = slices.items(@intToEnum(Field, i));
226227 field_slice[index] = field_slice[self.len - 1];
227228 field_slice[self.len - 1] = undefined;
......@@ -233,7 +234,7 @@ pub fn MultiArrayList(comptime S: type) type {
233234 /// after it to preserve order.
234235 pub fn orderedRemove(self: *Self, index: usize) void {
235236 const slices = self.slice();
236 inline for (fields) |field_info, field_index| {
237 inline for (fields) |_, field_index| {
237238 const field_slice = slices.items(@intToEnum(Field, field_index));
238239 var i = index;
239240 while (i < self.len - 1) : (i += 1) {
lib/std/net.zig+7
......@@ -270,6 +270,8 @@ pub const Ip4Address = extern struct {
270270 options: std.fmt.FormatOptions,
271271 out_stream: anytype,
272272 ) !void {
273 _ = fmt;
274 _ = options;
273275 const bytes = @ptrCast(*const [4]u8, &self.sa.addr);
274276 try std.fmt.format(out_stream, "{}.{}.{}.{}:{}", .{
275277 bytes[0],
......@@ -281,6 +283,7 @@ pub const Ip4Address = extern struct {
281283 }
282284
283285 pub fn getOsSockLen(self: Ip4Address) os.socklen_t {
286 _ = self;
284287 return @sizeOf(os.sockaddr_in);
285288 }
286289};
......@@ -556,6 +559,8 @@ pub const Ip6Address = extern struct {
556559 options: std.fmt.FormatOptions,
557560 out_stream: anytype,
558561 ) !void {
562 _ = fmt;
563 _ = options;
559564 const port = mem.bigToNative(u16, self.sa.port);
560565 if (mem.eql(u8, self.sa.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
561566 try std.fmt.format(out_stream, "[::ffff:{}.{}.{}.{}]:{}", .{
......@@ -598,6 +603,7 @@ pub const Ip6Address = extern struct {
598603 }
599604
600605 pub fn getOsSockLen(self: Ip6Address) os.socklen_t {
606 _ = self;
601607 return @sizeOf(os.sockaddr_in6);
602608 }
603609};
......@@ -1062,6 +1068,7 @@ fn IN6_IS_ADDR_SITELOCAL(a: [16]u8) bool {
10621068
10631069// Parameters `b` and `a` swapped to make this descending.
10641070fn addrCmpLessThan(context: void, b: LookupAddr, a: LookupAddr) bool {
1071 _ = context;
10651072 return a.sortkey < b.sortkey;
10661073}
10671074
lib/std/once.zig+1
......@@ -61,6 +61,7 @@ test "Once executes its function just once" {
6161 for (threads) |*handle| {
6262 handle.* = try std.Thread.spawn(struct {
6363 fn thread_fn(x: u8) void {
64 _ = x;
6465 global_once.call();
6566 }
6667 }.thread_fn, 0);
lib/std/os.zig+13-3
......@@ -1164,6 +1164,7 @@ fn openOptionsFromFlags(flags: u32) windows.OpenFileOptions {
11641164/// TODO currently, this function does not handle all flag combinations
11651165/// or makes use of perm argument.
11661166pub fn openW(file_path_w: []const u16, flags: u32, perm: mode_t) OpenError!fd_t {
1167 _ = perm;
11671168 var options = openOptionsFromFlags(flags);
11681169 options.dir = std.fs.cwd().fd;
11691170 return windows.OpenFile(file_path_w, options) catch |err| switch (err) {
......@@ -1273,6 +1274,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)
12731274/// TODO currently, this function does not handle all flag combinations
12741275/// or makes use of perm argument.
12751276pub fn openatW(dir_fd: fd_t, file_path_w: []const u16, flags: u32, mode: mode_t) OpenError!fd_t {
1277 _ = mode;
12761278 var options = openOptionsFromFlags(flags);
12771279 options.dir = dir_fd;
12781280 return windows.OpenFile(file_path_w, options) catch |err| switch (err) {
......@@ -2169,6 +2171,7 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!v
21692171pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
21702172
21712173pub fn mkdiratWasi(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!void {
2174 _ = mode;
21722175 switch (wasi.path_create_directory(dir_fd, sub_dir_path.ptr, sub_dir_path.len)) {
21732176 wasi.ESUCCESS => return,
21742177 wasi.EACCES => return error.AccessDenied,
......@@ -2216,6 +2219,7 @@ pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirErr
22162219}
22172220
22182221pub fn mkdiratW(dir_fd: fd_t, sub_path_w: []const u16, mode: u32) MakeDirError!void {
2222 _ = mode;
22192223 const sub_dir_handle = windows.OpenFile(sub_path_w, .{
22202224 .dir = dir_fd,
22212225 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,
......@@ -2291,6 +2295,7 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
22912295
22922296/// Windows-only. Same as `mkdir` but the parameters is WTF16 encoded.
22932297pub fn mkdirW(dir_path_w: []const u16, mode: u32) MakeDirError!void {
2298 _ = mode;
22942299 const sub_dir_handle = windows.OpenFile(dir_path_w, .{
22952300 .dir = std.fs.cwd().fd,
22962301 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,
......@@ -3868,6 +3873,7 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
38683873/// Otherwise use `access` or `accessC`.
38693874/// TODO currently this ignores `mode`.
38703875pub fn accessW(path: [*:0]const u16, mode: u32) windows.GetFileAttributesError!void {
3876 _ = mode;
38713877 const ret = try windows.GetFileAttributesW(path);
38723878 if (ret != windows.INVALID_FILE_ATTRIBUTES) {
38733879 return;
......@@ -3918,6 +3924,8 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces
39183924/// is NtDll-prefixed, null-terminated, WTF-16 encoded.
39193925/// TODO currently this ignores `mode` and `flags`
39203926pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32) AccessError!void {
3927 _ = mode;
3928 _ = flags;
39213929 if (sub_path_w[0] == '.' and sub_path_w[1] == 0) {
39223930 return;
39233931 }
......@@ -4895,6 +4903,8 @@ pub fn res_mkquery(
48954903 newrr: ?[*]const u8,
48964904 buf: []u8,
48974905) usize {
4906 _ = data;
4907 _ = newrr;
48984908 // This implementation is ported from musl libc.
48994909 // A more idiomatic "ziggy" implementation would be welcome.
49004910 var name = dname;
......@@ -5341,7 +5351,7 @@ pub fn sendfile(
53415351 ENXIO => return error.Unseekable,
53425352 ESPIPE => return error.Unseekable,
53435353 else => |err| {
5344 const discard = unexpectedErrno(err);
5354 unexpectedErrno(err) catch {};
53455355 break :sf;
53465356 },
53475357 }
......@@ -5422,7 +5432,7 @@ pub fn sendfile(
54225432 EPIPE => return error.BrokenPipe,
54235433
54245434 else => {
5425 const discard = unexpectedErrno(err);
5435 unexpectedErrno(err) catch {};
54265436 if (amt != 0) {
54275437 return amt;
54285438 } else {
......@@ -5484,7 +5494,7 @@ pub fn sendfile(
54845494 EPIPE => return error.BrokenPipe,
54855495
54865496 else => {
5487 const discard = unexpectedErrno(err);
5497 unexpectedErrno(err) catch {};
54885498 if (amt != 0) {
54895499 return amt;
54905500 } else {
lib/std/os/bits/linux.zig+1-1
......@@ -1286,7 +1286,7 @@ pub const CAP_BLOCK_SUSPEND = 36;
12861286pub const CAP_AUDIT_READ = 37;
12871287pub const CAP_LAST_CAP = CAP_AUDIT_READ;
12881288
1289pub fn cap_valid(u8: x) bool {
1289pub fn cap_valid(x: u8) bool {
12901290 return x >= 0 and x <= CAP_LAST_CAP;
12911291}
12921292
lib/std/os/linux.zig+2-1
......@@ -70,6 +70,7 @@ fn splitValueLE64(val: i64) [2]u32 {
7070 };
7171}
7272fn splitValueBE64(val: i64) [2]u32 {
73 const u = @bitCast(u64, val);
7374 return [2]u32{
7475 @truncate(u32, u >> 32),
7576 @truncate(u32, u),
......@@ -1022,7 +1023,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
10221023 for (msgvec[0..kvlen]) |*msg, i| {
10231024 var size: i32 = 0;
10241025 const msg_iovlen = @intCast(usize, msg.msg_hdr.msg_iovlen); // kernel side this is treated as unsigned
1025 for (msg.msg_hdr.msg_iov[0..msg_iovlen]) |iov, j| {
1026 for (msg.msg_hdr.msg_iov[0..msg_iovlen]) |iov| {
10261027 if (iov.iov_len > std.math.maxInt(i32) or @addWithOverflow(i32, size, @intCast(i32, iov.iov_len), &size)) {
10271028 // batch-send all messages up to the current message
10281029 if (next_unsent < i) {
lib/std/os/linux/bpf.zig+2-2
......@@ -1513,7 +1513,7 @@ pub fn map_create(map_type: MapType, key_size: u32, value_size: u32, max_entries
15131513 EINVAL => error.MapTypeOrAttrInvalid,
15141514 ENOMEM => error.SystemResources,
15151515 EPERM => error.AccessDenied,
1516 else => |err| unexpectedErrno(rc),
1516 else => |err| unexpectedErrno(err),
15171517 };
15181518}
15191519
......@@ -1539,7 +1539,7 @@ pub fn map_lookup_elem(fd: fd_t, key: []const u8, value: []u8) !void {
15391539 EINVAL => return error.FieldInAttrNeedsZeroing,
15401540 ENOENT => return error.NotFound,
15411541 EPERM => return error.AccessDenied,
1542 else => |err| return unexpectedErrno(rc),
1542 else => |err| return unexpectedErrno(err),
15431543 }
15441544}
15451545
lib/std/os/linux/io_uring.zig+6-3
......@@ -284,6 +284,7 @@ pub const IO_Uring = struct {
284284 }
285285
286286 fn copy_cqes_ready(self: *IO_Uring, cqes: []io_uring_cqe, wait_nr: u32) u32 {
287 _ = wait_nr;
287288 const ready = self.cq_ready();
288289 const count = std.math.min(cqes.len, ready);
289290 var head = self.cq.head.*;
......@@ -320,6 +321,7 @@ pub const IO_Uring = struct {
320321 /// Not idempotent, calling more than once will result in other CQEs being lost.
321322 /// Matches the implementation of cqe_seen() in liburing.
322323 pub fn cqe_seen(self: *IO_Uring, cqe: *io_uring_cqe) void {
324 _ = cqe;
323325 self.cq_advance(1);
324326 }
325327
......@@ -728,6 +730,7 @@ pub const CompletionQueue = struct {
728730 }
729731
730732 pub fn deinit(self: *CompletionQueue) void {
733 _ = self;
731734 // A no-op since we now share the mmap with the submission queue.
732735 // Here for symmetry with the submission queue, and for any future feature support.
733736 }
......@@ -1272,12 +1275,12 @@ test "accept/connect/send/recv" {
12721275
12731276 var accept_addr: os.sockaddr = undefined;
12741277 var accept_addr_len: os.socklen_t = @sizeOf(@TypeOf(accept_addr));
1275 const accept = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0);
1278 _ = try ring.accept(0xaaaaaaaa, server, &accept_addr, &accept_addr_len, 0);
12761279 try testing.expectEqual(@as(u32, 1), try ring.submit());
12771280
12781281 const client = try os.socket(address.any.family, os.SOCK_STREAM | os.SOCK_CLOEXEC, 0);
12791282 defer os.close(client);
1280 const connect = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen());
1283 _ = try ring.connect(0xcccccccc, client, &address.any, address.getOsSockLen());
12811284 try testing.expectEqual(@as(u32, 1), try ring.submit());
12821285
12831286 var cqe_accept = try ring.copy_cqe();
......@@ -1305,7 +1308,7 @@ test "accept/connect/send/recv" {
13051308
13061309 const send = try ring.send(0xeeeeeeee, client, buffer_send[0..], 0);
13071310 send.flags |= linux.IOSQE_IO_LINK;
1308 const recv = try ring.recv(0xffffffff, cqe_accept.res, buffer_recv[0..], 0);
1311 _ = try ring.recv(0xffffffff, cqe_accept.res, buffer_recv[0..], 0);
13091312 try testing.expectEqual(@as(u32, 2), try ring.submit());
13101313
13111314 const cqe_send = try ring.copy_cqe();
lib/std/os/linux/mips.zig+2-1
......@@ -31,7 +31,8 @@ pub fn syscall_pipe(fd: *[2]i32) usize {
3131 \\ sw $3, 4($4)
3232 \\ 2:
3333 : [ret] "={$2}" (-> usize)
34 : [number] "{$2}" (@enumToInt(SYS.pipe))
34 : [number] "{$2}" (@enumToInt(SYS.pipe)),
35 [fd] "{$4}" (fd)
3536 : "memory", "cc", "$7"
3637 );
3738}
lib/std/os/linux/vdso.zig-1
......@@ -15,7 +15,6 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
1515
1616 const eh = @intToPtr(*elf.Ehdr, vdso_addr);
1717 var ph_addr: usize = vdso_addr + eh.e_phoff;
18 const ph = @intToPtr(*elf.Phdr, ph_addr);
1918
2019 var maybe_dynv: ?[*]usize = null;
2120 var base: usize = maxInt(usize);
lib/std/os/test.zig+4
......@@ -353,6 +353,7 @@ test "spawn threads" {
353353}
354354
355355fn start1(ctx: void) u8 {
356 _ = ctx;
356357 return 0;
357358}
358359
......@@ -379,6 +380,7 @@ test "thread local storage" {
379380
380381threadlocal var x: i32 = 1234;
381382fn testTls(context: void) !void {
383 _ = context;
382384 if (x != 1234) return error.TlsBadStartValue;
383385 x += 1;
384386 if (x != 1235) return error.TlsBadEndValue;
......@@ -425,6 +427,7 @@ const IterFnError = error{
425427};
426428
427429fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void {
430 _ = size;
428431 // Count how many libraries are loaded
429432 counter.* += @as(usize, 1);
430433
......@@ -731,6 +734,7 @@ test "sigaction" {
731734
732735 const S = struct {
733736 fn handler(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) void {
737 _ = ctx_ptr;
734738 // Check that we received the correct signal.
735739 switch (native_os) {
736740 .netbsd => {
lib/std/os/uefi.zig+1
......@@ -37,6 +37,7 @@ pub const Guid = extern struct {
3737 options: std.fmt.FormatOptions,
3838 writer: anytype,
3939 ) !void {
40 _ = options;
4041 if (f.len == 0) {
4142 return std.fmt.format(writer, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", .{
4243 self.time_low,
lib/std/os/uefi/protocols/managed_network_protocol.zig+1
......@@ -35,6 +35,7 @@ pub const ManagedNetworkProtocol = extern struct {
3535 /// Translates an IP multicast address to a hardware (MAC) multicast address.
3636 /// This function may be unsupported in some MNP implementations.
3737 pub fn mcastIpToMac(self: *const ManagedNetworkProtocol, ipv6flag: bool, ipaddress: *const c_void, mac_address: *MacAddress) Status {
38 _ = mac_address;
3839 return self._mcast_ip_to_mac(self, ipv6flag, ipaddress);
3940 }
4041
lib/std/os/windows.zig-1
......@@ -1156,7 +1156,6 @@ pub fn GetFinalPathNameByHandle(
11561156 &mount_points_struct.MountPoints[0],
11571157 )[0..mount_points_struct.NumberOfMountPoints];
11581158
1159 var found: bool = false;
11601159 for (mount_points) |mount_point| {
11611160 const symlink = @ptrCast(
11621161 [*]const u16,
lib/std/packed_int_array.zig+1
......@@ -194,6 +194,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: Endian, comptim
194194
195195 ///Returns the number of elements in the packed array
196196 pub fn len(self: Self) usize {
197 _ = self;
197198 return int_count;
198199 }
199200
lib/std/pdb.zig+4-1
......@@ -594,6 +594,7 @@ pub const Pdb = struct {
594594 error.InvalidValue => return error.InvalidDebugInfo,
595595 else => |e| return e,
596596 };
597 _ = version;
597598 sect_cont_offset += @sizeOf(u32);
598599 }
599600 while (sect_cont_offset != section_contrib_size) {
......@@ -617,6 +618,7 @@ pub const Pdb = struct {
617618 // Parse the InfoStreamHeader.
618619 const version = try reader.readIntLittle(u32);
619620 const signature = try reader.readIntLittle(u32);
621 _ = signature;
620622 const age = try reader.readIntLittle(u32);
621623 const guid = try reader.readBytesNoEof(16);
622624
......@@ -673,6 +675,7 @@ pub const Pdb = struct {
673675 }
674676
675677 pub fn getSymbolName(self: *Pdb, module: *Module, address: u64) ?[]const u8 {
678 _ = self;
676679 std.debug.assert(module.populated);
677680
678681 var symbol_i: usize = 0;
......@@ -904,7 +907,7 @@ const Msf = struct {
904907 // These streams are not used, but still participate in the file
905908 // and must be taken into account when resolving stream indices.
906909 const Nil = 0xFFFFFFFF;
907 for (stream_sizes) |*s, i| {
910 for (stream_sizes) |*s| {
908911 const size = try directory.reader().readIntLittle(u32);
909912 s.* = if (size == Nil) 0 else blockCountFromSize(size, superblock.BlockSize);
910913 }
lib/std/priority_dequeue.zig+1-1
......@@ -428,7 +428,7 @@ pub fn PriorityDequeue(comptime T: type) type {
428428 warn("{}, ", .{e});
429429 }
430430 warn("array: ", .{});
431 for (self.items) |e, i| {
431 for (self.items) |e| {
432432 warn("{}, ", .{e});
433433 }
434434 warn("len: {} ", .{self.len});
lib/std/priority_queue.zig+1-1
......@@ -249,7 +249,7 @@ pub fn PriorityQueue(comptime T: type) type {
249249 warn("{}, ", .{e});
250250 }
251251 warn("array: ", .{});
252 for (self.items) |e, i| {
252 for (self.items) |e| {
253253 warn("{}, ", .{e});
254254 }
255255 warn("len: {} ", .{self.len});
lib/std/process.zig+2
......@@ -419,6 +419,7 @@ pub const ArgIteratorWindows = struct {
419419 };
420420 }
421421 fn emitBackslashes(self: *ArgIteratorWindows, buf: *std.ArrayList(u16), emit_count: usize) !void {
422 _ = self;
422423 var i: usize = 0;
423424 while (i < emit_count) : (i += 1) {
424425 try buf.append(std.mem.nativeToLittle(u16, '\\'));
......@@ -748,6 +749,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
748749 }
749750 try os.dl_iterate_phdr(&paths, error{OutOfMemory}, struct {
750751 fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void {
752 _ = size;
751753 const name = info.dlpi_name orelse return;
752754 if (name[0] == '/') {
753755 const item = try list.allocator.dupeZ(u8, mem.spanZ(name));
lib/std/rand/ziggurat.zig+1-1
......@@ -175,5 +175,5 @@ test "exp dist sanity" {
175175test "table gen" {
176176 if (please_windows_dont_oom) return error.SkipZigTest;
177177
178 const table = NormDist;
178 _ = NormDist;
179179}
lib/std/sort.zig+4
......@@ -37,9 +37,11 @@ pub fn binarySearch(
3737test "binarySearch" {
3838 const S = struct {
3939 fn order_u32(context: void, lhs: u32, rhs: u32) math.Order {
40 _ = context;
4041 return math.order(lhs, rhs);
4142 }
4243 fn order_i32(context: void, lhs: i32, rhs: i32) math.Order {
44 _ = context;
4345 return math.order(lhs, rhs);
4446 }
4547 };
......@@ -1133,6 +1135,7 @@ fn swap(
11331135pub fn asc(comptime T: type) fn (void, T, T) bool {
11341136 const impl = struct {
11351137 fn inner(context: void, a: T, b: T) bool {
1138 _ = context;
11361139 return a < b;
11371140 }
11381141 };
......@@ -1144,6 +1147,7 @@ pub fn asc(comptime T: type) fn (void, T, T) bool {
11441147pub fn desc(comptime T: type) fn (void, T, T) bool {
11451148 const impl = struct {
11461149 fn inner(context: void, a: T, b: T) bool {
1150 _ = context;
11471151 return a > b;
11481152 }
11491153 };
lib/std/special/c.zig+2
......@@ -160,6 +160,7 @@ fn strncmp(_l: [*:0]const u8, _r: [*:0]const u8, _n: usize) callconv(.C) c_int {
160160}
161161
162162fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
163 _ = errnum;
163164 return "TODO strerror implementation";
164165}
165166
......@@ -173,6 +174,7 @@ test "strncmp" {
173174// Avoid dragging in the runtime safety mechanisms into this .o file,
174175// unless we're trying to test this file.
175176pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
177 _ = error_return_trace;
176178 if (builtin.is_test) {
177179 @setCold(true);
178180 std.debug.panic("{s}", .{msg});
lib/std/special/compiler_rt.zig+1
......@@ -602,6 +602,7 @@ pub usingnamespace @import("compiler_rt/atomics.zig");
602602// Avoid dragging in the runtime safety mechanisms into this .o file,
603603// unless we're trying to test this file.
604604pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
605 _ = error_return_trace;
605606 @setCold(true);
606607 if (is_test) {
607608 std.debug.panic("{s}", .{msg});
lib/std/special/compiler_rt/addXf3.zig-5
......@@ -83,7 +83,6 @@ fn addXf3(comptime T: type, a: T, b: T) T {
8383
8484 const signBit = (@as(Z, 1) << (significandBits + exponentBits));
8585 const maxExponent = ((1 << exponentBits) - 1);
86 const exponentBias = (maxExponent >> 1);
8786
8887 const implicitBit = (@as(Z, 1) << significandBits);
8988 const quietBit = implicitBit >> 1;
......@@ -98,10 +97,6 @@ fn addXf3(comptime T: type, a: T, b: T) T {
9897 const aAbs = aRep & absMask;
9998 const bAbs = bRep & absMask;
10099
101 const negative = (aRep & signBit) != 0;
102 const exponent = @intCast(i32, aAbs >> significandBits) - exponentBias;
103 const significand = (aAbs & significandMask) | implicitBit;
104
105100 const infRep = @bitCast(Z, std.math.inf(T));
106101
107102 // Detect if a or b is zero, infinity, or NaN.
lib/std/special/compiler_rt/atomics.zig+11
......@@ -80,18 +80,21 @@ var spinlocks: SpinlockTable = SpinlockTable{};
8080// Those work on any object no matter the pointer alignment nor its size.
8181
8282fn __atomic_load(size: u32, src: [*]u8, dest: [*]u8, model: i32) callconv(.C) void {
83 _ = model;
8384 var sl = spinlocks.get(@ptrToInt(src));
8485 defer sl.release();
8586 @memcpy(dest, src, size);
8687}
8788
8889fn __atomic_store(size: u32, dest: [*]u8, src: [*]u8, model: i32) callconv(.C) void {
90 _ = model;
8991 var sl = spinlocks.get(@ptrToInt(dest));
9092 defer sl.release();
9193 @memcpy(dest, src, size);
9294}
9395
9496fn __atomic_exchange(size: u32, ptr: [*]u8, val: [*]u8, old: [*]u8, model: i32) callconv(.C) void {
97 _ = model;
9598 var sl = spinlocks.get(@ptrToInt(ptr));
9699 defer sl.release();
97100 @memcpy(old, ptr, size);
......@@ -106,6 +109,8 @@ fn __atomic_compare_exchange(
106109 success: i32,
107110 failure: i32,
108111) callconv(.C) i32 {
112 _ = success;
113 _ = failure;
109114 var sl = spinlocks.get(@ptrToInt(ptr));
110115 defer sl.release();
111116 for (ptr[0..size]) |b, i| {
......@@ -135,6 +140,7 @@ comptime {
135140fn atomicLoadFn(comptime T: type) fn (*T, i32) callconv(.C) T {
136141 return struct {
137142 fn atomic_load_N(src: *T, model: i32) callconv(.C) T {
143 _ = model;
138144 if (@sizeOf(T) > largest_atomic_size) {
139145 var sl = spinlocks.get(@ptrToInt(src));
140146 defer sl.release();
......@@ -162,6 +168,7 @@ comptime {
162168fn atomicStoreFn(comptime T: type) fn (*T, T, i32) callconv(.C) void {
163169 return struct {
164170 fn atomic_store_N(dst: *T, value: T, model: i32) callconv(.C) void {
171 _ = model;
165172 if (@sizeOf(T) > largest_atomic_size) {
166173 var sl = spinlocks.get(@ptrToInt(dst));
167174 defer sl.release();
......@@ -189,6 +196,7 @@ comptime {
189196fn atomicExchangeFn(comptime T: type) fn (*T, T, i32) callconv(.C) T {
190197 return struct {
191198 fn atomic_exchange_N(ptr: *T, val: T, model: i32) callconv(.C) T {
199 _ = model;
192200 if (@sizeOf(T) > largest_atomic_size) {
193201 var sl = spinlocks.get(@ptrToInt(ptr));
194202 defer sl.release();
......@@ -218,6 +226,8 @@ comptime {
218226fn atomicCompareExchangeFn(comptime T: type) fn (*T, *T, T, i32, i32) callconv(.C) i32 {
219227 return struct {
220228 fn atomic_compare_exchange_N(ptr: *T, expected: *T, desired: T, success: i32, failure: i32) callconv(.C) i32 {
229 _ = success;
230 _ = failure;
221231 if (@sizeOf(T) > largest_atomic_size) {
222232 var sl = spinlocks.get(@ptrToInt(ptr));
223233 defer sl.release();
......@@ -255,6 +265,7 @@ comptime {
255265fn fetchFn(comptime T: type, comptime op: builtin.AtomicRmwOp) fn (*T, T, i32) callconv(.C) T {
256266 return struct {
257267 pub fn fetch_op_N(ptr: *T, val: T, model: i32) callconv(.C) T {
268 _ = model;
258269 if (@sizeOf(T) > largest_atomic_size) {
259270 var sl = spinlocks.get(@ptrToInt(ptr));
260271 defer sl.release();
lib/std/special/compiler_rt/comparedf2_test.zig+1-1
......@@ -100,7 +100,7 @@ const test_vectors = init: {
100100};
101101
102102test "compare f64" {
103 for (test_vectors) |vector, i| {
103 for (test_vectors) |vector| {
104104 try std.testing.expect(test__cmpdf2(vector));
105105 }
106106}
lib/std/special/compiler_rt/comparesf2_test.zig+1-1
......@@ -100,7 +100,7 @@ const test_vectors = init: {
100100};
101101
102102test "compare f32" {
103 for (test_vectors) |vector, i| {
103 for (test_vectors) |vector| {
104104 try std.testing.expect(test__cmpsf2(vector));
105105 }
106106}
lib/std/special/compiler_rt/divtf3.zig-1
......@@ -12,7 +12,6 @@ const wideMultiply = @import("divdf3.zig").wideMultiply;
1212pub fn __divtf3(a: f128, b: f128) callconv(.C) f128 {
1313 @setRuntimeSafety(builtin.is_test);
1414 const Z = std.meta.Int(.unsigned, 128);
15 const SignedZ = std.meta.Int(.signed, 128);
1615
1716 const significandBits = std.math.floatMantissaBits(f128);
1817 const exponentBits = std.math.floatExponentBits(f128);
lib/std/special/compiler_rt/extendXfYf2.zig-1
......@@ -46,7 +46,6 @@ fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: std.meta.Int(.unsi
4646 const dst_rep_t = std.meta.Int(.unsigned, @typeInfo(dst_t).Float.bits);
4747 const srcSigBits = std.math.floatMantissaBits(src_t);
4848 const dstSigBits = std.math.floatMantissaBits(dst_t);
49 const SrcShift = std.math.Log2Int(src_rep_t);
5049 const DstShift = std.math.Log2Int(dst_rep_t);
5150
5251 // Various constants whose values follow from the type parameters.
lib/std/special/compiler_rt/fixuint.zig-1
......@@ -16,7 +16,6 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
1616 else => unreachable,
1717 };
1818 const typeWidth = @typeInfo(rep_t).Int.bits;
19 const srep_t = @import("std").meta.Int(.signed, typeWidth);
2019 const significandBits = switch (fp_t) {
2120 f32 => 23,
2221 f64 => 52,
lib/std/special/compiler_rt/truncXfYf2.zig-1
......@@ -50,7 +50,6 @@ fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
5050 const srcSigBits = std.math.floatMantissaBits(src_t);
5151 const dstSigBits = std.math.floatMantissaBits(dst_t);
5252 const SrcShift = std.math.Log2Int(src_rep_t);
53 const DstShift = std.math.Log2Int(dst_rep_t);
5453
5554 // Various constants whose values follow from the type parameters.
5655 // Any reasonable optimizer will fold and propagate all of these.
lib/std/special/ssp.zig+2
......@@ -27,6 +27,8 @@ extern fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8
2727
2828// Avoid dragging in the runtime safety mechanisms into this .o file.
2929pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
30 _ = msg;
31 _ = error_return_trace;
3032 @setCold(true);
3133 if (@hasDecl(std.os, "abort"))
3234 std.os.abort();
lib/std/target.zig+1-1
......@@ -157,7 +157,7 @@ pub const Target = struct {
157157 pub fn format(
158158 self: WindowsVersion,
159159 comptime fmt: []const u8,
160 options: std.fmt.FormatOptions,
160 _: std.fmt.FormatOptions,
161161 out_stream: anytype,
162162 ) !void {
163163 if (fmt.len > 0 and fmt[0] == 's') {
lib/std/testing.zig-1
......@@ -191,7 +191,6 @@ test "expectEqual.union(enum)" {
191191 };
192192
193193 const a10 = T{ .a = 10 };
194 const a20 = T{ .a = 20 };
195194
196195 try expectEqual(a10, a10);
197196}
lib/std/unicode.zig+1-1
......@@ -210,7 +210,7 @@ pub fn utf8ValidateSlice(s: []const u8) bool {
210210 return false;
211211 }
212212 i += cp_len;
213 } else |err| {
213 } else |_| {
214214 return false;
215215 }
216216 }
lib/std/unicode/throughput_test.zig-2
......@@ -47,8 +47,6 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {
4747pub fn main() !void {
4848 const stdout = std.io.getStdOut().writer();
4949
50 const args = try std.process.argsAlloc(std.heap.page_allocator);
51
5250 try stdout.print("short ASCII strings\n", .{});
5351 {
5452 const result = try benchmarkCodepointCount("abc");
lib/std/x/net/ip.zig+2
......@@ -53,6 +53,8 @@ pub const Address = union(enum) {
5353 opts: fmt.FormatOptions,
5454 writer: anytype,
5555 ) !void {
56 _ = opts;
57 _ = layout;
5658 switch (self) {
5759 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
5860 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
lib/std/x/os/io.zig-1
......@@ -122,7 +122,6 @@ test "reactor/linux: drive async tcp client/listener pair" {
122122
123123 const IPv4 = std.x.os.IPv4;
124124 const IPv6 = std.x.os.IPv6;
125 const Socket = std.x.os.Socket;
126125
127126 const reactor = try Reactor.init(.{ .close_on_exec = true });
128127 defer reactor.deinit();
lib/std/x/os/net.zig+2
......@@ -143,6 +143,7 @@ pub const IPv4 = extern struct {
143143 opts: fmt.FormatOptions,
144144 writer: anytype,
145145 ) !void {
146 _ = opts;
146147 if (comptime layout.len != 0 and layout[0] != 's') {
147148 @compileError("Unsupported format specifier for IPv4 type '" ++ layout ++ "'.");
148149 }
......@@ -352,6 +353,7 @@ pub const IPv6 = extern struct {
352353 opts: fmt.FormatOptions,
353354 writer: anytype,
354355 ) !void {
356 _ = opts;
355357 const specifier = comptime &[_]u8{if (layout.len == 0) 'x' else switch (layout[0]) {
356358 'x', 'X' => |specifier| specifier,
357359 's' => 'x',
lib/std/x/os/socket.zig+4-2
......@@ -117,7 +117,7 @@ pub const Socket = struct {
117117 };
118118 }
119119
120 /// Returns the number of bytes that make up the `sockaddr` equivalent to the address.
120 /// Returns the number of bytes that make up the `sockaddr` equivalent to the address.
121121 pub fn getNativeSize(self: Socket.Address) u32 {
122122 return switch (self) {
123123 .ipv4 => @sizeOf(os.sockaddr_in),
......@@ -132,6 +132,8 @@ pub const Socket = struct {
132132 opts: fmt.FormatOptions,
133133 writer: anytype,
134134 ) !void {
135 _ = opts;
136 _ = layout;
135137 switch (self) {
136138 .ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
137139 .ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
......@@ -280,7 +282,7 @@ pub const Socket = struct {
280282 ///
281283 /// Microsoft's documentation and glibc denote the fields to be unsigned
282284 /// short's on Windows, whereas glibc and musl denote the fields to be
283 /// int's on every other platform.
285 /// int's on every other platform.
284286 pub const Linger = extern struct {
285287 pub const Field = switch (native_os.tag) {
286288 .windows => c_ushort,
lib/std/x/os/socket_windows.zig+7-3
......@@ -292,6 +292,7 @@ pub fn Mixin(comptime Socket: type) type {
292292 /// with a set of flags specified. It returns the number of bytes that were
293293 /// read into the buffer provided.
294294 pub fn readMessage(self: Socket, msg: *Socket.Message, flags: u32) !usize {
295 _ = flags;
295296 const call = try windows.loadWinsockExtensionFunction(ws2_32.LPFN_WSARECVMSG, self.fd, ws2_32.WSAID_WSARECVMSG);
296297
297298 var num_bytes: u32 = undefined;
......@@ -367,16 +368,19 @@ pub fn Mixin(comptime Socket: type) type {
367368
368369 /// Query and return the latest cached error on the socket.
369370 pub fn getError(self: Socket) !void {
371 _ = self;
370372 return {};
371373 }
372374
373375 /// Query the read buffer size of the socket.
374376 pub fn getReadBufferSize(self: Socket) !u32 {
377 _ = self;
375378 return 0;
376379 }
377380
378381 /// Query the write buffer size of the socket.
379382 pub fn getWriteBufferSize(self: Socket) !u32 {
383 _ = self;
380384 return 0;
381385 }
382386
......@@ -406,7 +410,7 @@ pub fn Mixin(comptime Socket: type) type {
406410
407411 /// On connection-oriented sockets, have keep-alive messages be sent periodically. The timing in which keep-alive
408412 /// messages are sent are dependant on operating system settings. It returns `error.UnsupportedSocketOption` if
409 /// the host does not support periodically sending keep-alive messages on connection-oriented sockets.
413 /// the host does not support periodically sending keep-alive messages on connection-oriented sockets.
410414 pub fn setKeepAlive(self: Socket, enabled: bool) !void {
411415 return self.setOption(ws2_32.SOL_SOCKET, ws2_32.SO_KEEPALIVE, mem.asBytes(&@as(u32, @boolToInt(enabled))));
412416 }
......@@ -438,7 +442,7 @@ pub fn Mixin(comptime Socket: type) type {
438442
439443 /// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
440444 /// set on a non-blocking socket.
441 ///
445 ///
442446 /// Set a timeout on the socket that is to occur if no messages are successfully written
443447 /// to its bound destination after a specified number of milliseconds. A subsequent write
444448 /// to the socket will thereafter return `error.WouldBlock` should the timeout be exceeded.
......@@ -448,7 +452,7 @@ pub fn Mixin(comptime Socket: type) type {
448452
449453 /// WARNING: Timeouts only affect blocking sockets. It is undefined behavior if a timeout is
450454 /// set on a non-blocking socket.
451 ///
455 ///
452456 /// Set a timeout on the socket that is to occur if no messages are successfully read
453457 /// from its bound destination after a specified number of milliseconds. A subsequent
454458 /// read from the socket will thereafter return `error.WouldBlock` should the timeout be
lib/std/zig/ast.zig+1-1
......@@ -1866,7 +1866,7 @@ pub const Tree = struct {
18661866 }
18671867
18681868 fn fullStructInit(tree: Tree, info: full.StructInit.Ast) full.StructInit {
1869 const token_tags = tree.tokens.items(.tag);
1869 _ = tree;
18701870 var result: full.StructInit = .{
18711871 .ast = info,
18721872 };
lib/std/zig/c_builtins.zig+2
......@@ -136,6 +136,7 @@ pub inline fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) c_int {
136136}
137137
138138pub inline fn __builtin_object_size(ptr: ?*const c_void, ty: c_int) usize {
139 _ = ptr;
139140 // clang semantics match gcc's: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
140141 // If it is not possible to determine which objects ptr points to at compile time,
141142 // __builtin_object_size should return (size_t) -1 for type 0 or 1 and (size_t) 0
......@@ -186,6 +187,7 @@ pub inline fn __builtin_memcpy(
186187/// The return value of __builtin_expect is `expr`. `c` is the expected value
187188/// of `expr` and is used as a hint to the compiler in C. Here it is unused.
188189pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long {
190 _ = c;
189191 return expr;
190192}
191193
lib/std/zig/fmt.zig+2
......@@ -8,6 +8,7 @@ pub fn formatId(
88 options: std.fmt.FormatOptions,
99 writer: anytype,
1010) !void {
11 _ = fmt;
1112 if (isValidId(bytes)) {
1213 return writer.writeAll(bytes);
1314 }
......@@ -41,6 +42,7 @@ pub fn formatEscapes(
4142 options: std.fmt.FormatOptions,
4243 writer: anytype,
4344) !void {
45 _ = options;
4446 for (bytes) |byte| switch (byte) {
4547 '\n' => try writer.writeAll("\\n"),
4648 '\r' => try writer.writeAll("\\r"),
lib/std/zig/parse.zig+26-26
......@@ -586,7 +586,7 @@ const Parser = struct {
586586 const thread_local_token = p.eatToken(.keyword_threadlocal);
587587 const var_decl = try p.parseVarDecl();
588588 if (var_decl != 0) {
589 const semicolon_token = try p.expectToken(.semicolon);
589 _ = try p.expectToken(.semicolon);
590590 return var_decl;
591591 }
592592 if (thread_local_token != null) {
......@@ -614,7 +614,7 @@ const Parser = struct {
614614 fn expectUsingNamespace(p: *Parser) !Node.Index {
615615 const usingnamespace_token = p.assertToken(.keyword_usingnamespace);
616616 const expr = try p.expectExpr();
617 const semicolon_token = try p.expectToken(.semicolon);
617 _ = try p.expectToken(.semicolon);
618618 return p.addNode(.{
619619 .tag = .@"usingnamespace",
620620 .main_token = usingnamespace_token,
......@@ -647,7 +647,7 @@ const Parser = struct {
647647 const align_expr = try p.parseByteAlign();
648648 const section_expr = try p.parseLinkSection();
649649 const callconv_expr = try p.parseCallconv();
650 const bang_token = p.eatToken(.bang);
650 _ = p.eatToken(.bang);
651651
652652 const return_type_expr = try p.parseTypeExpr();
653653 if (return_type_expr == 0) {
......@@ -775,7 +775,7 @@ const Parser = struct {
775775
776776 /// ContainerField <- KEYWORD_comptime? IDENTIFIER (COLON (KEYWORD_anytype / TypeExpr) ByteAlign?)? (EQUAL Expr)?
777777 fn expectContainerField(p: *Parser) !Node.Index {
778 const comptime_token = p.eatToken(.keyword_comptime);
778 _ = p.eatToken(.keyword_comptime);
779779 const name_token = p.assertToken(.identifier);
780780
781781 var align_expr: Node.Index = 0;
......@@ -967,7 +967,7 @@ const Parser = struct {
967967 _ = try p.expectToken(.l_paren);
968968 const condition = try p.expectExpr();
969969 _ = try p.expectToken(.r_paren);
970 const then_payload = try p.parsePtrPayload();
970 _ = try p.parsePtrPayload();
971971
972972 // TODO propose to change the syntax so that semicolons are always required
973973 // inside if statements, even if there is an `else`.
......@@ -992,7 +992,7 @@ const Parser = struct {
992992 else_required = true;
993993 break :blk assign_expr;
994994 };
995 const else_token = p.eatToken(.keyword_else) orelse {
995 _ = p.eatToken(.keyword_else) orelse {
996996 if (else_required) {
997997 try p.warn(.expected_semi_or_else);
998998 }
......@@ -1005,7 +1005,7 @@ const Parser = struct {
10051005 },
10061006 });
10071007 };
1008 const else_payload = try p.parsePayload();
1008 _ = try p.parsePayload();
10091009 const else_expr = try p.expectStatement();
10101010 return p.addNode(.{
10111011 .tag = .@"if",
......@@ -1087,7 +1087,7 @@ const Parser = struct {
10871087 else_required = true;
10881088 break :blk assign_expr;
10891089 };
1090 const else_token = p.eatToken(.keyword_else) orelse {
1090 _ = p.eatToken(.keyword_else) orelse {
10911091 if (else_required) {
10921092 try p.warn(.expected_semi_or_else);
10931093 }
......@@ -1122,7 +1122,7 @@ const Parser = struct {
11221122 _ = try p.expectToken(.l_paren);
11231123 const condition = try p.expectExpr();
11241124 _ = try p.expectToken(.r_paren);
1125 const then_payload = try p.parsePtrPayload();
1125 _ = try p.parsePtrPayload();
11261126 const cont_expr = try p.parseWhileContinueExpr();
11271127
11281128 // TODO propose to change the syntax so that semicolons are always required
......@@ -1162,7 +1162,7 @@ const Parser = struct {
11621162 else_required = true;
11631163 break :blk assign_expr;
11641164 };
1165 const else_token = p.eatToken(.keyword_else) orelse {
1165 _ = p.eatToken(.keyword_else) orelse {
11661166 if (else_required) {
11671167 try p.warn(.expected_semi_or_else);
11681168 }
......@@ -1189,7 +1189,7 @@ const Parser = struct {
11891189 });
11901190 }
11911191 };
1192 const else_payload = try p.parsePayload();
1192 _ = try p.parsePayload();
11931193 const else_expr = try p.expectStatement();
11941194 return p.addNode(.{
11951195 .tag = .@"while",
......@@ -1550,7 +1550,7 @@ const Parser = struct {
15501550 },
15511551 .l_bracket => switch (p.token_tags[p.tok_i + 1]) {
15521552 .asterisk => {
1553 const lbracket = p.nextToken();
1553 _ = p.nextToken();
15541554 const asterisk = p.nextToken();
15551555 var sentinel: Node.Index = 0;
15561556 prefix: {
......@@ -1907,7 +1907,7 @@ const Parser = struct {
19071907 if (found_payload == 0) try p.warn(.expected_loop_payload);
19081908
19091909 const then_expr = try p.expectExpr();
1910 const else_token = p.eatToken(.keyword_else) orelse {
1910 _ = p.eatToken(.keyword_else) orelse {
19111911 return p.addNode(.{
19121912 .tag = .for_simple,
19131913 .main_token = for_token,
......@@ -1938,11 +1938,11 @@ const Parser = struct {
19381938 _ = try p.expectToken(.l_paren);
19391939 const condition = try p.expectExpr();
19401940 _ = try p.expectToken(.r_paren);
1941 const then_payload = try p.parsePtrPayload();
1941 _ = try p.parsePtrPayload();
19421942 const cont_expr = try p.parseWhileContinueExpr();
19431943
19441944 const then_expr = try p.expectExpr();
1945 const else_token = p.eatToken(.keyword_else) orelse {
1945 _ = p.eatToken(.keyword_else) orelse {
19461946 if (cont_expr == 0) {
19471947 return p.addNode(.{
19481948 .tag = .while_simple,
......@@ -1966,7 +1966,7 @@ const Parser = struct {
19661966 });
19671967 }
19681968 };
1969 const else_payload = try p.parsePayload();
1969 _ = try p.parsePayload();
19701970 const else_expr = try p.expectExpr();
19711971 return p.addNode(.{
19721972 .tag = .@"while",
......@@ -2104,7 +2104,7 @@ const Parser = struct {
21042104 /// FnCallArguments <- LPAREN ExprList RPAREN
21052105 /// ExprList <- (Expr COMMA)* Expr?
21062106 fn parseSuffixExpr(p: *Parser) !Node.Index {
2107 if (p.eatToken(.keyword_async)) |async_token| {
2107 if (p.eatToken(.keyword_async)) |_| {
21082108 var res = try p.expectPrimaryTypeExpr();
21092109 while (true) {
21102110 const node = try p.parseSuffixOp(res);
......@@ -2565,8 +2565,8 @@ const Parser = struct {
25652565 p.tok_i += 2;
25662566 while (true) {
25672567 if (p.eatToken(.r_brace)) |_| break;
2568 const doc_comment = try p.eatDocComments();
2569 const identifier = try p.expectToken(.identifier);
2568 _ = try p.eatDocComments();
2569 _ = try p.expectToken(.identifier);
25702570 switch (p.token_tags[p.tok_i]) {
25712571 .comma => p.tok_i += 1,
25722572 .r_brace => {
......@@ -2634,7 +2634,7 @@ const Parser = struct {
26342634 if (found_payload == 0) try p.warn(.expected_loop_payload);
26352635
26362636 const then_expr = try p.expectTypeExpr();
2637 const else_token = p.eatToken(.keyword_else) orelse {
2637 _ = p.eatToken(.keyword_else) orelse {
26382638 return p.addNode(.{
26392639 .tag = .for_simple,
26402640 .main_token = for_token,
......@@ -2665,11 +2665,11 @@ const Parser = struct {
26652665 _ = try p.expectToken(.l_paren);
26662666 const condition = try p.expectExpr();
26672667 _ = try p.expectToken(.r_paren);
2668 const then_payload = try p.parsePtrPayload();
2668 _ = try p.parsePtrPayload();
26692669 const cont_expr = try p.parseWhileContinueExpr();
26702670
26712671 const then_expr = try p.expectTypeExpr();
2672 const else_token = p.eatToken(.keyword_else) orelse {
2672 _ = p.eatToken(.keyword_else) orelse {
26732673 if (cont_expr == 0) {
26742674 return p.addNode(.{
26752675 .tag = .while_simple,
......@@ -2693,7 +2693,7 @@ const Parser = struct {
26932693 });
26942694 }
26952695 };
2696 const else_payload = try p.parsePayload();
2696 _ = try p.parsePayload();
26972697 const else_expr = try p.expectTypeExpr();
26982698 return p.addNode(.{
26992699 .tag = .@"while",
......@@ -3570,12 +3570,12 @@ const Parser = struct {
35703570 _ = try p.expectToken(.l_paren);
35713571 const condition = try p.expectExpr();
35723572 _ = try p.expectToken(.r_paren);
3573 const then_payload = try p.parsePtrPayload();
3573 _ = try p.parsePtrPayload();
35743574
35753575 const then_expr = try bodyParseFn(p);
35763576 if (then_expr == 0) return p.fail(.invalid_token);
35773577
3578 const else_token = p.eatToken(.keyword_else) orelse return p.addNode(.{
3578 _ = p.eatToken(.keyword_else) orelse return p.addNode(.{
35793579 .tag = .if_simple,
35803580 .main_token = if_token,
35813581 .data = .{
......@@ -3583,7 +3583,7 @@ const Parser = struct {
35833583 .rhs = then_expr,
35843584 },
35853585 });
3586 const else_payload = try p.parsePayload();
3586 _ = try p.parsePayload();
35873587 const else_expr = try bodyParseFn(p);
35883588 if (else_expr == 0) return p.fail(.invalid_token);
35893589
lib/std/zig/parser_test.zig-1
......@@ -5201,7 +5201,6 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
52015201 defer tree.deinit(allocator);
52025202
52035203 for (tree.errors) |parse_error| {
5204 const token_start = tree.tokens.items(.start)[parse_error.token];
52055204 const loc = tree.tokenLocation(0, parse_error.token);
52065205 try stderr.print("(memory buffer):{d}:{d}: error: ", .{ loc.line + 1, loc.column + 1 });
52075206 try tree.renderError(parse_error, stderr);
lib/std/zig/render.zig-6
......@@ -1086,8 +1086,6 @@ fn renderWhile(gpa: *Allocator, ais: *Ais, tree: ast.Tree, while_node: ast.full.
10861086 }
10871087
10881088 if (while_node.ast.else_expr != 0) {
1089 const first_else_expr_tok = tree.firstToken(while_node.ast.else_expr);
1090
10911089 if (indent_then_expr) {
10921090 ais.pushIndent();
10931091 try renderExpression(gpa, ais, tree, while_node.ast.then_expr, .newline);
......@@ -1133,7 +1131,6 @@ fn renderContainerField(
11331131 field: ast.full.ContainerField,
11341132 space: Space,
11351133) Error!void {
1136 const main_tokens = tree.nodes.items(.main_token);
11371134 if (field.comptime_token) |t| {
11381135 try renderToken(ais, tree, t, .space); // comptime
11391136 }
......@@ -1519,7 +1516,6 @@ fn renderBlock(
15191516) Error!void {
15201517 const token_tags = tree.tokens.items(.tag);
15211518 const node_tags = tree.nodes.items(.tag);
1522 const nodes_data = tree.nodes.items(.data);
15231519 const lbrace = tree.nodes.items(.main_token)[block_node];
15241520
15251521 if (token_tags[lbrace - 1] == .colon and
......@@ -1617,7 +1613,6 @@ fn renderArrayInit(
16171613 space: Space,
16181614) Error!void {
16191615 const token_tags = tree.tokens.items(.tag);
1620 const token_starts = tree.tokens.items(.start);
16211616
16221617 if (array_init.ast.type_expr == 0) {
16231618 try renderToken(ais, tree, array_init.ast.lbrace - 1, .none); // .
......@@ -2046,7 +2041,6 @@ fn renderCall(
20462041 space: Space,
20472042) Error!void {
20482043 const token_tags = tree.tokens.items(.tag);
2049 const main_tokens = tree.nodes.items(.main_token);
20502044
20512045 if (call.async_token) |async_token| {
20522046 try renderToken(ais, tree, async_token, .space);
lib/std/zig/system.zig+3-9
......@@ -200,6 +200,7 @@ pub const NativePaths = struct {
200200 }
201201
202202 fn appendArray(self: *NativePaths, array: *ArrayList([:0]u8), s: []const u8) !void {
203 _ = self;
203204 const item = try array.allocator.dupeZ(u8, s);
204205 errdefer array.allocator.free(item);
205206 try array.append(item);
......@@ -332,7 +333,7 @@ pub const NativeTargetInfo = struct {
332333 if (std.builtin.Version.parse(buf[0 .. len - 1])) |ver| {
333334 os.version_range.semver.min = ver;
334335 os.version_range.semver.max = ver;
335 } else |err| {
336 } else |_| {
336337 return error.OSVersionDetectionFail;
337338 }
338339 },
......@@ -478,13 +479,6 @@ pub const NativeTargetInfo = struct {
478479 }
479480 const ld_info_list = ld_info_list_buffer[0..ld_info_list_len];
480481
481 if (cross_target.dynamic_linker.get()) |explicit_ld| {
482 const explicit_ld_basename = fs.path.basename(explicit_ld);
483 for (ld_info_list) |ld_info| {
484 const standard_ld_basename = fs.path.basename(ld_info.ld.get().?);
485 }
486 }
487
488482 // Best case scenario: the executable is dynamically linked, and we can iterate
489483 // over our own shared objects and find a dynamic linker.
490484 self_exe: {
......@@ -838,7 +832,7 @@ pub const NativeTargetInfo = struct {
838832
839833 if (dynstr) |ds| {
840834 const strtab_len = std.math.min(ds.size, strtab_buf.len);
841 const strtab_read_len = try preadMin(file, &strtab_buf, ds.offset, shstrtab_len);
835 const strtab_read_len = try preadMin(file, &strtab_buf, ds.offset, strtab_len);
842836 const strtab = strtab_buf[0..strtab_read_len];
843837 // TODO this pointer cast should not be necessary
844838 const rpoff_usize = std.math.cast(usize, rpoff) catch |err| switch (err) {
lib/std/zig/system/macos.zig+2-2
......@@ -68,10 +68,10 @@ pub fn detect(target_os: *Target.Os) !void {
6868 return;
6969 }
7070 continue;
71 } else |err| {
71 } else |_| {
7272 return error.OSVersionDetectionFail;
7373 }
74 } else |err| {
74 } else |_| {
7575 return error.OSVersionDetectionFail;
7676 }
7777 }
lib/std/zig/system/x86.zig+1
......@@ -28,6 +28,7 @@ inline fn hasMask(input: u32, mask: u32) bool {
2828}
2929
3030pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, cross_target: CrossTarget) Target.Cpu {
31 _ = cross_target;
3132 var cpu = Target.Cpu{
3233 .arch = arch,
3334 .model = Target.Cpu.Model.generic(arch),
lib/std/zig/tokenizer.zig-1
......@@ -416,7 +416,6 @@ pub const Tokenizer = struct {
416416 self.pending_invalid_token = null;
417417 return token;
418418 }
419 const start_index = self.index;
420419 var state: State = .start;
421420 var result = Token{
422421 .tag = .eof,
src/AstGen.zig+415-323
......@@ -206,7 +206,6 @@ pub const ResultLoc = union(enum) {
206206 };
207207
208208 fn strategy(rl: ResultLoc, block_scope: *GenZir) Strategy {
209 var elide_store_to_block_ptr_instructions = false;
210209 switch (rl) {
211210 // In this branch there will not be any store_to_block_ptr instructions.
212211 .discard, .none, .none_or_ref, .ty, .ref => return .{
......@@ -482,61 +481,61 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
482481
483482 .assign => {
484483 try assign(gz, scope, node);
485 return rvalue(gz, scope, rl, .void_value, node);
484 return rvalue(gz, rl, .void_value, node);
486485 },
487486
488487 .assign_bit_shift_left => {
489488 try assignShift(gz, scope, node, .shl);
490 return rvalue(gz, scope, rl, .void_value, node);
489 return rvalue(gz, rl, .void_value, node);
491490 },
492491 .assign_bit_shift_right => {
493492 try assignShift(gz, scope, node, .shr);
494 return rvalue(gz, scope, rl, .void_value, node);
493 return rvalue(gz, rl, .void_value, node);
495494 },
496495
497496 .assign_bit_and => {
498497 try assignOp(gz, scope, node, .bit_and);
499 return rvalue(gz, scope, rl, .void_value, node);
498 return rvalue(gz, rl, .void_value, node);
500499 },
501500 .assign_bit_or => {
502501 try assignOp(gz, scope, node, .bit_or);
503 return rvalue(gz, scope, rl, .void_value, node);
502 return rvalue(gz, rl, .void_value, node);
504503 },
505504 .assign_bit_xor => {
506505 try assignOp(gz, scope, node, .xor);
507 return rvalue(gz, scope, rl, .void_value, node);
506 return rvalue(gz, rl, .void_value, node);
508507 },
509508 .assign_div => {
510509 try assignOp(gz, scope, node, .div);
511 return rvalue(gz, scope, rl, .void_value, node);
510 return rvalue(gz, rl, .void_value, node);
512511 },
513512 .assign_sub => {
514513 try assignOp(gz, scope, node, .sub);
515 return rvalue(gz, scope, rl, .void_value, node);
514 return rvalue(gz, rl, .void_value, node);
516515 },
517516 .assign_sub_wrap => {
518517 try assignOp(gz, scope, node, .subwrap);
519 return rvalue(gz, scope, rl, .void_value, node);
518 return rvalue(gz, rl, .void_value, node);
520519 },
521520 .assign_mod => {
522521 try assignOp(gz, scope, node, .mod_rem);
523 return rvalue(gz, scope, rl, .void_value, node);
522 return rvalue(gz, rl, .void_value, node);
524523 },
525524 .assign_add => {
526525 try assignOp(gz, scope, node, .add);
527 return rvalue(gz, scope, rl, .void_value, node);
526 return rvalue(gz, rl, .void_value, node);
528527 },
529528 .assign_add_wrap => {
530529 try assignOp(gz, scope, node, .addwrap);
531 return rvalue(gz, scope, rl, .void_value, node);
530 return rvalue(gz, rl, .void_value, node);
532531 },
533532 .assign_mul => {
534533 try assignOp(gz, scope, node, .mul);
535 return rvalue(gz, scope, rl, .void_value, node);
534 return rvalue(gz, rl, .void_value, node);
536535 },
537536 .assign_mul_wrap => {
538537 try assignOp(gz, scope, node, .mulwrap);
539 return rvalue(gz, scope, rl, .void_value, node);
538 return rvalue(gz, rl, .void_value, node);
540539 },
541540
542541 // zig fmt: off
......@@ -598,10 +597,10 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
598597 .asm_simple => return asmExpr(gz, scope, rl, node, tree.asmSimple(node)),
599598 .@"asm" => return asmExpr(gz, scope, rl, node, tree.asmFull(node)),
600599
601 .string_literal => return stringLiteral(gz, scope, rl, node),
602 .multiline_string_literal => return multilineStringLiteral(gz, scope, rl, node),
600 .string_literal => return stringLiteral(gz, rl, node),
601 .multiline_string_literal => return multilineStringLiteral(gz, rl, node),
603602
604 .integer_literal => return integerLiteral(gz, scope, rl, node),
603 .integer_literal => return integerLiteral(gz, rl, node),
605604 // zig fmt: on
606605
607606 .builtin_call_two, .builtin_call_two_comma => {
......@@ -641,7 +640,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
641640 },
642641 .@"return" => return ret(gz, scope, node),
643642 .field_access => return fieldAccess(gz, scope, rl, node),
644 .float_literal => return floatLiteral(gz, scope, rl, node),
643 .float_literal => return floatLiteral(gz, rl, node),
645644
646645 .if_simple => return ifExpr(gz, scope, rl, node, tree.ifSimple(node)),
647646 .@"if" => return ifExpr(gz, scope, rl, node, tree.ifFull(node)),
......@@ -660,7 +659,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
660659 .lhs = lhs,
661660 .start = start,
662661 });
663 return rvalue(gz, scope, rl, result, node);
662 return rvalue(gz, rl, result, node);
664663 },
665664 .slice => {
666665 const lhs = try expr(gz, scope, .ref, node_datas[node].lhs);
......@@ -672,7 +671,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
672671 .start = start,
673672 .end = end,
674673 });
675 return rvalue(gz, scope, rl, result, node);
674 return rvalue(gz, rl, result, node);
676675 },
677676 .slice_sentinel => {
678677 const lhs = try expr(gz, scope, .ref, node_datas[node].lhs);
......@@ -686,7 +685,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
686685 .end = end,
687686 .sentinel = sentinel,
688687 });
689 return rvalue(gz, scope, rl, result, node);
688 return rvalue(gz, rl, result, node);
690689 },
691690
692691 .deref => {
......@@ -695,22 +694,22 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
695694 .ref, .none_or_ref => return lhs,
696695 else => {
697696 const result = try gz.addUnNode(.load, lhs, node);
698 return rvalue(gz, scope, rl, result, node);
697 return rvalue(gz, rl, result, node);
699698 },
700699 }
701700 },
702701 .address_of => {
703702 const result = try expr(gz, scope, .ref, node_datas[node].lhs);
704 return rvalue(gz, scope, rl, result, node);
703 return rvalue(gz, rl, result, node);
705704 },
706 .undefined_literal => return rvalue(gz, scope, rl, .undef, node),
707 .true_literal => return rvalue(gz, scope, rl, .bool_true, node),
708 .false_literal => return rvalue(gz, scope, rl, .bool_false, node),
709 .null_literal => return rvalue(gz, scope, rl, .null_value, node),
705 .undefined_literal => return rvalue(gz, rl, .undef, node),
706 .true_literal => return rvalue(gz, rl, .bool_true, node),
707 .false_literal => return rvalue(gz, rl, .bool_false, node),
708 .null_literal => return rvalue(gz, rl, .null_value, node),
710709 .optional_type => {
711710 const operand = try typeExpr(gz, scope, node_datas[node].lhs);
712711 const result = try gz.addUnNode(.optional_type, operand, node);
713 return rvalue(gz, scope, rl, result, node);
712 return rvalue(gz, rl, result, node);
714713 },
715714 .unwrap_optional => switch (rl) {
716715 .ref => return gz.addUnNode(
......@@ -718,7 +717,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
718717 try expr(gz, scope, .ref, node_datas[node].lhs),
719718 node,
720719 ),
721 else => return rvalue(gz, scope, rl, try gz.addUnNode(
720 else => return rvalue(gz, rl, try gz.addUnNode(
722721 .optional_payload_safe,
723722 try expr(gz, scope, .none, node_datas[node].lhs),
724723 node,
......@@ -738,13 +737,13 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
738737 const statements = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs];
739738 return blockExpr(gz, scope, rl, node, statements);
740739 },
741 .enum_literal => return simpleStrTok(gz, scope, rl, main_tokens[node], node, .enum_literal),
742 .error_value => return simpleStrTok(gz, scope, rl, node_datas[node].rhs, node, .error_value),
743 .anyframe_literal => return rvalue(gz, scope, rl, .anyframe_type, node),
740 .enum_literal => return simpleStrTok(gz, rl, main_tokens[node], node, .enum_literal),
741 .error_value => return simpleStrTok(gz, rl, node_datas[node].rhs, node, .error_value),
742 .anyframe_literal => return rvalue(gz, rl, .anyframe_type, node),
744743 .anyframe_type => {
745744 const return_type = try typeExpr(gz, scope, node_datas[node].rhs);
746745 const result = try gz.addUnNode(.anyframe_type, return_type, node);
747 return rvalue(gz, scope, rl, result, node);
746 return rvalue(gz, rl, result, node);
748747 },
749748 .@"catch" => {
750749 const catch_token = main_tokens[node];
......@@ -838,14 +837,14 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
838837 .grouped_expression => return expr(gz, scope, rl, node_datas[node].lhs),
839838 .array_type => return arrayType(gz, scope, rl, node),
840839 .array_type_sentinel => return arrayTypeSentinel(gz, scope, rl, node),
841 .char_literal => return charLiteral(gz, scope, rl, node),
842 .error_set_decl => return errorSetDecl(gz, scope, rl, node),
840 .char_literal => return charLiteral(gz, rl, node),
841 .error_set_decl => return errorSetDecl(gz, rl, node),
843842 .array_access => return arrayAccess(gz, scope, rl, node),
844843 .@"comptime" => return comptimeExprAst(gz, scope, rl, node),
845844 .@"switch", .switch_comma => return switchExpr(gz, scope, rl, node),
846845
847846 .@"nosuspend" => return nosuspendExpr(gz, scope, rl, node),
848 .@"suspend" => return suspendExpr(gz, scope, rl, node),
847 .@"suspend" => return suspendExpr(gz, scope, node),
849848 .@"await" => return awaitExpr(gz, scope, rl, node),
850849 .@"resume" => return resumeExpr(gz, scope, rl, node),
851850
......@@ -905,7 +904,6 @@ fn nosuspendExpr(
905904 node: ast.Node.Index,
906905) InnerError!Zir.Inst.Ref {
907906 const astgen = gz.astgen;
908 const gpa = astgen.gpa;
909907 const tree = astgen.tree;
910908 const node_datas = tree.nodes.items(.data);
911909 const body_node = node_datas[node].lhs;
......@@ -918,13 +916,12 @@ fn nosuspendExpr(
918916 gz.nosuspend_node = node;
919917 const result = try expr(gz, scope, rl, body_node);
920918 gz.nosuspend_node = 0;
921 return rvalue(gz, scope, rl, result, node);
919 return rvalue(gz, rl, result, node);
922920}
923921
924922fn suspendExpr(
925923 gz: *GenZir,
926924 scope: *Scope,
927 rl: ResultLoc,
928925 node: ast.Node.Index,
929926) InnerError!Zir.Inst.Ref {
930927 const astgen = gz.astgen;
......@@ -980,7 +977,7 @@ fn awaitExpr(
980977 const operand = try expr(gz, scope, .none, rhs_node);
981978 const tag: Zir.Inst.Tag = if (gz.nosuspend_node != 0) .await_nosuspend else .@"await";
982979 const result = try gz.addUnNode(tag, operand, node);
983 return rvalue(gz, scope, rl, result, node);
980 return rvalue(gz, rl, result, node);
984981}
985982
986983fn resumeExpr(
......@@ -995,7 +992,7 @@ fn resumeExpr(
995992 const rhs_node = node_datas[node].lhs;
996993 const operand = try expr(gz, scope, .none, rhs_node);
997994 const result = try gz.addUnNode(.@"resume", operand, node);
998 return rvalue(gz, scope, rl, result, node);
995 return rvalue(gz, rl, result, node);
999996}
1000997
1001998fn fnProtoExpr(
......@@ -1101,7 +1098,7 @@ fn fnProtoExpr(
11011098 .is_test = false,
11021099 .is_extern = false,
11031100 });
1104 return rvalue(gz, scope, rl, result, fn_proto.ast.proto_node);
1101 return rvalue(gz, rl, result, fn_proto.ast.proto_node);
11051102}
11061103
11071104fn arrayInitExpr(
......@@ -1113,7 +1110,6 @@ fn arrayInitExpr(
11131110) InnerError!Zir.Inst.Ref {
11141111 const astgen = gz.astgen;
11151112 const tree = astgen.tree;
1116 const gpa = astgen.gpa;
11171113 const node_tags = tree.nodes.items(.tag);
11181114 const main_tokens = tree.nodes.items(.main_token);
11191115
......@@ -1173,32 +1169,32 @@ fn arrayInitExpr(
11731169 },
11741170 .ref => {
11751171 if (types.array != .none) {
1176 return arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, types.array, types.elem, .array_init_ref);
1172 return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, .array_init_ref);
11771173 } else {
1178 return arrayInitExprRlNone(gz, scope, rl, node, array_init.ast.elements, .array_init_anon_ref);
1174 return arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon_ref);
11791175 }
11801176 },
11811177 .none, .none_or_ref => {
11821178 if (types.array != .none) {
1183 return arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, types.array, types.elem, .array_init);
1179 return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, .array_init);
11841180 } else {
1185 return arrayInitExprRlNone(gz, scope, rl, node, array_init.ast.elements, .array_init_anon);
1181 return arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);
11861182 }
11871183 },
11881184 .ty => |ty_inst| {
11891185 if (types.array != .none) {
1190 const result = try arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, types.array, types.elem, .array_init);
1191 return rvalue(gz, scope, rl, result, node);
1186 const result = try arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, .array_init);
1187 return rvalue(gz, rl, result, node);
11921188 } else {
11931189 const elem_type = try gz.addUnNode(.elem_type, ty_inst, node);
1194 return arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, ty_inst, elem_type, .array_init);
1190 return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, elem_type, .array_init);
11951191 }
11961192 },
11971193 .ptr, .inferred_ptr => |ptr_inst| {
1198 return arrayInitExprRlPtr(gz, scope, rl, node, array_init.ast.elements, ptr_inst);
1194 return arrayInitExprRlPtr(gz, scope, node, array_init.ast.elements, ptr_inst);
11991195 },
12001196 .block_ptr => |block_gz| {
1201 return arrayInitExprRlPtr(gz, scope, rl, node, array_init.ast.elements, block_gz.rl_ptr);
1197 return arrayInitExprRlPtr(gz, scope, node, array_init.ast.elements, block_gz.rl_ptr);
12021198 },
12031199 }
12041200}
......@@ -1206,7 +1202,6 @@ fn arrayInitExpr(
12061202fn arrayInitExprRlNone(
12071203 gz: *GenZir,
12081204 scope: *Scope,
1209 rl: ResultLoc,
12101205 node: ast.Node.Index,
12111206 elements: []const ast.Node.Index,
12121207 tag: Zir.Inst.Tag,
......@@ -1229,10 +1224,8 @@ fn arrayInitExprRlNone(
12291224fn arrayInitExprRlTy(
12301225 gz: *GenZir,
12311226 scope: *Scope,
1232 rl: ResultLoc,
12331227 node: ast.Node.Index,
12341228 elements: []const ast.Node.Index,
1235 array_ty_inst: Zir.Inst.Ref,
12361229 elem_ty_inst: Zir.Inst.Ref,
12371230 tag: Zir.Inst.Tag,
12381231) InnerError!Zir.Inst.Ref {
......@@ -1257,7 +1250,6 @@ fn arrayInitExprRlTy(
12571250fn arrayInitExprRlPtr(
12581251 gz: *GenZir,
12591252 scope: *Scope,
1260 rl: ResultLoc,
12611253 node: ast.Node.Index,
12621254 elements: []const ast.Node.Index,
12631255 result_ptr: Zir.Inst.Ref,
......@@ -1293,11 +1285,10 @@ fn structInitExpr(
12931285) InnerError!Zir.Inst.Ref {
12941286 const astgen = gz.astgen;
12951287 const tree = astgen.tree;
1296 const gpa = astgen.gpa;
12971288
12981289 if (struct_init.ast.fields.len == 0) {
12991290 if (struct_init.ast.type_expr == 0) {
1300 return rvalue(gz, scope, rl, .empty_struct, node);
1291 return rvalue(gz, rl, .empty_struct, node);
13011292 }
13021293 array: {
13031294 const node_tags = tree.nodes.items(.tag);
......@@ -1319,15 +1310,17 @@ fn structInitExpr(
13191310 break :blk try gz.addArrayTypeSentinel(.zero_usize, elem_type, sentinel);
13201311 };
13211312 const result = try gz.addUnNode(.struct_init_empty, array_type_inst, node);
1322 return rvalue(gz, scope, rl, result, node);
1313 return rvalue(gz, rl, result, node);
13231314 }
13241315 }
13251316 const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);
13261317 const result = try gz.addUnNode(.struct_init_empty, ty_inst, node);
1327 return rvalue(gz, scope, rl, result, node);
1318 return rvalue(gz, rl, result, node);
13281319 }
13291320 switch (rl) {
13301321 .discard => {
1322 if (struct_init.ast.type_expr != 0)
1323 _ = try typeExpr(gz, scope, struct_init.ast.type_expr);
13311324 for (struct_init.ast.fields) |field_init| {
13321325 _ = try expr(gz, scope, .discard, field_init);
13331326 }
......@@ -1336,36 +1329,35 @@ fn structInitExpr(
13361329 .ref => {
13371330 if (struct_init.ast.type_expr != 0) {
13381331 const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);
1339 return structInitExprRlTy(gz, scope, rl, node, struct_init, ty_inst, .struct_init_ref);
1332 return structInitExprRlTy(gz, scope, node, struct_init, ty_inst, .struct_init_ref);
13401333 } else {
1341 return structInitExprRlNone(gz, scope, rl, node, struct_init, .struct_init_anon_ref);
1334 return structInitExprRlNone(gz, scope, node, struct_init, .struct_init_anon_ref);
13421335 }
13431336 },
13441337 .none, .none_or_ref => {
13451338 if (struct_init.ast.type_expr != 0) {
13461339 const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);
1347 return structInitExprRlTy(gz, scope, rl, node, struct_init, ty_inst, .struct_init);
1340 return structInitExprRlTy(gz, scope, node, struct_init, ty_inst, .struct_init);
13481341 } else {
1349 return structInitExprRlNone(gz, scope, rl, node, struct_init, .struct_init_anon);
1342 return structInitExprRlNone(gz, scope, node, struct_init, .struct_init_anon);
13501343 }
13511344 },
13521345 .ty => |ty_inst| {
13531346 if (struct_init.ast.type_expr == 0) {
1354 return structInitExprRlTy(gz, scope, rl, node, struct_init, ty_inst, .struct_init);
1347 return structInitExprRlTy(gz, scope, node, struct_init, ty_inst, .struct_init);
13551348 }
13561349 const inner_ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr);
1357 const result = try structInitExprRlTy(gz, scope, rl, node, struct_init, inner_ty_inst, .struct_init);
1358 return rvalue(gz, scope, rl, result, node);
1350 const result = try structInitExprRlTy(gz, scope, node, struct_init, inner_ty_inst, .struct_init);
1351 return rvalue(gz, rl, result, node);
13591352 },
1360 .ptr, .inferred_ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst),
1361 .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, rl, node, struct_init, block_gz.rl_ptr),
1353 .ptr, .inferred_ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, node, struct_init, ptr_inst),
1354 .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, node, struct_init, block_gz.rl_ptr),
13621355 }
13631356}
13641357
13651358fn structInitExprRlNone(
13661359 gz: *GenZir,
13671360 scope: *Scope,
1368 rl: ResultLoc,
13691361 node: ast.Node.Index,
13701362 struct_init: ast.full.StructInit,
13711363 tag: Zir.Inst.Tag,
......@@ -1400,7 +1392,6 @@ fn structInitExprRlNone(
14001392fn structInitExprRlPtr(
14011393 gz: *GenZir,
14021394 scope: *Scope,
1403 rl: ResultLoc,
14041395 node: ast.Node.Index,
14051396 struct_init: ast.full.StructInit,
14061397 result_ptr: Zir.Inst.Ref,
......@@ -1412,6 +1403,9 @@ fn structInitExprRlPtr(
14121403 const field_ptr_list = try gpa.alloc(Zir.Inst.Index, struct_init.ast.fields.len);
14131404 defer gpa.free(field_ptr_list);
14141405
1406 if (struct_init.ast.type_expr != 0)
1407 _ = try typeExpr(gz, scope, struct_init.ast.type_expr);
1408
14151409 for (struct_init.ast.fields) |field_init, i| {
14161410 const name_token = tree.firstToken(field_init) - 2;
14171411 const str_index = try astgen.identAsString(name_token);
......@@ -1432,7 +1426,6 @@ fn structInitExprRlPtr(
14321426fn structInitExprRlTy(
14331427 gz: *GenZir,
14341428 scope: *Scope,
1435 rl: ResultLoc,
14361429 node: ast.Node.Index,
14371430 struct_init: ast.full.StructInit,
14381431 ty_inst: Zir.Inst.Ref,
......@@ -1657,8 +1650,8 @@ fn blockExpr(
16571650 return labeledBlockExpr(gz, scope, rl, block_node, statements, .block);
16581651 }
16591652
1660 try blockExprStmts(gz, scope, block_node, statements);
1661 return rvalue(gz, scope, rl, .void_value, block_node);
1653 try blockExprStmts(gz, scope, statements);
1654 return rvalue(gz, rl, .void_value, block_node);
16621655}
16631656
16641657fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: ast.TokenIndex) !void {
......@@ -1670,9 +1663,6 @@ fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: ast.Toke
16701663 const gen_zir = scope.cast(GenZir).?;
16711664 if (gen_zir.label) |prev_label| {
16721665 if (try astgen.tokenIdentEql(label, prev_label.token)) {
1673 const tree = astgen.tree;
1674 const main_tokens = tree.nodes.items(.main_token);
1675
16761666 const label_name = try astgen.identifierTokenString(label);
16771667 return astgen.failTokNotes(label, "redefinition of label '{s}'", .{
16781668 label_name,
......@@ -1735,7 +1725,7 @@ fn labeledBlockExpr(
17351725 defer block_scope.labeled_breaks.deinit(astgen.gpa);
17361726 defer block_scope.labeled_store_to_block_ptr_list.deinit(astgen.gpa);
17371727
1738 try blockExprStmts(&block_scope, &block_scope.base, block_node, statements);
1728 try blockExprStmts(&block_scope, &block_scope.base, statements);
17391729
17401730 if (!block_scope.label.?.used) {
17411731 return astgen.failTok(label_token, "unused block label", .{});
......@@ -1771,21 +1761,15 @@ fn labeledBlockExpr(
17711761 const block_ref = gz.indexToRef(block_inst);
17721762 switch (rl) {
17731763 .ref => return block_ref,
1774 else => return rvalue(gz, parent_scope, rl, block_ref, block_node),
1764 else => return rvalue(gz, rl, block_ref, block_node),
17751765 }
17761766 },
17771767 }
17781768}
17791769
1780fn blockExprStmts(
1781 gz: *GenZir,
1782 parent_scope: *Scope,
1783 node: ast.Node.Index,
1784 statements: []const ast.Node.Index,
1785) !void {
1770fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const ast.Node.Index) !void {
17861771 const astgen = gz.astgen;
17871772 const tree = astgen.tree;
1788 const main_tokens = tree.nodes.items(.main_token);
17891773 const node_tags = tree.nodes.items(.tag);
17901774
17911775 var block_arena = std.heap.ArenaAllocator.init(gz.astgen.gpa);
......@@ -1800,8 +1784,8 @@ fn blockExprStmts(
18001784 .simple_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.simpleVarDecl(statement)),
18011785 .aligned_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.alignedVarDecl(statement)),
18021786
1803 .@"defer" => scope = try deferStmt(gz, scope, statement, &block_arena.allocator, .defer_normal),
1804 .@"errdefer" => scope = try deferStmt(gz, scope, statement, &block_arena.allocator, .defer_error),
1787 .@"defer" => scope = try makeDeferScope(scope, statement, &block_arena.allocator, .defer_normal),
1788 .@"errdefer" => scope = try makeDeferScope(scope, statement, &block_arena.allocator, .defer_error),
18051789
18061790 .assign => try assign(gz, scope, statement),
18071791
......@@ -1826,6 +1810,7 @@ fn blockExprStmts(
18261810 }
18271811
18281812 try genDefers(gz, parent_scope, scope, .none);
1813 try checkUsed(gz, parent_scope, scope);
18291814}
18301815
18311816fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: ast.Node.Index) InnerError!void {
......@@ -2119,6 +2104,7 @@ fn genDefers(
21192104 inner_scope: *Scope,
21202105 err_code: Zir.Inst.Ref,
21212106) InnerError!void {
2107 _ = err_code;
21222108 const astgen = gz.astgen;
21232109 const tree = astgen.tree;
21242110 const node_datas = tree.nodes.items(.data);
......@@ -2154,8 +2140,49 @@ fn genDefers(
21542140 }
21552141}
21562142
2157fn deferStmt(
2143fn checkUsed(
21582144 gz: *GenZir,
2145 outer_scope: *Scope,
2146 inner_scope: *Scope,
2147) InnerError!void {
2148 const astgen = gz.astgen;
2149
2150 var scope = inner_scope;
2151 while (scope != outer_scope) {
2152 switch (scope.tag) {
2153 .gen_zir => scope = scope.cast(GenZir).?.parent,
2154 .local_val => {
2155 const s = scope.cast(Scope.LocalVal).?;
2156 switch (s.used) {
2157 .used => {},
2158 .fn_param => return astgen.failTok(s.token_src, "unused function parameter", .{}),
2159 .constant => return astgen.failTok(s.token_src, "unused local constant", .{}),
2160 .variable => unreachable,
2161 .loop_index => unreachable,
2162 .capture => return astgen.failTok(s.token_src, "unused capture", .{}),
2163 }
2164 scope = s.parent;
2165 },
2166 .local_ptr => {
2167 const s = scope.cast(Scope.LocalPtr).?;
2168 switch (s.used) {
2169 .used => {},
2170 .fn_param => unreachable,
2171 .constant => return astgen.failTok(s.token_src, "unused local constant", .{}),
2172 .variable => return astgen.failTok(s.token_src, "unused local variable", .{}),
2173 .loop_index => return astgen.failTok(s.token_src, "unused loop index capture", .{}),
2174 .capture => unreachable,
2175 }
2176 scope = s.parent;
2177 },
2178 .defer_normal, .defer_error => scope = scope.cast(Scope.Defer).?.parent,
2179 .namespace => unreachable,
2180 .top => unreachable,
2181 }
2182 }
2183}
2184
2185fn makeDeferScope(
21592186 scope: *Scope,
21602187 node: ast.Node.Index,
21612188 block_arena: *Allocator,
......@@ -2274,6 +2301,7 @@ fn varDecl(
22742301 .name = ident_name,
22752302 .inst = init_inst,
22762303 .token_src = name_token,
2304 .used = .constant,
22772305 };
22782306 return &sub_scope.base;
22792307 }
......@@ -2341,6 +2369,7 @@ fn varDecl(
23412369 .name = ident_name,
23422370 .inst = init_inst,
23432371 .token_src = name_token,
2372 .used = .constant,
23442373 };
23452374 return &sub_scope.base;
23462375 }
......@@ -2369,7 +2398,8 @@ fn varDecl(
23692398 .name = ident_name,
23702399 .ptr = init_scope.rl_ptr,
23712400 .token_src = name_token,
2372 .is_comptime = true,
2401 .maybe_comptime = true,
2402 .used = .constant,
23732403 };
23742404 return &sub_scope.base;
23752405 },
......@@ -2414,7 +2444,7 @@ fn varDecl(
24142444 resolve_inferred_alloc = alloc;
24152445 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };
24162446 };
2417 const init_inst = try expr(gz, scope, var_data.result_loc, var_decl.ast.init_node);
2447 _ = try expr(gz, scope, var_data.result_loc, var_decl.ast.init_node);
24182448 if (resolve_inferred_alloc != .none) {
24192449 _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node);
24202450 }
......@@ -2425,7 +2455,8 @@ fn varDecl(
24252455 .name = ident_name,
24262456 .ptr = var_data.alloc,
24272457 .token_src = name_token,
2428 .is_comptime = is_comptime,
2458 .maybe_comptime = is_comptime,
2459 .used = .variable,
24292460 };
24302461 return &sub_scope.base;
24312462 },
......@@ -2441,7 +2472,6 @@ fn emitDbgNode(gz: *GenZir, node: ast.Node.Index) !void {
24412472
24422473 const astgen = gz.astgen;
24432474 const tree = astgen.tree;
2444 const node_tags = tree.nodes.items(.tag);
24452475 const token_starts = tree.tokens.items(.start);
24462476 const decl_start = token_starts[tree.firstToken(gz.decl_node_index)];
24472477 const node_start = token_starts[tree.firstToken(node)];
......@@ -2530,7 +2560,7 @@ fn boolNot(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) Inne
25302560
25312561 const operand = try expr(gz, scope, bool_rl, node_datas[node].lhs);
25322562 const result = try gz.addUnNode(.bool_not, operand, node);
2533 return rvalue(gz, scope, rl, result, node);
2563 return rvalue(gz, rl, result, node);
25342564}
25352565
25362566fn bitNot(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!Zir.Inst.Ref {
......@@ -2540,7 +2570,7 @@ fn bitNot(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) Inner
25402570
25412571 const operand = try expr(gz, scope, .none, node_datas[node].lhs);
25422572 const result = try gz.addUnNode(.bit_not, operand, node);
2543 return rvalue(gz, scope, rl, result, node);
2573 return rvalue(gz, rl, result, node);
25442574}
25452575
25462576fn negation(
......@@ -2556,7 +2586,7 @@ fn negation(
25562586
25572587 const operand = try expr(gz, scope, .none, node_datas[node].lhs);
25582588 const result = try gz.addUnNode(tag, operand, node);
2559 return rvalue(gz, scope, rl, result, node);
2589 return rvalue(gz, rl, result, node);
25602590}
25612591
25622592fn ptrType(
......@@ -2566,9 +2596,6 @@ fn ptrType(
25662596 node: ast.Node.Index,
25672597 ptr_info: ast.full.PtrType,
25682598) InnerError!Zir.Inst.Ref {
2569 const astgen = gz.astgen;
2570 const tree = astgen.tree;
2571
25722599 const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type);
25732600
25742601 const simple = ptr_info.ast.align_node == 0 and
......@@ -2585,7 +2612,7 @@ fn ptrType(
25852612 .elem_type = elem_type,
25862613 },
25872614 } });
2588 return rvalue(gz, scope, rl, result, node);
2615 return rvalue(gz, rl, result, node);
25892616 }
25902617
25912618 var sentinel_ref: Zir.Inst.Ref = .none;
......@@ -2645,7 +2672,7 @@ fn ptrType(
26452672 } });
26462673 gz.instructions.appendAssumeCapacity(new_index);
26472674
2648 return rvalue(gz, scope, rl, result, node);
2675 return rvalue(gz, rl, result, node);
26492676}
26502677
26512678fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !Zir.Inst.Ref {
......@@ -2665,7 +2692,7 @@ fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !Z
26652692 const elem_type = try typeExpr(gz, scope, node_datas[node].rhs);
26662693
26672694 const result = try gz.addBin(.array_type, len, elem_type);
2668 return rvalue(gz, scope, rl, result, node);
2695 return rvalue(gz, rl, result, node);
26692696}
26702697
26712698fn arrayTypeSentinel(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !Zir.Inst.Ref {
......@@ -2687,7 +2714,7 @@ fn arrayTypeSentinel(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.I
26872714 const sentinel = try expr(gz, scope, .{ .ty = elem_type }, extra.sentinel);
26882715
26892716 const result = try gz.addArrayTypeSentinel(len, elem_type, sentinel);
2690 return rvalue(gz, scope, rl, result, node);
2717 return rvalue(gz, rl, result, node);
26912718}
26922719
26932720const WipDecls = struct {
......@@ -2918,6 +2945,10 @@ fn fnDecl(
29182945 const name_token = param.name_token orelse {
29192946 return astgen.failNode(param.type_expr, "missing parameter name", .{});
29202947 };
2948 if (param.type_expr != 0)
2949 _ = try typeExpr(&fn_gz, params_scope, param.type_expr);
2950 if (mem.eql(u8, "_", tree.tokenSlice(name_token)))
2951 continue;
29212952 const param_name = try astgen.identAsString(name_token);
29222953 // Create an arg instruction. This is needed to emit a semantic analysis
29232954 // error for shadowing decls.
......@@ -2930,16 +2961,19 @@ fn fnDecl(
29302961 .name = param_name,
29312962 .inst = arg_inst,
29322963 .token_src = name_token,
2964 .used = .fn_param,
29332965 };
29342966 params_scope = &sub_scope.base;
29352967
29362968 // Additionally put the param name into `string_bytes` and reference it with
29372969 // `extra` so that we have access to the data in codegen, for debug info.
29382970 const str_index = try astgen.identAsString(name_token);
2939 astgen.extra.appendAssumeCapacity(str_index);
2971 try astgen.extra.append(astgen.gpa, str_index);
29402972 }
2973 _ = try typeExpr(&fn_gz, params_scope, fn_proto.ast.return_type);
29412974
29422975 _ = try expr(&fn_gz, params_scope, .none, body_node);
2976 try checkUsed(gz, &fn_gz.base, params_scope);
29432977 }
29442978
29452979 const need_implicit_ret = blk: {
......@@ -3632,7 +3666,7 @@ fn unionDeclInner(
36323666 };
36333667 defer block_scope.instructions.deinit(gpa);
36343668
3635 var namespace: Scope.Namespace = .{ .parent = &gz.base };
3669 var namespace: Scope.Namespace = .{ .parent = scope };
36363670 defer namespace.decls.deinit(gpa);
36373671
36383672 var wip_decls: WipDecls = .{};
......@@ -3916,7 +3950,7 @@ fn containerDecl(
39163950 assert(arg_inst == .none);
39173951
39183952 const result = try structDeclInner(gz, scope, node, container_decl, layout);
3919 return rvalue(gz, scope, rl, result, node);
3953 return rvalue(gz, rl, result, node);
39203954 },
39213955 .keyword_union => {
39223956 const layout = if (container_decl.layout_token) |t| switch (token_tags[t]) {
......@@ -3928,7 +3962,7 @@ fn containerDecl(
39283962 const have_auto_enum = container_decl.ast.enum_token != null;
39293963
39303964 const result = try unionDeclInner(gz, scope, node, container_decl.ast.members, layout, arg_inst, have_auto_enum);
3931 return rvalue(gz, scope, rl, result, node);
3965 return rvalue(gz, rl, result, node);
39323966 },
39333967 .keyword_enum => {
39343968 if (container_decl.layout_token) |t| {
......@@ -4033,7 +4067,7 @@ fn containerDecl(
40334067 };
40344068 defer block_scope.instructions.deinit(gpa);
40354069
4036 var namespace: Scope.Namespace = .{ .parent = &gz.base };
4070 var namespace: Scope.Namespace = .{ .parent = scope };
40374071 defer namespace.decls.deinit(gpa);
40384072
40394073 var wip_decls: WipDecls = .{};
......@@ -4257,20 +4291,18 @@ fn containerDecl(
42574291 astgen.extra.appendAssumeCapacity(cur_bit_bag);
42584292 astgen.extra.appendSliceAssumeCapacity(fields_data.items);
42594293
4260 return rvalue(gz, scope, rl, gz.indexToRef(decl_inst), node);
4294 return rvalue(gz, rl, gz.indexToRef(decl_inst), node);
42614295 },
42624296 .keyword_opaque => {
4263 var namespace: Scope.Namespace = .{ .parent = &gz.base };
4297 var namespace: Scope.Namespace = .{ .parent = scope };
42644298 defer namespace.decls.deinit(gpa);
42654299
42664300 var wip_decls: WipDecls = .{};
42674301 defer wip_decls.deinit(gpa);
42684302
42694303 for (container_decl.ast.members) |member_node| {
4270 const member = switch (node_tags[member_node]) {
4271 .container_field_init => tree.containerFieldInit(member_node),
4272 .container_field_align => tree.containerFieldAlign(member_node),
4273 .container_field => tree.containerField(member_node),
4304 switch (node_tags[member_node]) {
4305 .container_field_init, .container_field_align, .container_field => {},
42744306
42754307 .fn_decl => {
42764308 const fn_proto = node_datas[member_node].lhs;
......@@ -4391,7 +4423,7 @@ fn containerDecl(
43914423 continue;
43924424 },
43934425 else => unreachable,
4394 };
4426 }
43954427 }
43964428 {
43974429 const empty_slot_count = WipDecls.fields_per_u32 - (wip_decls.decl_index % WipDecls.fields_per_u32);
......@@ -4420,18 +4452,13 @@ fn containerDecl(
44204452 }
44214453 astgen.extra.appendSliceAssumeCapacity(wip_decls.payload.items);
44224454
4423 return rvalue(gz, scope, rl, gz.indexToRef(decl_inst), node);
4455 return rvalue(gz, rl, gz.indexToRef(decl_inst), node);
44244456 },
44254457 else => unreachable,
44264458 }
44274459}
44284460
4429fn errorSetDecl(
4430 gz: *GenZir,
4431 scope: *Scope,
4432 rl: ResultLoc,
4433 node: ast.Node.Index,
4434) InnerError!Zir.Inst.Ref {
4461fn errorSetDecl(gz: *GenZir, rl: ResultLoc, node: ast.Node.Index) InnerError!Zir.Inst.Ref {
44354462 const astgen = gz.astgen;
44364463 const gpa = astgen.gpa;
44374464 const tree = astgen.tree;
......@@ -4459,16 +4486,11 @@ fn errorSetDecl(
44594486 }
44604487 }
44614488
4462 const tag: Zir.Inst.Tag = switch (gz.anon_name_strategy) {
4463 .parent => .error_set_decl,
4464 .anon => .error_set_decl_anon,
4465 .func => .error_set_decl_func,
4466 };
44674489 const result = try gz.addPlNode(.error_set_decl, node, Zir.Inst.ErrorSetDecl{
44684490 .fields_len = @intCast(u32, field_names.items.len),
44694491 });
44704492 try astgen.extra.appendSlice(gpa, field_names.items);
4471 return rvalue(gz, scope, rl, result, node);
4493 return rvalue(gz, rl, result, node);
44724494}
44734495
44744496fn tryExpr(
......@@ -4479,7 +4501,6 @@ fn tryExpr(
44794501 operand_node: ast.Node.Index,
44804502) InnerError!Zir.Inst.Ref {
44814503 const astgen = parent_gz.astgen;
4482 const tree = astgen.tree;
44834504
44844505 const fn_block = astgen.fn_block orelse {
44854506 return astgen.failNode(node, "invalid 'try' outside function scope", .{});
......@@ -4528,12 +4549,11 @@ fn tryExpr(
45284549 const unwrapped_payload = try else_scope.addUnNode(err_ops[2], operand, node);
45294550 const else_result = switch (rl) {
45304551 .ref => unwrapped_payload,
4531 else => try rvalue(&else_scope, &else_scope.base, block_scope.break_result_loc, unwrapped_payload, node),
4552 else => try rvalue(&else_scope, block_scope.break_result_loc, unwrapped_payload, node),
45324553 };
45334554
45344555 return finishThenElseBlock(
45354556 parent_gz,
4536 scope,
45374557 rl,
45384558 node,
45394559 &block_scope,
......@@ -4541,8 +4561,6 @@ fn tryExpr(
45414561 &else_scope,
45424562 condbr,
45434563 cond,
4544 node,
4545 node,
45464564 then_result,
45474565 else_result,
45484566 block,
......@@ -4603,12 +4621,15 @@ fn orelseCatchExpr(
46034621 .name = err_name,
46044622 .inst = try then_scope.addUnNode(unwrap_code_op, operand, node),
46054623 .token_src = payload,
4624 .used = .capture,
46064625 };
46074626 break :blk &err_val_scope.base;
46084627 };
46094628
46104629 block_scope.break_count += 1;
46114630 const then_result = try expr(&then_scope, then_sub_scope, block_scope.break_result_loc, rhs);
4631 try checkUsed(parent_gz, &then_scope.base, then_sub_scope);
4632
46124633 // We hold off on the break instructions as well as copying the then/else
46134634 // instructions into place until we know whether to keep store_to_block_ptr
46144635 // instructions or not.
......@@ -4620,12 +4641,11 @@ fn orelseCatchExpr(
46204641 const unwrapped_payload = try else_scope.addUnNode(unwrap_op, operand, node);
46214642 const else_result = switch (rl) {
46224643 .ref => unwrapped_payload,
4623 else => try rvalue(&else_scope, &else_scope.base, block_scope.break_result_loc, unwrapped_payload, node),
4644 else => try rvalue(&else_scope, block_scope.break_result_loc, unwrapped_payload, node),
46244645 };
46254646
46264647 return finishThenElseBlock(
46274648 parent_gz,
4628 scope,
46294649 rl,
46304650 node,
46314651 &block_scope,
......@@ -4633,8 +4653,6 @@ fn orelseCatchExpr(
46334653 &else_scope,
46344654 condbr,
46354655 cond,
4636 node,
4637 node,
46384656 then_result,
46394657 else_result,
46404658 block,
......@@ -4645,7 +4663,6 @@ fn orelseCatchExpr(
46454663
46464664fn finishThenElseBlock(
46474665 parent_gz: *GenZir,
4648 parent_scope: *Scope,
46494666 rl: ResultLoc,
46504667 node: ast.Node.Index,
46514668 block_scope: *GenZir,
......@@ -4653,8 +4670,6 @@ fn finishThenElseBlock(
46534670 else_scope: *GenZir,
46544671 condbr: Zir.Inst.Index,
46554672 cond: Zir.Inst.Ref,
4656 then_src: ast.Node.Index,
4657 else_src: ast.Node.Index,
46584673 then_result: Zir.Inst.Ref,
46594674 else_result: Zir.Inst.Ref,
46604675 main_block: Zir.Inst.Index,
......@@ -4664,7 +4679,6 @@ fn finishThenElseBlock(
46644679 // We now have enough information to decide whether the result instruction should
46654680 // be communicated via result location pointer or break instructions.
46664681 const strat = rl.strategy(block_scope);
4667 const astgen = block_scope.astgen;
46684682 switch (strat.tag) {
46694683 .break_void => {
46704684 if (!parent_gz.refIsNoReturn(then_result)) {
......@@ -4697,7 +4711,7 @@ fn finishThenElseBlock(
46974711 const block_ref = parent_gz.indexToRef(main_block);
46984712 switch (rl) {
46994713 .ref => return block_ref,
4700 else => return rvalue(parent_gz, parent_scope, rl, block_ref, node),
4714 else => return rvalue(parent_gz, rl, block_ref, node),
47014715 }
47024716 },
47034717 }
......@@ -4733,7 +4747,7 @@ fn fieldAccess(
47334747 .lhs = try expr(gz, scope, .ref, object_node),
47344748 .field_name_start = str_index,
47354749 }),
4736 else => return rvalue(gz, scope, rl, try gz.addPlNode(.field_val, node, Zir.Inst.Field{
4750 else => return rvalue(gz, rl, try gz.addPlNode(.field_val, node, Zir.Inst.Field{
47374751 .lhs = try expr(gz, scope, .none_or_ref, object_node),
47384752 .field_name_start = str_index,
47394753 }), node),
......@@ -4748,7 +4762,6 @@ fn arrayAccess(
47484762) InnerError!Zir.Inst.Ref {
47494763 const astgen = gz.astgen;
47504764 const tree = astgen.tree;
4751 const main_tokens = tree.nodes.items(.main_token);
47524765 const node_datas = tree.nodes.items(.data);
47534766 switch (rl) {
47544767 .ref => return gz.addBin(
......@@ -4756,7 +4769,7 @@ fn arrayAccess(
47564769 try expr(gz, scope, .ref, node_datas[node].lhs),
47574770 try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs),
47584771 ),
4759 else => return rvalue(gz, scope, rl, try gz.addBin(
4772 else => return rvalue(gz, rl, try gz.addBin(
47604773 .elem_val,
47614774 try expr(gz, scope, .none_or_ref, node_datas[node].lhs),
47624775 try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs),
......@@ -4779,12 +4792,11 @@ fn simpleBinOp(
47794792 .lhs = try expr(gz, scope, .none, node_datas[node].lhs),
47804793 .rhs = try expr(gz, scope, .none, node_datas[node].rhs),
47814794 });
4782 return rvalue(gz, scope, rl, result, node);
4795 return rvalue(gz, rl, result, node);
47834796}
47844797
47854798fn simpleStrTok(
47864799 gz: *GenZir,
4787 scope: *Scope,
47884800 rl: ResultLoc,
47894801 ident_token: ast.TokenIndex,
47904802 node: ast.Node.Index,
......@@ -4793,7 +4805,7 @@ fn simpleStrTok(
47934805 const astgen = gz.astgen;
47944806 const str_index = try astgen.identAsString(ident_token);
47954807 const result = try gz.addStrTok(op_inst_tag, str_index, ident_token);
4796 return rvalue(gz, scope, rl, result, node);
4808 return rvalue(gz, rl, result, node);
47974809}
47984810
47994811fn boolBinOp(
......@@ -4819,7 +4831,7 @@ fn boolBinOp(
48194831 try rhs_scope.setBoolBrBody(bool_br);
48204832
48214833 const block_ref = gz.indexToRef(bool_br);
4822 return rvalue(gz, scope, rl, block_ref, node);
4834 return rvalue(gz, rl, block_ref, node);
48234835}
48244836
48254837fn ifExpr(
......@@ -4846,7 +4858,7 @@ fn ifExpr(
48464858 inst: Zir.Inst.Ref,
48474859 bool_bit: Zir.Inst.Ref,
48484860 } = c: {
4849 if (if_full.error_token) |error_token| {
4861 if (if_full.error_token) |_| {
48504862 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;
48514863 const err_union = try expr(&block_scope, &block_scope.base, cond_rl, if_full.ast.cond_expr);
48524864 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_err_ptr else .is_err;
......@@ -4854,7 +4866,7 @@ fn ifExpr(
48544866 .inst = err_union,
48554867 .bool_bit = try block_scope.addUnNode(tag, err_union, node),
48564868 };
4857 } else if (if_full.payload_token) |payload_token| {
4869 } else if (if_full.payload_token) |_| {
48584870 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;
48594871 const optional = try expr(&block_scope, &block_scope.base, cond_rl, if_full.ast.cond_expr);
48604872 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_non_null_ptr else .is_non_null;
......@@ -4883,27 +4895,38 @@ fn ifExpr(
48834895 var payload_val_scope: Scope.LocalVal = undefined;
48844896
48854897 const then_sub_scope = s: {
4886 if (if_full.error_token) |error_token| {
4887 const tag: Zir.Inst.Tag = if (payload_is_ref)
4888 .err_union_payload_unsafe_ptr
4889 else
4890 .err_union_payload_unsafe;
4891 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
4892 const ident_name = try astgen.identAsString(error_token);
4893 payload_val_scope = .{
4894 .parent = &then_scope.base,
4895 .gen_zir = &then_scope,
4896 .name = ident_name,
4897 .inst = payload_inst,
4898 .token_src = error_token,
4899 };
4900 break :s &payload_val_scope.base;
4898 if (if_full.error_token != null) {
4899 if (if_full.payload_token) |payload_token| {
4900 const tag: Zir.Inst.Tag = if (payload_is_ref)
4901 .err_union_payload_unsafe_ptr
4902 else
4903 .err_union_payload_unsafe;
4904 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
4905 const token_name_index = payload_token + @boolToInt(payload_is_ref);
4906 const ident_name = try astgen.identAsString(token_name_index);
4907 const token_name_str = tree.tokenSlice(token_name_index);
4908 if (mem.eql(u8, "_", token_name_str))
4909 break :s &then_scope.base;
4910 payload_val_scope = .{
4911 .parent = &then_scope.base,
4912 .gen_zir = &then_scope,
4913 .name = ident_name,
4914 .inst = payload_inst,
4915 .token_src = payload_token,
4916 .used = .capture,
4917 };
4918 break :s &payload_val_scope.base;
4919 } else {
4920 break :s &then_scope.base;
4921 }
49014922 } else if (if_full.payload_token) |payload_token| {
49024923 const ident_token = if (payload_is_ref) payload_token + 1 else payload_token;
49034924 const tag: Zir.Inst.Tag = if (payload_is_ref)
49044925 .optional_payload_unsafe_ptr
49054926 else
49064927 .optional_payload_unsafe;
4928 if (mem.eql(u8, "_", tree.tokenSlice(ident_token)))
4929 break :s &then_scope.base;
49074930 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
49084931 const ident_name = try astgen.identAsString(ident_token);
49094932 payload_val_scope = .{
......@@ -4912,6 +4935,7 @@ fn ifExpr(
49124935 .name = ident_name,
49134936 .inst = payload_inst,
49144937 .token_src = ident_token,
4938 .used = .capture,
49154939 };
49164940 break :s &payload_val_scope.base;
49174941 } else {
......@@ -4921,6 +4945,7 @@ fn ifExpr(
49214945
49224946 block_scope.break_count += 1;
49234947 const then_result = try expr(&then_scope, then_sub_scope, block_scope.break_result_loc, if_full.ast.then_expr);
4948 try checkUsed(parent_gz, &then_scope.base, then_sub_scope);
49244949 // We hold off on the break instructions as well as copying the then/else
49254950 // instructions into place until we know whether to keep store_to_block_ptr
49264951 // instructions or not.
......@@ -4942,21 +4967,27 @@ fn ifExpr(
49424967 .err_union_code;
49434968 const payload_inst = try else_scope.addUnNode(tag, cond.inst, node);
49444969 const ident_name = try astgen.identAsString(error_token);
4970 const error_token_str = tree.tokenSlice(error_token);
4971 if (mem.eql(u8, "_", error_token_str))
4972 break :s &else_scope.base;
49454973 payload_val_scope = .{
49464974 .parent = &else_scope.base,
49474975 .gen_zir = &else_scope,
49484976 .name = ident_name,
49494977 .inst = payload_inst,
49504978 .token_src = error_token,
4979 .used = .capture,
49514980 };
49524981 break :s &payload_val_scope.base;
49534982 } else {
49544983 break :s &else_scope.base;
49554984 }
49564985 };
4986 const e = try expr(&else_scope, sub_scope, block_scope.break_result_loc, else_node);
4987 try checkUsed(parent_gz, &else_scope.base, sub_scope);
49574988 break :blk .{
49584989 .src = else_node,
4959 .result = try expr(&else_scope, sub_scope, block_scope.break_result_loc, else_node),
4990 .result = e,
49604991 };
49614992 } else .{
49624993 .src = if_full.ast.then_expr,
......@@ -4965,7 +4996,6 @@ fn ifExpr(
49654996
49664997 return finishThenElseBlock(
49674998 parent_gz,
4968 scope,
49694999 rl,
49705000 node,
49715001 &block_scope,
......@@ -4973,8 +5003,6 @@ fn ifExpr(
49735003 &else_scope,
49745004 condbr,
49755005 cond.bool_bit,
4976 if_full.ast.then_expr,
4977 else_info.src,
49785006 then_result,
49795007 else_info.result,
49805008 block,
......@@ -5087,7 +5115,7 @@ fn whileExpr(
50875115 inst: Zir.Inst.Ref,
50885116 bool_bit: Zir.Inst.Ref,
50895117 } = c: {
5090 if (while_full.error_token) |error_token| {
5118 if (while_full.error_token) |_| {
50915119 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;
50925120 const err_union = try expr(&continue_scope, &continue_scope.base, cond_rl, while_full.ast.cond_expr);
50935121 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_err_ptr else .is_err;
......@@ -5095,7 +5123,7 @@ fn whileExpr(
50955123 .inst = err_union,
50965124 .bool_bit = try continue_scope.addUnNode(tag, err_union, node),
50975125 };
5098 } else if (while_full.payload_token) |payload_token| {
5126 } else if (while_full.payload_token) |_| {
50995127 const cond_rl: ResultLoc = if (payload_is_ref) .ref else .none;
51005128 const optional = try expr(&continue_scope, &continue_scope.base, cond_rl, while_full.ast.cond_expr);
51015129 const tag: Zir.Inst.Tag = if (payload_is_ref) .is_non_null_ptr else .is_non_null;
......@@ -5119,46 +5147,35 @@ fn whileExpr(
51195147 try loop_scope.instructions.append(astgen.gpa, cond_block);
51205148 try continue_scope.setBlockBody(cond_block);
51215149
5122 // TODO avoid emitting the continue expr when there
5123 // are no jumps to it. This happens when the last statement of a while body is noreturn
5124 // and there are no `continue` statements.
5125 if (while_full.ast.cont_expr != 0) {
5126 _ = try expr(&loop_scope, &loop_scope.base, .{ .ty = .void_type }, while_full.ast.cont_expr);
5127 }
5128 const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat;
5129 _ = try loop_scope.addNode(repeat_tag, node);
5130
5131 try loop_scope.setBlockBody(loop_block);
5132 loop_scope.break_block = loop_block;
5133 loop_scope.continue_block = cond_block;
5134 if (while_full.label_token) |label_token| {
5135 loop_scope.label = @as(?GenZir.Label, GenZir.Label{
5136 .token = label_token,
5137 .block_inst = loop_block,
5138 });
5139 }
5140
51415150 var then_scope = parent_gz.makeSubBlock(&continue_scope.base);
51425151 defer then_scope.instructions.deinit(astgen.gpa);
51435152
51445153 var payload_val_scope: Scope.LocalVal = undefined;
51455154
51465155 const then_sub_scope = s: {
5147 if (while_full.error_token) |error_token| {
5148 const tag: Zir.Inst.Tag = if (payload_is_ref)
5149 .err_union_payload_unsafe_ptr
5150 else
5151 .err_union_payload_unsafe;
5152 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
5153 const ident_name = try astgen.identAsString(error_token);
5154 payload_val_scope = .{
5155 .parent = &then_scope.base,
5156 .gen_zir = &then_scope,
5157 .name = ident_name,
5158 .inst = payload_inst,
5159 .token_src = error_token,
5160 };
5161 break :s &payload_val_scope.base;
5156 if (while_full.error_token != null) {
5157 if (while_full.payload_token) |payload_token| {
5158 const tag: Zir.Inst.Tag = if (payload_is_ref)
5159 .err_union_payload_unsafe_ptr
5160 else
5161 .err_union_payload_unsafe;
5162 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
5163 const ident_token = if (payload_is_ref) payload_token + 1 else payload_token;
5164 if (mem.eql(u8, "_", tree.tokenSlice(ident_token)))
5165 break :s &then_scope.base;
5166 const ident_name = try astgen.identAsString(payload_token + @boolToInt(payload_is_ref));
5167 payload_val_scope = .{
5168 .parent = &then_scope.base,
5169 .gen_zir = &then_scope,
5170 .name = ident_name,
5171 .inst = payload_inst,
5172 .token_src = payload_token,
5173 .used = .capture,
5174 };
5175 break :s &payload_val_scope.base;
5176 } else {
5177 break :s &then_scope.base;
5178 }
51625179 } else if (while_full.payload_token) |payload_token| {
51635180 const ident_token = if (payload_is_ref) payload_token + 1 else payload_token;
51645181 const tag: Zir.Inst.Tag = if (payload_is_ref)
......@@ -5167,12 +5184,15 @@ fn whileExpr(
51675184 .optional_payload_unsafe;
51685185 const payload_inst = try then_scope.addUnNode(tag, cond.inst, node);
51695186 const ident_name = try astgen.identAsString(ident_token);
5187 if (mem.eql(u8, "_", tree.tokenSlice(ident_token)))
5188 break :s &then_scope.base;
51705189 payload_val_scope = .{
51715190 .parent = &then_scope.base,
51725191 .gen_zir = &then_scope,
51735192 .name = ident_name,
51745193 .inst = payload_inst,
51755194 .token_src = ident_token,
5195 .used = .capture,
51765196 };
51775197 break :s &payload_val_scope.base;
51785198 } else {
......@@ -5180,8 +5200,29 @@ fn whileExpr(
51805200 }
51815201 };
51825202
5203 // This code could be improved to avoid emitting the continue expr when there
5204 // are no jumps to it. This happens when the last statement of a while body is noreturn
5205 // and there are no `continue` statements.
5206 // Tracking issue: https://github.com/ziglang/zig/issues/9185
5207 if (while_full.ast.cont_expr != 0) {
5208 _ = try expr(&loop_scope, then_sub_scope, .{ .ty = .void_type }, while_full.ast.cont_expr);
5209 }
5210 const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat;
5211 _ = try loop_scope.addNode(repeat_tag, node);
5212
5213 try loop_scope.setBlockBody(loop_block);
5214 loop_scope.break_block = loop_block;
5215 loop_scope.continue_block = cond_block;
5216 if (while_full.label_token) |label_token| {
5217 loop_scope.label = @as(?GenZir.Label, GenZir.Label{
5218 .token = label_token,
5219 .block_inst = loop_block,
5220 });
5221 }
5222
51835223 loop_scope.break_count += 1;
51845224 const then_result = try expr(&then_scope, then_sub_scope, loop_scope.break_result_loc, while_full.ast.then_expr);
5225 try checkUsed(parent_gz, &then_scope.base, then_sub_scope);
51855226
51865227 var else_scope = parent_gz.makeSubBlock(&continue_scope.base);
51875228 defer else_scope.instructions.deinit(astgen.gpa);
......@@ -5200,21 +5241,26 @@ fn whileExpr(
52005241 .err_union_code;
52015242 const payload_inst = try else_scope.addUnNode(tag, cond.inst, node);
52025243 const ident_name = try astgen.identAsString(error_token);
5244 if (mem.eql(u8, tree.tokenSlice(error_token), "_"))
5245 break :s &else_scope.base;
52035246 payload_val_scope = .{
52045247 .parent = &else_scope.base,
52055248 .gen_zir = &else_scope,
52065249 .name = ident_name,
52075250 .inst = payload_inst,
52085251 .token_src = error_token,
5252 .used = .capture,
52095253 };
52105254 break :s &payload_val_scope.base;
52115255 } else {
52125256 break :s &else_scope.base;
52135257 }
52145258 };
5259 const e = try expr(&else_scope, sub_scope, loop_scope.break_result_loc, else_node);
5260 try checkUsed(parent_gz, &else_scope.base, sub_scope);
52155261 break :blk .{
52165262 .src = else_node,
5217 .result = try expr(&else_scope, sub_scope, loop_scope.break_result_loc, else_node),
5263 .result = e,
52185264 };
52195265 } else .{
52205266 .src = while_full.ast.then_expr,
......@@ -5229,7 +5275,6 @@ fn whileExpr(
52295275 const break_tag: Zir.Inst.Tag = if (is_inline) .break_inline else .@"break";
52305276 return finishThenElseBlock(
52315277 parent_gz,
5232 scope,
52335278 rl,
52345279 node,
52355280 &loop_scope,
......@@ -5237,8 +5282,6 @@ fn whileExpr(
52375282 &else_scope,
52385283 condbr,
52395284 cond.bool_bit,
5240 while_full.ast.then_expr,
5241 else_info.src,
52425285 then_result,
52435286 else_info.result,
52445287 loop_block,
......@@ -5345,6 +5388,7 @@ fn forExpr(
53455388 .name = name_str_index,
53465389 .inst = payload_inst,
53475390 .token_src = ident,
5391 .used = .capture,
53485392 };
53495393 payload_sub_scope = &payload_val_scope.base;
53505394 } else if (is_ptr) {
......@@ -5367,13 +5411,15 @@ fn forExpr(
53675411 .name = index_name,
53685412 .ptr = index_ptr,
53695413 .token_src = index_token,
5370 .is_comptime = parent_gz.force_comptime,
5414 .maybe_comptime = is_inline,
5415 .used = .loop_index,
53715416 };
53725417 break :blk &index_scope.base;
53735418 };
53745419
53755420 loop_scope.break_count += 1;
53765421 const then_result = try expr(&then_scope, then_sub_scope, loop_scope.break_result_loc, for_full.ast.then_expr);
5422 try checkUsed(parent_gz, &then_scope.base, then_sub_scope);
53775423
53785424 var else_scope = parent_gz.makeSubBlock(&cond_scope.base);
53795425 defer else_scope.instructions.deinit(astgen.gpa);
......@@ -5402,7 +5448,6 @@ fn forExpr(
54025448 const break_tag: Zir.Inst.Tag = if (is_inline) .break_inline else .@"break";
54035449 return finishThenElseBlock(
54045450 parent_gz,
5405 scope,
54065451 rl,
54075452 node,
54085453 &loop_scope,
......@@ -5410,8 +5455,6 @@ fn forExpr(
54105455 &else_scope,
54115456 condbr,
54125457 cond,
5413 for_full.ast.then_expr,
5414 else_info.src,
54155458 then_result,
54165459 else_info.result,
54175460 loop_block,
......@@ -5614,10 +5657,12 @@ fn switchExpr(
56145657 .name = capture_name,
56155658 .inst = capture,
56165659 .token_src = payload_token,
5660 .used = .capture,
56175661 };
56185662 break :blk &capture_val_scope.base;
56195663 };
56205664 const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_loc, case.ast.target_expr);
5665 try checkUsed(parent_gz, &case_scope.base, sub_scope);
56215666 if (!parent_gz.refIsNoReturn(case_result)) {
56225667 block_scope.break_count += 1;
56235668 _ = try case_scope.addBreak(.@"break", switch_block, case_result);
......@@ -5706,6 +5751,7 @@ fn switchExpr(
57065751 .name = capture_name,
57075752 .inst = capture,
57085753 .token_src = payload_token,
5754 .used = .capture,
57095755 };
57105756 break :blk &capture_val_scope.base;
57115757 };
......@@ -5739,6 +5785,7 @@ fn switchExpr(
57395785 }
57405786
57415787 const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_loc, case.ast.target_expr);
5788 try checkUsed(parent_gz, &case_scope.base, sub_scope);
57425789 if (!parent_gz.refIsNoReturn(case_result)) {
57435790 block_scope.break_count += 1;
57445791 _ = try case_scope.addBreak(.@"break", switch_block, case_result);
......@@ -5752,6 +5799,7 @@ fn switchExpr(
57525799 const item_node = case.ast.values[0];
57535800 const item_inst = try comptimeExpr(parent_gz, scope, item_rl, item_node);
57545801 const case_result = try expr(&case_scope, sub_scope, block_scope.break_result_loc, case.ast.target_expr);
5802 try checkUsed(parent_gz, &case_scope.base, sub_scope);
57555803 if (!parent_gz.refIsNoReturn(case_result)) {
57565804 block_scope.break_count += 1;
57575805 _ = try case_scope.addBreak(.@"break", switch_block, case_result);
......@@ -5950,7 +5998,7 @@ fn switchExpr(
59505998 const block_ref = parent_gz.indexToRef(switch_block);
59515999 switch (rl) {
59526000 .ref => return block_ref,
5953 else => return rvalue(parent_gz, scope, rl, block_ref, switch_node),
6001 else => return rvalue(parent_gz, rl, block_ref, switch_node),
59546002 }
59556003 },
59566004 .break_void => {
......@@ -6016,7 +6064,6 @@ fn ret(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!Zir.Inst.Ref
60166064 const astgen = gz.astgen;
60176065 const tree = astgen.tree;
60186066 const node_datas = tree.nodes.items(.data);
6019 const main_tokens = tree.nodes.items(.main_token);
60206067
60216068 if (gz.in_defer) return astgen.failNode(node, "cannot return from defer expression", .{});
60226069
......@@ -6092,7 +6139,7 @@ fn identifier(
60926139 }
60936140
60946141 if (simple_types.get(ident_name)) |zir_const_ref| {
6095 return rvalue(gz, scope, rl, zir_const_ref, ident);
6142 return rvalue(gz, rl, zir_const_ref, ident);
60966143 }
60976144
60986145 if (ident_name.len >= 2) integer: {
......@@ -6118,7 +6165,7 @@ fn identifier(
61186165 .bit_count = bit_count,
61196166 } },
61206167 });
6121 return rvalue(gz, scope, rl, result, ident);
6168 return rvalue(gz, rl, result, ident);
61226169 }
61236170 }
61246171
......@@ -6131,33 +6178,37 @@ fn identifier(
61316178 while (true) switch (s.tag) {
61326179 .local_val => {
61336180 const local_val = s.cast(Scope.LocalVal).?;
6134 if (hit_namespace) {
6135 // captures of non-locals need to be emitted as decl_val or decl_ref
6136 // This *might* be capturable depending on if it is comptime known
6137 break;
6138 }
6181
61396182 if (local_val.name == name_str_index) {
6140 return rvalue(gz, scope, rl, local_val.inst, ident);
6183 local_val.used = .used;
6184 // Captures of non-locals need to be emitted as decl_val or decl_ref.
6185 // This *might* be capturable depending on if it is comptime known.
6186 if (!hit_namespace) {
6187 return rvalue(gz, rl, local_val.inst, ident);
6188 }
61416189 }
61426190 s = local_val.parent;
61436191 },
61446192 .local_ptr => {
61456193 const local_ptr = s.cast(Scope.LocalPtr).?;
61466194 if (local_ptr.name == name_str_index) {
6195 local_ptr.used = .used;
61476196 if (hit_namespace) {
6148 if (local_ptr.is_comptime)
6197 if (local_ptr.maybe_comptime)
61496198 break
61506199 else
61516200 return astgen.failNodeNotes(ident, "'{s}' not accessible from inner function", .{ident_name}, &.{
61526201 try astgen.errNoteTok(local_ptr.token_src, "declared here", .{}),
61536202 // TODO add crossed function definition here note.
6203 // Maybe add a note to the error about it being because of the var,
6204 // maybe recommend copying it into a const variable. -SpexGuy
61546205 });
61556206 }
61566207 switch (rl) {
61576208 .ref, .none_or_ref => return local_ptr.ptr,
61586209 else => {
61596210 const loaded = try gz.addUnNode(.load, local_ptr.ptr, ident);
6160 return rvalue(gz, scope, rl, loaded, ident);
6211 return rvalue(gz, rl, loaded, ident);
61616212 },
61626213 }
61636214 }
......@@ -6191,14 +6242,13 @@ fn identifier(
61916242 .ref, .none_or_ref => return gz.addStrTok(.decl_ref, name_str_index, ident_token),
61926243 else => {
61936244 const result = try gz.addStrTok(.decl_val, name_str_index, ident_token);
6194 return rvalue(gz, scope, rl, result, ident);
6245 return rvalue(gz, rl, result, ident);
61956246 },
61966247 }
61976248}
61986249
61996250fn stringLiteral(
62006251 gz: *GenZir,
6201 scope: *Scope,
62026252 rl: ResultLoc,
62036253 node: ast.Node.Index,
62046254) InnerError!Zir.Inst.Ref {
......@@ -6214,19 +6264,17 @@ fn stringLiteral(
62146264 .len = str.len,
62156265 } },
62166266 });
6217 return rvalue(gz, scope, rl, result, node);
6267 return rvalue(gz, rl, result, node);
62186268}
62196269
62206270fn multilineStringLiteral(
62216271 gz: *GenZir,
6222 scope: *Scope,
62236272 rl: ResultLoc,
62246273 node: ast.Node.Index,
62256274) InnerError!Zir.Inst.Ref {
62266275 const astgen = gz.astgen;
62276276 const tree = astgen.tree;
62286277 const node_datas = tree.nodes.items(.data);
6229 const main_tokens = tree.nodes.items(.main_token);
62306278
62316279 const start = node_datas[node].lhs;
62326280 const end = node_datas[node].rhs;
......@@ -6258,10 +6306,10 @@ fn multilineStringLiteral(
62586306 .len = @intCast(u32, string_bytes.items.len - str_index),
62596307 } },
62606308 });
6261 return rvalue(gz, scope, rl, result, node);
6309 return rvalue(gz, rl, result, node);
62626310}
62636311
6264fn charLiteral(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !Zir.Inst.Ref {
6312fn charLiteral(gz: *GenZir, rl: ResultLoc, node: ast.Node.Index) !Zir.Inst.Ref {
62656313 const astgen = gz.astgen;
62666314 const tree = astgen.tree;
62676315 const main_tokens = tree.nodes.items(.main_token);
......@@ -6281,15 +6329,10 @@ fn charLiteral(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index)
62816329 },
62826330 };
62836331 const result = try gz.addInt(value);
6284 return rvalue(gz, scope, rl, result, node);
6332 return rvalue(gz, rl, result, node);
62856333}
62866334
6287fn integerLiteral(
6288 gz: *GenZir,
6289 scope: *Scope,
6290 rl: ResultLoc,
6291 node: ast.Node.Index,
6292) InnerError!Zir.Inst.Ref {
6335fn integerLiteral(gz: *GenZir, rl: ResultLoc, node: ast.Node.Index) InnerError!Zir.Inst.Ref {
62936336 const astgen = gz.astgen;
62946337 const tree = astgen.tree;
62956338 const main_tokens = tree.nodes.items(.main_token);
......@@ -6301,7 +6344,7 @@ fn integerLiteral(
63016344 1 => .one,
63026345 else => try gz.addInt(small_int),
63036346 };
6304 return rvalue(gz, scope, rl, result, node);
6347 return rvalue(gz, rl, result, node);
63056348 } else |err| switch (err) {
63066349 error.InvalidCharacter => unreachable, // Caught by the parser.
63076350 error.Overflow => {},
......@@ -6332,17 +6375,11 @@ fn integerLiteral(
63326375 const limbs = big_int.limbs[0..big_int.len()];
63336376 assert(big_int.isPositive());
63346377 const result = try gz.addIntBig(limbs);
6335 return rvalue(gz, scope, rl, result, node);
6378 return rvalue(gz, rl, result, node);
63366379}
63376380
6338fn floatLiteral(
6339 gz: *GenZir,
6340 scope: *Scope,
6341 rl: ResultLoc,
6342 node: ast.Node.Index,
6343) InnerError!Zir.Inst.Ref {
6381fn floatLiteral(gz: *GenZir, rl: ResultLoc, node: ast.Node.Index) InnerError!Zir.Inst.Ref {
63446382 const astgen = gz.astgen;
6345 const arena = astgen.arena;
63466383 const tree = astgen.tree;
63476384 const main_tokens = tree.nodes.items(.main_token);
63486385
......@@ -6363,7 +6400,7 @@ fn floatLiteral(
63636400 const bigger_again: f128 = smaller_float;
63646401 if (bigger_again == float_number) {
63656402 const result = try gz.addFloat(smaller_float, node);
6366 return rvalue(gz, scope, rl, result, node);
6403 return rvalue(gz, rl, result, node);
63676404 }
63686405 // We need to use 128 bits. Break the float into 4 u32 values so we can
63696406 // put it into the `extra` array.
......@@ -6374,7 +6411,7 @@ fn floatLiteral(
63746411 .piece2 = @truncate(u32, int_bits >> 64),
63756412 .piece3 = @truncate(u32, int_bits >> 96),
63766413 });
6377 return rvalue(gz, scope, rl, result, node);
6414 return rvalue(gz, rl, result, node);
63786415}
63796416
63806417fn asmExpr(
......@@ -6385,7 +6422,6 @@ fn asmExpr(
63856422 full: ast.full.Asm,
63866423) InnerError!Zir.Inst.Ref {
63876424 const astgen = gz.astgen;
6388 const arena = astgen.arena;
63896425 const tree = astgen.tree;
63906426 const main_tokens = tree.nodes.items(.main_token);
63916427 const node_datas = tree.nodes.items(.data);
......@@ -6427,6 +6463,33 @@ fn asmExpr(
64276463 // issues and decide how to handle outputs. Do we want this to be identifiers?
64286464 // Or maybe we want to force this to be expressions with a pointer type.
64296465 // Until that is figured out this is only hooked up for referencing Decls.
6466 // TODO we have put this as an identifier lookup just so that we don't get
6467 // unused vars for outputs. We need to check if this is correct in the future ^^
6468 // so we just put in this simple lookup. This is a workaround.
6469 {
6470 var s = scope;
6471 while (true) switch (s.tag) {
6472 .local_val => {
6473 const local_val = s.cast(Scope.LocalVal).?;
6474 if (local_val.name == str_index) {
6475 local_val.used = .used;
6476 break;
6477 }
6478 s = local_val.parent;
6479 },
6480 .local_ptr => {
6481 const local_ptr = s.cast(Scope.LocalPtr).?;
6482 if (local_ptr.name == str_index) {
6483 local_ptr.used = .used;
6484 break;
6485 }
6486 s = local_ptr.parent;
6487 },
6488 .gen_zir => s = s.cast(GenZir).?.parent,
6489 .defer_normal, .defer_error => s = s.cast(Scope.Defer).?.parent,
6490 .namespace, .top => break,
6491 };
6492 }
64306493 const operand = try gz.addStrTok(.decl_ref, str_index, ident_token);
64316494 outputs[i] = .{
64326495 .name = name,
......@@ -6447,7 +6510,6 @@ fn asmExpr(
64476510 const name = try astgen.identAsString(symbolic_name);
64486511 const constraint_token = symbolic_name + 2;
64496512 const constraint = (try astgen.strLitAsString(constraint_token)).index;
6450 const has_arrow = token_tags[symbolic_name + 4] == .arrow;
64516513 const operand = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[input_node].lhs);
64526514 inputs[i] = .{
64536515 .name = name,
......@@ -6492,7 +6554,7 @@ fn asmExpr(
64926554 .inputs = inputs,
64936555 .clobbers = clobbers_buffer[0..clobber_i],
64946556 });
6495 return rvalue(gz, scope, rl, result, node);
6557 return rvalue(gz, rl, result, node);
64966558}
64976559
64986560fn as(
......@@ -6507,7 +6569,7 @@ fn as(
65076569 switch (rl) {
65086570 .none, .none_or_ref, .discard, .ref, .ty => {
65096571 const result = try expr(gz, scope, .{ .ty = dest_type }, rhs);
6510 return rvalue(gz, scope, rl, result, node);
6572 return rvalue(gz, rl, result, node);
65116573 },
65126574 .ptr, .inferred_ptr => |result_ptr| {
65136575 return asRlPtr(gz, scope, rl, result_ptr, rhs, dest_type);
......@@ -6529,18 +6591,18 @@ fn unionInit(
65296591 const field_name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[1]);
65306592 switch (rl) {
65316593 .none, .none_or_ref, .discard, .ref, .ty, .inferred_ptr => {
6532 const field_type = try gz.addPlNode(.field_type_ref, params[1], Zir.Inst.FieldTypeRef{
6594 _ = try gz.addPlNode(.field_type_ref, params[1], Zir.Inst.FieldTypeRef{
65336595 .container_type = union_type,
65346596 .field_name = field_name,
65356597 });
65366598 const result = try expr(gz, scope, .{ .ty = union_type }, params[2]);
6537 return rvalue(gz, scope, rl, result, node);
6599 return rvalue(gz, rl, result, node);
65386600 },
65396601 .ptr => |result_ptr| {
6540 return unionInitRlPtr(gz, scope, rl, node, result_ptr, params[2], union_type, field_name);
6602 return unionInitRlPtr(gz, scope, node, result_ptr, params[2], union_type, field_name);
65416603 },
65426604 .block_ptr => |block_scope| {
6543 return unionInitRlPtr(gz, scope, rl, node, block_scope.rl_ptr, params[2], union_type, field_name);
6605 return unionInitRlPtr(gz, scope, node, block_scope.rl_ptr, params[2], union_type, field_name);
65446606 },
65456607 }
65466608}
......@@ -6548,7 +6610,6 @@ fn unionInit(
65486610fn unionInitRlPtr(
65496611 parent_gz: *GenZir,
65506612 scope: *Scope,
6551 rl: ResultLoc,
65526613 node: ast.Node.Index,
65536614 result_ptr: Zir.Inst.Ref,
65546615 expr_node: ast.Node.Index,
......@@ -6596,7 +6657,7 @@ fn asRlPtr(
65966657 parent_zir.appendAssumeCapacity(src_inst);
65976658 }
65986659 const casted_result = try parent_gz.addBin(.as, dest_type, result);
6599 return rvalue(parent_gz, scope, rl, casted_result, operand_node);
6660 return rvalue(parent_gz, rl, casted_result, operand_node);
66006661 } else {
66016662 try parent_zir.appendSlice(astgen.gpa, as_scope.instructions.items);
66026663 return result;
......@@ -6620,16 +6681,16 @@ fn bitCast(
66206681 .lhs = dest_type,
66216682 .rhs = operand,
66226683 });
6623 return rvalue(gz, scope, rl, result, node);
6684 return rvalue(gz, rl, result, node);
66246685 },
66256686 .ref => {
66266687 return astgen.failNode(node, "cannot take address of `@bitCast` result", .{});
66276688 },
66286689 .ptr, .inferred_ptr => |result_ptr| {
6629 return bitCastRlPtr(gz, scope, rl, node, dest_type, result_ptr, rhs);
6690 return bitCastRlPtr(gz, scope, node, dest_type, result_ptr, rhs);
66306691 },
66316692 .block_ptr => |block| {
6632 return bitCastRlPtr(gz, scope, rl, node, dest_type, block.rl_ptr, rhs);
6693 return bitCastRlPtr(gz, scope, node, dest_type, block.rl_ptr, rhs);
66336694 },
66346695 }
66356696}
......@@ -6637,7 +6698,6 @@ fn bitCast(
66376698fn bitCastRlPtr(
66386699 gz: *GenZir,
66396700 scope: *Scope,
6640 rl: ResultLoc,
66416701 node: ast.Node.Index,
66426702 dest_type: Zir.Inst.Ref,
66436703 result_ptr: Zir.Inst.Ref,
......@@ -6662,7 +6722,7 @@ fn typeOf(
66626722 }
66636723 if (params.len == 1) {
66646724 const result = try gz.addUnNode(.typeof, try expr(gz, scope, .none, params[0]), node);
6665 return rvalue(gz, scope, rl, result, node);
6725 return rvalue(gz, rl, result, node);
66666726 }
66676727 const arena = gz.astgen.arena;
66686728 var items = try arena.alloc(Zir.Inst.Ref, params.len);
......@@ -6671,7 +6731,7 @@ fn typeOf(
66716731 }
66726732
66736733 const result = try gz.addExtendedMultiOp(.typeof_peer, node, items);
6674 return rvalue(gz, scope, rl, result, node);
6734 return rvalue(gz, rl, result, node);
66756735}
66766736
66776737fn builtinCall(
......@@ -6711,7 +6771,6 @@ fn builtinCall(
67116771 switch (info.tag) {
67126772 .import => {
67136773 const node_tags = tree.nodes.items(.tag);
6714 const node_datas = tree.nodes.items(.data);
67156774 const operand_node = params[0];
67166775
67176776 if (node_tags[operand_node] != .string_literal) {
......@@ -6722,7 +6781,7 @@ fn builtinCall(
67226781 const str = try astgen.strLitAsString(str_lit_token);
67236782 try astgen.imports.put(astgen.gpa, str.index, {});
67246783 const result = try gz.addStrTok(.import, str.index, str_lit_token);
6725 return rvalue(gz, scope, rl, result, node);
6784 return rvalue(gz, rl, result, node);
67266785 },
67276786 .compile_log => {
67286787 const arg_refs = try astgen.gpa.alloc(Zir.Inst.Ref, params.len);
......@@ -6731,7 +6790,7 @@ fn builtinCall(
67316790 for (params) |param, i| arg_refs[i] = try expr(gz, scope, .none, param);
67326791
67336792 const result = try gz.addExtendedMultiOp(.compile_log, node, arg_refs);
6734 return rvalue(gz, scope, rl, result, node);
6793 return rvalue(gz, rl, result, node);
67356794 },
67366795 .field => {
67376796 const field_name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[1]);
......@@ -6745,7 +6804,7 @@ fn builtinCall(
67456804 .lhs = try expr(gz, scope, .none, params[0]),
67466805 .field_name = field_name,
67476806 });
6748 return rvalue(gz, scope, rl, result, node);
6807 return rvalue(gz, rl, result, node);
67496808 },
67506809 .as => return as( gz, scope, rl, node, params[0], params[1]),
67516810 .bit_cast => return bitCast( gz, scope, rl, node, params[0], params[1]),
......@@ -6764,9 +6823,32 @@ fn builtinCall(
67646823 .identifier => {
67656824 const ident_token = main_tokens[params[0]];
67666825 decl_name = try astgen.identAsString(ident_token);
6767 // TODO look for local variables in scope matching `decl_name` and emit a compile
6768 // error. Only top-level declarations can be exported. Until this is done, the
6769 // compile error will end up being "use of undeclared identifier" in Sema.
6826 {
6827 var s = scope;
6828 while (true) switch (s.tag) {
6829 .local_val => {
6830 const local_val = s.cast(Scope.LocalVal).?;
6831 if (local_val.name == decl_name) {
6832 local_val.used = .used;
6833 break;
6834 }
6835 s = local_val.parent;
6836 },
6837 .local_ptr => {
6838 const local_ptr = s.cast(Scope.LocalPtr).?;
6839 if (local_ptr.name == decl_name) {
6840 if (!local_ptr.maybe_comptime)
6841 return astgen.failNode(params[0], "unable to export runtime-known value", .{});
6842 local_ptr.used = .used;
6843 break;
6844 }
6845 s = local_ptr.parent;
6846 },
6847 .gen_zir => s = s.cast(GenZir).?.parent,
6848 .defer_normal, .defer_error => s = s.cast(Scope.Defer).?.parent,
6849 .namespace, .top => break,
6850 };
6851 }
67706852 },
67716853 .field_access => {
67726854 const namespace_node = node_datas[params[0]].lhs;
......@@ -6776,7 +6858,7 @@ fn builtinCall(
67766858 decl_name = try astgen.identAsString(field_ident);
67776859 },
67786860 else => return astgen.failNode(
6779 params[0], "the first @export parameter must be an identifier", .{},
6861 params[0], "symbol to export must identify a declaration", .{},
67806862 ),
67816863 }
67826864 const options = try comptimeExpr(gz, scope, .{ .ty = .export_options_type }, params[1]);
......@@ -6785,7 +6867,7 @@ fn builtinCall(
67856867 .decl_name = decl_name,
67866868 .options = options,
67876869 });
6788 return rvalue(gz, scope, rl, .void_value, node);
6870 return rvalue(gz, rl, .void_value, node);
67896871 },
67906872 .@"extern" => {
67916873 const type_inst = try typeExpr(gz, scope, params[0]);
......@@ -6795,18 +6877,18 @@ fn builtinCall(
67956877 .lhs = type_inst,
67966878 .rhs = options,
67976879 });
6798 return rvalue(gz, scope, rl, result, node);
6880 return rvalue(gz, rl, result, node);
67996881 },
68006882
6801 .breakpoint => return simpleNoOpVoid(gz, scope, rl, node, .breakpoint),
6802 .fence => return simpleNoOpVoid(gz, scope, rl, node, .fence),
6883 .breakpoint => return simpleNoOpVoid(gz, rl, node, .breakpoint),
6884 .fence => return simpleNoOpVoid(gz, rl, node, .fence),
68036885
6804 .This => return rvalue(gz, scope, rl, try gz.addNodeExtended(.this, node), node),
6805 .return_address => return rvalue(gz, scope, rl, try gz.addNodeExtended(.ret_addr, node), node),
6806 .src => return rvalue(gz, scope, rl, try gz.addNodeExtended(.builtin_src, node), node),
6807 .error_return_trace => return rvalue(gz, scope, rl, try gz.addNodeExtended(.error_return_trace, node), node),
6808 .frame => return rvalue(gz, scope, rl, try gz.addNodeExtended(.frame, node), node),
6809 .frame_address => return rvalue(gz, scope, rl, try gz.addNodeExtended(.frame_address, node), node),
6886 .This => return rvalue(gz, rl, try gz.addNodeExtended(.this, node), node),
6887 .return_address => return rvalue(gz, rl, try gz.addNodeExtended(.ret_addr, node), node),
6888 .src => return rvalue(gz, rl, try gz.addNodeExtended(.builtin_src, node), node),
6889 .error_return_trace => return rvalue(gz, rl, try gz.addNodeExtended(.error_return_trace, node), node),
6890 .frame => return rvalue(gz, rl, try gz.addNodeExtended(.frame, node), node),
6891 .frame_address => return rvalue(gz, rl, try gz.addNodeExtended(.frame_address, node), node),
68106892
68116893 .type_info => return simpleUnOpType(gz, scope, rl, node, params[0], .type_info),
68126894 .size_of => return simpleUnOpType(gz, scope, rl, node, params[0], .size_of),
......@@ -6862,7 +6944,7 @@ fn builtinCall(
68626944 .lhs = dest_align,
68636945 .rhs = rhs,
68646946 });
6865 return rvalue(gz, scope, rl, result, node);
6947 return rvalue(gz, rl, result, node);
68666948 },
68676949
68686950 .has_decl => return hasDeclOrField(gz, scope, rl, node, params[0], params[1], .has_decl),
......@@ -6898,7 +6980,7 @@ fn builtinCall(
68986980 .node = gz.nodeIndexToRelative(node),
68996981 .operand = operand,
69006982 });
6901 return rvalue(gz, scope, rl, result, node);
6983 return rvalue(gz, rl, result, node);
69026984 },
69036985 .wasm_memory_grow => {
69046986 const index_arg = try expr(gz, scope, .{ .ty = .u32_type }, params[0]);
......@@ -6908,7 +6990,7 @@ fn builtinCall(
69086990 .lhs = index_arg,
69096991 .rhs = delta_arg,
69106992 });
6911 return rvalue(gz, scope, rl, result, node);
6993 return rvalue(gz, rl, result, node);
69126994 },
69136995 .c_define => {
69146996 const name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[0]);
......@@ -6918,7 +7000,7 @@ fn builtinCall(
69187000 .lhs = name,
69197001 .rhs = value,
69207002 });
6921 return rvalue(gz, scope, rl, result, node);
7003 return rvalue(gz, rl, result, node);
69227004 },
69237005
69247006 .splat => {
......@@ -6928,7 +7010,7 @@ fn builtinCall(
69287010 .lhs = len,
69297011 .rhs = scalar,
69307012 });
6931 return rvalue(gz, scope, rl, result, node);
7013 return rvalue(gz, rl, result, node);
69327014 },
69337015 .reduce => {
69347016 const op = try expr(gz, scope, .{ .ty = .reduce_op_type }, params[0]);
......@@ -6937,7 +7019,7 @@ fn builtinCall(
69377019 .lhs = op,
69387020 .rhs = scalar,
69397021 });
6940 return rvalue(gz, scope, rl, result, node);
7022 return rvalue(gz, rl, result, node);
69417023 },
69427024
69437025 .add_with_overflow => return overflowArithmetic(gz, scope, rl, node, params, .add_with_overflow),
......@@ -6964,7 +7046,7 @@ fn builtinCall(
69647046 .rhs = rhs,
69657047 .ptr = ptr,
69667048 });
6967 return rvalue(gz, scope, rl, result, node);
7049 return rvalue(gz, rl, result, node);
69687050 },
69697051
69707052 .atomic_load => {
......@@ -6984,7 +7066,7 @@ fn builtinCall(
69847066 .lhs = ptr,
69857067 .rhs = ordering,
69867068 });
6987 return rvalue(gz, scope, rl, result, node);
7069 return rvalue(gz, rl, result, node);
69887070 },
69897071 .atomic_rmw => {
69907072 const int_type = try typeExpr(gz, scope, params[0]);
......@@ -7007,7 +7089,7 @@ fn builtinCall(
70077089 .operand = operand,
70087090 .ordering = ordering,
70097091 });
7010 return rvalue(gz, scope, rl, result, node);
7092 return rvalue(gz, rl, result, node);
70117093 },
70127094 .atomic_store => {
70137095 const int_type = try typeExpr(gz, scope, params[0]);
......@@ -7028,7 +7110,7 @@ fn builtinCall(
70287110 .operand = operand,
70297111 .ordering = ordering,
70307112 });
7031 return rvalue(gz, scope, rl, result, node);
7113 return rvalue(gz, rl, result, node);
70327114 },
70337115 .mul_add => {
70347116 const float_type = try typeExpr(gz, scope, params[0]);
......@@ -7040,7 +7122,7 @@ fn builtinCall(
70407122 .mulend2 = mulend2,
70417123 .addend = addend,
70427124 });
7043 return rvalue(gz, scope, rl, result, node);
7125 return rvalue(gz, rl, result, node);
70447126 },
70457127 .call => {
70467128 const options = try comptimeExpr(gz, scope, .{ .ty = .call_options_type }, params[0]);
......@@ -7051,7 +7133,7 @@ fn builtinCall(
70517133 .callee = callee,
70527134 .args = args,
70537135 });
7054 return rvalue(gz, scope, rl, result, node);
7136 return rvalue(gz, rl, result, node);
70557137 },
70567138 .field_parent_ptr => {
70577139 const parent_type = try typeExpr(gz, scope, params[0]);
......@@ -7062,7 +7144,7 @@ fn builtinCall(
70627144 .field_name = field_name,
70637145 .field_ptr = try expr(gz, scope, .{ .ty = field_ptr_type }, params[2]),
70647146 });
7065 return rvalue(gz, scope, rl, result, node);
7147 return rvalue(gz, rl, result, node);
70667148 },
70677149 .memcpy => {
70687150 const result = try gz.addPlNode(.memcpy, node, Zir.Inst.Memcpy{
......@@ -7070,7 +7152,7 @@ fn builtinCall(
70707152 .source = try expr(gz, scope, .{ .ty = .manyptr_const_u8_type }, params[1]),
70717153 .byte_count = try expr(gz, scope, .{ .ty = .usize_type }, params[2]),
70727154 });
7073 return rvalue(gz, scope, rl, result, node);
7155 return rvalue(gz, rl, result, node);
70747156 },
70757157 .memset => {
70767158 const result = try gz.addPlNode(.memset, node, Zir.Inst.Memset{
......@@ -7078,7 +7160,7 @@ fn builtinCall(
70787160 .byte = try expr(gz, scope, .{ .ty = .u8_type }, params[1]),
70797161 .byte_count = try expr(gz, scope, .{ .ty = .usize_type }, params[2]),
70807162 });
7081 return rvalue(gz, scope, rl, result, node);
7163 return rvalue(gz, rl, result, node);
70827164 },
70837165 .shuffle => {
70847166 const result = try gz.addPlNode(.shuffle, node, Zir.Inst.Shuffle{
......@@ -7087,7 +7169,7 @@ fn builtinCall(
70877169 .b = try expr(gz, scope, .none, params[2]),
70887170 .mask = try comptimeExpr(gz, scope, .none, params[3]),
70897171 });
7090 return rvalue(gz, scope, rl, result, node);
7172 return rvalue(gz, rl, result, node);
70917173 },
70927174 .async_call => {
70937175 const result = try gz.addPlNode(.builtin_async_call, node, Zir.Inst.AsyncCall{
......@@ -7096,14 +7178,14 @@ fn builtinCall(
70967178 .fn_ptr = try expr(gz, scope, .none, params[2]),
70977179 .args = try expr(gz, scope, .none, params[3]),
70987180 });
7099 return rvalue(gz, scope, rl, result, node);
7181 return rvalue(gz, rl, result, node);
71007182 },
71017183 .Vector => {
71027184 const result = try gz.addPlNode(.vector_type, node, Zir.Inst.Bin{
71037185 .lhs = try comptimeExpr(gz, scope, .{.ty = .u32_type}, params[0]),
71047186 .rhs = try typeExpr(gz, scope, params[1]),
71057187 });
7106 return rvalue(gz, scope, rl, result, node);
7188 return rvalue(gz, rl, result, node);
71077189 },
71087190
71097191 }
......@@ -7112,13 +7194,12 @@ fn builtinCall(
71127194
71137195fn simpleNoOpVoid(
71147196 gz: *GenZir,
7115 scope: *Scope,
71167197 rl: ResultLoc,
71177198 node: ast.Node.Index,
71187199 tag: Zir.Inst.Tag,
71197200) InnerError!Zir.Inst.Ref {
71207201 _ = try gz.addNode(tag, node);
7121 return rvalue(gz, scope, rl, .void_value, node);
7202 return rvalue(gz, rl, .void_value, node);
71227203}
71237204
71247205fn hasDeclOrField(
......@@ -7136,7 +7217,7 @@ fn hasDeclOrField(
71367217 .lhs = container_type,
71377218 .rhs = name,
71387219 });
7139 return rvalue(gz, scope, rl, result, node);
7220 return rvalue(gz, rl, result, node);
71407221}
71417222
71427223fn typeCast(
......@@ -7152,7 +7233,7 @@ fn typeCast(
71527233 .lhs = try typeExpr(gz, scope, lhs_node),
71537234 .rhs = try expr(gz, scope, .none, rhs_node),
71547235 });
7155 return rvalue(gz, scope, rl, result, node);
7236 return rvalue(gz, rl, result, node);
71567237}
71577238
71587239fn simpleUnOpType(
......@@ -7165,7 +7246,7 @@ fn simpleUnOpType(
71657246) InnerError!Zir.Inst.Ref {
71667247 const operand = try typeExpr(gz, scope, operand_node);
71677248 const result = try gz.addUnNode(tag, operand, node);
7168 return rvalue(gz, scope, rl, result, node);
7249 return rvalue(gz, rl, result, node);
71697250}
71707251
71717252fn simpleUnOp(
......@@ -7179,7 +7260,7 @@ fn simpleUnOp(
71797260) InnerError!Zir.Inst.Ref {
71807261 const operand = try expr(gz, scope, operand_rl, operand_node);
71817262 const result = try gz.addUnNode(tag, operand, node);
7182 return rvalue(gz, scope, rl, result, node);
7263 return rvalue(gz, rl, result, node);
71837264}
71847265
71857266fn cmpxchg(
......@@ -7209,7 +7290,7 @@ fn cmpxchg(
72097290 .fail_order = try expr(gz, scope, .{ .ty = .atomic_ordering_type }, params[5]),
72107291 // zig fmt: on
72117292 });
7212 return rvalue(gz, scope, rl, result, node);
7293 return rvalue(gz, rl, result, node);
72137294}
72147295
72157296fn bitBuiltin(
......@@ -7224,7 +7305,7 @@ fn bitBuiltin(
72247305 const int_type = try typeExpr(gz, scope, int_type_node);
72257306 const operand = try expr(gz, scope, .{ .ty = int_type }, operand_node);
72267307 const result = try gz.addUnNode(tag, operand, node);
7227 return rvalue(gz, scope, rl, result, node);
7308 return rvalue(gz, rl, result, node);
72287309}
72297310
72307311fn divBuiltin(
......@@ -7240,7 +7321,7 @@ fn divBuiltin(
72407321 .lhs = try expr(gz, scope, .none, lhs_node),
72417322 .rhs = try expr(gz, scope, .none, rhs_node),
72427323 });
7243 return rvalue(gz, scope, rl, result, node);
7324 return rvalue(gz, rl, result, node);
72447325}
72457326
72467327fn simpleCBuiltin(
......@@ -7256,7 +7337,7 @@ fn simpleCBuiltin(
72567337 .node = gz.nodeIndexToRelative(node),
72577338 .operand = operand,
72587339 });
7259 return rvalue(gz, scope, rl, .void_value, node);
7340 return rvalue(gz, rl, .void_value, node);
72607341}
72617342
72627343fn offsetOf(
......@@ -7274,7 +7355,7 @@ fn offsetOf(
72747355 .lhs = type_inst,
72757356 .rhs = field_name,
72767357 });
7277 return rvalue(gz, scope, rl, result, node);
7358 return rvalue(gz, rl, result, node);
72787359}
72797360
72807361fn shiftOp(
......@@ -7293,7 +7374,7 @@ fn shiftOp(
72937374 .lhs = lhs,
72947375 .rhs = rhs,
72957376 });
7296 return rvalue(gz, scope, rl, result, node);
7377 return rvalue(gz, rl, result, node);
72977378}
72987379
72997380fn cImport(
......@@ -7318,7 +7399,7 @@ fn cImport(
73187399 try block_scope.setBlockBody(block_inst);
73197400 try gz.instructions.append(gpa, block_inst);
73207401
7321 return rvalue(gz, scope, rl, .void_value, node);
7402 return rvalue(gz, rl, .void_value, node);
73227403}
73237404
73247405fn overflowArithmetic(
......@@ -7348,7 +7429,7 @@ fn overflowArithmetic(
73487429 .rhs = rhs,
73497430 .ptr = ptr,
73507431 });
7351 return rvalue(gz, scope, rl, result, node);
7432 return rvalue(gz, rl, result, node);
73527433}
73537434
73547435fn callExpr(
......@@ -7400,7 +7481,7 @@ fn callExpr(
74007481 };
74017482 break :res try gz.addCall(tag, lhs, args, node);
74027483 };
7403 return rvalue(gz, scope, rl, result, node); // TODO function call with result location
7484 return rvalue(gz, rl, result, node); // TODO function call with result location
74047485}
74057486
74067487pub const simple_types = std.ComptimeStringMap(Zir.Inst.Ref, .{
......@@ -7876,7 +7957,6 @@ fn nodeMayEvalToError(tree: *const ast.Tree, start_node: ast.Node.Index) enum {
78767957/// If the `ResultLoc` is `ty`, it will coerce the result to the type.
78777958fn rvalue(
78787959 gz: *GenZir,
7879 scope: *Scope,
78807960 rl: ResultLoc,
78817961 result: Zir.Inst.Ref,
78827962 src_node: ast.Node.Index,
......@@ -8024,7 +8104,6 @@ fn parseStrLit(
80248104 bytes: []const u8,
80258105 offset: u32,
80268106) InnerError!void {
8027 const tree = astgen.tree;
80288107 const raw_string = bytes[offset..];
80298108 var buf_managed = buf.toManaged(astgen.gpa);
80308109 const result = std.zig.string_literal.parseAppend(&buf_managed, raw_string);
......@@ -8327,6 +8406,15 @@ const Scope = struct {
83278406 top,
83288407 };
83298408
8409 // either .used or the type of the var/constant
8410 const Used = enum {
8411 fn_param,
8412 constant,
8413 variable,
8414 loop_index,
8415 capture,
8416 used,
8417 };
83308418 /// This is always a `const` local and importantly the `inst` is a value type, not a pointer.
83318419 /// This structure lives as long as the AST generation of the Block
83328420 /// node that contains the variable.
......@@ -8341,6 +8429,8 @@ const Scope = struct {
83418429 token_src: ast.TokenIndex,
83428430 /// String table index.
83438431 name: u32,
8432 /// has this variable been referenced?
8433 used: Used,
83448434 };
83458435
83468436 /// This could be a `const` or `var` local. It has a pointer instead of a value.
......@@ -8357,7 +8447,10 @@ const Scope = struct {
83578447 token_src: ast.TokenIndex,
83588448 /// String table index.
83598449 name: u32,
8360 is_comptime: bool,
8450 /// true means we find out during Sema whether the value is comptime. false means it is already known at AstGen the value is runtime-known.
8451 maybe_comptime: bool,
8452 /// has this variable been referenced?
8453 used: Used,
83618454 };
83628455
83638456 const Defer = struct {
......@@ -8467,7 +8560,6 @@ const GenZir = struct {
84678560 fn calcLine(gz: GenZir, node: ast.Node.Index) u32 {
84688561 const astgen = gz.astgen;
84698562 const tree = astgen.tree;
8470 const node_tags = tree.nodes.items(.tag);
84718563 const token_starts = tree.tokens.items(.start);
84728564 const decl_start = token_starts[tree.firstToken(gz.decl_node_index)];
84738565 const node_start = token_starts[tree.firstToken(node)];
src/Compilation.zig+8-4
......@@ -325,7 +325,6 @@ pub const AllErrors = struct {
325325 },
326326
327327 pub fn renderToStdErr(msg: Message, ttyconf: std.debug.TTY.Config) void {
328 const stderr_mutex = std.debug.getStderrMutex();
329328 const held = std.debug.getStderrMutex().acquire();
330329 defer held.release();
331330 const stderr = std.io.getStdErr();
......@@ -524,6 +523,7 @@ pub const AllErrors = struct {
524523 errors: *std.ArrayList(Message),
525524 msg: []const u8,
526525 ) !void {
526 _ = arena;
527527 try errors.append(.{ .plain = .{ .msg = msg } });
528528 }
529529
......@@ -1639,7 +1639,7 @@ pub fn update(self: *Compilation) !void {
16391639 // Make sure std.zig is inside the import_table. We unconditionally need
16401640 // it for start.zig.
16411641 const std_pkg = module.root_pkg.table.get("std").?;
1642 _ = try module.importPkg(module.root_pkg, std_pkg);
1642 _ = try module.importPkg(std_pkg);
16431643
16441644 // Put a work item in for every known source file to detect if
16451645 // it changed, and, if so, re-compute ZIR and then queue the job
......@@ -2283,8 +2283,12 @@ fn workerAstGenFile(
22832283) void {
22842284 defer wg.finish();
22852285
2286 var child_prog_node = prog_node.start(file.sub_file_path, 0);
2287 child_prog_node.activate();
2288 defer child_prog_node.end();
2289
22862290 const mod = comp.bin_file.options.module.?;
2287 mod.astGenFile(file, prog_node) catch |err| switch (err) {
2291 mod.astGenFile(file) catch |err| switch (err) {
22882292 error.AnalysisFail => return,
22892293 else => {
22902294 file.status = .retryable_failure;
......@@ -2373,7 +2377,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult {
23732377 // We need to "unhit" in this case, to keep the digests matching.
23742378 const prev_hash_state = man.hash.peekBin();
23752379 const actual_hit = hit: {
2376 const is_hit = try man.hit();
2380 _ = try man.hit();
23772381 if (man.files.items.len == 0) {
23782382 man.unhit(prev_hash_state, 0);
23792383 break :hit false;
src/DepTokenizer.zig+2-3
......@@ -944,7 +944,7 @@ fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {
944944 try out.writeAll(text);
945945 var i: usize = text.len;
946946 const end = 79;
947 while (i < 79) : (i += 1) {
947 while (i < end) : (i += 1) {
948948 try out.writeAll(&[_]u8{label[0]});
949949 }
950950 try out.writeAll("\n");
......@@ -953,7 +953,7 @@ fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {
953953fn printRuler(out: anytype) !void {
954954 var i: usize = 0;
955955 const end = 79;
956 while (i < 79) : (i += 1) {
956 while (i < end) : (i += 1) {
957957 try out.writeAll("-");
958958 }
959959 try out.writeAll("\n");
......@@ -1057,4 +1057,3 @@ const printable_char_tab: [256]u8 = (
10571057 "................................................................" ++
10581058 "................................................................"
10591059).*;
1060
src/Module.zig+24-25
......@@ -774,7 +774,10 @@ pub const Fn = struct {
774774 ir.dumpFn(mod, func);
775775 }
776776
777 pub fn deinit(func: *Fn, gpa: *Allocator) void {}
777 pub fn deinit(func: *Fn, gpa: *Allocator) void {
778 _ = func;
779 _ = gpa;
780 }
778781};
779782
780783pub const Var = struct {
......@@ -1561,7 +1564,6 @@ pub const SrcLoc = struct {
15611564 .node_offset_array_access_index => |node_off| {
15621565 const tree = try src_loc.file_scope.getTree(gpa);
15631566 const node_datas = tree.nodes.items(.data);
1564 const node_tags = tree.nodes.items(.tag);
15651567 const node = src_loc.declRelativeToNodeIndex(node_off);
15661568 const main_tokens = tree.nodes.items(.main_token);
15671569 const tok_index = main_tokens[node_datas[node].rhs];
......@@ -1570,7 +1572,6 @@ pub const SrcLoc = struct {
15701572 },
15711573 .node_offset_slice_sentinel => |node_off| {
15721574 const tree = try src_loc.file_scope.getTree(gpa);
1573 const node_datas = tree.nodes.items(.data);
15741575 const node_tags = tree.nodes.items(.tag);
15751576 const node = src_loc.declRelativeToNodeIndex(node_off);
15761577 const full = switch (node_tags[node]) {
......@@ -1586,7 +1587,6 @@ pub const SrcLoc = struct {
15861587 },
15871588 .node_offset_call_func => |node_off| {
15881589 const tree = try src_loc.file_scope.getTree(gpa);
1589 const node_datas = tree.nodes.items(.data);
15901590 const node_tags = tree.nodes.items(.tag);
15911591 const node = src_loc.declRelativeToNodeIndex(node_off);
15921592 var params: [1]ast.Node.Index = undefined;
......@@ -1625,7 +1625,6 @@ pub const SrcLoc = struct {
16251625 .node_offset_deref_ptr => |node_off| {
16261626 const tree = try src_loc.file_scope.getTree(gpa);
16271627 const node_datas = tree.nodes.items(.data);
1628 const node_tags = tree.nodes.items(.tag);
16291628 const node = src_loc.declRelativeToNodeIndex(node_off);
16301629 const tok_index = node_datas[node].lhs;
16311630 const token_starts = tree.tokens.items(.start);
......@@ -1633,7 +1632,6 @@ pub const SrcLoc = struct {
16331632 },
16341633 .node_offset_asm_source => |node_off| {
16351634 const tree = try src_loc.file_scope.getTree(gpa);
1636 const node_datas = tree.nodes.items(.data);
16371635 const node_tags = tree.nodes.items(.tag);
16381636 const node = src_loc.declRelativeToNodeIndex(node_off);
16391637 const full = switch (node_tags[node]) {
......@@ -1648,7 +1646,6 @@ pub const SrcLoc = struct {
16481646 },
16491647 .node_offset_asm_ret_ty => |node_off| {
16501648 const tree = try src_loc.file_scope.getTree(gpa);
1651 const node_datas = tree.nodes.items(.data);
16521649 const node_tags = tree.nodes.items(.tag);
16531650 const node = src_loc.declRelativeToNodeIndex(node_off);
16541651 const full = switch (node_tags[node]) {
......@@ -1771,7 +1768,6 @@ pub const SrcLoc = struct {
17711768
17721769 .node_offset_fn_type_cc => |node_off| {
17731770 const tree = try src_loc.file_scope.getTree(gpa);
1774 const node_datas = tree.nodes.items(.data);
17751771 const node_tags = tree.nodes.items(.tag);
17761772 const node = src_loc.declRelativeToNodeIndex(node_off);
17771773 var params: [1]ast.Node.Index = undefined;
......@@ -1790,7 +1786,6 @@ pub const SrcLoc = struct {
17901786
17911787 .node_offset_fn_type_ret_ty => |node_off| {
17921788 const tree = try src_loc.file_scope.getTree(gpa);
1793 const node_datas = tree.nodes.items(.data);
17941789 const node_tags = tree.nodes.items(.tag);
17951790 const node = src_loc.declRelativeToNodeIndex(node_off);
17961791 var params: [1]ast.Node.Index = undefined;
......@@ -1810,7 +1805,6 @@ pub const SrcLoc = struct {
18101805 .node_offset_anyframe_type => |node_off| {
18111806 const tree = try src_loc.file_scope.getTree(gpa);
18121807 const node_datas = tree.nodes.items(.data);
1813 const node_tags = tree.nodes.items(.tag);
18141808 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
18151809 const node = node_datas[parent_node].rhs;
18161810 const main_tokens = tree.nodes.items(.main_token);
......@@ -2217,7 +2211,7 @@ comptime {
22172211 }
22182212}
22192213
2220pub fn astGenFile(mod: *Module, file: *Scope.File, prog_node: *std.Progress.Node) !void {
2214pub fn astGenFile(mod: *Module, file: *Scope.File) !void {
22212215 const tracy = trace(@src());
22222216 defer tracy.end();
22232217
......@@ -2502,7 +2496,6 @@ pub fn astGenFile(mod: *Module, file: *Scope.File, prog_node: *std.Progress.Node
25022496 @ptrCast([*]const u8, file.zir.instructions.items(.data).ptr);
25032497 if (data_has_safety_tag) {
25042498 // The `Data` union has a safety tag but in the file format we store it without.
2505 const tags = file.zir.instructions.items(.tag);
25062499 for (file.zir.instructions.items(.data)) |*data, i| {
25072500 const as_struct = @ptrCast(*const Stage1DataLayout, data);
25082501 safety_buffer[i] = as_struct.data;
......@@ -2838,7 +2831,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl: *Decl) InnerError!void {
28382831}
28392832
28402833pub fn semaPkg(mod: *Module, pkg: *Package) !void {
2841 const file = (try mod.importPkg(mod.root_pkg, pkg)).file;
2834 const file = (try mod.importPkg(pkg)).file;
28422835 return mod.semaFile(file);
28432836}
28442837
......@@ -3137,7 +3130,7 @@ pub const ImportFileResult = struct {
31373130 is_new: bool,
31383131};
31393132
3140pub fn importPkg(mod: *Module, cur_pkg: *Package, pkg: *Package) !ImportFileResult {
3133pub fn importPkg(mod: *Module, pkg: *Package) !ImportFileResult {
31413134 const gpa = mod.gpa;
31423135
31433136 // The resolved path is used as the key in the import table, to detect if
......@@ -3190,7 +3183,7 @@ pub fn importFile(
31903183 import_string: []const u8,
31913184) !ImportFileResult {
31923185 if (cur_file.pkg.table.get(import_string)) |pkg| {
3193 return mod.importPkg(cur_file.pkg, pkg);
3186 return mod.importPkg(pkg);
31943187 }
31953188 const gpa = mod.gpa;
31963189
......@@ -3386,7 +3379,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo
33863379 log.debug("scan existing {*} ({s}) of {*}", .{ decl, decl.name, namespace });
33873380 // Update the AST node of the decl; even if its contents are unchanged, it may
33883381 // have been re-ordered.
3389 const prev_src_node = decl.src_node;
33903382 decl.src_node = decl_node;
33913383 decl.src_line = line;
33923384
......@@ -3395,7 +3387,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) InnerError!vo
33953387 decl.has_align = has_align;
33963388 decl.has_linksection = has_linksection;
33973389 decl.zir_decl_index = @intCast(u32, decl_sub_index);
3398 if (decl.getFunction()) |func| {
3390 if (decl.getFunction()) |_| {
33993391 switch (mod.comp.bin_file.tag) {
34003392 .coff => {
34013393 // TODO Implement for COFF
......@@ -3764,6 +3756,7 @@ pub fn analyzeExport(
37643756 errdefer de_gop.value_ptr.* = mod.gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1);
37653757}
37663758pub fn constInst(mod: *Module, arena: *Allocator, src: LazySrcLoc, typed_value: TypedValue) !*ir.Inst {
3759 _ = mod;
37673760 const const_inst = try arena.create(ir.Inst.Constant);
37683761 const_inst.* = .{
37693762 .base = .{
......@@ -4132,6 +4125,7 @@ pub fn floatAdd(
41324125 lhs: Value,
41334126 rhs: Value,
41344127) !Value {
4128 _ = src;
41354129 switch (float_type.tag()) {
41364130 .f16 => {
41374131 @panic("TODO add __trunctfhf2 to compiler-rt");
......@@ -4165,6 +4159,7 @@ pub fn floatSub(
41654159 lhs: Value,
41664160 rhs: Value,
41674161) !Value {
4162 _ = src;
41684163 switch (float_type.tag()) {
41694164 .f16 => {
41704165 @panic("TODO add __trunctfhf2 to compiler-rt");
......@@ -4198,6 +4193,7 @@ pub fn floatDiv(
41984193 lhs: Value,
41994194 rhs: Value,
42004195) !Value {
4196 _ = src;
42014197 switch (float_type.tag()) {
42024198 .f16 => {
42034199 @panic("TODO add __trunctfhf2 to compiler-rt");
......@@ -4231,6 +4227,7 @@ pub fn floatMul(
42314227 lhs: Value,
42324228 rhs: Value,
42334229) !Value {
4230 _ = src;
42344231 switch (float_type.tag()) {
42354232 .f16 => {
42364233 @panic("TODO add __trunctfhf2 to compiler-rt");
......@@ -4264,6 +4261,7 @@ pub fn simplePtrType(
42644261 mutable: bool,
42654262 size: std.builtin.TypeInfo.Pointer.Size,
42664263) Allocator.Error!Type {
4264 _ = mod;
42674265 if (!mutable and size == .Slice and elem_ty.eql(Type.initTag(.u8))) {
42684266 return Type.initTag(.const_slice_u8);
42694267 }
......@@ -4298,6 +4296,7 @@ pub fn ptrType(
42984296 @"volatile": bool,
42994297 size: std.builtin.TypeInfo.Pointer.Size,
43004298) Allocator.Error!Type {
4299 _ = mod;
43014300 assert(host_size == 0 or bit_offset < host_size * 8);
43024301
43034302 // TODO check if type can be represented by simplePtrType
......@@ -4315,6 +4314,7 @@ pub fn ptrType(
43154314}
43164315
43174316pub fn optionalType(mod: *Module, arena: *Allocator, child_type: Type) Allocator.Error!Type {
4317 _ = mod;
43184318 switch (child_type.tag()) {
43194319 .single_const_pointer => return Type.Tag.optional_single_const_pointer.create(
43204320 arena,
......@@ -4335,6 +4335,7 @@ pub fn arrayType(
43354335 sentinel: ?Value,
43364336 elem_type: Type,
43374337) Allocator.Error!Type {
4338 _ = mod;
43384339 if (elem_type.eql(Type.initTag(.u8))) {
43394340 if (sentinel) |some| {
43404341 if (some.eql(Value.initTag(.zero))) {
......@@ -4365,6 +4366,7 @@ pub fn errorUnionType(
43654366 error_set: Type,
43664367 payload: Type,
43674368) Allocator.Error!Type {
4369 _ = mod;
43684370 assert(error_set.zigTypeTag() == .ErrorSet);
43694371 if (error_set.eql(Type.initTag(.anyerror)) and payload.eql(Type.initTag(.void))) {
43704372 return Type.initTag(.anyerror_void_error_union);
......@@ -4692,11 +4694,9 @@ pub fn analyzeUnionFields(mod: *Module, union_obj: *Union) InnerError!void {
46924694 const src: LazySrcLoc = .{ .node_offset = union_obj.node_offset };
46934695 extra_index += @boolToInt(small.has_src_node);
46944696
4695 const tag_type_ref = if (small.has_tag_type) blk: {
4696 const tag_type_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
4697 if (small.has_tag_type) {
46974698 extra_index += 1;
4698 break :blk tag_type_ref;
4699 } else .none;
4699 }
47004700
47014701 const body_len = if (small.has_body_len) blk: {
47024702 const body_len = zir.extra[extra_index];
......@@ -4784,6 +4784,7 @@ pub fn analyzeUnionFields(mod: *Module, union_obj: *Union) InnerError!void {
47844784 cur_bit_bag >>= 1;
47854785 const unused = @truncate(u1, cur_bit_bag) != 0;
47864786 cur_bit_bag >>= 1;
4787 _ = unused;
47874788
47884789 const field_name_zir = zir.nullTerminatedString(zir.extra[extra_index]);
47894790 extra_index += 1;
......@@ -4800,11 +4801,9 @@ pub fn analyzeUnionFields(mod: *Module, union_obj: *Union) InnerError!void {
48004801 break :blk align_ref;
48014802 } else .none;
48024803
4803 const tag_ref: Zir.Inst.Ref = if (has_tag) blk: {
4804 const tag_ref = @intToEnum(Zir.Inst.Ref, zir.extra[extra_index]);
4804 if (has_tag) {
48054805 extra_index += 1;
4806 break :blk tag_ref;
4807 } else .none;
4806 }
48084807
48094808 // This string needs to outlive the ZIR code.
48104809 const field_name = try decl_arena.allocator.dupe(u8, field_name_zir);
src/Sema.zig+64-22
......@@ -702,6 +702,7 @@ fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) I
702702}
703703
704704fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
705 _ = inst;
705706 const tracy = trace(@src());
706707 defer tracy.end();
707708 return sema.mod.fail(&block.base, sema.src, "TODO implement zirCoerceResultPtr", .{});
......@@ -776,6 +777,7 @@ fn zirStructDecl(
776777}
777778
778779fn createTypeName(sema: *Sema, block: *Scope.Block, name_strategy: Zir.Inst.NameStrategy) ![:0]u8 {
780 _ = block;
779781 switch (name_strategy) {
780782 .anon => {
781783 // It would be neat to have "struct:line:column" but this name has
......@@ -1074,6 +1076,10 @@ fn zirOpaqueDecl(
10741076 const src = inst_data.src();
10751077 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
10761078
1079 _ = name_strategy;
1080 _ = inst_data;
1081 _ = src;
1082 _ = extra;
10771083 return sema.mod.fail(&block.base, sema.src, "TODO implement zirOpaqueDecl", .{});
10781084}
10791085
......@@ -1230,14 +1236,13 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In
12301236
12311237fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
12321238 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
1233 const src = inst_data.src();
12341239 const arg_name = inst_data.get(sema.code);
12351240 const arg_index = sema.next_arg_index;
12361241 sema.next_arg_index += 1;
12371242
12381243 // TODO check if arg_name shadows a Decl
12391244
1240 if (block.inlining) |inlining| {
1245 if (block.inlining) |_| {
12411246 return sema.param_inst_list[arg_index];
12421247 }
12431248
......@@ -1636,6 +1641,7 @@ fn zirStr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
16361641}
16371642
16381643fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1644 _ = block;
16391645 const tracy = trace(@src());
16401646 defer tracy.end();
16411647
......@@ -1644,6 +1650,7 @@ fn zirInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
16441650}
16451651
16461652fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1653 _ = block;
16471654 const tracy = trace(@src());
16481655 defer tracy.end();
16491656
......@@ -1661,6 +1668,7 @@ fn zirIntBig(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
16611668}
16621669
16631670fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1671 _ = block;
16641672 const arena = sema.arena;
16651673 const inst_data = sema.code.instructions.items(.data)[inst].float;
16661674 const src = inst_data.src();
......@@ -1673,6 +1681,7 @@ fn zirFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*
16731681}
16741682
16751683fn zirFloat128(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
1684 _ = block;
16761685 const arena = sema.arena;
16771686 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
16781687 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
......@@ -2354,6 +2363,7 @@ fn analyzeCall(
23542363}
23552364
23562365fn zirIntType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2366 _ = block;
23572367 const tracy = trace(@src());
23582368 defer tracy.end();
23592369
......@@ -2462,6 +2472,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
24622472}
24632473
24642474fn zirErrorValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2475 _ = block;
24652476 const tracy = trace(@src());
24662477 defer tracy.end();
24672478
......@@ -2622,6 +2633,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inn
26222633}
26232634
26242635fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
2636 _ = block;
26252637 const tracy = trace(@src());
26262638 defer tracy.end();
26272639
......@@ -3005,7 +3017,6 @@ fn zirFunc(
30053017 defer tracy.end();
30063018
30073019 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3008 const src = inst_data.src();
30093020 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);
30103021 const param_types = sema.code.refSlice(extra.end, extra.data.param_types_len);
30113022
......@@ -3061,7 +3072,9 @@ fn funcCommon(
30613072
30623073 const fn_ty: Type = fn_ty: {
30633074 // Hot path for some common function types.
3064 if (zir_param_types.len == 0 and !var_args and align_val.tag() == .null_value) {
3075 if (zir_param_types.len == 0 and !var_args and align_val.tag() == .null_value and
3076 !inferred_error_set)
3077 {
30653078 if (return_type.zigTypeTag() == .NoReturn and cc == .Unspecified) {
30663079 break :fn_ty Type.initTag(.fn_noreturn_no_args);
30673080 }
......@@ -3092,6 +3105,10 @@ fn funcCommon(
30923105 return mod.fail(&block.base, src, "TODO implement support for function prototypes to have alignment specified", .{});
30933106 }
30943107
3108 if (inferred_error_set) {
3109 return mod.fail(&block.base, src, "TODO implement functions with inferred error sets", .{});
3110 }
3111
30953112 break :fn_ty try Type.Tag.function.create(sema.arena, .{
30963113 .param_types = param_types,
30973114 .return_type = return_type,
......@@ -3332,9 +3349,7 @@ fn zirBitcast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError
33323349 defer tracy.end();
33333350
33343351 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
3335 const src = inst_data.src();
33363352 const dest_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
3337 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
33383353 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
33393354
33403355 const dest_type = try sema.resolveType(block, dest_ty_src, extra.lhs);
......@@ -3499,6 +3514,8 @@ fn zirSwitchCapture(
34993514 const switch_info = zir_datas[capture_info.switch_inst].pl_node;
35003515 const src = switch_info.src();
35013516
3517 _ = is_ref;
3518 _ = is_multi;
35023519 return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCapture", .{});
35033520}
35043521
......@@ -3516,6 +3533,7 @@ fn zirSwitchCaptureElse(
35163533 const switch_info = zir_datas[capture_info.switch_inst].pl_node;
35173534 const src = switch_info.src();
35183535
3536 _ = is_ref;
35193537 return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCaptureElse", .{});
35203538}
35213539
......@@ -3653,7 +3671,6 @@ fn analyzeSwitch(
36533671 extra_index += 1;
36543672 const body_len = sema.code.extra[extra_index];
36553673 extra_index += 1;
3656 const body = sema.code.extra[extra_index..][0..body_len];
36573674 extra_index += body_len;
36583675
36593676 try sema.validateSwitchItemEnum(
......@@ -3763,7 +3780,6 @@ fn analyzeSwitch(
37633780 extra_index += 1;
37643781 const body_len = sema.code.extra[extra_index];
37653782 extra_index += 1;
3766 const body = sema.code.extra[extra_index..][0..body_len];
37673783 extra_index += body_len;
37683784
37693785 try sema.validateSwitchItem(
......@@ -3859,7 +3875,6 @@ fn analyzeSwitch(
38593875 extra_index += 1;
38603876 const body_len = sema.code.extra[extra_index];
38613877 extra_index += 1;
3862 const body = sema.code.extra[extra_index..][0..body_len];
38633878 extra_index += body_len;
38643879
38653880 try sema.validateSwitchItemBool(
......@@ -3942,7 +3957,6 @@ fn analyzeSwitch(
39423957 extra_index += 1;
39433958 const body_len = sema.code.extra[extra_index];
39443959 extra_index += 1;
3945 const body = sema.code.extra[extra_index..][0..body_len];
39463960 extra_index += body_len;
39473961
39483962 try sema.validateSwitchItemSparse(
......@@ -4457,6 +4471,7 @@ fn validateSwitchNoRange(
44574471fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
44584472 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
44594473 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
4474 _ = extra;
44604475 const src = inst_data.src();
44614476
44624477 return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{});
......@@ -4515,12 +4530,17 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
45154530fn zirShl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
45164531 const tracy = trace(@src());
45174532 defer tracy.end();
4533
4534 _ = block;
4535 _ = inst;
45184536 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShl", .{});
45194537}
45204538
45214539fn zirShr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
45224540 const tracy = trace(@src());
45234541 defer tracy.end();
4542
4543 _ = inst;
45244544 return sema.mod.fail(&block.base, sema.src, "TODO implement zirShr", .{});
45254545}
45264546
......@@ -4590,18 +4610,24 @@ fn zirBitwise(
45904610fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
45914611 const tracy = trace(@src());
45924612 defer tracy.end();
4613
4614 _ = inst;
45934615 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});
45944616}
45954617
45964618fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
45974619 const tracy = trace(@src());
45984620 defer tracy.end();
4621
4622 _ = inst;
45994623 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayCat", .{});
46004624}
46014625
46024626fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
46034627 const tracy = trace(@src());
46044628 defer tracy.end();
4629
4630 _ = inst;
46054631 return sema.mod.fail(&block.base, sema.src, "TODO implement zirArrayMul", .{});
46064632}
46074633
......@@ -5061,6 +5087,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
50615087}
50625088
50635089fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5090 _ = block;
50645091 const zir_datas = sema.code.instructions.items(.data);
50655092 const inst_data = zir_datas[inst].un_node;
50665093 const src = inst_data.src();
......@@ -5069,6 +5096,7 @@ fn zirTypeof(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!
50695096}
50705097
50715098fn zirTypeofElem(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
5099 _ = block;
50725100 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
50735101 const src = inst_data.src();
50745102 const operand_ptr = try sema.resolveInst(inst_data.operand);
......@@ -5594,6 +5622,10 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
55945622 return mod.failWithOwnedErrorMsg(&block.base, msg);
55955623 }
55965624
5625 if (is_ref) {
5626 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true", .{});
5627 }
5628
55975629 const is_comptime = for (field_inits) |field_init| {
55985630 if (field_init.value() == null) {
55995631 break false;
......@@ -5617,18 +5649,24 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
56175649fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {
56185650 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
56195651 const src = inst_data.src();
5652
5653 _ = is_ref;
56205654 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{});
56215655}
56225656
56235657fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {
56245658 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
56255659 const src = inst_data.src();
5660
5661 _ = is_ref;
56265662 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInit", .{});
56275663}
56285664
56295665fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) InnerError!*Inst {
56305666 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
56315667 const src = inst_data.src();
5668
5669 _ = is_ref;
56325670 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{});
56335671}
56345672
......@@ -5771,7 +5809,6 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerErro
57715809 return sema.mod.fail(&block.base, type_src, "expected pointer, found '{}'", .{type_res});
57725810 const ptr_align = type_res.ptrAlignment(sema.mod.getTarget());
57735811
5774 const uncasted_operand = try sema.resolveInst(extra.rhs);
57755812 if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| {
57765813 const addr = val.toUnsignedInt();
57775814 if (!type_res.isAllowzeroPtr() and addr == 0)
......@@ -6025,6 +6062,8 @@ fn zirAwait(
60256062) InnerError!*Inst {
60266063 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
60276064 const src = inst_data.src();
6065
6066 _ = is_nosuspend;
60286067 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAwait", .{});
60296068}
60306069
......@@ -6035,7 +6074,6 @@ fn zirVarExtended(
60356074) InnerError!*Inst {
60366075 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
60376076 const src = sema.src;
6038 const align_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at align
60396077 const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type
60406078 const mut_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at mut token
60416079 const init_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at init expr
......@@ -6305,6 +6343,8 @@ fn addSafetyCheck(sema: *Sema, parent_block: *Scope.Block, ok: *Inst, panic_id:
63056343}
63066344
63076345fn safetyPanic(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, panic_id: PanicId) !Zir.Inst.Index {
6346 _ = sema;
6347 _ = panic_id;
63086348 // TODO Once we have a panic function to call, call it here instead of breakpoint.
63096349 _ = try block.addNoOp(src, Type.initTag(.void), .breakpoint);
63106350 _ = try block.addNoOp(src, Type.initTag(.noreturn), .unreach);
......@@ -6618,6 +6658,8 @@ fn elemPtrArray(
66186658 });
66196659 }
66206660 }
6661 _ = elem_index;
6662 _ = elem_index_src;
66216663 return sema.mod.fail(&block.base, src, "TODO implement more analyze elemptr for arrays", .{});
66226664}
66236665
......@@ -7131,6 +7173,7 @@ fn analyzeSlice(
71317173 ptr_child.isVolatilePtr(),
71327174 return_ptr_size,
71337175 );
7176 _ = return_type;
71347177
71357178 return sema.mod.fail(&block.base, src, "TODO implement analysis of slice", .{});
71367179}
......@@ -7476,14 +7519,14 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type
74767519 struct_obj.status = .have_field_types;
74777520 return ty;
74787521 },
7479 .extern_options => return sema.resolveBuiltinTypeFields(block, src, ty, "ExternOptions"),
7480 .export_options => return sema.resolveBuiltinTypeFields(block, src, ty, "ExportOptions"),
7481 .atomic_ordering => return sema.resolveBuiltinTypeFields(block, src, ty, "AtomicOrdering"),
7482 .atomic_rmw_op => return sema.resolveBuiltinTypeFields(block, src, ty, "AtomicRmwOp"),
7483 .calling_convention => return sema.resolveBuiltinTypeFields(block, src, ty, "CallingConvention"),
7484 .float_mode => return sema.resolveBuiltinTypeFields(block, src, ty, "FloatMode"),
7485 .reduce_op => return sema.resolveBuiltinTypeFields(block, src, ty, "ReduceOp"),
7486 .call_options => return sema.resolveBuiltinTypeFields(block, src, ty, "CallOptions"),
7522 .extern_options => return sema.resolveBuiltinTypeFields(block, src, "ExternOptions"),
7523 .export_options => return sema.resolveBuiltinTypeFields(block, src, "ExportOptions"),
7524 .atomic_ordering => return sema.resolveBuiltinTypeFields(block, src, "AtomicOrdering"),
7525 .atomic_rmw_op => return sema.resolveBuiltinTypeFields(block, src, "AtomicRmwOp"),
7526 .calling_convention => return sema.resolveBuiltinTypeFields(block, src, "CallingConvention"),
7527 .float_mode => return sema.resolveBuiltinTypeFields(block, src, "FloatMode"),
7528 .reduce_op => return sema.resolveBuiltinTypeFields(block, src, "ReduceOp"),
7529 .call_options => return sema.resolveBuiltinTypeFields(block, src, "CallOptions"),
74877530
74887531 .@"union", .union_tagged => {
74897532 const union_obj = ty.cast(Type.Payload.Union).?.data;
......@@ -7509,7 +7552,6 @@ fn resolveBuiltinTypeFields(
75097552 sema: *Sema,
75107553 block: *Scope.Block,
75117554 src: LazySrcLoc,
7512 ty: Type,
75137555 name: []const u8,
75147556) InnerError!Type {
75157557 const resolved_ty = try sema.getBuiltinType(block, src, name);
......@@ -7524,7 +7566,7 @@ fn getBuiltinType(
75247566) InnerError!Type {
75257567 const mod = sema.mod;
75267568 const std_pkg = mod.root_pkg.table.get("std").?;
7527 const std_file = (mod.importPkg(mod.root_pkg, std_pkg) catch unreachable).file;
7569 const std_file = (mod.importPkg(std_pkg) catch unreachable).file;
75287570 const opt_builtin_inst = try sema.analyzeNamespaceLookup(
75297571 block,
75307572 src,
src/ThreadPool.zig+2-2
......@@ -101,7 +101,7 @@ pub fn deinit(self: *ThreadPool) void {
101101
102102pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void {
103103 if (std.builtin.single_threaded) {
104 const result = @call(.{}, func, args);
104 @call(.{}, func, args);
105105 return;
106106 }
107107
......@@ -114,7 +114,7 @@ pub fn spawn(self: *ThreadPool, comptime func: anytype, args: anytype) !void {
114114 fn runFn(runnable: *Runnable) void {
115115 const run_node = @fieldParentPtr(RunQueue.Node, "data", runnable);
116116 const closure = @fieldParentPtr(@This(), "run_node", run_node);
117 const result = @call(.{}, func, closure.arguments);
117 @call(.{}, func, closure.arguments);
118118
119119 const held = closure.pool.lock.acquire();
120120 defer held.release();
src/Zir.zig+14-4
......@@ -3176,6 +3176,7 @@ const Writer = struct {
31763176 inst: Inst.Index,
31773177 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
31783178 const inst_data = self.code.instructions.items(.data)[inst].array_type_sentinel;
3179 _ = inst_data;
31793180 try stream.writeAll("TODO)");
31803181 }
31813182
......@@ -3213,6 +3214,7 @@ const Writer = struct {
32133214 inst: Inst.Index,
32143215 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
32153216 const inst_data = self.code.instructions.items(.data)[inst].ptr_type;
3217 _ = inst_data;
32163218 try stream.writeAll("TODO)");
32173219 }
32183220
......@@ -3559,6 +3561,8 @@ const Writer = struct {
35593561 assert(body.len == 0);
35603562 try stream.writeAll("{}, {})");
35613563 } else {
3564 const prev_parent_decl_node = self.parent_decl_node;
3565 if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off);
35623566 self.indent += 2;
35633567 if (body.len == 0) {
35643568 try stream.writeAll("{}, {\n");
......@@ -3621,6 +3625,7 @@ const Writer = struct {
36213625 try stream.writeAll(",\n");
36223626 }
36233627
3628 self.parent_decl_node = prev_parent_decl_node;
36243629 self.indent -= 2;
36253630 try stream.writeByteNTimes(' ', self.indent);
36263631 try stream.writeAll("})");
......@@ -3689,6 +3694,8 @@ const Writer = struct {
36893694 const body = self.code.extra[extra_index..][0..body_len];
36903695 extra_index += body.len;
36913696
3697 const prev_parent_decl_node = self.parent_decl_node;
3698 if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off);
36923699 self.indent += 2;
36933700 if (body.len == 0) {
36943701 try stream.writeAll("{}, {\n");
......@@ -3754,6 +3761,7 @@ const Writer = struct {
37543761 try stream.writeAll(",\n");
37553762 }
37563763
3764 self.parent_decl_node = prev_parent_decl_node;
37573765 self.indent -= 2;
37583766 try stream.writeByteNTimes(' ', self.indent);
37593767 try stream.writeAll("})");
......@@ -3909,6 +3917,8 @@ const Writer = struct {
39093917 assert(body.len == 0);
39103918 try stream.writeAll("{}, {})");
39113919 } else {
3920 const prev_parent_decl_node = self.parent_decl_node;
3921 if (src_node) |off| self.parent_decl_node = self.relativeToNodeIndex(off);
39123922 self.indent += 2;
39133923 if (body.len == 0) {
39143924 try stream.writeAll("{}, {\n");
......@@ -3949,6 +3959,7 @@ const Writer = struct {
39493959 }
39503960 try stream.writeAll(",\n");
39513961 }
3962 self.parent_decl_node = prev_parent_decl_node;
39523963 self.indent -= 2;
39533964 try stream.writeByteNTimes(' ', self.indent);
39543965 try stream.writeAll("})");
......@@ -4431,6 +4442,7 @@ const Writer = struct {
44314442 }
44324443
44334444 fn writeInstIndex(self: *Writer, stream: anytype, inst: Inst.Index) !void {
4445 _ = self;
44344446 return stream.print("%{d}", .{inst});
44354447 }
44364448
......@@ -4451,6 +4463,7 @@ const Writer = struct {
44514463 name: []const u8,
44524464 flag: bool,
44534465 ) !void {
4466 _ = self;
44544467 if (!flag) return;
44554468 try stream.writeAll(name);
44564469 }
......@@ -4739,7 +4752,6 @@ fn findDeclsSwitch(
47394752 var extra_index: usize = special.end;
47404753 var scalar_i: usize = 0;
47414754 while (scalar_i < extra.data.cases_len) : (scalar_i += 1) {
4742 const item_ref = @intToEnum(Inst.Ref, zir.extra[extra_index]);
47434755 extra_index += 1;
47444756 const body_len = zir.extra[extra_index];
47454757 extra_index += 1;
......@@ -4779,7 +4791,6 @@ fn findDeclsSwitchMulti(
47794791 {
47804792 var scalar_i: usize = 0;
47814793 while (scalar_i < extra.data.scalar_cases_len) : (scalar_i += 1) {
4782 const item_ref = @intToEnum(Inst.Ref, zir.extra[extra_index]);
47834794 extra_index += 1;
47844795 const body_len = zir.extra[extra_index];
47854796 extra_index += 1;
......@@ -4800,12 +4811,11 @@ fn findDeclsSwitchMulti(
48004811 extra_index += 1;
48014812 const items = zir.refSlice(extra_index, items_len);
48024813 extra_index += items_len;
4814 _ = items;
48034815
48044816 var range_i: usize = 0;
48054817 while (range_i < ranges_len) : (range_i += 1) {
4806 const item_first = @intToEnum(Inst.Ref, zir.extra[extra_index]);
48074818 extra_index += 1;
4808 const item_last = @intToEnum(Inst.Ref, zir.extra[extra_index]);
48094819 extra_index += 1;
48104820 }
48114821
src/air.zig+36
......@@ -304,9 +304,12 @@ pub const Inst = struct {
304304 base: Inst,
305305
306306 pub fn operandCount(self: *const NoOp) usize {
307 _ = self;
307308 return 0;
308309 }
309310 pub fn getOperand(self: *const NoOp, index: usize) ?*Inst {
311 _ = self;
312 _ = index;
310313 return null;
311314 }
312315 };
......@@ -316,6 +319,7 @@ pub const Inst = struct {
316319 operand: *Inst,
317320
318321 pub fn operandCount(self: *const UnOp) usize {
322 _ = self;
319323 return 1;
320324 }
321325 pub fn getOperand(self: *const UnOp, index: usize) ?*Inst {
......@@ -331,6 +335,7 @@ pub const Inst = struct {
331335 rhs: *Inst,
332336
333337 pub fn operandCount(self: *const BinOp) usize {
338 _ = self;
334339 return 2;
335340 }
336341 pub fn getOperand(self: *const BinOp, index: usize) ?*Inst {
......@@ -356,9 +361,12 @@ pub const Inst = struct {
356361 name: [*:0]const u8,
357362
358363 pub fn operandCount(self: *const Arg) usize {
364 _ = self;
359365 return 0;
360366 }
361367 pub fn getOperand(self: *const Arg, index: usize) ?*Inst {
368 _ = self;
369 _ = index;
362370 return null;
363371 }
364372 };
......@@ -391,9 +399,12 @@ pub const Inst = struct {
391399 body: Body,
392400
393401 pub fn operandCount(self: *const Block) usize {
402 _ = self;
394403 return 0;
395404 }
396405 pub fn getOperand(self: *const Block, index: usize) ?*Inst {
406 _ = self;
407 _ = index;
397408 return null;
398409 }
399410 };
......@@ -412,9 +423,12 @@ pub const Inst = struct {
412423 body: Body,
413424
414425 pub fn operandCount(self: *const BrBlockFlat) usize {
426 _ = self;
415427 return 0;
416428 }
417429 pub fn getOperand(self: *const BrBlockFlat, index: usize) ?*Inst {
430 _ = self;
431 _ = index;
418432 return null;
419433 }
420434 };
......@@ -427,9 +441,11 @@ pub const Inst = struct {
427441 operand: *Inst,
428442
429443 pub fn operandCount(self: *const Br) usize {
444 _ = self;
430445 return 1;
431446 }
432447 pub fn getOperand(self: *const Br, index: usize) ?*Inst {
448 _ = self;
433449 if (index == 0)
434450 return self.operand;
435451 return null;
......@@ -443,9 +459,12 @@ pub const Inst = struct {
443459 block: *Block,
444460
445461 pub fn operandCount(self: *const BrVoid) usize {
462 _ = self;
446463 return 0;
447464 }
448465 pub fn getOperand(self: *const BrVoid, index: usize) ?*Inst {
466 _ = self;
467 _ = index;
449468 return null;
450469 }
451470 };
......@@ -490,6 +509,7 @@ pub const Inst = struct {
490509 else_death_count: u32 = 0,
491510
492511 pub fn operandCount(self: *const CondBr) usize {
512 _ = self;
493513 return 1;
494514 }
495515 pub fn getOperand(self: *const CondBr, index: usize) ?*Inst {
......@@ -516,9 +536,12 @@ pub const Inst = struct {
516536 val: Value,
517537
518538 pub fn operandCount(self: *const Constant) usize {
539 _ = self;
519540 return 0;
520541 }
521542 pub fn getOperand(self: *const Constant, index: usize) ?*Inst {
543 _ = self;
544 _ = index;
522545 return null;
523546 }
524547 };
......@@ -530,9 +553,12 @@ pub const Inst = struct {
530553 body: Body,
531554
532555 pub fn operandCount(self: *const Loop) usize {
556 _ = self;
533557 return 0;
534558 }
535559 pub fn getOperand(self: *const Loop, index: usize) ?*Inst {
560 _ = self;
561 _ = index;
536562 return null;
537563 }
538564 };
......@@ -544,9 +570,12 @@ pub const Inst = struct {
544570 variable: *Module.Var,
545571
546572 pub fn operandCount(self: *const VarPtr) usize {
573 _ = self;
547574 return 0;
548575 }
549576 pub fn getOperand(self: *const VarPtr, index: usize) ?*Inst {
577 _ = self;
578 _ = index;
550579 return null;
551580 }
552581 };
......@@ -559,9 +588,12 @@ pub const Inst = struct {
559588 field_index: usize,
560589
561590 pub fn operandCount(self: *const StructFieldPtr) usize {
591 _ = self;
562592 return 1;
563593 }
564594 pub fn getOperand(self: *const StructFieldPtr, index: usize) ?*Inst {
595 _ = self;
596 _ = index;
565597 var i = index;
566598
567599 if (i < 1)
......@@ -593,6 +625,7 @@ pub const Inst = struct {
593625 };
594626
595627 pub fn operandCount(self: *const SwitchBr) usize {
628 _ = self;
596629 return 1;
597630 }
598631 pub fn getOperand(self: *const SwitchBr, index: usize) ?*Inst {
......@@ -621,9 +654,12 @@ pub const Inst = struct {
621654 column: u32,
622655
623656 pub fn operandCount(self: *const DbgStmt) usize {
657 _ = self;
624658 return 0;
625659 }
626660 pub fn getOperand(self: *const DbgStmt, index: usize) ?*Inst {
661 _ = self;
662 _ = index;
627663 return null;
628664 }
629665 };
src/codegen.zig+22-6
......@@ -118,7 +118,6 @@ pub fn generateSymbol(
118118 if (typed_value.ty.sentinel()) |sentinel| {
119119 try code.ensureCapacity(code.items.len + payload.data.len + 1);
120120 code.appendSliceAssumeCapacity(payload.data);
121 const prev_len = code.items.len;
122121 switch (try generateSymbol(bin_file, src_loc, .{
123122 .ty = typed_value.ty.elemType(),
124123 .val = sentinel,
......@@ -565,7 +564,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
565564 .r11 = true, // fp
566565 .r14 = true, // lr
567566 };
568 inline for (callee_preserved_regs) |reg, i| {
567 inline for (callee_preserved_regs) |reg| {
569568 if (self.register_manager.isRegAllocated(reg)) {
570569 @field(saved_regs, @tagName(reg)) = true;
571570 }
......@@ -603,7 +602,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
603602 } else {
604603 if (math.cast(i26, amt)) |offset| {
605604 writeInt(u32, self.code.items[jmp_reloc..][0..4], Instruction.b(.al, offset).toU32());
606 } else |err| {
605 } else |_| {
607606 return self.failSymbol("exitlude jump is too large", .{});
608607 }
609608 }
......@@ -676,7 +675,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
676675 } else {
677676 if (math.cast(i28, amt)) |offset| {
678677 writeInt(u32, self.code.items[jmp_reloc..][0..4], Instruction.b(offset).toU32());
679 } else |err| {
678 } else |_| {
680679 return self.failSymbol("exitlude jump is too large", .{});
681680 }
682681 }
......@@ -1498,6 +1497,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
14981497 swap_lhs_and_rhs: bool,
14991498 op: ir.Inst.Tag,
15001499 ) !void {
1500 _ = src;
15011501 assert(lhs_mcv == .register or rhs_mcv == .register);
15021502
15031503 const op1 = if (swap_lhs_and_rhs) rhs_mcv.register else lhs_mcv.register;
......@@ -1906,6 +1906,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
19061906 try self.genX8664ModRMRegToStack(src, dst_ty, off, src_reg, mr + 0x1);
19071907 },
19081908 .immediate => |imm| {
1909 _ = imm;
19091910 return self.fail(src, "TODO implement x86 ADD/SUB/CMP source immediate", .{});
19101911 },
19111912 .embedded_in_code, .memory, .stack_offset => {
......@@ -2055,6 +2056,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
20552056 return self.genSetStack(src, dst_ty, off, MCValue{ .register = dst_reg });
20562057 },
20572058 .immediate => |imm| {
2059 _ = imm;
20582060 return self.fail(src, "TODO implement x86 multiply source immediate", .{});
20592061 },
20602062 .embedded_in_code, .memory, .stack_offset => {
......@@ -2983,14 +2985,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
29832985 .arm, .armeb => {
29842986 if (math.cast(i26, @intCast(i32, index) - @intCast(i32, self.code.items.len + 8))) |delta| {
29852987 writeInt(u32, try self.code.addManyAsArray(4), Instruction.b(.al, delta).toU32());
2986 } else |err| {
2988 } else |_| {
29872989 return self.fail(src, "TODO: enable larger branch offset", .{});
29882990 }
29892991 },
29902992 .aarch64, .aarch64_be, .aarch64_32 => {
29912993 if (math.cast(i28, @intCast(i32, index) - @intCast(i32, self.code.items.len + 8))) |delta| {
29922994 writeInt(u32, try self.code.addManyAsArray(4), Instruction.b(delta).toU32());
2993 } else |err| {
2995 } else |_| {
29942996 return self.fail(src, "TODO: enable larger branch offset", .{});
29952997 }
29962998 },
......@@ -3308,9 +3310,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
33083310 }
33093311 },
33103312 .compare_flags_unsigned => |op| {
3313 _ = op;
33113314 return self.fail(src, "TODO implement set stack variable with compare flags value (unsigned)", .{});
33123315 },
33133316 .compare_flags_signed => |op| {
3317 _ = op;
33143318 return self.fail(src, "TODO implement set stack variable with compare flags value (signed)", .{});
33153319 },
33163320 .immediate => {
......@@ -3318,6 +3322,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
33183322 return self.genSetStack(src, ty, stack_offset, MCValue{ .register = reg });
33193323 },
33203324 .embedded_in_code => |code_offset| {
3325 _ = code_offset;
33213326 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});
33223327 },
33233328 .register => |reg| {
......@@ -3354,6 +3359,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
33543359 }
33553360 },
33563361 .memory => |vaddr| {
3362 _ = vaddr;
33573363 return self.fail(src, "TODO implement set stack variable from memory vaddr", .{});
33583364 },
33593365 .stack_offset => |off| {
......@@ -3382,9 +3388,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
33823388 }
33833389 },
33843390 .compare_flags_unsigned => |op| {
3391 _ = op;
33853392 return self.fail(src, "TODO implement set stack variable with compare flags value (unsigned)", .{});
33863393 },
33873394 .compare_flags_signed => |op| {
3395 _ = op;
33883396 return self.fail(src, "TODO implement set stack variable with compare flags value (signed)", .{});
33893397 },
33903398 .immediate => |x_big| {
......@@ -3437,12 +3445,14 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
34373445 }
34383446 },
34393447 .embedded_in_code => |code_offset| {
3448 _ = code_offset;
34403449 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});
34413450 },
34423451 .register => |reg| {
34433452 try self.genX8664ModRMRegToStack(src, ty, stack_offset, reg, 0x89);
34443453 },
34453454 .memory => |vaddr| {
3455 _ = vaddr;
34463456 return self.fail(src, "TODO implement set stack variable from memory vaddr", .{});
34473457 },
34483458 .stack_offset => |off| {
......@@ -3471,9 +3481,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
34713481 }
34723482 },
34733483 .compare_flags_unsigned => |op| {
3484 _ = op;
34743485 return self.fail(src, "TODO implement set stack variable with compare flags value (unsigned)", .{});
34753486 },
34763487 .compare_flags_signed => |op| {
3488 _ = op;
34773489 return self.fail(src, "TODO implement set stack variable with compare flags value (signed)", .{});
34783490 },
34793491 .immediate => {
......@@ -3481,6 +3493,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
34813493 return self.genSetStack(src, ty, stack_offset, MCValue{ .register = reg });
34823494 },
34833495 .embedded_in_code => |code_offset| {
3496 _ = code_offset;
34843497 return self.fail(src, "TODO implement set stack variable from embedded_in_code", .{});
34853498 },
34863499 .register => |reg| {
......@@ -3513,6 +3526,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
35133526 }
35143527 },
35153528 .memory => |vaddr| {
3529 _ = vaddr;
35163530 return self.fail(src, "TODO implement set stack variable from memory vaddr", .{});
35173531 },
35183532 .stack_offset => |off| {
......@@ -3843,6 +3857,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
38433857 );
38443858 },
38453859 .compare_flags_signed => |op| {
3860 _ = op;
38463861 return self.fail(src, "TODO set register with compare flags value (signed)", .{});
38473862 },
38483863 .immediate => |x| {
......@@ -4461,6 +4476,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
44614476 dummy,
44624477
44634478 pub fn allocIndex(self: Register) ?u4 {
4479 _ = self;
44644480 return null;
44654481 }
44664482 };
src/codegen/arm.zig+1-1
......@@ -674,7 +674,7 @@ pub const Instruction = union(enum) {
674674 };
675675 const imm4h: u4 = switch (offset) {
676676 .immediate => |imm| @truncate(u4, imm >> 4),
677 .register => |reg| 0b0000,
677 .register => 0b0000,
678678 };
679679
680680 return Instruction{
src/codegen/c.zig+9-1
......@@ -47,6 +47,8 @@ fn formatTypeAsCIdentifier(
4747 options: std.fmt.FormatOptions,
4848 writer: anytype,
4949) !void {
50 _ = fmt;
51 _ = options;
5052 var buffer = [1]u8{0} ** 128;
5153 // We don't care if it gets cut off, it's still more unique than a number
5254 var buf = std.fmt.bufPrint(&buffer, "{}", .{data}) catch &buffer;
......@@ -63,6 +65,8 @@ fn formatIdent(
6365 options: std.fmt.FormatOptions,
6466 writer: anytype,
6567) !void {
68 _ = fmt;
69 _ = options;
6670 for (ident) |c, i| {
6771 switch (c) {
6872 'a'...'z', 'A'...'Z', '_' => try writer.writeByte(c),
......@@ -747,6 +751,7 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi
747751}
748752
749753fn genVarPtr(o: *Object, inst: *Inst.VarPtr) !CValue {
754 _ = o;
750755 return CValue{ .decl_ref = inst.variable.owner_decl };
751756}
752757
......@@ -937,6 +942,8 @@ fn genCall(o: *Object, inst: *Inst.Call) !CValue {
937942}
938943
939944fn genDbgStmt(o: *Object, inst: *Inst.DbgStmt) !CValue {
945 _ = o;
946 _ = inst;
940947 // TODO emit #line directive here with line number and filename
941948 return CValue.none;
942949}
......@@ -1016,11 +1023,13 @@ fn genBitcast(o: *Object, inst: *Inst.UnOp) !CValue {
10161023}
10171024
10181025fn genBreakpoint(o: *Object, inst: *Inst.NoOp) !CValue {
1026 _ = inst;
10191027 try o.writer().writeAll("zig_breakpoint();\n");
10201028 return CValue.none;
10211029}
10221030
10231031fn genUnreach(o: *Object, inst: *Inst.NoOp) !CValue {
1032 _ = inst;
10241033 try o.writer().writeAll("zig_unreachable();\n");
10251034 return CValue.none;
10261035}
......@@ -1107,7 +1116,6 @@ fn genAsm(o: *Object, as: *Inst.Assembly) !CValue {
11071116 for (as.inputs) |i, index| {
11081117 if (i[0] == '{' and i[i.len - 1] == '}') {
11091118 const reg = i[1 .. i.len - 1];
1110 const arg = as.args[index];
11111119 if (index > 0) {
11121120 try writer.writeAll(", ");
11131121 }
src/codegen/llvm.zig+4
......@@ -154,6 +154,7 @@ pub const Object = struct {
154154 object_pathZ: [:0]const u8,
155155
156156 pub fn create(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Object {
157 _ = sub_path;
157158 const self = try allocator.create(Object);
158159 errdefer allocator.destroy(self);
159160
......@@ -742,6 +743,7 @@ pub const FuncGen = struct {
742743 }
743744
744745 fn genRetVoid(self: *FuncGen, inst: *Inst.NoOp) ?*const llvm.Value {
746 _ = inst;
745747 _ = self.builder.buildRetVoid();
746748 return null;
747749 }
......@@ -873,6 +875,7 @@ pub const FuncGen = struct {
873875 }
874876
875877 fn genUnreach(self: *FuncGen, inst: *Inst.NoOp) ?*const llvm.Value {
878 _ = inst;
876879 _ = self.builder.buildUnreachable();
877880 return null;
878881 }
......@@ -1013,6 +1016,7 @@ pub const FuncGen = struct {
10131016 }
10141017
10151018 fn genBreakpoint(self: *FuncGen, inst: *Inst.NoOp) !?*const llvm.Value {
1019 _ = inst;
10161020 const llvn_fn = self.getIntrinsic("llvm.debugtrap");
10171021 _ = self.builder.buildCall(llvn_fn, null, 0, "");
10181022 return null;
src/codegen/spirv.zig+1-3
......@@ -714,7 +714,6 @@ pub const DeclGen = struct {
714714 return self.fail(inst.base.src, "TODO: SPIR-V backend: binary operations for strange integers", .{});
715715 }
716716
717 const is_bool = info.class == .bool;
718717 const is_float = info.class == .float;
719718 const is_signed = info.signedness == .signed;
720719 // **Note**: All these operations must be valid for vectors as well!
......@@ -802,8 +801,6 @@ pub const DeclGen = struct {
802801 const result_id = self.spv.allocResultId();
803802 const result_type_id = try self.genType(inst.base.src, inst.base.ty);
804803
805 const info = try self.arithmeticTypeInfo(inst.operand.ty);
806
807804 const opcode = switch (inst.base.tag) {
808805 // Bool -> bool
809806 .not => Opcode.OpLogicalNot,
......@@ -867,6 +864,7 @@ pub const DeclGen = struct {
867864 // are not allowed to be created from a phi node, and throw an error for those. For now, genType already throws
868865 // an error for pointers.
869866 const result_type_id = try self.genType(inst.base.src, inst.base.ty);
867 _ = result_type_id;
870868
871869 try writeOpcode(&self.code, .OpPhi, 2 + @intCast(u16, incoming_blocks.items.len * 2)); // result type + result + variable/parent...
872870
src/codegen/wasm.zig+7-6
......@@ -702,7 +702,7 @@ pub const Context = struct {
702702 try writer.writeByte(wasm.valtype(.i32)); // error code is always an i32 integer.
703703 try writer.writeByte(val_type);
704704 },
705 else => |ret_type| {
705 else => {
706706 try leb.writeULEB128(writer, @as(u32, 1));
707707 // Can we maybe get the source index of the return type?
708708 const val_type = try self.genValtype(.{ .node_offset = 0 }, return_type);
......@@ -721,7 +721,7 @@ pub const Context = struct {
721721 // TODO: check for and handle death of instructions
722722 const mod_fn = blk: {
723723 if (typed_value.val.castTag(.function)) |func| break :blk func.data;
724 if (typed_value.val.castTag(.extern_fn)) |ext_fn| return Result.appended; // don't need code body for extern functions
724 if (typed_value.val.castTag(.extern_fn)) |_| return Result.appended; // don't need code body for extern functions
725725 unreachable;
726726 };
727727
......@@ -849,7 +849,6 @@ pub const Context = struct {
849849 }
850850
851851 fn genCall(self: *Context, inst: *Inst.Call) InnerError!WValue {
852 const func_inst = inst.func.castTag(.constant).?;
853852 const func_val = inst.func.value().?;
854853
855854 const target: *Decl = blk: {
......@@ -914,7 +913,7 @@ pub const Context = struct {
914913 .local => |local| {
915914 try self.emitWValue(rhs);
916915 try writer.writeByte(wasm.opcode(.local_set));
917 try leb.writeULEB128(writer, lhs.local);
916 try leb.writeULEB128(writer, local);
918917 },
919918 else => unreachable,
920919 }
......@@ -926,6 +925,7 @@ pub const Context = struct {
926925 }
927926
928927 fn genArg(self: *Context, inst: *Inst.Arg) InnerError!WValue {
928 _ = inst;
929929 // arguments share the index with locals
930930 defer self.local_index += 1;
931931 return WValue{ .local = self.local_index };
......@@ -1146,8 +1146,6 @@ pub const Context = struct {
11461146 }
11471147
11481148 fn genCmp(self: *Context, inst: *Inst.BinOp, op: std.math.CompareOperator) InnerError!WValue {
1149 const ty = inst.lhs.ty.tag();
1150
11511149 // save offset, so potential conditions can insert blocks in front of
11521150 // the comparison that we can later jump back to
11531151 const offset = self.code.items.len;
......@@ -1216,12 +1214,15 @@ pub const Context = struct {
12161214 }
12171215
12181216 fn genBreakpoint(self: *Context, breakpoint: *Inst.NoOp) InnerError!WValue {
1217 _ = self;
1218 _ = breakpoint;
12191219 // unsupported by wasm itself. Can be implemented once we support DWARF
12201220 // for wasm
12211221 return .none;
12221222 }
12231223
12241224 fn genUnreachable(self: *Context, unreach: *Inst.NoOp) InnerError!WValue {
1225 _ = unreach;
12251226 try self.code.append(wasm.opcode(.@"unreachable"));
12261227 return .none;
12271228 }
src/glibc.zig-1
......@@ -497,7 +497,6 @@ fn add_include_dirs(comp: *Compilation, arena: *Allocator, args: *std.ArrayList(
497497 const target = comp.getTarget();
498498 const arch = target.cpu.arch;
499499 const opt_nptl: ?[]const u8 = if (target.os.tag == .linux) "nptl" else "htl";
500 const glibc = try lib_path(comp, arena, lib_libc ++ "glibc");
501500
502501 const s = path.sep_str;
503502
src/link.zig+1-1
......@@ -517,7 +517,7 @@ pub const File = struct {
517517 .target = base.options.target,
518518 .output_mode = .Obj,
519519 });
520 const o_directory = base.options.module.?.zig_cache_artifact_directory;
520 const o_directory = module.zig_cache_artifact_directory;
521521 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
522522 break :blk full_obj_path;
523523 }
src/link/C.zig+10-2
......@@ -76,7 +76,10 @@ pub fn deinit(self: *C) void {
7676 self.decl_table.deinit(self.base.allocator);
7777}
7878
79pub fn allocateDeclIndexes(self: *C, decl: *Module.Decl) !void {}
79pub fn allocateDeclIndexes(self: *C, decl: *Module.Decl) !void {
80 _ = self;
81 _ = decl;
82}
8083
8184pub fn freeDecl(self: *C, decl: *Module.Decl) void {
8285 _ = self.decl_table.swapRemove(decl);
......@@ -307,4 +310,9 @@ pub fn updateDeclExports(
307310 module: *Module,
308311 decl: *Module.Decl,
309312 exports: []const *Module.Export,
310) !void {}
313) !void {
314 _ = exports;
315 _ = decl;
316 _ = module;
317 _ = self;
318}
src/link/Coff.zig+4-1
......@@ -831,7 +831,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
831831 .target = self.base.options.target,
832832 .output_mode = .Obj,
833833 });
834 const o_directory = self.base.options.module.?.zig_cache_artifact_directory;
834 const o_directory = module.zig_cache_artifact_directory;
835835 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
836836 break :blk full_obj_path;
837837 }
......@@ -1340,6 +1340,9 @@ pub fn getDeclVAddr(self: *Coff, decl: *const Module.Decl) u64 {
13401340}
13411341
13421342pub fn updateDeclLineNumber(self: *Coff, module: *Module, decl: *Module.Decl) !void {
1343 _ = self;
1344 _ = module;
1345 _ = decl;
13431346 // TODO Implement this
13441347}
13451348
src/link/Elf.zig+8-3
......@@ -1262,7 +1262,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
12621262 .target = self.base.options.target,
12631263 .output_mode = .Obj,
12641264 });
1265 const o_directory = self.base.options.module.?.zig_cache_artifact_directory;
1265 const o_directory = module.zig_cache_artifact_directory;
12661266 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
12671267 break :blk full_obj_path;
12681268 }
......@@ -1938,6 +1938,9 @@ fn freeTextBlock(self: *Elf, text_block: *TextBlock) void {
19381938}
19391939
19401940fn shrinkTextBlock(self: *Elf, text_block: *TextBlock, new_block_size: u64) void {
1941 _ = self;
1942 _ = text_block;
1943 _ = new_block_size;
19411944 // TODO check the new capacity, and if it crosses the size threshold into a big enough
19421945 // capacity, insert a free list node for it.
19431946}
......@@ -2706,6 +2709,7 @@ pub fn updateDeclExports(
27062709
27072710/// Must be called only after a successful call to `updateDecl`.
27082711pub fn updateDeclLineNumber(self: *Elf, module: *Module, decl: *const Module.Decl) !void {
2712 _ = module;
27092713 const tracy = trace(@src());
27102714 defer tracy.end();
27112715
......@@ -2979,6 +2983,7 @@ fn dbgLineNeededHeaderBytes(self: Elf) u32 {
29792983}
29802984
29812985fn dbgInfoNeededHeaderBytes(self: Elf) u32 {
2986 _ = self;
29822987 return 120;
29832988}
29842989
......@@ -3372,7 +3377,7 @@ const CsuObjects = struct {
33723377 if (result.crtend) |*obj| obj.* = try fs.path.join(arena, &[_][]const u8{ gcc_dir_path, obj.* });
33733378 },
33743379 else => {
3375 inline for (std.meta.fields(@TypeOf(result))) |f, i| {
3380 inline for (std.meta.fields(@TypeOf(result))) |f| {
33763381 if (@field(result, f.name)) |*obj| {
33773382 obj.* = try fs.path.join(arena, &[_][]const u8{ crt_dir_path, obj.* });
33783383 }
......@@ -3380,7 +3385,7 @@ const CsuObjects = struct {
33803385 },
33813386 }
33823387 } else {
3383 inline for (std.meta.fields(@TypeOf(result))) |f, i| {
3388 inline for (std.meta.fields(@TypeOf(result))) |f| {
33843389 if (@field(result, f.name)) |*obj| {
33853390 if (comp.crt_files.get(obj.*)) |crtf| {
33863391 obj.* = crtf.full_object_path;
src/link/MachO.zig+5-4
......@@ -441,6 +441,7 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
441441}
442442
443443pub fn flushModule(self: *MachO, comp: *Compilation) !void {
444 _ = comp;
444445 const tracy = trace(@src());
445446 defer tracy.end();
446447
......@@ -533,7 +534,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
533534 .target = self.base.options.target,
534535 .output_mode = .Obj,
535536 });
536 const o_directory = self.base.options.module.?.zig_cache_artifact_directory;
537 const o_directory = module.zig_cache_artifact_directory;
537538 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
538539 break :blk full_obj_path;
539540 }
......@@ -1254,6 +1255,9 @@ fn freeTextBlock(self: *MachO, text_block: *TextBlock) void {
12541255}
12551256
12561257fn shrinkTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64) void {
1258 _ = self;
1259 _ = text_block;
1260 _ = new_block_size;
12571261 // TODO check the new capacity, and if it crosses the size threshold into a big enough
12581262 // capacity, insert a free list node for it.
12591263}
......@@ -2918,7 +2922,6 @@ fn relocateSymbolTable(self: *MachO) !void {
29182922 const nsyms = nlocals + nglobals + nundefs;
29192923
29202924 if (symtab.nsyms < nsyms) {
2921 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
29222925 const needed_size = nsyms * @sizeOf(macho.nlist_64);
29232926 if (needed_size > self.allocatedSizeLinkedit(symtab.symoff)) {
29242927 // Move the entire symbol table to a new location
......@@ -3150,7 +3153,6 @@ fn writeExportTrie(self: *MachO) !void {
31503153 const nwritten = try trie.write(stream.writer());
31513154 assert(nwritten == trie.size);
31523155
3153 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
31543156 const dyld_info = &self.load_commands.items[self.dyld_info_cmd_index.?].DyldInfoOnly;
31553157 const allocated_size = self.allocatedSizeLinkedit(dyld_info.export_off);
31563158 const needed_size = mem.alignForwardGeneric(u64, buffer.len, @alignOf(u64));
......@@ -3357,7 +3359,6 @@ fn populateLazyBindOffsetsInStubHelper(self: *MachO, buffer: []const u8) !void {
33573359 error.EndOfStream => break,
33583360 else => return err,
33593361 };
3360 const imm: u8 = inst & macho.BIND_IMMEDIATE_MASK;
33613362 const opcode: u8 = inst & macho.BIND_OPCODE_MASK;
33623363
33633364 switch (opcode) {
src/link/MachO/DebugSymbols.zig+6-7
......@@ -500,7 +500,6 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt
500500 if (self.debug_aranges_section_dirty) {
501501 const dwarf_segment = &self.load_commands.items[self.dwarf_segment_cmd_index.?].Segment;
502502 const debug_aranges_sect = &dwarf_segment.sections.items[self.debug_aranges_section_index.?];
503 const debug_info_sect = dwarf_segment.sections.items[self.debug_info_section_index.?];
504503
505504 var di_buf = std.ArrayList(u8).init(allocator);
506505 defer di_buf.deinit();
......@@ -844,7 +843,6 @@ fn relocateSymbolTable(self: *DebugSymbols) !void {
844843 const nsyms = nlocals + nglobals;
845844
846845 if (symtab.nsyms < nsyms) {
847 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
848846 const needed_size = nsyms * @sizeOf(macho.nlist_64);
849847 if (needed_size > self.allocatedSizeLinkedit(symtab.symoff)) {
850848 // Move the entire symbol table to a new location
......@@ -901,14 +899,10 @@ fn writeStringTable(self: *DebugSymbols) !void {
901899}
902900
903901pub fn updateDeclLineNumber(self: *DebugSymbols, module: *Module, decl: *const Module.Decl) !void {
902 _ = module;
904903 const tracy = trace(@src());
905904 defer tracy.end();
906905
907 const tree = decl.namespace.file_scope.tree;
908 const node_tags = tree.nodes.items(.tag);
909 const node_datas = tree.nodes.items(.data);
910 const token_starts = tree.tokens.items(.start);
911
912906 const func = decl.val.castTag(.function).?.data;
913907 const line_off = @intCast(u28, decl.src_line + func.lbrace_line);
914908
......@@ -933,6 +927,8 @@ pub fn initDeclDebugBuffers(
933927 module: *Module,
934928 decl: *Module.Decl,
935929) !DeclDebugBuffers {
930 _ = self;
931 _ = module;
936932 const tracy = trace(@src());
937933 defer tracy.end();
938934
......@@ -1195,6 +1191,7 @@ fn addDbgInfoType(
11951191 dbg_info_buffer: *std.ArrayList(u8),
11961192 target: std.Target,
11971193) !void {
1194 _ = self;
11981195 switch (ty.zigTypeTag()) {
11991196 .Void => unreachable,
12001197 .NoReturn => unreachable,
......@@ -1371,6 +1368,7 @@ fn getRelocDbgInfoSubprogramHighPC() u32 {
13711368}
13721369
13731370fn dbgLineNeededHeaderBytes(self: DebugSymbols, module: *Module) u32 {
1371 _ = self;
13741372 const directory_entry_format_count = 1;
13751373 const file_name_entry_format_count = 1;
13761374 const directory_count = 1;
......@@ -1385,6 +1383,7 @@ fn dbgLineNeededHeaderBytes(self: DebugSymbols, module: *Module) u32 {
13851383}
13861384
13871385fn dbgInfoNeededHeaderBytes(self: DebugSymbols) u32 {
1386 _ = self;
13881387 return 120;
13891388}
13901389
src/link/MachO/Object.zig-1
......@@ -478,7 +478,6 @@ pub fn parseDebugInfo(self: *Object) !void {
478478
479479 self.tu_path = try std.fs.path.join(self.allocator, &[_][]const u8{ comp_dir, name });
480480 self.tu_mtime = mtime: {
481 var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
482481 const stat = try self.file.?.stat();
483482 break :mtime @intCast(u64, @divFloor(stat.mtime, 1_000_000_000));
484483 };
src/link/MachO/Zld.zig+5-8
......@@ -108,6 +108,7 @@ const TlvOffset = struct {
108108 offset: u64,
109109
110110 fn cmp(context: void, a: TlvOffset, b: TlvOffset) bool {
111 _ = context;
111112 return a.source_addr < b.source_addr;
112113 }
113114};
......@@ -432,13 +433,12 @@ fn mapAndUpdateSections(
432433
433434fn updateMetadata(self: *Zld) !void {
434435 for (self.objects.items) |object| {
435 const object_seg = object.load_commands.items[object.segment_cmd_index.?].Segment;
436436 const text_seg = &self.load_commands.items[self.text_segment_cmd_index.?].Segment;
437437 const data_const_seg = &self.load_commands.items[self.data_const_segment_cmd_index.?].Segment;
438438 const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
439439
440440 // Create missing metadata
441 for (object.sections.items) |sect, sect_id| {
441 for (object.sections.items) |sect| {
442442 const segname = sect.segname();
443443 const sectname = sect.sectname();
444444
......@@ -1294,7 +1294,6 @@ fn allocateLinkeditSegment(self: *Zld) void {
12941294}
12951295
12961296fn allocateSegment(self: *Zld, index: u16, offset: u64) !void {
1297 const base_vmaddr = self.load_commands.items[self.pagezero_segment_cmd_index.?].Segment.inner.vmsize;
12981297 const seg = &self.load_commands.items[index].Segment;
12991298
13001299 // Allocate the sections according to their alignment at the beginning of the segment.
......@@ -1375,7 +1374,7 @@ fn allocateTentativeSymbols(self: *Zld) !void {
13751374 }
13761375
13771376 // Convert tentative definitions into regular symbols.
1378 for (self.tentatives.values()) |sym, i| {
1377 for (self.tentatives.values()) |sym| {
13791378 const tent = sym.cast(Symbol.Tentative) orelse unreachable;
13801379 const reg = try self.allocator.create(Symbol.Regular);
13811380 errdefer self.allocator.destroy(reg);
......@@ -1427,7 +1426,6 @@ fn writeStubHelperCommon(self: *Zld) !void {
14271426 const got = &data_const_segment.sections.items[self.got_section_index.?];
14281427 const data_segment = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
14291428 const data = &data_segment.sections.items[self.data_section_index.?];
1430 const la_symbol_ptr = data_segment.sections.items[self.la_symbol_ptr_section_index.?];
14311429
14321430 self.stub_helper_stubs_start_off = blk: {
14331431 switch (self.arch.?) {
......@@ -1761,7 +1759,7 @@ fn resolveSymbolsInObject(self: *Zld, object: *Object) !void {
17611759
17621760 t_sym.alias = sym;
17631761 sym_ptr.* = sym;
1764 } else if (sym.cast(Symbol.Unresolved)) |und| {
1762 } else if (sym.cast(Symbol.Unresolved)) |_| {
17651763 if (self.globals.get(sym.name)) |g_sym| {
17661764 sym.alias = g_sym;
17671765 continue;
......@@ -2654,7 +2652,6 @@ fn setEntryPoint(self: *Zld) !void {
26542652 // TODO we should respect the -entry flag passed in by the user to set a custom
26552653 // entrypoint. For now, assume default of `_main`.
26562654 const seg = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
2657 const text = seg.sections.items[self.text_section_index.?];
26582655 const sym = self.globals.get("_main") orelse return error.MissingMainEntrypoint;
26592656 const entry_sym = sym.cast(Symbol.Regular) orelse unreachable;
26602657 const ec = &self.load_commands.items[self.main_cmd_index.?].Main;
......@@ -2862,7 +2859,6 @@ fn populateLazyBindOffsetsInStubHelper(self: *Zld, buffer: []const u8) !void {
28622859 error.EndOfStream => break,
28632860 else => return err,
28642861 };
2865 const imm: u8 = inst & macho.BIND_IMMEDIATE_MASK;
28662862 const opcode: u8 = inst & macho.BIND_OPCODE_MASK;
28672863
28682864 switch (opcode) {
......@@ -2959,6 +2955,7 @@ fn writeDebugInfo(self: *Zld) !void {
29592955 for (self.objects.items) |object| {
29602956 const tu_path = object.tu_path orelse continue;
29612957 const tu_mtime = object.tu_mtime orelse continue;
2958 _ = tu_mtime;
29622959 const dirname = std.fs.path.dirname(tu_path) orelse "./";
29632960 // Current dir
29642961 try stabs.append(.{
src/link/MachO/bind.zig+1
......@@ -10,6 +10,7 @@ pub const Pointer = struct {
1010};
1111
1212pub fn pointerCmp(context: void, a: Pointer, b: Pointer) bool {
13 _ = context;
1314 if (a.segment_id < b.segment_id) return true;
1415 if (a.segment_id == b.segment_id) {
1516 return a.offset < b.offset;
src/link/MachO/reloc/x86_64.zig-1
......@@ -175,7 +175,6 @@ pub const Parser = struct {
175175
176176 const rel_type = @intToEnum(macho.reloc_type_x86_64, rel.r_type);
177177 const target = Relocation.Target.from_reloc(rel, parser.symbols);
178 const is_extern = rel.r_extern == 1;
179178
180179 const offset = @intCast(u32, rel.r_address);
181180 const inst = parser.code[offset..][0..4];
src/link/SpirV.zig+7-1
......@@ -102,6 +102,7 @@ pub fn deinit(self: *SpirV) void {
102102}
103103
104104pub fn updateDecl(self: *SpirV, module: *Module, decl: *Module.Decl) !void {
105 _ = module;
105106 // Keep track of all decls so we can iterate over them on flush().
106107 _ = try self.decl_table.getOrPut(self.base.allocator, decl);
107108}
......@@ -111,7 +112,12 @@ pub fn updateDeclExports(
111112 module: *Module,
112113 decl: *const Module.Decl,
113114 exports: []const *Module.Export,
114) !void {}
115) !void {
116 _ = self;
117 _ = module;
118 _ = decl;
119 _ = exports;
120}
115121
116122pub fn freeDecl(self: *SpirV, decl: *Module.Decl) void {
117123 assert(self.decl_table.swapRemove(decl));
src/link/Wasm.zig+9-4
......@@ -216,7 +216,7 @@ pub fn updateDecl(self: *Wasm, module: *Module, decl: *Module.Decl) !void {
216216 try module.failed_decls.put(module.gpa, decl, context.err_msg);
217217 return;
218218 },
219 else => |e| return err,
219 else => |e| return e,
220220 };
221221
222222 const code: []const u8 = switch (result) {
......@@ -258,7 +258,12 @@ pub fn updateDeclExports(
258258 module: *Module,
259259 decl: *const Module.Decl,
260260 exports: []const *Module.Export,
261) !void {}
261) !void {
262 _ = self;
263 _ = module;
264 _ = decl;
265 _ = exports;
266}
262267
263268pub fn freeDecl(self: *Wasm, decl: *Module.Decl) void {
264269 if (self.getFuncidx(decl)) |func_idx| {
......@@ -300,6 +305,7 @@ pub fn flush(self: *Wasm, comp: *Compilation) !void {
300305}
301306
302307pub fn flushModule(self: *Wasm, comp: *Compilation) !void {
308 _ = comp;
303309 const tracy = trace(@src());
304310 defer tracy.end();
305311
......@@ -496,7 +502,6 @@ pub fn flushModule(self: *Wasm, comp: *Compilation) !void {
496502 if (data_size != 0) {
497503 const header_offset = try reserveVecSectionHeader(file);
498504 const writer = file.writer();
499 var len: u32 = 0;
500505 // index to memory section (currently, there can only be 1 memory section in wasm)
501506 try leb.writeULEB128(writer, @as(u32, 0));
502507
......@@ -558,7 +563,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
558563 .target = self.base.options.target,
559564 .output_mode = .Obj,
560565 });
561 const o_directory = self.base.options.module.?.zig_cache_artifact_directory;
566 const o_directory = module.zig_cache_artifact_directory;
562567 const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
563568 break :blk full_obj_path;
564569 }
src/main.zig+2-2
......@@ -500,7 +500,7 @@ const Emit = union(enum) {
500500};
501501
502502fn optionalBoolEnvVar(arena: *Allocator, name: []const u8) !bool {
503 if (std.process.getEnvVarOwned(arena, name)) |value| {
503 if (std.process.getEnvVarOwned(arena, name)) |_| {
504504 return true;
505505 } else |err| switch (err) {
506506 error.EnvironmentVariableNotFound => return false,
......@@ -2565,6 +2565,7 @@ pub fn cmdInit(
25652565 args: []const []const u8,
25662566 output_mode: std.builtin.OutputMode,
25672567) !void {
2568 _ = gpa;
25682569 {
25692570 var i: usize = 0;
25702571 while (i < args.len) : (i += 1) {
......@@ -3749,7 +3750,6 @@ pub fn cmdAstCheck(
37493750
37503751 var color: Color = .auto;
37513752 var want_output_text = false;
3752 var have_zig_source_file = false;
37533753 var zig_source_file: ?[]const u8 = null;
37543754
37553755 var i: usize = 0;
src/mingw.zig-2
......@@ -372,11 +372,9 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
372372
373373 try child.spawn();
374374
375 const stdout_reader = child.stdout.?.reader();
376375 const stderr_reader = child.stderr.?.reader();
377376
378377 // TODO https://github.com/ziglang/zig/issues/6343
379 const stdout = try stdout_reader.readAllAlloc(arena, std.math.maxInt(u32));
380378 const stderr = try stderr_reader.readAllAlloc(arena, 10 * 1024 * 1024);
381379
382380 const term = child.wait() catch |err| {
src/musl.zig-1
......@@ -143,7 +143,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
143143 const dirname = path.dirname(src_file).?;
144144 const basename = path.basename(src_file);
145145 const noextbasename = basename[0 .. basename.len - std.fs.path.extension(basename).len];
146 const before_arch_dir = path.dirname(dirname).?;
147146 const dirbasename = path.basename(dirname);
148147
149148 var is_arch_specific = false;
src/print_env.zig+1
......@@ -5,6 +5,7 @@ const Allocator = std.mem.Allocator;
55const fatal = @import("main.zig").fatal;
66
77pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void {
8 _ = args;
89 const self_exe_path = try std.fs.selfExePathAlloc(gpa);
910 defer gpa.free(self_exe_path);
1011
src/print_targets.zig+1
......@@ -17,6 +17,7 @@ pub fn cmdTargets(
1717 stdout: anytype,
1818 native_target: Target,
1919) !void {
20 _ = args;
2021 var zig_lib_directory = introspect.findZigLibDir(allocator) catch |err| {
2122 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});
2223 };
src/register_manager.zig+2-12
......@@ -265,6 +265,8 @@ fn MockFunction(comptime Register: type) type {
265265 }
266266
267267 pub fn spillInstruction(self: *Self, src: LazySrcLoc, reg: Register, inst: *ir.Inst) !void {
268 _ = src;
269 _ = inst;
268270 try self.spilled.append(self.allocator, reg);
269271 }
270272 };
......@@ -281,12 +283,6 @@ test "default state" {
281283 };
282284 defer function.deinit();
283285
284 var mock_instruction = ir.Inst{
285 .tag = .breakpoint,
286 .ty = Type.initTag(.void),
287 .src = .unneeded,
288 };
289
290286 try expect(!function.register_manager.isRegAllocated(.r2));
291287 try expect(!function.register_manager.isRegAllocated(.r3));
292288 try expect(function.register_manager.isRegFree(.r2));
......@@ -365,12 +361,6 @@ test "tryAllocRegs" {
365361 };
366362 defer function.deinit();
367363
368 var mock_instruction = ir.Inst{
369 .tag = .breakpoint,
370 .ty = Type.initTag(.void),
371 .src = .unneeded,
372 };
373
374364 try expectEqual([_]MockRegister2{ .r0, .r1, .r2 }, function.register_manager.tryAllocRegs(3, .{ null, null, null }, &.{}).?);
375365
376366 // Exceptions
src/stage1.zig+2
......@@ -407,6 +407,8 @@ export fn stage2_add_link_lib(
407407 symbol_name_ptr: [*c]const u8,
408408 symbol_name_len: usize,
409409) ?[*:0]const u8 {
410 _ = symbol_name_len;
411 _ = symbol_name_ptr;
410412 const comp = @intToPtr(*Compilation, stage1.userdata);
411413 const lib_name = std.ascii.allocLowerString(comp.gpa, lib_name_ptr[0..lib_name_len]) catch return "out of memory";
412414 const target = comp.getTarget();
src/test.zig+3
......@@ -70,6 +70,8 @@ const ErrorMsg = union(enum) {
7070 options: std.fmt.FormatOptions,
7171 writer: anytype,
7272 ) !void {
73 _ = fmt;
74 _ = options;
7375 switch (self) {
7476 .src => |src| {
7577 return writer.print("{s}:{d}:{d}: {s}: {s}", .{
......@@ -592,6 +594,7 @@ pub const TestContext = struct {
592594 thread_pool: *ThreadPool,
593595 global_cache_directory: Compilation.Directory,
594596 ) !void {
597 _ = self;
595598 const target_info = try std.zig.system.NativeTargetInfo.detect(allocator, case.target);
596599 const target = target_info.target;
597600
src/tracy.zig+3-1
......@@ -28,7 +28,9 @@ pub const ___tracy_c_zone_context = extern struct {
2828};
2929
3030pub const Ctx = if (enable) ___tracy_c_zone_context else struct {
31 pub fn end(self: Ctx) void {}
31 pub fn end(self: Ctx) void {
32 _ = self;
33 }
3234};
3335
3436pub inline fn trace(comptime src: std.builtin.SourceLocation) Ctx {
src/translate_c.zig+15-9
......@@ -206,6 +206,7 @@ const Scope = struct {
206206 }
207207
208208 fn findBlockReturnType(inner: *Scope, c: *Context) clang.QualType {
209 _ = c;
209210 var scope = inner;
210211 while (true) {
211212 switch (scope.id) {
......@@ -601,7 +602,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const clang.FunctionDecl) Error!void {
601602 var scope = &block_scope.base;
602603
603604 var param_id: c_uint = 0;
604 for (proto_node.data.params) |*param, i| {
605 for (proto_node.data.params) |*param| {
605606 const param_name = param.name orelse {
606607 proto_node.data.is_extern = true;
607608 proto_node.data.is_export = false;
......@@ -785,7 +786,7 @@ const builtin_typedef_map = std.ComptimeStringMap([]const u8, .{
785786});
786787
787788fn transTypeDef(c: *Context, scope: *Scope, typedef_decl: *const clang.TypedefNameDecl) Error!void {
788 if (c.decl_table.get(@ptrToInt(typedef_decl.getCanonicalDecl()))) |name|
789 if (c.decl_table.get(@ptrToInt(typedef_decl.getCanonicalDecl()))) |_|
789790 return; // Avoid processing this decl twice
790791 const toplevel = scope.id == .root;
791792 const bs: *Scope.Block = if (!toplevel) try scope.findBlockScope(c) else undefined;
......@@ -935,7 +936,7 @@ fn hasFlexibleArrayField(c: *Context, record_def: *const clang.RecordDecl) bool
935936}
936937
937938fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordDecl) Error!void {
938 if (c.decl_table.get(@ptrToInt(record_decl.getCanonicalDecl()))) |name|
939 if (c.decl_table.get(@ptrToInt(record_decl.getCanonicalDecl()))) |_|
939940 return; // Avoid processing this decl twice
940941 const record_loc = record_decl.getLocation();
941942 const toplevel = scope.id == .root;
......@@ -1080,7 +1081,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
10801081}
10811082
10821083fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const clang.EnumDecl) Error!void {
1083 if (c.decl_table.get(@ptrToInt(enum_decl.getCanonicalDecl()))) |name|
1084 if (c.decl_table.get(@ptrToInt(enum_decl.getCanonicalDecl()))) |_|
10841085 return; // Avoid processing this decl twice
10851086 const enum_loc = enum_decl.getLocation();
10861087 const toplevel = scope.id == .root;
......@@ -1312,6 +1313,7 @@ fn transConvertVectorExpr(
13121313 source_loc: clang.SourceLocation,
13131314 expr: *const clang.ConvertVectorExpr,
13141315) TransError!Node {
1316 _ = source_loc;
13151317 const base_stmt = @ptrCast(*const clang.Stmt, expr);
13161318
13171319 var block_scope = try Scope.Block.init(c, scope, true);
......@@ -1321,7 +1323,6 @@ fn transConvertVectorExpr(
13211323 const src_type = qualTypeCanon(src_expr.getType());
13221324 const src_vector_ty = @ptrCast(*const clang.VectorType, src_type);
13231325 const src_element_qt = src_vector_ty.getElementType();
1324 const src_element_type_node = try transQualType(c, &block_scope.base, src_element_qt, base_stmt.getBeginLoc());
13251326
13261327 const src_expr_node = try transExpr(c, &block_scope.base, src_expr, .used);
13271328
......@@ -1434,6 +1435,7 @@ fn transSimpleOffsetOfExpr(
14341435 scope: *Scope,
14351436 expr: *const clang.OffsetOfExpr,
14361437) TransError!Node {
1438 _ = scope;
14371439 assert(expr.getNumComponents() == 1);
14381440 const component = expr.getComponent(0);
14391441 if (component.getKind() == .Field) {
......@@ -2270,6 +2272,7 @@ fn transStringLiteralInitializer(
22702272/// both operands resolve to addresses. The C standard requires that both operands
22712273/// point to elements of the same array object, but we do not verify that here.
22722274fn cIsPointerDiffExpr(c: *Context, stmt: *const clang.BinaryOperator) bool {
2275 _ = c;
22732276 const lhs = @ptrCast(*const clang.Stmt, stmt.getLHS());
22742277 const rhs = @ptrCast(*const clang.Stmt, stmt.getRHS());
22752278 return stmt.getOpcode() == .Sub and
......@@ -2573,6 +2576,7 @@ fn transInitListExprVector(
25732576 expr: *const clang.InitListExpr,
25742577 ty: *const clang.Type,
25752578) TransError!Node {
2579 _ = ty;
25762580 const qt = getExprQualType(c, @ptrCast(*const clang.Expr, expr));
25772581 const vector_type = try transQualType(c, scope, qt, loc);
25782582 const init_count = expr.getNumInits();
......@@ -2722,6 +2726,7 @@ fn transImplicitValueInitExpr(
27222726 expr: *const clang.Expr,
27232727 used: ResultUsed,
27242728) TransError!Node {
2729 _ = used;
27252730 const source_loc = expr.getBeginLoc();
27262731 const qt = getExprQualType(c, expr);
27272732 const ty = qt.getTypePtr();
......@@ -3408,6 +3413,7 @@ fn transUnaryExprOrTypeTraitExpr(
34083413 stmt: *const clang.UnaryExprOrTypeTraitExpr,
34093414 result_used: ResultUsed,
34103415) TransError!Node {
3416 _ = result_used;
34113417 const loc = stmt.getBeginLoc();
34123418 const type_node = try transQualType(c, scope, stmt.getTypeOfArgument(), loc);
34133419
......@@ -3802,7 +3808,6 @@ fn transBinaryConditionalOperator(c: *Context, scope: *Scope, stmt: *const clang
38023808 const res_is_bool = qualTypeIsBoolean(qt);
38033809 const casted_stmt = @ptrCast(*const clang.AbstractConditionalOperator, stmt);
38043810 const cond_expr = casted_stmt.getCond();
3805 const true_expr = casted_stmt.getTrueExpr();
38063811 const false_expr = casted_stmt.getFalseExpr();
38073812
38083813 // c: (cond_expr)?:(false_expr)
......@@ -3895,6 +3900,7 @@ fn maybeSuppressResult(
38953900 used: ResultUsed,
38963901 result: Node,
38973902) TransError!Node {
3903 _ = scope;
38983904 if (used == .used) return result;
38993905 return Tag.discard.create(c.arena, result);
39003906}
......@@ -4336,12 +4342,10 @@ fn transCreateNodeNumber(c: *Context, num: anytype, num_kind: enum { int, float
43364342}
43374343
43384344fn transCreateNodeMacroFn(c: *Context, name: []const u8, ref: Node, proto_alias: *ast.Payload.Func) !Node {
4339 const scope = &c.global_scope.base;
4340
43414345 var fn_params = std.ArrayList(ast.Payload.Param).init(c.gpa);
43424346 defer fn_params.deinit();
43434347
4344 for (proto_alias.data.params) |param, i| {
4348 for (proto_alias.data.params) |param| {
43454349 const param_name = param.name orelse
43464350 try std.fmt.allocPrint(c.arena, "arg_{d}", .{c.getMangle()});
43474351
......@@ -5657,6 +5661,7 @@ fn parseCSpecifierQualifierList(c: *Context, m: *MacroCtx, scope: *Scope, allow_
56575661}
56585662
56595663fn parseCNumericType(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
5664 _ = scope;
56605665 const KwCounter = struct {
56615666 double: u8 = 0,
56625667 long: u8 = 0,
......@@ -5758,6 +5763,7 @@ fn parseCNumericType(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
57585763}
57595764
57605765fn parseCAbstractDeclarator(c: *Context, m: *MacroCtx, scope: *Scope, node: Node) ParseError!Node {
5766 _ = scope;
57615767 switch (m.next().?) {
57625768 .Asterisk => {
57635769 // last token of `node`
src/type.zig+4-2
......@@ -600,9 +600,11 @@ pub const Type = extern union {
600600
601601 pub const HashContext = struct {
602602 pub fn hash(self: @This(), t: Type) u64 {
603 _ = self;
603604 return t.hash();
604605 }
605606 pub fn eql(self: @This(), a: Type, b: Type) bool {
607 _ = self;
606608 return a.eql(b);
607609 }
608610 };
......@@ -777,6 +779,7 @@ pub const Type = extern union {
777779 options: std.fmt.FormatOptions,
778780 writer: anytype,
779781 ) @TypeOf(writer).Error!void {
782 _ = options;
780783 comptime assert(fmt.len == 0);
781784 var ty = start_type;
782785 while (true) {
......@@ -3013,7 +3016,7 @@ pub const Type = extern union {
30133016 .base = .{ .tag = t },
30143017 .data = data,
30153018 };
3016 return Type{ .ptr_otherwise = &ptr.base };
3019 return file_struct.Type{ .ptr_otherwise = &ptr.base };
30173020 }
30183021
30193022 pub fn Data(comptime t: Tag) type {
......@@ -3163,7 +3166,6 @@ pub const CType = enum {
31633166 longdouble,
31643167
31653168 pub fn sizeInBits(self: CType, target: Target) u16 {
3166 const arch = target.cpu.arch;
31673169 switch (target.os.tag) {
31683170 .freestanding, .other => switch (target.cpu.arch) {
31693171 .msp430 => switch (self) {
src/value.zig+8
......@@ -626,6 +626,7 @@ pub const Value = extern union {
626626 return std.mem.dupe(allocator, u8, payload.data);
627627 }
628628 if (self.castTag(.repeated)) |payload| {
629 _ = payload;
629630 @panic("TODO implement toAllocatedBytes for this Value tag");
630631 }
631632 if (self.castTag(.decl_ref)) |payload| {
......@@ -747,6 +748,7 @@ pub const Value = extern union {
747748
748749 /// Asserts the type is an enum type.
749750 pub fn toEnum(val: Value, enum_ty: Type, comptime E: type) E {
751 _ = enum_ty;
750752 // TODO this needs to resolve other kinds of Value tags rather than
751753 // assuming the tag will be .enum_field_index.
752754 const field_index = val.castTag(.enum_field_index).?.data;
......@@ -935,6 +937,7 @@ pub const Value = extern union {
935937 /// Converts an integer or a float to a float.
936938 /// Returns `error.Overflow` if the value does not fit in the new type.
937939 pub fn floatCast(self: Value, allocator: *Allocator, ty: Type, target: Target) !Value {
940 _ = target;
938941 switch (ty.tag()) {
939942 .f16 => {
940943 @panic("TODO add __trunctfhf2 to compiler-rt");
......@@ -1292,17 +1295,21 @@ pub const Value = extern union {
12921295
12931296 pub const ArrayHashContext = struct {
12941297 pub fn hash(self: @This(), v: Value) u32 {
1298 _ = self;
12951299 return v.hash_u32();
12961300 }
12971301 pub fn eql(self: @This(), a: Value, b: Value) bool {
1302 _ = self;
12981303 return a.eql(b);
12991304 }
13001305 };
13011306 pub const HashContext = struct {
13021307 pub fn hash(self: @This(), v: Value) u64 {
1308 _ = self;
13031309 return v.hash();
13041310 }
13051311 pub fn eql(self: @This(), a: Value, b: Value) bool {
1312 _ = self;
13061313 return a.eql(b);
13071314 }
13081315 };
......@@ -1345,6 +1352,7 @@ pub const Value = extern union {
13451352 }
13461353
13471354 pub fn fieldValue(val: Value, allocator: *Allocator, index: usize) error{OutOfMemory}!Value {
1355 _ = allocator;
13481356 switch (val.tag()) {
13491357 .@"struct" => {
13501358 const field_values = val.castTag(.@"struct").?.data;
test/behavior/align.zig+1
......@@ -167,6 +167,7 @@ test "generic function with align param" {
167167}
168168
169169fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
170 _ = align_bytes;
170171 return 0x1;
171172}
172173
test/behavior/async_fn.zig+26
......@@ -13,6 +13,7 @@ test "simple coroutine suspend and resume" {
1313 resume frame;
1414 try expect(global_x == 3);
1515 const af: anyframe->void = &frame;
16 _ = af;
1617 resume frame;
1718 try expect(global_x == 4);
1819}
......@@ -45,6 +46,7 @@ test "suspend at end of function" {
4546 fn doTheTest() !void {
4647 try expect(x == 1);
4748 const p = async suspendAtEnd();
49 _ = p;
4850 try expect(x == 2);
4951 }
5052
......@@ -131,7 +133,9 @@ test "@frameSize" {
131133 other(1);
132134 }
133135 fn other(param: i32) void {
136 _ = param;
134137 var local: i32 = undefined;
138 _ = local;
135139 suspend {}
136140 }
137141 };
......@@ -181,6 +185,7 @@ test "coroutine suspend, resume" {
181185
182186test "coroutine suspend with block" {
183187 const p = async testSuspendBlock();
188 _ = p;
184189 try expect(!global_result);
185190 resume a_promise;
186191 try expect(global_result);
......@@ -207,6 +212,7 @@ var await_final_result: i32 = 0;
207212test "coroutine await" {
208213 await_seq('a');
209214 var p = async await_amain();
215 _ = p;
210216 await_seq('f');
211217 resume await_a_promise;
212218 await_seq('i');
......@@ -243,6 +249,7 @@ var early_final_result: i32 = 0;
243249test "coroutine await early return" {
244250 early_seq('a');
245251 var p = async early_amain();
252 _ = p;
246253 early_seq('f');
247254 try expect(early_final_result == 1234);
248255 try expect(std.mem.eql(u8, &early_points, "abcdef"));
......@@ -276,6 +283,7 @@ test "async function with dot syntax" {
276283 }
277284 };
278285 const p = async S.foo();
286 _ = p;
279287 try expect(S.y == 2);
280288}
281289
......@@ -362,11 +370,13 @@ test "error return trace across suspend points - early return" {
362370 const p = nonFailing();
363371 resume p;
364372 const p2 = async printTrace(p);
373 _ = p2;
365374}
366375
367376test "error return trace across suspend points - async return" {
368377 const p = nonFailing();
369378 const p2 = async printTrace(p);
379 _ = p2;
370380 resume p;
371381}
372382
......@@ -396,6 +406,7 @@ fn printTrace(p: anyframe->(anyerror!void)) callconv(.Async) void {
396406test "break from suspend" {
397407 var my_result: i32 = 1;
398408 const p = async testBreakFromSuspend(&my_result);
409 _ = p;
399410 try std.testing.expect(my_result == 2);
400411}
401412fn testBreakFromSuspend(my_result: *i32) callconv(.Async) void {
......@@ -619,11 +630,14 @@ test "returning a const error from async function" {
619630 fn amain() !void {
620631 var download_frame = async fetchUrl(10, "a string");
621632 const download_text = try await download_frame;
633 _ = download_text;
622634
623635 @panic("should not get here");
624636 }
625637
626638 fn fetchUrl(unused: i32, url: []const u8) ![]u8 {
639 _ = unused;
640 _ = url;
627641 frame = @frame();
628642 suspend {}
629643 ok = true;
......@@ -700,6 +714,7 @@ fn testAsyncAwaitTypicalUsage(
700714
701715 var global_download_frame: anyframe = undefined;
702716 fn fetchUrl(allocator: *std.mem.Allocator, url: []const u8) anyerror![]u8 {
717 _ = url;
703718 const result = try std.mem.dupe(allocator, u8, "expected download text");
704719 errdefer allocator.free(result);
705720 if (suspend_download) {
......@@ -713,6 +728,7 @@ fn testAsyncAwaitTypicalUsage(
713728
714729 var global_file_frame: anyframe = undefined;
715730 fn readFile(allocator: *std.mem.Allocator, filename: []const u8) anyerror![]u8 {
731 _ = filename;
716732 const result = try std.mem.dupe(allocator, u8, "expected file text");
717733 errdefer allocator.free(result);
718734 if (suspend_file) {
......@@ -730,6 +746,7 @@ test "alignment of local variables in async functions" {
730746 const S = struct {
731747 fn doTheTest() !void {
732748 var y: u8 = 123;
749 _ = y;
733750 var x: u8 align(128) = 1;
734751 try expect(@ptrToInt(&x) % 128 == 0);
735752 }
......@@ -742,6 +759,7 @@ test "no reason to resolve frame still works" {
742759}
743760fn simpleNothing() void {
744761 var x: i32 = 1234;
762 _ = x;
745763}
746764
747765test "async call a generic function" {
......@@ -802,6 +820,7 @@ test "struct parameter to async function is copied to the frame" {
802820 if (x == 0) return;
803821 clobberStack(x - 1);
804822 var y: i32 = x;
823 _ = y;
805824 }
806825
807826 fn bar(f: *@Frame(foo)) void {
......@@ -1212,6 +1231,7 @@ test "suspend in while loop" {
12121231 suspend {}
12131232 return val;
12141233 } else |err| {
1234 err catch {};
12151235 return 0;
12161236 }
12171237 }
......@@ -1341,6 +1361,7 @@ test "async function passed 0-bit arg after non-0-bit arg" {
13411361 }
13421362
13431363 fn bar(x: i32, args: anytype) anyerror!void {
1364 _ = args;
13441365 global_frame = @frame();
13451366 suspend {}
13461367 global_int = x;
......@@ -1636,6 +1657,8 @@ test "@asyncCall with pass-by-value arguments" {
16361657 pub const AT = [5]u8;
16371658
16381659 pub fn f(_fill0: u64, s: ST, _fill1: u64, a: AT, _fill2: u64) callconv(.Async) void {
1660 _ = s;
1661 _ = a;
16391662 // Check that the array and struct arguments passed by value don't
16401663 // end up overflowing the adjacent fields in the frame structure.
16411664 expectEqual(F0, _fill0) catch @panic("test failure");
......@@ -1654,6 +1677,7 @@ test "@asyncCall with pass-by-value arguments" {
16541677 [_]u8{ 1, 2, 3, 4, 5 },
16551678 F2,
16561679 });
1680 _ = frame_ptr;
16571681}
16581682
16591683test "@asyncCall with arguments having non-standard alignment" {
......@@ -1662,6 +1686,7 @@ test "@asyncCall with arguments having non-standard alignment" {
16621686
16631687 const S = struct {
16641688 pub fn f(_fill0: u32, s: struct { x: u64 align(16) }, _fill1: u64) callconv(.Async) void {
1689 _ = s;
16651690 // The compiler inserts extra alignment for s, check that the
16661691 // generated code picks the right slot for fill1.
16671692 expectEqual(F0, _fill0) catch @panic("test failure");
......@@ -1673,4 +1698,5 @@ test "@asyncCall with arguments having non-standard alignment" {
16731698 // The function pointer must not be comptime-known.
16741699 var t = S.f;
16751700 var frame_ptr = @asyncCall(&buffer, {}, t, .{ F0, undefined, F1 });
1701 _ = frame_ptr;
16761702}
test/behavior/atomics.zig-2
......@@ -97,7 +97,6 @@ test "cmpxchg with ptr" {
9797
9898test "cmpxchg with ignored result" {
9999 var x: i32 = 1234;
100 var ptr = &x;
101100
102101 _ = @cmpxchgStrong(i32, &x, 1234, 5678, .Monotonic, .Monotonic);
103102
......@@ -195,7 +194,6 @@ fn testAtomicRmwInt() !void {
195194test "atomics with different types" {
196195 try testAtomicsWithType(bool, true, false);
197196 inline for (.{ u1, i4, u5, i15, u24 }) |T| {
198 var x: T = 0;
199197 try testAtomicsWithType(T, 0, 1);
200198 }
201199 try testAtomicsWithType(u0, 0, 0);
test/behavior/await_struct.zig+1
......@@ -12,6 +12,7 @@ var await_final_result = Foo{ .x = 0 };
1212test "coroutine await struct" {
1313 await_seq('a');
1414 var p = async await_amain();
15 _ = p;
1516 await_seq('f');
1617 resume await_a_promise;
1718 await_seq('i');
test/behavior/bit_shifting.zig+1-1
......@@ -100,5 +100,5 @@ test "comptime shr of BigInt" {
100100}
101101
102102test "comptime shift safety check" {
103 const x = @as(usize, 42) << @sizeOf(usize);
103 _ = @as(usize, 42) << @sizeOf(usize);
104104}
test/behavior/bugs/1310.zig+2
......@@ -16,6 +16,8 @@ pub const InvocationTable_ = struct_InvocationTable_;
1616pub const VM_ = struct_VM_;
1717
1818fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {
19 _ = _vm;
20 _ = options;
1921 return 11;
2022}
2123
test/behavior/bugs/1467.zig+1
......@@ -4,4 +4,5 @@ pub const S = extern struct {
44};
55test "bug 1467" {
66 const s: S = undefined;
7 _ = s;
78}
test/behavior/bugs/1500.zig+4
......@@ -7,4 +7,8 @@ const B = fn (A) void;
77test "allow these dependencies" {
88 var a: A = undefined;
99 var b: B = undefined;
10 if (false) {
11 a;
12 b;
13 }
1014}
test/behavior/bugs/2346.zig+2
......@@ -1,6 +1,8 @@
11test "fixed" {
22 const a: *void = undefined;
33 const b: *[1]void = a;
4 _ = b;
45 const c: *[0]u8 = undefined;
56 const d: []u8 = c;
7 _ = d;
68}
test/behavior/bugs/2578.zig+3-1
......@@ -5,7 +5,9 @@ const Foo = struct {
55var foo: Foo = undefined;
66const t = &foo;
77
8fn bar(pointer: ?*c_void) void {}
8fn bar(pointer: ?*c_void) void {
9 _ = pointer;
10}
911
1012test "fixed" {
1113 bar(t);
test/behavior/bugs/2692.zig+3-1
......@@ -1,4 +1,6 @@
1fn foo(a: []u8) void {}
1fn foo(a: []u8) void {
2 _ = a;
3}
24
35test "address of 0 length array" {
46 var pt: [0]u8 = undefined;
test/behavior/bugs/3367.zig+3-1
......@@ -3,7 +3,9 @@ const Foo = struct {
33};
44
55const Mixin = struct {
6 pub fn two(self: Foo) void {}
6 pub fn two(self: Foo) void {
7 _ = self;
8 }
79};
810
911test "container member access usingnamespace decls" {
test/behavior/bugs/3586.zig+1
......@@ -8,4 +8,5 @@ test "fixed" {
88 var ctr = Container{
99 .params = NoteParams{},
1010 };
11 _ = ctr;
1112}
test/behavior/bugs/4328.zig+2
......@@ -53,10 +53,12 @@ test "Peer resolution of extern function calls in @TypeOf" {
5353test "Extern function calls, dereferences and field access in @TypeOf" {
5454 const Test = struct {
5555 fn test_fn_1(a: c_long) @TypeOf(fopen("test", "r").*) {
56 _ = a;
5657 return .{ .dummy_field = 0 };
5758 }
5859
5960 fn test_fn_2(a: anytype) @TypeOf(fopen("test", "r").*.dummy_field) {
61 _ = a;
6062 return 255;
6163 }
6264
test/behavior/bugs/4560.zig+4
......@@ -25,6 +25,10 @@ pub fn StringHashMap(comptime V: type) type {
2525}
2626
2727pub fn HashMap(comptime K: type, comptime V: type) type {
28 if (false) {
29 K;
30 V;
31 }
2832 return struct {
2933 size: usize,
3034 max_distance_from_start_index: usize,
test/behavior/bugs/4954.zig+1-1
......@@ -1,5 +1,5 @@
11fn f(buf: []u8) void {
2 var ptr = &buf[@sizeOf(u32)];
2 _ = &buf[@sizeOf(u32)];
33}
44
55test "crash" {
test/behavior/bugs/529_other_file_2.zig+3-1
......@@ -1,4 +1,6 @@
11pub const A = extern struct {
22 field: c_int,
33};
4export fn issue529(a: ?*A) void {}
4export fn issue529(a: ?*A) void {
5 _ = a;
6}
test/behavior/bugs/5487.zig+1
......@@ -1,6 +1,7 @@
11const io = @import("std").io;
22
33pub fn write(_: void, bytes: []const u8) !usize {
4 _ = bytes;
45 return 0;
56}
67pub fn writer() io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write) {
test/behavior/bugs/624.zig+1
......@@ -12,6 +12,7 @@ const ListenerContext = struct {
1212const ContextAllocator = MemoryPool(TestContext);
1313
1414fn MemoryPool(comptime T: type) type {
15 _ = T;
1516 return struct {
1617 n: usize,
1718 };
test/behavior/bugs/679.zig+1
......@@ -2,6 +2,7 @@ const std = @import("std");
22const expect = std.testing.expect;
33
44pub fn List(comptime T: type) type {
5 _ = T;
56 return u32;
67}
78
test/behavior/bugs/7003.zig+1
......@@ -5,4 +5,5 @@ test "@Type should resolve its children types" {
55 comptime var sparse_info = @typeInfo(anyerror!sparse);
66 sparse_info.ErrorUnion.payload = dense;
77 const B = @Type(sparse_info);
8 _ = B;
89}
test/behavior/bugs/7027.zig+3-1
......@@ -9,7 +9,9 @@ const Foobar = struct {
99 }
1010};
1111
12fn foo(arg: anytype) void {}
12fn foo(arg: anytype) void {
13 _ = arg;
14}
1315
1416test "" {
1517 comptime var foobar = Foobar.foo();
test/behavior/bugs/704.zig+3-1
......@@ -1,5 +1,7 @@
11const xxx = struct {
2 pub fn bar(self: *xxx) void {}
2 pub fn bar(self: *xxx) void {
3 _ = self;
4 }
35};
46test "bug 704" {
57 var x: xxx = undefined;
test/behavior/bugs/7250.zig+3-1
......@@ -3,7 +3,9 @@ const nrfx_uart_t = extern struct {
33 drv_inst_idx: u8,
44};
55
6pub fn nrfx_uart_rx(p_instance: [*c]const nrfx_uart_t) void {}
6pub fn nrfx_uart_rx(p_instance: [*c]const nrfx_uart_t) void {
7 _ = p_instance;
8}
79
810threadlocal var g_uart0 = nrfx_uart_t{
911 .p_reg = 0,
test/behavior/bugs/828.zig+6
......@@ -4,6 +4,7 @@ const CountBy = struct {
44 const One = CountBy{ .a = 1 };
55
66 pub fn counter(self: *const CountBy) Counter {
7 _ = self;
78 return Counter{ .i = 0 };
89 }
910};
......@@ -18,6 +19,7 @@ const Counter = struct {
1819};
1920
2021fn constCount(comptime cb: *const CountBy, comptime unused: u32) void {
22 _ = unused;
2123 comptime {
2224 var cnt = cb.counter();
2325 if (cnt.i != 0) @compileError("Counter instance reused!");
......@@ -30,4 +32,8 @@ test "comptime struct return should not return the same instance" {
3032 //a second parameter is required to trigger the bug
3133 const ValA = constCount(&CountBy.One, 12);
3234 const ValB = constCount(&CountBy.One, 15);
35 if (false) {
36 ValA;
37 ValB;
38 }
3339}
test/behavior/bugs/920.zig+2
......@@ -46,6 +46,8 @@ fn norm_f_inv(y: f64) f64 {
4646 return math.sqrt(-2.0 * math.ln(y));
4747}
4848fn norm_zero_case(random: *Random, u: f64) f64 {
49 _ = random;
50 _ = u;
4951 return 0.0;
5052}
5153
test/behavior/cast.zig+9-2
......@@ -102,6 +102,7 @@ fn castToOptionalTypeError(z: i32) !void {
102102
103103 const f = z;
104104 const g: anyerror!?i32 = f;
105 _ = g catch {};
105106
106107 const a = A{ .a = z };
107108 const b: anyerror!?A = a;
......@@ -114,7 +115,9 @@ test "implicitly cast from int to anyerror!?T" {
114115}
115116fn implicitIntLitToOptional() void {
116117 const f: ?i32 = 1;
118 _ = f;
117119 const g: anyerror!?i32 = 1;
120 _ = g catch {};
118121}
119122
120123test "return null from fn() anyerror!?&T" {
......@@ -821,9 +824,13 @@ test "variable initialization uses result locations properly with regards to the
821824test "cast between [*c]T and ?[*:0]T on fn parameter" {
822825 const S = struct {
823826 const Handler = ?fn ([*c]const u8) callconv(.C) void;
824 fn addCallback(handler: Handler) void {}
827 fn addCallback(handler: Handler) void {
828 _ = handler;
829 }
825830
826 fn myCallback(cstr: ?[*:0]const u8) callconv(.C) void {}
831 fn myCallback(cstr: ?[*:0]const u8) callconv(.C) void {
832 _ = cstr;
833 }
827834
828835 fn doTheTest() void {
829836 addCallback(myCallback);
test/behavior/enum.zig+2
......@@ -111,6 +111,8 @@ test "enum type" {
111111 .y = 5678,
112112 },
113113 };
114 try expect(foo1.One == 13);
115 try expect(foo2.Two.x == 1234 and foo2.Two.y == 5678);
114116 const bar = Bar.B;
115117
116118 try expect(bar == Bar.B);
test/behavior/error.zig+13-3
......@@ -103,6 +103,7 @@ fn testErrorSetType() !void {
103103
104104 const a: MyErrSet!i32 = 5678;
105105 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
106 try expect(b catch error.OutOfMemory == error.OutOfMemory);
106107
107108 if (a) |value| try expect(value == 5678) else |err| switch (err) {
108109 error.OutOfMemory => unreachable,
......@@ -138,7 +139,10 @@ test "comptime test error for empty error set" {
138139const EmptyErrorSet = error{};
139140
140141fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) !void {
141 if (x) |v| try expect(v == 1234) else |err| @compileError("bad");
142 if (x) |v| try expect(v == 1234) else |err| {
143 _ = err;
144 @compileError("bad");
145 }
142146}
143147
144148test "syntax: optional operator in front of error union operator" {
......@@ -162,6 +166,7 @@ fn testErrToIntWithOnePossibleValue(
162166
163167test "empty error union" {
164168 const x = error{} || error{};
169 _ = x;
165170}
166171
167172test "error union peer type resolution" {
......@@ -204,6 +209,7 @@ fn entry() void {
204209
205210fn foo2(f: fn () anyerror!void) void {
206211 const x = f();
212 x catch {};
207213}
208214
209215fn bar2() (error{}!void) {}
......@@ -338,6 +344,7 @@ test "optional error set is the same size as error set" {
338344test "debug info for optional error set" {
339345 const SomeError = error{Hello};
340346 var a_local_variable: ?SomeError = null;
347 _ = a_local_variable;
341348}
342349
343350test "nested catch" {
......@@ -349,7 +356,7 @@ test "nested catch" {
349356 return error.Wrong;
350357 }
351358 fn func() anyerror!Foo {
352 const x = fail() catch
359 _ = fail() catch
353360 fail() catch
354361 return error.Bad;
355362 unreachable;
......@@ -390,6 +397,7 @@ test "function pointer with return type that is error union with payload which i
390397 const Err = error{UnspecifiedErr};
391398
392399 fn bar(a: i32) anyerror!*Foo {
400 _ = a;
393401 return Err.UnspecifiedErr;
394402 }
395403
......@@ -444,7 +452,9 @@ test "error payload type is correctly resolved" {
444452
445453test "error union comptime caching" {
446454 const S = struct {
447 fn foo(comptime arg: anytype) void {}
455 fn foo(comptime arg: anytype) void {
456 arg catch {};
457 }
448458 };
449459
450460 S.foo(@as(anyerror!void, {}));
test/behavior/eval.zig+9-2
......@@ -184,6 +184,7 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) usize {
184184 comptime var i: usize = 0;
185185 inline while (i < 10) : (i += 1) {
186186 const result = if (b) false else true;
187 _ = result;
187188 }
188189 comptime {
189190 return i;
......@@ -195,6 +196,7 @@ test "inlined loop has array literal with elided runtime scope on first iteratio
195196 comptime var i: usize = 0;
196197 inline while (i < 2) : (i += 1) {
197198 const result = if (i == 0) [1]i32{2} else runtime;
199 _ = result;
198200 }
199201 comptime {
200202 try expect(i == 2);
......@@ -420,6 +422,7 @@ test {
420422}
421423
422424pub fn TypeWithCompTimeSlice(comptime field_name: []const u8) type {
425 _ = field_name;
423426 return struct {
424427 pub const Node = struct {};
425428 };
......@@ -696,7 +699,9 @@ test "refer to the type of a generic function" {
696699 f(i32);
697700}
698701
699fn doNothingWithType(comptime T: type) void {}
702fn doNothingWithType(comptime T: type) void {
703 _ = T;
704}
700705
701706test "zero extend from u0 to u1" {
702707 var zero_u0: u0 = 0;
......@@ -817,7 +822,9 @@ test "two comptime calls with array default initialized to undefined" {
817822 result.getCpuArch();
818823 }
819824
820 pub fn getCpuArch(self: CrossTarget) void {}
825 pub fn getCpuArch(self: CrossTarget) void {
826 _ = self;
827 }
821828 };
822829
823830 const DynamicLinker = struct {
test/behavior/fn.zig+8-2
......@@ -23,6 +23,7 @@ test "void parameters" {
2323 try voidFun(1, void{}, 2, {});
2424}
2525fn voidFun(a: i32, b: void, c: i32, d: void) !void {
26 _ = d;
2627 const v = b;
2728 const vv: void = if (a == 1) v else {};
2829 try expect(a + c == 3);
......@@ -57,7 +58,9 @@ test "call function with empty string" {
5758 acceptsString("");
5859}
5960
60fn acceptsString(foo: []u8) void {}
61fn acceptsString(foo: []u8) void {
62 _ = foo;
63}
6164
6265fn @"weird function name"() i32 {
6366 return 1234;
......@@ -70,7 +73,9 @@ test "implicit cast function unreachable return" {
7073 wantsFnWithVoid(fnWithUnreachable);
7174}
7275
73fn wantsFnWithVoid(f: fn () void) void {}
76fn wantsFnWithVoid(f: fn () void) void {
77 _ = f;
78}
7479
7580fn fnWithUnreachable() noreturn {
7681 unreachable;
......@@ -162,6 +167,7 @@ const Point3 = struct {
162167 y: i32,
163168
164169 fn addPointCoords(self: Point3, comptime T: type) i32 {
170 _ = T;
165171 return self.x + self.y;
166172 }
167173};
test/behavior/for.zig+11-3
......@@ -29,10 +29,14 @@ test "for loop with pointer elem var" {
2929 mangleString(target[0..]);
3030 try expect(mem.eql(u8, &target, "bcdefgh"));
3131
32 for (source) |*c, i|
32 for (source) |*c, i| {
33 _ = i;
3334 try expect(@TypeOf(c) == *const u8);
34 for (target) |*c, i|
35 }
36 for (target) |*c, i| {
37 _ = i;
3538 try expect(@TypeOf(c) == *u8);
39 }
3640}
3741
3842fn mangleString(s: []u8) void {
......@@ -53,6 +57,7 @@ test "basic for loop" {
5357 buf_index += 1;
5458 }
5559 for (array) |item, index| {
60 _ = item;
5661 buffer[buf_index] = @intCast(u8, index);
5762 buf_index += 1;
5863 }
......@@ -62,6 +67,7 @@ test "basic for loop" {
6267 buf_index += 1;
6368 }
6469 for (array_ptr) |item, index| {
70 _ = item;
6571 buffer[buf_index] = @intCast(u8, index);
6672 buf_index += 1;
6773 }
......@@ -70,7 +76,7 @@ test "basic for loop" {
7076 buffer[buf_index] = item;
7177 buf_index += 1;
7278 }
73 for (unknown_size) |item, index| {
79 for (unknown_size) |_, index| {
7480 buffer[buf_index] = @intCast(u8, index);
7581 buf_index += 1;
7682 }
......@@ -118,6 +124,7 @@ test "2 break statements and an else" {
118124 var buf: [10]u8 = undefined;
119125 var ok = false;
120126 ok = for (buf) |item| {
127 _ = item;
121128 if (f) break false;
122129 if (t) break true;
123130 } else false;
......@@ -136,6 +143,7 @@ test "for with null and T peer types and inferred result location type" {
136143 break item;
137144 }
138145 } else null) |v| {
146 _ = v;
139147 @panic("fail");
140148 }
141149 }
test/behavior/if.zig+1-1
......@@ -45,7 +45,7 @@ var global_with_err: anyerror!u32 = error.SomeError;
4545test "unwrap mutable global var" {
4646 if (global_with_val) |v| {
4747 try expect(v == 0);
48 } else |e| {
48 } else |_| {
4949 unreachable;
5050 }
5151 if (global_with_err) |_| {
test/behavior/import.zig+1-1
......@@ -18,5 +18,5 @@ test "import in non-toplevel scope" {
1818}
1919
2020test "import empty file" {
21 const empty = @import("import/empty.zig");
21 _ = @import("import/empty.zig");
2222}
test/behavior/inttoptr.zig+1-1
......@@ -5,7 +5,7 @@ test "casting random address to function pointer" {
55
66fn randomAddressToFunction() void {
77 var addr: usize = 0xdeadbeef;
8 var ptr = @intToPtr(fn () void, addr);
8 _ = @intToPtr(fn () void, addr);
99}
1010
1111test "mutate through ptr initialized with constant intToPtr value" {
test/behavior/ir_block_deps.zig+1
......@@ -5,6 +5,7 @@ fn foo(id: u64) !i32 {
55 1 => getErrInt(),
66 2 => {
77 const size = try getErrInt();
8 _ = size;
89 return try getErrInt();
910 },
1011 else => error.ItBroke,
test/behavior/math.zig+11
......@@ -333,6 +333,12 @@ test "quad hex float literal parsing in range" {
333333 const b = 0x1.dedafcff354b6ae9758763545432p-9;
334334 const c = 0x1.2f34dd5f437e849b4baab754cdefp+4534;
335335 const d = 0x1.edcbff8ad76ab5bf46463233214fp-435;
336 if (false) {
337 a;
338 b;
339 c;
340 d;
341 }
336342}
337343
338344test "quad hex float literal parsing accurate" {
......@@ -457,6 +463,11 @@ test "hex float literal within range" {
457463 const a = 0x1.0p16383;
458464 const b = 0x0.1p16387;
459465 const c = 0x1.0p-16382;
466 if (false) {
467 a;
468 b;
469 c;
470 }
460471}
461472
462473test "truncating shift left" {
test/behavior/misc.zig+18-4
......@@ -234,6 +234,7 @@ test "compile time global reinterpret" {
234234test "explicit cast maybe pointers" {
235235 const a: ?*i32 = undefined;
236236 const b: ?*f32 = @ptrCast(?*f32, a);
237 _ = b;
237238}
238239
239240test "generic malloc free" {
......@@ -244,14 +245,18 @@ var some_mem: [100]u8 = undefined;
244245fn memAlloc(comptime T: type, n: usize) anyerror![]T {
245246 return @ptrCast([*]T, &some_mem[0])[0..n];
246247}
247fn memFree(comptime T: type, memory: []T) void {}
248fn memFree(comptime T: type, memory: []T) void {
249 _ = memory;
250}
248251
249252test "cast undefined" {
250253 const array: [100]u8 = undefined;
251254 const slice = @as([]const u8, &array);
252255 testCastUndefined(slice);
253256}
254fn testCastUndefined(x: []const u8) void {}
257fn testCastUndefined(x: []const u8) void {
258 _ = x;
259}
255260
256261test "cast small unsigned to larger signed" {
257262 try expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
......@@ -451,6 +456,7 @@ test "@typeName" {
451456}
452457
453458fn TypeFromFn(comptime T: type) type {
459 _ = T;
454460 return struct {};
455461}
456462
......@@ -554,7 +560,12 @@ test "packed struct, enum, union parameters in extern function" {
554560 }), &(PackedUnion{ .a = 1 }));
555561}
556562
557export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion) void {}
563export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion) void {
564 if (false) {
565 a;
566 b;
567 }
568}
558569
559570test "slicing zero length array" {
560571 const s1 = ""[0..];
......@@ -583,6 +594,7 @@ test "self reference through fn ptr field" {
583594 };
584595
585596 fn foo(a: A) u8 {
597 _ = a;
586598 return 12;
587599 }
588600 };
......@@ -752,7 +764,9 @@ test "extern variable with non-pointer opaque type" {
752764
753765test "lazy typeInfo value as generic parameter" {
754766 const S = struct {
755 fn foo(args: anytype) void {}
767 fn foo(args: anytype) void {
768 _ = args;
769 }
756770 };
757771 S.foo(@typeInfo(@TypeOf(.{})));
758772}
test/behavior/null.zig+2
......@@ -39,6 +39,7 @@ test "test maybe object and get a pointer to the inner value" {
3939test "rhs maybe unwrap return" {
4040 const x: ?bool = true;
4141 const y = x orelse return;
42 _ = y;
4243}
4344
4445test "maybe return" {
......@@ -129,6 +130,7 @@ var struct_with_optional: StructWithOptional = undefined;
129130test "unwrap optional which is field of global var" {
130131 struct_with_optional.field = null;
131132 if (struct_with_optional.field) |payload| {
133 _ = payload;
132134 unreachable;
133135 }
134136 struct_with_optional.field = 1234;
test/behavior/optional.zig+2
......@@ -128,6 +128,7 @@ test "nested orelse" {
128128 const x = maybe() orelse
129129 maybe() orelse
130130 return null;
131 _ = x;
131132 unreachable;
132133 }
133134 const Foo = struct {
......@@ -160,6 +161,7 @@ test "self-referential struct through a slice of optional" {
160161test "assigning to an unwrapped optional field in an inline loop" {
161162 comptime var maybe_pos_arg: ?comptime_int = null;
162163 inline for ("ab") |x| {
164 _ = x;
163165 maybe_pos_arg = 0;
164166 if (maybe_pos_arg.? != 0) {
165167 @compileError("bad");
test/behavior/pointers.zig+10-2
......@@ -65,6 +65,10 @@ test "assigning integer to C pointer" {
6565 var x: i32 = 0;
6666 var ptr: [*c]u8 = 0;
6767 var ptr2: [*c]u8 = x;
68 if (false) {
69 ptr;
70 ptr2;
71 }
6872}
6973
7074test "implicit cast single item pointer to C pointer and back" {
......@@ -78,7 +82,6 @@ test "implicit cast single item pointer to C pointer and back" {
7882test "C pointer comparison and arithmetic" {
7983 const S = struct {
8084 fn doTheTest() !void {
81 var one: usize = 1;
8285 var ptr1: [*c]u32 = 0;
8386 var ptr2 = ptr1 + 10;
8487 try expect(ptr1 == 0);
......@@ -176,6 +179,7 @@ test "assign null directly to C pointer and test null equality" {
176179 try expect(!(x != null));
177180 try expect(!(null != x));
178181 if (x) |same_x| {
182 _ = same_x;
179183 @panic("fail");
180184 }
181185 var otherx: i32 = undefined;
......@@ -186,7 +190,10 @@ test "assign null directly to C pointer and test null equality" {
186190 comptime try expect(null == y);
187191 comptime try expect(!(y != null));
188192 comptime try expect(!(null != y));
189 if (y) |same_y| @panic("fail");
193 if (y) |same_y| {
194 _ = same_y;
195 @panic("fail");
196 }
190197 const othery: i32 = undefined;
191198 comptime try expect((y orelse &othery) == &othery);
192199
......@@ -325,6 +332,7 @@ test "@ptrToInt on null optional at comptime" {
325332 {
326333 const pointer = @intToPtr(?*u8, 0x000);
327334 const x = @ptrToInt(pointer);
335 _ = x;
328336 comptime try expect(0 == @ptrToInt(pointer));
329337 }
330338 {
test/behavior/reflection.zig+5
......@@ -15,6 +15,11 @@ test "reflection: function return type, var args, and param types" {
1515}
1616
1717fn dummy(a: bool, b: i32, c: f32) i32 {
18 if (false) {
19 a;
20 b;
21 c;
22 }
1823 return 1234;
1924}
2025
test/behavior/sizeof_and_typeof.zig+2-2
......@@ -195,11 +195,11 @@ test "branching logic inside @TypeOf" {
195195
196196fn fn1(alpha: bool) void {
197197 const n: usize = 7;
198 const v = if (alpha) n else @sizeOf(usize);
198 _ = if (alpha) n else @sizeOf(usize);
199199}
200200
201201test "lazy @sizeOf result is checked for definedness" {
202 const f = fn1;
202 _ = fn1;
203203}
204204
205205test "@bitSizeOf" {
test/behavior/slice.zig+1
......@@ -104,6 +104,7 @@ test "obtaining a null terminated slice" {
104104
105105 // now we obtain a null terminated slice:
106106 const ptr = buf[0..3 :0];
107 _ = ptr;
107108
108109 var runtime_len: usize = 3;
109110 const ptr2 = buf[0..runtime_len :0];
test/behavior/slice_sentinel_comptime.zig+28
......@@ -3,6 +3,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
33 comptime {
44 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
55 const slice = target[0..3 :'d'];
6 _ = slice;
67 }
78
89 // ptr_array
......@@ -10,6 +11,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
1011 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
1112 var target = &buf;
1213 const slice = target[0..3 :'d'];
14 _ = slice;
1315 }
1416
1517 // vector_ConstPtrSpecialBaseArray
......@@ -17,6 +19,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
1719 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
1820 var target: [*]u8 = &buf;
1921 const slice = target[0..3 :'d'];
22 _ = slice;
2023 }
2124
2225 // vector_ConstPtrSpecialRef
......@@ -24,6 +27,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
2427 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
2528 var target: [*]u8 = @ptrCast([*]u8, &buf);
2629 const slice = target[0..3 :'d'];
30 _ = slice;
2731 }
2832
2933 // cvector_ConstPtrSpecialBaseArray
......@@ -31,6 +35,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
3135 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
3236 var target: [*c]u8 = &buf;
3337 const slice = target[0..3 :'d'];
38 _ = slice;
3439 }
3540
3641 // cvector_ConstPtrSpecialRef
......@@ -38,6 +43,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
3843 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
3944 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
4045 const slice = target[0..3 :'d'];
46 _ = slice;
4147 }
4248
4349 // slice
......@@ -45,6 +51,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
4551 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4652 var target: []u8 = &buf;
4753 const slice = target[0..3 :'d'];
54 _ = slice;
4855 }
4956}
5057
......@@ -53,6 +60,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
5360 comptime {
5461 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
5562 const slice = target[0..13 :0xff];
63 _ = slice;
5664 }
5765
5866 // ptr_array
......@@ -60,6 +68,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
6068 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
6169 var target = &buf;
6270 const slice = target[0..13 :0xff];
71 _ = slice;
6372 }
6473
6574 // vector_ConstPtrSpecialBaseArray
......@@ -67,6 +76,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
6776 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
6877 var target: [*]u8 = &buf;
6978 const slice = target[0..13 :0xff];
79 _ = slice;
7080 }
7181
7282 // vector_ConstPtrSpecialRef
......@@ -74,6 +84,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
7484 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
7585 var target: [*]u8 = @ptrCast([*]u8, &buf);
7686 const slice = target[0..13 :0xff];
87 _ = slice;
7788 }
7889
7990 // cvector_ConstPtrSpecialBaseArray
......@@ -81,6 +92,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
8192 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
8293 var target: [*c]u8 = &buf;
8394 const slice = target[0..13 :0xff];
95 _ = slice;
8496 }
8597
8698 // cvector_ConstPtrSpecialRef
......@@ -88,6 +100,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
88100 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
89101 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
90102 const slice = target[0..13 :0xff];
103 _ = slice;
91104 }
92105
93106 // slice
......@@ -95,6 +108,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
95108 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
96109 var target: []u8 = &buf;
97110 const slice = target[0..13 :0xff];
111 _ = slice;
98112 }
99113}
100114
......@@ -103,6 +117,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
103117 comptime {
104118 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
105119 const slice = target[0..3 :'d'];
120 _ = slice;
106121 }
107122
108123 // ptr_array
......@@ -110,6 +125,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
110125 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
111126 var target = &buf;
112127 const slice = target[0..3 :'d'];
128 _ = slice;
113129 }
114130
115131 // vector_ConstPtrSpecialBaseArray
......@@ -117,6 +133,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
117133 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
118134 var target: [*]u8 = &buf;
119135 const slice = target[0..3 :'d'];
136 _ = slice;
120137 }
121138
122139 // vector_ConstPtrSpecialRef
......@@ -124,6 +141,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
124141 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
125142 var target: [*]u8 = @ptrCast([*]u8, &buf);
126143 const slice = target[0..3 :'d'];
144 _ = slice;
127145 }
128146
129147 // cvector_ConstPtrSpecialBaseArray
......@@ -131,6 +149,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
131149 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
132150 var target: [*c]u8 = &buf;
133151 const slice = target[0..3 :'d'];
152 _ = slice;
134153 }
135154
136155 // cvector_ConstPtrSpecialRef
......@@ -138,6 +157,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
138157 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
139158 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
140159 const slice = target[0..3 :'d'];
160 _ = slice;
141161 }
142162
143163 // slice
......@@ -145,6 +165,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
145165 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
146166 var target: []u8 = &buf;
147167 const slice = target[0..3 :'d'];
168 _ = slice;
148169 }
149170}
150171
......@@ -153,6 +174,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
153174 comptime {
154175 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
155176 const slice = target[0..14 :0];
177 _ = slice;
156178 }
157179
158180 // ptr_array
......@@ -160,6 +182,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
160182 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
161183 var target = &buf;
162184 const slice = target[0..14 :0];
185 _ = slice;
163186 }
164187
165188 // vector_ConstPtrSpecialBaseArray
......@@ -167,6 +190,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
167190 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
168191 var target: [*]u8 = &buf;
169192 const slice = target[0..14 :0];
193 _ = slice;
170194 }
171195
172196 // vector_ConstPtrSpecialRef
......@@ -174,6 +198,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
174198 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
175199 var target: [*]u8 = @ptrCast([*]u8, &buf);
176200 const slice = target[0..14 :0];
201 _ = slice;
177202 }
178203
179204 // cvector_ConstPtrSpecialBaseArray
......@@ -181,6 +206,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
181206 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
182207 var target: [*c]u8 = &buf;
183208 const slice = target[0..14 :0];
209 _ = slice;
184210 }
185211
186212 // cvector_ConstPtrSpecialRef
......@@ -188,6 +214,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
188214 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
189215 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
190216 const slice = target[0..14 :0];
217 _ = slice;
191218 }
192219
193220 // slice
......@@ -195,5 +222,6 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
195222 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
196223 var target: []u8 = &buf;
197224 const slice = target[0..14 :0];
225 _ = slice;
198226 }
199227}
test/behavior/struct.zig+10-3
......@@ -182,6 +182,7 @@ test "empty struct method call" {
182182}
183183const EmptyStruct = struct {
184184 fn method(es: *const EmptyStruct) i32 {
185 _ = es;
185186 return 1234;
186187 }
187188};
......@@ -452,9 +453,11 @@ fn alloc(comptime T: type) []T {
452453test "call method with mutable reference to struct with no fields" {
453454 const S = struct {
454455 fn doC(s: *const @This()) bool {
456 _ = s;
455457 return true;
456458 }
457459 fn do(s: *@This()) bool {
460 _ = s;
458461 return true;
459462 }
460463 };
......@@ -584,13 +587,14 @@ test "default struct initialization fields" {
584587 const x = S{
585588 .b = 5,
586589 };
587 if (x.a + x.b != 1239) {
588 @compileError("it should be comptime known");
589 }
590590 var five: i32 = 5;
591591 const y = S{
592592 .b = five,
593593 };
594 if (x.a + x.b != 1239) {
595 @compileError("it should be comptime known");
596 }
597 try expectEqual(y, x);
594598 try expectEqual(1239, x.a + x.b);
595599}
596600
......@@ -624,11 +628,13 @@ test "for loop over pointers to struct, getting field from struct pointer" {
624628 var ok = true;
625629
626630 fn eql(a: []const u8) bool {
631 _ = a;
627632 return true;
628633 }
629634
630635 const ArrayList = struct {
631636 fn toSlice(self: *ArrayList) []*Foo {
637 _ = self;
632638 return @as([*]*Foo, undefined)[0..0];
633639 }
634640 };
......@@ -654,6 +660,7 @@ test "zero-bit field in packed struct" {
654660 y: void,
655661 };
656662 var x: S = undefined;
663 _ = x;
657664}
658665
659666test "struct field init with catch" {
test/behavior/switch.zig+15-3
......@@ -103,6 +103,7 @@ fn switchProngWithVarFn(a: SwitchProngWithVarEnum) !void {
103103 },
104104 SwitchProngWithVarEnum.Meh => |x| {
105105 const v: void = x;
106 _ = v;
106107 },
107108 }
108109}
......@@ -385,6 +386,7 @@ test "switch with null and T peer types and inferred result location type" {
385386 0 => true,
386387 else => null,
387388 }) |v| {
389 _ = v;
388390 @panic("fail");
389391 }
390392 }
......@@ -410,12 +412,18 @@ test "switch prongs with cases with identical payload types" {
410412 try expect(@TypeOf(e) == usize);
411413 try expect(e == 8);
412414 },
413 .B => |e| @panic("fail"),
415 .B => |e| {
416 _ = e;
417 @panic("fail");
418 },
414419 }
415420 }
416421 fn doTheSwitch2(u: Union) !void {
417422 switch (u) {
418 .A, .C => |e| @panic("fail"),
423 .A, .C => |e| {
424 _ = e;
425 @panic("fail");
426 },
419427 .B => |e| {
420428 try expect(@TypeOf(e) == isize);
421429 try expect(e == -8);
......@@ -454,6 +462,7 @@ test "switch variable for range and multiple prongs" {
454462 }
455463 }
456464 };
465 _ = S;
457466}
458467
459468var state: u32 = 0;
......@@ -506,7 +515,10 @@ test "switch on error set with single else" {
506515 fn doTheTest() !void {
507516 var some: error{Foo} = error.Foo;
508517 try expect(switch (some) {
509 else => |a| true,
518 else => |a| blk: {
519 a catch {};
520 break :blk true;
521 },
510522 });
511523 }
512524 };
test/behavior/tuple.zig+1
......@@ -105,6 +105,7 @@ test "tuple initializer for var" {
105105 .id = @as(usize, 2),
106106 .name = Bytes{ .id = 20 },
107107 };
108 _ = tmp;
108109 }
109110 };
110111
test/behavior/type.zig+6-1
......@@ -431,11 +431,14 @@ test "Type.Fn" {
431431
432432 const foo = struct {
433433 fn func(a: usize, b: bool) align(4) callconv(.C) usize {
434 _ = a;
435 _ = b;
434436 return 0;
435437 }
436438 }.func;
437439 const Foo = @Type(@typeInfo(@TypeOf(foo)));
438440 const foo_2: Foo = foo;
441 _ = foo_2;
439442}
440443
441444test "Type.BoundFn" {
......@@ -443,7 +446,9 @@ test "Type.BoundFn" {
443446 if (builtin.target.cpu.arch == .wasm32 or builtin.target.cpu.arch == .wasm64) return error.SkipZigTest;
444447
445448 const TestStruct = packed struct {
446 pub fn foo(self: *const @This()) align(4) callconv(.Unspecified) void {}
449 pub fn foo(self: *const @This()) align(4) callconv(.Unspecified) void {
450 _ = self;
451 }
447452 };
448453 const test_instance: TestStruct = undefined;
449454 try testing.expect(std.meta.eql(
test/behavior/type_info.zig+8-2
......@@ -277,7 +277,9 @@ const TestStruct = packed struct {
277277 fieldC: *Self,
278278 fieldD: u32 = 4,
279279
280 pub fn foo(self: *const Self) void {}
280 pub fn foo(self: *const Self) void {
281 _ = self;
282 }
281283 const Self = @This();
282284};
283285
......@@ -326,9 +328,12 @@ extern fn fooAligned(a: usize, b: bool, ...) align(4) callconv(.C) usize;
326328
327329test "typeInfo with comptime parameter in struct fn def" {
328330 const S = struct {
329 pub fn func(comptime x: f32) void {}
331 pub fn func(comptime x: f32) void {
332 _ = x;
333 }
330334 };
331335 comptime var info = @typeInfo(S);
336 _ = info;
332337}
333338
334339test "type info: vectors" {
......@@ -368,6 +373,7 @@ test "type info: pass to function" {
368373}
369374
370375fn passTypeInfo(comptime info: TypeInfo) type {
376 _ = info;
371377 return void;
372378}
373379
test/behavior/underscore.zig+2
......@@ -7,7 +7,9 @@ test "ignore lval with underscore" {
77
88test "ignore lval with underscore (for loop)" {
99 for ([_]void{}) |_, i| {
10 _ = i;
1011 for ([_]void{}) |_, j| {
12 _ = j;
1113 break;
1214 }
1315 break;
test/behavior/union.zig+9-2
......@@ -374,7 +374,9 @@ const Attribute = union(enum) {
374374 B: u8,
375375};
376376
377fn setAttribute(attr: Attribute) void {}
377fn setAttribute(attr: Attribute) void {
378 _ = attr;
379}
378380
379381fn Setter(attr: Attribute) type {
380382 return struct {
......@@ -465,7 +467,9 @@ test "union no tag with struct member" {
465467 const Struct = struct {};
466468 const Union = union {
467469 s: Struct,
468 pub fn foo(self: *@This()) void {}
470 pub fn foo(self: *@This()) void {
471 _ = self;
472 }
469473 };
470474 var u = Union{ .s = Struct{} };
471475 u.foo();
......@@ -703,6 +707,7 @@ test "method call on an empty union" {
703707 X2: [0]u8,
704708
705709 pub fn useIt(self: *@This()) bool {
710 _ = self;
706711 return true;
707712 }
708713 };
......@@ -771,6 +776,7 @@ test "@unionInit on union w/ tag but no fields" {
771776 no_op: void,
772777
773778 pub fn decode(buf: []const u8) Data {
779 _ = buf;
774780 return @unionInit(Data, "no_op", {});
775781 }
776782 };
......@@ -781,6 +787,7 @@ test "@unionInit on union w/ tag but no fields" {
781787
782788 fn doTheTest() !void {
783789 var data: Data = .{ .no_op = .{} };
790 _ = data;
784791 var o = Data.decode(&[_]u8{});
785792 try expectEqual(Type.no_op, o);
786793 }
test/behavior/var_args.zig+5-2
......@@ -18,7 +18,7 @@ test "add arbitrary args" {
1818}
1919
2020fn readFirstVarArg(args: anytype) void {
21 const value = args[0];
21 _ = args[0];
2222}
2323
2424test "send void arg to var args" {
......@@ -48,6 +48,7 @@ test "runtime parameter before var args" {
4848}
4949
5050fn extraFn(extra: u32, args: anytype) !usize {
51 _ = extra;
5152 if (args.len >= 1) {
5253 try expect(args[0] == false);
5354 }
......@@ -63,9 +64,11 @@ const foos = [_]fn (anytype) bool{
6364};
6465
6566fn foo1(args: anytype) bool {
67 _ = args;
6668 return true;
6769}
6870fn foo2(args: anytype) bool {
71 _ = args;
6972 return false;
7073}
7174
......@@ -79,5 +82,5 @@ test "pass zero length array to var args param" {
7982}
8083
8184fn doNothingWithFirstArg(args: anytype) void {
82 const a = args[0];
85 _ = args[0];
8386}
test/behavior/vector.zig+2
......@@ -113,6 +113,7 @@ test "array to vector" {
113113 var foo: f32 = 3.14;
114114 var arr = [4]f32{ foo, 1.5, 0.0, 0.0 };
115115 var vec: Vector(4, f32) = arr;
116 _ = vec;
116117}
117118
118119test "vector casts of sizes not divisable by 8" {
......@@ -264,6 +265,7 @@ test "initialize vector which is a struct field" {
264265 var foo = Vec4Obj{
265266 .data = [_]f32{ 1, 2, 3, 4 },
266267 };
268 _ = foo;
267269 }
268270 };
269271 try S.doTheTest();
test/behavior/void.zig+1-1
......@@ -36,5 +36,5 @@ test "void optional" {
3636
3737test "void array as a local variable initializer" {
3838 var x = [_]void{{}} ** 1004;
39 var y = x[0];
39 _ = x[0];
4040}
test/behavior/while.zig+2-2
......@@ -151,14 +151,14 @@ test "while on optional with else result follow break prong" {
151151test "while on error union with else result follow else prong" {
152152 const result = while (returnError()) |value| {
153153 break value;
154 } else |err| @as(i32, 2);
154 } else |_| @as(i32, 2);
155155 try expect(result == 2);
156156}
157157
158158test "while on error union with else result follow break prong" {
159159 const result = while (returnSuccess(10)) |value| {
160160 break value;
161 } else |err| @as(i32, 2);
161 } else |_| @as(i32, 2);
162162 try expect(result == 10);
163163}
164164
test/stage2/cbe.zig+37-28
......@@ -93,16 +93,16 @@ pub fn addCases(ctx: *TestContext) !void {
9393 , "");
9494 case.addError(
9595 \\pub export fn main() c_int {
96 \\ const c = @intToError(0);
96 \\ _ = @intToError(0);
9797 \\ return 0;
9898 \\}
99 , &.{":2:27: error: integer value 0 represents no error"});
99 , &.{":2:21: error: integer value 0 represents no error"});
100100 case.addError(
101101 \\pub export fn main() c_int {
102 \\ const c = @intToError(3);
102 \\ _ = @intToError(3);
103103 \\ return 0;
104104 \\}
105 , &.{":2:27: error: integer value 3 represents no error"});
105 , &.{":2:21: error: integer value 3 represents no error"});
106106 }
107107
108108 {
......@@ -383,6 +383,7 @@ pub fn addCases(ctx: *TestContext) !void {
383383 \\ true => 2,
384384 \\ false => 3,
385385 \\ };
386 \\ _ = b;
386387 \\}
387388 , &.{
388389 ":6:9: error: duplicate switch value",
......@@ -398,6 +399,7 @@ pub fn addCases(ctx: *TestContext) !void {
398399 \\ f64, i32 => 3,
399400 \\ else => 4,
400401 \\ };
402 \\ _ = b;
401403 \\}
402404 , &.{
403405 ":6:14: error: duplicate switch value",
......@@ -414,6 +416,7 @@ pub fn addCases(ctx: *TestContext) !void {
414416 \\ f16...f64 => 3,
415417 \\ else => 4,
416418 \\ };
419 \\ _ = b;
417420 \\}
418421 , &.{
419422 ":3:30: error: ranges not allowed when switching on type 'type'",
......@@ -431,6 +434,7 @@ pub fn addCases(ctx: *TestContext) !void {
431434 \\ 3 => 40,
432435 \\ else => 50,
433436 \\ };
437 \\ _ = b;
434438 \\}
435439 , &.{
436440 ":8:14: error: unreachable else prong; all cases already handled",
......@@ -556,10 +560,10 @@ pub fn addCases(ctx: *TestContext) !void {
556560 \\const E1 = packed enum { a, b, c };
557561 \\const E2 = extern enum { a, b, c };
558562 \\export fn foo() void {
559 \\ const x = E1.a;
563 \\ _ = E1.a;
560564 \\}
561565 \\export fn bar() void {
562 \\ const x = E2.a;
566 \\ _ = E2.a;
563567 \\}
564568 , &.{
565569 ":1:12: error: enums do not support 'packed' or 'extern'; instead provide an explicit integer tag type",
......@@ -579,10 +583,10 @@ pub fn addCases(ctx: *TestContext) !void {
579583 \\ c,
580584 \\};
581585 \\export fn foo() void {
582 \\ const x = E1.a;
586 \\ _ = E1.a;
583587 \\}
584588 \\export fn bar() void {
585 \\ const x = E2.a;
589 \\ _ = E2.a;
586590 \\}
587591 , &.{
588592 ":3:5: error: enum fields cannot be marked comptime",
......@@ -621,7 +625,7 @@ pub fn addCases(ctx: *TestContext) !void {
621625 \\ c,
622626 \\};
623627 \\export fn foo() void {
624 \\ const x = E1.a;
628 \\ _ = E1.a;
625629 \\}
626630 , &.{
627631 ":3:7: error: expected ',', found 'align'",
......@@ -638,7 +642,7 @@ pub fn addCases(ctx: *TestContext) !void {
638642 \\ _,
639643 \\};
640644 \\export fn foo() void {
641 \\ const x = E1.a;
645 \\ _ = E1.a;
642646 \\}
643647 , &.{
644648 ":6:5: error: redundant non-exhaustive enum mark",
......@@ -653,7 +657,7 @@ pub fn addCases(ctx: *TestContext) !void {
653657 \\ _ = 10,
654658 \\};
655659 \\export fn foo() void {
656 \\ const x = E1.a;
660 \\ _ = E1.a;
657661 \\}
658662 , &.{
659663 ":5:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value",
......@@ -662,7 +666,7 @@ pub fn addCases(ctx: *TestContext) !void {
662666 case.addError(
663667 \\const E1 = enum {};
664668 \\export fn foo() void {
665 \\ const x = E1.a;
669 \\ _ = E1.a;
666670 \\}
667671 , &.{
668672 ":1:12: error: enum declarations must have at least one tag",
......@@ -671,7 +675,7 @@ pub fn addCases(ctx: *TestContext) !void {
671675 case.addError(
672676 \\const E1 = enum { a, b, _ };
673677 \\export fn foo() void {
674 \\ const x = E1.a;
678 \\ _ = E1.a;
675679 \\}
676680 , &.{
677681 ":1:12: error: non-exhaustive enum missing integer tag type",
......@@ -681,7 +685,7 @@ pub fn addCases(ctx: *TestContext) !void {
681685 case.addError(
682686 \\const E1 = enum { a, b, c, b, d };
683687 \\pub export fn main() c_int {
684 \\ const x = E1.a;
688 \\ _ = E1.a;
685689 \\}
686690 , &.{
687691 ":1:28: error: duplicate enum tag",
......@@ -691,28 +695,28 @@ pub fn addCases(ctx: *TestContext) !void {
691695 case.addError(
692696 \\pub export fn main() c_int {
693697 \\ const a = true;
694 \\ const b = @enumToInt(a);
698 \\ _ = @enumToInt(a);
695699 \\}
696700 , &.{
697 ":3:26: error: expected enum or tagged union, found bool",
701 ":3:20: error: expected enum or tagged union, found bool",
698702 });
699703
700704 case.addError(
701705 \\pub export fn main() c_int {
702706 \\ const a = 1;
703 \\ const b = @intToEnum(bool, a);
707 \\ _ = @intToEnum(bool, a);
704708 \\}
705709 , &.{
706 ":3:26: error: expected enum, found bool",
710 ":3:20: error: expected enum, found bool",
707711 });
708712
709713 case.addError(
710714 \\const E = enum { a, b, c };
711715 \\pub export fn main() c_int {
712 \\ const b = @intToEnum(E, 3);
716 \\ _ = @intToEnum(E, 3);
713717 \\}
714718 , &.{
715 ":3:15: error: enum 'test_case.E' has no tag with value 3",
719 ":3:9: error: enum 'test_case.E' has no tag with value 3",
716720 ":1:11: note: enum declared here",
717721 });
718722
......@@ -780,10 +784,10 @@ pub fn addCases(ctx: *TestContext) !void {
780784 case.addError(
781785 \\const E = enum { a, b, c };
782786 \\pub export fn main() c_int {
783 \\ var x = E.d;
787 \\ _ = E.d;
784788 \\}
785789 , &.{
786 ":3:14: error: enum 'test_case.E' has no member named 'd'",
790 ":3:10: error: enum 'test_case.E' has no member named 'd'",
787791 ":1:11: note: enum declared here",
788792 });
789793
......@@ -791,6 +795,7 @@ pub fn addCases(ctx: *TestContext) !void {
791795 \\const E = enum { a, b, c };
792796 \\pub export fn main() c_int {
793797 \\ var x: E = .d;
798 \\ _ = x;
794799 \\}
795800 , &.{
796801 ":3:17: error: enum 'test_case.E' has no field named 'd'",
......@@ -818,31 +823,35 @@ pub fn addCases(ctx: *TestContext) !void {
818823 \\
819824 );
820825 ctx.h("header with single param function", linux_x64,
821 \\export fn start(a: u8) void{}
826 \\export fn start(a: u8) void{
827 \\ _ = a;
828 \\}
822829 ,
823830 \\ZIG_EXTERN_C void start(uint8_t a0);
824831 \\
825832 );
826833 ctx.h("header with multiple param function", linux_x64,
827 \\export fn start(a: u8, b: u8, c: u8) void{}
834 \\export fn start(a: u8, b: u8, c: u8) void{
835 \\ _ = a; _ = b; _ = c;
836 \\}
828837 ,
829838 \\ZIG_EXTERN_C void start(uint8_t a0, uint8_t a1, uint8_t a2);
830839 \\
831840 );
832841 ctx.h("header with u32 param function", linux_x64,
833 \\export fn start(a: u32) void{}
842 \\export fn start(a: u32) void{ _ = a; }
834843 ,
835844 \\ZIG_EXTERN_C void start(uint32_t a0);
836845 \\
837846 );
838847 ctx.h("header with usize param function", linux_x64,
839 \\export fn start(a: usize) void{}
848 \\export fn start(a: usize) void{ _ = a; }
840849 ,
841850 \\ZIG_EXTERN_C void start(uintptr_t a0);
842851 \\
843852 );
844853 ctx.h("header with bool param function", linux_x64,
845 \\export fn start(a: bool) void{}
854 \\export fn start(a: bool) void{_ = a;}
846855 ,
847856 \\ZIG_EXTERN_C void start(bool a0);
848857 \\
......@@ -866,7 +875,7 @@ pub fn addCases(ctx: *TestContext) !void {
866875 \\
867876 );
868877 ctx.h("header with multiple includes", linux_x64,
869 \\export fn start(a: u32, b: usize) void{}
878 \\export fn start(a: u32, b: usize) void{ _ = a; _ = b; }
870879 ,
871880 \\ZIG_EXTERN_C void start(uint32_t a0, uintptr_t a1);
872881 \\
test/stage2/test.zig+27-10
......@@ -246,11 +246,20 @@ pub fn addCases(ctx: *TestContext) !void {
246246 "",
247247 );
248248 }
249 {
250 var case = ctx.exe("unused vars", linux_x64);
251 case.addError(
252 \\pub fn main() void {
253 \\ const x = 1;
254 \\}
255 , &.{":2:11: error: unused local constant"});
256 }
249257 {
250258 var case = ctx.exe("@TypeOf", linux_x64);
251259 case.addCompareOutput(
252260 \\pub fn main() void {
253261 \\ var x: usize = 0;
262 \\ _ = x;
254263 \\ const z = @TypeOf(x, @as(u128, 5));
255264 \\ assert(z == u128);
256265 \\}
......@@ -275,9 +284,9 @@ pub fn addCases(ctx: *TestContext) !void {
275284 );
276285 case.addError(
277286 \\pub fn main() void {
278 \\ const z = @TypeOf(true, 1);
287 \\ _ = @TypeOf(true, 1);
279288 \\}
280 , &[_][]const u8{":2:15: error: incompatible types: 'bool' and 'comptime_int'"});
289 , &[_][]const u8{":2:9: error: incompatible types: 'bool' and 'comptime_int'"});
281290 }
282291
283292 {
......@@ -738,6 +747,7 @@ pub fn addCases(ctx: *TestContext) !void {
738747 \\ \\ cool thx
739748 \\ \\
740749 \\ ;
750 \\ _ = ignore;
741751 \\ add('ぁ', '\x03');
742752 \\}
743753 \\
......@@ -889,6 +899,7 @@ pub fn addCases(ctx: *TestContext) !void {
889899 \\ try expect(false);
890900 \\ }
891901 \\ };
902 \\ _ = S;
892903 \\}
893904 ,
894905 &.{":4:13: error: invalid 'try' outside function scope"},
......@@ -979,6 +990,7 @@ pub fn addCases(ctx: *TestContext) !void {
979990 \\ return bar;
980991 \\ }
981992 \\ };
993 \\ _ = S;
982994 \\}
983995 , &.{
984996 ":5:20: error: 'bar' not accessible from inner function",
......@@ -1064,6 +1076,7 @@ pub fn addCases(ctx: *TestContext) !void {
10641076 \\ @compileLog(b, 20, f, x);
10651077 \\ @compileLog(1000);
10661078 \\ var bruh: usize = true;
1079 \\ _ = bruh;
10671080 \\ unreachable;
10681081 \\}
10691082 \\export fn other() void {
......@@ -1209,6 +1222,7 @@ pub fn addCases(ctx: *TestContext) !void {
12091222 case.addError(
12101223 \\pub fn main() void {
12111224 \\ var x = null;
1225 \\ _ = x;
12121226 \\}
12131227 , &[_][]const u8{
12141228 ":2:9: error: variable of type '@Type(.Null)' must be const or comptime",
......@@ -1378,7 +1392,9 @@ pub fn addCases(ctx: *TestContext) !void {
13781392 \\pub fn main() void {
13791393 \\ doNothing(0);
13801394 \\}
1381 \\fn doNothing(arg: u0) void {}
1395 \\fn doNothing(arg: u0) void {
1396 \\ _ = arg;
1397 \\}
13821398 ,
13831399 "",
13841400 );
......@@ -1448,14 +1464,14 @@ pub fn addCases(ctx: *TestContext) !void {
14481464 case.addCompareOutput(
14491465 \\pub fn main() void {
14501466 \\ const E = error{ A, B, D } || error { A, B, C };
1451 \\ const a = E.A;
1452 \\ const b = E.B;
1453 \\ const c = E.C;
1454 \\ const d = E.D;
1467 \\ E.A catch {};
1468 \\ E.B catch {};
1469 \\ E.C catch {};
1470 \\ E.D catch {};
14551471 \\ const E2 = error { X, Y } || @TypeOf(error.Z);
1456 \\ const x = E2.X;
1457 \\ const y = E2.Y;
1458 \\ const z = E2.Z;
1472 \\ E2.X catch {};
1473 \\ E2.Y catch {};
1474 \\ E2.Z catch {};
14591475 \\ assert(anyerror || error { Z } == anyerror);
14601476 \\}
14611477 \\fn assert(b: bool) void {
......@@ -1477,6 +1493,7 @@ pub fn addCases(ctx: *TestContext) !void {
14771493 \\ [arg1] "{rdi}" (code)
14781494 \\ : "rcx", "r11", "memory"
14791495 \\ );
1496 \\ _ = x;
14801497 \\}
14811498 , &[_][]const u8{":4:27: error: expected type, found comptime_int"});
14821499 }
test/stage2/wasm.zig+11-1
......@@ -64,7 +64,7 @@ pub fn addCases(ctx: *TestContext) !void {
6464 \\ foo(10, 20);
6565 \\ return 5;
6666 \\}
67 \\fn foo(x: u32, y: u32) void {}
67 \\fn foo(x: u32, y: u32) void { _ = x; _ = y; }
6868 , "5\n");
6969 }
7070
......@@ -76,6 +76,10 @@ pub fn addCases(ctx: *TestContext) !void {
7676 \\ var i: u32 = 5;
7777 \\ var y: f32 = 42.0;
7878 \\ var x: u32 = 10;
79 \\ if (false) {
80 \\ y;
81 \\ x;
82 \\ }
7983 \\ return i;
8084 \\}
8185 , "5\n");
......@@ -84,12 +88,14 @@ pub fn addCases(ctx: *TestContext) !void {
8488 \\pub export fn _start() u32 {
8589 \\ var i: u32 = 5;
8690 \\ var y: f32 = 42.0;
91 \\ _ = y;
8792 \\ var x: u32 = 10;
8893 \\ foo(i, x);
8994 \\ i = x;
9095 \\ return i;
9196 \\}
9297 \\fn foo(x: u32, y: u32) void {
98 \\ _ = y;
9399 \\ var i: u32 = 10;
94100 \\ i = x;
95101 \\}
......@@ -388,6 +394,10 @@ pub fn addCases(ctx: *TestContext) !void {
388394 \\pub export fn _start() i32 {
389395 \\ var number1 = Number.One;
390396 \\ var number2: Number = .Two;
397 \\ if (false) {
398 \\ number1;
399 \\ number2;
400 \\ }
391401 \\ const number3 = @intToEnum(Number, 2);
392402 \\
393403 \\ return @enumToInt(number3);
test/standalone/hello_world/hello_libc.zig+2
......@@ -8,6 +8,8 @@ const c = @cImport({
88const msg = "Hello, world!\n";
99
1010pub export fn main(argc: c_int, argv: **u8) c_int {
11 _ = argv;
12 _ = argc;
1113 if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1;
1214 return 0;
1315}
test/standalone/issue_339/test.zig+2
......@@ -1,5 +1,7 @@
11const StackTrace = @import("std").builtin.StackTrace;
22pub fn panic(msg: []const u8, stack_trace: ?*StackTrace) noreturn {
3 _ = msg;
4 _ = stack_trace;
35 @breakpoint();
46 while (true) {}
57}
test/standalone/issue_8550/main.zig+5
......@@ -1,6 +1,11 @@
11export fn main(r0: u32, r1: u32, atags: u32) callconv(.C) noreturn {
2 _ = r0;
3 _ = r1;
4 _ = atags;
25 unreachable; // never gets run so it doesn't matter
36}
47pub fn panic(msg: []const u8, error_return_trace: ?*@import("std").builtin.StackTrace) noreturn {
8 _ = msg;
9 _ = error_return_trace;
510 while (true) {}
611}
test/tests.zig+2-1
......@@ -417,6 +417,8 @@ pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []
417417}
418418
419419pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
420 _ = test_filter;
421 _ = modes;
420422 const step = b.step("test-cli", "Test the command line interface");
421423
422424 const exe = b.addExecutable("test-cli", "test/cli.zig");
......@@ -525,7 +527,6 @@ pub fn addPkgTests(
525527 if (skip_single_threaded and test_target.single_threaded)
526528 continue;
527529
528 const ArchTag = std.meta.Tag(std.Target.Cpu.Arch);
529530 if (test_target.disable_native and
530531 test_target.target.getOsTag() == std.Target.current.os.tag and
531532 test_target.target.getCpuArch() == std.Target.current.cpu.arch)
tools/process_headers.zig+3
......@@ -236,12 +236,14 @@ const DestTarget = struct {
236236
237237 const HashContext = struct {
238238 pub fn hash(self: @This(), a: DestTarget) u32 {
239 _ = self;
239240 return @enumToInt(a.arch) +%
240241 (@enumToInt(a.os) *% @as(u32, 4202347608)) +%
241242 (@enumToInt(a.abi) *% @as(u32, 4082223418));
242243 }
243244
244245 pub fn eql(self: @This(), a: DestTarget, b: DestTarget) bool {
246 _ = self;
245247 return a.arch.eql(b.arch) and
246248 a.os == b.os and
247249 a.abi == b.abi;
......@@ -256,6 +258,7 @@ const Contents = struct {
256258 is_generic: bool,
257259
258260 fn hitCountLessThan(context: void, lhs: *const Contents, rhs: *const Contents) bool {
261 _ = context;
259262 return lhs.hit_count < rhs.hit_count;
260263 }
261264};
tools/update_clang_options.zig+3
......@@ -585,6 +585,8 @@ const Syntax = union(enum) {
585585 options: std.fmt.FormatOptions,
586586 out_stream: anytype,
587587 ) !void {
588 _ = fmt;
589 _ = options;
588590 switch (self) {
589591 .multi_arg => |n| return out_stream.print(".{{.{s}={}}}", .{ @tagName(self), n }),
590592 else => return out_stream.print(".{s}", .{@tagName(self)}),
......@@ -663,6 +665,7 @@ fn syntaxMatchesWithEql(syntax: Syntax) bool {
663665}
664666
665667fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {
668 _ = context;
666669 // Priority is determined by exact matches first, followed by prefix matches in descending
667670 // length, with key as a final tiebreaker.
668671 const a_syntax = objSyntax(a);
tools/update_cpu_features.zig+3
......@@ -1227,14 +1227,17 @@ fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
12271227}
12281228
12291229fn featureLessThan(context: void, a: Feature, b: Feature) bool {
1230 _ = context;
12301231 return std.ascii.lessThanIgnoreCase(a.zig_name, b.zig_name);
12311232}
12321233
12331234fn cpuLessThan(context: void, a: Cpu, b: Cpu) bool {
1235 _ = context;
12341236 return std.ascii.lessThanIgnoreCase(a.zig_name, b.zig_name);
12351237}
12361238
12371239fn asciiLessThan(context: void, a: []const u8, b: []const u8) bool {
1240 _ = context;
12381241 return std.ascii.lessThanIgnoreCase(a, b);
12391242}
12401243
tools/update_glibc.zig+5-3
......@@ -155,7 +155,7 @@ pub fn main() !void {
155155 }
156156 const fn_set = &target_funcs_gop.value_ptr.list;
157157
158 for (lib_names) |lib_name, lib_name_index| {
158 for (lib_names) |lib_name| {
159159 const lib_prefix = if (std.mem.eql(u8, lib_name, "ld")) "" else "lib";
160160 const basename = try fmt.allocPrint(allocator, "{s}{s}.abilist", .{ lib_prefix, lib_name });
161161 const abi_list_filename = blk: {
......@@ -263,7 +263,7 @@ pub fn main() !void {
263263
264264 // Now the mapping of version and function to integer index is complete.
265265 // Here we create a mapping of function name to list of versions.
266 for (abi_lists) |*abi_list, abi_index| {
266 for (abi_lists) |*abi_list| {
267267 const value = target_functions.getPtr(@ptrToInt(abi_list)).?;
268268 const fn_vers_list = &value.fn_vers_list;
269269 for (value.list.items) |*ver_fn| {
......@@ -286,7 +286,7 @@ pub fn main() !void {
286286 const abilist_txt = buffered.writer();
287287
288288 // first iterate over the abi lists
289 for (abi_lists) |*abi_list, abi_index| {
289 for (abi_lists) |*abi_list| {
290290 const fn_vers_list = &target_functions.getPtr(@ptrToInt(abi_list)).?.fn_vers_list;
291291 for (abi_list.targets) |target, it_i| {
292292 if (it_i != 0) try abilist_txt.writeByte(' ');
......@@ -312,10 +312,12 @@ pub fn main() !void {
312312}
313313
314314pub fn strCmpLessThan(context: void, a: []const u8, b: []const u8) bool {
315 _ = context;
315316 return std.mem.order(u8, a, b) == .lt;
316317}
317318
318319pub fn versionLessThan(context: void, a: []const u8, b: []const u8) bool {
320 _ = context;
319321 const sep_chars = "GLIBC_.";
320322 var a_tokens = std.mem.tokenize(a, sep_chars);
321323 var b_tokens = std.mem.tokenize(b, sep_chars);
tools/update_spirv_features.zig+1
......@@ -37,6 +37,7 @@ const Version = struct {
3737 }
3838
3939 fn lessThan(ctx: void, a: Version, b: Version) bool {
40 _ = ctx;
4041 return if (a.major == b.major)
4142 a.minor < b.minor
4243 else